GerardLouis
Posts: 11
Joined: Sat Jun 15, 2013 9:44 pm

baudrate 128000 pyserial not working

Sat Jun 15, 2013 10:08 pm

Hello,

I am new to the raspberrypi and python and want to read de incoming data from a CellLog8S datalogger on port /dev/ttyUSB0
With the command 'dmesg' in the terminal i can see that the CellLog8S is recognized by the system and the driver cp210x is used.
The CellLog is sending with 128000 baud, 8 databits and 1 stopbit.
I used the following code:

import serial
ser = serial.Serial(‘/dev/ttyUSB0′, 128000)
while 1 :
ser.readline()


After line 2 i get an error. When changing baudrate to 9600 there is no error, but i can’t see anything on the screen after the last line and 2 times enter.
Tried several other baudrate values. The best i get are some weird characters.
Is there a possibility to use the correct baudrate for the celllog: 128000?
Or does anyone know how to read the USB0 port in an other way.

Thanks in advance,

GerardLouis

cae2100
Posts: 143
Joined: Tue Jan 08, 2013 10:35 am
Contact: Website

Re: baudrate 128000 pyserial not working

Sun Jun 16, 2013 12:49 am

128k isnt a standard speed, and in all honesty, Ive never seen anything that's used that baud rate. You may want to try 115200 instead since that's standard baud rate on stuff like that.
If it isnt smoking and blown into pieces, it's not pushed far enough yet. :P
http://cae2100.wordpress.com

GerardLouis
Posts: 11
Joined: Sat Jun 15, 2013 9:44 pm

Re: baudrate 128000 pyserial not working

Sun Jun 16, 2013 5:11 pm

Thanks for the reply cae2100. I tried that baudrate too. It doesn't give an error but it also gives no readings.
128000 baud is the rate according the manufacturers specs. It is also used in a windowsprogram called Logview. Works ok there.

cae2100
Posts: 143
Joined: Tue Jan 08, 2013 10:35 am
Contact: Website

Re: baudrate 128000 pyserial not working

Sun Jun 16, 2013 6:24 pm

maybe just hook it up to the windows computer and try to change the baud rate somehow to something standard. From looking around the web, it seems that the issue is a limitation of pyserial and not being able to use the non standard speeds.
If it isnt smoking and blown into pieces, it's not pushed far enough yet. :P
http://cae2100.wordpress.com

GerardLouis
Posts: 11
Joined: Sat Jun 15, 2013 9:44 pm

Re: baudrate 128000 pyserial not working

Mon Jun 17, 2013 9:34 pm

That is just the problem. The firmware of the device can't be changed.
Searched in different fora for an answer but nobody found a possibility to change the firmware. From a previous answer from Junsi about another issue with the device, i understand that they don't change the firmware anymore.
So i am stuck with the 128000 baud.

DrMag
Posts: 64
Joined: Sat Jun 01, 2013 7:59 pm

Re: baudrate 128000 pyserial not working

Tue Jun 18, 2013 5:17 pm

Are you using python 2 or 3? I get no error in python 2. The error in python 3 indicates it's doing floating point division somewhere instead of integer; likely pyserial uses a single "/" symbol in calculating the baudrate, and so it's passing the wrong data type for non-standard rates.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5658
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: baudrate 128000 pyserial not working

Tue Jun 18, 2013 5:30 pm

There is a hack where you can choose the closest standard baud rate, but adjust the UART clock on GPU.
See:
http://www.raspberrypi.org/phpBB3/viewt ... 24&t=19908
for an example.

GerardLouis
Posts: 11
Joined: Sat Jun 15, 2013 9:44 pm

Re: baudrate 128000 pyserial not working

Wed Jun 19, 2013 12:38 pm

@DrMag: i am using python 2.7.3

@dom: i have tried your method. Gives no error message but also no reading of data.
The supported baudrate nearest to 128000 is 115200.
3000000 x 128000/115200 = 3333333
So added this to the config.txt file:

init_uart_clock=3333333
#init_uart_baud=115200

Tried with and without that last line.
Tried with and without adding this in the cmdline.txt file:

bcm2708.uart_clock=3000000

and this to the config.txt file:

init_uart_clock set=3333333

My python code looks like this:

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

GerardLouis
Posts: 11
Joined: Sat Jun 15, 2013 9:44 pm

Re: baudrate 128000 pyserial not working

Wed Jun 19, 2013 12:48 pm

Something strange happened:
vcgencmd measure_clock uart gives me:
frequency(22)=3334000
so the frequency is rounded to the nearest thousend.
When i did the command again i strangely got:
frequency(22)=3333000

Could this rounding be the problem?

samson241
Posts: 81
Joined: Fri Apr 05, 2013 7:07 am
Location: Western United States

Re: baudrate 128000 pyserial not working

Thu Jun 20, 2013 6:11 pm

I don't think I've ever seen a baud that high... I use 9600...
I realize this question must seem stupid and i apologize in advance.

GerardLouis
Posts: 11
Joined: Sat Jun 15, 2013 9:44 pm

Re: baudrate 128000 pyserial not working

Thu Jun 20, 2013 6:39 pm

@samson241: There are much higher possible baudrates.

From the Pyserial website:
http://pyserial.sourceforge.net/pyseria ... .BAUDRATES
The parameter baudrate can be one of the standard values:
50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600,
19200, 38400, 57600, 115200. These are well supported on all platforms.
Standard values above 115200 such as: 230400, 460800, 500000, 576000,
921600, 1000000, 1152000, 1500000, 2000000, 2500000, 3000000, 3500000,
4000000 also work on many platforms.

GerardLouis
Posts: 11
Joined: Sat Jun 15, 2013 9:44 pm

Re: baudrate 128000 pyserial not working

Mon Jun 24, 2013 1:13 am

I have changed my code to see some output:

Code: Select all

import serial
import time
ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=1)
time.sleep(1)
while 1 :
        print time.asctime(),
        print(': '),
        print ser.readline()
 
The output in the terminal is:

Code: Select all

pi@raspberrypi ~/python $ python readUSB0.py
Mon Jun 24 02:48:44 2013 :  ����������������������������������
Mon Jun 24 02:48:46 2013 :  ����������������������������������
Mon Jun 24 02:48:48 2013 :  
Mon Jun 24 02:48:49 2013 :  ����������������������������������
Mon Jun 24 02:48:50 2013 :  ����������������������������������
Mon Jun 24 02:48:52 2013 :  
Mon Jun 24 02:48:53 2013 :  ����������������������������������
Mon Jun 24 02:48:54 2013 :  ����������������������������������
Mon Jun 24 02:48:56 2013 :  
Mon Jun 24 02:48:57 2013 :  ����������������������������������
Mon Jun 24 02:48:58 2013 :  
Mon Jun 24 02:48:59 2013 :  ����������������������������������
Mon Jun 24 02:49:00 2013 :  ����������������������������������
Mon Jun 24 02:49:02 2013 :  
Mon Jun 24 02:49:03 2013 :  ����������������������������������
Mon Jun 24 02:49:04 2013 :  ����������������������������������
Mon Jun 24 02:49:06 2013 :  
Mon Jun 24 02:49:07 2013 :  ����������������������������������
Mon Jun 24 02:49:08 2013 :  ����������������������������������
Mon Jun 24 02:49:10 2013 :  
Mon Jun 24 02:49:11 2013 :  ����������������������������������
Mon Jun 24 02:49:12 2013 :  ����������������������������������
Mon Jun 24 02:49:14 2013 :  
Mon Jun 24 02:49:15 2013 :  ����������������������������������
Mon Jun 24 02:49:16 2013 :  ����������������������������������
Mon Jun 24 02:49:18 2013 :  
Mon Jun 24 02:49:19 2013 :  ����������������������������������
Mon Jun 24 02:49:20 2013 :  ����������������������������������
Mon Jun 24 02:49:22 2013 :  
Mon Jun 24 02:49:23 2013 :  ����������������������������������
Mon Jun 24 02:49:24 2013 :  ����������������������������������
Mon Jun 24 02:49:26 2013 :  
Mon Jun 24 02:49:27 2013 :  ����������������������������������
Mon Jun 24 02:49:28 2013 :  ����������������������������������
Mon Jun 24 02:49:30 2013 :  
Mon Jun 24 02:49:31 2013 :  ����������������������������������
Mon Jun 24 02:49:32 2013 :  
Mon Jun 24 02:49:33 2013 :  ����������������������������������
Instead of the question marks it should be like this format:

$1;1;;12654;0;0;0;0;0;0;0;12654;20<CR><LF>

1st cell 12654mV, 2nd to 8th cell 0mV and batterypack 12654mV
(CellLog8S connected to 12V leadAGM battery, data format send by the Junsi CellLog8S every 2 seconds)

DrMag
Posts: 64
Joined: Sat Jun 01, 2013 7:59 pm

Re: baudrate 128000 pyserial not working

Tue Jun 25, 2013 7:19 pm

If it were me, the next step I'd do would be to use a different program to look at the serial stream to be sure it's what I expect. For example, instead of using pyserial, I'd use screen or something like it to connect to the device and be sure I can actually get data at the expected 128000 baud. Once I'm certain that everything is behaving as expected, I'd know the issue is entirely with pyserial. I suspect that even with tweaking the clock you're getting frame errors.

Another possibility (which may change everything entirely) is that your device isn't using 8N1. It'd be really great to see a sample of the data line signal. If you had a digital oscilloscope or logic analyzer, that would be ideal.

GerardLouis
Posts: 11
Joined: Sat Jun 15, 2013 9:44 pm

Re: baudrate 128000 pyserial not working

Wed Jun 26, 2013 3:11 am

Thanks for the advice DrMag. I don't have an oscilloscope or analyzer. Maybe now is a good time to get one.
I will try it and report my findings later.

Return to “Python”