NerdKits - electronics education for a digital generation  
Did you know that you can input numbers in binary via a DIP switch, and output them to the LCD? Learn more...

You are not logged in. [log in]

Project Help and Ideas » Reading in Temperature data in python

March 10, 2010
by waspinator

Hi,

Just finished the nerdkits booklet, and now I'd like to be able to read in that serial stream we sent in the temperature sensor tutorial. I'm using ubuntu, and I can get the data using minicom, but I would like to get it using the serial module of python. It should be very simple, but I get gibberish when I try to read from the serial port in python.

This is my python program

#! /usr/bin/python

import serial

ser = serial.Serial('/dev/ttyUSB0')
print ser
s = ser.read(10)
print s

and this is the output:

Serial<id=0xb759264c, open=True>(port='/dev/ttyUSB0', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=0, rtscts=0, dsrdtr=0)
����������

Does anyone know why I'm getting �?

Thanks,

Waspinator

March 10, 2010
by mrobbins
(NerdKits Staff)

Hi Waspinator,

The first clue is that the baud rate is incorrect -- we've set the microcontroller for 115200 by default, so you've got to set the PC-side for the same baud rate.

Try replacing:

ser = serial.Serial('/dev/ttyUSB0')

with

ser = serial.Serial('/dev/ttyUSB0', 115200)

and see if that works.

Mike

March 10, 2010
by waspinator

Thanks!

I feel like an idiot. I thought I had tried that already, but I guess I didn't. works perfectly now.

Thanks again,

Waspinator

Post a Reply

Please log in to post a reply.