This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Air Quality Monitor Stand alone unit
#1
Werk
I am building a stand alone AQ unit for a friend but cannot get the LCD to display anything.
I have changed the display, (it works on another unit if i change the address in the software to suit) but not with the new build.
I have not installed the Tx socket or Tx unit and LED.
Code is attached
Regards
Jim

Code:
/***************************************************************************
WeatherDuino - Air Quality Monitor
For PMS7003 and MH-Z19B

Version:                  : 7.1 b004
Arduino IDE Compatilility : IDE 1.8.3
Version Release date      : 10/02/2018
Last revision date        : 10/02/2018
Licence                   : GNU GPLv3
Author                    : Werk_AG (MeteoCercal)
Support Forum             : http://www.meteocercal.info/forum


-------------------------------------------------------------------------------------
         >>>>>>>>>>>> About Copyrights <<<<<<<<<<<<<<<
-------------------------------------------------------------------------------------
License:GNU General Public License v3.0

   WeatherDuino Pro2 PLUS Base Unit / RF Receiver
   Copyright (C) 2017  Werk_AG - www.meteocercal.info

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*************************************************************************************/

#include <RH_ASK.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Timer.h>
#include "Adafruit_SHT31.h"     // library for SHT31
#include <SHT2x.h>              // library for SHT2x
#include <HTU21D.h>
#include <SoftwareSerial.h>
#include "Config_AQI.h"         // User configurable options file


const char* VersionNumber = "v7.10 b004";
// --------------------------------------------------------------------------------------
//   Hardware input/output pins
// --------------------------------------------------------------------------------------
#define TX_PTT_PIN      7
#define TX_PIN          8
#define PMS7003_SetPin  9      
#define PM_RX           10
#define PM_TX           11
#define CO2_RX          12
#define CO2_TX          13


#if (LCD_Display == 1)
// ---- Define LCD I2C address
// Only change this if your LCD don't display any data. I2C_Scanner utility may help you to find the address of your LCD display
// Default address will work most of the times!
#define LCD_I2C_Address 0x20

LiquidCrystal_I2C lcd(LCD_I2C_Address, 20, 4);
byte heart[8] = {0x0, 0xa, 0x1f, 0x1f, 0xe, 0x4, 0x0};     // custom character:
#endif

// --------------------------------------------------------------------------------------
//   Usefull Macros
// --------------------------------------------------------------------------------------
#define setPortHIGH(port, pin) ((port) |= (1 << (pin)))
#define setPortLOW(port, pin) ((port) &= ~(1 << (pin)))


// --------------------------------------------------------------------------------------
//   General variables
// --------------------------------------------------------------------------------------
const char* PM_units = {" ug/m3"};
const byte Z19_readCMD[9] = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};   // Z19 command to ask for data
 
const byte readInterval  = 15;     // 15 Minutes - WARNING!!! - NEVER CHANGE THIS VALUE, OR ALL CALCULATIONS WILL BE WRONG

byte readCount_1H        = 0;

uint16_t CO2_1H_Avg      = 0;
uint16_t AQI_12H_nowCast = 0;

uint16_t CO2_RAW         = 0;
uint16_t CO2_instant     = 0;
unsigned int Z19_Temp;
unsigned int Z19_Ready   = 15000;
bool Z19_Valid_read      = false;

float Temperature        = 0.0;
float Humidity           = 0.0;
float PM25_1H_Avg        = 0.0;
float PM25_12H_NowCast   = 0.0;
float pm10,pm25;
long last_AQIread;


// Data to calc AQI index from PM2.5 (EPA Standard)
const float concentrationBoundaries[7][2] =
{
  {0.0f,12.0f},
  {12.0001f,35.499f},
  {35.5f,55.499f},
  {55.5f,150.499f},
  {150.5f,250.499f},
  {250.5f,350.499f},
  {350.5f,500.499f}
};

const unsigned int indexBoundaries[7][2] =
{
  {0,50},
  {51,100},
  {101,150},
  {151,200},
  {201,300},
  {301,400},
  {401,500}
};


// -------------------------------------------------------------------
//      Data structure for PMS7003
// -------------------------------------------------------------------
#if (PMsensor_type == 0)
struct PMS7003_datastruct {
   uint8_t  frameHeader[2];
   //uint16_t frameLen = MAX_FRAME_LEN;
   float concPM1_0_CF1;
   float concPM2_5_CF1;
   float concPM10_0_CF1;
   float concPM1_0_amb;
   float concPM2_5_amb;
   float concPM10_0_amb;
   //uint16_t rawGt0_3um;
   //uint16_t rawGt0_5um;
   //uint16_t rawGt1_0um;
   //uint16_t rawGt2_5um;
   //uint16_t rawGt5_0um;
   //uint16_t rawGt10_0um;
   //uint8_t  version;
   //uint8_t  errorCode;
   uint16_t checksum;
} PMS7003;
#endif


// --------------------------------------------------------------------------------------
//   Arrays for 1H averages and 12 hours NowCast
// --------------------------------------------------------------------------------------
uint16_t CO2_1H_array[4];
float PM25_1H_array[4];
float PM25_12H_array[12];


//---------------------------------------------------------
//     Create objects
//---------------------------------------------------------
#if (TH_Sensor == 1)
 HTU21D TH;
#endif
#if (TH_Sensor == 3)
 Adafruit_SHT31 sht31 = Adafruit_SHT31();  
#endif

 SoftwareSerial Dust_Serial(PM_RX, PM_TX);       // define serial for PM sensor

#if (Use_CO2 == 1)
 SoftwareSerial CO2_Serial(CO2_RX, CO2_TX);    // define serial for CO2 sensor
#endif

#if (TX_Mode == 1)
 RH_ASK ask433(1000, -1, TX_PIN, TX_PTT_PIN);
#endif  

Timer t;

// --------------------------------------------------------------------------------------
//   Setup things
// --------------------------------------------------------------------------------------
void setup()
{

#if ((Debug_PM == 1) || (Debug_CO2 == 1))
 Serial.begin(19200);
 Serial.println(F("     WeatherDuino 4Pro"));
 Serial.print(F("Air Quality Monitor "));
 Serial.println(VersionNumber);
 Serial.println();
 Serial.println(F("Please wait..."));
 Serial.println();
#endif
 Dust_Serial.begin(9600);  //Create Software Serial for Dust sensor
#if (Use_CO2 == 1)
 CO2_Serial.begin(9600);   //Create Software Serial for CO2 sensor
#endif  
#if (PMsensor_type == 1)
Dust_Serial.listen();
Dust_Serial.write(SLEEPCMD, 19);               // Put the sensor in sleep mode
Dust_Serial.flush();
#endif
Wire.begin();


//------------------------------------------------------------
// Setup PINS
//------------------------------------------------------------
 pinMode(TX_PIN, OUTPUT);
 pinMode(TX_PTT_PIN, OUTPUT);
 digitalWrite(TX_PTT_PIN, LOW);
   
 // Set the Pin used to control the SET function on PMS7003 (LOW = sleep mode)
 pinMode(PMS7003_SetPin, OUTPUT);
 setPortLOW(PORTB, 1);                // Pin 9 - Used in final boards
 
 
//------------------------------------------------------------
// Setup the transmitter and transmition timers
//------------------------------------------------------------
 #if (TX_Mode == 1)
   ask433.init();
 #endif
 
 // Init devices
 #if (TH_Sensor == 1)
   // TH.begin();
 #endif
 #if (TH_Sensor == 3)
   sht31.begin(SHT31_address);    
 #endif
 #if LCD_Display == 1
   lcd.begin();
   init_LCD();
 #endif

 #if (Use_CO2 == 1)
   warmUp();                          // Warm UP MH-Z19 for 3 minutes
   Setup_MH_Z19();
 #endif

 read_THsensor();
 
 #if LCD_Display == 1
  update_LCD();
 #endif
 
 read_AQISensors();

 t.every(37000, runEvery37s);        
 t.every(60000 * readInterval, read_AQISensors);  
     
}


// --------------------------------------------------------------------------------------
//   Main Loop
// --------------------------------------------------------------------------------------
void loop()
{  
 t.update();

// Reboot if millis is close to rollover. RTC_Millis won't work properly if millis rolls over.  Takes 49 days to rollover
//if ( now_millis > 4294000000UL ) softReset();    
}

Code:
--------------------------------------------------------------------------------------
//   WeatherDuino - Air Quality Monitor v7.10 b004
//                  User Configurable Options
// --------------------------------------------------------------------------------------

// --------------------------------------------------------------------------------------
//   Define ID and TX unit number
// --------------------------------------------------------------------------------------
#define StationID  0xA1      // Must be equal to your RX Unit (Value from 0x00 to 0xFF)  


// --------------------------------------------------------------------------------------
//   Define type of PM sensor
// --------------------------------------------------------------------------------------
#define PMsensor_type   0    // 0= PMS7003


// --------------------------------------------------------------------------------------
//   For the PMS7003 define data set
// --------------------------------------------------------------------------------------
#define PMS7003_dataSet 1    // 0= CF1, 1= Ambiente (You should always use this data set)


// --------------------------------------------------------------------------------------
//   CO2 (MH-Z19) Settings
//   Note: For outside use, the MH-Z19B model produces more accurate results
// --------------------------------------------------------------------------------------
#define Use_CO2         1    // 0= Not instaled, 1= Instaled
#define Z19_model       2    // 1= Model A, 2= Model B  (ATTENTION: Make sure you select the correct model)                            

// Set measure range                              
#define Z19_range       5    // Don't change (Keeps default factory range 0..5000 ppm)
                            // Valid values for Model A: 1= 1000ppm, 2= 2000ppm, 3= 3000ppm, 5=5000ppm
                            // Valid values for Model B: 2= 2000ppm, 5= 5000ppm

int16_t CO2_OffSet   = 0;    // Fine adjust to compensate sensor error (This value should be determined case by case. Values between -50 and 50)

// --------------------------------------------------------------------------------------
//   Define type of Temperature / Humidity sensor
// --------------------------------------------------------------------------------------
#define TH_Sensor    1       // 1= HTU21D, 2= SHT2x, 3=SHT3x  


// --------------------------------------------------------------------------------------
//   Enable / Disable RF data transmission
// --------------------------------------------------------------------------------------
#define TX_Mode     0       // 0= No data will be transmitted via RF, 1= Transmit Data


// --------------------------------------------------------------------------------------
//   Enable / Disable LCD Display
// --------------------------------------------------------------------------------------
#define LCD_Display  1       // 0= Disable Display, 1= Enable Display


// --------------------------------------------------------------------------------------
//   Enable / Disable PM sensor Debug on Serial Monitor
// --------------------------------------------------------------------------------------
#define Debug_PM     1      // 0= Disable 1= Enable


// --------------------------------------------------------------------------------------
//   Enable / Disable CO2 sensor Debug on Serial Monitor
// --------------------------------------------------------------------------------------
#define Debug_CO2    1      // 0= Disable 1= Enable


// --------------------------------------------------------------------------------------
//   SHT31 I2C Address - Default address will work most of the times!
// --------------------------------------------------------------------------------------
#define SHT31_address 0x44       // Default value is 0x44, but it can be changed to 0x45
Reply
#2
Hi Jim,

If a particular LCD module works with one unit at a given address, it should work with any other unit using the the same I2C address.
Having or not the TX module installed doesn't affect the functionality of the LCD display.
MeteoCercal - Air Quality Data
Click here to watch at my ThingSpeak channel

[Image: banner_EN.php]

Reply
#3
(12-02-2018, 19:05)Werk_AG Wrote: Hi Jim,

If a particular LCD module works with one unit at a given address, it should work with any other unit using the the same I2C address.
Having or not the TX module installed doesn't affect the functionality of the LCD display.

Werk,
I understand the address issues but I could not get the system to boot. 
I finally solved the issue, it was the HTU21D, I have no idea why but by disconnecting it the unit boots as it should and I replaced it with a spare and now all is working well.
On the issue of 20 x4 LCD’s I recently received a couple of serial units without the I2C module, and realising my mistake, I ordered the modules and attached them but they will not work with my AQ unit.
I noticed that the only difference is that the two capacitors C1 andC2 are missing from the two ex serial modules.
Do you know what the values of these SMD caps are? C2 appears to be a tantalum as it has a polarity marking, because I am sure that if fitted they would be usable again
Regards
Jim
Reply
#4
(13-02-2018, 22:15)[Barrow4491 Wrote: On the issue of 20 x4 LCD’s I recently received a couple of serial units without the I2C module, and realising my mistake, I ordered the modules and attached them but they will not work with my AQ unit.
I noticed that the only difference is that the two capacitors C1 andC2 are missing from the two ex serial modules.
Do you know what the values of these SMD caps are? C2 appears to be a tantalum as it has a polarity marking, because I am sure that if fitted they would be usable again

Hi Jim,

Do not fully understand what you are dealing with serial modules? I'm used to buying both parts separately, and after soldering I've never experienced any problems.
For example on Aliexpress:

LCD 2004 5V yellow-green - the price is USD 3.29
I2C interface LCD 1602 2004 - the price USD 0.94

   

   

Good luck!
Best Regards
Zdenek
[Image: banner.php]
Reply
#5
I also order i2c modules separately and solder them. It is necessary to make bridges of welds on A0 A1 and A2 to define the address, after the address does not correspond to what one can find on internet. Just use an I2c address scan provided with the weatherduino software package.
So just change the address in the INO RX.
Reply
#6
(14-02-2018, 08:09)f4aii Wrote: Just use an I2c address scan provided with the weatherduino software package.
So just change the address in the INO RX.

Yes, that's exactly my choice - but I always had the same address ...
Have a nice day.
Best Regards
Zdenek
[Image: banner.php]
Reply
#7
Usually I don't do any bridges at A0, A1 or A2. Without any bridges, the I2C address is 0x27 (at least for all the back pack modules I have seen), which is the default address defined on the software.
MeteoCercal - Air Quality Data
Click here to watch at my ThingSpeak channel

[Image: banner_EN.php]

Reply
#8
[attachment=1317 Wrote:Werk_AG pid='8888' dateline='1518633182']Usually I don't do any bridges at A0, A1 or A2. Without any bridges, the I2C address is 0x27 (at least for all the back pack modules I have seen), which is the default address defined on the software.

Werk,
As mentioned i have an issue with two  20 x 4 LCD displays.
The top one in the photo was purchased as an I2C compatible device and works well with the address of 0x3F (chip is PCF 8574AT).
The lower one is one of two purchased as serial models and I attached the I2C boards myself, both have the same 8574AT chip but neither will work regardless of address used.
The only difference appears to be that the non working boards do not have capacitors C1 and C2 fitted
Any ideas?
Jim


Attached File(s) Image(s)
   
Reply
#9
I have already looked for a breakdown like this, it was the brightness knob that was not turned correctly and I had a white screen.
I guess you've already eliminated that possibility.

you have to go and get C1 and C2 at the local electrics shop and solder them!
Reply




Users browsing this thread: 1 Guest(s)