i am currently working on a project where i have 2 potentiometers, i need to read the values from potentiometer and send the values to Matlab for plotting the data in x and y axis
this my arduino code for reading the values from potentiometer
void setup()
{
// Start serial at 9600 baud
Serial.begin(9600);
}
void loop()
{
// Read the input on analog pin 11 and 12:
int sensorValue = analogRead(A11);
int sensorValue2 = analogRead(A12);
Serial.print(sensorValue,4);
Serial.print(" Sensor Value 1");
Serial.print(sensorValue2,4);
Serial.print(" sensorValue 2 ");
Serial.println();
}
i like to know how to send above the serial data to matlab
You wrote some code. It did something.
You expected the code to do something.
All we can tell is that what it did was not what you wanted. Since you've not told us what it did, or how that differs from your expectations, you are on your own. Good luck.
void setup()
{
// Start serial at 9600 baud
Serial.begin(9600);
}
void loop()
{
// Read the input on analog pin 11 and 12:
int sensorValue = analogRead(A11);
int sensorValue2 = analogRead(A12);
Serial.print(sensorValue);
Serial.print(",");
Serial.println(sensorValue2);
/*
And you will send strings like:
10,20\n
11,15\n
100,255\n
where \n is line feed and I removed the text strings, which are not necessary IMHO.
.and so on .....
The MATLAB receiver code is yours, see below ..
*/
}
I have no clue how it the code to receive data from a serial line looks like in Matlab. But this is a fragment I'm using Processing.
// Read serial data
while (myPort.available() > 0) { // New data?
char ch = myPort.readChar();
if (ch >= '0' && ch <= '9') {
value[arrayIndex] = (value[arrayIndex] * 10 + (ch - '0'));
} else if (ch == ',') {
arrayIndex++;
kommaZahl++;
} else if ( ch == '\n') {
// Print results when in debugging mode
if (debug) {
println(value[0]);
println(value[1]);
}
And you can easily check the results using the serial console in ARDUINO.