How to change variables in the arduino code w/o having to re-upload the code???

Hello,

We are using an arduino board for a balancing robot project. Right now we are playing with the gains for the motor but have to re-upload the code every time we change a parameter in the code. We are wondering if there is a way we can change these variables on the fly saving a bunch of time without having to re-upload the code every time. Someone told me we can use Serial.Write for this??? But I cannot find anything on it. Any other suggestions if serial is not the way to go would be greatly appreciated.

Wire a routine which checks for available Serial data, and if it find it, use it to set your variable.
For example say your variable (no idea what it is as you haven't been clear) is a byte:

byte someMysticalVariable;
...
if (Serial.available()){
  someMysticalVariable = Serial.read();
}

That would simply set the variable to whatever value is received from the serial port.
You could write something to parse decimal strings e.g. if you type 1234 into the Arduino serial monitor, you will actually receive four bytes, ('1','2','3','4'} which you would have to convert back into an integer.

Look at Arduino IDE example called 'Dimmer' ( File -> Examples - > Communication -> Dimmer ) . It might give you some idea :slight_smile:

Try this:

byte someMysticalVariable;
...
if (Serial.available()){
someMysticalVariable = Serial.read();
}

this might work.

You might want to use parseInt(), not read()!

...and you may wish to check the age of this thread (and the membership status of the OP...)