- #1
xentity1x
- 12
- 0
I'm trying to setup serial communication between Matlab and an Arduino. As a test I have a logical input to the Arduino (it can be either 0 or 1). I then want to pass the value of the input to Matlab and display it. Here's the Arduino code I have:
Here's the Matlab code:
I want Matlab to check the value being sent to it serially every second. What ends up happening is it just displays the first value it gets over and over again. So if the first value of the input is 1, it keeps displaying 1 over and over again regardless if the input goes back to 0. What am I doing wrong?
Code:
void setup() {
Serial.begin(9600);
pinMode(5, INPUT);
}
void loop() {
int NPleft = digitalRead(5);
Serial.println(NPleft);
}
Here's the Matlab code:
Code:
delete(instrfindall)
clear all
s1 = serial('COM3'); % define serial port
s1.TimerPeriod=1;
s1.Terminator='LF';
fopen(s1);
s1.BaudRate=9600; % define baud rate
s1.TimerFcn=@(x,y)disp(char(fscanf(s1)));
I want Matlab to check the value being sent to it serially every second. What ends up happening is it just displays the first value it gets over and over again. So if the first value of the input is 1, it keeps displaying 1 over and over again regardless if the input goes back to 0. What am I doing wrong?