Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 01:50 17 Jun 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Tempr help needed please

Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 04:42am 20 Jun 2016
Copy link to clipboard 
Print this post

I've been struggling all day trying to get the temperature to display on a 7" led SSD1963

Basically it draws 3 boxes with the time and date in the top and bottom boxes and the temperature in the 1st box

But no matter how I try and format the TEMPR command I cannot get it to show the temperature.
It comes up as Error: Expression syntax

This makes me assume I've got the right idea but it's not correct

I've tried almost every available options for typing tempr that I can think of and none work.

The DS18B20 is on pin 18

any ideas?

[code]
option explicit
option default none
RTC GETTIME

cls


CONST DBlue = RGB(0, 0, 128) ' A dark blue colour
COLOUR RGB(GREEN), RGB(BLACK) ' Set the default colours
FONT 1, 2 ' Set the default font
BOX 260, 0, 280, 99, 3, RGB(Blue), DBlue
BOX 260, 381 , 280, 99, 3, RGB(Blue), DBlue
BOX 0,0, 240, 99, 3, RGB(Blue), DBlue
DO
TEMPR START 18,2
TEXT 400,50, date$, CM, 1, 2, RGB(CYAN), DBlue
TEXT 400,430, time$, CM, 1, 2, RGB(CYAN), DBlue
TEXT 125,50, str$(TEMPR(18),0,1) " C", CM, 1, 2, RGB(CYAN), DBlue
loop

end
[/code]

By the way what is the 0,1 at the end of the TEMPR command for? I can'f find them mentioned in the manual

 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8648
Posted: 06:48am 20 Jun 2016
Copy link to clipboard 
Print this post

  Quote  By the way what is the 0,1 at the end of the TEMPR command for?


That is because they are part of the STR$ function which is your problem. Check the syntax of STR$
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 07:04am 20 Jun 2016
Copy link to clipboard 
Print this post

Thanks Peter, I got it working and I discovered you can't put a "C" in the same TEXT statement, I had to add another line with "C" positioned at the end of the temperature reading
I did read about tempr in the manual before asking and also checked out examples on the forum


One last question

Any idea why the temperature displays wrong sometimes? it misses the decimal point out altogether on some readings but corrects itself in a couple of readings afterwards

At the moment it's reading 226.55 C which is obviously wrong.


EDIT:

I thought it might have been because it's refreshing too quickly so I changed the code to
[code]
if secs mod 10 = 0 then
TEMPR START 18,2
End if
pause 1000
TEXT 125,50, STR$(TEMPR(18)), CM, 1, 2, RGB(CYAN), DBlue
TEXT 185,50, "C", CM, 1, 2, RGB(CYAN), DBlue
[/code]

but it's still doing the same thing, temp readings too high or missing the decimal point altogetherEdited by lew247 2016-06-21
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 09:09am 20 Jun 2016
Copy link to clipboard 
Print this post

EDIT I thought I had fixed it but I haven't
It ended up with the temp right but the clock wrong
Edited by lew247 2016-06-21
 
mikeb

Senior Member

Joined: 10/04/2016
Location: Australia
Posts: 173
Posted: 09:37am 20 Jun 2016
Copy link to clipboard 
Print this post

Hi,
Have another look at the STR$ formatting in the manual. there you will find methods to 'pad' the string to ensure it always sends the same number of characters.
the problem is how MMbasic formats on its own. If your temperature reading is a whole number then that is all it will send eg, 22 instead of 22.00 (or whatever resolution you have called for). I have also fallen into the trap of thinking I have read the manual (sorry Geoff ) but when I've had a 'mum' look things tend to leap out at me.

Regards, Mike B.
There are 10 kinds of people in the world.
Those that understand binary and those that don't.
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 10:05am 20 Jun 2016
Copy link to clipboard 
Print this post

I really can't figure this out

What I'm trying to do is use the excellent code Matherp wrote for displaying a clock on the LCD display with Big Ben as a background.

I have it in the centre of the screen with the clock and hands the correct size and working perfectly

The clock size is 280 X 280

I have a box above the clock and one below - the one above displays the DATE - working perfectly

The box below displays the TIME in decimal - working perfectly

The box on the upper left is "MEANT" to display the temperature from a DS18B20 and ideally refresh it every 5 seconds or so

This is the bit I am having problems with,

I can get it to display the Temp and it's fine but it updates itself every second and I've fixed the "double display/decimal point missing" by adding a new line of blank text before it updates the temperature

This "would" be fine but I cannot get it to update every 5 seconds

It updates every second and also slows the second hand of the clock slightly.

If I move the code to other sections, the clock stops working.

This is the code in case anyone would be kind enough and have a look and let me know if you spit what I've missed please

[code]
''''''''''''''''''''''''''''''''''''''''
'Big BEN ClOCK & TEMP '
'Thanks to Matherp for most of the code'
''''''''''''''''''''''''''''''''''''''''

RTC GETTIME
const buffersize = 2500
dim integer buff(buffersize)
dim integer nt=4 'Number of triangles being updated
dim integer xx0(nt*2-1),yy0(nt*2-1),xx1(nt*2-1),yy1(nt*2-1),xx2(nt*2-1),yy2(nt*2-1),tcol(nt*2-1),secs,mins,hours,first=1
cls


CONST DBlue = RGB(0, 0, 128) ' A dark blue colour
COLOUR RGB(GREEN), RGB(BLACK) ' Set the default colours
FONT 1, 2 ' Set the default font
BOX 260, 0, 280, 99, 3, RGB(Blue), DBlue
BOX 260, 381 , 280, 99, 3, RGB(Blue), DBlue
BOX 0,0, 240, 99, 3, RGB(Blue), DBlue
DO

load image "bigben.bmp",260,100
Circle MM.Hres\2, MM.Vres\2, (MM.Vres\2-MM.Vres\12)\12, 0, , rgb(red), rgb(red))
Circle MM.Hres\2, MM.Vres\2, (MM.Vres\2-MM.Vres\12)\15, 0, , 0, 0
Circle MM.Hres\2, MM.Vres\2, (MM.Vres\2-MM.Vres\12)\20, 0, , RGB(gray), RGB(gray)
secs=val(right$(time$,2))
mins=val(mid$(time$,4,2))
hours=val(left$(time$,2))
do
secs=val(right$(time$,2))
mins=val(mid$(time$,4,2))
hours=val(left$(time$,2))
hands(secs,mins,hours,(MM.Vres\2-MM.Vres\3.87),MM.Hres\2, MM.Vres\2)
do
loop while val(right$(time$,2))=secs


TEXT 400,50, date$, CM, 1, 2, RGB(WHITE), DBlue
TEXT 400,430, time$, CM, 1, 2, RGB(WHITE), DBlue
TEMPR START 18,2
TEXT 125,50, " ", CM, 1, 2, RGB(WHITE), DBlue
TEXT 125,50, STR$(TEMPR(18)), CM, 1, 2, RGB(WHITE), DBlue
TEXT 185,50, "C", CM, 1, 2, RGB(WHITE), DBlue
loop
loop

end


'
Sub hands(seconds As integer, minutes as integer, hours as integer, size as integer, x as integer, y as integer)
Local integer x1,y1,x2,y2,x0,y0,i
local float angle=seconds*6
rotatetriangle(2,RGB(RED),angle,x,y,-3,50,3,50,-3,-size) 'make up the second hand with two triangles
rotatetriangle(3,RGB(RED),angle,x,y,3,-size,3,50,-3,-size)
angle=minutes*6 + seconds/10
rotatetriangle(0,RGB(BLACK),angle,x,y,-size/15,0,size/15,0,0,-size*0.8)
angle=hours*30 + minutes/2
rotatetriangle(1,RGB(BLACK),angle,x,y,-size/12,0,size/12,0,0,-size*0.5)
if first then
i=triangles(nt, buff() , tcol(nt), xx0(nt), yy0(nt), xx1(nt), yy1(nt), xx2(nt), yy2(nt))
print "Read buffer is ",i/buffersize*100,"% used"
first=0
else
i=triangles(nt*2, buff() , tcol(), xx0(), yy0(), xx1(), yy1(), xx2(), yy2())
endif
Circle x,y, size\12, 0, , rgb(red), rgb(red))
Circle x,y, size\15, 0, , 0, 0
Circle x,y, size\20, 0, , RGB(gray), RGB(gray)
End Sub

sub rotatetriangle(n as integer, col as integer, angle as float, x as integer, y as integer, x0 as integer, y0 as integer, x1 as integer, y1 as integer, x2 as integer, y2 as integer)
local float sine=sin(rad(angle)),cosine=cos(rad(angle))
local integer x0a,y0a,x1a,y1a,x2a,y2a
x0a= x0*cosine - y0 * sine + x
y0a= y0*cosine + x0 * sine + y
x1a= x1*cosine - y1 * sine + x
y1a= y1*cosine + x1 * sine + y
x2a= x2*cosine - y2 * sine + x
y2a= y2*cosine + x2 * sine + y
xx0(n)=xx0(n+nt)
yy0(n)=yy0(n+nt)
xx1(n)=xx1(n+nt)
yy1(n)=yy1(n+nt)
xx2(n)=xx2(n+nt)
yy2(n)=yy2(n+nt)
xx0(n+nt)=x0a
yy0(n+nt)=y0a
xx1(n+nt)=x1a
yy1(n+nt)=y1a
xx2(n+nt)=x2a
yy2(n+nt)=y2a
tcol(n)=-1
tcol(n+nt)=col
end sub

sub mm.startup
setrd(30)' set up the read pin
end sub

Csub setrd
00000000
27BDFFE8 AFBF0014 AFB00010 3C109D00 8C830000 8E020090 24050008 00003021
A043002D 8E030090 8E020010 0040F809 8064002D 8E030090 8E020010 24050065
8064002D 0040F809 00003021 8E030090 8E02001C 24050006 0040F809 8064002D
8FBF0014 8FB00010 03E00008 27BD0018
End Csub

CFunction triangles
0000024B
'defineregion
3C029D00 8C480094 8C420098 24091000 3C03BF88 AC696134 8C430000 8D020000
248AFFFF 24A9FFFF 0062402B 01463021 01274821 11000003 00605821 00405821
00601021 3C039D00 8C680090 240C0001 81030015 146C000B 24070002 8102002C
00806821 28420007 14400023 00C06021 00063027 00042027 008B6021 1000001E
00CB6821 14670008 24070003 00063027 00042027 00A06821 01206021 00C22821
10000015 00824821 1467000E 00094827 8103002C 00053827 28630007 01222821
00C06021 00806821 1060000B 00E24821 00063027 00042027 008B6021 10000006
00CB6821 00056027 012B6821 018B6021 00802821 00C04821 000D1202 3C03BF88
24080800 240B1000 000C2202 00057202 00093A02 34421800 2406022A AC666430
35AD1800 AC686134 34841800 AC686138 358C1800 AC6B6138 35CE1800 AC626430
34A51800 34E71800 35291800 2402022B AC686134 AC686138 AC6D6430 AC686134
AC686138 AC646430 AC686134 AC686138 AC6C6430 AC686134 AC686138 AC6B6134
AC626430 AC686134 AC686138 AC6B6138 AC6E6430 AC686134 AC686138 AC656430
AC686134 AC686138 AC676430 AC686134 AC686138 AC696430 AC686134 AC686138
03E00008 00000000
'writeRectangle
27BDFFD8 AFB40020 AFB3001C 00C0A021 00E09821 72749802 AFB00010 8FB00038
AFB20018 AFB10014 00109403 00108A03 AFBF0024 0411FF80 00000000 3C02BF88
24031000 24040800 2405022C AC436134 36521800 AC456430 36311800 AC446134
36101800 AC446138 AC436138 1260000F 2673FFFF 24030800 2404FFFF 2673FFFF
AC526430 AC436134 AC436138 AC516430 AC436134 AC436138 AC506430 AC436134
AC436138 1664FFF6 2673FFFF 8FBF0024 8FB40020 8FB3001C 8FB20018 8FB10014
8FB00010 03E00008 27BD0028
'ReadRectangle
27BDFFC8 AFBF0034 AFBE0030 AFB7002C AFB60028 AFB50024 AFB40020 AFB3001C
AFB20018 3C139D00 AFB10014 AFB00010 8E630090 0080B021 8E620028 8064002D
00C0A821 00E0F021 00A0B821 0040F809 8FB10048 8E640090 8E630024 24050006
8084002D 24100001 0060F809 00508004 8E630090 00409021 8E620024 8064002D
24050005 0040F809 0015A040 0295A021 00409821 729E1002 02C02021 02E02821
02A03021 03C03821 0051A021 0411FF2F 00000000 3C05BF88 24061000 ACA66134
8FA3004C 24070800 2402022E ACA26430 ACA76134 ACA76138 ACA66138 240600FF
00711821 3C02BF81 3C04BF88 ACA6641C AE700000 8C45F220 8C45F220 AE500000
8C866420 26310003 0234282B A0660000 AE700000 8C46F220 8C46F220 AE500000
8C866420 A0660001 AE700000 8C46F220 8C46F220 AE500000 8C866420 A0660002
14A0FFEB 24630003 3C02BF88 240300FF AC43641C 8FBF0034 02201021 8FBE0030
8FB7002C 8FB60028 8FB50024 8FB40020 8FB3001C 8FB20018 8FB10014 8FB00010
03E00008 27BD0038
'RestoreRectangle
27BDFFE0 AFB20018 AFB10014 00C09021 00E08821 72328802 AFB00010 AFBF001C
8FB00030 0411FEEF 00000000 3C02BF88 24031000 24040800 2405022C AC436134
AC456430 AC446134 AC446138 AC436138 1220001D 2631FFFF 8FA40034 02202821
00902021 24030800 2407FFFF 80860000 24A5FFFF 34C61800 AC466430 AC436134
AC436138 80860001 34C61800 AC466430 AC436134 AC436138 80860002 24840003
34C61800 AC466430 AC436134 AC436138 54A7FFEF 80860000 00111040 26100003
00518821 02118021 8FBF001C 02001021 8FB20018 8FB10014 8FB00010 03E00008
27BD0020
'triangles
27BDFFA8 AFB20038 8FA3006C 00809021 8FA40074 AFBE0050 AFB7004C 0083102A
AFB3003C AFB10034 AFBF0054 AFB60048 AFB50044 AFB40040 AFB00030 00A09821
00C0B821 AFA70064 8FB10068 10400006 8FBE007C 02201021 AFA4006C 8FB10070
AFA30074 AFA20070 8FA30074 03C3102A 10400009 8FA6006C 8FA20070 8FA40078
AFBE0074 AFA20078 AFA40070 0060F021 8FA6006C 8FA30074 0066102A 50400008
8FA6006C 8FA40074 02201021 AFA60074 8FB10070 AFA4006C AFA20070 8FA6006C
14DE0036 8FA30074 8FA30070 0071102A 14400006 02203821 0223102A 10400005
8FA40078 10000002 8FA70070 8FB10070 8FA40078 0091102A 54400003 8FB10078
00E4102A 0082380B 1640000C 24020001 8FA5006C 24E70001 02202021 24060001
00F13823 AFB30010 AFB70014 0411FF19 00000000 100000B0 00409821 1642000C
8FA20064 8FA5006C 24E70001 02202021 24060001 00F13823 AFB30010 AFB70014
0411FF6E 00000000 100000A3 00409821 8FA5006C 24E70001 02202021 24060001
00F13823 AFA20010 AFB70014 0411FECE 00000000 10000099 8FBF0054 8FA4006C
007E1026 0002102B 00621023 AFA20020 0044102A 14400044 00808021 8FA60070
8FA20078 00641823 00D13023 00511023 03C42023 AFA60024 AFA20028 0000A021
0000A821 AFA30018 AFA4001C 24160001 8FA40018 8FA6001C 02002821 02A4001A
008001F4 02C03821 00001012 00511021 0286001A 00C001F4 00001812 00711821
0062302A 10C00003 00402021 00601021 00801821 24660001 00402021 16400009
00C23023 02002821 02C03821 AFB30010 AFB70014 0411FECF 00000000 10000012
00409821 5656000C 8FA20064 24630001 00402021 02002821 00623023 02C03821
AFB30010 AFB70014 0411FF24 00000000 10000005 00409821 AFB70014 AFA20010
0411FE89 00000000 8FA30020 8FA40024 8FA60028 26100001 0070102A 02A4A821
1040FFCB 0286A021 03D0102A 1440004A 8FA30070 8FA20078 8FA40074 8FA60078
00431023 AFA20024 8FA2006C 0204A023 00D13023 0202A823 8FA20024 70D5A802
03C41823 8FA4006C AFA60020 AFA30018 03C42023 AFA4001C 24160001 7054A002
8FA40018 8FA6001C 02002821 0284001A 008001F4 8FA40070 02C03821 00001012
00441021 02A6001A 00C001F4 00001812 00711821 0062202A 10800003 00403021
00601021 00C01821 24660001 00402021 16400009 00C23023 02002821 02C03821
AFB30010 AFB70014 0411FE82 00000000 10000012 00409821 5656000C 8FA20064
24630001 00402021 02002821 00623023 02C03821 AFB30010 AFB70014 0411FED7
00000000 10000005 00409821 AFB70014 AFA20010 0411FE3C 00000000 8FA30024
8FA40020 26100001 03D0102A 0283A021 1040FFCB 02A4A821 8FBF0054 02601021
8FBE0050 8FB7004C 8FB60048 8FB50044 8FB40040 8FB3003C 8FB20038 8FB10034
8FB00030 03E00008 27BD0058
'main
27BDFFB0 AFBE0048 AFB70044 AFB60040 AFB5003C AFB40038 AFB1002C AFBF004C
AFB30034 AFB20030 AFB00028 8C820000 00808821 00A0A821 AFA60058 00E0A021
8FBE0068 8FB7006C 1840002B 8FB60070 8CC40004 04800004 8CC70000 00008021
1000009B 00001821 8FB20058 00001821 00001021 00008021 8FA40060 8FA50064
02834821 00834021 00A33021 02E32021 03C32821 02C31821 8D2C0000 8D0B0000
8CCA0000 8CA90000 8C880000 8C630000 24040001 00402821 02A03021 AFA30024
AFAC0010 AFAB0014 AFAA0018 AFA9001C AFA80020 0411FEBF 00000000 8E240000
26100001 0204202A 14800006 001018C0 10000030 00001021 00008021 1000002D
00001021 8E44000C 8E470008 0480FFDA 26520008 8FA40058 001018C0 00831021
8C440004 8C470000 04810069 00001021 10000021 8E230000 8FA50060 8FA40064
02834821 00A34021 00833021 03C32821 02E32021 02C31821 8D2C0000 8D0B0000
8CCA0000 8CA90000 8C880000 8C630000 00002021 00402821 02A03021 AFA30024
AFAC0010 AFAB0014 AFAA0018 AFA9001C AFA80020 0411FE8F 00000000 8E240000
8FA50058 26730001 0264202A 1480000D 00B21821 8E230000 0203182A 10600036
8FA40058 001018C0 00832821 8CA40004 04800031 8CA70000 26120001 10000008
001290C0 8C640004 26450008 0480FFF1 8C670000 02401821 1000FFCF 00A09021
8FA50060 8FA40064 02834821 00A34021 00833021 03C32821 02E32021 02C31821
8D2C0000 8D0B0000 8CCA0000 8CA90000 8C880000 8C630000 24040002 00402821
02A03021 AFA30024 AFAC0010 AFAB0014 AFAA0018 AFA9001C AFA80020 0411FE5D
00000000 8E240000 8FA50058 26100001 0204202A 10800008 00B21821 8C640004
26450008 04800004 8C670000 02401821 1000FFDB 00A09021 8FBF004C 00021FC3
8FBE0048 000210C3 8FB70044 8FB60040 8FB5003C 8FB40038 8FB30034 8FB20030
8FB1002C 8FB00028 03E00008 27BD0050 26120001 001290C0 02009821 1000FF96
00001021
End CFunction
[/code]




Edited by lew247 2016-06-21
 
mikeb

Senior Member

Joined: 10/04/2016
Location: Australia
Posts: 173
Posted: 12:17pm 20 Jun 2016
Copy link to clipboard 
Print this post

Hi lew,
The way I understand it is this. Everyone please feel free to correct me.
The 'TEMP START' command should be up in the 'secs=val' loop. That way the DS18B20 is doing its conversion while you are waiting for the 'secs' value to change further down. Once it has changed, and breaks out of the 'while' loop, the DS18B20 is instantly ready to respond to the 'TEMPR' command regardless of the resolution you have configured the DS18B20 for. At present you are issuing the 'TEMP START' command, two lines later you issue the 'TEMPR' command and have to wait for the DS18B20 to finish its conversion. This defeats the purpose of the 'TEMP START' command and causing the problem with your 'seconds' hand. The manual explains this clearly.
If you use an RTC you can use the 'squarewave' output pin to connect to an MM pin, and in conjunction with an interrupt, you can update everything on a precise time interval rather than waiting for the 'secs val' to change. Keep in mind your program cannot do anything else while it is stuck in the 'while' loop unless it is interrupted.
Try organising your program to check this variable on each pass and carry out a subroutine on change.

Regards, Mike B.
There are 10 kinds of people in the world.
Those that understand binary and those that don't.
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 10:02pm 20 Jun 2016
Copy link to clipboard 
Print this post

Thanks mikeb

That helped a lot.
it's working now

Can you explain how to use the RTC in the way you describe?

I've attached a pic of the one I have it has these 2 pins - I presume you mean using one of them?
[quote]
32K - 32KHz oscillator output. Open drain, you need to attach a pullup to read this signal from a microcontroller pin

SQW - optional square wave or interrupt output. Open drain, you need to attach a pullup to read this signal from a microcontroller pin
[/quote]

I've checked the manual and it doesn't help in this respect for newbies to programming
The only thing I found is using the RTC to update the clock every 12 hours, but I dont understand how this works?
[code]SETTICK 12 * 3600000, SetTime, 4[/code]
Obviously settick sets up a second timer but I don't get the 12 * 3600000, what it means, or the 4 at the end of the line.

This is the modification I did to get the temp working




[code]TEMPR START 18,2
Settick 1000 ,L1,1

do
secs=val(right$(time$,2))
mins=val(mid$(time$,4,2))
hours=val(left$(time$,2))
hands(secs,mins,hours,(MM.Vres\2-MM.Vres\3.87),MM.Hres\2, MM.Vres\2)
do
loop while val(right$(time$,2))=secs
TEXT 400,50, date$, CM, 1, 2, RGB(WHITE), DBlue
TEXT 400,430, time$, CM, 1, 2, RGB(WHITE), DBlue
loop
loop

end

Sub L1
secs2=secs2+1 'update seconds timer
if secs2 => 5 then '
secs2 = 0 'reset counter
TEXT 125,50, " ", CM, 1, 2, RGB(WHITE), DBlue
TEXT 125,50, STR$(TEMPR(18)), CM, 1, 2, RGB(WHITE), DBlue
TEXT 185,50, "C", CM, 1, 2, RGB(WHITE), DBlue
endif
End Sub [/code]
Edited by lew247 2016-06-22
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1809
Posted: 10:41pm 20 Jun 2016
Copy link to clipboard 
Print this post

Lew,
12*3600000 is the number of milliseconds in 12 hours, there are 4 Tick timers and the four means timer no.4...
Paul.Edited by palcal 2016-06-22
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 11:06pm 20 Jun 2016
Copy link to clipboard 
Print this post

Thanks Paul

I didn't know there were 4 tick timers.

However I can't get my brain to agree

1000 mS = 1 second?
60000mS = 1 minute
3600000mS = 1 hour
43200000mS = 12 hours ?

or am I calculating it wrong?

Edited by lew247 2016-06-22
 
mikeb

Senior Member

Joined: 10/04/2016
Location: Australia
Posts: 173
Posted: 11:51pm 20 Jun 2016
Copy link to clipboard 
Print this post

Hi lew,

Glad it works for you.
I've got 10 of those RTC modules. The first thing I do is remove the diode (D2) and 200R (R5) resistor (next to the SCL pin). Lithium 'coin' cells are not designed for recharging . Check on the web and find how many people are surprised that the cell ends up bulging. Particularly if the device is used at 5V. (Vmax 5V5).

The RTC is an I2C device so you need to connect to the I2C peripheral of the MM.
As you are using an SSD1963 you must have an MM+ so connect the SCL pin to pin 44 and the SDA pin to pin 43. Connect Vcc to +3V3 and use a pullup resistor (4k7) from pin SQW to Vcc. Thie SQW pin can be connected to any free digital input.
I'm not at my design PC at the moment so can't give you, exact, working examples to follow. Have a look through Geoff's really great manuals for usage of interrupt (otherwise just branch on change of secs variable and forget SQW),
RTC GETTIME and RTC SETTIME.
By default the RTC has a SQW frequency of 8.192kHz (not very useful) so you have to write to the configuration register (0Eh) and set bits 3 and 4 to 0.
If you haven't already download a copy of the DS3231 datasheet. Tried to upload but it is too big.
For now it is probably easiest for you to get rid of your 'DO ....WHILE' loop
and do an IF.....THEN. IF seconds has changed THEN update your time and temperature variables, start another conversion and write your new data to the display ENDIF go and do something else.
Lose the TEMP START command at the top of your program otherwise you may execute it inadvertently. It just means that the first second after power up you won't do a temperature conversion.
Do you really need the 5 sec delay between conversions ?

Regards, Mike B.

Edited by mikeb 2016-06-22
There are 10 kinds of people in the world.
Those that understand binary and those that don't.
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 12:03am 21 Jun 2016
Copy link to clipboard 
Print this post

Thanks
I'd totally forgotten about removing the charging section of the rtc.

[quote]Do you really need the 5 sec delay between conversions ? [/quote]

Not really,but it was the easiest way to get the temp to stay on screen without corrupting (overwriting itself without clearing the temp first)

I could make the delay a lot longer and probably will but I set it to 5 secs just while I'm figuring out how to get the lcd to do what I want

LewisEdited by lew247 2016-06-22
 
mikeb

Senior Member

Joined: 10/04/2016
Location: Australia
Posts: 173
Posted: 01:17am 21 Jun 2016
Copy link to clipboard 
Print this post

Hi Lewis,

No worries. Keep posting. I sure as s^&t will. Won't know unless we stick up our hands. Lots of very clever people on this forum.
What part of the UK are you in ? I was born in a little place called Coulsden,
just outside of London I think. Last time back there was 1978. Still travel on the British passport.
Moved to Oz 53 years ago with my parents.

Have a good one.

Mike B.
There are 10 kinds of people in the world.
Those that understand binary and those that don't.
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 01:23am 21 Jun 2016
Copy link to clipboard 
Print this post

I'm on the east side of Manchester
I've been through Coulsden when I was working in that area a few years ago installing mobile phone cell sites.
 
mikeb

Senior Member

Joined: 10/04/2016
Location: Australia
Posts: 173
Posted: 10:25am 21 Jun 2016
Copy link to clipboard 
Print this post

  lew247 said   Thanks Paul

I didn't know there were 4 tick timers.

However I can't get my brain to agree

1000 mS = 1 second?
60000mS = 1 minute
3600000mS = 1 hour
43200000mS = 12 hours ?

or am I calculating it wrong?



SETTICK 12 * 3600000, SetTime, 4

12 times !!!! Edited by mikeb 2016-06-22
There are 10 kinds of people in the world.
Those that understand binary and those that don't.
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1809
Posted: 10:45am 21 Jun 2016
Copy link to clipboard 
Print this post

Lew, that is updating every 12 hours.
3600000 millisecs is one hour 12*3600000 is twelve hours.
Paul.Edited by palcal 2016-06-22
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 09:04pm 21 Jun 2016
Copy link to clipboard 
Print this post

Thanks
amazing how sometimes I miss something so simple - I should have spotted that!
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024