def fetchDate(wrds): word_idx = None ### alarm.sleep_memory isn't present on PyPortal ### Storing the word_idx in a register on the temperature sensor - niishhh! import adafruit_adt7410 adafruit_adt7410.ADT7410.reset = lambda self: self ### nobble the reset adt = adafruit_adt7410.ADT7410(board.I2C(), address=0x48) ### Look for a value (well) below default of 10 degrees if adt.low_temperature < 0.0: word_idx = round((0.0 - adt.low_temperature) * 128) wrds.selector_value = word_idx d_print(1, "Retrieved word_idx", word_idx) ### If word_idx isn't set need to fetch the data from t'Internet if word_idx is None: import supervisor import adafruit_datetime from adafruit_pyportal import PyPortal pyportal = PyPortal(status_neopixel=board.NEOPIXEL) pyportal.get_local_time() wordle_oday = adafruit_datetime.date(*wrds.selector_value).toordinal() now_oday = adafruit_datetime.datetime.now().toordinal() word_idx = now_oday - wordle_oday d_print(1, "Saving word_idx", word_idx) adt.low_temperature = (0 - word_idx ) / 128 time.sleep(10) supervisor.reload()
def initialize_input(self): import adafruit_adt7410 from adafruit_extended_bus import ExtendedI2C self.sensor = adafruit_adt7410.ADT7410( ExtendedI2C(self.input_dev.i2c_bus), address=int(str(self.input_dev.i2c_location), 16)) self.sensor.high_resolution = True
def __init__( self, adxl343_address: int = 0x53, adt7410_address: int = 0x48, i2c: Optional[int] = None, ): if i2c is None: i2c = board.I2C() self._adxl343 = adafruit_adxl34x.ADXL345(i2c, address=adxl343_address) self._adt7410 = adafruit_adt7410.ADT7410(i2c, address=adt7410_address)
aio_username = secrets["aio_username"] aio_key = secrets["aio_key"] # Create an instance of the Adafruit IO HTTP client io = IO_HTTP(aio_username, aio_key, wifi) try: # Get the 'temperature' feed from Adafruit IO temperature_feed = io.get_feed("temperature") except AdafruitIO_RequestError: # If no 'temperature' feed exists, create one temperature_feed = io.create_new_feed("temperature") # Set up ADT7410 sensor i2c_bus = busio.I2C(board.SCL, board.SDA) adt = adafruit_adt7410.ADT7410(i2c_bus, address=0x48) adt.high_resolution = True while True: try: temperature = adt.temperature # set temperature value to two precision points temperature = "%0.2f" % (temperature) print("Current Temperature: {0}*C".format(temperature)) print("Sending to Adafruit IO...") io.send_data(temperature_feed["key"], temperature) print("Data sent!") except (ValueError, RuntimeError) as e: print("Failed to get data, retrying\n", e) wifi.reset()
def temp_init(): i2c_bus = busio.I2C(board.SCL, board.SDA) adt = adafruit_adt7410.ADT7410(i2c_bus, address=0x48) adt.high_resolution = True return adt
import terminalio from adafruit_display_text import label text_area = label.Label( terminalio.FONT, text="PyPortal\nRocks", max_glyphs=50, # Optionally allow longer text to be added color = 0x00FF00, x=20, # Pixel offsets from (0, 0) the top left y=20, line_spacing=1, # Distance between lines ) temp_sensor = adafruit_adt7410.ADT7410( busio.I2C(board.SCL, board.SDA), address=0x48, # Specific device address for ADT7410 ) temp_sensor.high_resolution = True # Connect to the NeoPixel (there is only one so it is index 0) # auto_write means we don't have to call pixels.show() each time pixels = neopixel.NeoPixel(board.NEOPIXEL, 1, auto_write=True) def play_sound_file(file_path): try: with open(file_path, "rb") as f: wave = audioio.WaveFile(f) audio.play(wave) while audio.playing: time.sleep(0.005)