What information can I send to a PICAXE?

kamilan

Member
Hey there guys, just a quick query.

I've got a 08M and an 18X PICAXE. At the moment just using the 08M chip to test stuff. I've written some code in LabVIEW to send serial information to the PICAXE. LabVIEW is configured to output a string. I know that I can send strings. Can I send integers/numbers? I want to send a number from LabVIEW in the form of a string to a PICAXE chip. Then the PICAXE chip uses that number in a subroutine.

I thought,

serin 1, N4800_8, ("START"),w5

would work, as I output *START,1000* from LABVIEW thinking 1000 would be put into w5 but it doesn't.

Do I need to convert the 1000 into a special sort of format or?

Could someone shed some light on the matter please.

Thanks

Kamilan
 

boriz

Senior Member
You’ll need to think in terms of bytes. “1000” is a 4 byte string. To receive it you would need to receive 4 bytes.

Try this:
Code:
W0=1000
Do:loop
Run it in the PE simulator and look at the two bytes that make up W0 (B0 and B1).

B0 = 232 (%11101000) and B1 = 3 (%00000011)

So to get the number 1000 into the Picaxe, you’ll need to transmit these two bytes: 232,003

Make sense?
 

lanternfish

Senior Member
If b0 & b1 are to be used in word variable, w0, then surely the format would have to be:

Serin 1,N4800_8,("START"),b1,b0
 

Andrew Cowan

Senior Member
Transmit 3 then 232 into b0 and b1:

b0=%11101000 (=232)
b1=%00000011 (=3)

w0=%0000001111101000 (=1000)

A
 
Last edited:

hippy

Ex-Staff (retired)
Some confusion creeping in here ...

b0 is LSB of w0
b1 is MSB of w0

To get 1000 (decimal) into w0 ...

send 3 then 232 if reading with Serin 1,N4800_8,("START"),b1,b0 ' MSB first

send 232 then 3 if reading with Serin 1,N4800_8,("START"),b0,b1 ' LSB first
 

BeanieBots

Moderator
But can LAbView send "1000" as 3,232 ?
It might be that all four ASCII bytes need to be sent & received.
Serin 1,N4800_8,("START"),b3,b2,b1,b0

Then (written to show how it works rather than efficiently) get the number back.

b3=b3-$30
b2=b2-$30
b1=b1-$30
b0=b0-$30

w2=b3*1000
w3=b2*100
w4=b1*10

w5=w2+w3+w4+b0

I'll leave it to others to show a much more efficient way of doing it.
 

kamilan

Member
The Soluition

Hello,

I was wandering about this for a while, and the code is simple, but thank you for the suggestions.

serin 1,N4800_8,w0,#w1

This way, I can send serial information such as a chatacter(s) and/or output whole numbers.

ASCII "A" is decimal 65. Therefore code could look like this

symbol DIRECTION = w0
symbol SPEED = w1

Main:

serin 1,N4800_8,DIRECTION,#SPEED
if DIRECTION "S" then MotorSpeed
if DIRECTION "F" then MotorForward
if DIRECTION "B" then MotorBackward
goto Main

MotorSpeed:
pwmout 2,150,SPEED
goto Main

MotorForward:
etc

MotorBackward:
etc

This means, that using labview, I can send one ASCII character to determine the direction of the motor, and an ASCII number from 0 to 65535 when using an PICAXE chip to determine the speed. Mind you the PWMOUT on an 08M 400 is 100% dutycycle and 200 is 50% dutycycle and so on so forth.

Obviously there are ways to get around if you need larger numbers.
 
Last edited:

westaust55

Moderator
But SERIN and SEROUT only handle 8 bits at a time in each variable so you can only transmit and receive values 0 to 255.
More reading of the manual 2 required.

The protocol is fixed as N,8,1
 

kamilan

Member
There are 8 bits, and the maximum is 0 - 255 when using binary counting.

But, w0 consists of two two 8 bit numbers (b0 & b1) making the largest number to be sorted in w0 65535.

HOWEVER!!!

I dont understand the difference between using w0 and #w0?

Anyone shed some light on the matter?
 
Last edited:

SilentScreamer

Senior Member
The way to send w0 is to send b0 then b1 like this:

Code:
serout 7,N2400,(b0,b1)
If you do #w0 it will send each digit individually as ASCII characters i.e. If w0 is 5642 then

Code:
serout 7,N2400,(#w0)
will send 35 (ASCII for 5) then 36 (ASCII for 6) then 34 (ASCII for 4) then 32 (ASCII for 2).

I am not however sure if #w0 is valid syntax.
 

hippy

Ex-Staff (retired)
I dont understand the difference between using w0 and #w0?
Using "SERIN pin,baud,w0" will read a single 8-bit byte ( or 8-bit character ) value into w0.

Using "SERIN pin,baud,#w0" will read a stream of decimal digit 8-bit characters up to a non-digit character and convert the received representation into a 16-bit number value stored in w0.
 

kamilan

Member
Hippy,

Does that mean when using #w0 it is possible to cause an overflow error? My terminology is crap, but I'll try and explain.

If i continuously keep sending data (character after character) when will the serin command fail because there is only so much information w0 can store in terms of a number?

Cheers

K

***UPDATE***

I tried this code, and it works sweet. I can send information from LabVIEW in string format to control direction and speed. For forward and reverse, I will use PIN4 to toggle direction on the motor driver chip. :) Anyone needing help with LabVIEW and PICAXE give me a yell.

setfreq m8
symbol DIRECTION = w0
symbol SPEED = w1

Main: let direction = 0
let speed = 0

serin 1,N4800_8,("ABC"),DIRECTION,#SPEED
if DIRECTION = "S" then pwmout 2 , 0, 0 endif
if DIRECTION = "F" then MotorForward
if DIRECTION = "B" then MotorBackward
goto Main

MotorForward:
high 4
pwmout 2 , 199, SPEED
goto Main

MotorBackward:
low 4
pwmout 2 , 199, SPEED
goto Main
 
Last edited:
Top