help for two way PC comm with 08m (vb)

Denzel

Senior Member
Okay, i need help help in solving a small visual basic (2005 ed.) problem.
Im sure your all tired of repetitive questions about visual basic when theres loads of information everywhere about it....

im using an 08m and i want to send information to the pc and vica versa using visual basic .

I know how to do this and im not asking how I go about this,
My problem is that the baud rate for sertxd is stuck at 4800 which is fine as I just set the baud rate for my programme (using Dim WithEvents serialPortcomm As New IO.Ports.SerialPort) in order to recieve data from the picaxe.

But heres my dilemma. When the pc sends information to the picaxe it sends it at the baud rate selected as above (4800) which you may well know that not only does the 08m not support serrxd but it also cannot serin using the 4800 baud rate. This proves a problem as I can only send data OR recieve data but not both as I have to change the baud rate.

Is there anyway of getting around this other than buying a picaxe that supports serrxd or the 4800 baud rate??

Heres the code......

'this is to connect the port and change settings so that information can be recieved

Private Sub btnConnect_Click(ByVal sender As Object, ByVal e As System.EventArgs)Handles btnConnect.Click

If serialPort2.IsOpen Then
serialPort2.Close()
End If

Try
With serialPort2
.PortName = cbbCOMPorts.Text
.BaudRate = 4800
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
End With
serialPort2.Open()

lblMessage.Text = cbbCOMPorts.Text & " connected."
btnConnect.Enabled = False
btnDisconnect.Enabled = True
Catch ex As Exception
MsgBox(ex.ToString)
End Try

' the following is an event when data is recieved onto the buffer from the picaxe using sertxd

Private Sub SerialPort_OnComm() Handles SerialPort.OnComm
ReceiveBuffer.Append(SerialPort.InputString)
Debug.WriteLine(ReceiveBuffer.ToString)
datapx = (ReceiveBuffer.ToString)
Updatelogs()
end sub

'this code below is to send a small string of data to the picaxe

Try
serialPort2.Write(txtDataToSend.Text & vbCrLf)
With txtDataReceived
.SelectionColor = Color.Black
.AppendText(txtDataToSend.Text & vbCrLf)
.ScrollToCaret()
End With
txtDataToSend.Text = String.Empty
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub

Any help with this would be much appreciated
thanks

Denz
 

hippy

Ex-Staff (retired)
Easiest option : You can force the 08M to up its SerIn baud rate to 4800 which is easy to do and will speed up comms throughput ...

- Do
- SetFreq M8
- SerIn RX_PIN, N2400,b0 ' Receives at 4800 baud
- SetFreq M4
- SerTxd( "<",b0,">" )
- Loop

Program that up then use the Programming Editor Terminal or a Terminal Emulator at 4800 baud and see everything you send echoed back.
 

moxhamj

New Member
Hippy's answer will work fine but why "My problem is that the baud rate for sertxd is stuck at 4800"? What is stuck - the picaxe or the computer or both?
 

Denzel

Senior Member
"stuck" is merely an incompetent use of slang referring, to and I quote, "The baud rate is fixed at 4800,n,8,1" as from the sertxd definition picaxe manual #2

I am in the process of making alterations to my vb code which I hope will solve this. something along the lines of the picaxe sending a byte which will be recieved at the wrong baud rate, this byte will be discarded but still triggers the "on comm", the baud rate will be changed until important data is recieved then the baud rate will be changed back.

I also considered changing the baud rate from 4800 to 2400 to send data to the picaxe and then changing it back so it is ready to recieve from the picaxe but i had errors with the picaxe data coming in.

thanks for the exceptions thus far. I will keep you posted
 

BCJKiwi

Senior Member
Just read the next few lines in the manual! - Its not stuck. 08M can run at 8MHz on internal resonator.

page 153
setfreq
Syntax:
setfreq freq
- freq is the keyword that selects the appropriate frequency
08M, 14M, 20M internal m4, m8

page 146
The baud rate is fixed at 4800,n,8,1
Affect of Increased Clock Speed:
Increasing the clock speed increases the serial baud rate as shown below.
4MHz 8MHz 16MHz
4800 9600 19200

i.e.
setfreq m8
will produce 9600 baud
 
Last edited:

moxhamj

New Member
Is there any reason you have to use the sertxd? You can use serout to pin 0 and set it at any baud rate.
 

hippy

Ex-Staff (retired)
Changing the baud rate on the fly in VB can be done but it is problematical; you have to ensure the transmit buffer is empty before doing so and receiving bytes at the wrong baud rate can trigger inconsistent and/or multiple error events. I've done it but it was much more complicated than I expected.

I'd definitely recommend altering the PICAXE code so SEROUT runs at 4800 or SERTXD runs at 2400 and not changing the baud rate within VB.
 

Denzel

Senior Member
update

right well i tried the setfreq and this seems to be working but its some very strange things are happening:

here is the picaxe code i am using..

main:
for b1 = 0 to 4 'this loop justy sends a series of example data
setfreq m4
sertxd(#b1)
pause 400
sertxd("None")
pause 400
sertxd("Small")
pause 400
sertxd("High")
pause 400
next b1 ‘ next loop
do 'this loop recieves at 8mhz and transmits a "t" and the number recieved
setfreq m8
serin 4,N2400,b2
setfreq m4
sertxd("t",b2)
loop
end


This is the data I get via the terminal

SmallHigh2NoneSmallHigh3NoneSmallHigh4NoneSmallHigh[so far so good..]t2t3t5t7t9t4t3[here the picaxe has recieved my numbers and sent them back complete with "t"]œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ[This is where it gets strange, the numbers i send don't come back at all instead i get this jargon this occurs randomly]0NoneSmallHigh1NoneSmallHigh2NoneSmallHigh3NoneSmallHigh4NoneSmallHigh[The programme has restarted which it definately shoudlnt have]

any information on this would be very helpful

thanks
 

moxhamj

New Member
Could be a delay. Could be data at double or half the baud rate partially synching. This is getting very complex for a quite simple task. See http://www.instructables.com/id/Automate-your-science-experiments/
for some minimalist code that uses serout to pin 0 at 2400 baud.

main:serin 3,N2400,("Data"),b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13
readadc10 1,w0' read the analog value on pin1 (physical leg 6)
readadc10 2,w1
serout 0,N2400,("Data", b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13)
goto main
 

hippy

Ex-Staff (retired)
Is the serial connected to both Serial In and the SERIN leg ? That would cause a 'restart' if the Serial In isn't pulled to 0V; as you type that gets interpreted as a download initiation, but not a valid one, so the PICAXE restarts execution.
 

Denzel

Senior Member
...

No the serin is not connected to the serial input I have a little switch much like that on the 08m starter kit. It programmes everytime without fail so I will try transmitting the data from the picaxe between longer intervals.

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

My aim if your interested is to control my radio controlled vehicle which involves tank tracks a robotic arm with 4 degrees of motion (4 servos + dc motor) with two way voice communication (via hacked walkie talkies), wireless video, 20 second non volatile sound recording infrared lighting for the camera and then my two sensors temperature and hydrocarbon gas sensor. all of which I have constructed myself, apart from the cameras and servos blah blah etc.

so far everything is working apart from the sensor side which i am yet to add. control is my main issue now and I have got a pair of 433mhz modules working and so I want to control this vehicle wirelessly from the computer via vb and get data wirelessly from the vehicle about temperature and gas levels (approximately every 20 seconds).

A nice little project that has kept me entertained for the last few months.
any suggestions would be appreciated.
 

Denzel

Senior Member
hmmm

Would grounding the serial in (programming pin) while using the serin 4 setup stop the programme restarting? does this pin float?

because this simple example code to force the serin to 4800 baud returns a bunch of "||||||||||||||||||||||||||||||"

Do
SetFreq M8
SerIn 4, N2400,b0 ' Receives at 4800 baud
SetFreq M4
SerTxd( "<",b0,">" ) 'or SerTxd( "<",#b0,">" )
Loop
 
Last edited:

Denzel

Senior Member
...

Hehe ok. i seem to have fixed it by grounding the serin pin with yet another switch.
Which just goes to prove that trial and error is far more effective than asking questions before you try anything.

thank you very much
 
Top