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.
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 KingdomPosts: 8648
Posted: 06:48am 20 Jun 2016
Copy link to clipboard
Print this post
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 KingdomPosts: 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 KingdomPosts: 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: AustraliaPosts: 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 KingdomPosts: 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
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 KingdomPosts: 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: AustraliaPosts: 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 KingdomPosts: 1676
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-22There 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 KingdomPosts: 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: AustraliaPosts: 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 KingdomPosts: 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: AustraliaPosts: 173
Posted: 10:25am 21 Jun 2016
Copy link to clipboard
Print this post
SETTICK 12 * 3600000, SetTime, 4
12 times !!!! Edited by mikeb 2016-06-22There are 10 kinds of people in the world. Those that understand binary and those that don't.
palcal
Guru
Joined: 12/10/2011 Location: AustraliaPosts: 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 KingdomPosts: 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!