Hobbyist Toolkit

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial port comms not working between RPi Zero 2 W and Windows

Solved!
Go to solution

Hi fellow wire workers,

 

Goal: to establish serial comms between RPi Zero 2 W and Windows (Putty or LabVIEW)

Error Desc:  LabVIEW code on RPi gives timeout when attempting to write data to serial port 1

 

Details: I have made headway in causing the RPi Zero 2 W to appear as a serial device under device manager under Windows 10. However when I attempt to write characters to the RPi ASRL1 from LabVIEW to be Rx by a Putty Terminal I get a timeout error [1].  I have been using this RPi with much LabVIEW code including digital IO,  so I know I have the main build/deploy/run processes figured out.  I do not want to use the GPIO pins on the RPi I want to use the USB data connector withi RPi configured as a USB Device connected to my PC via a USB-micro cable (I think I have configured the RPi serial port OK to that end per other help pages [2])

 

Any suggestions as to debugging steps ?

 

Here is a snapshot of the state(s) of my system:

  1. Device Manager:showing RPi present
    Peter_B_0-1694489497291.png
  2. Code snippet run on the RPi  (also attached)
    Peter_B_1-1694489761217.png
  3. Error snippet
    Peter_B_2-1694489863772.png
  4. PuTTy settings plus terminal window blank (no local echo)
    Peter_B_5-1694490065952.png

     

 

[1] Error -1073807339 occurred at VISA Write in Main.lvlib:Main.vi

Possible reason(s): VISA: (Hex 0xBFFF0015) Timeout expired before operation completed.

 

[2] I turned my RPi into a serial gadget  per the following

https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget/serial-gadget

main changes were to :

  1. to the /boot/config.txt file
    append
       dtoverlay=dwc2
    and comment out
       # otg_mode=1
  2. to /boot/cmdline.txt file :
    prepend
      dwc_otg.lpm_enable=0
    delete
      console=serial0,115200 
    append:
       rootwait modules-load=dwc2,g_serial 
       enable_uart=1

 

Peter
0 Kudos
Message 1 of 7
(4,573 Views)

I am making some progress  - at least no timeout and the 14 bytes appear written from the RPi's perspective.

Peter_B_1-1694496542900.png  

Peter_B_0-1694499200218.png

 

 

but PuTTy is still to Rx them, I';ll report back when I have progress...

 

I discovered there are two serial ports setup on the RPi serial0 is for bluetooth (using the H/W UART)  and serial1 is the one I am trying to connect to (whihc uses a S/W UART and I might swap them around once I make more progres per here [1])

Peter_B_0-1694496315983.png

 

[1] https://hallard.me/enable-serial-port-on-raspberry-pi/

Peter
0 Kudos
Message 2 of 7
(4,545 Views)
Solution
Accepted by topic author Peter_B

 

Hi Peter,
Good to hear that you're making progress with the RPi Zero 2 W. I don't have access to a Rpi at the moment, but here are a few things to try.

 

The two visa devices you mentioned may be the UART's on the RPi Zero 2 W. They are not used for the USB serial gadget device.

Did you run the visa find device vi to update the visaconf.ini file with the USB device?

I think the USB serial gadget device is mapped in Linux as /dev/ttyGS0

You can check using dmesg on a shell to the Rpi. The USB serial gadget device name should be listed in the output.

You may be able to test the connection from the Rpi to PC using the minicom terminal program on the Rpi and puTTy on the PC.
If it's not installed by default you may need to enter


sudo apt-get install minicom

 

I think the command line to start the program is


sudo minicom -D /dev/ttyGS0

 

Characters entered into minicom should be echoed in the puTTy terminal program on the PC and vice versa.

If this works OK you may need to create a manual entry for /dev/ttyGS0 in the visaconf.ini file on the Rpi.

You should then see the new visa alias from LabVIEW on the Rpi.

 

The USB Ethernet gadget device also works with LabVIEW on the Rpi 🙂
It can be used as a way of deploying LabVIEW programs to the RPi Zero 2 W without a WiFi connection.

You can connect to the Rpi using the host name
Eg
pi02w.local

 

Cheers,
Andy.

0 Kudos
Message 3 of 7
(4,464 Views)

Hi Andy,

thank you so much for chiming in to assist me !

 


The USB Ethernet gadget device also works with LabVIEW on the Rpi


I will enable the ethernet gadget if for some reason the WiFi method I use proves inconvenient as that is how I have been establishing a connection reliably for now.   It just turned out there is a separate requirement for this project to use serial comms.

 

I was able to locate the visaconf.ini file and edited it manually, adding in the last section for the USB serial gadget device  per here:

 

pi@raspberrypi:/srv/chroot/labview/etc/ni-visa $ sudo nano visaconf.ini

pi@raspberrypi:/srv/chroot/labview/etc/ni-visa $ cat visaconf.ini
....<snip>...

[ASRL-RSRC-ALIAS]

Name0="ASRL1::INSTR"
Enabled0=1
Static0=0
SystemName0="/dev/ttyAMA0"
BaudRate0=9600
Parity0=0
StopBits0=10
DataBits0=8
FlowCtrl0=0

Name1="ASRL2::INSTR"
Enabled1=1
Static1=0
SystemName1="/dev/ttyS0"
BaudRate1=9600
Parity1=0
StopBits1=10
DataBits1=8
FlowCtrl1=0

Name0="ASRL3::INSTR"
Enabled0=1
Static0=0
SystemName1="/dev/ttyGS0"
BaudRate1=115200
Parity1=0
StopBits1=10
DataBits1=8
FlowCtrl1=0

NumOfResources=3

 

If that doesn't work I will go back and try out the minicom option you suggested.

I will keep you posted.

 

Peter
0 Kudos
Message 4 of 7
(4,439 Views)

Hi Andy, I'm happy to declare success !!

 

Thank you very much. 

I have two followup questions if that is OK.

  1. is this using a H/W or S/W UART ?
  2. ASRL3:INSTR doesn't show up in the find resource list, only 1 and 2 show up as per prior screen shot.  Do you know why ?  
    Peter_B_0-1694669981236.png

 

 

To note some typos I had in the prior visaconf.ini file above, here are the correct settings:

 

Name2="ASRL3::INSTR"
Enabled2=1
Static2=0
SystemName2="/dev/ttyGS0"
BaudRate2=115200
Parity2=0
StopBits2=10
DataBits2=8
FlowCtrl2=0

NumOfResources=3

Peter
0 Kudos
Message 5 of 7
(4,427 Views)

Hi Peter,

Great news!

 

With regards to your questions

 

1) It is a device driver that provides a USB serial device  and a Linux serial device. I don't think it uses SW UARTS internally and so changing the baud rate would have no effect on transfer rates.

 

2) The find device vi checks the entries in visaconf.ini to see if they are online.  It's not finding /dev/ttyGS0. You could try setting the static parameter to 1 in visaconf.ini

 

Andy.

0 Kudos
Message 6 of 7
(4,403 Views)

Thanks again Andy.

 

I can confirm setting 

Static2=1

causes it to come up in the find resource list,

 

I'm glad it is likely to be a physical UART as they are more robust than the software UART (which I read that one of /dev/serial0 /dev/serial1 may well be in the RPi zero).

Peter
0 Kudos
Message 7 of 7
(4,381 Views)