Hello
I am just beginning. Made it as far as the first WebServer-Control Outputs.
And I am puzzled:
Copied and uploaded both the boot.py and the main.py code from github and saved unchanged to the ESP8266 I am using.
RESET my 8266 (RST button) – the onboard LED turns on.
Website loads OK across my LAN.
But when I click the ON button the LED turns OFF and off when I click the ON button.
By reversing the values as below:
if led1_on == 6:
print(‘LED ON’)
led1.value(0)
if led1_off == 6:
print(‘LED OFF’)
led1.value(1)
I get the desired result.
To check out my thinking I re-installed the firmware then ran the following direct from the Editor:
FIRSTLY
from machine import Pin
led1 = Pin(2, Pin.OUT)
led1.value(1)
Which turns the onboard LED off
Then
from machine import Pin
led1 = Pin(2, Pin.OUT)
led1.value(0)
Which turns the onboard LED on.
Completely the opposite of what I have understood to date.
As my LIMITED understanding has been that a value(1) puts a pin High -ie On
And (0) puts it Low.
Have I got this all wrong?
Pi4 Raspian Linux 10 (buster)
Thonny 3.3.3
Hi Steve,
in the ESP the LED is always connected to +5V so you need to put its other contact (cathode) to GND to make it lit!
For this reason when you set its GPIO pin to 0 (LOW) you are switching it on an viceversa.
Generally speaking you must set to LOW/HIGH a GPIO depending on the voltage polarity you are switching on/off. There’s no “absolute” ON and OFF!
Hi Steve.
Enzo is right.
For the ESP8266, the on-board LED works with “inverted logic”. Send HIGH to turn it off and LOW to turn it on.
Regards,
Sara
Enzo: Thank you
Sara: Thank you too – Did I miss something in the book that mentioned this? If not perhaps worth flagging up for a change in the next edition. If only to stop Noobs scratching their heads. I also noted some differences in the code between the book and github.
Hi.
I’m sorry. That is not mentioned in the eBook. We should definitely add a note about that in the next update.
Sometimes the eBook and the github code are slightly different. This happens when we make some changes to the code (to correct typos or improvements) and a new eBook version wasn’t yet released. The github code is always the most up to date.
Those changes are taken into account whenever there’s an update. However, sometimes it may be the case that I forgot to update something. If you find some typos or errors, it would be great if you shared that with us, so that we can improve the eBook. Thanks.
Regards,
Sara
This is somewhat basic electronics and you should always look at the data sheet of a product that you buy.
There is generally a reason why a component is active low or high. It’s probable in this case due to the source and/or sink current available. Please read about this so you have an understanding of what it means.