Detecting LED vs. RGB LED #10503
Replies: 6 comments 23 replies
-
You could try to set Pin7 to INPUT mode and read back the input value. Maybe there is a difference between the two boards. but chances are low. So the only choice would be to put some kind of configuration file on the board, telling which led to use, or use two different small python scripts to lite up the LED. |
Beta Was this translation helpful? Give feedback.
-
Is the board assembled over a baseboard? If affirmative, depending on what is connected to pins A0 to A5, you could try detecting the board type, as the order of these pins is different. Or you could add some pull-up/down resistor to one of the pins on the boards with the newest module and detecting the level by setting the pin's internal pull-down/up. |
Beta Was this translation helpful? Give feedback.
-
You could use a simple DIP-Switch to set the hardware-configuration. |
Beta Was this translation helpful? Give feedback.
-
@dmpayton Wow, that's quite a frustrating change! You would need to test this, but perhaps you could just assume that it's the 2.x hardware and drive the neopixel, but then leave the pin in the state suitable for the 1.x hardware. i.e. When you want to change the LED state, send the appropriate WS2812 signal (using the I'm pretty sure the WS2812 won't care about the state of the pin being left high or low. |
Beta Was this translation helpful? Give feedback.
-
Thank you all for the suggestions, there are definitely some things I want to try in a future hardware iteration! @mattytrentini was kind enough to respond to me on Twitter, suggesting to set the pin to output high, switch to input, and time the voltage drop. Here's my implementation: def led_voltage_drop():
pin = machine.Pin(7, machine.Pin.OUT)
pin.on()
pin.init(machine.Pin.IN)
start = time.ticks_us()
while pin.value() != 0:
continue
return time.ticks_diff(time.ticks_us(), start) Open to any suggestions, but here are the results so far:
There's definitely an overall difference between the two, and the numbers appear consistent across a few boards of each version that I've tried. Huzzah! It should now be just a simple check to get the version: def board_version():
# 8,000 is roughly in the middle between the two LEDs
if led_voltage_drop() < 8000:
# Usually < 3,000
return '2.1.0'
# Usually > 10,000
return '1.0.0' Does this seem like a reasonable solution and implementation? I'm newer to EE (my background is mostly web dev), so I don't know if there are any other considerations that should be taken into account here. Is there anything else that might affect the voltage drop duration, causing my code to set the wrong version? |
Beta Was this translation helpful? Give feedback.
-
See below. I used a SAMD51 board. Pin D13 has a simple LED on the board. So the script fills the neopixels, blinks 3 times the LED, clears the neopixels, blinks the LED three times, ......
|
Beta Was this translation helpful? Give feedback.
-
Hey MicroPython folks! I'm in a bit of a pickle of a jam, and could use some help.
I've been working on building IOT air quality monitors with a local environmental nonprofit. We've been using the Wemos C3 Mini (v1.0.0) with the latest MicroPython 1.19.1, and we've distributed about 50 of 'em in Central California.
Wemos recently started shipping a new version of this board, v2.1.0, which is fine, except for the LED differences – the 1.0.0 boards shipped with a single blue LED, while the 2.1.0 boards have an RGB LED, and both boards have the LEDs on pin 7. There's not a lot that's changed in the schematics, other than the antenna and the LED.
On the v1.0.0 boards, I was using the blue LED as a general system status indicator, pulsing and blinking for various tasks and errors. I'm really hoping to be able to use the RGB LED on the newer boards to also indicate air quality at-a-glance.
My code needs to support both versions of the board because OTA updates pull from the same git repo and it feels crazy to run separate builds just to control an LED.
I was hoping to find a way to differentiate between the boards – a version number or something, somewhere in
sys
,os.uname
,esp32
, etc – but have come up short. I was wondering if there's some way to, I dunno, inspect the pin to see how it behaves so I can determine the board version and use the right led driver at runtime?I'm a fair bit stuck on this right now, so any tips, ideas, suggestions or general advice would be super appreciated! Thank you!
Beta Was this translation helpful? Give feedback.
All reactions