I need to get the values from three load cells that are connected to A0, A1 and A2 pins, separately. At the moment, my code in Java that prints the data from Arduino is this:
public synchronized void serialEvent(SerialPortEvent oEvent) {
if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
try {
load = input.readLine();
System.out.println(load);
System.out.println("====DATA FINISHED====");
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
And I get this from the Console:
0
====DATA FINISHED====
3
====DATA FINISHED====
5
====DATA FINISHED====
I wanted to reach the values of A0, A1, A2 separated from each other, but they are coming all together.
My arduino code is:
int firstSensor = 0; // first analog sensor
int secondSensor = 0; // second analog sensor
int thirdSensor = 0; // third analog sensor
int inByte = 0; // incoming serial byte
void setup() {
Serial.begin(9600);
}
void loop() {
// read first analog input
firstSensor = analogRead(A0);
// delay 10ms to let the ADC recover:
delay(10);
// read second analog input
secondSensor = analogRead(A1);
delay(10),
// read third analog input
thirdSensor = analogRead(A2);
// send sensor values:
Serial.println(firstSensor);
Serial.println(secondSensor);
Serial.println(thirdSensor);
}
I'm new to JAVA, Arduino and here (stackoverflow), I'm sorry for any 'bad' mistake in this post.
Thanks in advance.
Take a look at this tutorial
In short You will need to add some extra data like <sensor_name>=<sensor_value>
Then in your java code you can split on the = and get the sensor name and value