Go Down

Topic: Change Code on the fly - submit commands faster (without loading) (Read 605 times) previous topic - next topic

MiddleAge

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



Osgeld

#1
Aug 06, 2012, 07:34 am Last Edit: Aug 06, 2012, 07:38 am by Osgeld Reason: 1
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 ...)
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

Krodal

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

PeterH


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?
I only provide help via the forum - please do not contact me for private consultancy.

MiddleAge


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.

wildbill



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.

MiddleAge


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!

Krodal

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.

MiddleAge


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!

PeterH


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.
I only provide help via the forum - please do not contact me for private consultancy.

MiddleAge



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!


wildbill

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.

Go Up