New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reset of Leonardo boards #30
Comments
I encountered the same problem. |
I fixed the problem with your code joh, along with minor fixes. see #349d254 |
sorry, it was #37 |
I have created a separate branch by taking @guicho271828 code. https://github.com/sudar/Arduino-Makefile/tree/leonardo Kindly check it and let me know if it works properly. Will merge it with master once it is confirmed to work. |
Shouldn't this also be the case for the Arduino Micro (
I just tested the new |
there is no ard-reset-leonardo now, we merged the functionality into the makefile as part of commit 60ca7d2 could you try |
The only reason why this is not added is because I don't have a micro to test it with :)
We have rewrote the way reset is handled for leonardo and the bin/ard-reset-leonardo script is merged inside bin/ard-reset-arduino itself in commit 60ca7d2 . Also check out #62 Can you kindly test whether this works for micro as well. If yes, then I can do the required code changes and push an update. I have also created #80 to track this. |
@sej7278 You beat me by a couple of minutes ;) |
mwahaha, you can't beat me even with your time machine! i'll have a pull request up in a mo as soon as i can think of a way to check for leonardo OR micro in an ifeq() |
Strangely, the new
If the Micro had been idle, |
can you try modifying the old ard-reset-leonardo python script so that it starts at 1200 baud instead of 57600, as there was something about having to change from the initial baud rather than just starting at 1200bps in some comment somewhere. so i guess: #!/usr/bin/python
import sys
import serial
ser = serial.Serial(sys.argv[1], 1200)
ser.setBaudrate(1200)
ser.close() if that fails to reset, then we can modify ard-reset-arduino --leonardo to start at 57600 and change to 1200 |
Nope, doesn't matter. So, this works:
... while this doesn't (always):
|
can you try your perl without the dies as you have to open, set baud, close; and if one of those dies it won't reset. but i've not idea why otherwise. |
I added the |
well if none of the commands fail, that's very odd. points to an OS issue perhaps, what platform is this - don't say fscking OSX! ;) |
Heh no, it's Linux 3.8, running under Ubuntu 13.04. I'd rather think it to be a Device::SerialPort bug, but I don't have time to look at it myself... |
If you want to debug this further, it might be worth logging the system calls made by the python and Perl programs. On linux strace should do this. |
@mjoldfield strace is a good idea thanks. @maleadt I did have a bit of a grok around pySerial to compare with Device::SerialPort but its too much work for the moment. strace might show something obvious hopefully - probably something not freed or blocking the filehandle, or maybe something python does silently. i'm not even sure if wait-connection-leonardo is required these days. |
I tried to reset leonardo by using both perl and python in Ubuntu. Both the scripts reset the board properly for me. I have also run strace and have attached the output of both perl and python as well as the code I used in this gist https://gist.github.com/sudar/5823250 One observation I had right away is that the trace of python has more than double the number of lines when compared with the perl version |
they're both opening in the same way, perl seems to be going over-the-top changing baud rates and then failing to close the filehandle:
python just does:
|
I've added a pull request just to add the Micro to the same reset routine as the Leonardo. We can revisit why its not working all the time when we have some time to debug, but with my Boarduino I cannot get it to fail once. |
Thanks. I just merged it. |
It seems there is still an issue with the Leonardo, mine will not properly reset on my Linux machine:
Manually running ard-reset-arduino and then checking dmesg also shows the device is not properly resetting. |
My strace log (made with
The close works, but it actually resets the baudrate to 57600 before closing it seems :-S |
Oh wait, the close didn't work, I was looking at the wrong close :-) |
Also, it seems that just before the close, the perl library resets the baudrate to whatever it was at the start. This doesn't happen in the traces posted by sej7278, but I suspect this is because his python script left the baudrate at 1200 and doesn't try to change it back. Also, it seems the descriptor is closed twice: The first time it works, the second time it (obviously) fails. |
Just running |
Yeah even I was facing this issue when I try to reset leonardo using Perl. If I use the Python script, then it resets all the time. But if I use Perl script, then it resets, only if it was previously reset using Python script or by using |
Heh, apologies for the spam run, but I think I've found a solution. Not sure if I like it, though, but at least it confirms my previous suspicions. I just added an explicit file descriptor close in the script, which circumvents the "restore baudrate" feature. The relevant code now looks like:
Some things I wonder:
The strace now looks like:
|
The Arduino IDE does this. They explicitly restore the bautrate to 57600 after reset. |
Perhaps it makes sense to drop Device::SerialPort and just do a few calls to POSIX:: directly? |
Or convert to Python altogether :-) |
I am leaning towards this, instead of |
When you say Windows users, how does any of this actually work on Windows - does it use cygwin or something? I think using stty from the Makefile directly is probably preferable to a perl/python script but doubt its very portable. maybe we should drop windows support (nobody volunteered to test it even works) as they can use the CLI support in IDE 1.5 anyway, are windows users really going to install cygwin/gcc, perl/python and libraries to use this? at best we should limit ourselves to only using what comes bundled with the IDE on windows, which i assume is avr-gcc and avrdude and not much else. the Device::SerialPort docs seem a bit unreliable as the call to destroy() doesn't even work as its already closed using close() |
Technically if cygwin is installed, then most of what we have should work in Windows. But as you said, no one has tested it so far, so I don't know for sure. The reason, why I said I would prefer Python over using |
I've added the regular arduino (DTR) functionality from ard-reset-arduino into the old python ard-reset-leonardo and tweaked it a bit. it now seems to work on my pro micro and mega2560. could people please test it on a few platforms/boards please? its on gist |
@matthijskooijman, @sudar, do you find that reseting a Leonardo or [ Sparkfun Pro] Micro requires 8 seconds? Is there a way around that? Thanks for the stty suggestion. I have created https://gist.github.com/RichardBronosky/0500556194a45f2d4855#file-leoreset-sh that I use so I can reset with the device tethered from inside my backpack. |
Arduino Leonardo bootloader (Atmega32u4) requires DTR to 0 to fully reset into the bootloader. This is what the Arduino IDE is doing to reset a Leonardo:
My Python script to reset a Leonardo is like this:
ALSO: sleep for 1 second before calling the programmer (avrdude, etc); give time to the bootloader to start. |
If I have a Python script running it at 9600 baud. I just tried all the python varieties of resetting the leostick. None worked. |
@CMCDragonkai How are you calling the Python script? Are you sleeping for 1 second after closing the serial port and before trying to talk to the bootloader? |
@alejolp I don't quite understand your question. Are you saying to close the serial port, sleep for 1 second, then reopen? How does this reset the Leonardo (Leostick)? My serial ports are already being closed when I shutdown the Python program. This answer says http://stackoverflow.com/a/21082531/582917 that you just need to toggle the DTR. What's the relationship between opening and closing the serial port, the DTR toggle and the 1200 baud? Why is all this required to just reset the board? In my case, the port is already open. Do I need to close, reopen at 9600, close, then open at 1200, then close? This one doesn't have a DTR toggle at all: https://defendtheplanet.net/2014/07/11/reset-arduino-micro-via-python-serial/ Here's my attempt:
|
@CMCDragonkai The reset procedure is: open port at 1200 bps with DTR=false, and close. You need to wait 1 second to reset and the bootloader to kick in. Then you can talk to the bootloader and upload the firmware or whatever. If you have the serial port already open somewhere else, you need to close it first, otherwise you don't. Check out the context on Arduino IDE touching the port for reset. |
Reset of Leonardo type boards is done a bit differently:
Please consider adding support for this to ard-reset-arduino. I'm no Perl wiz, but the following Python code did the trick:
Cheers!
The text was updated successfully, but these errors were encountered: