Skip to content
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

Rewrite ard-leonardo-reset script in perl #62

Closed
sudar opened this issue Jun 11, 2013 · 9 comments
Closed

Rewrite ard-leonardo-reset script in perl #62

sudar opened this issue Jun 11, 2013 · 9 comments
Milestone

Comments

@sudar
Copy link
Owner

sudar commented Jun 11, 2013

Right now the bin/ard-leonardo-reset script is in Python. All the other scripts are in perl, so it would be nice to rewrite this in perl as well.

My perl skills are not that good. It would be nice if someone with better perl skills than mine does this.

@sej7278
Copy link
Collaborator

sej7278 commented Jun 13, 2013

Without a Leonardo to test with I can't be sure, but if someone could test this, we could prettyify it with helptext/argument passing etc. Also it doesn't hang my serial port afterwards (on mega) so I assume wait-connection-leonardo would no longer be required (have to test that on a real Leo though, as it does weird virtual device create/destroy when booting).

#!/usr/bin/env perl

use strict;
use warnings;
use Device::SerialPort;

my $port = Device::SerialPort->new('/dev/ttyACM0'); # open port
$port->baudrate(1200); # set baud
$port->write_settings; # restart with new baud
$port->close; # close port

@sudar
Copy link
Owner Author

sudar commented Jun 13, 2013

Thanks.

I will test it when I get back home today, in a couple of hours.

@sudar
Copy link
Owner Author

sudar commented Jun 13, 2013

I tested the above code with Leonardo and it is working.

On second thought, I was thinking whether it will make sense to pass a extra parameter to bin/ard-reset-arduino perl script itself and have this code there. One less file to manage. Also at a later point if Arduino comes with a new board we can modify one perl script itself, instead of creating multiple files.

What are your thoughts?

@sej7278
Copy link
Collaborator

sej7278 commented Jun 13, 2013

yes i think it is worth merging the two, i'll have a go at it soon.

oh did you check that the serial port didn't disappear after the reset - which is what the wait-connection-leonardo script fixes? it'd be nice to reduce 3 scripts down to 1.

@sudar
Copy link
Owner Author

sudar commented Jun 13, 2013

yes i think it is worth merging the two, i'll have a go at it soon.

Cool. Thanks 👍

oh did you check that the serial port didn't disappear after the reset

Yes it does disappear. I did a quick search and it seems to be an expected behavior http://arduino.cc/en/Guide/ArduinoLeonardo#toc3

@sej7278
Copy link
Collaborator

sej7278 commented Jun 13, 2013

yes but it should come back after a second or so, having to pull the cable is a bit naff.

@sej7278
Copy link
Collaborator

sej7278 commented Jun 13, 2013

could you test my commit bed0fd4 with your Leonardo please?

i've made it backwards-compatible so no change is required for the arduino to reset. not a lot of changes required actually, most of the commit is whitespace fixes!

oddly enough either leonardo or arduino method resets my Boarduino!

$ make reset
-------------------------
Arduino.mk Configuration:
- [USER]               ARDUINO_DIR = /usr/share/arduino 
- [AUTODETECTED]       ARDUINO_VERSION = 105 
- [USER]               AVR_TOOLS_DIR = /usr 
- [COMPUTED]           ARDUINO_LIB_PATH = /usr/share/arduino/libraries (from ARDUINO_DIR)
- [COMPUTED]           ARDUINO_VAR_PATH = /usr/share/arduino/hardware/arduino/variants (from ARDUINO_DIR)
- [USER]               ARDMK_DIR = /usr 
- [USER]               ARDMK_PATH = /data7/useful_software/arduino/arduino-mk/my_git/Arduino-Makefile/bin 
-                      ARDUINO_SKETCHBOOK = /home/simon/programming/c++/arduino 
- [DEFAULT]            USER_LIB_PATH = /home/simon/programming/c++/arduino/libraries (in user sketchbook)
- [USER]               BOARD_TAG = leonardo 
- [DETECTED]           MONITOR_BAUDRATE = 9600  (in sketch)
- [AUTODETECTED]       Size utility: AVR-aware for enhanced output
-
-                      ARDUINO_LIBS =
- [USER]                 LCD
- [SYSTEM]               Wire
- [SYSTEM]               Wire/utility
- [SYSTEM]               Wire/utility
-------------------------
Resetting Arduino...
/data7/useful_software/arduino/arduino-mk/my_git/Arduino-Makefile/bin/ard-reset-arduino --leonardo  /dev/ttyUSB0
/data7/useful_software/arduino/arduino-mk/my_git/Arduino-Makefile/bin/wait-connection-leonardo /dev/ttyUSB0
Connection Established

@sudar
Copy link
Owner Author

sudar commented Jun 14, 2013

could you test my commit bed0fd4 with your Leonardo please?

I just tested it in Leonardo and it works.

But out of 10+ times, it failed for about 1-2 times. I guess this is because of the timing issue.

The reset is triggered when the Leonardo's virtual (CDC) serial / COM port is opened at 1200 baud and then closed. When this happens, the processor will reset, breaking the USB connection to the computer (meaning that the virtual serial / COM port will disappear). After the processor resets, the bootloader starts, remaining active for about 8 seconds. The bootloader can also be initiated by pressing the reset button on the Leonardo. Note that when the board first powers up, it will jump straight to the user sketch, if present, rather than initiating the bootloader.

If for some reason, avrdude is not able to send the first request, within 8 seconds, then the processor starts to execute user code and the upload fails. But this happens very rarely. I guess we can do only so much.

Even when the upload fails, if I press the RESET button in the board, then the upload works properly.

i've made it backwards-compatible so no change is required for the arduino to reset. not a lot of changes required actually, most of the commit is whitespace fixes!

I tested with Uno as well and it works perfectly.

Can I go ahead and merge this, or do you want to do any more changes/cleanup?

@sej7278
Copy link
Collaborator

sej7278 commented Jun 14, 2013

you can merge it sure, as i don't think it is any worse than the python script as far as the timing issue goes - that's what wait-connection-leonardo is supposed to handle.

after some googling, it seems nobody (even the IDE) has a 100% reliable setup here, mainly due to the computer handling disappearing USB devices than the Leo itself.

moved it to a pull request which merges into your upstream fine (with the #70 libs dir fix) to make it easier for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants