Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

Code Block
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

  • UTFT
  • Sodaq_SHT2x
  • DFRobot_I2CMultiplexer


Code Block
#include <SPI.h>
#include <SD.h>
#include <UTFT.h>
#include <DFRobot_I2CMultiplexer.h>
#include <Wire.h>
#include <Sodaq_SHT2x.h>

// 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,0);
  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);
  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;
      }
      // BMEx80
      if ( (i2cPort == 118) || (i2cPort == 119) ) {
       i=3;
      }
      // 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;
      }
      // BMEx80
      if ( (i2cPort == 118) || (i2cPort == 119) ) {
       i=3;
      }
      // 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 ();
  initSensors ();
  delay(1000);
  drawTable ();

}

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