Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions CLUE/CLUE_Rock_Paper_Scissors/advanced/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,10 @@
from rps_display import RPSDisplay, blankScreen


# Look for our name in secrets.py file if present
ble_name = None
try:
from secrets import secrets
ble_name = secrets.get("rps_name")
if ble_name is None:
ble_name = secrets.get("ble_name")
if ble_name is None:
print("INFO: No rps_name or ble_name entry found in secrets dict")
except ImportError:
pass # File is optional, reaching here is not a program error

# Look for our name in settings.toml file if present
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much simpler with using defaults

ble_name = os.getenv("rps_name", os.getenv("ble_name"))
if ble_name is None:
print("INFO: No rps_name or ble_name entry found in settings.toml")

debug = 1

Expand Down Expand Up @@ -228,7 +220,7 @@ def button_right():
# Intro screen with audio
rps_display.introductionScreen()

# Enable the Bluetooth LE radio and set player's name (from secrets.py)
# Enable the Bluetooth LE radio and set player's name (from settings.toml)
ble = BLERadio()
if ble_name is not None:
ble.name = ble_name
Expand Down
30 changes: 18 additions & 12 deletions Cheekmate/CircuitPython/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
CHEEKMATE: secret message receiver using WiFi, Adafruit IO and a haptic
buzzer. Periodically polls an Adafruit IO dashboard, converting new messages
to Morse code.

secrets.py file must be present and contain WiFi & Adafruit IO credentials.
"""

from os import getenv
import gc
import time
import ssl
Expand All @@ -23,11 +22,20 @@
import wifi
from adafruit_io.adafruit_io import IO_HTTP

try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
ssid = getenv("CIRCUITPY_WIFI_SSID")
password = getenv("CIRCUITPY_WIFI_PASSWORD")
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
aio_key = getenv("ADAFRUIT_AIO_KEY")

if None in [ssid, password, aio_username, aio_key]:
raise RuntimeError(
"WiFi and Adafruit IO settings are kept in settings.toml, "
"please add them there. The settings file must contain "
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
"'ADAFRUIT_AIO_USERNAME' and 'ADAFRUIT_AIO_KEY' at a minimum."
)

# CONFIGURABLE GLOBALS -----------------------------------------------------

Expand Down Expand Up @@ -154,10 +162,10 @@ def play(string):
# WIFI CONNECT -------------------------------------------------------------

try:
print("Connecting to {}...".format(secrets["ssid"]), end="")
wifi.radio.connect(secrets["ssid"], secrets["password"])
print(f"Connecting to {ssid}...")
wifi.radio.connect(ssid, password)
print("OK")
print("IP:", wifi.radio.ipv4_address)
print(f"IP: {wifi.radio.ipv4_address}")

pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())
Expand All @@ -169,8 +177,6 @@ def play(string):

# ADAFRUIT IO INITIALIZATION -----------------------------------------------

aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]
io = IO_HTTP(aio_username, aio_key, requests)

# SUCCESSFUL STARTUP, PROCEED INTO MAIN LOOP -------------------------------
Expand Down
59 changes: 33 additions & 26 deletions CircuitPython_WeatherCloud/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: MIT

from os import getenv
import time
import random
import audioio
Expand All @@ -20,25 +21,29 @@
button = digitalio.DigitalInOut(board.A1)
button.switch_to_input(pull=digitalio.Pull.UP)

wave_file = open("sound/Rain.wav", "rb")
wave = audiocore.WaveFile(wave_file)
with open("sound/Rain.wav", "rb") as wave_file:
wave = audiocore.WaveFile(wave_file)
audio = audioio.AudioOut(board.A0)

# Get WiFi details, ensure these are setup in settings.toml
ssid = getenv("CIRCUITPY_WIFI_SSID")
password = getenv("CIRCUITPY_WIFI_PASSWORD")

# Get wifi details and more from a secrets.py file
try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
if None in [ssid, password]:
raise RuntimeError(
"WiFi settings are kept in settings.toml, "
"please add them there. The settings file must contain "
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
"at a minimum."
)

# Use cityname, country code where countrycode is ISO3166 format.
# E.g. "New York, US" or "London, GB"
LOCATION = secrets['timezone']
LOCATION = getenv('timezone')

# Set up where we'll be fetching data from
DATA_SOURCE = "http://api.openweathermap.org/data/2.5/weather?q="+secrets['timezone']
DATA_SOURCE += "&appid="+secrets['openweather_token']
DATA_SOURCE = "http://api.openweathermap.org/data/2.5/weather?q="+LOCATION
DATA_SOURCE += "&appid="+getenv('openweather_token')

# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
Expand All @@ -47,8 +52,8 @@

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards
wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel)
pixels = neopixel.NeoPixel(board.D2, 150, brightness=1.0, auto_write=False)
pixels.fill(0x050505)
pixels.show()
Expand Down Expand Up @@ -134,18 +139,18 @@
raining = snowing = thundering = has_sound = False
if weather_type == 'Sunny':
palette = sunny_palette
wave_file = open("sound/Clear.wav", "rb")
wave = audiocore.WaveFile(wave_file)
with open("sound/Clear.wav", "rb") as wave_file:
wave = audiocore.WaveFile(wave_file)
has_sound = True
if weather_type == 'Clouds':
palette = cloudy_palette
wave_file = open("sound/Clouds.wav", "rb")
wave = audiocore.WaveFile(wave_file)
with open("sound/Clouds.wav", "rb") as wave_file:
wave = audiocore.WaveFile(wave_file)
has_sound = True
if weather_type == 'Rain':
palette = cloudy_palette
wave_file = open("sound/Rain.wav", "rb")
wave = audiocore.WaveFile(wave_file)
with open("sound/Rain.wav", "rb") as wave_file:
wave = audiocore.WaveFile(wave_file)
raining = True
has_sound = True
if weather_type == 'Thunderstorm':
Expand All @@ -156,8 +161,8 @@
next_bolt_time = time.monotonic() + random.randint(1, 5)
if weather_type == 'Snow':
palette = cloudy_palette
wave_file = open("sound/Snow.wav", "rb")
wave = audiocore.WaveFile(wave_file)
with open("sound/Snow.wav", "rb") as wave_file:
wave = audiocore.WaveFile(wave_file)
snowing = True
has_sound = True
weather_refresh = time.monotonic()
Expand Down Expand Up @@ -204,11 +209,13 @@
# pick next thunderbolt time now
Thunder = random.randint(0, 2)
if Thunder == 0:
wave_file = open("sound/Thunderstorm0.wav", "rb")
wave_filename = "sound/Thunderstorm0.wav"
elif Thunder == 1:
wave_file = open("sound/Thunderstorm1.wav", "rb")
wave_filename = "sound/Thunderstorm1.wav"
elif Thunder == 2:
wave_file = open("sound/Thunderstorm2.wav", "rb")
wave = audiocore.WaveFile(wave_file)
audio.play(wave)
wave_filename = "sound/Thunderstorm2.wav"
if wave_filename:
with open(wave_filename, "rb") as wave_file:
wave = audiocore.WaveFile(wave_file)
audio.play(wave)
next_bolt_time = time.monotonic() + random.randint(5, 15) # between 5 and 15 s
13 changes: 0 additions & 13 deletions CircuitPython_WeatherCloud/secrets.py
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed and turned into settings.toml per discord convo

This file was deleted.

12 changes: 12 additions & 0 deletions CircuitPython_WeatherCloud/settings.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: 2020 Limor Fried for Adafruit Industries
#
# SPDX-License-Identifier: MIT

# This file is where you keep private settings, passwords, and tokens!
# If you put them in the code you risk committing that info or sharing it


CIRCUITPY_WIFI_SSID="your-wifi-ssid"
CIRCUITPY_WIFI_PASSWORD="your-wifi-password"
timezone="America/New_York" # http://worldtimeapi.org/timezones
openweather_token="putYourOpenWeatherTokenHere"
25 changes: 20 additions & 5 deletions CircuitPython_qrio/adafruit_io/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

"""
This demo is designed for the Kaluga development kit version 1.3 with the
ILI9341 display. Your secrets.py must be populated with your wifi credentials
ILI9341 display. Your settings.toml must be populated with your wifi credentials
and your Adafruit IO credentials.
"""

from os import getenv
import ssl
from secrets import secrets
from ulab import numpy as np
from terminalio import FONT
import board
Expand All @@ -25,6 +25,21 @@
from adafruit_io.adafruit_io import IO_MQTT
import adafruit_minimqtt.adafruit_minimqtt as MQTT

# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
ssid = getenv("CIRCUITPY_WIFI_SSID")
password = getenv("CIRCUITPY_WIFI_PASSWORD")
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
aio_key = getenv("ADAFRUIT_AIO_KEY")

if None in [ssid, password, aio_username, aio_key]:
raise RuntimeError(
"WiFi and Adafruit IO settings are kept in settings.toml, "
"please add them there. The settings file must contain "
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
"'ADAFRUIT_AIO_USERNAME' and 'ADAFRUIT_AIO_KEY' at a minimum."
)

# To change the name of the feed on adafruit_io, just modify this string:
feed_name = "qrstring"

Expand Down Expand Up @@ -53,14 +68,14 @@
cam.colorspace = adafruit_ov2640.OV2640_COLOR_YUV

print("Connecting to WIFI")
wifi.radio.connect(secrets["ssid"], secrets["password"])
wifi.radio.connect(ssid, password)
pool = socketpool.SocketPool(wifi.radio)

print("Connecting to Adafruit IO")
mqtt_client = MQTT.MQTT(
broker="io.adafruit.com",
username=secrets["aio_username"],
password=secrets["aio_key"],
username=aio_username,
password=aio_key,
socket_pool=pool,
ssl_context=ssl.create_default_context(),
)
Expand Down
3 changes: 1 addition & 2 deletions CircuitPython_qrio/usb_hid/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

"""
This demo is designed for the Kaluga development kit version 1.3 with the
ILI9341 display. Your secrets.py must be populated with your wifi credentials
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one doesn't use wifi or AIO

and your Adafruit IO credentials.
ILI9341 display.
"""

from ulab import numpy as np
Expand Down
22 changes: 14 additions & 8 deletions CircuitStonks/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: MIT

from os import getenv
import time
import board
from digitalio import DigitalInOut
Expand All @@ -14,24 +15,29 @@

minitft = minitft_featherwing.MiniTFTFeatherWing()

# Get wifi details and more from a secrets.py file
try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
# Get WiFi details, ensure these are setup in settings.toml
ssid = getenv("CIRCUITPY_WIFI_SSID")
password = getenv("CIRCUITPY_WIFI_PASSWORD")

if None in [ssid, password]:
raise RuntimeError(
"WiFi settings are kept in settings.toml, "
"please add them there. The settings file must contain "
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
"at a minimum."
)

# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.D13)
esp32_ready = DigitalInOut(board.D11)
esp32_reset = DigitalInOut(board.D12)
spi = board.SPI()
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets)
wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password)

# Symbol "INX" for S&P500, "DJIA" for Dow
DATA_SOURCE = "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&apikey="
DATA_SOURCE += secrets['alphavantage_key']
DATA_SOURCE += getenv('alphavantage_key')
symbols = ["DJIA", "INX", "AAPL", "TSLA", "MSFT"]

# Set text, font, and color
Expand Down
11 changes: 0 additions & 11 deletions CircuitStonks/secrets.py

This file was deleted.

11 changes: 11 additions & 0 deletions CircuitStonks/settings.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SPDX-FileCopyrightText: 2020 Limor Fried for Adafruit Industries
#
# SPDX-License-Identifier: MIT

# This file is where you keep private settings, passwords, and tokens!
# If you put them in the code you risk committing that info or sharing it

CIRCUITPY_WIFI_SSID="your-wifi-ssid"
CIRCUITPY_WIFI_PASSWORD="your-wifi-password"
timezone="America/New_York" # http://worldtimeapi.org/timezones
alphavantage_key="GRABAFREEKEYONLINE"
Loading