Pushing Arduino code from C++ program

Greetings fellow DIY-ers! I've been busy the last couple of days developing a RGB LED-controlling program for the computer to control Arduino-connected RGB strips. I've had a previous version before, but this time I'm focusing on simplicity in the program. Therefor, I want the option to be able to push code to the Arduino directly from the C++ program, the user wouldn't have to open a sketch in the Arduino IDE, only click a button inside my program. Now, I already have a way to send data from the C++ program via USB-Serial interface to the Arduino, but I'm not quite sure how I would push actual Arduino code to the board.

My question is, what is a good way to push Arduino code from a C++ program to an Arduino board? Are there are chars i should send beforehand which tells the board that the following data is going to be code for it to boot up in? Or can this only be done in the Arduino IDE? I will go look in the Arduino IDE source code when I have the time, but I thought this could be a good place to ask.

Thank you in advance!

I have written this Python program to compile and upload Arduino programs by calling the Arduino IDE. I presume you can do the same with C++.

...R

Robin2:
I have written this Python program to compile and upload Arduino programs by calling the Arduino IDE. I presume you can do the same with C++.

...R

After some updating the code to Python 3.5.2 and fighting Windows' aggressiveness toward making itself function properly, I got it to work! :slight_smile: Now, all I need to know are the different build options, specifically 'board', 'action' and 'port'. What are the formats for the 'board', is it just like it is in the default build options? (arduino:avr:uno for Uno) And for 'action', what can I supply there other than verify? And for 'port', how is that formatted on Windows machines? I know what COM-port the user has, but how should the argument be formatted on Windows?

I am now using IDE 1.6.3 and the board specification needs to change a little. What version are you using?

These are three of the settings I use with 1.6.3

// board, arduino:avr:uno
// board, arduino:avr:mega:cpu=atmega2560
// board, ATTinyCore:avr:attinyx4:chip=84;pinmapping=old;clock=8internal

I will try to show an example of how you figure those out

In the file ...../arduino-1.6.3/hardware/arduino/avr/boards.txt
you should see this entry for the Mega (II have shortened it here)
##############################################################

mega.name=Arduino Mega or Mega 2560

mega.vid.0=0x2341

...SNIP......

mega.build.board=AVR_MEGA2560

Arduino Mega w/ ATmega2560

-------------------------

mega.menu.cpu.atmega2560=ATmega2560 (Mega 2560)

mega.menu.cpu.atmega2560.upload.protocol=wiring

...SNIP....

##############################################################

It is from the piece in bold that I have derived cpu=atmega2560 and note, especially that I have NOT derived it from the piece that says
mega.menu.cpu.atmega2560**=ATmega2560** (Mega 2560)

I hope that gives you some hints for how to proceed.

You may not have the Attiny core, and, in any case, it will not be in the same boards.txt file

...R

Robin2:
I am now using IDE 1.6.3 and the board specification needs to change a little. What version are you using?

These are three of the settings I use with 1.6.3

// board, arduino:avr:uno
// board, arduino:avr:mega:cpu=atmega2560
// board, ATTinyCore:avr:attinyx4:chip=84;pinmapping=old;clock=8internal

I will try to show an example of how you figure those out

In the file ...../arduino-1.6.3/hardware/arduino/avr/boards.txt
you should see this entry for the Mega (II have shortened it here)
##############################################################

mega.name=Arduino Mega or Mega 2560

mega.vid.0=0x2341

...SNIP......

mega.build.board=AVR_MEGA2560

Arduino Mega w/ ATmega2560

-------------------------

mega.menu.cpu.atmega2560=ATmega2560 (Mega 2560)

mega.menu.cpu.atmega2560.upload.protocol=wiring

...SNIP....

##############################################################

It is from the piece in bold that I have derived cpu=atmega2560 and note, especially that I have NOT derived it from the piece that says
mega.menu.cpu.atmega2560**=ATmega2560** (Mega 2560)

I hope that gives you some hints for how to proceed.

You may not have the Attiny core, and, in any case, it will not be in the same boards.txt file

...R

I'm using 1.6.5. Also, what would i parse except for --verify? If i wanted to do anything else than verify the code, like to build and push the code, what would I push?

If you want to upload the code change // action, verify to // action, upload

Sorry, but I don't plan to provide detailed support for this. You need to read the Arduino documentation and work things out yourself, just as I had to.

You probably need to study how the commandline that is created by my Python code compares to the documentation.

...R