Hi,problem occurred. My current steps are as follows
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
Firstly, I created a connection with Raspberry Pi in MATLAB and sent a matrix Theme
Copy
r = raspi;
pc = serialdev(r,'/dev/serial0');
dataToSend = [22;4;5;6;7];
byteStream = typecast(dataToSend, 'double');
Then,I will deploy the following code to Raspberry Pi to read data from the serial port and send some data to the serial port
Theme
Copy
function tablelook()%#codegen
r = raspi;
rsp = serialdev(r,'/dev/serial0');
output = read(rsp,5,'double');
...%my system code
write(rsp,1,'double')
(I obtain my final 0/1 through the five input parameters and output it to the serial port)
Finally,I read the data in MALTAB
Theme
Copy
read(pc,1,'double')
But I get wrong data during transmission,all of them is zeros.
Can you give me some advice?
Many thanks,
Bang
On 11/13/23 5:03 AM, Jackson Zhang wrote:problem occurred. My current steps are as follows
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
Firstly, I created a connection with Raspberry Pi in MATLAB and sent a matrix
Theme
Copy
r = raspi;
pc = serialdev(r,'/dev/serial0');
dataToSend = [22;4;5;6;7];
byteStream = typecast(dataToSend, 'double');
Then,I will deploy the following code to Raspberry Pi to read data from the serial port and send some data to the serial port
Theme
Copy
function tablelook()%#codegen
r = raspi;
rsp = serialdev(r,'/dev/serial0');
output = read(rsp,5,'double');
...%my system code
write(rsp,1,'double')
(I obtain my final 0/1 through the five input parameters and output it to the serial port)
Finally,I read the data in MALTAB
Theme
Copy
read(pc,1,'double')
But I get wrong data during transmission,all of them is zeros.
Can you give me some advice?
Many thanks,
Bang
"Serial" can mean several things these days - from
RS-232 and friends to SPI and I2C
Sounds like you want RS-232
I'd suggest a practical tutorial like :
https://roboticsbackend.com/raspberry-pi-arduino-serial-communication/
DO remember that PIs operate at 3.3 volts and PC serial
comms are usually 5 volts - and the REAL standard is
like up to 15 volts, including NEGATIVE volts. Ergo
level-shifting hardware is required. It's cheap and not
hard to use, try AdaFruit or Seeed or SparkFun, but you
HAVE to use it.
RS-232 can be done with as few as three wires - transmit,
receive and ground. Usually, these days, you don't need
the hardware "flow control" wires. 232 CAN do a LOT of
things, but 99.9% of people rarely go beyond the simple.
Somewhere I saw an OPTICAL FIBER serial link which gets
past those voltage issues. Alas a quick look reveals
nobody selling such things of late. It would be good
for medium-length runs though ... no noise issues. If
you are fair at electronics though you could MAKE one.
On 11/13/23 5:03 AM, Jackson Zhang wrote:problem occurred. My current steps are as follows
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
I just want the raspberry pi run some code independently,and can send and receive data to my PC with serial ports.Firstly, I created a connection with Raspberry Pi in MATLAB and sent a matrix
Theme
Copy
r = raspi;
pc = serialdev(r,'/dev/serial0');
dataToSend = [22;4;5;6;7];
byteStream = typecast(dataToSend, 'double');
Then,I will deploy the following code to Raspberry Pi to read data from the serial port and send some data to the serial port
Theme
Copy
function tablelook()%#codegen
r = raspi;
rsp = serialdev(r,'/dev/serial0');
output = read(rsp,5,'double');
...%my system code
write(rsp,1,'double')
(I obtain my final 0/1 through the five input parameters and output it to the serial port)
Finally,I read the data in MALTAB
Theme
Copy
read(pc,1,'double')
But I get wrong data during transmission,all of them is zeros.
Can you give me some advice?
Many thanks,
Bang
"Serial" can mean several things these days - from
RS-232 and friends to SPI and I2C
Sounds like you want RS-232
I'd suggest a practical tutorial like :
https://roboticsbackend.com/raspberry-pi-arduino-serial-communication/
DO remember that PIs operate at 3.3 volts and PC serial
comms are usually 5 volts - and the REAL standard is
like up to 15 volts, including NEGATIVE volts. Ergo
level-shifting hardware is required. It's cheap and not
hard to use, try AdaFruit or Seeed or SparkFun, but you
HAVE to use it.
RS-232 can be done with as few as three wires - transmit,
receive and ground. Usually, these days, you don't need
the hardware "flow control" wires. 232 CAN do a LOT of
things, but 99.9% of people rarely go beyond the simple.
Somewhere I saw an OPTICAL FIBER serial link which gets
past those voltage issues. Alas a quick look reveals
nobody selling such things of late. It would be good
for medium-length runs though ... no noise issues. If
you are fair at electronics though you could MAKE one.
On Tuesday, November 14, 2023 at 12:26:53 PM UTC+8, 56d.1152 wrote:problem occurred. My current steps are as follows
On 11/13/23 5:03 AM, Jackson Zhang wrote:
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
I just want the raspberry pi run some code independently,and can send and receive data to my PC with serial ports.Firstly, I created a connection with Raspberry Pi in MATLAB and sent a matrix"Serial" can mean several things these days - from
Theme
Copy
r = raspi;
pc = serialdev(r,'/dev/serial0');
dataToSend = [22;4;5;6;7];
byteStream = typecast(dataToSend, 'double');
Then,I will deploy the following code to Raspberry Pi to read data from the serial port and send some data to the serial port
Theme
Copy
function tablelook()%#codegen
r = raspi;
rsp = serialdev(r,'/dev/serial0');
output = read(rsp,5,'double');
...%my system code
write(rsp,1,'double')
(I obtain my final 0/1 through the five input parameters and output it to the serial port)
Finally,I read the data in MALTAB
Theme
Copy
read(pc,1,'double')
But I get wrong data during transmission,all of them is zeros.
Can you give me some advice?
Many thanks,
Bang
RS-232 and friends to SPI and I2C
Sounds like you want RS-232
I'd suggest a practical tutorial like :
https://roboticsbackend.com/raspberry-pi-arduino-serial-communication/
DO remember that PIs operate at 3.3 volts and PC serial
comms are usually 5 volts - and the REAL standard is
like up to 15 volts, including NEGATIVE volts. Ergo
level-shifting hardware is required. It's cheap and not
hard to use, try AdaFruit or Seeed or SparkFun, but you
HAVE to use it.
RS-232 can be done with as few as three wires - transmit,
receive and ground. Usually, these days, you don't need
the hardware "flow control" wires. 232 CAN do a LOT of
things, but 99.9% of people rarely go beyond the simple.
Somewhere I saw an OPTICAL FIBER serial link which gets
past those voltage issues. Alas a quick look reveals
nobody selling such things of late. It would be good
for medium-length runs though ... no noise issues. If
you are fair at electronics though you could MAKE one.
On 11/14/23 2:16 AM, Jackson Zhang wrote:problem occurred. My current steps are as follows
On Tuesday, November 14, 2023 at 12:26:53 PM UTC+8, 56d.1152 wrote:
On 11/13/23 5:03 AM, Jackson Zhang wrote:
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
I just want the raspberry pi run some code independently,and can send and receive data to my PC with serial ports.Firstly, I created a connection with Raspberry Pi in MATLAB and sent a matrix"Serial" can mean several things these days - from
Theme
Copy
r = raspi;
pc = serialdev(r,'/dev/serial0');
dataToSend = [22;4;5;6;7];
byteStream = typecast(dataToSend, 'double');
Then,I will deploy the following code to Raspberry Pi to read data from the serial port and send some data to the serial port
Theme
Copy
function tablelook()%#codegen
r = raspi;
rsp = serialdev(r,'/dev/serial0');
output = read(rsp,5,'double');
...%my system code
write(rsp,1,'double')
(I obtain my final 0/1 through the five input parameters and output it to the serial port)
Finally,I read the data in MALTAB
Theme
Copy
read(pc,1,'double')
But I get wrong data during transmission,all of them is zeros.
Can you give me some advice?
Many thanks,
Bang
RS-232 and friends to SPI and I2C
Sounds like you want RS-232
I'd suggest a practical tutorial like :
https://roboticsbackend.com/raspberry-pi-arduino-serial-communication/
DO remember that PIs operate at 3.3 volts and PC serial
comms are usually 5 volts - and the REAL standard is
like up to 15 volts, including NEGATIVE volts. Ergo
level-shifting hardware is required. It's cheap and not
hard to use, try AdaFruit or Seeed or SparkFun, but you
HAVE to use it.
RS-232 can be done with as few as three wires - transmit,
receive and ground. Usually, these days, you don't need
the hardware "flow control" wires. 232 CAN do a LOT of
things, but 99.9% of people rarely go beyond the simple.
Somewhere I saw an OPTICAL FIBER serial link which gets
past those voltage issues. Alas a quick look reveals
nobody selling such things of late. It would be good
for medium-length runs though ... no noise issues. If
you are fair at electronics though you could MAKE one.
A very simple pgm example here :
https://stackoverflow.com/questions/17539185/serial-communication-with-raspberry-pi
More complicated examples here :
https://pimylifeup.com/raspberry-pi-serial/
Bi-directional async comms are more involved, you'd
start by putting the send and receive examples above
into separate threads and 'pipe' info to the mother
program. You'd also need a pair of serial lines ...
it'd be like a "chat" server where either party can
transmit even as the other is also doing so. The good
old Send/Receive-Then-Wait model is easier.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 371 |
Nodes: | 16 (2 / 14) |
Uptime: | 36:49:28 |
Calls: | 7,932 |
Calls today: | 2 |
Files: | 12,998 |
Messages: | 5,805,537 |