Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 00:25 03 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 : Air Quality Sensors and Systems for MM?

     Page 2 of 4    
Author Message
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 840
Posted: 12:42am 01 Feb 2020
Copy link to clipboard 
Print this post

Folks, the nova SDS011 sensor arrived yesterday but I haven't had a chance to play with it yet - I will shortly.

Cheers,

Andrew
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1593
Posted: 03:02pm 01 Feb 2020
Copy link to clipboard 
Print this post

Geoff,

I read the article in Silicon Chip and am going to build the Air Quality Monitor. You say you have plans to add a particulate sensor and a CO2 sensor. I wonder if you could also add a DS3231 RTC so the graph could have real time stamps on it? Perhaps a small digital clock display up the top? I believe th I2C addresses don't conflict.

Bill
Keep safe. Live long and prosper.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 10:25pm 01 Feb 2020
Copy link to clipboard 
Print this post

No Bill, an RTC was not on the list.  It seems like a lot of trouble (for the constructor) to get a small improvement but perhaps it could be made optional.  Something to look into.

Geoff
Geoff Graham - http://geoffg.net
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 840
Posted: 10:57pm 01 Feb 2020
Copy link to clipboard 
Print this post

OK,
I've got the sensor running by using the supplied USB connector and some free Windows software from here.

This takes the binary data from the SDS011 and plots a graph of P10 and P2.5 readings over time (on the PC). (I've not mastered it by any means)





Now "all" I need to understand is how to dispense with the TTL to USB connector and communicate with a MM (I'll probably use another LCD Backpack).
Jim's pdf's above seem to explain it all - but are a little beyond me (particularly communicating via serial in hex (I'm used to ASCII strings)).
(any tips welcome . . .)

Re the timing, I have an HC-12 network whereby every remote device (about a dozen) receives a date and time message every two hours - based on a GPS in the base station. The two hours is arbitrary but the MM time drift seems to be not too bad over this. (I prefer GPSs to RTCs - comes from a lot of sea-miles).

My plan is to add an HC-12 to this new unit so it can be located anywhere (within range) that I want to read PPM.

Cheers,

Andrew
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5911
Posted: 11:12pm 01 Feb 2020
Copy link to clipboard 
Print this post

My sensor should arrive this week sometime but not sure when I will get a chance to play with it.

I would have liked it a couple of days ago when the PM2.5 levels reached 200+ here.
Today its back down to 1 where it belongs.

Jim
VK7JH
MMedit   MMBasic Help
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 840
Posted: 12:50am 05 Feb 2020
Copy link to clipboard 
Print this post

Hi all,
Here is my (simple) code to read the default output from the SDS011.
This is a work in progress as I now need to:
- set the duty cycle
- plot the output in a meaningful way
- move it from the bench to the real world.

I'd really appreciate enhancements to my code etc (particularly the comms).
(Once again I am in awe of how simple, yet powerful, MM and MMBASIC are to use)

Cheers,

Andrew



 'AIRQUAL.BAS
 
 'Uses an SDS011 particle sensor to measure and report particulate matter densities (P2.5 and P10)
 
'v6:
 'zzz comments to be investigated further
 'All this does is print the "C0" data and CSum, p2.5 and P10 every second
 
'NOTES_ON_SDS011:
 
'See: https://www.thebackshed.com/forum/ViewTopic.php?FID=16&TID=11922&LastEntry=Y#143737
 ' for links to protocols and documentation.
 
 'The default is for the sensor to send data every second - this will limit its life to < a year
 'Hence restrict duty cycle to "30 seconds every 5 minutes will see me out" - quote from Tassie Jim.
 'Settings for Sleep and Work are not saved after powerdown
 'The connector L to R is:
 ' 1: n/c
 ' 2: n/c (=PM2.5 PWM output)
 ' 3: 5v input
 ' 4: n/c (=PM10 PWM output)
 ' 5: Gnd
 ' 6: RX - connect to MM pin 10
 ' 7: TX - connect to MM pin 9
 
 option explicit
 Const True  = 1
 Const False = 0
 
 dim string Indata(9)
 dim integer Count, Flag_Data, I, CSum
 dim Float PM25, PM10
 
 OPEN "COM2:9600,256,Get_In" as #1  'Incoming data
 Count = -1  'This is a counter NOT a True/False flag
 Flag_Data = False
 
'MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM_Main_loop:
 do
   if Flag_Data then
     Flag_Data = False
     Csum = 0
     
     if hex$(ASC(Indata(1))) = "C0" then   'We have a data reporting line
       for I = 0 to 9
         Print I; Tab(5); ASC(Indata(I)); tab(15); hex$(ASC(Indata(I)),2)
         if I > 1 AND I < 8 then
           CSUM = CSUM + ASC(Indata(I))
         End If
       next I
       
       PM25 = ASC(Indata(3))*256 + ASC(Indata(2))/10
       PM10 = ASC(Indata(5))*256 + ASC(Indata(4))/10
       print CSUM; tab(10); Hex$(CSUM), PM25, PM10
       print 'Put a gap between packets
     End If 'End of data reporting test
     'zzzMore output to come here
     
   End If
 Loop
'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm_End_of_main_loop:
 
Sub Get_In
 Count = Count + 1
 Indata(Count) = input$(1,1)
   
 if hex$(ASC(Indata(Count))) = "AB" then 'the end of this packet
   Flag_Data = True
   Count = -1
   Exit Sub
 End if
End Sub 'Get_In
Edited 2020-02-05 10:52 by Andrew_G
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 840
Posted: 06:42am 05 Feb 2020
Copy link to clipboard 
Print this post

Hi all,
I've spent several days on this and I have RTFM but I'm stumped by my lack of understanding of non-ASCII communications.
I can now read the data as it comes in, and I can calculate the checksum (sort of).

But I can't see how to send data to the sensor.

The communication protocol that Tassie Jim cites above gives the following example to query the current working mode:
"AA B4 02 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 AB"

How do I write this to the sensor (ie PRINT #1, <what?> )?

(It should respond along the lines of:
"AA C5 02 00 00 00 A1 60 03 AB" to show the sensor is in report active mode but I see nothing back.)

Many thanks,

Andrew


(Jim's protocol document says:

"1 Protocol Configuration:
Serial Port: 5V TTL, 9600bps with 8 data bit, no parity, one stop bit
Data Packet (19 bytes): Head+Command ID+Data (15 bytes)+checksum+Tail

Checksum: Low 8bit of the sum result of Data Bytes not including packet head, tail and Command ID"

In the above line:
"AA" and "AB" are the Head and Tail,
"B4" is the Command ID,
"02 . . . to FF FF" are the data,
"FF FF" means that the packet is for all sensors, not just a specific ID,
"the last "00" is the checksum.)
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5911
Posted: 06:43am 05 Feb 2020
Copy link to clipboard 
Print this post

My sensor arrived today.
  Quote    ' SDS011 dust sensor
 ' serial 9600 8 N 1 5V TTL
 '
 ' device = &HFFFF for all connected devices.
 '
 DIM FLOAT PM25, PM10
 
DIM INTEGER x, readAvailable, sleepTime
 
DIM k$, r$, reportMode$, state$, ID$
 
 
OPEN "COM2:9600,256" AS #3  'Incoming data
 x = sendCMD(8,1,0,&HFFFF) ' duty cycle continuous to get the initial reading
 PAUSE 1000
 x = sendCMD(
2,0,0,&HFFFF) ' check report mode
 x = sendCMD(6,0,0,&HFFFF) ' check state
 x = sendCMD(8,1,5,&HFFFF) ' duty cycle 30 secs on every 5 minutes
 
 
DO
   
IF LOC(#3) > 0 THEN
     k$ =
INPUT$(1,#3)
     r$ = r$ + k$
     
IF ASC(k$) = 171 THEN doRead ' end of data flag rec
   ENDIF
   
IF readAvailable THEN doDisplay
 
LOOP
 
SUB doDisplay
 
PRINT TIME$;", PM2.5="; STR$(PM25,4,1);" ug/M3, PM10="; STR$(PM10,4,1);" ug/M3, Mode= "; reportMode$;", State= "; state$;
 
IF sleepTime = 0 THEN
   
PRINT ", Duty= continuous"
 
ELSE
   
PRINT ", Duty= "; (sleepTime + 30)/60;" mins"
 
ENDIF
 readAvailable =
0
END SUB
 
SUB doRead
 
LOCAL INTEGER replyMode
 
IF MID$(r$,2,1)= CHR$(&hC0) THEN replyMode = 1
 
IF MID$(r$,2,1)= CHR$(&hC5) THEN replyMode = ASC(MID$(r$,3,1))
 
SELECT CASE replyMode
   
CASE 1 ' data
     PM25 = (ASC(MID$(r$,3,1)) + ASC(MID$(r$,4,1))*256)/10
     PM10 = (
ASC(MID$(r$,5,1)) + ASC(MID$(r$,6,1))*256)/10
   
CASE 2 ' data reporting mode
     IF ASC(MID$(r$,5,1)) = 1 THEN
       reportMode$ =
"query "
     
ELSE
       reportMode$ =
"active"
     
ENDIF
   
CASE 5 ' new ID
     ID$ = HEX$(MID$(r$,8,1),2)+HEX$(MID$(r$,9,1),2)
   
CASE 6 ' sleep mode
     IF ASC(MID$(r$,5,1)) = 1 THEN
       state$ =
"awake "
     
ELSE
       state$ =
"sleep "
     
ENDIF
   
CASE 8 ' duty cycle
     sleepTime = ASC(MID$(r$,5,1)) *60 - 30
     
IF sleepTime < 0 THEN sleepTime = 0
 
END SELECT
 r$ =
""
 readAvailable =
1
END SUB
 
FUNCTION sendCMD( c AS INTEGER, d AS INTEGER, e AS INTEGER, device AS INTEGER) AS INTEGER
 
LOCAL s$
 s$ =
CHR$(&hAA)+CHR$(&hB4)+CHR$(c)+CHR$(d)+CHR$(e)+STRING$(10,0)+CHR$(device\256)+CHR$(device AND 255)
 s$ = s$ + cs$(s$,
17)+CHR$(&hAB)
 
PRINT #3,s$;
END FUNCTION
 
FUNCTION cs$(s$,l AS INTEGER)' l should be 7 for reply or 17 for command
 LOCAL n, k
 
FOR n = 3 TO l
   k = k +
ASC(MID$(s$,n,1))
 
NEXT n
 cs$ =
CHR$(k AND 255)
END FUNCTION

Using an interrupt for the received data as you have done would be much better but it didn't suit my setup.

It can take 30 seconds to see a reading on startup.
There is one reading every 5 minutes as configured above.
I haven't bothered doing a checksum of incoming data, only commands sent.

17:23:25, PM2.5=    0.0 ug/M3, PM10=    0.0 ug/M3, Mode= , State= , Duty= continuous
17:23:25, PM2.5=    0.0 ug/M3, PM10=    0.0 ug/M3, Mode= , State= , Duty= continuous
17:23:25, PM2.5=    0.0 ug/M3, PM10=    0.0 ug/M3, Mode= active, State= , Duty= continuous
17:23:25, PM2.5=    0.0 ug/M3, PM10=    0.0 ug/M3, Mode= active, State= awake , Duty= continuous
17:23:25, PM2.5=    0.0 ug/M3, PM10=    0.0 ug/M3, Mode= active, State= awake , Duty=  270
17:24:20, PM2.5=    0.8 ug/M3, PM10=    2.6 ug/M3, Mode= active, State= awake , Duty=  270
17:29:21, PM2.5=    0.9 ug/M3, PM10=    2.7 ug/M3, Mode= active, State= awake , Duty=  270
17:34:21, PM2.5=    1.0 ug/M3, PM10=    6.5 ug/M3, Mode= active, State= awake , Duty=  270
17:39:22, PM2.5=    1.1 ug/M3, PM10=    4.0 ug/M3, Mode= active, State= awake , Duty=  270


I just need to wait for the next smokey day.

Jim
VK7JH
MMedit   MMBasic Help
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 840
Posted: 09:03pm 05 Feb 2020
Copy link to clipboard 
Print this post

Hi Jim,
Thank you! There is so much to learn. Lots of little things like the CHR$ data element by data element and the correct checksum calculation. You have made my day!

One thing that caught my eye, and has puzzled me, in the last "Function cs$" you have:

FOR n = 3 to 1
...

Is that what you intend (instead of FOR n = 1 to 3) or is there a STEP -1 missing?

Thanks again,

Andrew
Edited 2020-02-06 07:04 by Andrew_G
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5911
Posted: 09:22pm 05 Feb 2020
Copy link to clipboard 
Print this post

That's an L not one.

I knew I shouldn't use ell or oh for variables

Jim
VK7JH
MMedit   MMBasic Help
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 840
Posted: 09:28pm 05 Feb 2020
Copy link to clipboard 
Print this post

Thanks Jim,
That explains it and of course makes sense/context.
I had noticed some of the "l"s and "o"s (they added a bit of spice to my reading overnight). (Even capitals would help . . . but don't bother now - I'll go looking)

Cheers,

Andrew

(Edit: The o was one of mine. I'd typed in "Co" instead of "C0" - took a while to find - A)
Edited 2020-02-06 07:32 by Andrew_G
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5911
Posted: 08:36pm 06 Feb 2020
Copy link to clipboard 
Print this post

I left my sensor running in my office over night
When I went to bed PM2.5 was 1 - 1.2 but this morning it was reading ~10
I checked the EPA site and they read 15 for PM2.5 so that's close considering I am reading indoors.
Not that I needed the sensor to tell me. The lungs do that without any prompting.

Bloody easterly weather brings the smoke haze back.

Jim
VK7JH
MMedit   MMBasic Help
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 840
Posted: 12:18am 07 Feb 2020
Copy link to clipboard 
Print this post

Hi Jim,
Yes I think the readings are pretty close to good enough, especially since I'm likely to be comparing a "felt OK" with "better stay indoors" degree of accuracy.

My current problem is to find a box that fits it and an LCD Back pack (I want to graph it over time) - a normal #3 jiffy box is just too small (it is 7 (plus a little more for the air tube and a connector) x 7 x ~2.5 cm).
There is a "waterproof" box that might fit it all (9 x 11.5 x 5.5 cm) and I can cut a hole to fit the LCD in the lid. (At this stage I don't want to leave it out overnight.)

Cheers,

Andrew

(In an effort to see when it was actually "Working" I tried attaching a LED to the fan but that didn't work so now I send a "CMD(6,0,0,&HFFFF)" every minute and it reports back OK - I'll show that on the LCD.)
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 08:50pm 08 Feb 2020
Copy link to clipboard 
Print this post

Plan on ordering a couple today.

With a couple of spare Backpacks & a handful of E28's & HC-11's on hand, the idea of an E28 controlled remote sensor comes straight to mind.

Display indoors & sensor outside; but that idea would be short lived as I'd feel robbed if I didn't have an indoor reading as well.


Cheers

Phil.
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 840
Posted: 10:40pm 08 Feb 2020
Copy link to clipboard 
Print this post

Hi Phil,
I've been playing with the sensor ( off and on ) and with Jim's code it really is easy to use.
We should have explained that it has a fan to suck air in (via the built in nozzle or an optional tube up to 1m long (not supplied)). The fan exhausts out a rectangular slot (no nozzle) into your enclosure. So, whilst the tube could be inserted into a neat hole the "exhaust" means the enclosure would not easily be air/water tight.
It looks like a Jaycar box "HB6126" or "HB6127" will fit the sensor and an MM LCD V2 backpack with a 2.8" LCD but NOT a v3 or a 3.5" LCD (unless you hack the box).

Cheers,

Andrew
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5911
Posted: 10:58pm 08 Feb 2020
Copy link to clipboard 
Print this post

It is also important to keep light away from the input and output ports.
I will put a short tube on the input and if it goes outside it will be in my weather enclosure with the tube extending outside through a hole in the enclosure. A black plastic Jaycar box with sufficient holes for the exhaust will complete the sensor setup.

I will probably get a second unit.

I am a still playing inside and pleased with the results. Having the EPA nearby helps a lot.

Jim
VK7JH
MMedit   MMBasic Help
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 840
Posted: 02:47am 09 Feb 2020
Copy link to clipboard 
Print this post

Hi,
I just used a pair of side-cutters to hack into one of the Jaycar "HB6126" (or "HB6127") boxes and it is remarkably easy to accommodate a MK3 Backpack with 3.5" LCD - 5 min to a rough stage.
(I can route a neat enough rectangular hole for the LCD).
This will be my goto from now on.

Andrew
(Edit: route has an "e")
Edited 2020-02-14 08:16 by Andrew_G
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5911
Posted: 08:33pm 21 Feb 2020
Copy link to clipboard 
Print this post

I ordered a second unit on the 9th Feb. It finally shipped on 21st Feb.
Corona virus is certainly slowing things down.
I hope the postage time doesn't drag out any more than usual.

Jim
VK7JH
MMedit   MMBasic Help
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 01:39am 22 Feb 2020
Copy link to clipboard 
Print this post

When it arrives maybe it would be a good idea to wipe it down with freon, alcohol or maybe clorox and then a blast from a hot air gun before breathing near it!!!

Paul in NY
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 09:18pm 09 Mar 2020
Copy link to clipboard 
Print this post

My CCS811's arrived last week & were promptly plugged on a bread board.

First run was a fail, as the back pack had an older firmware that didn't support Static. Quick firmware update fixed that.

Powered it up & did the firmware around midday Friday, so was burned in by Sunday.
Only notable observation during that period was the readings from the HDC1080.
The temp seems a quite few degrees off compared to the DS18B20's I have in each room.

Showed 24° for the bedroom this morn while the DSB showed 20.8°.
Dunno is it could just be the module self heating, but was out a lot more than I expected.

Interesting moving it from room to room. And in particular using the mower a few metres from the back door.

An SDS011 should arrive later this week, so will have a look at that as well.

With the cooler weather coming it will be Wood Heater Season soon.
That will bring interest as I exclusively burn well seasoned Iron Bark here with minimal smoke visible, but noticed a new neighbour stocking up a winter supply over the weekend. A truck load of shipping pallets arrived & were cut to fire sized billets & stacked against the fence.

Think I sensed a Test Run of their fire early last week; smelt that burning Rubbish Dump smell wafting in the back door....


Cheers.


Edit,

I assume it's fine to ignore the 20min warm up period when it's off for a few seconds to change the battery bank?
Edited 2020-03-10 07:39 by Phil23
 
     Page 2 of 4    
Print this page
© JAQ Software 2024