Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Love may fail, but courtesy will previal." -- A Kurt Vonnegut fan


computers / comp.sys.raspberry-pi / Re: How to Read and Write Serial Port Data in Raspberry Pi

SubjectAuthor
* How to Read and Write Serial Port Data in Raspberry PiJackson Zhang
`* Re: How to Read and Write Serial Port Data in Raspberry Pi56d.1152
 +- Re: How to Read and Write Serial Port Data in Raspberry PiJackson Zhang
 `* Re: How to Read and Write Serial Port Data in Raspberry PiJackson Zhang
  `* Re: How to Read and Write Serial Port Data in Raspberry Pi56d.1152
   `- Re: How to Read and Write Serial Port Data in Raspberry PiPaul

1
How to Read and Write Serial Port Data in Raspberry Pi

<393eb2af-e7e2-45dc-b8ca-8729d2cb10f3n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=7886&group=comp.sys.raspberry-pi#7886

  copy link   Newsgroups: comp.sys.raspberry-pi
X-Received: by 2002:ac8:5743:0:b0:41e:3db2:d7f6 with SMTP id 3-20020ac85743000000b0041e3db2d7f6mr243425qtx.4.1699869821622;
Mon, 13 Nov 2023 02:03:41 -0800 (PST)
X-Received: by 2002:a17:903:1313:b0:1cc:3c52:1b13 with SMTP id
iy19-20020a170903131300b001cc3c521b13mr1672958plb.11.1699869821376; Mon, 13
Nov 2023 02:03:41 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.sys.raspberry-pi
Date: Mon, 13 Nov 2023 02:03:40 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=51.195.241.195; posting-account=hv3L6woAAABbq8tJzjtKdF_feRWGcsgX
NNTP-Posting-Host: 51.195.241.195
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <393eb2af-e7e2-45dc-b8ca-8729d2cb10f3n@googlegroups.com>
Subject: How to Read and Write Serial Port Data in Raspberry Pi
From: condifly1030@gmail.com (Jackson Zhang)
Injection-Date: Mon, 13 Nov 2023 10:03:41 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2179
 by: Jackson Zhang - Mon, 13 Nov 2023 10:03 UTC

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

Re: How to Read and Write Serial Port Data in Raspberry Pi

<UJicnda4Irmeas_4nZ2dnZfqnPadnZ2d@earthlink.com>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=7915&group=comp.sys.raspberry-pi#7915

  copy link   Newsgroups: comp.sys.raspberry-pi
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!border-2.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail
NNTP-Posting-Date: Tue, 14 Nov 2023 04:26:43 +0000
Subject: Re: How to Read and Write Serial Port Data in Raspberry Pi
Newsgroups: comp.sys.raspberry-pi
References: <393eb2af-e7e2-45dc-b8ca-8729d2cb10f3n@googlegroups.com>
From: 56d.1152@ztq9.net (56d.1152)
Organization: polymer illumination
Date: Mon, 13 Nov 2023 23:26:38 -0500
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
MIME-Version: 1.0
In-Reply-To: <393eb2af-e7e2-45dc-b8ca-8729d2cb10f3n@googlegroups.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
Message-ID: <UJicnda4Irmeas_4nZ2dnZfqnPadnZ2d@earthlink.com>
Lines: 60
X-Usenet-Provider: http://www.giganews.com
NNTP-Posting-Host: 99.101.150.97
X-Trace: sv3-KhKrb3//2DkIpb16S6Rb5fRFD0YnIFO3y4OZ2PUeUf9RUFQyljfAfEBFGkiBDEyi3DQg1Jw4uVs+95T!gE69aNV5sNCYmY80gQhAnkUCM0w1kcVmfoOn651zwU0lQ1t/5xCG0kVne9mSn4geYfXACfHX9lKD!Cy9eqXOSMYDF8KIQ241v
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
 by: 56d.1152 - Tue, 14 Nov 2023 04:26 UTC

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

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.

Re: How to Read and Write Serial Port Data in Raspberry Pi

<575de524-9da1-435c-857a-05ae9b43073fn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=7918&group=comp.sys.raspberry-pi#7918

  copy link   Newsgroups: comp.sys.raspberry-pi
X-Received: by 2002:ac8:618b:0:b0:41c:bd1d:7df0 with SMTP id kq11-20020ac8618b000000b0041cbd1d7df0mr27656qtb.0.1699946046024;
Mon, 13 Nov 2023 23:14:06 -0800 (PST)
X-Received: by 2002:a17:902:ac8f:b0:1cc:2769:28a5 with SMTP id
h15-20020a170902ac8f00b001cc276928a5mr423626plr.5.1699946045698; Mon, 13 Nov
2023 23:14:05 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.sys.raspberry-pi
Date: Mon, 13 Nov 2023 23:14:05 -0800 (PST)
In-Reply-To: <UJicnda4Irmeas_4nZ2dnZfqnPadnZ2d@earthlink.com>
Injection-Info: google-groups.googlegroups.com; posting-host=108.181.23.29; posting-account=hv3L6woAAABbq8tJzjtKdF_feRWGcsgX
NNTP-Posting-Host: 108.181.23.29
References: <393eb2af-e7e2-45dc-b8ca-8729d2cb10f3n@googlegroups.com> <UJicnda4Irmeas_4nZ2dnZfqnPadnZ2d@earthlink.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <575de524-9da1-435c-857a-05ae9b43073fn@googlegroups.com>
Subject: Re: How to Read and Write Serial Port Data in Raspberry Pi
From: condifly1030@gmail.com (Jackson Zhang)
Injection-Date: Tue, 14 Nov 2023 07:14:06 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Jackson Zhang - Tue, 14 Nov 2023 07:14 UTC

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

Yes you are right,I use RS-485 to connact raspberry pi and PC.And I already connect them with RXD、TXD、GND,I can detect the data of RS-485 use serial assist,but I dont know how to judge whether the raspberry pi receive the data too?

Re: How to Read and Write Serial Port Data in Raspberry Pi

<8f7c2acf-da3f-48fc-8394-f3fc7d858605n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=7919&group=comp.sys.raspberry-pi#7919

  copy link   Newsgroups: comp.sys.raspberry-pi
X-Received: by 2002:a05:622a:1813:b0:41e:a615:1173 with SMTP id t19-20020a05622a181300b0041ea6151173mr29471qtc.7.1699946186446; Mon, 13 Nov 2023 23:16:26 -0800 (PST)
X-Received: by 2002:a17:90a:6006:b0:27d:7b16:5b7b with SMTP id y6-20020a17090a600600b0027d7b165b7bmr2480612pji.0.1699946186185; Mon, 13 Nov 2023 23:16:26 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!69.80.99.14.MISMATCH!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.sys.raspberry-pi
Date: Mon, 13 Nov 2023 23:16:25 -0800 (PST)
In-Reply-To: <UJicnda4Irmeas_4nZ2dnZfqnPadnZ2d@earthlink.com>
Injection-Info: google-groups.googlegroups.com; posting-host=108.181.23.29; posting-account=hv3L6woAAABbq8tJzjtKdF_feRWGcsgX
NNTP-Posting-Host: 108.181.23.29
References: <393eb2af-e7e2-45dc-b8ca-8729d2cb10f3n@googlegroups.com> <UJicnda4Irmeas_4nZ2dnZfqnPadnZ2d@earthlink.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8f7c2acf-da3f-48fc-8394-f3fc7d858605n@googlegroups.com>
Subject: Re: How to Read and Write Serial Port Data in Raspberry Pi
From: condifly1030@gmail.com (Jackson Zhang)
Injection-Date: Tue, 14 Nov 2023 07:16:26 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 66
 by: Jackson Zhang - Tue, 14 Nov 2023 07:16 UTC

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 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 :
>
> 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.
I just want the raspberry pi run some code independently,and can send and receive data to my PC with serial ports.

Re: How to Read and Write Serial Port Data in Raspberry Pi

<qeidnQDxJ5MV38n4nZ2dnZfqn_GdnZ2d@earthlink.com>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=7949&group=comp.sys.raspberry-pi#7949

  copy link   Newsgroups: comp.sys.raspberry-pi
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!69.80.99.26.MISMATCH!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 15 Nov 2023 04:01:12 +0000
Subject: Re: How to Read and Write Serial Port Data in Raspberry Pi
Newsgroups: comp.sys.raspberry-pi
References: <393eb2af-e7e2-45dc-b8ca-8729d2cb10f3n@googlegroups.com> <UJicnda4Irmeas_4nZ2dnZfqnPadnZ2d@earthlink.com> <8f7c2acf-da3f-48fc-8394-f3fc7d858605n@googlegroups.com>
From: 56d.1152@ztq9.net (56d.1152)
Organization: polymer illumination
Date: Tue, 14 Nov 2023 23:01:12 -0500
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0
MIME-Version: 1.0
In-Reply-To: <8f7c2acf-da3f-48fc-8394-f3fc7d858605n@googlegroups.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 8bit
Message-ID: <qeidnQDxJ5MV38n4nZ2dnZfqn_GdnZ2d@earthlink.com>
Lines: 77
X-Usenet-Provider: http://www.giganews.com
NNTP-Posting-Host: 99.101.150.97
X-Trace: sv3-cRwjjQfqH/iff3YamqW2YA62n6E01U3/8lz1rt69AR38tr1a5NJU3EgIdGfxlUe5XdvtR5A9jM3XbUl!KbIsqvVtyO3w/lAgkdR3RWRPgNyEXPkzufuFSSB7VnpfvM2kCjPt72h7+tPLhYY118liai5endee!dyiroNkY9770wp7vPdF+
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
 by: 56d.1152 - Wed, 15 Nov 2023 04:01 UTC

On 11/14/23 2:16 AM, Jackson Zhang wrote:
> 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 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 :
>>
>> 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.
> I just want the raspberry pi run some code independently,and can send and receive data to my PC with serial ports.

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.

Re: How to Read and Write Serial Port Data in Raspberry Pi

<ujt4on$2rmbq$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=8060&group=comp.sys.raspberry-pi#8060

  copy link   Newsgroups: comp.sys.raspberry-pi
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nospam@needed.invalid (Paul)
Newsgroups: comp.sys.raspberry-pi
Subject: Re: How to Read and Write Serial Port Data in Raspberry Pi
Date: Sat, 25 Nov 2023 10:44:22 -0500
Organization: A noiseless patient Spider
Lines: 102
Message-ID: <ujt4on$2rmbq$1@dont-email.me>
References: <393eb2af-e7e2-45dc-b8ca-8729d2cb10f3n@googlegroups.com>
<UJicnda4Irmeas_4nZ2dnZfqnPadnZ2d@earthlink.com>
<8f7c2acf-da3f-48fc-8394-f3fc7d858605n@googlegroups.com>
<qeidnQDxJ5MV38n4nZ2dnZfqn_GdnZ2d@earthlink.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 25 Nov 2023 15:44:24 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="726cf14af196d6c162554d7ad6f1adc8";
logging-data="3004794"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19yRu96A0EqlpHNRl2Z3Lh4exhkrOh9MN4="
User-Agent: Ratcatcher/2.0.0.25 (Windows/20130802)
Cancel-Lock: sha1:nPoSL9W1S8UgfCg93OkOI8l3DSo=
In-Reply-To: <qeidnQDxJ5MV38n4nZ2dnZfqn_GdnZ2d@earthlink.com>
Content-Language: en-US
 by: Paul - Sat, 25 Nov 2023 15:44 UTC

On 11/14/2023 11:01 PM, 56d.1152 wrote:
> On 11/14/23 2:16 AM, Jackson Zhang wrote:
>> 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 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 :
>>>
>>> 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.
>>    I just want the raspberry pi run some code independently,and can send and receive data to my PC with serial ports.
>
>
> 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.

Depending on what kind of serial link you are debugging, this is sage advice.
A comment down near the end of the article says...

https://www.abelectronics.co.uk/kb/article/1035/serial-port-setup-in-raspberry-pi-os

"You can check if the serial port works
by following our Serial Port Loopback Test <===
tutorial steps."

Tying TX to RX and "debugging your software path", is a
time honored tradition. Home experimenters have to be
a lot more inventive, when they have no test equipment.
Before you even hook up any level shifters, and start
connecting to a second device, you want to prove the local
device is working properly.

For example, if you typed "U" and a "U" did not come back,
then there would be no point hooking up any interconnect cables
to a second device, until that issue was corrected. Once your
device can talk to itself, then you can work on the harder problem
of making it talk to a peer.

Paul

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor