NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » Reading in Temperature data in python

March 10, 2010
by waspinator
waspinator's Avatar

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)

mrobbins's Avatar

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
waspinator's Avatar

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.

Did you know that you can aim and fire a servo-controlled water gun from your computer? Learn more...