View Full Version : Tutorial for interfacing a Propeller to a PC with VB 2008!

05-25-2010, 08:35 AM
After I had to prowl the internet for information on how to get this "Should be simple" task done, I decided to write a tutorial about it. Now others can learn to interface the Propeller to the PC and make cool PC apps that can continue to help Propeller programmers. I've spent all afternoon on it, so I hope you like it!



Check out my new website!! (http://microcontrolled.propmodule.com/home.html)

Use the Propeller icon!! http://www.proptools.org/images/Propeller.gif

Follow me on Twitter! Search "Microcontrolled"

Post Edited (Microcontrolled) : 5/25/2010 5:17:18 PM GMT

05-25-2010, 08:59 AM
Looks good - Thanks!

One suggestion - maybe attach it in PDF incase people don't have Office 2007+

05-25-2010, 09:00 AM
OK, I will tomorrow. Thanks!

Check out my new website!! (http://microcontrolled.propmodule.com/home.html)

Use the Propeller icon!! http://www.proptools.org/images/Propeller.gif

Follow me on Twitter! Search "Microcontrolled"

05-26-2010, 12:15 AM
PDF file has been uploaded! Now everyone should be able to view it.

Check out my new website!! (http://microcontrolled.propmodule.com/home.html)

Use the Propeller icon!! http://www.proptools.org/images/Propeller.gif

Follow me on Twitter! Search "Microcontrolled"

05-26-2010, 12:28 AM
This is very decent of you to share this, I was looking for info on this subject thank you

05-26-2010, 12:38 AM
Microcontrolled said...
I've spent all afternoon on it, so I hope you like it!

Very nice paper with lots of good explanations. Many newcomers will appreciate your effort.

Cheers :)

May the road rise to meet you; may the sun shine on your back.
May you create something useful, even if it's just a hack.

05-26-2010, 02:45 AM
@Microcontrolled -·Thats good now ·lets see your take on receiving in VB2008!

···································Fix it, if ain't broke!

D Rat

Dave Ratcliff N6YEE

Post Edited (ratronic) : 5/25/2010 7:50:24 PM GMT

05-26-2010, 06:10 AM
@ratronic: Yeah... I still havn't got that working myself. http://forums.parallax.com/images/smilies/wink.gif
@jazzed: Thanks! I spent so much time figuring this out myself that I figured I should let everyone else have an easy source.
@mikediv: Thank you! I hope it helps!

Check out my new website!! (http://microcontrolled.propmodule.com/home.html)

Use the Propeller icon!! http://www.proptools.org/images/Propeller.gif

Follow me on Twitter! Search "Microcontrolled"

05-26-2010, 06:23 AM
Microcontrolled, I haven't really figured it out completly myself either, but this a 'modified' file I found on the internet I use pieces of whenever I need something. I was kinda hoping you did!

···································Fix it, if ain't broke!

D Rat

Dave Ratcliff N6YEE

05-26-2010, 07:13 AM
Hey Gang,

I don't know if this will help..

I have found that using a timer to "recieve", is very helpfull.

Set up a timer tick event to ".readexisting", every tick it will "readexisting" Data, and update a Label or a textbox or whatever...

I set mine up to give a reading for RCtime, and also a Light to freq. converter.. (Wanna see it?)

Anyways, thanks MicroControlled, for the quick lesson in communicating with the Prop to PC. it was very helpfull to me,
It confirmed what I had discovered allready.. which is a good thing.

Also, (for the absolute newbie) make sure when you send a string to the Prop... TERMINATE THE STRING!! With a 0, or..
Prepare to spend hours hunting down the "bug"..

Oh and don't forget to put an "@" in front of the string pointer...That drove Me insane for a few hours hunting down that one... sigh...

This works, (@whatEverDataPointer)... this won't work (WhatEverDataPointer)... You WILL know what I mean...

All part of the fun I guess..

05-26-2010, 07:22 AM
@Ttailspin: Let's see your code! I would like to expand upon the tutorial to include reading as well.
@ratroinc: Let me check it out.

Check out my new website!! (http://microcontrolled.propmodule.com/home.html)

Use the Propeller icon!! http://www.proptools.org/images/Propeller.gif

Follow me on Twitter! Search "Microcontrolled"

05-26-2010, 09:09 AM
Nice work microcontrolled. I am sure it will be appreciated.

Would you like to expand your work???

In Sphinx there is a simple ftp (file transfer protocol) that mpark has used. I started to split it out to a seperate Sphinx aware program (prop end) just like DIR. Michael has a C PC program that will do the ftp. Would you like to do the protocol in VB to extend SphinxOS ?

Another app would be to make a VT100 terminal in VB for the prop. Not all codes need to be supported.

Links to other interesting threads:

· Home of the MultiBladeProps: TriBlade (http://forums.parallax.com/showthread.php?p=786418),·RamBlade (http://forums.parallax.com/showthread.php?p=849265),·SixBlade (http://forums.parallax.com/showthread.php?p=780033), website (http://bluemagic.biz/cluso.htm)
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator) (http://forums.parallax.com/showthread.php?p=790917)
· Prop Tools under Development or Completed (Index) (http://forums.parallax.com/showthread.php?p=753439)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) (http://forums.parallax.com/showthread.php?p=778427) ZiCog (Z80) (http://forums.parallax.com/showthread.php?p=788511) , MoCog (6809) (http://forums.parallax.com/showthread.php?p=811043)·
· Prop OS: SphinxOS (http://forums.parallax.com/showthread.php?p=819353)·, PropDos (http://www.orrtech.us/propdos/) , PropCmd (http://obex.parallax.com/objects/440/)··· Search the Propeller forums (http://www.google.com/advanced_search?q=+site:forums.parallax.com&num=20&hl=en&lr=)·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz (http://www.bluemagic.biz)·· MultiBlade Props: www.cluso.bluemagic.biz (http://www.cluso.bluemagic.biz)

05-26-2010, 10:12 AM
Here is some Working Code as written by a GrandMaster Carpenter...
Hey, What can I say,..·I can Cut and Paste with the best of them.

For Visual Basic recieveing, I use this..

Private Sub BtnRecieve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRecieve.Click

If _port.IsOpen Then
TxtRecieved.Text = _port.ReadExisting
MsgBox("NO COMMUNICATION PORT IS DETECTED" & (Chr(13) & Chr(10)) & (Chr(10)) & "PLEASE TRY AGAIN" & (Chr(13) & Chr(10)) & "SEE THE OPTIONS MENU", , "No Communication Port has been detected")
End If
End Sub

What Visual Basic Recieves from the Propeller, is this...

PUB RCtime | time
' Configure counter module.
'COGNEW (RCtime, @RCstack)
ctra[30..26] := %01000 ' Set mode to "POS detector"
ctra[5..0] := 20 ' Set APIN to 20 (P20)
frqa := 1 ' Increment phsa by 1 for each clock tick

'' Repeatedly takes and displays Pin(20) RC decay measurements.


repeat 20 'Set how many measurments before returning

' Charge RC circuit.
dira[20] := outa[20] := 1 ' Set pin to output-high
waitcnt(clkfreq/100_000 + cnt) ' Wait for circuit to charge

' Start RC decay measurement.
phsa~ ' Clear the phsa register
dira[20]~ ' Pin to input stops charging circuit


waitcnt(clkfreq/60 + cnt)
' Measurement has been ready for a while.
'Adjust ticks between phsa~ & dira[20]~.
time := (phsa - 624) #> 0

'Display Result
Pst.Str(String(13, "time = "))
waitcnt(clkfreq/2 + cnt)

I have no idea how to post Visual Basic Code, I will try to just attach the PCommunication Project.

And The Propeller File, is also named PCommunication..

IF the Two Programs are ran at the same time, AND the Prop. Pro. Dev. Board IS wired As woefully described.
It should function in all sorts of fun and entertaining ways, and indeed, the comm port, will "comport"...
Just Play around with them, and See what You can See, They were written by a Newbie, so a Newbie should
be able to sort it out..(LOL, I bet the Pro's Might struggle with it, at least, it will be a good laugh for them.)

As a Disclaimer, the code and comments, are written for Me, and Me alone, REGARD THEM AT YER OWN RISK.
Please, Feel Free to comment on My comment's, I would love to hear what any Pro would say of them.

Again, I am a Profesional·Carpenter, My day to day hand tools, are somewhat more Primative than a lap top,
and communication with a keyboard can be diffucult and awkward at best, at least·for Myself·that is..

Anyways, I will try My best to Post Up the Two Programs now.. I may need instruction on this.

Post Edited (Ttailspin) : 5/26/2010 3:28:24 AM GMT

05-26-2010, 11:34 AM
This is a great little tute.

Next step - if you are sending data you will find vb has trouble with bytes 128 to 255, so you have to convert that string into byte values if you want the full range of ascii values. This becomes relevant if you are sending binary files.

Reading values back can be done in lots of ways but a timer as already suggested is a good system. Check for bytes in the buffer several times a second, and then read in that number of bytes.

@Cluso, VT100 terminal is already done in visual basic, as is xmodem, and the more basic input and output of bytes.
@microcontrolled, if you like you can pull to bits the code I have that does all the above - smarthome.viviti.com/propeller (http://smarthome.viviti.com/propeller) down near the bottom just above the picture of wordstar is a link "IDE" and that contains a huge amount of vb code that can do all the things you want. The complicated part is simplifying it. Then of course, once you make it simple, it doesn't do what you want so you have to make it complicated again.

addit Sorry about that last bit, but I've just finished reading Catch 22 and the writing style is somewhat contagious!

www.smarthome.viviti.com/propeller (http://www.smarthome.viviti.com/propeller)

Mike G
05-26-2010, 12:08 PM
Here's a fairly easy way to read bytes in VB.NET

Imports System.IO.Ports
Imports System.Threading

Module Module1

Public WithEvents serial As New SerialPort()
'Dim handler As New SerialDataReceivedEventHandler(AddressOf SerialDataReceivedEventHandler)

Sub Main()
Dim portName As String = String.Empty
Dim baud As Integer
Dim cki As ConsoleKeyInfo

Console.WriteLine("We need to open a serial port!")
Console.WriteLine("Enter a serial port name in the form of COM1")
portName = Console.ReadLine()

Console.WriteLine("Enter a baud rate. Integers only, 57600 is a good baud.")
baud = Integer.Parse(Console.ReadLine())

serial.PortName = portName
serial.BaudRate = baud

If serial.IsOpen() Then
Console.WriteLine("Port {0} open at {1}", serial.PortName, serial.BaudRate)
Console.WriteLine("Waiting for serial port DataReceived event.")

End If

cki = Console.ReadKey(True)
Loop While cki.Key <> ConsoleKey.Escape


End Sub

Public Sub SerialDataReceivedEventHandler(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles serial.DataReceived

Dim readBuffer(serial.BytesToRead) As Byte

Dim numBytes As Integer = serial.Read(readBuffer, 0, readBuffer.Length)

Console.WriteLine(BitConverter.ToString(readBuffer ))

'For i As Integer = 0 To numBytes - 1
' Console.Write(readBuffer(i) & " ")
'Next i

End Sub

End Module

Propeller Code

_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

message byte "Hello World",0

byte command
byte temp

serial : "Parallax Serial Terminal"

PUB Main
serial.StartRxTx(31, 30, 0, 57600)


{ Write Hello World }
waitcnt(1_000_000 + cnt)

Timers are good if you need/want to poll the serial port. My opinion, use the DataReceived event.

Edit added project files

Post Edited (Mike G) : 5/26/2010 1:21:38 PM GMT

Jim Fouch
05-26-2010, 06:05 PM
Here is an example of both sides for send and receive I did in SPIN and VB.Net 2008.

It was for a project I did a few months ago to control 4 120Vac circuits and cause a power interruption as specific points for very small amounts of time.

It shows how to use a separate thread to do the receiving·from the COMM port.

Jim Fouch


05-27-2010, 07:15 AM
I've been reviewing the options above all day. I still can't get one working with my current setup. I wonder what is wrong....

Check out my new website!! (http://microcontrolled.propmodule.com/home.html)

Use the Propeller icon!! http://www.proptools.org/images/Propeller.gif

Follow me on Twitter! Search "Microcontrolled"

Mike G
05-27-2010, 08:01 AM
I double checked my SerialHelloWorld.zip file. It's all there. Just download and unzip. The prop code is in the spin file and the .NET stuff, well just double click the SerialHelloWorld.sln file. Load SerialHelloWorld.spin in the prop then run the .NET project. That's about it. It's a console app... so you need to enter a com port and baud when prompted. The com port name will be something like "COMx" where x is is the port number. Baud is an integer. Press the "Esc" key to exit.

If you're having problem integrating in your own project, post your code for help. You have to "New" the serial port for the DataReceived event to wire up.

Post Edited (Mike G) : 5/27/2010 1:08:22 AM GMT