Simple PC to MCU communication

pctomcucomm.png

Hello guys, this is a simple walkthrough that lets you understand how to do BASIC communication between your PC and your MCU (for now it's only from PC to MCU, still have to experiment a bit on the other way). It involves the use of visual basic (i have used version 6) and a picaxe.

HARDWARE PART

First of all we need to set up the hardware. What we need to do is a circuit which is actually identical to the download circuit, only thing we are not gonna connect it to the same pins (so don't use your on-board jack). What you need to do is make a small circuit with an audio jack so that you can insert your jack (the one you normally use for downloading code to your picaxe) and make the 3 pins (of the audio jack) goto the MCU pins the way shown below.

NB: i will be using the first setup for this tutorial. If you are using the second one, you will need to use T<baudrate> instead of N<baudrate> for the SERIN command on the picaxe. One other thing: The pin listed below are standard input and output pins. I am not using the standard pins connected to the download circuit as i have read they cannot work for reception (though the serial output pin CAN work for transmission.

IMPORTANT : if you are using PICAXE 20 or 08 check the "interfacing circuits" guide as there are additional components to be added in case you are using pin 3 as an input

If you are using the audio jack as suggested above (in fact you could also use some other methods like 9 pin female headers that get attached directly to the PC's serial port), here's a drawing that might help you out about which pin goes to which resistor and then to which pin.

conn23.jpg

(from www.world-educational-services.net)

Now you have your hardware set up properly.

VISUAL BASIC PART

First of all we'll start by making a program on VB. What you need to do once you installed it is make a new EXE file and add a component (right click on the components tab and the click component) and add (tick) the "Microsoft Comm Control 6.0" component, which enables serial communication through the PC's 9-pin serial port.

If you're not experienced with Visual Basic i reccomend the full walkthrough which you can find here: http://www.rentron.com/VisualBasic.htm

(it also includes MCU communication)

...if you have some experience with VB, you just need the following commands to make it work:

MSComm1.CommPort = (specifies the Port you are using)

MSComm1.Settings = "2400,N,8,1" (specifies the settings, in this case 2400 baud, no parity, 8 data bits, 1 stop bit, as used by PICAXE MCUs)

MSComm1.DTREnable = False (not really sure what this is, but the above walkthrough says it is necessary)

MSComm1.PortOpen = True (necessary for enabling the port, remember to close it at the end of the program)

MSComm1.Output = Chr$(Variable) (command used to send a variable to the MCU)

if you want a fully working example you can find it in the above link

...and now to the picaxe part

PICAXE PART

i'll just show you a very very simple program which tells you when and which variables you receive with the above commands.

---------------------

Main:

serin 0,N2400,b0

debug

goto Main

--------------------

if you also have your programming cable connected (in fact i was using two, one attached to the standard audio jack which i also use for programming that in this case worked out the debug function, and the other one shown above for the serial communication coming from Visual Basic) you can actually see the values of the variables sent by VB in the b0 variable! Amazing!

Very interesting!
Although i haven’t start to play with picaxe yet, your article is really interesting! (and I wish i could program a picaxe robot in Visual Basic… ^_^v )

Ah very cool! I’ve been
Ah very cool! I’ve been wondering how to work this out. I’m setting up a bot that records information over a period of time, and the whole “send data back to the computer after collecting” was kinda confusing me…

i still have to understand

i still have to understand properly (i haven’t even looked at it actually) the second part of that tutorial (from MCU to PC), but yes, i too think it is a very interesting thing! Some time ago i have made a program in VB which uploaded a file via FTP to an internet site. Combining these two programs would be very interesting. You could be having your MCU post its result directly on the net via a PC, so you could check them anytime anywhere.

:slight_smile:

And on the other side, you

And on the other side, you also easily control your robot from anywhere…

Do you know if it works in VB.Net?

(edit: well, i asked Uncle Goole, and yes it seems to be possible… :smiley: )

i don’t know much
i don’t know much unfortunately. If if you some other way of interfacing, software side i mean, feel free to add it to this walkthrough. Unfortunately VB is not the best option out there, but i don’t know how to use serial communication with other languages :frowning:

Don’t panic

It should be easier to do the PIC -> PC than it was to do the PC -> PIC, because you don’t have to worry so much about the receive buffer overflowing in a PC. You should just be able to squirt data out and the PC handles all teh low level stuff for you.

Lookin’ good so far!

atmega

can ya tell me how to set this up with an atmega32 or atmega8…

tanx