nosoup
Posts: 8
Joined: Fri Jul 13, 2018 6:50 am

Serial connection troubleshooting

Fri Jul 13, 2018 7:45 am

I am trying to connect an old dose calibrator to my pi to make it more usable.

The serial interface (RS232) settings are 9600 N 8 1. The manual states that the device sends information every 2 seconds with this message format: <ISOTOPE>: <VALUE><UNIT>. For instance "I-131: 185 MBq"

The pins carry this signals
1-shielding
2-RXD not used
3-TXD
5-GND
4,6,7,8,9-not used

I have used an FTDI RS232 to usb converter, a raspberry model B+ and run this script with python 3.6:

Code: Select all

import serial

ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
  
while 1:
  lectura=ser.readline()
  print (lectura)
However the output I'm getting is just:
b' '
b' '
b' '
b' '
...

If I unplug the cable from the calibrator side, the output keeps coming regardless.
If change the ttyUSB0 to a file in /dev/serial/by-id that appears when I plug the usb converter the output is the same.

Googling I have found a couple threads reporting these empty b' ', but none seemed to provide a solution...

I'm a total beginner, what should I try next?

Thanks

User avatar
lmarmisa
Posts: 1260
Joined: Thu Feb 14, 2013 2:22 am
Location: Jávea, Spain

Re: Serial connection troubleshooting

Fri Jul 13, 2018 12:16 pm

Before developing a script, I recommend using a terminal emulator like picocom:

Code: Select all

sudo apt-get install picocom

Code: Select all

picocom -b 9600 /dev/ttyUSB0
The exit sequence is Ctr-a Ctrl-x

Once you will be able to see chars and lines with picocom, you can go back to your script if such script is really needed.

hippy
Posts: 6863
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Serial connection troubleshooting

Fri Jul 13, 2018 12:56 pm

nosoup wrote:
Fri Jul 13, 2018 7:45 am
The manual states that the device sends information every 2 seconds with this message format: <ISOTOPE>: <VALUE><UNIT>. For instance "I-131: 185 MBq"
If that is literally the case then ser.readline() may not what you want to use as there won't be any end of line received to terminate what has been sent.

If you can provide a link to the manual which says what it sends that can be verified.

If there is no end of line termination sent you will need to implement something which can accumulate the characters received and detect the gap between each set of characters.

I don't know if the timeout is doing that, whether b'' indicates no data received or is discarding everything which has been received.

I would start by writing a program which just receives a byte at a time and prints those which arrive. If nothing appears there's presumably nothing being received.

User avatar
lmarmisa
Posts: 1260
Joined: Thu Feb 14, 2013 2:22 am
Location: Jávea, Spain

Re: Serial connection troubleshooting

Fri Jul 13, 2018 1:06 pm

Pay attention to your RS232 cable. You will need probably a null-modem cable. If you do not cross wires 2 and 3, you will be not able to receive any char.

https://en.wikipedia.org/wiki/Null_mode ... Wiring.png
https://en.wikipedia.org/wiki/Null_modem

This python 2 script should work:

Code: Select all

#!/usr/bin/env python

import serial

ser = serial.Serial('/dev/ttyUSB0', 115200)
  
while 1:
  lectura=ser.readline().rstrip()
  print lectura

User avatar
davidcoton
Posts: 4677
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Serial connection troubleshooting

Fri Jul 13, 2018 7:09 pm

lmarmisa wrote:
Fri Jul 13, 2018 1:06 pm
This python 2 script should work...
No, it won't.
nosoup wrote:The serial interface (RS232) settings are 9600 N 8 1.
So you have the wrong baudrate in your code.
Sorry if that is pedantic and obvious to everyone.
Signature retired

User avatar
lmarmisa
Posts: 1260
Joined: Thu Feb 14, 2013 2:22 am
Location: Jávea, Spain

Re: Serial connection troubleshooting

Fri Jul 13, 2018 9:31 pm

Sorry, I did not change the baudrate :o

Code: Select all

#!/usr/bin/env python

import serial

ser = serial.Serial('/dev/ttyUSB0',9600)
  
while 1:
  lectura=ser.readline().rstrip()
  print lectura

nosoup
Posts: 8
Joined: Fri Jul 13, 2018 6:50 am

Re: Serial connection troubleshooting

Mon Jul 16, 2018 6:59 am

Sorry for the late reply. Thank you all.
manual.jpg
manual.jpg (247.04 KiB) Viewed 673 times
Seems Imarmisa is right and I need a null modem cable, since the manual says the TxD line of the device connects to the RxD in the PC...

I'll look for a null modem cable and update with the results.

Thanks a lot!

nosoup
Posts: 8
Joined: Fri Jul 13, 2018 6:50 am

Re: Serial connection troubleshooting

Tue Jul 17, 2018 8:20 am

So as soon as I connect the null modem cable the device shuts down and won't boot unless I unplug the cable. It doesn't matter if the raspberry or the serial to usb are connected on the other side.

I tested the cable connecting a pc to the raspberry using termite and it works perfectly.

Since most of the pins are not used, could it be that the device is somewhat protected against "unwanted pins"? I have read that there are several null modem cable configurations, one being "3 wires" that resembles better the connection from the manual. I'm going to mod the null modem cable leaving only pins 2, 3 and 5 and see what happens. Any other idea?

Thank you

Edit: maybe the cable has handshake, causing the incompatibility?
https://www.delock.com/produkt/84250/pd ... sprache=en
The datasheet however says nothing...

Edit: I popped open one end of the cable and there was a bridge on pins 4 and 6. I cut all pins except 2, 3 and 5 and now it works!! Thanks again :D

User avatar
lmarmisa
Posts: 1260
Joined: Thu Feb 14, 2013 2:22 am
Location: Jávea, Spain

Re: Serial connection troubleshooting

Tue Jul 17, 2018 2:07 pm

nosoup wrote:
Tue Jul 17, 2018 8:20 am
So as soon as I connect the null modem cable the device shuts down and won't boot unless I unplug the cable. It doesn't matter if the raspberry or the serial to usb are connected on the other side.
According to your comments the RS232 to USB adapter could be damaged or the cable is defective.

Unplug the cable from the adapter and check if the RPI boots normally in that case.

I tested the cable connecting a pc to the raspberry using termite and it works perfectly.

Since most of the pins are not used, could it be that the device is somewhat protected against "unwanted pins"? I have read that there are several null modem cable configurations, one being "3 wires" that resembles better the connection from the manual. I'm going to mod the null modem cable leaving only pins 2, 3 and 5 and see what happens. Any other idea?
You really need only two wires on your cable:

1) txd/rxd (pin 3 on one side; pin 2 on the other side)
2) ground (pin 5). Other unused wires should be not a problem except if the cable is defective and there is some kind of short circuit.

Thank you

Edit: maybe the cable has handshake, causing the incompatibility?
https://www.delock.com/produkt/84250/pd ... sprache=en
The datasheet however says nothing...
The cable is a passive element. If you have soldering iron, tin and connectors you could easily build your own cable with only two wires.

Have you a multitester?.

I believe that your cable or your dongle have a shortcircuit and the demand of current on the USB interface is very high. So, the voltage of the RPi (5V) falls and therefore the RPi is unable to run.

nosoup
Posts: 8
Joined: Fri Jul 13, 2018 6:50 am

Re: Serial connection troubleshooting

Tue Jul 17, 2018 4:17 pm

Just to clarify. The Rpi had no issues running, it was the dose calibrator the one shutting down as soon as the cable went near. Connecting the Rpi to a pc throught the same null-modem + usb converter showed no issues at all.

I like the do your own cable idea. I'll finish dismantling the modem cable and rewire it as a small adapter.

User avatar
lmarmisa
Posts: 1260
Joined: Thu Feb 14, 2013 2:22 am
Location: Jávea, Spain

Re: Serial connection troubleshooting

Tue Jul 17, 2018 4:45 pm

A few comments:

1) I wrote my post while your edited yours. So, I did not know that your solved your problem.

2) Sorry. I misunderstood which element was not booting.

3) A 2 wires cable will be functional, of course. But I recommend a more practical cable with 3 wires (2/3, 3/2 & 5/5). So both sides will be interchangeable.

Return to “Beginners”