RGB led problem

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
wonde05
Posts: 26
Joined: Thu Apr 08, 2021 12:53 pm

RGB led problem

Post by wonde05 » Thu Apr 08, 2021 1:09 pm

guys I connected RGB led to an esp32 board but all 3 doesn't turn off after I turn them on on. and for example if i want to toggle the red 3 times and turn off it toggles 3 times but won't turn off it keeps on with out toggling. and this is the case for all 3 colors. can you tell me what the problem is ?
Last edited by wonde05 on Fri Apr 09, 2021 8:27 am, edited 1 time in total.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: question

Post by Roberthh » Thu Apr 08, 2021 1:17 pm

People here are not very good at remote mind reading, so we need more technical details.
Please tell us,

- which RGB led you are use
- how you connected it to the ESP32 board and
- which python commands you used.

wonde05
Posts: 26
Joined: Thu Apr 08, 2021 12:53 pm

Re: question

Post by wonde05 » Thu Apr 08, 2021 1:38 pm

i used 1554799RL common anode RGB and esp32_dev_kit-v4 board i connected red to gpio 17, green to gpio 15 and blue to gpio 23 through resistors of course and i used a simple python code

Code: Select all

from machine import Pin
from time import sleep
led = Pin(17,Pin.OUT)
for i in range (n):                   #  this is just for the red
    led.on()
    sleep(0.5)
    led.off()
    sleep(0.5)

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: question

Post by Roberthh » Thu Apr 08, 2021 2:07 pm

Assuming you have the common anode at 3.3V it should work. Two notes:

- led.on() and led.off() are confusing API names, since led.on() switches the output to high level, and led.off() to low level. So led.off() should switch the led on, and the opposite. But it should switch. I prefer to specify the levels with led.value(1) and led.value(0)
- I am a little bit reluctant to use GPIO17, because that sometimes used for memory circuits. But at long as your board continues to run and the code does not report an error, it should be fine.

Edit: I re-edited your code a little bit. Besides whitespace I changed pin.OUT into Pin.OUT.

Code: Select all

from machine import Pin
from time import sleep
led = Pin(17,Pin.OUT)
for i in range (n):                   #  this is just for the red
    led.on()
    sleep(0.5)
    led.off()
    sleep(0.5)

wonde05
Posts: 26
Joined: Thu Apr 08, 2021 12:53 pm

Re: question

Post by wonde05 » Thu Apr 08, 2021 2:57 pm

I tried different types of code it doesn't work may be the problem is with in the led it self. and yes the common anode is on 3.3v

Code: Select all

from machine import Pin
from time import sleep
led = Pin(17,Pin.OUT)
for i in range (3):                   #  this is just for the red
     led.value(1)
     sleep(0.5)
     led.value(0)
     sleep(0.5)
  
this code should blink the led 3 times and stop it, after blinking 3 times it stops blinking but it doesn't turn off . its the same problem for all 3 color leds .

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: question

Post by Roberthh » Thu Apr 08, 2021 3:12 pm

Everything is fine. Just the way LED is connected, led.value(0) switched the led ON, led.value(1) switches it OFF.

wonde05
Posts: 26
Joined: Thu Apr 08, 2021 12:53 pm

Re: RGB led problem

Post by wonde05 » Fri Apr 09, 2021 8:34 am

I replaced

Code: Select all

from machine import Pin, I2C
from time import sleep
ledred = Pin(17, Pin.OUT)
ledblue = Pin(23, Pin.OUT)
ledgreen = Pin(15, Pin.OUT)
for i in range (3):
    ledgreen.on()
    sleep(0.5)
    ledgreen.0ff()
    sleep(0.5)
by this

Code: Select all

from machine import Pin, I2C
from time import sleep
ledred = Pin(17, Pin.OUT)
ledblue = Pin(23, Pin.OUT)
ledgreen = Pin(15, Pin.OUT)
for i in range (3):
    ledgreen.value(0)
    sleep(0.5)
    ledgreen.value(1)
    sleep(0.5)

its works fine now thank you.

Post Reply