From f29daea7367120a96e1dfa7c51a19b013bbb4df6 Mon Sep 17 00:00:00 2001 From: mperino Date: Sun, 28 Nov 2021 20:28:58 -0800 Subject: [PATCH 1/9] Update esp_atcontrol_simpletest.py Fixed errors with some AT commands not being properly buffered in CP. --- examples/esp_atcontrol_simpletest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/esp_atcontrol_simpletest.py b/examples/esp_atcontrol_simpletest.py index 9c70539..ab66cbf 100644 --- a/examples/esp_atcontrol_simpletest.py +++ b/examples/esp_atcontrol_simpletest.py @@ -24,7 +24,7 @@ TX = board.ESP_TX resetpin = DigitalInOut(board.WIFI_RESET) rtspin = False - uart = busio.UART(TX, RX, baudrate=11520) + uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048) esp_boot = DigitalInOut(board.WIFI_MODE) esp_boot.direction = Direction.OUTPUT esp_boot.value = True From d4c9bdc46f90234ead92b01a3b313b6ea01ec329 Mon Sep 17 00:00:00 2001 From: mperino Date: Mon, 29 Nov 2021 07:01:22 -0800 Subject: [PATCH 2/9] Update esp_atcontrol_aio_post.py Fix for Issue #48 --- examples/esp_atcontrol_aio_post.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/esp_atcontrol_aio_post.py b/examples/esp_atcontrol_aio_post.py index 0696147..27bbd9c 100644 --- a/examples/esp_atcontrol_aio_post.py +++ b/examples/esp_atcontrol_aio_post.py @@ -33,7 +33,7 @@ TX = board.ESP_TX resetpin = DigitalInOut(board.WIFI_RESET) rtspin = False - uart = busio.UART(TX, RX, baudrate=11520) + uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048) esp_boot = DigitalInOut(board.WIFI_MODE) esp_boot.direction = Direction.OUTPUT esp_boot.value = True From 70b99a3b8a85293a040878ed5adf05af6de8c71e Mon Sep 17 00:00:00 2001 From: mperino Date: Mon, 29 Nov 2021 09:29:20 -0800 Subject: [PATCH 3/9] Update esp_atcontrol_cheerlights.py Fixes for #48, added support for Challenger RP2040 Wifi --- examples/esp_atcontrol_cheerlights.py | 48 ++++++++++++++++++--------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/examples/esp_atcontrol_cheerlights.py b/examples/esp_atcontrol_cheerlights.py index 08d3cc1..eeec51c 100644 --- a/examples/esp_atcontrol_cheerlights.py +++ b/examples/esp_atcontrol_cheerlights.py @@ -1,3 +1,4 @@ + # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT @@ -24,21 +25,38 @@ print("WiFi secrets are kept in secrets.py, please add them there!") raise - -# With a Particle Argon -RX = board.ESP_TX -TX = board.ESP_RX -resetpin = DigitalInOut(board.ESP_WIFI_EN) -rtspin = DigitalInOut(board.ESP_CTS) -uart = busio.UART(TX, RX, timeout=0.1) -esp_boot = DigitalInOut(board.ESP_BOOT_MODE) -esp_boot.direction = Direction.OUTPUT -esp_boot.value = True -status_light = None +# Debug Level +# Change the Debug Flag if you have issues with AT commands +debugflag = False + +if board.board_id == "challenger_rp2040_wifi": + RX = board.ESP_RX + TX = board.ESP_TX + resetpin = DigitalInOut(board.WIFI_RESET) + rtspin = False + uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048) + esp_boot = DigitalInOut(board.WIFI_MODE) + esp_boot.direction = Direction.OUTPUT + esp_boot.value = True + status_light = None + pixel_pin = board.NEOPIXEL + num_pixels = 1 +else: + RX = board.ESP_TX + TX = board.ESP_RX + resetpin = DigitalInOut(board.ESP_WIFI_EN) + rtspin = DigitalInOut(board.ESP_CTS) + uart = busio.UART(TX, RX, timeout=0.1) + esp_boot = DigitalInOut(board.ESP_BOOT_MODE) + esp_boot.direction = Direction.OUTPUT + esp_boot.value = True + status_light = None + pixel_pin = board.A1 + num_pixels = 16 print("ESP AT commands") esp = adafruit_espatcontrol.ESP_ATcontrol( - uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=False + uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=debugflag ) wifi = adafruit_espatcontrol_wifimanager.ESPAT_WiFiManager(esp, secrets, status_light) @@ -47,8 +65,8 @@ DATA_LOCATION = ["feeds", 0, "field2"] -# neopixels -pixels = neopixel.NeoPixel(board.A1, 16, brightness=0.3) +# Setup and Clear neopixels +pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3) pixels.fill(0) # we'll save the value in question @@ -77,7 +95,7 @@ green = color >> 8 & 0xFF blue = color & 0xFF gamma_corrected = fancy.gamma_adjust(fancy.CRGB(red, green, blue)).pack() - + print('Setting LED To: G:{0},R:{1},B:{2},Gamma:{3}'.format(green, red, blue, gamma_corrected)) pixels.fill(gamma_corrected) last_value = value response = None From b5558132a05cea543bc462a632c270b711c48e67 Mon Sep 17 00:00:00 2001 From: mperino Date: Mon, 29 Nov 2021 11:15:55 -0800 Subject: [PATCH 4/9] Update esp_atcontrol_countviewer.py Fix for #48, added support for defining RGBW vs. RGB NEOPixels as a VAR, added flag for wether a display is attached, better output formatting. --- examples/esp_atcontrol_countviewer.py | 89 +++++++++++++++++++-------- 1 file changed, 64 insertions(+), 25 deletions(-) diff --git a/examples/esp_atcontrol_countviewer.py b/examples/esp_atcontrol_countviewer.py index 0a75aa8..51056e8 100644 --- a/examples/esp_atcontrol_countviewer.py +++ b/examples/esp_atcontrol_countviewer.py @@ -27,7 +27,8 @@ # CONFIGURATION PLAY_SOUND_ON_CHANGE = False -NEOPIXELS_ON_CHANGE = False +NEOPIXELS_ON_CHANGE = True +DISPLAY_ATTACHED = False TIME_BETWEEN_QUERY = 60 # in seconds # Some data sources and JSON locations to try out @@ -63,17 +64,36 @@ # "screen_names=adafruit" # DATA_LOCATION = [0, "followers_count"] - -# With a Particle Argon -RX = board.ESP_TX -TX = board.ESP_RX -resetpin = DigitalInOut(board.ESP_WIFI_EN) -rtspin = DigitalInOut(board.ESP_CTS) -uart = busio.UART(TX, RX, timeout=0.1) -esp_boot = DigitalInOut(board.ESP_BOOT_MODE) -esp_boot.direction = Direction.OUTPUT -esp_boot.value = True - +# Debug Level +# Change the Debug Flag if you have issues with AT commands +debugflag = False + +if board.board_id == "challenger_rp2040_wifi": + RX = board.ESP_RX + TX = board.ESP_TX + resetpin = DigitalInOut(board.WIFI_RESET) + rtspin = False + uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048) + esp_boot = DigitalInOut(board.WIFI_MODE) + esp_boot.direction = Direction.OUTPUT + esp_boot.value = True + status_light = None + pixel_pin = board.NEOPIXEL + num_pixels = 1 + pixel_type = "RGBW/GRBW" +else: + RX = board.ESP_TX + TX = board.ESP_RX + resetpin = DigitalInOut(board.ESP_WIFI_EN) + rtspin = DigitalInOut(board.ESP_CTS) + uart = busio.UART(TX, RX, timeout=0.1) + esp_boot = DigitalInOut(board.ESP_BOOT_MODE) + esp_boot.direction = Direction.OUTPUT + esp_boot.value = True + status_light = None + pixel_pin = board.A1 + num_pixels = 16 + pixel_type = "RGB/GRB" # Create the connection to the co-processor and reset esp = adafruit_espatcontrol.ESP_ATcontrol( @@ -82,17 +102,20 @@ esp.hard_reset() requests.set_socket(socket, esp) - -# Create the I2C interface. -i2c = busio.I2C(board.SCL, board.SDA) -# Attach a 7 segment display and display -'s so we know its not live yet -display = segments.Seg7x4(i2c) -display.print("----") +# display +if DISPLAY_ATTACHED: + # Create the I2C interface. + i2c = busio.I2C(board.SCL, board.SDA) + # Attach a 7 segment display and display -'s so we know its not live yet + display = segments.Seg7x4(i2c) + display.print("----") # neopixels if NEOPIXELS_ON_CHANGE: - pixels = neopixel.NeoPixel(board.A1, 16, brightness=0.4, pixel_order=(1, 0, 2, 3)) - pixels.fill(0) + pixels = neopixel.NeoPixel( + pixel_pin, num_pixels, brightness=0.4, pixel_order=(1, 0, 2, 3) + ) + pixels.fill(20) # music! if PLAY_SOUND_ON_CHANGE: @@ -111,7 +134,12 @@ def chime_light(): """Light up LEDs and play a tune""" if NEOPIXELS_ON_CHANGE: for i in range(0, 100, 10): - pixels.fill((i, i, i)) + if pixel_type == "RGB/GRB": + pixels.fill((i, i, i)) + elif pixel_type == "RGBW/GRBW": + pixels.fill((i, i, i, i)) + pixels.show() + time.sleep(1) if PLAY_SOUND_ON_CHANGE: with audioio.AudioOut(board.A0) as audio: audio.play(wave) @@ -119,7 +147,13 @@ def chime_light(): pass if NEOPIXELS_ON_CHANGE: for i in range(100, 0, -10): - pixels.fill((i, i, i)) + for i in range(0, 100, 10): + if pixel_type == "RGB/GRB": + pixels.fill((i, i, i)) + elif pixel_type == "RGBW/GRBW": + pixels.fill((i, i, i, i)) + pixels.show() + time.sleep(1) pixels.fill(0) @@ -148,8 +182,11 @@ def chime_light(): value = value[x] if not value: continue - print(times, the_time, "value:", value) - display.print(int(value)) + print("Times:{0}. The Time:{1}. Value: {2}".format(times, the_time, value)) + if DISPLAY_ATTACHED: + display.print(int(value)) + else: + print("INT Value:{0}".format(int(value))) if last_value != value: chime_light() # animate the neopixels @@ -159,5 +196,7 @@ def chime_light(): # normally we wouldn't have to do this, but we get bad fragments r = value = None gc.collect() - print(gc.mem_free()) # pylint: disable=no-member + print("GC MEM:{0}".format(gc.mem_free())) # pylint: disable=no-member + print("Sleeping for: {0} Seconds".format(TIME_BETWEEN_QUERY)) time.sleep(TIME_BETWEEN_QUERY) + From 85a1f074184b73e82def6a5616502249d91f4e47 Mon Sep 17 00:00:00 2001 From: mperino Date: Mon, 29 Nov 2021 11:29:25 -0800 Subject: [PATCH 5/9] Update esp_atcontrol_localtime.py Added support for Challenger RP2040 WiFI, added a setting for the sleep between Polling, added a Print statement when it is sleeping and for how long. --- examples/esp_atcontrol_localtime.py | 46 ++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/examples/esp_atcontrol_localtime.py b/examples/esp_atcontrol_localtime.py index ba7bc1c..d553831 100644 --- a/examples/esp_atcontrol_localtime.py +++ b/examples/esp_atcontrol_localtime.py @@ -21,22 +21,38 @@ print("WiFi secrets are kept in secrets.py, please add them there!") raise - -# With a Particle Argon -RX = board.ESP_TX -TX = board.ESP_RX -resetpin = DigitalInOut(board.ESP_WIFI_EN) -rtspin = DigitalInOut(board.ESP_CTS) -uart = busio.UART(TX, RX, timeout=0.1) -esp_boot = DigitalInOut(board.ESP_BOOT_MODE) -esp_boot.direction = Direction.OUTPUT -esp_boot.value = True -status_light = None - +# Debug Level +# Change the Debug Flag if you have issues with AT commands +debugflag = False + +# How Long to sleep between polling +sleep_duration = 5 + +if board.board_id == "challenger_rp2040_wifi": + RX = board.ESP_RX + TX = board.ESP_TX + resetpin = DigitalInOut(board.WIFI_RESET) + rtspin = False + uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048) + esp_boot = DigitalInOut(board.WIFI_MODE) + esp_boot.direction = Direction.OUTPUT + esp_boot.value = True + status_light = None + +else: + RX = board.ESP_TX + TX = board.ESP_RX + resetpin = DigitalInOut(board.ESP_WIFI_EN) + rtspin = DigitalInOut(board.ESP_CTS) + uart = busio.UART(TX, RX, timeout=0.1) + esp_boot = DigitalInOut(board.ESP_BOOT_MODE) + esp_boot.direction = Direction.OUTPUT + esp_boot.value = True + status_light = None print("ESP AT commands") esp = adafruit_espatcontrol.ESP_ATcontrol( - uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=False + uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=debugflag ) wifi = adafruit_espatcontrol_wifimanager.ESPAT_WiFiManager(esp, secrets, status_light) @@ -78,4 +94,6 @@ while True: print(time.localtime()) - time.sleep(1) + print("Sleeping for: {0} Seconds".format(sleep_duration)) + time.sleep(sleep_duration) + From 0786a08c87b17a506c5b3cc142b32910cd64dc65 Mon Sep 17 00:00:00 2001 From: mperino Date: Mon, 29 Nov 2021 11:41:48 -0800 Subject: [PATCH 6/9] Update esp_atcontrol_webclient.py Added support for Challenger RP2040, added a variable for setting the Time Between Queries, and print when it sleeps.. --- examples/esp_atcontrol_webclient.py | 40 ++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/examples/esp_atcontrol_webclient.py b/examples/esp_atcontrol_webclient.py index 68e05f5..da50e7f 100644 --- a/examples/esp_atcontrol_webclient.py +++ b/examples/esp_atcontrol_webclient.py @@ -18,21 +18,37 @@ print("WiFi secrets are kept in secrets.py, please add them there!") raise +# Debug Level +# Change the Debug Flag if you have issues with AT commands +debugflag = False -# With a Particle Argon -RX = board.ESP_TX -TX = board.ESP_RX -resetpin = DigitalInOut(board.ESP_WIFI_EN) -rtspin = DigitalInOut(board.ESP_CTS) -uart = busio.UART(TX, RX, timeout=0.1) -esp_boot = DigitalInOut(board.ESP_BOOT_MODE) -esp_boot.direction = Direction.OUTPUT -esp_boot.value = True +# How long between queries +TIME_BETWEEN_QUERY = 60 # in seconds +if board.board_id == "challenger_rp2040_wifi": + RX = board.ESP_RX + TX = board.ESP_TX + resetpin = DigitalInOut(board.WIFI_RESET) + rtspin = False + uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048) + esp_boot = DigitalInOut(board.WIFI_MODE) + esp_boot.direction = Direction.OUTPUT + esp_boot.value = True + status_light = None +else: + RX = board.ESP_TX + TX = board.ESP_RX + resetpin = DigitalInOut(board.ESP_WIFI_EN) + rtspin = DigitalInOut(board.ESP_CTS) + uart = busio.UART(TX, RX, timeout=0.1) + esp_boot = DigitalInOut(board.ESP_BOOT_MODE) + esp_boot.direction = Direction.OUTPUT + esp_boot.value = True + status_light = None print("ESP AT commands") esp = adafruit_espatcontrol.ESP_ATcontrol( - uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=False + uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=debugflag ) URL = "http://wifitest.adafruit.com/testwifi/index.html" @@ -57,8 +73,8 @@ print("Content size:", r.headers["content-length"]) print("Encoding:", r.encoding) print("Text:", r.text) - - time.sleep(60) + print("Sleeping for: {0} Seconds".format(TIME_BETWEEN_QUERY)) + time.sleep(TIME_BETWEEN_QUERY) except (ValueError, RuntimeError, adafruit_espatcontrol.OKError) as e: print("Failed to get data, retrying\n", e) continue From bc8f50243ec28233de3edba566940f44bfc7f2e2 Mon Sep 17 00:00:00 2001 From: mperino Date: Mon, 29 Nov 2021 12:02:33 -0800 Subject: [PATCH 7/9] Black reformatting --- examples/esp_atcontrol_cheerlights.py | 7 +++++-- examples/esp_atcontrol_countviewer.py | 1 - examples/esp_atcontrol_localtime.py | 1 - 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/esp_atcontrol_cheerlights.py b/examples/esp_atcontrol_cheerlights.py index eeec51c..d123176 100644 --- a/examples/esp_atcontrol_cheerlights.py +++ b/examples/esp_atcontrol_cheerlights.py @@ -1,4 +1,3 @@ - # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT @@ -95,7 +94,11 @@ green = color >> 8 & 0xFF blue = color & 0xFF gamma_corrected = fancy.gamma_adjust(fancy.CRGB(red, green, blue)).pack() - print('Setting LED To: G:{0},R:{1},B:{2},Gamma:{3}'.format(green, red, blue, gamma_corrected)) + print( + "Setting LED To: G:{0},R:{1},B:{2},Gamma:{3}".format( + green, red, blue, gamma_corrected + ) + ) pixels.fill(gamma_corrected) last_value = value response = None diff --git a/examples/esp_atcontrol_countviewer.py b/examples/esp_atcontrol_countviewer.py index 51056e8..d26db06 100644 --- a/examples/esp_atcontrol_countviewer.py +++ b/examples/esp_atcontrol_countviewer.py @@ -199,4 +199,3 @@ def chime_light(): print("GC MEM:{0}".format(gc.mem_free())) # pylint: disable=no-member print("Sleeping for: {0} Seconds".format(TIME_BETWEEN_QUERY)) time.sleep(TIME_BETWEEN_QUERY) - diff --git a/examples/esp_atcontrol_localtime.py b/examples/esp_atcontrol_localtime.py index d553831..7a23a01 100644 --- a/examples/esp_atcontrol_localtime.py +++ b/examples/esp_atcontrol_localtime.py @@ -96,4 +96,3 @@ print(time.localtime()) print("Sleeping for: {0} Seconds".format(sleep_duration)) time.sleep(sleep_duration) - From a22be3affe57d042565ed37c29e85bcba280241d Mon Sep 17 00:00:00 2001 From: mperino Date: Mon, 29 Nov 2021 12:21:21 -0800 Subject: [PATCH 8/9] Update esp_atcontrol_countviewer.py bad loop fixed --- examples/esp_atcontrol_countviewer.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/esp_atcontrol_countviewer.py b/examples/esp_atcontrol_countviewer.py index d26db06..dbf1a49 100644 --- a/examples/esp_atcontrol_countviewer.py +++ b/examples/esp_atcontrol_countviewer.py @@ -147,10 +147,9 @@ def chime_light(): pass if NEOPIXELS_ON_CHANGE: for i in range(100, 0, -10): - for i in range(0, 100, 10): - if pixel_type == "RGB/GRB": - pixels.fill((i, i, i)) - elif pixel_type == "RGBW/GRBW": + if pixel_type == "RGB/GRB": + pixels.fill((i, i, i)) + elif pixel_type == "RGBW/GRBW": pixels.fill((i, i, i, i)) pixels.show() time.sleep(1) From 68fac389f7dd884fd19d4c0110f87e5c5a6f9950 Mon Sep 17 00:00:00 2001 From: mperino Date: Mon, 29 Nov 2021 12:34:42 -0800 Subject: [PATCH 9/9] Loop Fixed --- examples/esp_atcontrol_countviewer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/esp_atcontrol_countviewer.py b/examples/esp_atcontrol_countviewer.py index dbf1a49..671fb4c 100644 --- a/examples/esp_atcontrol_countviewer.py +++ b/examples/esp_atcontrol_countviewer.py @@ -150,7 +150,7 @@ def chime_light(): if pixel_type == "RGB/GRB": pixels.fill((i, i, i)) elif pixel_type == "RGBW/GRBW": - pixels.fill((i, i, i, i)) + pixels.fill((i, i, i, i)) pixels.show() time.sleep(1) pixels.fill(0)