I'm developing some Arduino code using XBees to sense environmental data at a remote location. My Arduino code is working great and I'm now ready to upload my remotely acquired data to my computer so that I can parse the data and send it via an SMS message to my smart phone. This way I can monitor my remote location from anywhere.
I'm using a chunk of code I got from the "Getting Started with Processing" book by Reas and Fry. I am able to get the Arduino/XBee data into my computer this way, but I have a problem/issue:
The Arduino code loops continually, but each time I start the Processing Code, it restarts (resets?) the Arduino code. The Arduino code starts over from the beginning going through setup and then into the loop. I have no idea why this is happening. Here is the Processing code I'm using:
// Based on Example 11-07 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
// This sketch, as modified by kjh, reads data from an Arduino, stores it in an array
// then saves the data to a file on disk.
// Create object from Serial class
// define size of data array
 val =
// Data received from the serial port
// representing the setting of the pot
// array index
// scratch value
// IMPORTANT NOTE:
// The first serial port retrieved by Serial.list()
// should be your Arduino. If not, uncomment the next
// line by deleting the // before it. Run the sketch
// again to see a list of serial ports. Then, change
// the 0 in between [ and ] to the number of the port
// that your Arduino is connected to.
arduinoPort = Serial.
// If data is available,
x = port.read();
// read it and store it in val
//val = map(val, 0, 255, 0, height); // Convert the value
(i > asize-
My Arduino code does not read data from the computer or Processing, it only sends data to Processing. The Arduino code is quite long and involved using a fair amount of XBee interface code so I didn't include it here. But, as I said, it is running fine except for being restarted each time I run the Processing code. I'm using an Mega Arduino board connected to my PC via the USB cable.
I greatly appreciate any assistance on this.