Hi guys,
I am quite new to micropython, I usually only use C on micros and a bit of Python to test things.
I have a Nucleo F411 and yesterday I compiled micropython and flashed it, and then I did some small test using rshell to change main.py.
When I tried the last little test I saw something that I cannot explain easily, this was the code in main:
[code]
import pyb
print("Hello from Micropython!")
pyb.LED(1).toggle()
[/code]
What I saw is that the Led went always on after pressing the reset button and seeing the print on my serial terminal. Afterward, if I sent the same command through the serial the led effectively toggled.
What is physically happening?
Do I need to insert a delay for any reason?
Thanks
[SOLVED]Toggling a led on Nucleo F411. Do I need a delay?
[SOLVED]Toggling a led on Nucleo F411. Do I need a delay?
Last edited by antwtna on Fri Mar 08, 2019 3:42 pm, edited 1 time in total.
Re: Toggling a led on Nucleo F411. Do I need a delay?
toggle() is ONE command. If the LED is off, it gets switched on, if it's on it gets switched off.
If you want to blink a led you have to call toogle() in a loop - and yes, in this case you need a delay because you won't be able to see the blinking otherwise because it is way too fast for your slow human eyes.
If you want to blink a led you have to call toogle() in a loop - and yes, in this case you need a delay because you won't be able to see the blinking otherwise because it is way too fast for your slow human eyes.
Re: Toggling a led on Nucleo F411. Do I need a delay?
Hi, thanks for your answer.
I really wanted to see the Led change at every reset, and I expected that if I pressed the reset when the led was off it would turn on, and the next time, when the led is already on, pressing the reset button the led would turn off.
Anyway, your answer made me think about it, and I realize that the led status may be cleared at every reset, and this means that the led is turned off at every reset and then toggled on by that code. Silly me for not realizing this
A better test would have been a callback linked to the USR button.
Thank you!
I really wanted to see the Led change at every reset, and I expected that if I pressed the reset when the led was off it would turn on, and the next time, when the led is already on, pressing the reset button the led would turn off.
Anyway, your answer made me think about it, and I realize that the led status may be cleared at every reset, and this means that the led is turned off at every reset and then toggled on by that code. Silly me for not realizing this
A better test would have been a callback linked to the USR button.
Thank you!
Re: Toggling a led on Nucleo F411. Do I need a delay?
Yes, every microcontroller tries a clean reset which sets all periphials to a clean status.
Otherwise programs can't be sure how the requested periphial is configured.
Otherwise programs can't be sure how the requested periphial is configured.
Re: [SOLVED]Toggling a led on Nucleo F411. Do I need a delay?
Yes, that was a very dummy question, sorry
The fact is that I was only thinking from a "software" perspective("ok, it should toggle"), and my mind was kind of stuck into it.
The fact is that I was only thinking from a "software" perspective("ok, it should toggle"), and my mind was kind of stuck into it.