Skip to content

Commit b555813

Browse files
authored
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.
1 parent 70b99a3 commit b555813

File tree

1 file changed

+64
-25
lines changed

1 file changed

+64
-25
lines changed

examples/esp_atcontrol_countviewer.py

Lines changed: 64 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,26 @@ 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+
for i in range(0, 100, 10):
151+
if pixel_type == "RGB/GRB":
152+
pixels.fill((i, i, i))
153+
elif pixel_type == "RGBW/GRBW":
154+
pixels.fill((i, i, i, i))
155+
pixels.show()
156+
time.sleep(1)
123157
pixels.fill(0)
124158

125159

@@ -148,8 +182,11 @@ def chime_light():
148182
value = value[x]
149183
if not value:
150184
continue
151-
print(times, the_time, "value:", value)
152-
display.print(int(value))
185+
print("Times:{0}. The Time:{1}. Value: {2}".format(times, the_time, value))
186+
if DISPLAY_ATTACHED:
187+
display.print(int(value))
188+
else:
189+
print("INT Value:{0}".format(int(value)))
153190

154191
if last_value != value:
155192
chime_light() # animate the neopixels
@@ -159,5 +196,7 @@ def chime_light():
159196
# normally we wouldn't have to do this, but we get bad fragments
160197
r = value = None
161198
gc.collect()
162-
print(gc.mem_free()) # pylint: disable=no-member
199+
print("GC MEM:{0}".format(gc.mem_free())) # pylint: disable=no-member
200+
print("Sleeping for: {0} Seconds".format(TIME_BETWEEN_QUERY))
163201
time.sleep(TIME_BETWEEN_QUERY)
202+

0 commit comments

Comments
 (0)