• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Fundemental Undertanding of Pin/Led values

Q&A Forum › Category: ESP8266 › Fundemental Undertanding of Pin/Led values
0 Vote Up Vote Down
Steve asked 4 years ago

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

5 Answers
0 Vote Up Vote Down
Enzo Pontone answered 4 years ago

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!

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

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

0 Vote Up Vote Down
Steve answered 4 years ago

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.

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

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

0 Vote Up Vote Down
Steve Mercer answered 4 years ago

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.

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.