Pages: [1]   Go Down
Author Topic: Change Code on the fly - submit commands faster (without loading)  (Read 532 times)
0 Members and 1 Guest are viewing this topic.
Vienna
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, maybe someone has an idea for a solution.

I use arduino m328p, everything works fine smiley-mr-green. Program is extremly simple, based on the blink sketch under the examples the led on pin 13 blinks once and after that never again.

My task is: let the led blink now, and after that in 3 seconds again, and after that my be in 5 seconds again, and then in 2 seconds again and so on and so on. The time between is not predictable.

At the moment I can do this by loading the blink.hex to arduino by the command line:
avrdude -C c:\etc\ardude.conf -c arduino -p m328p -P com3 -U flash:w:Blink.hex", wait 3 seconds, avrdude again, wait 5 seconds, avrdude, wait 2 seconds and so on.

(In reallity not a lamp should blink but a mini motor should run and do something - but to simplify it, lets use a lamp).

So everything is fine but a little unpretty. I have to load the whole stuff (although it is very small) to the flash every few seconds, that consumes time (about 1 second). So I can never let the lamp light after 1/2 second.

My question: is there a way to start the program again faster without loading the flash. As arduino is always connected to the pc I would prefer to set on the light by submitting a command directly to the unit.

Any idea from the gurus?
Thanks and regards
Rudolf


Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

just send it something via the serial port to change. There is no reason to constantly burn new software to the chip over a simple variable change. (nevermind your killing the write cycles on your arduinos flash ram, which is huge but an erase and rewrite every couple seconds ...)
« Last Edit: August 06, 2012, 12:38:05 am by Osgeld » Logged


Offline Offline
Edison Member
*
Karma: 9
Posts: 1016
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Start the Arduino program.
Select the board, the serial port in the 'Extra' menu.
Write your code and use the upload button.
That's all.

If you have overwritten your boot loader, use the extra menu to burn that again (just once). After that you only have to 'upload' your code.

The goal of Arduino is to make it simple, and you never have to use avrdude yourself.

In your sketch, use the random() function to wait for an unpredictable time.
http://arduino.cc/en/Reference/random
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My task is: let the led blink now, and after that in 3 seconds again, and after that my be in 5 seconds again, and then in 2 seconds again and so on and so on. The time between is not predictable.

How is the time between defined? Is something outside the Arduino deciding when to perform the blink, or do you want the Arduino to decide?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Vienna
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How is the time between defined? Is something outside the Arduino deciding when to perform the blink, or do you want the Arduino to decide?
Decision occurs outside Arduino. Only a program, independent from Arduino knows when its time to blink.
Logged

New Jersey
Online Online
Faraday Member
**
Karma: 67
Posts: 3702
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How is the time between defined? Is something outside the Arduino deciding when to perform the blink, or do you want the Arduino to decide?
Decision occurs outside Arduino. Only a program, independent from Arduino knows when its time to blink.

So, make that process, by whatever means, send something to the arduino over serial to tel it to blink.
Logged

Vienna
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Start the Arduino program.
Select the board, the serial port in the 'Extra' menu.
Write your code and use the upload button.
That's all.

If you have overwritten your boot loader, use the extra menu to burn that again (just once). After that you only have to 'upload' your code.

The goal of Arduino is to make it simple, and you never have to use avrdude yourself.


Thanks for the hint Krodal. Exactly this is what I want BUT it has to occur automatically without having to do something with my hands. In other words - how can I automate the described procedure (select board, upload code). In other words: how can I upload code by command line?
Thanks again for your time to help me!
Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1016
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, I see.

You could make a script, but that's complicated.
What if you make a single sketch that can do it all.....
The variable part can perhaps be stored as variables in EEPROM.
You can use avrdude to program the EEPROM.
Logged

Vienna
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, I see.

You could make a script, but that's complicated.
What if you make a single sketch that can do it all.....
The variable part can perhaps be stored as variables in EEPROM.
You can use avrdude to program the EEPROM.

Yes - that's a good idea! This might help. Thanks Krodal!
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Only a program, independent from Arduino knows when its time to blink.

Does this exist, or is it something you expect to create?

You don't need to upload sketches or change configuration or anything like that, if every blink is going to be commanded. All you need is a program that will write a "blink now" message to the PC's serial port for the Arduino, and a sketch on the Arduino that blinks each time it receives a "blink now" message.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Vienna
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Only a program, independent from Arduino knows when its time to blink.

Does this exist, or is it something you expect to create?

It exists. A smartcard is printed. After leaving the printer it "falls" down to a cardreader that reads the chipinfo. As soon as the data from the card has been read, a small motor will push the card away to free the place for the next card. This small motor (which I have digged out of a damaged mini rc-driven helicopter) is hanging directly on pin 13 (led) of arduino. This pin delivers enough volt for the mini-motor to do something, in this case to move the card away. The program that reads the info from the card exists and should be extended to start the motor for 1 second. Sounds crazy but there is no reason it should not work (and make me unforgetable  smiley-red)

Only a program, independent from Arduino knows when its time to blink.

You don't need to upload sketches or change configuration or anything like that, if every blink is going to be commanded. All you need is a program that will write a "blink now" message to the PC's serial port for the Arduino, and a sketch on the Arduino that blinks each time it receives a "blink now" message.

Good idea - I will continue to check forum for code snippets. In case of success I will surely publish the code in this threat.
Thanks PeterH!

Logged

New Jersey
Online Online
Faraday Member
**
Karma: 67
Posts: 3702
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This small motor (which I have digged out of a damaged mini rc-driven helicopter) is hanging directly on pin 13
You might consider using a transistor to switch the motor on, even if it's just switching the Arduino 5V line. The I/O pins can't source much current and unless that motor is minuscule, you're likely drawing enough to eventually damage your arduino. There are examples in the playground that show how to wire it up.
Logged

Pages: [1]   Go Up
Jump to: