Hi there,
I am new to Arduino and I have got a problem I am working on for 2 days...
I measure voltage with my Arduino Mega board and I want to send it to Matlab to visualize it and so on.
Here is my Arduino code:
const float sensorVoltage=A0;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
float inputVoltage2=analogRead(sensorVoltage);
float voltage2=5*inputVoltage2/1024;
Serial.println(voltage2);
}
The Arduino code works so far. It shows me the measured voltage. The problem is the interaction with Matlab.
Here is my Matlab code:
delete(instrfind({'Port'},{'COM5'}));
s = serial('COM5', 'BaudRate', 9600);
fopen(s);
a=fscanf(s,'%f');
disp(a)
Matlab stores my variable a as a 1x7char in the workspace. But why?? I never defined anything as a character or as an array.
That's why I get a warning: Warning: Unsuccessful read: Matching failure in format..
disp(a) prints: ¦H0.29
0,29 would be the correct value, but why are there these signs in front of the value?...
Please help me
So you seriously plan to use pin 3.14159 sometime in the future? Pin numbers are INTEGER values.
After you open the serial port, which resets the Arduino, how long do you give it to reset before you expect it up, running, and sending serial data?