Uncategorized

ttyusb0 problem

Asked 
Active today
Viewed 21 times
0

I’m trying to establish a serial communication between my Raspberry PI 3 B+ – running on Raspbian 10 Buster – and a testing machine I have. The normal behavior of the machine is to send test related data via serial as soon as a test is finished.

I managed to establish the communication in Windows 10 through PuttY using a USB to Serial adapter and it worked fine. However, with the Raspberry I didn’t manage to make the communication work.

The setup is as follows: the USB end of the adapter is connected to one of the Raspberry’s USB slots, and the RS232 end is connected to my machine. In the Raspberry’s side, the USB was given the /dev/ttyUSB0 device name. Here is the output of dmesg | tail:

[ 2702.802083] usb 1-1.1.3: new full-speed USB device number 6 using dwc_otg
[ 2702.934357] usb 1-1.1.3: New USB device found, idVendor=067b, idProduct=2303, bcdDevice= 4.00
[ 2702.934373] usb 1-1.1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 2702.934383] usb 1-1.1.3: Product: USB-Serial Controller D
[ 2702.934393] usb 1-1.1.3: Manufacturer: Prolific Technology Inc. 
[ 2702.935304] pl2303 1-1.1.3:1.0: pl2303 converter detected
[ 2702.939720] usb 1-1.1.3: pl2303 converter now attached to ttyUSB0

I already tried using screen and minicom, and setting them up with 9600 8N1, but they just hang after establishing the connection. The ttyUSB0 is configured as shown bellow:

pi@raspberrypi:~ $ stty -F /dev/ttyUSB0
speed 9600 baud; line = 0;
min = 100; time = 2;
-icrnl -imaxbel
-opost -onlcr
-isig -icanon -echo

After doing a bit of research, i found that I could try doing cat -v < /dev/ttyUSB0 in one terminal emulator, then opening another one and entering echo "hello\r" > /dev/ttyUSB0; this didn’t give me anything in the cat terminal, though. Could it be that – because one end of the cable is connected to the Raspberry and the other to the machine – I cannot communicate with myself locally?

Could anyone help me? I’m really stuck here.

 New contributor
  • To get loop-back communication via ttyUSB0 on the Rpi you probably need to cross-connect the Tx lead to the Rx lead on the RS232 end of the converter and then connect only the USB end to the RPi. – yesno 1 hour ago
  • @Emanoel Costa, Ah, let me see. You project is interesting. My questions: (1) I have summarized your problem in my draft answer, please let me know if I understand the situation correctly, (2) I see that you use “cat” and “echo”, I wonder if you sometimes write short bash scripts for testing, or in fact you are using C++ or python for your project? – tlfong01 1 hour ago    
  • It should work. A clear photo showing the connections at the testing machine may help. If it works on a PC (using USB) it will work on a Pi (using USB). – joan 51 mins ago
  • @Emanoel Costa, I have finished my first draft of the answer to your question. Don’t bother to spend too much time reading the old post I referred. The most important thing is to read my python serial test program to compare and contrast your serial port set up and loop back. Once you climb over this block, the rest is easy. Happy programming! Cheers! – tlfong01 12 mins ago   
  • @yesno, I believe you are right. I think that I would really need to connect both Tx and Rx on the RS232 end of the cable to do the local loop-back communication. I didn’t think of this at the time, though haha. – Emanoel Costa 7 mins ago
  • @joan, that’s what I thought too. – Emanoel Costa 7 mins ago
  • @Emanoel Costa, I am a GUI guy and don’t know much terminal commands. So I actually have not gone through you test report. In case you are are a newbie to Rpi serial, remember to do Raspi-Config: Enable Serial, DISABLE SERIAL CONSOLE. Also my python program runs in Desktop GUI Thonny. If you run in terminal mode, you might need to use “sudo”, … Good Luck. – tlfong01 5 mins ago   
  • @tlfong01 hey man, gladly I already managed to fix my problem, but your answer is really helpful. You summarized my problem precisely. Sadly I have not enough reputation to up vote it haha. After doing some tests, I decided to try another identical machine – they’re really old pneumatic leaking-test machines – with different communication parameters (/dev/ttyUSB0 9600 7E1 – 7 data bits, 1 stop bit and even parity), and to my surprise it worked! – Emanoel Costa 2 mins ago
  • @Emanoel Costa, I am glad you solved your problem. Cheers. – tlfong01 just now   Edit   

0

Question

Objective

How to send a machine’s test results to Rpi3B+ buster USB to serial port (5V TTY) .

Progress

Machine can send test results to Win10 PuttY, using WinPC USB to serial (5VTTY) (not RS232 +-12V adapter/cable)

Problem

Rpi3B+ buster 5V USB hub USB to serial port (/dev/ttyUSB0 9600 N81) does not seem to get the data from the machine.

Answer

Discussions

The OP’s project development methodology is sort of incremental/continuous test/prototyping based, and consists of 2 steps:

(1) Read machine test results by WinPC PuTTY, using USB to serial cable.

(2) Read machine test results by Rpi buster, also using USB to serial cable, with terminal commands “cat”, and “echo”

Suggestions

I would suggest the OP to do the following:

(1) Write short python test programs instead of bash commands.

(2) Do loop back test for Rpi USB to serial cable setup, to make sure Rpi internal serial hardware and setup is OK.

(3) Put the test machine aside, do the WinPC to Rpi loop back test, to make sure Rpi serial to external

References

(1) My IR Transceiver (LIRC) Project

These couple of months I have been doing a couple of home automation projects using sensors (temperature, humidity, pressure etc) and actuators (relays and solenoid, and motor etc). I mainly use I2C, SPI, and UART. My basic project development approach is similar to the OP.

The most recent project is IR transceiver. I am using the same approach as the OP.

(a) Use Win10 RealTerm to do loop back test,

(b) Use Rpi UART (on board TxD, and RxD pins, both 3V3 and stepped up 5V0) and two USB to serial cables. All three serial ports can local echo, and also port to port echo.

(c) Win10 RealTerm send/receive to IR transceiver.

(d) Rpi buster pythong serial send/receive to IR transceiver.

Appendices

(A) Problem with LIRC on Raspberry Pi 3

(B) How many serial ports are on the Pi 3?

(C) Raspberry Pi to Arduino Serial (UART Using GPIO Pins TxD, RdX ) Communication Not Working

(D) Rpi Serial Testing Functions – tlfong01 2019oct03hkt2147

.END of Answer

/ to continue, …

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: