Let's Make Robots!

Picaxe 08M with visual basic 6

Hi guys,

For the past few weeks I have been playing with Visual Basic 6 and attempting to get it talking to my picaxe 08M chip.  I have found a few tutorials online that are not exactly for this chip but I can follow and understand how they work (at least i think so).  My goal that I am trying to achieve is a simple off and on LED switch via VB6.  I have tried tweaking my code many times and going through various tutorials but I have had no success. Here is how i have been setting up.

I have the standard programing cable plugged in with the serial output of the cable going to pin 4 of my picaxe.

I have an LED hooked up to Pin 1 (this is the LED that I am trying to blink on and off)

After reading the manual I have come to understand that SERIN is the command to use on the picaxe end to listen for serial input.

Here is my picaxe code.

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

main:

serin 4,N2400,b1

if b1 = 0 then ahigh

if b1 = 1 then alow

goto main

ahigh:
high 1
goto main

alow:
low 1
goto main

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

And this is the Visual Basic 6 code: (I have 2 buttons set up, one to send a "0" for off and the other to send "1" for on)

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

Option Explicit

Private Sub Command1_Click()
MSComm1.Output = Chr$(0)

End Sub

Private Sub Command2_Click()
MSComm1.Output = Chr$(1)
End Sub

Private Sub Form_Load()

MSComm1.CommPort = 10

' 2400 baud, no parity, 8 data bits, 1 stop bit
MSComm1.Settings = "2400,N,8,1"

' Disable DTR
MSComm1.DTREnable = False

' Open the port
MSComm1.PortOpen = True

End Sub
----------------------------------------------------------------------

 

As far as this project goes for me, i have been trying for a few weeks now and I feel I am not getting anywhere. Not looking for a easy way out but more so someone to show me where I am going wrong as there must be something I am missing.

 

Thanks for the help guys :)

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Hey man,

Yeah i have tried swapping over the RX/TX lines. I have learnt from that mistake multiple times in the past also!

I have just started trying to send data the other way using this:

Main:
serout 0,N2400,(65)
pause 1000
goto main

 

In the picaxe terminal window, sure enough I can see A being received on repeat however when i open up my VB6 project, my textbox i have setup to display input does not display what I want. I am pretty sure that this means that its more so the VB side of things that is the problem and not so much the picaxe. Don't wanna give up on this though.

Thanks for the help again Chris

The following link, http://support.microsoft.com/kb/823179 , is for VB6 serial port communications.

One difference I see in your code versus the Microsoft code is

 

' Send the attention command to the modem.

        MSComm1.Output = "ATV1Q0" & Chr(13)

Your code, MSComm1.Output = Chr$(1), their code, MSComm1.Output = Chr(1). I know I paraphrased. I don't know the function of the dollar sign or no dollar sign.

One other "stupid" question. Do you know for sure you have comm port 10? I have read often times that Windows generates new ports as a USB -> serial convertor is plugged and unplugged.

 

Just checked out the link that you send through, Honestly, I am unsure of that the purpose of the "$" does but multiple examples I have found on the internet refer to it as Chr$(value). Just played around with the code again using what you suggested and still having no luck.  As I was saying to Chris in previous post, I am pretty sure that I am going to need to spend a few more hard hours studdying up on my VB coding as I think this is the problem area.

As for the Comm port, I have made that mistake many times and it has become second nature to check this every time I plug my cable in. lol. That one is an easy mistake to make sometimes.

Thanks again for the help dude!

As it seems to be some uncertainty about the VB program an if communication actually reaches the PICAXE, one test might be to turn on a LED right after the serin statement and pause. Then at least there should be a value in b1 (but if it’s 0 or 1 remains to be seen)

Hi guys!

After many days of frustration, I have got my picaxe chip talking with VB6!

It turned out to be a simple problem that I should have picked up (dont you hate when that happens). My serial input pin on my picaxe was left floating.  I wired this to ground and bingo!  Here is my code for anyone who is reading this trying to do the same thing in future!

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

My Picaxe code:

Hook up an LED to pin 2 and your serial input to pin 4. (DO NOT FORGET TO WIRE YOUR STANDARD SERIAL IN TO GROUND ;)  )

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

main:

serin 4,N2400,b1

if b1 = "H" then ahigh

if b1 = "L" then alow

goto main


ahigh:
high 2
goto main

alow:
low 2
goto main

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

Visual Basic 6 code,

 Add 2 command buttons, a text box and make sure you have your MSComm settings set the same as your picaxe!

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

 

Private Sub Form_Load()
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
MSComm1.PortOpen = True
End Sub


Private Sub Command1_Click()
MSComm1.Output = "H"
Text1.Text = "H"
End Sub

Private Sub Command2_Click()
MSComm1.Output = "L"
Text1.Text = "L"
End Sub


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

From there hopefully your LED clicks off and on!

Thanks to all you guys who helped out and kept me going!

the serial connection hooked up as shown in Manual 2 on page 199? 

Chris even mentioned that you would require the 10k and 22k resistors for a serial connection. Maybe you missed that comment. :)

Umm my problem that I was having was that when I unplugged my serial input pin after downloading my program, I would plug it into pin 4. This just left the Serial Input of the picaxe floating. What I did was a ran a wire from that serial to ground and bingo.  Manual 1 page 27 does actually state that it must not be left floating or the program will not run.  I now have 2 leds hooked up and a servo all controlled via VB6.  I am over the moon that I actually got it going (With everyones help ofcourse)

Once again I do thank everyone for their help! :)

I just wanted to make sure we were looking/talking about the same thing.

PICAXE Serial schematic

As you can see by the above schematic, the input pin is in fact tied to ground with the 10k resistor.