def connect_io(self): print('Connecting adafruit io...') self.io = RESTClient(secrets['aio_username'], secrets['aio_key'], self.wifi) self.feed_start_time_f = self.io.get_feed('feed-start') self.feed_end_time_f = self.io.get_feed('feed-end') self.feed_count_f = self.io.get_feed('feed-count') print('Done.')
def __init__(self, name): """Create an instance.""" # PyPortal ESP32 Setup esp32_cs = DigitalInOut(board.ESP_CS) esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) ADAFRUIT_IO_USER = secrets['adafruit_io_user'] ADAFRUIT_IO_KEY = secrets['adafruit_io_key'] # Create an instance of the Adafruit IO REST client self._io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi) self._name = '{0}-logging'.format(name) try: # Get the logging feed from Adafruit IO self._log_feed = self._io.get_feed(self._name) except AdafruitIO_RequestError: # If no logging feed exists, create one self._log_feed = self._io.create_new_feed(self._name)
def push_to_io(self, feed_key, data): # pylint: disable=line-too-long """Push data to an adafruit.io feed :param str feed_key: Name of feed key to push data to. :param data: data to send to feed """ # pylint: enable=line-too-long try: aio_username = secrets['aio_username'] aio_key = secrets['aio_key'] except KeyError: raise KeyError("Adafruit IO secrets are kept in secrets.py, please add them there!\n\n") wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(self._esp, secrets, None) io_client = RESTClient(aio_username, aio_key, wifi) while True: try: feed_id = io_client.get_feed(feed_key) except AdafruitIO_RequestError: # If no feed exists, create one feed_id = io_client.create_new_feed(feed_key) except RuntimeError as exception: print("An error occured, retrying! 1 -", exception) continue break while True: try: io_client.send_data(feed_id['key'], data) except RuntimeError as exception: print("An error occured, retrying! 2 -", exception) continue except NameError as exception: print(feed_id['key'], data, exception) continue break
esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) """ # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) aio_username = secrets['aio_username'] aio_key = secrets['aio_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(aio_username, aio_key, wifi) # Random Data ID # (to obtain this value, visit # https://io.adafruit.com/services/words # and copy over the location ID) random_data_id = 1234 while True: try: print('Fetching random data from Adafruit IO...') random_data = io.receive_random_data(random_data_id) print('Random Data: ', random_data['value']) print('Data Seed: ', random_data['seed']) print('Waiting 1 minute to fetch new randomized data...') except (ValueError, RuntimeError) as e:
esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) """ # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) ADAFRUIT_IO_USER = secrets['adafruit_io_user'] ADAFRUIT_IO_KEY = secrets['adafruit_io_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi) # Create a new group print('Creating a new Adafruit IO Group...') sensor_group = io.create_new_group('envsensors', 'a group of environmental sensors') # Add the 'temperature' feed to the group print('Adding feed temperature to group...') io.add_feed_to_group(sensor_group['key'], 'temperature') # Get info from the group print(sensor_group) # Delete the group print('Deleting group...')
esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) """ # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) aio_username = secrets['aio_username'] aio_key = secrets['aio_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(aio_username, aio_key, wifi) # Weather Location ID # (to obtain this value, visit # https://io.adafruit.com/services/weather # and copy over the location ID) location_id = 1234 print('Getting weather record from IO...') # Get the specified weather record with current weather # and all available forecast information. forecast = io.receive_weather(location_id) # Get today's forecast current_forecast = forecast['current'] print('It is {0} and {1}*F.'.format(current_forecast['summary'],
esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) """ # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) aio_username = secrets['aio_username'] aio_key = secrets['aio_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(aio_username, aio_key, wifi) # Create a new group print('Creating a new Adafruit IO Group...') sensor_group = io.create_new_group('envsensors', 'a group of environmental sensors') # Add the 'temperature' feed to the group print('Adding feed temperature to group...') io.add_feed_to_group(sensor_group['key'], 'temperature') # Get info from the group print(sensor_group) # Delete the group print('Deleting group...') io.delete_group('envsensors')
esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) """ # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) ADAFRUIT_IO_USER = secrets['adafruit_io_user'] ADAFRUIT_IO_KEY = secrets['adafruit_io_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi) # Weather Location ID # (to obtain this value, visit # https://io.adafruit.com/services/weather # and copy over the location ID) location_id = 1234 print('Getting weather record from IO...') # Get the specified weather record with current weather # and all available forecast information. forecast = io.receive_weather(location_id) # Get today's forecast current_forecast = forecast['current'] print('It is {0} and {1}*F.'.format(current_forecast['summary'],
esp32_ready = digitalio.DigitalInOut(board.ESP_BUSY) esp32_reset = digitalio.DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager( esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) aio_username = secrets['aio_username'] aio_key = secrets['aio_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(aio_username, aio_key, wifi) # Get the weight feed from IO weight_feed = io.get_feed('weight') # initialize the dymo scale units_pin = digitalio.DigitalInOut(board.D3) units_pin.switch_to_output() dymo = adafruit_dymoscale.DYMOScale(board.D4, units_pin) # take a reading of the current time, used for toggling the device out of sleep time_stamp = time.monotonic() while True: try: reading = dymo.weight
esp32_ready = DigitalInOut(board.D10) esp32_reset = DigitalInOut(board.D5) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) """ # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) ADAFRUIT_IO_USER = secrets['adafruit_io_user'] ADAFRUIT_IO_KEY = secrets['adafruit_io_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi) try: # Get the 'light' feed from Adafruit IO light_feed = io.get_feed('light') except AdafruitIO_RequestError: # If no 'light' feed exists, create one light_feed = io.create_new_feed('light') # Set up an analog light sensor on the PyPortal adc = AnalogIn(board.LIGHT) while True: light_value = adc.value print('Light Level: ', light_value) print('Sending to Adafruit IO...')
try: ADAFRUIT_IO_USER = secrets['aio_username'] ADAFRUIT_IO_KEY = secrets['aio_key'] OPEN_WEATHER_KEY = secrets['open_weather_key'] except KeyError: raise KeyError( 'To use this code, you need to include your Adafruit IO username \ and password in a secrets.py file on the CIRCUITPY drive.') # use https://openweathermap.org/find?q= to get city IDs # then set both city IDs below CITY_1_ID = '2641673' CITY_2_ID = '658225' # Create an instance of the Adafruit IO REST client io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi) # init. graphics helper gfx = thermometer_helper.Thermometer_GFX(celsius=True) # init. adt7410 i2c_bus = busio.I2C(board.SCL, board.SDA) adt = adafruit_adt7410.ADT7410(i2c_bus, address=0x48) adt.high_resolution = True # init. the light sensor light_sensor = AnalogIn(board.LIGHT) def set_backlight(val): """Adjust the TFT backlight.
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager( esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) try: ADAFRUIT_IO_USER = secrets['aio_username'] ADAFRUIT_IO_KEY = secrets['aio_key'] except KeyError: raise KeyError( 'To use this code, you need to include your Adafruit IO username \ and password in a secrets.py file on the CIRCUITPY drive.') # Create an instance of the Adafruit IO REST client io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi) # Get the temperature feed from Adafruit IO temperature_feed = io.get_feed('temperature') # init. graphics helper gfx = thermometer_helper.Thermometer_GFX(celsius=False) # init. adt7410 i2c_bus = busio.I2C(board.SCL, board.SDA) adt = adafruit_adt7410.ADT7410(i2c_bus, address=0x48) adt.high_resolution = True # init. the light sensor light_sensor = AnalogIn(board.LIGHT)
esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager( esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) ADAFRUIT_IO_USER = secrets['adafruit_io_user'] ADAFRUIT_IO_KEY = secrets['adafruit_io_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi) try: # Get the 'temperature' feed from Adafruit IO temperature_feed = io.get_feed('temperature') light_feed = io.get_feed('light') except AdafruitIO_RequestError: # If no 'temperature' feed exists, create one temperature_feed = io.create_new_feed('temperature') light_feed = io.create_new_feed('light') # Set up ADT7410 sensor i2c_bus = busio.I2C(board.SCL, board.SDA) adt = adafruit_adt7410.ADT7410(i2c_bus, address=0x48) adt.high_resolution = True
esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager( esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) ADAFRUIT_IO_USER = secrets['aio_username'] ADAFRUIT_IO_KEY = secrets['aio_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi) # create an i2c object i2c = busio.I2C(board.SCL, board.SDA) # instantiate the sensor objects veml = adafruit_veml6075.VEML6075(i2c, integration_time=100) sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c) bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) # change this to match the location's pressure (hPa) at sea level bme280.sea_level_pressure = 1013.25 # init. the graphics helper gfx = weatherstation_helper.WeatherStation_GFX() # init. the ADC
esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) """ # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) ADAFRUIT_IO_USER = secrets['adafruit_io_user'] ADAFRUIT_IO_KEY = secrets['adafruit_io_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi) try: # Get the 'location' feed from Adafruit IO location_feed = io.get_feed('location') except AdafruitIO_RequestError: # If no 'location' feed exists, create one location_feed = io.create_new_feed('location') # Set data data_value = 42 # Set up metadata associated with data_value metadata = {'lat': 40.726190, 'lon': -74.005334, 'ele': -6, 'created_at': None} # Send data and location metadata to the 'location' feed
esp32_ready = DigitalInOut(board.D10) esp32_reset = DigitalInOut(board.D5) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) """ # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) aio_username = secrets['aio_username'] aio_key = secrets['aio_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(aio_username, aio_key, wifi) try: # Get the 'light' feed from Adafruit IO light_feed = io.get_feed('light') except AdafruitIO_RequestError: # If no 'light' feed exists, create one light_feed = io.create_new_feed('light') # Set up an analog light sensor on the PyPortal adc = AnalogIn(board.LIGHT) while True: light_value = adc.value print('Light Level: ', light_value) print('Sending to Adafruit IO...')
esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) """ # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) ADAFRUIT_IO_USER = secrets['adafruit_io_user'] ADAFRUIT_IO_KEY = secrets['adafruit_io_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi) try: # Get the 'digital' feed from Adafruit IO digital_feed = io.get_feed('digital') except AdafruitIO_RequestError: # If no 'digital' feed exists, create one digital_feed = io.create_new_feed('digital') # Set up LED LED = DigitalInOut(board.D13) LED.direction = Direction.OUTPUT while True: # Get data from 'digital' feed print('getting data from IO...')
esp = adafruit_espatcontrol.ESP_ATcontrol(uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=False) wifi = adafruit_espatcontrol_wifimanager.ESPAT_WiFiManager( esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) aio_username = secrets['aio_username'] aio_key = secrets['aio_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(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') # Send random integer values to the feed random_value = randint(0, 50) print('Sending {0} to temperature feed...'.format(random_value)) io.send_data(temperature_feed['key'], random_value) print('Data sent!') # Retrieve data value from the feed
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 """Uncomment below for ItsyBitsy M4""" #status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager( esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) aio_username = secrets['aio_username'] aio_key = secrets['aio_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(aio_username, aio_key, wifi) try: # Get the 'location' feed from Adafruit IO location_feed = io.get_feed('location') except AdafruitIO_RequestError: # If no 'location' feed exists, create one location_feed = io.create_new_feed('location') # Set data data_value = 42 # Set up metadata associated with data_value metadata = {'lat': 40.726190, 'lon': -74.005334, 'ele': -6, 'created_at': None} # Send data and location metadata to the 'location' feed
class BabyClock: def __init__(self): self.splash = displayio.Group(max_size=5) self.bg_group = displayio.Group(max_size=1) board.DISPLAY.auto_brightness = True self.bg_file = None self.texts = [] # touchscreen self.touchscreen = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU, calibration=((5200, 59000),(5800, 57000)), size=(320, 240)) # connecting wifi self.wifi = connect_wifi() # connecting io self.connect_io() # setting local time set_local_time() # getting last feed time from adafruit io self.prev_feed_end_time, self.prev_feed_start_time, self.prev_feed_count = self.get_last_feed_time() board.DISPLAY.show(self.splash) def connect_io(self): print('Connecting adafruit io...') self.io = RESTClient(secrets['aio_username'], secrets['aio_key'], self.wifi) self.feed_start_time_f = self.io.get_feed('feed-start') self.feed_end_time_f = self.io.get_feed('feed-end') self.feed_count_f = self.io.get_feed('feed-count') print('Done.') """Send feed time with count of the day to adafruit io """ def new_feed_time(self): print('Loading history...') received_data = self.io.receive_data(self.feed_time_f['key']) print('Data from temperature feed: ', received_data['value']) """Get from adafruit io last feed time & count """ def get_last_feed_time(self): data = self.io.receive_data(self.feed_start_time_f['key']) prev_feed_start_time = str_to_time(data['value']) data = self.io.receive_data(self.feed_end_time_f['key']) prev_feed_end_time = str_to_time(data['value']) data = self.io.receive_data(self.feed_count_f['key']) prev_feed_count = int(data['value']) return prev_feed_end_time, prev_feed_start_time, prev_feed_count def clear_display(self): # remove all from group while self.bg_group: self.bg_group.pop() while self.splash: self.splash.pop() self.splash.append(self.bg_group) self.texts = [] def set_background(self, image_file): # close if open if self.bg_file: self.bg_file.close() self.bck_file = open(image_file, 'rb') bg = displayio.OnDiskBitmap(self.bck_file) bg_sprite = displayio.TileGrid(bg, pixel_shader=displayio.ColorConverter(), x=0, y=0) self.bg_group.append(bg_sprite) board.DISPLAY.refresh_soon() board.DISPLAY.wait_for_frame() def set_to_info(self, max_glyphs=2): self.dim_down() self.clear_display() self.set_background('back_info.bmp') # hour since, min since, count positions = [(210,45),(250,45),(230,110)] font = bitmap_font.load_font('/fonts/Nunito-Black-17.bdf') #font.load_glyphs(b'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') font.load_glyphs(b'0123456789:/-_,. ') for x, y in positions: text = Label(font, text='', max_glyphs=max_glyphs) text.x = x text.y = y text.color = 0x000000 self.splash.append(text) self.texts.append(text) # : text = Label(font, text=':') text.x = 238 text.y = 43 text.color =0x000000 self.splash.append(text) self.dim_up() def set_to_timer(self): self.dim_down() self.feed_start_time = time.localtime() if self.feed_start_time.tm_mday != self.prev_feed_start_time.tm_mday: self.prev_feed_count = 0 self.clear_display() self.set_background('back_timer.bmp') # hour since, min since, sec_since positions = [(100-50+10,120),(220-50+10,120)] font = bitmap_font.load_font('/fonts/Nunito-Light-75.bdf') #font.load_glyphs(b'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') font.load_glyphs(b'0123456789: ') for x, y in positions: text = Label(font, text='', max_glyphs=2) text.x = x text.y = y text.color = 0xffffff # white self.splash.append(text) self.texts.append(text) # add : between numbers text = Label(font, text=':') text.x = 160-7 text.y = 120-5 text.color = 0xffffff # white self.splash.append(text) self.dim_up() def set_texts(self, texts): for text_area, text in zip(self.texts, texts): text_area.text = str(text) def dim_down(self): board.DISPLAY.auto_brightness = False for i in range(100, -1, -1): # dim down board.DISPLAY.brightness = i/100 time.sleep(0.005) def dim_up(self): board.DISPLAY.auto_brightness = False for i in range(101): # dim down board.DISPLAY.brightness = (i)/100 time.sleep(0.005) board.DISPLAY.auto_brightness = True def send_to_io(self): # feed_start_time # feed_end_time # count # set previous self.prev_feed_end_time = time.localtime() self.prev_feed_start_time = self.feed_start_time self.prev_feed_count += 1 # send to io self.io.send_data(self.feed_start_time_f['key'], time_to_str(self.feed_start_time)) self.io.send_data(self.feed_end_time_f['key'], time_to_str(self.prev_feed_end_time)) self.io.send_data(self.feed_count_f['key'], self.prev_feed_count)
esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) """ # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) ADAFRUIT_IO_USER = secrets['adafruit_io_user'] ADAFRUIT_IO_KEY = secrets['adafruit_io_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi) # Create a new 'circuitpython' feed with a description print('Creating new Adafruit IO feed...') feed = io.create_new_feed('circuitpython', 'a Adafruit IO CircuitPython feed') # List a specified feed print('Retrieving new Adafruit IO feed...') specified_feed = io.get_feed('circuitpython') print(specified_feed) # Delete a specified feed by feed key print('Deleting feed...') io.delete_feed(specified_feed['key']) print('Feed deleted!')
esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) """ # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) aio_username = secrets['aio_username'] aio_key = secrets['aio_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(aio_username, aio_key, wifi) try: # Get the 'digital' feed from Adafruit IO digital_feed = io.get_feed('digital') except AdafruitIO_RequestError: # If no 'digital' feed exists, create one digital_feed = io.create_new_feed('digital') # Set up LED LED = DigitalInOut(board.D13) LED.direction = Direction.OUTPUT while True: # Get data from 'digital' feed print('getting data from IO...')
esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) """ # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) aio_username = secrets['aio_username'] aio_key = secrets['aio_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(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:
esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) """ # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) ADAFRUIT_IO_USER = secrets['adafruit_io_user'] ADAFRUIT_IO_KEY = secrets['adafruit_io_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_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') # Send random integer values to the feed random_value = randint(0, 50) print('Sending {0} to temperature feed...'.format(random_value)) io.send_data(temperature_feed['key'], random_value) print('Data sent!') # Retrieve data value from the feed
esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) """ # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) ADAFRUIT_IO_USER = secrets['adafruit_io_user'] ADAFRUIT_IO_KEY = secrets['adafruit_io_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_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:
esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) """ # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) aio_username = secrets['aio_username'] aio_key = secrets['aio_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(aio_username, aio_key, wifi) # Create a new 'circuitpython' feed with a description print('Creating new Adafruit IO feed...') feed = io.create_new_feed('circuitpython', 'a Adafruit IO CircuitPython feed') # List a specified feed print('Retrieving new Adafruit IO feed...') specified_feed = io.get_feed('circuitpython') print(specified_feed) # Delete a specified feed by feed key print('Deleting feed...') io.delete_feed(specified_feed['key']) print('Feed deleted!')
esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) 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) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) """ # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) ADAFRUIT_IO_USER = secrets['adafruit_io_user'] ADAFRUIT_IO_KEY = secrets['adafruit_io_key'] # Create an instance of the Adafruit IO REST client io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi) # Random Data ID # (to obtain this value, visit # https://io.adafruit.com/services/words # and copy over the location ID) random_data_id = 1234 while True: try: print('Fetching random data from Adafruit IO...') random_data = io.receive_random_data(random_data_id) print('Random Data: ', random_data['value']) print('Data Seed: ', random_data['seed']) print('Waiting 1 minute to fetch new randomized data...') except (ValueError, RuntimeError) as e: