![]() |
Forum Index : Microcontroller and PC projects : yet another clock
Author | Message | ||||
RonnS Senior Member ![]() Joined: 16/07/2015 Location: GermanyPosts: 121 |
first many thanks to P.Mather (BMP180) G.Graham(Clockface) and Duane C. Johnson AD0TJ i have take there codes shake it 3 times and so you can see the result needed parts a LCD Backpack from SiliconChip a RTC a BMP180 and a HIH 3030 cpu 48
option autorun on rtc gettime rem OPTION EXPLICIT rem OPTION DEFAULT float const i2caddr=&B1110111 const MS7=7 'set default wait period const signed=1 const unsigned=0 ' dim i2cin$ length 8 'max size for integer conversion dim UT,UP,i,j dim ac1,ac2,ac3,ac4,ac5,ac6,b1,b2,mb,mc,md 'bmp180 parameters dim x1,x2,b5,b6,x3,b3,b4,b7,OSS dim temperature,pressure DIM altitude as float dim OSSdata(4) dim OSSscale(4) Const c.face = RGB(32, 32, 96) Const c.bezel = RGB(white) const InTmpPin = 5 'Indoor DS18B20 uMITE Pin const InHumPin = 4 'Indoor DS18B20 uMITE Pin Const c.majormark = RGB(green) Const c.minormark = RGB(green) Altitude =45.0 setpin InHumPin,AIN TEMPR START InTmpPin ,1 I2C OPEN 100,1000 rem TEMPR START 5 ,3 InTmp =TEMPR(5) COLOR RGB(0,50,0),RGB(32,0,32)'Set Basic LED Display Colors BOX 0,0,318,239,7,RGB(0,0,255),RGB(32,0,32)'Add A Border TinyCircular Initclock init_1 Run_Main Sub InitClock Local Float i, y, xx, yy, r1, r2, tim Circle 159, 160,FaceRadius, 5, 1, RGB(255,255,255),RGB(0,0,0) For i = 0 To 59 If i Mod 15 = 0 Then For y = -2 To +2 tim = (i + y/10) : xx = Cos(Rad(tim * 6)) : yy = Sin(Rad(tim * 6)) r1 = ana.r - 20 : r2 = ana.r - 5 Line ana.x + xx*r1, ana.y - yy*r1, ana.x + xx*r2, ana.y - yy*r2, 1, c.majormark Next y ElseIf i Mod 5 = 0 Then For y = -2 To +2 tim = (i + y/10) : xx = Cos(Rad(tim * 6)) : yy = Sin(Rad(tim * 6)) r1 = ana.r - 15 : r2 = ana.r - 5 Line ana.x + xx*r1, ana.y - yy*r1, ana.x + xx*r2, ana.y - yy*r2, 1, c.majormark Next y Else tim = i : xx = Cos(Rad(tim * 6)) : yy = Sin(Rad(tim * 6)) r1 = ana.r - 10 : r2 = ana.r - 5 Line ana.x + xx*r1, ana.y - yy*r1, ana.x + xx*r2, ana.y - yy*r2, 1, c.majormark EndIf Next i end sub sub init_1 OSS=1 'set oversampling ratio ' OSS=0 ' Uncomment this line to check algorithm against datasheet OSSdata(0)=&H34 OSSdata(1)=&H74 OSSdata(2)=&HB4 OSSdata(3)=&HF4 OSSscale(0)=1 OSSscale(1)=2 OSSscale(2)=4 OSSscale(3)=8 I2C WRITE i2caddr,1,1,&HAA 'send read calibration data command I2C READ i2caddr,0,22,i2cin$() 'read in calibration data ac1=intconv(mid$(i2cin$,1,2),signed) ac2=intconv(mid$(i2cin$,3,2),signed) ac3=intconv(mid$(i2cin$,5,2),signed) ac4=intconv(mid$(i2cin$,7,2),unsigned) ac5=intconv(mid$(i2cin$,9,2),unsigned) ac6=intconv(mid$(i2cin$,11,2),unsigned) b1=intconv(mid$(i2cin$,13,2),signed) b2=intconv(mid$(i2cin$,15,2),signed) mb=intconv(mid$(i2cin$,17,2),signed) mc=intconv(mid$(i2cin$,19,2),signed) md=intconv(right$(i2cin$,2),signed) end sub sub Run_Main do rtc gettime InTmp =TEMPR(5) bmp180 DatTim$= Date$+" "+Time$'Date & Time String from the RTC 'Remember Old Clock Values and Get the New Ones SecsOld=Secs:Secs=Val(Mid$(DatTim$,18,2)) MinsOld=Mins:Mins=Val(Mid$(DatTim$,15,2)) HorsOld=Hors:Hors=Val(Mid$(DatTim$,12,2)) 'Rearange the RTC Time String DTim$=Mid$(DatTim$,7,4)+"/"+Mid$(DatTim$,4,2)+"/"+Left$(DatTim$,2)+" "+Mid$(DatTim$,12,8) 'Assemble Temperature String for Display on the Terminal HumVal=pin(4) InTemp$ =" Indoor :"+str$(temperature/10,4,1)+" C" RHCal=HumVal-0.5:D_RHCal=RHCal/0.02 True_RH = Cint((D_RHCal)/(1.0546-0.00216*(temperature/10))) T_RH$ ="Luft: "+Str$(True_RH)+" %RH" 'Remember Old Clock Hands Parameters OldSecX=secX:OldSecY=SecY:OldMinX=MinX:OldMinY=MinY:OldHorX=HorX:OldHorY=HorY 'Calculate the Hands Orientation Including the Small Analog Movements HorX=CenterX+Cos((Hors+Mins/60+Secs/3600 -3)/ 6*PI)*(FaceRadius-15*FaceThick) HorY=CenterY+Sin((Hors+Mins/60+Secs/3600 -3)/ 6*PI)*(FaceRadius-15*FaceThick) MinX=CenterX+Cos((Mins+Secs/60 -12)/30*PI)*(FaceRadius-10*FaceThick) MinY=CenterY+Sin((Mins+Secs/60 -12)/30*PI)*(FaceRadius-10*FaceThick) SecX=CenterX+Cos((Secs -15)/30*PI)*(FaceRadius-10*FaceThick) SecY=CenterY+Sin((Secs -15)/30*PI)*(FaceRadius-10*FaceThick) 'Erace Old Clock Hands, if changed, from the LCD Panel '---------------------------------------------------------------------------- If SecsOld<>Secs then for dthkn=0 to 7 LINE CenterX,CenterY,OldHorX,OldHorY+dthkn,1,RGB(0,0,0) next dthkn end if '----------------------------------------------------------------------------- If SecsOld<>Secs then for dthknm=0 to 1 LINE CenterX,CenterY,OldMinX,OldMinY+dthknm,1,RGB(0,0,0) next dthknm end if '---------------------------------------------------------------------------- 'Display New Clock Hands on the LCD Panel 'Note, Paint in this Order so Seconds Overlap Minutes, then Minutes Overlap Hours '----------------------------------------------------------------------------- If SecsOld<>Secs then LINE CenterX,CenterY,OldSecX,OldSecY,1,RGB(0,0,0) for thkn=0 to 7 LINE CenterX,CenterY,HorX,HorY+thkn,,RGB(255,255,255) next thkn '----------------------------------------------------------------------------- for thknm=0 to 1 LINE CenterX,CenterY,MinX,MinY+thknm,,RGB(255,255,255) next thknm LINE CenterX,CenterY,SecX,SecY,,RGB(255,255,128) 'Display Text on the LCD Panel 'TEXT X, Y,STRING,JUSTIFI,FONT,SCALE,C,BC TEXT 160, 1,DTim$ ,CT,1,2,RGB(128,255,128) TEXT 160,25,InTemp$ ,CT,1,2,RGB(128,255,128) TEXT 160,49,T_RH$ ,CT,1,2,RGB(128,255,128) TEXT 60,75,"Druck:" ,CT,1,2,RGB(128,255,128) TEXT 265,75,str$(cint(pressure/((1-(altitude/44330))^5.255)/100,4,1)) ,CT,1,2,RGB(128,255,128) loop end sub sub bmp180 I2C WRITE i2caddr,0,2,&HF4,&H2E 'send temp conversion pause MS7 'wait for temperature conversion I2C WRITE i2caddr,1,1,&HF6 'send read data I2C READ i2caddr,0,2,i2cin$() 'read 2 bytes UT=intconv(i2cin$,unsigned) ' UT=27898 ' Uncomment this line to check algorithm against datasheet I2C WRITE i2caddr,0,2,&HF4,ossdata(oss) 'send pressure conversion pause (oss+1)*ms7 'wait for the pressure conversion I2C WRITE i2caddr,1,1,&HF6 'send read data I2C READ i2caddr,0,3,i2cin$() 'read 3 bytes UP=intconv(i2cin$,unsigned) up=up>>(8-oss) 'scale the output by the number of unused bits in the xlsb byte ' UP=23843' Uncomment this line to check algorithm against datasheet calc_temp calc_pressure rem print "Temperature = ",str$(temperature/10,4,1),"Deg C" rem print "Local Pressure = ",str$(pressure/100,4,1),"Hectopascal/Mb" rem print "Sea level pressure = ",str$(pressure/((1-(altitude/44330))^5.255)/100,4,1),"Hecto pascal/Mb" end sub ' ' calc_temperature: calculate the temperature from the raw temperature given the calibration parameters ' sub calc_temp: X1=(UT-AC6)*AC5\powerof2(15) X2=MC*powerof2(11)/(X1+MD) 'This needs to be a floating divide to match the datasheet B5=X1+X2 temperature=(B5+8)\powerof2(4) end sub ' ' calc_pressure: calculate the pressure from the raw pressure given the calibration parameters and temperature output ' sub calc_pressure: B6=b5-4000 x1=(b2*(b6*b6/powerof2(12)))\powerof2(11) x2=ac2*b6\powerof2(11) x3=x1+x2 b3=(((ac1*4+x3)*ossscale(oss))+2)\4 X1=AC3*B6\POWEROF2(13) X2=(B1*(B6*B6/POWEROF2(12)))\POWEROF2(16) x3=((x1+x2)+2)\4 b4=ac4*(abs(x3+32768))\powerof2(15) b7=abs(up-b3)*(50000\ossscale(oss)) pressure=(b7*2)\b4 x1=(pressure\powerof2(8))*(pressure\powerof2(8)) x1=(x1*3038)\powerof2(16) x2=(-7357*pressure)\powerof2(16) pressure=pressure+(x1+x2+3791)\powerof2(4) end sub CFunction intconv 00000000 27bdfff8 00001021 00001821 afa20000 afa30004 90880000 1900000b 01003821 2503ffff 03a31821 24020001 00823021 90c60000 a0660000 24420001 00e2302a 10c0fffa 2463ffff 8ca20000 1040000d 03a81021 9042ffff 30420080 10400009 29020008 10400007 03a81021 27a40008 2403ffff a0430000 24420001 5444fffe a0430000 8fa20000 8fa30004 03e00008 27bd0008 End CFunction ' CFunction powerof2 00000000 27bdfff8 00001021 00001821 afa20000 afa30004 8c820000 000218c2 03a32021 000318c0 00431023 24030001 00431004 a0820000 8fa20000 8fa30004 03e00008 27bd0008 End CFunction sub TinyCircular CenterX=159:CenterY=160'Center Position of the Clock Face ana.x=159:ana.Y=160:ana.r=80 FaceRadius=80'Distance from Center to Upper Edge of the Clock Face AspRatio=1.00'Ratio of Face Width to Height FaceThick=2 'Basic Width of Outer Ring of Face TicRadius=0.8*FaceThick'Radius of Hour Clock Tic Marks rem r1 = FaceRadius - 20 : r2 = FaceRadius - 5 End Sub |
||||
RonnS Senior Member ![]() Joined: 16/07/2015 Location: GermanyPosts: 121 |
|
||||
Frank N. Furter Guru ![]() Joined: 28/05/2012 Location: GermanyPosts: 946 |
Hi RonnS, it's a very nice clock! ![]() Can you tell me what a HIH 3030 is? Is it a humidity sensor? Where is it to buy? Thanks! Frank |
||||
RonnS Senior Member ![]() Joined: 16/07/2015 Location: GermanyPosts: 121 |
.. hello, an thank you yes it is a Humidity Sensor with a simple analog output link Ron |
||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1982 |
That's HIH-5030 for anyone searching. They are a bit expensive but I have had no luck with the DHT22, I have had about 4 fail. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6269 |
I used the Honeywell units originally but found that they would only last about 2 years max before I had to replace them. It will be a while before I know if the DHT22's are any better. Make sure that they are easy to replace! Jim VK7JH MMedit |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |