Here is the Python to Propeller Tutorial!!
Ravenkallen
Posts: 1,057
Here it is. It took a while to figure out the best method to display the data. So i figured that almost everybody has a TV and a demo board. So here are some requirements of this demo...
You will need...
A PC:
Obviously. I have only tested this demo on Windows Vista. You will need to know how to find your COM port number. That can be found in the device manager and should be under COM ports...
Python 2.7:
You will need to have installed this and know how to use it some. You will be using the Python shell for entering commands, but you could save it as a program and run it later if desired. I have only tested this on this version of Python. It will probably work on the 3X series, but no guarantees.
Pyserial:
This can be found here. Install it using regular Windows procedures. You will want the 2x series exe.
http://pypi.python.org/pypi/pyserial.
Propeller demo board(Or equivalent):
This will be the main device for sending and receiving data and for displaying it on the TV.
TV:
For displaying values..
______________________________________________________________________________________________
Tutorial: For writing data to Propeller.
1: Connect your Propeller demo board to USB, power and a TV.
2: Find your COM port number.
3: Fire up the Python shell in the GUI. Test function by using a simple print command(e.g, print 'hello')
4: Load the program Python to Prop(write) onto your Propeller demo board. You should see a message displayed on the TV indicating a successful download.
5: Enter the following code into the Python shell...Substitute the COM port number(9) for your own number..
import serial
ser = serial.Serial('COM9')
ser.write("Hello")
6: You should see "Hello" displayed on your TV. That means it worked. You can write to the TV more if you want using the same ser.write("") command...after you are done, CLOSE THE COM PORT!! Use this command
ser.close()
If you don't close the COM port the port will lock out any other outside programs trying to access it. Including the Propeller serial terminal.
______________________________________________________________________________________________
Tutorial: Read from Propeller...
1: Follow all steps above except you must; swap the Propeller program for the other called Python to Prop(Read). Then type in the following code to the Python shell...
import serial
ser = serial.Serial('COM9')
ser.read(5)
You will then see the data displayed in the Python shell. Make sure to close the COM port again
______________________________________________________________________________________________
I am open for any comments/ suggestions. Need any help? Just give me a holler!
You will need...
A PC:
Obviously. I have only tested this demo on Windows Vista. You will need to know how to find your COM port number. That can be found in the device manager and should be under COM ports...
Python 2.7:
You will need to have installed this and know how to use it some. You will be using the Python shell for entering commands, but you could save it as a program and run it later if desired. I have only tested this on this version of Python. It will probably work on the 3X series, but no guarantees.
Pyserial:
This can be found here. Install it using regular Windows procedures. You will want the 2x series exe.
http://pypi.python.org/pypi/pyserial.
Propeller demo board(Or equivalent):
This will be the main device for sending and receiving data and for displaying it on the TV.
TV:
For displaying values..
______________________________________________________________________________________________
Tutorial: For writing data to Propeller.
1: Connect your Propeller demo board to USB, power and a TV.
2: Find your COM port number.
3: Fire up the Python shell in the GUI. Test function by using a simple print command(e.g, print 'hello')
4: Load the program Python to Prop(write) onto your Propeller demo board. You should see a message displayed on the TV indicating a successful download.
5: Enter the following code into the Python shell...Substitute the COM port number(9) for your own number..
import serial
ser = serial.Serial('COM9')
ser.write("Hello")
6: You should see "Hello" displayed on your TV. That means it worked. You can write to the TV more if you want using the same ser.write("") command...after you are done, CLOSE THE COM PORT!! Use this command
ser.close()
If you don't close the COM port the port will lock out any other outside programs trying to access it. Including the Propeller serial terminal.
______________________________________________________________________________________________
Tutorial: Read from Propeller...
1: Follow all steps above except you must; swap the Propeller program for the other called Python to Prop(Read). Then type in the following code to the Python shell...
import serial
ser = serial.Serial('COM9')
ser.read(5)
You will then see the data displayed in the Python shell. Make sure to close the COM port again
______________________________________________________________________________________________
I am open for any comments/ suggestions. Need any help? Just give me a holler!
Comments
I broke out my "Python Programming for the absolute beginner" that I never really did use. So many books so little time. Or maybe I just have a hard time focusing on one thing. Good thing I don't do this stuff for a living. Anyway I went through to Chapter 4 yesterday in anticipation for this tutorial, I should know just enough to get into trouble. I am going to try it in Ubuntu, If I can't get it going there I'll switch over to Vista. I'll report on my success or failure. Thanks again.
Ron
though I think retyping all these commands line by line is not very comfortable
how about posting a script that receives strings and shows the received strings in an extra window?
next step would be how to save the received data into a textfile transformin each CR-LF into a comma to create a CSV-file
best regards
Stefan
@Stefanl38 ... Yes, that is the next logical step. I just wanted for people to get the feel of the whole thing before they went any further. It is a basic demo. If you want to modify any of my code, you are certainly welcome...
@RonP... I am still somewhat of a newbie at Python to. It does seem to be a easy to learn language however.
For Linux it went like this for me: I used scanlinux.py to find the port.
I also found out by mistake that this monitor hooked up to my laptop has PIP. My TV here is about 20 feet away from my desk and I knew this monitor had TV inputs and every other input under the sun. So I thought well I can get by with just the laptop screen for this little demo, one gets spoiled with two monitors. Next thing I know pressing buttons on side to switch and presto PIP. This is also the first time hooking the demo board to a TV pretty neat. Think I'll play with the TV debug thing instead of the PST.
@Ravenkallen Thanks again. I find Python to be a like SPIN also. But I don't know much about other languages. I think I'll pursue learning Python as a PC programing language it should work for anything I need to do.
EDIT:
Later I found out I couldn't read I got this '\x00\x00\x00\xf8H' which means nothing to me. Found out I needed a timeout so this fixed it.
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
ser.read(5)
'Hello'
Thanks for the tutorial! I plan on trying it out this weekend.