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
> 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 :
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.