PC > PICAXE

Lliam20789

New Member
A quick question:

To control a servo;
When I use the PICAXE terminal program to send data to a PICAXE chip (08M) Receiving with:

serin 3,N2400,b1

I can only receive the first number...
So "213", returns "2"

The next step I took was:

serin 3,N2400,b1,b2,b3

This did receive a three digit number, slightly unreliably, but then how can I drive a servo with the data in 3 separate bits?

Help with either the serial input or combining 3 bits would be much appreciated.

Code:
Main:
serin 3,N2400,b1
serout 0,N2400, ("recieved ",b1,cr,lf)
servo 4,b1
pause 10
A quick question:

To control a servo;
When I use the PICAXE terminal program to send data to a PICAXE chip (08M) Receiving with:

serin 3,N2400,b1

I can only receive the first number...
So "213", returns "2"

The next step I took was:

serin 3,N2400,b1,b2,b3

This did receive a three digit number, slightly unreliably, but then how can I drive a servo with the data in 3 separate bits?

Help with either the serial input or combining 3 bits would be much appreciated.

<code><pre><font size=2 face='Courier'>

Main:
serin 3,N2400,b1
serout 0,N2400, (&quot;recieved &quot;,b1,cr,lf)
servo 4,b1
goto main

</font></pre></code>

Thanks,
Lliam.
 

BeanieBots

Moderator
Each of the digits will be the ASCII value.
For the numeric digits, this is the actual number plus $30 in hex or &quot;0&quot; in ASCII.
Therfore, to get from &quot;213&quot;, read in each digit and subtract $30 from each digit and then multilply by 100 or 10 depending on its position and sum them all up.
b0=&quot;2&quot;
b1=&quot;1&quot;
b2=&quot;3&quot;
in conventional maths:-
w3=(b0-$30)*100+(b1-$30)*10+(b2-$30) or
w3=(b0-&quot;0&quot;)*100+(b1-&quot;0&quot;)*10+(b2-&quot;0&quot;)

Edited by - beaniebots on 20/08/2007 08:09:47
 

hippy

Technical Support
Staff member
You can also use -<code><pre><font size=2 face='Courier'>serin 3,N2400,#b1 </font></pre></code> Type your number then press return.
 

steliosm

Senior Member
Lliam0002 exactly what Hippy said.
Be careful not to over-turn the servo. Values are generally between 75-225 but this has also to do with the servo it self. I usally move the servo between 80 - 220.
Just to be on the safe side put a couple of IF statements to check for values lower that 80 and greater that 220.
 

Lliam20789

New Member
Thankyou everyone,
I did try:
serin 3,N2400,#b1
But this didn't seem to work.. well I'll try it again this morning.

Thanks again,
Lliam
 

Lliam20789

New Member
I tried both of these ideas but neither of them worked...
BeanieBots returned a three digit ASCII number using the following code:

<code><pre><font size=2 face='Courier'>
Main:
Serin 3,N2400,b1,b2,b3
b3 = b3 - $30

b2 = b2 - $30
b2 = b2 * 10

b3 = b3 - $30
b3 = b3 * 100

w1 = b1 + b2 + b3

servo 4,w1

serout 0,N2400,#w1

pause 10
goto main
</font></pre></code>

Note: The &quot;#&quot; used in serial out is the only way to get the terminal to read the correct value.

&quot;Serin 3,N2400,#b1&quot;, does not return any value in the same program without the maths or the &quot;#&quot; in the serout line.

Can someone post a working code... please...

Thanks again.
 

hippy

Technical Support
Staff member
<code><pre><font size=2 face='Courier'>Do
SerIn 3,N2400,#b1
SerOut 0,N2400,(#b1,CR,LF)
Loop </font></pre></code> Should be working code. You have to enter a number ( one to three digits ) then return, space or some other non-digit ... because it doesn't otherwise know when the number has ended.

Edited by - hippy on 21/08/2007 13:49:16
 

BeanieBots

Moderator
Try replacing w1 with w3.
W1 is made up from b2 &amp; b3 so your code is corrupting the values with effects I wouldn't want to try and predict.

I've never tried using the # directive with serin but it works fine for serout. I have every faith that Hippy's code will fine and that some other error has occured within the values in your code.
 
Top