How can I create a program that allows me to run it and automatically upload a sketch to arduino without the software?

I have an Arduino uno board, and a robot that can follow, and have obstacle avoidance. My robot is designed for a person at school who has crutches for life, and the robot follows her with her books. I want to create a program with visual studio that automatically uploads each sketch to the board, depend on which button to click on. I already have visual micro for Visual Studio 10, and when I debug it or build it, it just uploads it to the robot. I need it to be a .bat file or a .exe file. If anyone could help me with this, I will be extremely grateful. Any ideas? Below I have a screenshot of what the program plans on doing.

Picture of How can I create a program that allows me to run it and automatically upload a sketch to arduino without the software?
sort by: active | newest | oldest
dunk8888young8 months ago

Hi all,i want to make a bat file that will compile arduino source code when i click it,below is an example of what i want to do,but this is for a 32u4 that i found,the bat file goes into a folder where the source code is.

I want to know how to compile an ino file say for an atmega 328p,can some one show me an example of 328p and how i add the .c and .h files and maybe have it upload via usbasp too.

example below

@echo off
set PATH="C:\Program Files\Arduino\hardware\tools\avr\bin";%PATH%

:loop
del test.*
make
if exist test.hex goto usb

:miss
pause
cls
goto loop

:usb
..\tool\reset COM5
make usb
avr-size test.elf -C --mcu=atmega32u4

pause
cls
goto loop

Why use separate sketches for various actions? Why not use a single sketch that handles everything? Seems like your making things too complicated.
28holes (author)  mpilchfamily5 years ago
Because I am entering it into a competition and we are having computers set up, so when I open the program, it will have two buttons on it and each button with upload each sketch to show its abilities. How can I use both sketches and put it into one, like you said?
Jayefuu 28holes5 years ago
Sounds like you just need to merge your programs then have them recognise an input button to select the operation mode.
28holes (author)  Jayefuu5 years ago
The problem is, I don't know how to even upload a .ino file to the arduino without the Arduino IDE. I have tried the windows command line build, but it doesn't upload and I don't know how to set it up, because they don't have instructions.
Jayefuu 28holes5 years ago
Why can't you use the IDE?
28holes (author)  Jayefuu5 years ago
Because, if you look up here at the screenshot, the program needs to upload it when I click the button. I am using Visual Studio 10, with visual micro.
Jayefuu 28holes5 years ago
You don't need a PC to switch between the code. You need a button on the robot and maybe an indicator LED to show which mode it's running in. You need to merge your two sets of code into one sketch that runs different parts depending on whether the button's held down on reset. Or something like that...
28holes (author)  Jayefuu5 years ago
Ok, thanks for helping me, I will try it.
What are the 2 actions you want the arduino bot to perform? Have you created the sketches that will get the robot to perform those actions? If so then post your code.

All you have to do is integrate the 2 sketches into a single sketch. Something like this: Where the void action1() and void action2() are the indivigual sketches you have created to make the robot do what it needs to do. You'll want to have 2 buttons set up on the acduino. In the example below the buttons are connected to pins 2 and 3 and tied to ground. When a button is pressed it starts one of the actions. When it is pressed again the action is stopped. Or if the second button is press the first action stops and the second action starts.

int button[] = {2, 3};  //asigns buttons to pins 2 and 3
int buttonstate = 0;  //button checker
int action = 0;  //variable to control which action rutine should be running

void setup()
{
  for(int x=0; x<2; x++)
  {
    pinMode(button[x],INPUT);  //button pins are input
    digitalWrite(button[x], HIGH);  //enables internal pullups, buttons start in HIGH position
  }
 
  //any aditional setup rutiens from your other sketches go here
 
}

void action1()
{
 
  for(int x=0; x<2; x++)
  {
    buttonstate = digitalRead(button[x]);
   
    if (buttonstae == LOW && button[x] == 2)
    {
      action = 0; //stops the current action
    }
   
    if (buttonstate == LOW && button[x] == 3)
    {
      action = 2;  //allows the current loop of action 1 to finish before starting action 2
    }
  }
  //everything from one of the sketches that makes the robot
  //do its thing goes here
}

void action1()
{
 
  for(int x=0; x<2; x++)
  {
    buttonstate = digitalRead(button[x]);
   
    if (buttonstae == LOW && button[x] == 3)
    {
      action = 0; //stops the current action
    }
   
    if (buttonstate == LOW && button[x] == 2)
    {
      action = 1;  //allows the current loop of action 2 to finish before starting action 1
    }
  }
  //everything from the other sketch that makes the robot
  //do its thing goes here
}

void loop()
{
  for(int x=0; x<2; x++)
  {
    buttonstate = digitalRead(button[x]);
   
    if (buttonstate == LOW && button[x] == 2)
    {  //if button on pin 2 is being pressed
      action = 1;  //change the variable to indicate whihch action should be ran
    } 
   
    if (buttonsate == LOW && button[x] == 3)
    {  //if button on pin 3 is being pressed
      action = 2;  //change the variable to indicate whihch action should be ran
    } 
   
    if (action == 1)
    {
      action1(); //runs the first action sequence
    }
   
    if (action ==2)
    {
      action2();  //runs the second action sequence
    }
  }
}

 

Of course you have to fill in the blanks with your code but that should give you a good start. No need to program in Visual Studio or have a PC connected to the robot to upload a new sketch. 

if you look at my Simon Says and Total Recall instructables you can see how i went from a simple arduino based single player game and added options and made it offer both a single and 2 player games.  
28holes (author)  Jayefuu5 years ago
Ok, so I can't merge the codes, because I our RadioShack doesn't have the parts. Any other ideas?
Jayefuu 28holes5 years ago
Eh????
28holes (author)  28holes5 years ago
And if possible, could you help me with the .bat files that are here: http://arduino.cc/playground/Code/WindowsCommandLine
I don't understand how it locates the sketch and uploads it.
mh76dk5 years ago
http://arduino.cc/playground/Main/DevelopmentTools in the "Others" section there are some commandline utilities that might be able to do what you want (I do not use Arduino so have not tried any of these solutions)
mh76dk mh76dk5 years ago
And (as usual) I spoke too soon, right below "Others" is the "Windows utilities" which seem to have exactly what you asked for