Page 1 of 1
led.off() turns it on and vise versa??
Posted: Fri Jan 31, 2020 8:14 pm
by MicroNinja
Why is the led turning off by the on() function? My Led (on board) is reacting the oposite to the function call.
led.on() and led.value(1) is actually turning it off whereas 0 or off turns it on
Code: Select all
from machine import Pin
LED_PIN = 2
LED_PIN, Pin.OUT)
led.on()
Am I doing something wrong?
Re: led.off() turns it on and vise versa??
Posted: Fri Jan 31, 2020 8:26 pm
by kevinkk525
Because the leds on those boards might be low active, therefore active when the pin is pulled to ground.
Re: led.off() turns it on and vise versa??
Posted: Fri Jan 31, 2020 8:37 pm
by emtee
kevinkk525 is most likely right in that the board you are using has an active low output for the onboard LED.
I am using a NodeMCU board with an active low LED. I was experiencing the LED going on when issuing a led.off() command and turning off when issuing a led.on() command.
The trick is in the initial configuration. I am using v1.10 and it allows the following configuration:
Code: Select all
class BLINK():
def __init__(self, pin_num=2):
self._pin_num = pin_num
# Connect to the LED pin
# NOTE - the on board LED uses an inverted output
self._led_pin = Pin(pin_num, Pin.OUT)
self._led = Signal(self._led_pin, invert=True)
Note the
invert=True in the Signal configuration. This should give the expected behaviour, i.e. LED turning on with led.on() and off with led.off().
Re: led.off() turns it on and vise versa??
Posted: Fri Jan 31, 2020 9:01 pm
by MicroNinja
Ah thank you guys that make sense now =)
I might be running an older version then. I got
Code: Select all
TypeError: extra keyword arguments given
But thats good enough, was just confused to why it happend!
Actually that was from the Led class which does not have invert argument
Code: Select all
object <class 'Pin'> is of type type
init -- <function>
value -- <function>
off -- <function>
on -- <function>
irq -- <function>
IN -- 0
OUT -- 1
OPEN_DRAIN -- 2
PULL_UP -- 1
IRQ_RISING -- 1
IRQ_FALLING -- 2
>>>
Re: led.off() turns it on and vise versa??
Posted: Mon Feb 10, 2020 3:09 am
by bitninja
Yeah this caught my attention a while back... so I had to look it up...
It's because they wire the LED so that the positive side is connected to power and the negative (drain) is connected to the output pin... so when it goes low (or to GROUND) the LED will light. It's because they can pass more current through the LED than if they wired the positive side to the output pin. The chip can only produce a small amount of current on it's outputs... apparently.
Didn't know about the Invert keyword though. Cool.