Author Options:

Serial communication between PC and picaxe 28X2 Answered

I am having problem in communicating with PC with Picaxe 28x2. Please help me in solving this problem as it is a very important project

My aim is to send the values of w1 and w2 variables ( values of the ultrasonic range sensors 1 and 2 ) to the PC and display them with the help of VB

my picaxe code is ...,

#picaxe 28x2
pulsout C.1,2
pulsin C.1,1,w1
pause 10

pulsout C.2,2
pulsin C.2,1,w2
pause 10

pause 100

goto main

and my VB code is ,

Imports System.IO
Imports Strings = Microsoft.VisualBasic
Public Class Form1
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer)
Dim WithEvents serialPort As New IO.Ports.SerialPort
Dim PicaxeRegisters(0 To 1) As Byte

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Timer1.Enabled = True
Timer1.Interval = 5000
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Call SerialTxRx()
End Sub
Sub SerialTxRx()
Dim labelstring As String = ""
Label1.Text = ""
If serialPort.IsOpen Then
End If
With serialPort
.PortName = "COM1"
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8 ' 8 bits
.StopBits = IO.Ports.StopBits.One
.ReadTimeout = 1000
.Read(PicaxeRegisters, 0, 2)
End With
For i = 0 To 1
labelstring = labelstring + " " + Str(PicaxeRegisters(i))
Label1.Text = labelstring
Catch ex As Exception
Label1.Text = "Timeout"
End Try

End Sub

End Class

I have not included the write command, since I have not included qualifiers in the picaxe code.

The Picaxe chip is sending the values ( I used the terminal in picaxe programming editor to realise this) but the visual basic is not displaying me the actual values sent by the picaxe chip. It is showing random values instead ... So i think that there is an error in the VB code.

Thank You 


The forums are retiring in 2021 and are now closed for new topics and comments.