How to recieve data serially from my arduino to raspberry pi via matlab?

1 view (last 30 days)
here is my code.
After complete configuration:
mypi=raspi();
myserialdevice = serialdev(mypi,'/dev/ttyAMA0',9600);
output = read(myserialdevice,100,'uint16')
output =
0×0 empty uint16 matrix
Even though I can see 10 recieved in my serial monitor of Arduino IDE. Also is there any way to make sure whether the connected port of arduino is correct or not? Because while trying at the first place also and creating myserialdevice, I got no error without even connecting my arduino to my pi.
  2 Comments
Jayaram Theegala
Jayaram Theegala on 3 Jan 2019
Can you make sure that the Tx and Rx GPIO pins of Raspberry Pi and Arduino are connected correctly. Also, Raspberry Pi hardware uses +3.3 V as HIGH voltage for serial communcation,so don't directly connect to devices that use higher voltages.
To answer your second question, an error won't be thrown because even when you don't have Arduino connected, this state is same as the state when Arduino is indeed connected but not sending any data.
shivam sahil
shivam sahil on 4 Jan 2019
Hi! Actually I was serially printing the data, I got it sorted by using char funciton, the data printed was just ASCII characters, now to solve it, I just added char in front of output and it is showing the data properly now.

Sign in to comment.

Accepted Answer

shivam sahil
shivam sahil on 4 Jan 2019
Hey peeps, I found the answer to this question. Actually the values printed here are ASCII codes of actual characters. In case you want to see the exact output, you can use this:
char(output)
Hope this helps you all.

More Answers (0)

Categories

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

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!