How to Read and Write Serial Port Data in Raspberry Pi

9 次查看(过去 30 天)
Hi,
I want Raspberry Pi to run a piece of code independently, read and write data from the serial port separately, and the other recipient is my PC. Can I directly deploy this code into it?I followed the Mathworks tutorial, but I don't know where the problem occurred. My current steps are as follows:
r = targetHardware('raspberry')
deploy(r,'tablelook')
function tablelook()%#codegen
r = raspi;
pc = serialdev(r,'/dev/serial0');
dataToSend = 1;
byteStream = typecast(dataToSend, 'uint16');
write(pc, byteStream);
output = read(pc,5,'uint16');
end
Raspberry Pi receives a 5 * 1 matrix from the PC and sends a 0/1 logic judgment to the PC.The code can run,but the data is incorrect,it's all zero.I dont know why it cannot work.
Many thanks,
Bang
  8 个评论
靖邦
靖邦 2023-11-13
There is anthoer way to detect the raspberry pi's serial port is open?My baud rates same,and others is same too.Here is my raspberrry pi parameter and PC parameter:

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Support Package for Raspberry Pi Hardware 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by