Program one Arduino with another / Duplicate function of Arduino

Hi Everyone

I'd like to use an Arduino to program another Arduino. I do not mean Arduino as ISP.

Lets say I have two Arduinos, A & B

I would like to upload a piece of software to Arduino A. Then, later, when Arduino A is no longer connected to my computer I connect it to Arduino B. Arduino A then copies its code to Arduino B, such that they are now identical.

Is this even possible?

How would I, conceptually, go about doing this?

Do I need my own bootloader or can I somehow piggy-back off of the standard bootloader?

Thanks for any suggestions

Regards

P.

I found this:-

Youtube video:- Self-replicating Arduino Sketch

Associated code:- Arduino-Copier

Previous video:- Arduino sketch that can program other boards

Edit: The code is very old, and will require some modifications to compile in recent versions of the IDE. I might have a play with it tonight.

OldSteve:
I found this:-

Youtube video:- Self-replicating Arduino Sketch

Associated code:- Arduino-Copier

Previous video:- Arduino sketch that can program other boards

Edit: The code is very old, and will require some modifications to compile in recent versions of the IDE. I might have a play with it tonight.

I did play with it two days ago. It doesn't compile on 1.0.6 and 1.6.5,maybe using 0022 will help if you are going to try it.

MalharD:
I did play with it two days ago. It doesn't compile on 1.0.6 and 1.6.5,maybe using 0022 will help if you are going to try it.

I'm planning to modify it for V1.6.5. (And maybe later versions.)

I have two UNOs sitting here doing nothing to test with if I can get it to compile.
I'll post the updated code here if I get it working. (Might be a big 'if', but we'll see.)

I changed the Serial.print(XXXX,BYTE) TO Serial.write(XXXX) everywhere, it gives some error related to HardwareSerial.cpp
Should we start a new thread ?
-Malhar

MalharD:
I changed the Serial.print(XXXX,BYTE) TO Serial.write(XXXX) everywhere, it gives some error related to HardwareSerial.cpp
Should we start a new thread ?
-Malhar

Wait and see if it works. You're jumping the gun a bit.
I got it to compile OK. I'll test it tomorrow.

You shouldn't really be jumping, posting it yourself on GitHub as you say. (And in your name, I notice.)
You knew I was doing it. Bloody rude in my opinion.

Edit: MalharD has since 'cleaned up', deleting the post telling us that he'd forked the project on GitHub, and providing a link to the fork.

OldSteve:
Wait and see if it works. You're jumping the gun a bit.
I got it to compile OK. I'll test it tomorrow.

You shouldn't really be jumping, posting it yourself on GitHub as you say. (And in your name, I notice.)
You knew I was doing it. Bloody rude in my opinion.

Sorry for that. I just forked that repo. I am trying to learn how to use Git. Sorry.
I posted a pull request to the original branch.
Sorry again.

You need to think before you do things like that. It's not very good manners.

I've attached the code that compiles now in V1.6.5. Still untested on hardware though.
(BlinkVirus only - I didn't attack the old version that needs Python as well.)

Edit: I just cleaned things up a bit and re-attached the project.

Edit2: The only thing I didn't do was to correct the sketch's compiled size 'sketchLength' at the top of "Copier.ino".
That's best done immediately before use. It might vary depending on the IDE/compiler version.
For me it was 4236 bytes. (This is also mentioned in the comments at the beginning of both files.)

BlinkVirus.zip (3.64 KB)

For me it was 4276 bytes. Toggling pin 2 resets the atmega328p on my breadboard. I don't see the replication. I May have some connections errors.

MalharD:
For me it was 4276 bytes. Toggling pin 2 resets the atmega328p on my breadboard. I don't see the replication. I May have some connections errors.

Well you're the one that wanted to jump the gun and put it on GitHub. Have a go at fixing it.
After getting the idea to modify it, then doing the work to make it compile, I was actually looking forward to seeing if it worked in the morning.

I can't be bothered with this any more.

I apologise for all that.

OldSteve:
After getting the idea to modify it, then doing the work to make it compile, I was actually looking forward to seeing if it worked in the morning.

I can't be bothered with this any more.

@Old Steve, I feel your frustration at this rather-too-eager-whippersnapper but I (and probably several others) were following this thread and I, for one, would be very interested to know whether you got it to work.

Any chance you could just take that final step, as I feel you're in the best position to actually try out the results of all your labours? Then you could post on GitHub in your name as you deserve the credit (if that's your thing, of course).

Just askin' ::slight_smile:

I don't say that's my thing and the author - George Caley deserves the full credit of this thing.
But I was working to make this sketch compile under arduino 1.XX , so I forked the git repo and started to work. I asked @OldSteve that if we will work on this and request a pull on the original repo. I was also going to add him as a contributor if I asked him his username on git. . But I have no experience with git system and I messed things up. I apologise for all this mess caused by me. Please forgive me for all this.

-Malhar

Easier way is to download code stored on an SD card.
I have programmer that does just that running code Nick Gammon developed with some tweaks for my hardware:

http://www.crossroadsfencing.com/BobuinoRev17/Programmer.html

I am just trying it for fun.
Once I blew everything I had to connect a arduino to my PC. But a good old serial port saved me.

-Malhar

Woah.

Amazing that I got people so excited. I'm gonna read up on the links you sent, OldSteve and come back.

@CrossRoads - I am sure there are easier ways of doing this. I'm just conceptually really interested in doing it microcontroller to microcontroller (I actually posted a thread like this about a year ago, but formulated the problem differently, but did not really find an approach I liked).

I don't use github, so I am not sure what this conflict is about (though I am confused as to why MalharD would want to start a new thread, when we have a perfectly good one right here) - but I am sure there was no evil intent here anywhere.

OK, I'm gonna read up and tinker a bit and see if I figure out anything useful.

Cheers

P.

Ralph_S_Bacon:
@Old Steve, I feel your frustration at this rather-too-eager-whippersnapper but I (and probably several others) were following this thread and I, for one, would be very interested to know whether you got it to work.

Any chance you could just take that final step, as I feel you're in the best position to actually try out the results of all your labours? Then you could post on GitHub in your name as you deserve the credit (if that's your thing, of course).

Just askin' ::slight_smile:

No I wasn't planning on forking it on GitHub myself. I didn't even put my name to the modification in the comments in each file. I only added the date they were modified to compile with later versions of the IDE and which version I'd tested it with. (I hate modifications and versions of libraries and other code that aren't dated.)

If I got it working properly, I only planned to hand it back to the author to place on his original gitHub page as a later version. The changes were only minor - changing a heap of 'Serial.print()' instructions to 'Serial.write()', then casting a few variables to uint8_t.

I didn't want to make a big deal of it at all, and just aimed to see if I could fix it, but someone else saw a way to build his reputation. :frowning:
I'm done with it, and with these forums for now. I'm taking a break.

The code is there for anyone to test, and if there is still a problem, fix.

fkeel:
I don't use github, so I am not sure what this conflict is about

GitHub is the website that hosts the download of most code and libraries used with Arduino.
MalharD was going to host the download of the modified code on GitHub under his own name. (GitHub originally hosted the old code, under the original author's name.) That's what upset me.
He'd even already set up the new GitHub 'fork'. (Now deleted.)

OK, after a sleep and a cool-down, (sulk :slight_smile: ), I decided that I wanted to finish what I started.

I've solved the last of the problems and got it working well now.
This time I altered the sketch's compiled size 'sketchLength' at the top of "Copier.ino", to reflect my compilation.
It's still best if anyone testing this sketch does it immediately before use. The compiled size is likely to vary depending on the IDE/compiler version.
For me it's now 4142 bytes, compiling (for UNO) with IDE V1.6.5.
(This is also mentioned in the comments at the beginning of both files.)

I added a few extra comments to the files, including connection details at the beginning of "BlinkVirus.ino".

Also changed all instances of "Serial.print(xxxx,BYTE)" to "Serial.print((char)xxxx)", instead of "Serial.write(xxxx)".
The latter worked OK, but used more flash memory. (4228 bytes vs 4142 bytes)
Every bit counts in these little beasts. :slight_smile:

To test, I first uploaded a small sketch to the target board that simply turned on the onboard LED, so I could see when things were happening. (The LED initially goes out when the source board connects, then it blinks continuously when the process is complete.)

After pressing the 'Trigger' button connected to the source board, it takes a second or two to complete the copy to the target board, then the source board's LED starts to blink.
After a further 3 or 4 seconds, the target board's LED begins to blink as well, synchronised to the source board's LED.

I have no idea if this will work with other boards. It was originally written for a UNO, but chances are that at the very least, other '328P-based boards will be OK.

I've attached the final, tested and working, version of the project.
@fkeel, I hope you find it useful, since you're the one that actually started the thread. :slight_smile:

BlinkVirus.zip (3.83 KB)

Thanks so much. This is super useful. When I was searching for this myself I just kept running into yet another Arduino as ISP tutorial. Getting a working bit of code is more than I ever hoped for. Thanks so much.

Am not able to test it right now, but I think I understand what the code is doing so I should be good to give this a shot soon :slight_smile:

I'm hoping to eventually get this running on Atmega2560s so I can take advantage of the extra serial ports :slight_smile:

I'll post back if and when I get it running. Might take some weeks though.

Thanks again

P.

fkeel:
Thanks so much. This is super useful. When I was searching for this myself I just kept running into yet another Arduino as ISP tutorial. Getting a working bit of code is more than I ever hoped for. Thanks so much.

Am not able to test it right now, but I think I understand what the code is doing so I should be good to give this a shot soon :slight_smile:

I'm hoping to eventually get this running on Atmega2560s so I can take advantage of the extra serial ports :slight_smile:

I'll post back if and when I get it running. Might take some weeks though.

Thanks again
P.

I only have one Mega2560 myself, so can't test using a pair of them. I'll be interested to hear how you get on.