serin combining

hi,

im using a serin [3000,lost],c.5,N9600_16,("SUMMER"),b2,b3,b4,b5 command

ive assume that b2 can only accept numbers between 0-9 so have added further b's

I want the set a temp hence b3,b5,b5 for example 37.5 but with out the .

so I want to convert b3,b4,b5 (375) in to a w1 value so it can then be compared with a ds18b20 data. can these be combine into w1 value somehow?
 

inglewoodpete

Senior Member
Configured as you have in your post, b2 to b5 can receive 8-bit bytes (Values 0-255).

What actually arrives in each byte will depend on what is sent from the sending end.
 
hi,

i cannot get it to recive any more than 0-9 per b"x" hence using 4 b"x" the build up the number to assemble a w1 value
 

Goeytex

Senior Member
Further to the other replies.... I cannot make heads nor tails of your actual problem. Please tell us EXACTLY what is being sent to serin and the source . According to your partial code, there is a qualifier "SUMMER", and then 4 more bytes.

So please post your complete code and a better description of the problem so that folks can make sense of the problem and what you may need to solve it. If this is two Picaxes communicating with each other, provide the code for both.
 

hippy

Technical Support
Staff member
i cannot get it to recive any more than 0-9 per b"x" hence using 4 b"x" the build up the number to assemble a w1 value
I suspect you are not receiving values 0-9 but ASCII characters "0"-"9". As others have said you need to post the program which sends to the PICAXE, then the two can be adjusted in parallel with each other to achieve what you require.
 

westaust55

Moderator
In the absence of full information about the format of the data being sent to the PICAXE, what do you see if you replace:
serin [3000,lost],c.5,N9600_16,("SUMMER"),b2,b3,b4,b5​
with the following:
serin [3000,lost],c.5,N9600_16,("SUMMER"),#w1​
#’s are for inputting ASCII decimal numbers into variables, rather than raw characters.
The incoming data must terminate with a non-digit character to complete the entry for word variable W1.
 
intailise:
;18m2
setfreq m16 ; 16mhz
symbol relay=b.6
w12=2200 ; set intail temp of 22.00C

main:

serin [9000,lost],c.5,N2400_16,("SS"),b21,b22,b23

let w12=b21*1000
let w7=b22*100 ;combine and make up new w12 value
let w13=b23*10
let w12=w12+w7+w13

lost:

Readtemp12 c.7,w1 ;read in result ds18b20
; convert data
let b9 =43 ;Display + (43) space (32)
IF W1 > 64655 THEN ;info - 55 degrees = 64656
let b9 =45 ;Display - (45)
W1 = - W1 ;info if - ie w1=1000 display - 10.00 C
ENDIF
W1 = W1 * 25 / 4;info + ie w1=8500 display 85.00 C
;BINTOASCII w1,b8,b7,b6,b11,b10
;IF b8 = "0" THEN : b8 = " " :ENDIF ; zero blanking b8
;IF b8 = " " AND b7 = "0" THEN : b7 = " " :ENDIF ; zero blanking b7



w8=w12-30 ;bottom temp total 0.60c range
w9=w12+30 ;top
if w1<w8 then high relay ;compare
elseif w1>w9 then low relay
endif
DEBUG
goto main
 
If you are receiving ASCII (not raw values) try this

let w12=b21 - 48 *1000
let w7=b22 - 48 *100 ;combine and make up new w12 value
let w13=b23 - 48 *10
 

westaust55

Moderator
If you are needing to use the program lines:
serin [9000,lost],c.5,N2400_16,("SS"),b21,b22,b23
let w12=b21 - 48 *1000
let w7=b22 - 48 *100 ;combine and make up new w12 value
let w13=b23 - 48 *10
let w12=w12+w7+w13

This can be reduced to
serin [9000,lost],c.5,N2400_16,("SS"),b21,b22,b23
w12 = b21 -48 * 10 + B22 -48 *10 + b23 &#8211; 48 * 10​

or,

as per post 7 you may be able to reduce this to:
serin [9000,lost],c.5,N2400_16,("SS"),#w12​
however, whatever is sending the data will need to send a non digit character (ie other than &#8220;0&#8221; to &#8220;9&#8221;) to terminate the input.
 

Jervis

New Member
Love that line. I will use it myself on my satnav program.

w12 = b21 -48 * 10 + B22 -48 *10 + b23 &#8211; 48 * 10

Thanks Westy!
 

hippy

Technical Support
Staff member
And even more efficient ...

w12 = b21 * 10 + b22 * 10 + b23 - 5328 * 10

That final *10 will not be needed for simply converting a three digit ASCII number to binary.
 
Last edited:

hippy

Technical Support
Staff member
Isn't the "magic number" 5328 ? (4800 + 480 + 48)
Absolutely right. And you have just revealed an MS-Calculator feature I wasn't aware of; that it takes into account precedence rather than being left to right ala PICAXE.

Seems no one else has ever noticed and it's not the first time I've made that mistake on the forum!
 
Top