Jump to content
  • Advertisement
Sign in to follow this  
pheonix2468

VB & Serial Port

This topic is 4074 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone, I am making an arcade controller for my A level project in electronics. It will interface with the PC via a serial port and all the actions on the controller will go through a vb app and possibly run a simple game. Im not masking for code i would just like to know of any decent resources on the matter. I am using: VB 2005 i could use 6 also The PC's serial Port And a picaxe-28a (Chip) Are there any books on this i can buy or order to the UK?? Thanks a lot in advance :)

Share this post


Link to post
Share on other sites
Advertisement
I'm assuming you're using the PICAXE's SERTXD (or SEROUT) to transmit data to the PC. System.IO.Ports.SerialPort provides access to the PC's serial port. Its usage is fairly self-explanatory. [smile]

If you're going to be sending data back to the PICAXE, remember that the PICAXE can't cope with fast input of serial data (though the new 28X1/28X2 parts will resolve this issue, as well as have a SERRXD to receive data over the programming cable link).

Good luck with the project!

Share this post


Link to post
Share on other sites
Actually im being wierd, i read that the picaxe serialIn is RESERVED for transmitting the picaxe program onto it, so i assumed that sending dfata from a pc to that would overwrite and program on the chip with garbage.

What im doing is connecting an input and an output pin of the chip to the transmit and receive pins of the rs232(aka serial port).

The issue that i have is that this is the first time ive done this and most of its goin well apart from the PC side where i'm stuck on receiving whether the receive pin is high or low.

The main idea is to have a timer, and depending on how many times the receive pin has gone high each tick, say either, move the character up, down left or right. The picaxe chip is programmed already with a programme which tells it to go high/low a certain number of times depending on which microswitch is made.

Thanks alot for the reply ;)

Share this post


Link to post
Share on other sites
Quote:
Original post by pheonix2468
Actually im being wierd, i read that the picaxe serialIn is RESERVED for transmitting the picaxe program onto it, so i assumed that sending dfata from a pc to that would overwrite and program on the chip with garbage.
Nope. You can use SERIN to read data in. The problem is that if the PC sends a stream of bytes in rapid succession you'll miss some as your BASIC program won't be able to keep up!

Be warned that serial data lines operate at +/- 15V - which can damage the PICAXE is connected directly to the chip! The Interfacing Circuits datasheet demonstrates how to hook up the PICAXE to a serial port.

You will not be able to read serial data on the serial in download pin (though you can output on the serial out pin using SERTXD). You would need to move the serial in line to another pin on the chip when testing - but don't forget to hold the PICAXE's serial in line low as it will otherwise think it's receiving a new download and will not run properly.

Quote:
What im doing is connecting an input and an output pin of the chip to the transmit and receive pins of the rs232(aka serial port).
Make sure you're doing this carefully, as mentioned above!

Quote:
The main idea is to have a timer, and depending on how many times the receive pin has gone high each tick, say either, move the character up, down left or right. The picaxe chip is programmed already with a programme which tells it to go high/low a certain number of times depending on which microswitch is made.
This would probably not be very reliable (very timing reliant); sending the status serially would be very easy.

The serial port is designed for transmitting data serially; polling individual data lines is not very practical with it. The parallel port makes this all a lot easier, though in that case you might as well just connect the switches directly to the parallel port and do away with the PICAXE. Personally, I'd play to the strengths of the PICAXE; use its analogue to digital conversion to provide some analogue input, and broadcast the results serially (which is a lot easier than counting signals in a time limit).

Something like this:

Do
B0 = Pins
SerTxd (B0)
Loop




...would read the status of the inputs and broadcast them out. Reading bytes from the SerialPort class would read the status of the inputs.

To make it a bit more interesting I'd probably read a byte in (using SERIN) then switch on it - if I was sent an 'A' I'd sample an analogue input and send back the result, if it was a 'D' I'd sample the digital inputs and send back the result. I'm not sure what your project requirements are.

EDIT: I'm approaching this from the perspective of a rank outsider trying to put the PICAXE to best use; you no doubt have numerous limitations and requirements over what you can and cannot do (and what you must and must not do). Ignore any points that go outside the spec.

[Edited by - benryves on April 23, 2007 10:40:09 AM]

Share this post


Link to post
Share on other sites
So by using the serin/out i can send a string to the pc instead?? say
i caould make it send the string "Up" and then the vb can read that?

Hehe anyway looks as though i have a lot of work to do now, i mean i have to redesign my picaxe code, i can do that at home, and then redesign my PCB haha.
Thanks alot benryves you are very resourcefull ;) good website too i have both you java apps on my phone :)


Edit**
You seem pretty well knowledgable in this feild :D. so to connect both circuits directly, you think i can just use a simple voltage divider?.

Also before we go completely off topic you know any decent resources for the vb side of this?

[Edited by - pheonix2468 on April 23, 2007 1:19:05 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by pheonix2468
So by using the serin/out i can send a string to the pc instead?? say
i caould make it send the string "Up" and then the vb can read that?
It is indeed nice and easy:
SEROUT 0, N2400, ("Up")

(Not sure which pins are available for serial input/output).

You can check what the PICAXE is sending by using the serial terminal (press F8 in Programming Editor) once you've sent your program to the PICAXE. Make sure you select the correct baud rate.

Receiving a string on the PICAXE end would be more difficult, so I'd stick with single characters/bytes. Transmitting the pin status in a loop (as I demonstrated above) is not very efficient, and it would flood the PC with hundreds of duplicate messages. Much better to only transmit when the PC requests it or, more sensibly, when something changes (so a message sent by the PICAXE might be "Up pressed" or "Left released"). Transmitting "raw" data (as opposed to human-readable data) would be easier for the VB program to decode and use up less space on the PICAXE, though. Again there's a slight synchronisation problem; you need to know how many bytes to read and you don't want either the PICAXE or the PC to go out of synch.

To remedy this, if you go for text I'd recommend sending it in lines; this means sticking the carriage return/line feed sequence on the end of each message, like this:
SEROUT 0, N2400, ("Down", CR, LF)

The .NET SerialPort class has a handy method to read a line in one go (the aptly-named SerialPort.ReadLine() method), you see. [smile]

Quote:
Hehe anyway looks as though i have a lot of work to do now, i mean i have to redesign my picaxe code, i can do that at home, and then redesign my PCB haha.
Sorry. Hopefully you can see where I'm coming from, though... and hadn't already etched the PCB!

Quote:
Thanks alot benryves you are very resourcefull ;) good website too i have both you java apps on my phone :)
I just happen to use PICAXE chips, studied A Level electronics, and do a lot of .NET development. Though microcontrollers were pretty much barred from our projects (maybe programming was seen as cheating or something).

Quote:
so to connect both circuits directly, you think i can just use a simple voltage divider?.
Which circuits are we talking about? To connect the PICAXE to the PC, use one of the two circuits on page 43 of this datasheet (Advanced Interfacing 2 - Serial Interfacing to a Computer).

Quote:
Also before we go completely off topic you know any decent resources for the vb side of this?
MSDN is invaluable for all things .NET and VB related. You'll need to set up the serial port to no parity, one stop bit, no handshaking and probably (in this case) 2400 baud. If you'd like me to knock together some simple (commented) VB sample code, I'd be more than happy to do so.

Share this post


Link to post
Share on other sites
hehe thanks a lot mate :)

You know before reading the last post i already have implemented a lot, i spent a few ours working on it and i have a nice BASIC script and my VB is coming along nicely, i used the picaxe sheet and the MSDN to find these out :) Thanks alot

You know id like to create a tutorial on this as there isnt much on it :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!