Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 09:45 02 May 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 : MM+ Plot & Scroll Digoo oC/RH & BME280 Pressure

Author Message
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1328
Posted: 01:23pm 10 May 2020
Copy link to clipboard 
Print this post

A couple of years ago (see TBS links in the listing credits) there were some great posts showing
how to use the uMite to access and decode 433MHz transmissions from the cheap but good alkaline
battery operated Digoo R8S temp/RH sensors. About the same time Peter Mather posted code to access
the wired I2C interface BME280 pressure sensor data.

I developed some code that displays a continuously scrolling plot of the temp/RH data from two
Digoo's (one inside and one outside, ten metres away) and the pressure sensor. I've decided to post
this work in case members are interested in some of the methods I used with the uMite+ since I'm sure
in future there will deservedly be a lot of focus on the new STM based MM2.

The system has been running in my office for a couple of years now and it quite stable.

The system includes:
1. the uMite+ (MX470) running on Peter's original 'universal' backpack V1.1
2. a 4.2" 40 pin SSD1963 480x272 display. Smaller displays are generally a bit too 'busy' and
restrict scale range. The 320x480 ILI9488 3.5" would be a preferred choice and improve scale range.
3. a piezo beeper,
4. a battery backed DS3232 RTC,
5. the RX470 433 MHz receiver module and
6. the wired I2C BME280 barometric pressure sensor and two Digoo R8S temp/%RH sensors.

Items 3-6 are mounted on the backpack.

Features of the program include:
1. a continuous seven hour display updating asynchronously, approx. once a minute for each Digoo
and every half minute for the BME280.
2. scrolling the display using the BLIT command - actually a 'pseudo' scroll but still effective.
3. maintaining an updated time grid on the X axis.
4. auto-scaling (only on barometric pressure but simple to add to temp/RH).
5. noise checking (with display) all data using rolling averages.



 'PLOT-DIGOO/BME280    Greg Yaxley - "paceman" @ thebackshed.com forum.
 'May 2020 MMBasic Ver 5.05.02
 'See http://www.thebackshed.com/forum/forum_posts.asp?TID=10464&KW=digoo&PN=1&TPN=5
 '----------------------------------------------------------------------------------
 'Scrolling time-plot for oC & %RH data transmitted from two 433MHz Digoo R8S sensors
 'and a wired BME280 (I2C protocol) pressure sensor.
 'Plots 7hrs of data on a DDS1963 4.3" screen, then scrolls in hourly increments.
 'Data is noise-checked using rolling average of five valid readings, +/- a range.
 'Auto-scaling implemented on BME280 pressure, but not Digoo temperature & humidity.
 '
 'Acknowledgements:
 '1. TBS forum "TassieJim" (Jim Hiley) method to read the Digoo 433 MHz transmission at:
 '"http://www.thebackshed.com/forum/forum_posts.asp?TID=10317&KW=decoding+433&PN=1&TPN=2"
 '2. TBS forum "disco4now" (Gerry Alardice) method to decode it at:
 '"http://www.thebackshed.com/forum/forum_posts.asp?TID=10335&KW=digoo"
 '3. TBS forum "matherP" (Peter Mather) method to read BME280 wired I2C pressure sensor:
 '"http://www.thebackshed.com/forum/forum_posts.asp?TID=8362&KW=bme280"
 '4. TBS forum "MicroBlocks" ( ) for day-of-week code.
 '----------------------------------------------------------------------------------
 option autorun on
 Option Explicit
 Option Default NONE
'-----------------------------------------------------------------------------------
 const blue=rgb(blue),green=rgb(green),yellow=rgb(yellow),red=rgb(red),black=rgb(black)
 const cyan=rgb(cyan),magenta=rgb(magenta),BRGRAY=rgb(100,100,100),LTGRAY=rgb(60,60,60)
 
 Dim tick%,tock%,code$
 Dim channel$,relhumid$,temp$,curdate$,curtime$,dattime$,info$,oldresult$
 Dim integer gridtop,plotstart,BMEcalled,xposn,yposP,scrolling
 Dim float topP=30.4,botP=29.6,topT=40,topR=100
 Dim integer cn1,cn2,cnP,noise,Ch1TN,Ch1RN,Ch2TN,Ch2RN
 Dim float Tch1(7),Rch1(7),Tch2(7),Rch2(7),Press(7),pressure
 
 const highrestimer = 49, receiveblip = 31  'on MM+ pins 49&31.
 PWM 1,10000,50 'PWM1A pin 48 on MM+, & counting pin 49 for the high resol'n timer.
 SETPIN highrestimer, CIN  'input (counting) pin for the high resolution timer.
 SETPIN receiveblip, INTL, blip  'input (receive) pin for data out (DO) of the 433MHz
 'receiver module. It triggers on high to low transition. Pin used must be 5V tolerant.
 'Each Digoo unit transmits oC/%RH data pair at ~50 sec intervals.
 
'=======================================================================================  
'  BME280 Declarations  - Peter Mather
'=======================================================================================
 
 const BME280_ADDRESS                    = &H76  'was 77 - changed to 76 for GY module
 const BME280_REGISTER_T1                = &H88
 const BME280_REGISTER_P1                = &H8E
 const BME280_REGISTER_H1                = &HA1
 const BME280_REGISTER_H2                = &HE1
 const BME280_REGISTER_CHIPID            = &HD0
 const BME280_REGISTER_CONTROLHUMID      = &HF2
 const BME280_REGISTER_CONTROL           = &HF4
 const BME280_REGISTER_PRESSUREDATA      = &HF7
 const BME280_REGISTER_TEMPDATA          = &HFA
 const BME280_REGISTER_HUMIDDATA         = &HFD
'  
 dim integer s16=&HFFFFFFFFFFFF0000 , s16b=&H8000
 dim integer s12=&HFFFFFFFFFFFFF000 , s12b=&H800
 dim integer s8= &HFFFFFFFFFFFFFF00 , s8b=&H80
'        
 DIM INTEGER T1,T2,T3     'uint16_t, int16_t, int16_t
 DIM INTEGER P1,P2,P3,P4,P5,P6,P7,P8,P9    'uint16_t, 8 x int16_t
 DIM INTEGER H1,H2,H3,H4,H5,H6     'uint8_t, int16_t , uint8_t, int16_t, int16_t, int8_t
'
 dim INTEGER t_fine  'stores accurate temp reading from temp conversion for use in
'pressure and humidity conversions

'=======================================================================================
' Main
'=======================================================================================
 
 cls
 rtc gettime
 drawgrids
 blit read #1,mm.hres-90,60,60,200   'store the blank scrolling area of the screen.
 bme280_init           'must be run before pressure or humidity
 settick 30000,BME     'read presuure every 30 secs.
 DO
 loop
'=======================================================================================
'BME280 Functions & Subroutines  -  Peter Mather
'=======================================================================================

Sub BME
 BMEcalled = 1      'flag used in plotdata sub to ignore any first bad pressure reading.
 print str$(bme280_read_temp(),2,2),"  ";     'DEBUG print BME temperature to console
 print str$(bme280_read_humidity(),2,2);      'DEBUG print BME %RH to console
 pressure = bme280_read_pressure()*0.029531   'convert mbar to "Hg
 Print "   ",str$(pressure,2,2)               'DEBUG print BME pressure to console
 text 312,30,str$(pressure,2,2),,2,,BLUE      'display pressure in screen box area
 gui beep 20            '20msec buzzer beep (on pin 21) to announce new pressure data.
END sub
 
'=======================================================================================
function  bme280_read_temp() as float
 local integer var1,var2,adc_T
 local adc%(2)
 i2c write BME280_ADDRESS,1,1,BME280_REGISTER_TEMPDATA
 i2c read BME280_ADDRESS,0,3,adc%()
 adc_T=((adc%(0)<<16) OR (adc%(1)<<8) or adc%(2))>>4
 var1  = ((((adc_T>>3) - (T1 <<1))) * T2) \ q(11)
 var2  = (((((adc_T>>4) - (T1)) * ((adc_T\ q(4)) - (T1))) \ q(12)) * (T3)) \ q(14)
 t_fine = var1 + var2
 bme280_read_temp = ((t_fine * 5 + 128) \ q(8))/100.0
end function
'
function  bme280_read_pressure() as float
 local integer var1, var2, adc_P, p
 local adc%(2)
 i2c write BME280_ADDRESS,1,1,BME280_REGISTER_PRESSUREDATA
 i2c read BME280_ADDRESS,0,3,adc%()
 adc_P=((adc%(0)<<16) OR (adc%(1)<<8) or adc%(2))>>4
 var1 = t_fine - 128000
 var2 = var1*var1*P6
 var2 = var2 + ((var1*P5)<<17)
 var2 = var2 + (P4<<35)
 var1 = ((var1*var1*P3)\q(8))+((var1*P2)<<12)
 var1 = ((1<<47)+var1)*P1\q(33)
 if var1 = 0 THEN
   bme280_read_pressure = 0  ' avoid exception caused by division by zero
   exit function
 endif
 p = 1048576 - adc_P
 p = (((p<<31) - var2)*3125) \ var1
 var1 = (P9 * (p\ q(13)) * (p\ q(13))) \ q(25)
 var2 = (P8 * p) \ q(19)
 p = ((p + var1 + var2) \ q(8)) + (P7<<4)
 bme280_read_pressure = p/25600.0
end function
'  
function  bme280_read_humidity() as float
 local integer v_x1,adc_H
 local adc%(1)
 i2c write BME280_ADDRESS,1,1,BME280_REGISTER_HUMIDDATA
 i2c read BME280_ADDRESS,0,2,adc%()
 adc_H=(adc%(0)<<8) or adc%(1)
 v_x1 = t_fine - 76800
 v_x1=(((((adc_H<<14)-((H4)<<20)-(H5*v_x1))+16384)\ q(15))*(((((((v_x1*H6)\ q(10))*(((v_x1*H3)\ q(11))+32768))\ q(10))+2097152)*H2+8192)\ q(14)))
 v_x1 = (v_x1 - (((((v_x1 \ q(15)) * (v_x1 \ q(15))) \ q(7)) * (H1)) \ q(4)))
 if v_x1< 0 then v_x1 = 0
 if v_x1 > 419430400 then v_x1= 419430400
 bme280_read_humidity = (v_x1\ q(12)) / 1024.0
end function
'
sub bme280_init
 local i%,cal%(17)
 i2c open 400,1000 '400KHz bus speed
 i2c write BME280_ADDRESS,1,1,BME280_REGISTER_CHIPID
 i2c read BME280_ADDRESS,0,1,i%
 if i%<>&H60 then print "Error BME280 not found"
 '  
 i2c write BME280_ADDRESS,1,1,BME280_REGISTER_T1
 i2c read BME280_ADDRESS,0,6,cal%()
 T1=cal%(0) OR (cal%(1)<< 8)
 T2=cal%(2) OR (cal%(3)<< 8):   if T2 and s16b then T2=T2 OR s16 'sign extend if req'd
 T3=cal%(4) OR (cal%(5)<< 8):   if T3 and s16b then T3=T3 OR s16
 '  
 i2c write BME280_ADDRESS,1,1,BME280_REGISTER_P1
 i2c read BME280_ADDRESS,0,18,cal%()
 P1=cal%(0) OR (cal%(1)<<8)
 P2=cal%(2) OR (cal%(3)<<8):   if P2 and s16b then P2=P2 OR s16 'sign extend if required
 P3=cal%(4) OR (cal%(5)<<8):   if P3 and s16b then P3=P3 OR s16
 P4=cal%(6) OR (cal%(7)<<8):   if P4 and s16b then P4=P4 OR s16
 P5=cal%(8) OR (cal%(9)<<8):   if P5 and s16b then P5=P5 OR s16
 P6=cal%(10) OR (cal%(11)<<8):   if P6 and s16b then P6=P6 OR s16
 P7=cal%(12) OR (cal%(13)<<8):   if P7 and s16b then P7=P7 OR s16
 P8=cal%(14) OR (cal%(15)<<8):   if P8 and s16b then P8=P8 OR s16
 P9=cal%(16) OR (cal%(17)<<8):   if P9 and s16b then P9=P9 OR s16
 '  
 i2c write BME280_ADDRESS,1,1,BME280_REGISTER_H1
 i2c read BME280_ADDRESS,0,1,H1
 i2c write BME280_ADDRESS,1,1,BME280_REGISTER_H2
 i2c read BME280_ADDRESS,0,7,cal%()
 H2=cal%(0) OR (cal%(1)<< 8):   if H2 and s16b then H2=H2 OR s16 'sign extend if req'd
 H3=cal%(2)
 H6=cal%(6):   if H6 and s8b then H6=H6 OR s8 'sign extend if required
 H4=(cal%(3)<<4) OR (cal%(4) and &H0F): if H4 and s12b then H4=H4 OR s12 'sign extend if req'd
 H5=(cal%(5)<<4) OR (cal%(4)>>4):  if H5 and s12b then H5=H5 OR s12
 '  
 i2c write BME280_ADDRESS,0,2,BME280_REGISTER_CONTROLHUMID,&H05 '16x oversampling humidity
 i2c write BME280_ADDRESS,0,2,BME280_REGISTER_CONTROL,&HB7      '16x oversampling pressure/temp, normal mode
end sub
'
function q(x as integer) as integer  'returns 2 raised to the power
 q=(1<<x)
End Function

'=======================================================================================
'                  Digoo Sensor - 433MHz decode and display.
'=======================================================================================
SUB blip                      'detects & reads Digoo 433MHz transmissions.
 tock% = tick%
 tick% = PIN(highrestimer)   'read the high resolution timer counts.
 select case tick%-tock%     'build the transmitted code bit by bit.
   case > 80
     if len(code$)=37 and left$(code$,1)="1" then getdata    'valid data.
     code$ =""
   case > 35
     code$ = code$ +"1"
   case > 15
     code$ = code$ +"0"
   case else                 'not valid transmission. This 'blip' is noise.
     code$ =""
 END select
END SUB
 '--------------------------------------------------
sub getdata                          'decodes the oC & %RH Digoo transmission.
 if mid$(code$,17,1)="0" then       '0 in bit 17 means a +ve temp.
   temp$ =STR$(VAL("&B"+mid$(code$,17,12))/10,2,1) 'rec'd oC is 0.1 res'n x10 so needs /10.
 else
   temp$ = "-" +STR$(VAL("&B"+reverse(mid$(code$,17,12),12))/10,2,1)  'temp is -ve.
 endif
 relhumid$ = STR$(VAL("&B"+mid$(code$,30,7)))      'rec'd %RH is whole numbers.
 channel$ = STR$(VAL("&B"+mid$(code$,15,2))+1)
 curdate$ = date$: curtime$ = time$
 dattime$ = right$(curdate$,2)+mid$(curdate$,4,2)+left$(curdate$,2)+" "+left$(curtime$,5)
 
 info$ = dattime$ + channel$ + temp$ + relhumid$
 if info$ = oldresult$ then exit sub  'removes the Digoo 'triple' transmission.
 oldresult$ = info$           'holds current result for above comparison.
 plotdata                     'valid information (data), so display it.
end sub
 '----------------------------------------------------
function reverse(in$,len%)as string   'inverts binary string - credit to MikeO at TBS.
 local x%
 for x%=1 to len%
   if mid$(in$,x%,1)="1" then
     reverse = reverse+"0"
   else
     reverse = reverse+"1"
   end if
 next x%
end function
 '----------------------------------------------------
sub drawgrids
 cls
 FONT #2          '12x20 NB: all fonts have chr(96) "`" replaced by degrees symbol.
 text 0,0,"  Date  Time  Ch  `C  %RH  Hg    Noise",,2
 gridtop = 3*mm.fontheight   'gridtop = top of y scales. Allows 3 rows of Font #2.
 box 0,0,mm.hres,20: box 0,0,mm.hres,gridtop     'boxes for heading & current data.
 font #1          '8x13
 timescale        'Display the timescale
 tempRHscales     'Display the temperature & %RH scales
 pressurescale    'Display the BME280 pressure scale
end sub
 '----------------------------------------------------
sub timescale        'Vertical grid (X axis) & Timescale (24hr format).
 local integer j,basehour
 static integer nextbasehour   'STATIC holds variable between SUB calls.
 
 'basehour' is the start time (hour) for the X grid time-scale. Scrolling starts when
 'the grid end is reached and a 'scrolling' flag is set in the 'scroll' subroutine.
 'The new basehour is then advanced one hour from the previous and stored in STATIC
 'variable 'nextbasehour' ready for the next scroll.
 
 if not scrolling then basehour = val(left$(time$,2)+"00") else basehour = nextbasehour
 nextbasehour = basehour +100          'advance nextbasehour if scrolling.
 if nextbasehour = 2400 then  nextbasehour =0   'test for midnight, reset if yes.
 
 for j=30 to MM.HRES step 60           '60 mins/gridline --> ~1 result per display line.
   if basehour = 2400 then  basehour =0       'test for midnight
   line j,gridtop,j,mm.vres,,BRGRAY           'one vertical grid line per hour.
   text j,mm.vres,str$(basehour,4,0,"0"),CB   'hour scale, 24-hour format, centered.
   basehour = basehour+100             'increments the hour scale in 24-hour format.
 next j
 dayndate                              'display day & date at centre base of screen.
 plotstart = val(mid$(time$,4,2)) +30  'mins past-the-hour to start (sync) the X plot.
 if scrolling then  plotstart = mm.hres-90  're-commence plotting in scrolling area.
 '======
 'if scrolling then  plotstart = mm.hres-90 else plotstart = mm.hres-32 'testing only
 '======
 timer=0   'zero elapsed-time base for X-axis data plot pos'n. in 'plotdata' sub.
end sub
 '----------------------------------------------------
SUB tempRHscales      'Draw Y-axis horiz. grid & oC/%RH fixed scales
 local integer j,t,r
 t = topT: r = topR
 'Horizontal grid lines - major and minor using MOD operator.
 for j=60 to mm.vres-10 step 25   '25lines=5oC 5lines/oC & 25lines=10%RH 2.5lines/%RH
   if j mod 2 then line 0,j,mm.hres,j,,LTGRAY else line 0,j,mm.hres,j,,BRGRAY
   text 0,j,str$(t,2,0," "),LM,,,yellow       'oC scale at left
   text mm.hres,j,str$(r),RM,,,green          '%RH scale at right
   t =t-5: r =r-10               'step oC & %RH scales by 5oC and 10%RH respectively.
 next j
end sub
 '----------------------------------------------------
sub pressurescale                     'Data from BME280 sensor. This scale autoranges.
 local integer j: local float k
 k = topP-0.1                        'scale starts 0.1 "Hg from gridtop
 for j= 85 to 235 step 50            'gives 0.1 "Hg = 25 pixels
   text 36,j,str$(k,2,1),LM,,,BLUE   'display scale within grid at left.
   k = k-0.2
 next  j
end sub
 '------------------------------------------------------------
sub plotdata                          'another Digoo oC/%RH data set coming in.
 local float flT,flRH
 flT =val(temp$):  flRH =val(relhumid$)  'convert to integer for noisecheck & plot.
 
 if flRH > 99.0 then flRH = 99.0     'DEBUG stops any over-scale RH stuffing up display.
 if flRH = 99.0 then relhumid$ = "99" 'DEBUG stops any over-scale RH stuffing up display.
 
 'Noisecheck data then display & plot on grid. Scroll at grid end.
 xposn = plotstart + (timer/60000)   'start posn + elapsed mins since grid draw or scroll.
 if xposn => mm.hres-30 then scroll  'if reached end of grid, start scrolling.
 
 If cn1=6 Then cn1=5     'Reset rolling average noisecheck data array counters to 5
 If cn2=6 Then cn2=5     'after first 6 have been built up. After that, number 6 is
 If cnP=6 Then cnP=5     'then always the current result.
 
 if channel$ ="1" then                'this is Ch1 data.
   cn1 = cn1+1                        'array element counter for Ch1 noisecheck arrays.
   Tch1(cn1)= flT:  Rch1(cn1)= flRH   'build up Ch1 noisecheck array elements.
   if cn1 =6 then                     'when six Ch1 array elements have been filled.
     text 8,20,dattime$ +"  "+ channel$,,2   'display date/time of current Ch1 data.
     print "                       ",Tch1(cn1)," ",Rch1(cn1) 'DEBUG Digoo Ch1 data
     noisecheck(Tch1(),5)             'check if Ch1 temp. is noise. Limits +/- 5oC.
     if noise then
       Ch1TN = Ch1TN +1                         'Update Ch1 temperature noise count.
       text 390,20,Str$(Ch1TN,2,0),,2,,yellow   'display it in textbox.
     else
       text 206,20,temp$,,2,,yellow   'display temperature in TCh1 textbox
       Pixel xposn,260-5*flT,yellow   'and plot using base & slope of temp. scale.        
     endif
     noisecheck(Rch1(),15)            'check if Ch1 %RH is noise. Limits +/- 10%.
     if noise then
       Ch1RN = Ch1RN +1               'Update Ch1 %RH noise count.
       text 430,20,Str$(Ch1RN,2,0),,2,,GREEN     'display it in textbox
     else
       text 270,20,relhumid$,,2,,green   'display %RH in RCh1 textbox & then plot
       Pixel xposn,260-(2.5*(flRH-20)),green  'using base, slope and offset of %RH scale.
     endif
   endif
   
 else                                 'this is Ch2 data.
   cn2 = cn2+1                        'counter for Ch2 rolling average noisecheck array.
   Tch2(cn2)= flT:   Rch2(cn2)= flRH  'build up Ch2 noisecheck array elements.
   If cn2 =6 Then                     'when six array elements have been filled
     text 8,39,dattime$ +"  "+ channel$,,2     'display date/time of current Ch2 data.
     print "                                  ",Tch2(cn2),"  ",Rch2(cn2) 'DEBUG Ch2 data
     noisecheck(Tch2(),5)             'check if Ch2 temp. is noise. Limits +/- 5oC.
     if noise then
       Ch2TN = Ch2TN +1               'update Ch2TN noisecount
       text 390,39,Str$(Ch2TN,2,0),,2,,MAGENTA    'display noisecount in TCh2 textbox
     else
       text 206,39,temp$,,2,,MAGENTA      'display temperature in TCh2 textbox
       Pixel xposn,260-5*flT,magenta      'and plot using base & slope of temp. scale.
     endif
     noisecheck(Rch2(),10)                'check if Ch2 %RH is noise. Limits +/- 15%.
     if noise then
       Ch2RN = Ch2RN +1                   'update Ch2RN noisecount
       text 430,39,Str$(Ch2RN,2,0),,2,,red      'display noisecount in RCh2 textbox
     else
       text 270,39,relhumid$,,2,,red      'display %RH in RCh2 textbox & then plot
       Pixel xposn,260-(2.5*(flRH-20)),red  'using base, slope and offset of %RH scale.
     endif
   endif
 endif
 gui beep 40                              'buzzer beep (pin 21) to announce new data.
 
 'Also, noisecheck BME280 presssure data, check within-scale then display & plot.
 if BMEcalled then                        'ignores very first pressure reading
   cnP = cnP+1                            'counter for rolling average noisecheck array.
   press(cnP) = pressure                  'build up noisecheck array.
   If cnP =6 Then noisecheck(press(),0.1) 'check if pressure reading is noise.
   if noise then
     text 320,30,Str$("Noise",2,2),,2,,BLUE  'DEBUG display "Noise" in pressure textbox
   else
     if pressure > topP-0.02 then         'pressure over-scale? Update limits &
       topP= topP+0.1: botP= botP+0.1: pressurescale  'display new pressurescale.
       triangle xposn,80,xposn+4,72,xposn-4,72,blue  'Draw indicative down-arrow.
     endif
     if pressure < botP+0.02 then         'pressure under-scale? Update limits &
       topP= topP-0.1: botP= botP-0.1: pressurescale  'display new pressurescale.
       triangle xposn,237,xposn+4,245,xposn-4,245,blue  'Draw indicative up-arrow.
     endif
     Text 312,30,Str$(pressure,2,2),,2,,BLUE    'display pressure in textbox
     yposP = 260-(250*(pressure-botP))     'base & slope of pressure scale
     pixel xposn,yposP,BLUE                'plot pressure; 1"Hg pressure =250 pixels.
   endif
 endif
end sub
'---------------------------------------------------
sub noisecheck(param() As float,limit As float) As integer   'Simple rolling average.
 Local integer i,m
 Local float sum,rollave
 
 noise =0                       'reset flag.
 For i = 1 To 5
   sum = sum + param(i)
 Next i
 rollave = sum/5                'calc. rolling average of first 5 array elements.
 If param(6)> rollave+limit Or param(6)< rollave-limit Then noise =1  'test current result.
 if noise then                                   'DEBUG
   line xposn,134,xposn,142                      'DEBUG mark display when noise occurred.
   text xposn,150,Str$(param(6),2,2),ctv,,,red   'DEBUG display param(6)vertically.
   text xposn,65,Str$(rollave,2,2),ctv,,,cyan    'DEBUG display rollave vertically.
 endif                                           'DEBUG
 If noise Then Exit Sub         'if noise, exit with flag set.
 For m = 1 To 6                 'if not noise, shuffle array back one. This drops 1st array
   param(m) = param(m+1)        'element thus the current data, param(6), is now param(5).
 Next m
End Sub
'---------------------------------------------------
sub scroll
 local integer b
 text mm.hres/2,mm.vres-mm.fontheight,"                  ",CB   '18 spaces clears dayndate.
 scrolling = 1                  'set scrolling flag for timescale subroutine.
 blit 78,260,18,260,13,12       'move second leftmost hours timescale to leftmost.
 for b = 90 to 390 step 60      'move main grid/data display left in 1hr segments....
   blit b,58,b-60,58,60,213     'from below data box to bottom of screen.
 next b
 blit write #1,mm.hres-90,60,60,200   'overwrite last hour with stored clean screen.
 timescale                      'update & display the timescale.
 pressurescale                  're-display pressure scale; it's been blitted offscreen.
 xposn =mm.hres-90              'reset plot pos'n to start of scroll area.
end sub
 '---------------------------------------------------
sub dayndate        'day-of-week code thanks to "MicroBlocks" at TBS forum.
 local integer year,month,day,dayofweek,a,m,y
 local string DOW$(6) length 3 = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
 local string dispdayndate$
 curdate$ = date$
 Year=VAL(MID$(curdate$,7,4)): Month=VAL(MID$(curdate$,4,2)): Day=VAL(MID$(curdate$,1,2))
 a = int((14-month)/12)
 m = month + 12*a - 2
 y = year - a
 DayOfWeek = (day+y+int(y/4)-int(y/100)+int(y/400)+int(31*m/12))mod 7
 dispdayndate$ = DOW$(DayOfWeek)+" "+curdate$
 text mm.hres/2,mm.vres-mm.fontheight,"<-- "+ dispdayndate$,CB   'DOW & date on timescale
end sub
 '---------------------------------------------------
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 844
Posted: 02:01pm 10 May 2020
Copy link to clipboard 
Print this post

Hi Greg,
Good job. Those Digoo things are good value. Seem to be OK on batteries as well.
Looks like it could be raining outside? 99% RH

Regards
Gerry
Latest F4 Latest H7
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1328
Posted: 02:52am 11 May 2020
Copy link to clipboard 
Print this post

Hi Gerry,
Thanks for that, though the tricky efforts were from you, Jim and Peter.
Yes it was certainly raining when that photo was taken and probably well over 99%. I had to limit the plot to 99 because over that, it stuffs up the display scrolling.

I've had a good run from the Digoo units too. I'm not sure when I last changed the batteries but I'd say they go about a year each. I added the noise-check to count and display bad results because they seem to correlate with low batteries. I also had to replace the internal coil aerials to improve the range - made little bare 'loaded' aerials to do it. Took me about half an hour to make each one, winding 16 neat turns of wire using a shish-kebab skewer as the template and cutting a tiny slot in the housing to fit. I also put one on the receiver and now 10 metres through a wall is a doddle.

When I first started playing with it I looked at the signal coming in at the receiver (with the scope) and was amazed how much white noise was there. I thought there was no way this could work so I coded a counter into the 'blip' routine and it triggered hundreds of times a second but still managed to get reliably through the rest of the code for the display. Someone (you maybe?) posted about adding a capacitor to the receiver to 'quieten' it but I couldn't find the post. I'd still like to do that if I could find the post.

The BME280 pressure sensor is very reliable and amazingly sensitive. It easily shows a obvious 'bump' when a front comes through. A couple of days ago there were three or four pressure bounces over about a three hour period.
Peter's code for the BME is pretty involved and makes the listing a bit hard to follow. It would be nice to be able to shorten that code but I'm an awful long way from being up to that. I remember at the time he posted it that he said he couldn't understand why the manufacturers made the handling of the registers so 'messy'. If Peter had cause to complain then I'm stearing well clear!

Greg
 
Print this page


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

© JAQ Software 2024