You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

Goal

Arduino device to compare data for as much t/RH sensors as possible without manual sensor switch

Preparation

Use of same sensor on i2c usually limited by 1 or 2 (using ALT i2c address) of same type. And SHT20, SHT21, SHT25, HTU21 is actually same type, so to be able to compare measurement there is need to use i2c multiplexer. In case of 8 line multiplexer there is possibility to have 8-16 sensor of same time to be connected with Arduino.

Sensor i2c addresses

Sensoraddress
alt address
specV
Senserion SHT2x0x40640x416520,21,253.3v
Senserion SHT3x0x44680x4569SHT3x3.3v
Senserion SHT8x0x4468
69SHT853.3v
Meas(1) HTU21D0x4064

HTU21D3.3v
Silicon Labs Si70210x4064

pdf3.3v
Bosch(2) BMEx800x761180x77119280,6803.3v
Ti(3) HDC10800x4064

pdf3.3v
AOSONG DHT120x5C92

*pdf3.3v
AOSONG AM23200x5C920xB8 ?
*pdf5v

1 TE Connectivity Measurement Specialties

Texas Instruments

3 Bosch Sensortec

Multiplexer Lines

Line0x400x440x5c0x770x410x450x760x70
ASHT21SHT30DHT12BME680



BSHT21
SHT30DHT12BME680



CHTU21D
SHT31DHT12BME280



DHTU21D
SHT31-BME280



EHTU21DSHT35-BME280



FSHT20
SHT35-BME680



GSHT21
SHT31-BME680



HSHT25
SHT85--



i2c Scan

Port:0  i2c addr 64  i2c addr 68  i2c addr 119
Port:1  i2c addr 64  i2c addr 68  i2c addr 119
Port:2  i2c addr 64  i2c addr 68  i2c addr 118
Port:3  i2c addr 64  i2c addr 68  i2c addr 118
Port:4  i2c addr 64  i2c addr 68  i2c addr 118
Port:5  i2c addr 64  i2c addr 68  i2c addr 92  i2c addr 118
Port:6  i2c addr 64  i2c addr 68  i2c addr 92  i2c addr 118
Port:7  i2c addr 64  i2c addr 68  i2c addr 92

Hardware in use

  1. Mega2560 keyestudio
  2. LCD 3.5 inch Arduino Mega2560
  3. DFRobot i2c multiplexer (or compatible ShangSi MoudleCX TCA9548A i2c multiplexer)
  4. Sensors (DHT11, SHT21, SHT20, SHT25, HTU21D, SHT30, SHT31, SHT35, SHT85, BME280, BME680)

Draft sketch

Libraries


mega-tft-sd-batch-sensors-test
#include <SPI.h>
#include <SD.h>
#include <UTFT.h>
#include <DFRobot_I2CMultiplexer.h>
#include <Wire.h>
//SHT2x
#include <Sodaq_SHT2x.h>
//SHT3x
#include <SHTSensor.h>
SHTSensor sht3x(SHTSensor::SHT3X);
// Adafruit BME680
#include <Adafruit_Sensor.h>
#include <Adafruit_BME680.h>
Adafruit_BME680 bme680l0;
Adafruit_BME680 bme680l1;
Adafruit_BME680 bme680l5;
Adafruit_BME680 bme680l6;
// Adafruit BME280
#include <Adafruit_BME280.h>
Adafruit_BME280 bme280l2;
Adafruit_BME280 bme280l3;
Adafruit_BME280 bme280l4;

// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t SevenSegNumFont[];
extern uint8_t BigFont[];

/*Create an I2CMultiplexer object, the address of I2CMultiplexer is 0x70*/
DFRobot_I2CMultiplexer I2CMultiplexer(0x70);

// SCREEN Type and PINs
UTFT LCD(ILI9486,38,39,40,41);

// SD Card PIN
const int SDCARD = 53;

// Variables
int x;
int y;
int i2cPort;
char i;

void setupSD ()
{
  LCD.clrScr();
  LCD.setColor(255, 255, 255);
  LCD.setBackColor(0, 0, 0);
  LCD.setFont(BigFont);
// Setup SD
  LCD.print("Initializing SD card...", LEFT, 1);
  pinMode(SDCARD, OUTPUT);
  if (!SD.begin(SDCARD)) {
    LCD.print("Card failed, or not present", LEFT, 18);
    return;
  }
  LCD.print("card initialized.", LEFT, 18);
}

void drawTable ()
{
  LCD.setFont(SmallFont);
  LCD.clrScr();

  // RED header
  LCD.setColor(80, 80, 80);
  LCD.fillRect(0, 0, 479, 13);
  // Gray Footer
  LCD.setColor(60, 70, 80);
  LCD.fillRect(0, 306, 479, 319);
  // Header Text (White)
  LCD.setColor(255, 255, 255);
  LCD.setBackColor(80, 80, 80);
  LCD.print("RH/t sensor comparision sketch", CENTER, 1);
  // Footer Text (Yellow)
  LCD.setBackColor(64, 64, 64);
  LCD.setColor(255,255,0);
  LCD.print("https://wiki.liutyi.info/", CENTER, 307);
  // Table title
  LCD.setBackColor(0, 0, 0);
  LCD.setColor(150,150,150);
  LCD.setFont(BigFont);
  LCD.print("     SHT2 SHT3 BMEx DHTx OTHr", CENTER, 18);
  for (uint8_t port=1; port<9; port++) {
    x=20;
    y=18+(28*port);
    LCD.printNumI(port, x, y);
  }
  // Gray Frame
  LCD.setColor(60, 60, 60);
  LCD.drawRect(0, 14, 479, 305);
  //Draw Grid and header text
  for (int y=14; y<270; y+=28)
    LCD.drawLine(1, y, 479, y);
  for (int x=79; x<479; x+=80)
    LCD.drawLine(x, 14, x, 266);
}

void initSensors ()
{
  LCD.setBackColor(0, 0, 0);
  LCD.setColor(100,100,0);
  LCD.setFont(BigFont);
  sht3x.init();
  for (uint8_t port=0; port<8; port++) {
    uint8_t* dev = I2CMultiplexer.scan(port);
    while(*dev){
      i2cPort=*dev;
      // SHT2x
      if ( i2cPort == 64 ) {
       i=1; 
      }
      // SHT3x
      if ( i2cPort == 68 ) {
      i=2;
      sht3x.setAccuracy(SHTSensor::SHT_ACCURACY_HIGH);
      }
      // BMEx80
      if ( (i2cPort == 118) || (i2cPort == 119) ) {
       i=3;
       switch (port) {
         case 0:
           bme680l0.begin(i2cPort);
           break;
         case 1:
           bme680l1.begin(i2cPort);
           break;
         case 2:
           bme280l2.begin(i2cPort);
           break;
         case 3:
           bme280l3.begin(i2cPort);
           break;
         case 4:
           bme280l4.begin(i2cPort);
           break;
         case 5:
           bme680l5.begin(i2cPort);
           break;                                       
         case 6:
           bme680l6.begin(i2cPort);
           break;           
       }
      }
      // DHTxx
      if ( i2cPort == 92 ) {
       i=4; 
      }
      x=20+(i*80); y=46+(28*port);
      LCD.printNumI (i2cPort, x, y);
      dev++;
    }
  }  
}

void readSensors ()
{
  float hum;
  float temp;
    LCD.setFont(SmallFont);
    LCD.setBackColor(0, 0, 0);
    for (uint8_t port=0; port<8; port++) {
    uint8_t* dev = I2CMultiplexer.scan(port);
    while(*dev){
      i2cPort=*dev;
      hum=0;
      temp=0;
      // SHT2x
      if ( i2cPort == 64 ) {
       i=1;
       hum=SHT2x.GetHumidity();
       temp=SHT2x.GetTemperature(); 
      }
      // SHT3x
      if ( i2cPort == 68 ) {
      i=2;
      if (sht3x.readSample()) {
       hum=sht3x.getHumidity();
       temp=sht3x.getTemperature();
       }
      }
      // BMEx80
      if ( (i2cPort == 118) || (i2cPort == 119) ) {
       i=3;
       switch (port) {
         case 0:
           hum=bme680l0.readHumidity();
           temp=bme680l0.readTemperature();
           break;
         case 1:
           hum=bme680l1.readHumidity();
           temp=bme680l1.readTemperature();
           break;
         case 2:
           hum=bme280l2.readHumidity();
           temp=bme280l2.readTemperature();
           break;
         case 3:
           hum=bme280l3.readHumidity();
           temp=bme280l3.readTemperature();
           break;
         case 4:
           hum=bme280l4.readHumidity();
           temp=bme280l4.readTemperature();
           break;
         case 5:
           hum=bme680l5.readHumidity();
           temp=bme680l5.readTemperature();
           break;                                       
         case 6:
           hum=bme680l6.readHumidity();
           temp=bme680l6.readTemperature();
           break;           
       }
      }
      // DHTxx
      if ( i2cPort == 92 ) {
       i=4; 
      }
      x=(i*80); y=44+(28*port);
      LCD.setColor(0,0,255);
      LCD.printNumF (hum, 2, x, y, '.', 5);
      x=38+(i*80); y=12+46+(28*port);
      LCD.setColor(255,255,0);
      LCD.printNumF (temp, 2, x, y, '.', 5);
      dev++;
    }
  }  
delay (2000);
}

void setup()
{
 int x;
 int y;
 char i;
// Setup the LCD
  LCD.InitLCD();
//  LCD.lcdOff();
//  LCD.lcdOn();
//  LCD.setContrast(64);
//  LCD.setBrightness(16);
//  LCD.fillScr(90,90,90);

  setupSD ();
// Clear the screen and draw the frame
  drawTable ();
  sht3x.init ();
  initSensors ();
  delay(1000);
  drawTable ();

}

void loop()
{
  //drawTable ();
  readSensors ();
  delay(1000);
}







  • No labels