Skip to content

Commit 246ed29

Browse files
authored
Merge pull request #50 from mperino/main
Fixes for "in Adafruit_CircuitPython_ESP_ATcontrol AT+CWLAP Does not return OK #48"
2 parents ccc5929 + 68fac38 commit 246ed29

6 files changed

+159
-68
lines changed

examples/esp_atcontrol_aio_post.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
TX = board.ESP_TX
3434
resetpin = DigitalInOut(board.WIFI_RESET)
3535
rtspin = False
36-
uart = busio.UART(TX, RX, baudrate=11520)
36+
uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048)
3737
esp_boot = DigitalInOut(board.WIFI_MODE)
3838
esp_boot.direction = Direction.OUTPUT
3939
esp_boot.value = True

examples/esp_atcontrol_cheerlights.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,38 @@
2424
print("WiFi secrets are kept in secrets.py, please add them there!")
2525
raise
2626

27-
28-
# With a Particle Argon
29-
RX = board.ESP_TX
30-
TX = board.ESP_RX
31-
resetpin = DigitalInOut(board.ESP_WIFI_EN)
32-
rtspin = DigitalInOut(board.ESP_CTS)
33-
uart = busio.UART(TX, RX, timeout=0.1)
34-
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
35-
esp_boot.direction = Direction.OUTPUT
36-
esp_boot.value = True
37-
status_light = None
27+
# Debug Level
28+
# Change the Debug Flag if you have issues with AT commands
29+
debugflag = False
30+
31+
if board.board_id == "challenger_rp2040_wifi":
32+
RX = board.ESP_RX
33+
TX = board.ESP_TX
34+
resetpin = DigitalInOut(board.WIFI_RESET)
35+
rtspin = False
36+
uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048)
37+
esp_boot = DigitalInOut(board.WIFI_MODE)
38+
esp_boot.direction = Direction.OUTPUT
39+
esp_boot.value = True
40+
status_light = None
41+
pixel_pin = board.NEOPIXEL
42+
num_pixels = 1
43+
else:
44+
RX = board.ESP_TX
45+
TX = board.ESP_RX
46+
resetpin = DigitalInOut(board.ESP_WIFI_EN)
47+
rtspin = DigitalInOut(board.ESP_CTS)
48+
uart = busio.UART(TX, RX, timeout=0.1)
49+
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
50+
esp_boot.direction = Direction.OUTPUT
51+
esp_boot.value = True
52+
status_light = None
53+
pixel_pin = board.A1
54+
num_pixels = 16
3855

3956
print("ESP AT commands")
4057
esp = adafruit_espatcontrol.ESP_ATcontrol(
41-
uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=False
58+
uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=debugflag
4259
)
4360
wifi = adafruit_espatcontrol_wifimanager.ESPAT_WiFiManager(esp, secrets, status_light)
4461

@@ -47,8 +64,8 @@
4764
DATA_LOCATION = ["feeds", 0, "field2"]
4865

4966

50-
# neopixels
51-
pixels = neopixel.NeoPixel(board.A1, 16, brightness=0.3)
67+
# Setup and Clear neopixels
68+
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3)
5269
pixels.fill(0)
5370

5471
# we'll save the value in question
@@ -77,7 +94,11 @@
7794
green = color >> 8 & 0xFF
7895
blue = color & 0xFF
7996
gamma_corrected = fancy.gamma_adjust(fancy.CRGB(red, green, blue)).pack()
80-
97+
print(
98+
"Setting LED To: G:{0},R:{1},B:{2},Gamma:{3}".format(
99+
green, red, blue, gamma_corrected
100+
)
101+
)
81102
pixels.fill(gamma_corrected)
82103
last_value = value
83104
response = None

examples/esp_atcontrol_countviewer.py

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
# CONFIGURATION
2929
PLAY_SOUND_ON_CHANGE = False
30-
NEOPIXELS_ON_CHANGE = False
30+
NEOPIXELS_ON_CHANGE = True
31+
DISPLAY_ATTACHED = False
3132
TIME_BETWEEN_QUERY = 60 # in seconds
3233

3334
# Some data sources and JSON locations to try out
@@ -63,17 +64,36 @@
6364
# "screen_names=adafruit"
6465
# DATA_LOCATION = [0, "followers_count"]
6566

66-
67-
# With a Particle Argon
68-
RX = board.ESP_TX
69-
TX = board.ESP_RX
70-
resetpin = DigitalInOut(board.ESP_WIFI_EN)
71-
rtspin = DigitalInOut(board.ESP_CTS)
72-
uart = busio.UART(TX, RX, timeout=0.1)
73-
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
74-
esp_boot.direction = Direction.OUTPUT
75-
esp_boot.value = True
76-
67+
# Debug Level
68+
# Change the Debug Flag if you have issues with AT commands
69+
debugflag = False
70+
71+
if board.board_id == "challenger_rp2040_wifi":
72+
RX = board.ESP_RX
73+
TX = board.ESP_TX
74+
resetpin = DigitalInOut(board.WIFI_RESET)
75+
rtspin = False
76+
uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048)
77+
esp_boot = DigitalInOut(board.WIFI_MODE)
78+
esp_boot.direction = Direction.OUTPUT
79+
esp_boot.value = True
80+
status_light = None
81+
pixel_pin = board.NEOPIXEL
82+
num_pixels = 1
83+
pixel_type = "RGBW/GRBW"
84+
else:
85+
RX = board.ESP_TX
86+
TX = board.ESP_RX
87+
resetpin = DigitalInOut(board.ESP_WIFI_EN)
88+
rtspin = DigitalInOut(board.ESP_CTS)
89+
uart = busio.UART(TX, RX, timeout=0.1)
90+
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
91+
esp_boot.direction = Direction.OUTPUT
92+
esp_boot.value = True
93+
status_light = None
94+
pixel_pin = board.A1
95+
num_pixels = 16
96+
pixel_type = "RGB/GRB"
7797

7898
# Create the connection to the co-processor and reset
7999
esp = adafruit_espatcontrol.ESP_ATcontrol(
@@ -82,17 +102,20 @@
82102
esp.hard_reset()
83103

84104
requests.set_socket(socket, esp)
85-
86-
# Create the I2C interface.
87-
i2c = busio.I2C(board.SCL, board.SDA)
88-
# Attach a 7 segment display and display -'s so we know its not live yet
89-
display = segments.Seg7x4(i2c)
90-
display.print("----")
105+
# display
106+
if DISPLAY_ATTACHED:
107+
# Create the I2C interface.
108+
i2c = busio.I2C(board.SCL, board.SDA)
109+
# Attach a 7 segment display and display -'s so we know its not live yet
110+
display = segments.Seg7x4(i2c)
111+
display.print("----")
91112

92113
# neopixels
93114
if NEOPIXELS_ON_CHANGE:
94-
pixels = neopixel.NeoPixel(board.A1, 16, brightness=0.4, pixel_order=(1, 0, 2, 3))
95-
pixels.fill(0)
115+
pixels = neopixel.NeoPixel(
116+
pixel_pin, num_pixels, brightness=0.4, pixel_order=(1, 0, 2, 3)
117+
)
118+
pixels.fill(20)
96119

97120
# music!
98121
if PLAY_SOUND_ON_CHANGE:
@@ -111,15 +134,25 @@ def chime_light():
111134
"""Light up LEDs and play a tune"""
112135
if NEOPIXELS_ON_CHANGE:
113136
for i in range(0, 100, 10):
114-
pixels.fill((i, i, i))
137+
if pixel_type == "RGB/GRB":
138+
pixels.fill((i, i, i))
139+
elif pixel_type == "RGBW/GRBW":
140+
pixels.fill((i, i, i, i))
141+
pixels.show()
142+
time.sleep(1)
115143
if PLAY_SOUND_ON_CHANGE:
116144
with audioio.AudioOut(board.A0) as audio:
117145
audio.play(wave)
118146
while audio.playing:
119147
pass
120148
if NEOPIXELS_ON_CHANGE:
121149
for i in range(100, 0, -10):
122-
pixels.fill((i, i, i))
150+
if pixel_type == "RGB/GRB":
151+
pixels.fill((i, i, i))
152+
elif pixel_type == "RGBW/GRBW":
153+
pixels.fill((i, i, i, i))
154+
pixels.show()
155+
time.sleep(1)
123156
pixels.fill(0)
124157

125158

@@ -148,8 +181,11 @@ def chime_light():
148181
value = value[x]
149182
if not value:
150183
continue
151-
print(times, the_time, "value:", value)
152-
display.print(int(value))
184+
print("Times:{0}. The Time:{1}. Value: {2}".format(times, the_time, value))
185+
if DISPLAY_ATTACHED:
186+
display.print(int(value))
187+
else:
188+
print("INT Value:{0}".format(int(value)))
153189

154190
if last_value != value:
155191
chime_light() # animate the neopixels
@@ -159,5 +195,6 @@ def chime_light():
159195
# normally we wouldn't have to do this, but we get bad fragments
160196
r = value = None
161197
gc.collect()
162-
print(gc.mem_free()) # pylint: disable=no-member
198+
print("GC MEM:{0}".format(gc.mem_free())) # pylint: disable=no-member
199+
print("Sleeping for: {0} Seconds".format(TIME_BETWEEN_QUERY))
163200
time.sleep(TIME_BETWEEN_QUERY)

examples/esp_atcontrol_localtime.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,38 @@
2121
print("WiFi secrets are kept in secrets.py, please add them there!")
2222
raise
2323

24-
25-
# With a Particle Argon
26-
RX = board.ESP_TX
27-
TX = board.ESP_RX
28-
resetpin = DigitalInOut(board.ESP_WIFI_EN)
29-
rtspin = DigitalInOut(board.ESP_CTS)
30-
uart = busio.UART(TX, RX, timeout=0.1)
31-
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
32-
esp_boot.direction = Direction.OUTPUT
33-
esp_boot.value = True
34-
status_light = None
35-
24+
# Debug Level
25+
# Change the Debug Flag if you have issues with AT commands
26+
debugflag = False
27+
28+
# How Long to sleep between polling
29+
sleep_duration = 5
30+
31+
if board.board_id == "challenger_rp2040_wifi":
32+
RX = board.ESP_RX
33+
TX = board.ESP_TX
34+
resetpin = DigitalInOut(board.WIFI_RESET)
35+
rtspin = False
36+
uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048)
37+
esp_boot = DigitalInOut(board.WIFI_MODE)
38+
esp_boot.direction = Direction.OUTPUT
39+
esp_boot.value = True
40+
status_light = None
41+
42+
else:
43+
RX = board.ESP_TX
44+
TX = board.ESP_RX
45+
resetpin = DigitalInOut(board.ESP_WIFI_EN)
46+
rtspin = DigitalInOut(board.ESP_CTS)
47+
uart = busio.UART(TX, RX, timeout=0.1)
48+
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
49+
esp_boot.direction = Direction.OUTPUT
50+
esp_boot.value = True
51+
status_light = None
3652

3753
print("ESP AT commands")
3854
esp = adafruit_espatcontrol.ESP_ATcontrol(
39-
uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=False
55+
uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=debugflag
4056
)
4157
wifi = adafruit_espatcontrol_wifimanager.ESPAT_WiFiManager(esp, secrets, status_light)
4258

@@ -78,4 +94,5 @@
7894

7995
while True:
8096
print(time.localtime())
81-
time.sleep(1)
97+
print("Sleeping for: {0} Seconds".format(sleep_duration))
98+
time.sleep(sleep_duration)

examples/esp_atcontrol_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
TX = board.ESP_TX
2525
resetpin = DigitalInOut(board.WIFI_RESET)
2626
rtspin = False
27-
uart = busio.UART(TX, RX, baudrate=11520)
27+
uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048)
2828
esp_boot = DigitalInOut(board.WIFI_MODE)
2929
esp_boot.direction = Direction.OUTPUT
3030
esp_boot.value = True

examples/esp_atcontrol_webclient.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,37 @@
1818
print("WiFi secrets are kept in secrets.py, please add them there!")
1919
raise
2020

21+
# Debug Level
22+
# Change the Debug Flag if you have issues with AT commands
23+
debugflag = False
2124

22-
# With a Particle Argon
23-
RX = board.ESP_TX
24-
TX = board.ESP_RX
25-
resetpin = DigitalInOut(board.ESP_WIFI_EN)
26-
rtspin = DigitalInOut(board.ESP_CTS)
27-
uart = busio.UART(TX, RX, timeout=0.1)
28-
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
29-
esp_boot.direction = Direction.OUTPUT
30-
esp_boot.value = True
25+
# How long between queries
26+
TIME_BETWEEN_QUERY = 60 # in seconds
3127

28+
if board.board_id == "challenger_rp2040_wifi":
29+
RX = board.ESP_RX
30+
TX = board.ESP_TX
31+
resetpin = DigitalInOut(board.WIFI_RESET)
32+
rtspin = False
33+
uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048)
34+
esp_boot = DigitalInOut(board.WIFI_MODE)
35+
esp_boot.direction = Direction.OUTPUT
36+
esp_boot.value = True
37+
status_light = None
38+
else:
39+
RX = board.ESP_TX
40+
TX = board.ESP_RX
41+
resetpin = DigitalInOut(board.ESP_WIFI_EN)
42+
rtspin = DigitalInOut(board.ESP_CTS)
43+
uart = busio.UART(TX, RX, timeout=0.1)
44+
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
45+
esp_boot.direction = Direction.OUTPUT
46+
esp_boot.value = True
47+
status_light = None
3248

3349
print("ESP AT commands")
3450
esp = adafruit_espatcontrol.ESP_ATcontrol(
35-
uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=False
51+
uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=debugflag
3652
)
3753

3854
URL = "http://wifitest.adafruit.com/testwifi/index.html"
@@ -57,8 +73,8 @@
5773
print("Content size:", r.headers["content-length"])
5874
print("Encoding:", r.encoding)
5975
print("Text:", r.text)
60-
61-
time.sleep(60)
76+
print("Sleeping for: {0} Seconds".format(TIME_BETWEEN_QUERY))
77+
time.sleep(TIME_BETWEEN_QUERY)
6278
except (ValueError, RuntimeError, adafruit_espatcontrol.OKError) as e:
6379
print("Failed to get data, retrying\n", e)
6480
continue

0 commit comments

Comments
 (0)