display problems

axp

New Member
hello,

i have been trying to read out a temeprature from the DS18B20 with the picaxe 18X... then i send it to a display but i think i have to convert the value first... i used this basic test program

init: pause 500
i2cslave $C6,i2cslow,i2cbyte
writei2c 0,(254,1,255)

main: readtemp 1,b1

b2 = %1111 & b1
writei2c 0,(254,128,255)
pause 10
writei2c 0,("temp:",$b1,255)
end


i get "temp:" but then a realy strange symbol... anybody an idea how to get de decimal value?

Grtz
 

hippy

Ex-Staff (retired)
Welcome to the PICAXE forum.

ReadTemp b1
BinToAscii b1,b2,b3,b4
WriteI2c 0,("temp:",b2,b3,b4,255)
 

axp

New Member
thank you,

now i have the problem that i have strange character for b1, and b2-b4 are just zero, i think the conversion of the DS18B20 is wrong, or should itbe the i2c protocol that is messing the thing up?
 

BeanieBots

Moderator
Add either a sertxd or debug to your code and see what the values actually are. That will at least eliminate any I2C/display problems from the equation.

EDIT:
Thread moved to active forum
 
Last edited:

axp

New Member
and what does this sertxd do? i don't understand, i fee lstupid now! it is in basic and i have been messing with this for 2 days now... :(
 

BeanieBots

Moderator
Just add a line to the code suggested by hippy.

ReadTemp b1
BinToAscii b1,b2,b3,b4
WriteI2c 0,("temp:",b2,b3,b4,255)
debug

When you download, a screen will appear which will show all the variable values.

Alternatively add the line
sertxd (#b2,#b3,#b4)
and you will be able to see the values in the terminal window (f8).

Both "debug" and "sertxd" are very useful commands for debugging code and variable values.
Both commands are explained in more detail in the manual.
 

hippy

Ex-Staff (retired)
sertxd (b2,b3,b4)

The variables have already been converted to ASCII character values :)
 

axp

New Member
if i run the program and i press F8 i get this:
is 0
ððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððZ‘<0The value is 0
ððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððZ000The value is 0
ððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððZ

so the value is still 0 :confused:

the program i used is

init: pause 500
i2cslave $C6,i2cslow,i2cbyte
writei2c 0,(254,1,255)

main:

ReadTemp 18,b1
BinToAscii b1,b2,b3,b4
' sertxd (b2,b3,b4)
WriteI2c 0,("temp:",b1,b2,b3,b4,255)
debug
 

hippy

Ex-Staff (retired)
WriteI2c 0,("temp:",b1,b2,b3,b4,255)

That wasn't what was suggested, try ...

WriteI2c 0,("temp:",b2,b3,b4,255)
 

MartinM57

Moderator
I'm confused - sending ascii strings across i2c, trying to write to the terminal window with writei2c, axp reporting a terminal window that says "The value is 0" when that literal isn't in the code....
 

axp

New Member
ok i tried this now but when i measure the data pin it is always on 'gnd'...

conclusion i still doens't work. i connected the data pin to pin1 of the picaxe (input2)

do i have to write readtemp 1,b1 or readtemp 2,b1
 

BeanieBots

Moderator
When writing code, you must refer to input/output pin numbers and NOT the actual chip leg numbers.
So, leg 1 on the 18X will be input 2

To read a sensor on leg 1, you must refer to PIN 2

Try readtemp 2,b1
 

Andrew Cowan

Senior Member
Have you tried:

main:
readtemp 2,b1
sertxd (#b1,13,10)
goto main

Then press F8 to open the serial terminal when it is running.

A
 

axp

New Member
ok, now it works kind off, we have a temperature of 44 , in finland :p

the strange thing is we have the data line of the sensor is in pin 18 (input 2) and the code says 'readtemp 1,b1' and it works! i don't understand...

does anybody how to shift a binary number with the 18X

thanks for the help already, i am going somewhere now
 

BeanieBots

Moderator
You are getting "legs" and "pins" mixed up.

For example, to read a sensor on input 1, (leg 18) you use readtemp 1,b0
For input 2 (leg 1) you use readtemp 2,b0

Same for outputs.
To make output 7 go high (leg 13) you use high 7.


What do you mean by "does anybody how to shift a binary number with the 18X"

Do you mean a binary shift as in multiply/divide by two?
 

BeanieBots

Moderator
The special shift commands "<< and >>" only work for X1/X2 parts.
To shift on an 18X, you will need to use a multiplier of the desired number of *2 (or /2) shifts.
eg to shift b0 left by four bits "b0=b0*16".
 
Top