0

I can blink the built-in LED using the standard code, but when running my moderately resource-intensive code, I cannot get the led to blink. I am connecting my Pico with WLAN. I interrupted the loop to execute the following code.

>>> import micropython                                                          
>>> micropython.mem_info()                                                      
stack: 540 out of 7936                                                          
GC: total: 192768, used: 24832, free: 167936                                    
 No. of 1-blocks: 468, 2-blocks: 84, max blk sz: 72, max free sz: 9509          
>>> from machine import Pin                                                     
>>> led = Pin('LED', Pin.OUT)                                                   
>>> led.on()                                                                    
>>> led.value()                                                                 
0                                                                               
>>> led                                                                         
Pin(EXT_GPIO0, mode=OUT)
  • I tried running the same on another machine, and I was able to replicate the same glitch
  • I am using Pico W 1.20.0 firmware

Can I do something to resolve this? Are there any other ways to blink the LED?

1
  • So you didn't post the code you are using or any evidence of a problem but want someone to tell you what is wrong.
    – Milliways
    Mar 9 at 21:53

2 Answers 2

0

Your micropython.mem_info() output shows that your stack usage is relatively low, but you can try increasing the stack size to see if it helps. Here you will find some info about memory management: https://docs.micropython.org/en/latest/develop/memorymgt.html

1
  • I was reading up on the memory layout of Pico and my first suspicion was that some overflow was happening. Will check it out
    – poloPlaya
    Mar 9 at 11:18
0

I don't see that that would blink the built-in LED, and it certainly isn't "standard code"

You can use a timer to blink a LED with minimal processor use. The following is a simple demo program which users timers and callback to blink 2 LED.

# Pico Timer LED
# https://microcontrollerslab.com/generate-delay-raspberry-pi-pico-timers-micropython/
from machine import Timer, Pin
led_onboard = Pin("LED", machine.Pin.OUT)
led2 = Pin(15, Pin.OUT)
led2.value(1)

timer=Timer(-1)
timer2=Timer(-1)

try:
    timer.init(period=500, mode=Timer.PERIODIC, callback=lambda t:led_onboard.toggle())
    timer2.init(period=1500, mode=Timer.PERIODIC, callback=lambda t:led2.toggle())
except:
    timer.deinit()
    timer2.deinit()
    led_onboard.value(0)
    led2.value(0)
3
  • I don't understand how adding a timer would solve the issue?? The reason I had to interrupt the program in the first place was that the timer-based LED was not working. When I tried to debug the issue I stumbled across this
    – poloPlaya
    Mar 9 at 11:15
  • Did you ACTUALLY try a timer? You have not posted any code which demonstrates any problem - your code doesn't use a timer (or indeed make any attempt to change the LED).
    – Milliways
    Mar 9 at 11:31
  • To iterate once again, I said I interrupted the loop to run the code I mentioned. The loop had a timer that blinked the LED, which isn't working. The timer worked fine before the code volume increased. Now coming to the problem, if you see I did led.on() followed by led.value(), which should've returned 1, but it's not the case. That's what is causing the LED to not blink while running the loop
    – poloPlaya
    Mar 9 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.