i am facing problem in receiving the transmitted values from arduino continuously

hello everyone, i am trying to serially receive the data from arduino. i am reading a series of analog devices and transmitting the converted value to matlab. but the changes in the output produced in the hardware is not reflected in matlab. it remains to read only the data it read for the first time. pls help me to solve this problem. here is the code of reception using matlab and the code for transmitting using arduino.
arduino code:
int analogInPin1 = A0;
int analogInPin2 = A1;
int analogInPin3 = A2;
int analogInPin4 = A3;
int analogInPin5 = A4;
int analogInPin6 = A5;
int sensorValue1 = 0;
int sensorValue2 = 0;
int sensorValue3 = 0;
int sensorValue4 = 0;
int sensorValue5 = 0;
int sensorValue6 = 0;
int outputValue1 = 0;
int outputValue2 = 0;
int outputValue3 = 0;
int outputValue4 = 0;
int outputValue5 = 0;
int outputValue6 = 0;
void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600);
pinMode(2,INPUT);
}
void loop()
{
// read the analog in value:
if(Serial.available() > 0)
{
sensorValue1 = analogRead(analogInPin1);
sensorValue2 = analogRead(analogInPin2);
sensorValue3= analogRead(analogInPin3);
sensorValue4 = analogRead(analogInPin4);
sensorValue5 = analogRead(analogInPin5);
sensorValue6 = analogRead(analogInPin6);
outputValue1 = map(sensorValue1, 0, 1023, 0, 255);
outputValue2 = map(sensorValue2, 0, 1023, 0, 255);
outputValue3 = map(sensorValue3, 0, 1023, 0, 255);
outputValue4 = map(sensorValue4, 0, 1023, 0, 255);
outputValue5 = map(sensorValue5, 0, 1023, 0, 255);
outputValue6 = map(sensorValue6, 0, 1023, 0, 255); // change the analog out value:
for(int i=0;i<30;i++)
{
Serial.println(outputValue1);
delay(100);
Serial.println(outputValue2);
delay(100);
Serial.println(outputValue3);
delay(100);
Serial.println(outputValue4);
delay(100);
Serial.println(outputValue5);
delay(100);
Serial.println(outputValue6);
delay(100);
}
}
}
matlab code:
s=serial('COM2');
fopen(s);
fwrite(s,100);
for i = 1:30
fread(s,6);
end
fclose(s);

Answers (0)

Categories

Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange

Asked:

on 12 May 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!