DS1307 output to ascii..

cactusface

Senior Member
Hi,
Having just got my Picaxe TestBed up and running.. I can't get the RTC output on to the LCD in the right format, sure I need to convert it, will BCDTOASCII do the job, looks like it might..

I pinched this code off the forum it was a reply that worked for someone, but for me the lines between****************** give syntax errors, ie. &amp not reconized, etc. I can't say I understand most of it, I see there's some masking off of nibbles, but what does +"0&quot do??

TIME: i2cslave %11010000, i2cslow, i2cbyte
readi2c 0, (seconds,mins,hour,day,date,month,year)
pause 10
i2cslave $C6,i2cslow,i2cbyte 'set up i2cslave for LCD
********************************
b1 = mins & $0F + "0"
b0 = mins / 10 + "0"
b3 = hour & $0F + "0"
b2 = hour / 12 + "0"
b5 = date & $0F + "0"
b4 = date / 17 + "0"
b7 = month & 4 + "0"
b6 = month / 0 + "0"
********************************
writei2c 0,(254,134,255) 'move to line 1 position 8
pause 10
writei2c 0,("TIME",255) 'output text
pause 10
writei2c 0,(254,193,255) 'move to line 2 position 2
pause 10
writei2c 0,(b2,b3,":",b0,b1," ",b4,b5,"/",b6,b7,255)
goto time

but for me it just gives errors when I try running it, my LCD is via the serial firmware chip, so changed the i2c commands to serout, but no good. My serial is on c.1 of 40x2 picaxe.

Come on brainybots someone must know, thanks for you help.
Regards
Mel.
 

westaust55

Moderator
That code form the archives suffered when Rev Ed went to a new forum.
Here is a tidied up version:

Code:
TIME: i2cslave %11010000, i2cslow, i2cbyte
readi2c 0, (seconds,mins,hour,day,date,month,year)
pause 10
i2cslave $C6,i2cslow,i2cbyte 'set up i2cslave for LCD
********************************
b1 = mins AND $0F + "0"
b0 = mins / 10 + "0"
b3 = hour AND $0F + "0"
b2 = hour / 12 + "0"
b5 = date AND $0F + "0"
b4 = date / 17 + "0"
b7 = month AND 4 + "0"
b6 = month / 0 + "0"
********************************
writei2c 0,(254,134,255) 'move to line 1 position 8
pause 10
writei2c 0,("TIME",255) 'output text
pause 10
writei2c 0,(254,193,255) 'move to line 2 position 2
pause 10
writei2c 0,(b2,b3,":",b0,b1," ",b4,b5,"/",b6,b7,255)
goto time
you need a series of SYMBOL statements to define the variables
seconds,mins,hour,day,date,month,year

To change the values the the variables to ASCII one way is to add $30 or "0" to the value of each digit.
The existing lines of code do that already for you

Alternatively, as you suggest, you can also use the BCDTOASCII command to "automatically" convert the seconds. mins, hours, etc value read from the RTC into two ASCII code digits representing the 10's and units
 
Last edited:

westaust55

Moderator
With respect to the hours when read from the DS1307, you will need to consider if the DS1307 is in 12 or 24 mhour mode and mask the hours value accordingly.

(1) If you are going to be using a value greater than 11 for hours, then you must also set and look at bit 6 to indicate you are using a 24 hour clock mode.
So $16 OR $01000000 = = > $56.
(2) If you are going to use 12 hour clock mode you must set and look at bit 5 instead for a PM indicator

I gave an example of code for this in another question on this forum a while back. Sorry cannot quickly locate and off to do other things now . . . .
 

westaust55

Moderator
Mel,

I found the thread I mentioned last night (after trying a different search) about the 12/24 hour mode wherein I had given a solution:
http://www.picaxeforum.co.uk/showthread.php?t=11925 and in particular see page 3.

I note in your other thread about your new board the LCD display has a number > 59 for the minutes.
Just a guess, but could it be related to this topic and you have the variables for hours and mins swapped around?
 

cactusface

Senior Member
Got the right time?

Hi one and all,
Well I've played with BCDTOASCII, got it wrong to start, looked at some of the links and coding that you chaps pointed me to...

And guess what I can now tell the Time (and Date) and get it on the screen, no problems yet, and I've left it running for over 24 Hours, perhaps I should switch it off for a day and check it's still OK.

I added a line to read the temp from a DS18b20 on pin c.0, (40x2) but all I get is 85c which according to the data sheet is the default reset value.

I will upload a picture and code, if someone could say well this is wrong, I could sort it out, but copied it from the manual....
Regards
Cactus
 

Attachments

westaust55

Moderator
DS18B20 not working

Your code my be okay but looking at various of your recent photos, I cannot see a 4.7k Ohm resistor from the DS18B20 data line to Vcc (+5V).
Have a look at the diagram on page 155 of PICAXE Manual 2 (currently rev 6.9)
 
Last edited:

cactusface

Senior Member
DS18B20 not working

Hi Wes,
Yes I did'ent spot the missing pull up until I ran the program, and wondered why it did'ent work. So I added the 4k7 resistor! as per manual, still no joy it still only reads back 85c! I may try adding a delay before reading the temp, otherwise I don't know the answer. I have a spare DS18b20 to try...
Any ideas anyone?
Regards
Cactus
 

westaust55

Moderator
Look at the DS18B20 datasheet and make sure that you have the +5V and Gnd pins correctly connected (that is, not swapped).
http://datasheets.maxim-ic.com/en/ds/DS18B20.pdf

Supply pins reversed can seemingly lead to an erroneous fixed value being received and every likelihood of "frying" the temp chip. Note that the TO-92 case diagram is a bottom view.

a fixed value of 85degC can also be related to timing issues writing the command to the DS18B20.

Suggest that you do not use the parasitic power method. That has been a cause of problems such as fixed value of 85degC.
 
Last edited:

cactusface

Senior Member
DS18B20 not working

Hi Wes,
Nice idea but no the things in the right way around, but to make doubley sure I have fitted a new DS18b20, checked with meter all OK. added a pause 1000 before and after the readtemp, still no good! But on first powering up I get 0c then the next read reverts to 85c. I am using port C as a general I/O port as by default i2c is on there, so I added the serial line for the LCD serial chip on c.1 and the DS18b20 on c.0, is there anything wrong there?? Not configured the port with DIRS has it's a bit of a mix.

What ever happend to POR or Power On Reset like the old pics used to use! A small cap of a few mF from the reset pin to ground, this holds the reset pin low for a time allowing the power to stabilize, and other devices to get up and running.

regards
Mel.
 

hippy

Ex-Staff (retired)
I am using port C as a general I/O port as by default i2c is on there, so I added the serial line for the LCD serial chip on c.1 and the DS18b20 on c.0, is there anything wrong there?? Not configured the port with DIRS has it's a bit of a mix.
Try stripping your code down to just the READTEMP and see how that fares. I'll test with a 40X2 in a short(ish) while and see how that goes for me ...

#Picaxe 40X2
#Terminal 9600
#No_Data
#No_Table
Do
ReadTemp C.0, w0
SerTxd( "Temp=", #w0, CR, LF )
Loop
 

hippy

Ex-Staff (retired)
Tested on 40X2-5V ( tested with 3V3 and 5V PSU ), Firmware B.0, Programming Editor 5.2.7, AXE090 development board, and the DS18B20 test code works perfectly for me on the C.0 pin.

I added a SEROUT on C.1 and issued an I2CSLAVE command to enable I2C and it's still running just fine. I suspect a wiring error or possibly a damaged DS18B20. Note that READTEMP does return 0 ( and quicker than 750ms ) if not connected.

With regards to the POR reset-slugging capacitor; that trick I believe can be used with any PICAXE's which have a Reset line.
 

cactusface

Senior Member
DS18B20 not working....Still

Hi Hippy,
Thanks for the suggestion, but it did'ent work! But glad to see it worked for you. I have replaced the DS18b20 and even put it on another pin C.7 but it still returns 85c on the LCD or an constant 10751 in the terminal, even with a little warming.

I really am at a loss now! As I have only just built this board, must check that the ports are wired up right, be a so and so if port C is really port D?? etc...

Idea try reading a pin where I know it's not! will that return 0 or 85c most likely 0.

I see there seems to be a few folks with similar problems, looking at other post and threads.

Regards
Cactus
 

hippy

Ex-Staff (retired)
I have replaced the DS18b20 and even put it on another pin C.7 but it still returns 85c on the LCD or an constant 10751 in the terminal
Not quite sure how you're getting "85" on an LCD and "10751" in Terminal unless that's a typo. Perhaps post your code. It may be working but duff code.

I'd test it on a breadboard if I were you, that way you'll know if it works there you've got a board problem otherwise you'll never know if it's a board problem, a DS18B20 problem, or possibly both.
 

Technical

Technical Support
Staff member
The power up reset value of the DS18B20 internal result register is 85 (see the datasheet Table 1), so that clearly indicates that your chip is talking ok and responding but not doing new temperature conversions.

Are you sure is is a DS18B20 (not an DS18S20 or DS1820)
 

cactusface

Senior Member
DS18b20 still not working..

Hi,
Just before I get myself to bed, tried it on a breadboard same result on port D, pin 7. Made sure it was powered the right way and had the 4k7 pull up. Faulry Picaxe faulty software (it's so easy, how could you get it wrong!!) faulty editer software or downloading, but there again everything else works OK. But this is the 3rd DS18b20 I've tried.. (good job they were FREE)

It's just got to be something stupid that I can't see, but what. Just a thought! should the pin start high or low, does it matter?
Regards
Cactus
 

hippy

Ex-Staff (retired)
It shouldn't matter. Please post the exact code are you running, and can you post a picture of the breadboard setup.
 

cactusface

Senior Member
DS18B20 not working....Still

Hi Hippy and Wes, etc .

Thanks for all you help and ideas, but I just can't get it to work. hippy as you suggested I used that basic bit of coding you posted, and the terminal shows, Temp=85, but to make sure I stuck it on a breadboard and changed it to Port D on pins 0 or 7 with the same result.

I think one of you may have said that if it's returning 85c then at least there's some kind of communication there, and that makes sense! So what is the problem, tried 2 or 3 DS18B20's. Checked for power and right connections, and pull up, etc. Used different ports.... What next?? As this is a new build, checked ports do connect to picaxe on the right pins, etc. No mix ups!
Here's a pic of the breadboard set up.
Regards
Cactus
 

Attachments

hippy

Ex-Staff (retired)
Your code runs fine for me on a 40X2-5V. No RTC connected nor LCD and I had to change to -

SerTxd ( #b20, CR, LF )

I suggest you put the 40X2 on the breadboard and see if that works. Both C.0 and D.7 worked for me.
 

eclectic

Moderator
@Mel.

I'm trying hard to get this circuit
not to work.

I'm failing.

Program
Code:
#picaxe 28X2 

main:
readtemp c.0,b0
sertxd (#b0,cr,lf)
pause 1000
goto main
 
 
 #rem
 also works, with pin modifications
 
 for 08M  18X ..
See Tech's comment, post #15,
and all the other suggestions please.

e
 

Attachments

cactusface

Senior Member
DS18B20 not working....Still

Hi,
OK to add to the mystery? I have now put the DS18b20 onto another board, this was the first test/programming board I made, added a Picaxe 18x. Used the bit of code that Hippy posted, modified it for the 18x and if I use b0 or w0 I still get a consistant 127 from the terminal, even if I try warming the DS18b20. I can only think their faulty but all 3 of them!! WE? have tested the software, I have checked and double checked the connections for correct power, pull up, etc... what's left.

Or am I being a bit blind?
Attached image and code.
Regards
Cactus.
 

Attachments

hippy

Ex-Staff (retired)
Looking at your 18X photo, it's not entirely clear but it looks to me like you have the sensor going to leg 2 ( Serial Out ). You are reading Input Pin 2 in your code, which for an 18X is leg 1.

The problem with moving the sensor from board to board and not onto breadboard with a PICAXE on that breadboard is that no one can look at it and say "that's right" with any degree of confidence. Though your boards and wiring may be perfect, have no faults, an independant observer cannot see that for themselves nor say that it is right. Thus a 'possible board fault' has to be added to the list everytime.

I'm also confused by the inconsistency of results; originally it was "all I get is 85c" and in post #13 "still returns 85c on the LCD or an constant 10751 in the terminal", now with the 18X you say, "I still get a consistant 127 from the terminal". Maybe that is simply interaction of the sensor on the Serial Out line ?

I don't know how robust the DS18B20 is - mine have survived various faults include having power reversed, but I may have been lucky. It's a single wire interface so it is possible it could be trying to drive the bus while the bus is being held high or low which could cause damage. A faulty circuit configuration could damage every sensor plugged in, once damaged you may never get any to work properly again. A damaged sensor could also damage any PICAXE it is connected to. You could simply be digging a big hole and causing domino effect damage.

I've seen a company's entire backup wiped out because an 'engineer' wouldn't accept that it was the drive at fault destroying whatever was inserted and kept trying backup after backup. Not a pretty sight to watch.

My next step would be - Get a new, never been used, DS18B20 and a new, never been used, PICAXE and build the minimal circuit on breadboard, test there with the simple code example. Use a Lab PSU for powering. If any mistakes or wiring errors, over-current indications, start again with new, unused components.

If that doesn't work I'd suspect your DS18B20 aren't actually DS18B20. If marked as such maybe a faulty batch or fake chips - where did you source them from ?

As eclectic suggests; post a photo of the sensor's markings. I'd double check they are DS18B20 before doing anything further.
 

MartinM57

Moderator
So this thread pushed me into getting that DS18B20 that I've had in a plastic bag for a couple of months out and wiring it up to pin B.0 on a 20X2...I've never used one before (DS18B20 that is)...
Code:
#PICAXE 20X2
#no_data
#no_table
#terminal 9600

main:
	readtemp B.0,b1               'read sensor on pin 0 into b1
	if b1 > 127 then negtemp      'test for negative
	sertxd (#b1)                  'transmit value
	goto endloop
	
negtemp:
	b1 = b1 - 128                 'adjust neg value
	sertxd ("-",#b1)              'transmit value

endloop:
	sertxd (" degrees", CR, LF)   'tidy up output

goto main
Sorry cf - it worked first time...
 

cactusface

Senior Member
DS18B20 you know the one!

Hi Folks,

Mr E well here's the picture, I can't see anything in the data sheet that suggest it's not a normal version. And Hippy they came direct from Maxim. I see what you mean about the breadboarding, I can see it's right and know its OK, but an outside observer?? the connection was to pin 1 which is A.2 on the 18X. As for the various different results! I can't say other than that's what they were.

Could I have a faulty Picaxe, I only got it a couple of weeks ago? You suggested I try a new one! It would explain some of the funny results and none working parts..... I'm fairly careful with them avoiding static, use a good low voltage/leakage iron, good sockets, etc.. OK perhaps I'll order a new Picaxe, etc and see, as you say breadboard it

Think I might just carry on with the project anyway, I still have to give my buggy-bot some IR front eyes, build my Function Gen (not Picaxe).
Regards
Cactus

Ho Dear just took a look at the Maxim site this is the Parasite!! Version, with no + connection, but it states that the + pin is not connected so should it matter, as the other pins are connected correctly. I'l get back to you soonish.
 

Attachments

Last edited:

Andrew Cowan

Senior Member
I've been DS18B20ing as well, and one of mine is stuck on 127. I know the PCB works (with another one of the same type) - thus I must have blown it up. If the parasitic thing isn't the problem, maybe you've just broken it (as I have).

A
 

hippy

Ex-Staff (retired)
@Andrew : Thanks for the information aboout the "127" value.

It could be that the DS18B20-PAR was operating but not working with a PICAXE and has given up the ghost along the way.

The datasheet I have for the PAR version says software compatible with the DS1822-PAR but oddly doesn't mention any compatibility or not with DS18B20. Can't be bothered going through the spec a line at a time to see if it differs.

It's not clear if pin 3 "NC - No connect" means not connected internally or "do not connect". The spec says it can handle 5V on all pins so, they may be undamaged and operational even if they won't work with a PICAXE.
 

westaust55

Moderator
@Andrew : Thanks for the information aboout the "127" value.

It could be that the DS18B20-PAR was operating but not working with a PICAXE and has given up the ghost along the way.

The datasheet I have for the PAR version says software compatible with the DS1822-PAR but oddly doesn't mention any compatibility or not with DS18B20. Can't be bothered going through the spec a line at a time to see if it differs.

It's not clear if pin 3 "NC - No connect" means not connected internally or "do not connect". The spec says it can handle 5V on all pins so, they may be undamaged and operational even if they won't work with a PICAXE.
From datasheet:
http://datasheets.maxim-ic.com/en/ds/DS18B20-PAR.pdf

pin 3 = NC = "No Connect. Doesn’t connect to internal circuit."​

Note also:
"To assure that the DS18B20-PAR has sufficient supply current, it is necessary to
provide a strong pullup on the 1-Wire bus whenever temperature conversions are taking place or data is
being copied from the scratchpad to EEPROM. This can be accomplished by using a MOSFET to pull
the bus directly to the rail as shown in Figure 2."
 
Last edited:

cactusface

Senior Member
DS18B20 not working.... Oh dear

Hi,
Well Wes I think you have it! I looked up the DS18B20 P version and see it has a FET connecting the data line to 5+ for data and comms.

I have now ordered a couple of "Normal" DS18B20's and I will report my findings ASAP, it must be the answer as everything else seemed OK, both code and hardware. As many of you tested too, you know what it's like but in this case the "P" was more significant that I thought.... Sorry for all the trouble.
Regards
Cactus
 

Michael V

Senior Member
Connection

I've been using a few of these.

I too have seen the "85C" and i think i may have a clue.

I use the DS18B20s on the end of a length of caple with a connector at the picaxe end. I've followed excellent advice from this forum and improved reliability and consistency by having the 4.7 pullup resistor at the sensor end, soldered directly to it.

I use readtemp12 with a one of sensor, and with multiple sensors the owin/owout commands, so i can save time by reading six sensors in the same second.

Also from this forum i learned that if you multiply the word variable you get from readtemp12 by 10/16, you get the temperature x 10. Then i convert to three integers using bintoascii, and write the integers to the LCD or sertxd with a "." before the last inteteger, and wallah! decimal temperatures.

I have noticed when i am plugging or unplugging the sensor then i sometimes get "85.0" produced . I've put this down as an artefact of a loose connection, when not all three connections are made, and have written code to ignore this result. (it would never be that hot). From memory it is a value of 1360 prior to conversion. I guess i'm suggesting you may have a bad connection somewhere!

Possibly also try a different resistor. I learned (also from this forum) that when you have a picaxe on a long cable, having a 4.7K pullup at both ends can improve the data reliability. I've had it work on a foreign circuit board that was built with a 2K7 reistor as an I2C pullup. The sensor does work with a 2K7, how good it is for the circuit i would not know.

Or, this may just be a coincidence!
 

cactusface

Senior Member
DS18B20 you know the one! it works!!

Hi Folks,
I have now got a new "Normal" DS18B20 and am very happy to say, it worked first time! It seemed very strange that I was having so many problems and you chaps were scratching your heads, wondering what I was doing wrong.

Perhaps there's something to learn here!! Like check the data sheet for that item and not one that looks close enough to it. Because that odd P,C or whatever tacked on the end of the code could make a world of difference!!

Thanks to Wes, Hippy, E and others who came to my rescue, Hopefully we can call the case well and truly closed.
Regards
Cactus.
 
Top