Bright Sparks AWARDS WINNERS ANNOUNCEMENT
The Forum » PICAXE Programs > Serial Data
Login Register Search Recent Posts

Kiwinewt

Posted: 28 June 2008 2:44 AM
 



Member Since:
25 June 2002
Posts: 391
Points: 78

This post was awarded 1 point!

Firstly, does anyone have any idea how to get a picaxe to pass data to a serial port? The best way would be for it to store the data and pass it when it recieves a query from the computer it is hooked up to via the serial port... Secondly, does anyone know anything about writing, say, a python program to read data from the serial port on Linux? I can do the python code to deal with the data once it has been recieved, its just a case of getting said data... Thirdly, Andrew, could I please leech that bit of picaxe code off you that I was working on on Friday? Cheers all Nate
============================================================
Is this an interesting post? In that case I have most likely crossposted to http://nate.walkerfamily.net.nz

Kiwinewt

Posted: 28 June 2008 11:31 AM
 



Member Since:
25 June 2002
Posts: 391
Points: 78

This post was awarded 2 points!

Update: Well I have solved this thanks to about half an hour playing around... and for those people who would find this useful: Firstly, install pyserial on your computer (use google to find it!) Secondly, this code returns a line with a new line char on the end to enable the python code to read it nicely. Hence the .strip() call on the end of the print line to stop it printing a blank line between them. Thirdly, enjoy! This code can be modified as you wish - pump in different things from the picaxe (whatever you want!) and process it in python. Python is a really easy language to play with! picaxe code: main: readtemp12 4, w1 w2 = w1 / 16 sertxd("The temperature is:",9,#w2,9,#w1,CR,LF) ' 9=tab,CR,LF = carrage return line feed sleep 5 'low power mode for 2.3sec*var aka about 12sec goto main python code: import serial ser = serial.Serial() ser.baudrate = 4800 ser.timeout = 100 ser.port='COM3' #change to correct port number ser.open() line = "" while line == "": line = ser.readline() #read a '\n' terminated line print line.strip() ser.close() Nate PS: My code isnt perfect. I never said it was. It is just an example, so play and comment and stuff well done Nate...helpful post Ross
============================================================
Is this an interesting post? In that case I have most likely crossposted to http://nate.walkerfamily.net.nz

William47316

Posted: 28 June 2008 8:56 PM
 



Member Since:
17 May 2005
Posts: 1997
Points: 1740

This post was awarded 1 point!

the sertxd command (some picaxe dont support the command) is probbably the fastest way to get data out of the picaxe as its sending at 4800baud and you dont have to type as much. as for storing data, you'll need to use a EEprom capable of storing the data and picaxe capable of reading/writing said EEPROM as for sending queries to it, the serin command would probably work however it locks the picaxe up until reset or it recives a serial command. i now have my own web server. http://resistorhelper.no-ip.org likewise...thanks William
============================================================
I am an older member but I rarely post

You need to be a member to post.