Switch to predefined array of sensors instead of i2c scan

Creating sensor types

sensors with different data retrieval methods

idnameSensors
0SHT2xSHT20, SHT21, SHT25, HTU21d
1Si7021Si7021
2HDC10xxHDC1080
3SHT3cSHT30, SHT31, SHT35, SHT88
4BME280BME280
5BME680BME680
6DHT1xDHT12
7DHT2xDHT22
const uint8_t EMPTY = 0; /* slot is empty or sensor disabled */
const uint8_t SHT2X = 1; /* include SHT20, SHT21, SHT25, HTU21d*/
const uint8_t SI70XX = 2; /* includes Si7021 */
const uint8_t HDC10xx = 3; /* includes HDC1080 */
const uint8_t SHT3X = 4; /* include SHT30, SHT31, SHT35, SHT88*/
const uint8_t BME280 = 5; /* includes BME280 */
const uint8_t BME680 = 6; /* includes BME680 */
const uint8_t DHT1X = 7; /* includes DHT12 */
const uint8_t DHT2X = 8; /* includes DHT22 */

Define multiplexors

idi2c adddrDescriptionswitch
0112Main Multiplexer with most of SHT2x, SHT3x, BMEx, DHT12 sensors000
1113Second Multiplexor with Si7021001
2114Third Multiplexer with HDC1080, BME680-2, SHT85, SHT3x010
3115Fourth Multiplexer with DHT22 (5v sensors), additional board100
uint8_t multiplexer[4]={112,113,114,115};


Define sensors map

using v2 7x8 Sensors board project#SensorsMap


12345678
1SHT25*SHT21SHT21SHT21SHT21SHT20SHT20SHT20
SHT35SHT35SHT31SHT31SHT31SHT31SHT30SHT30
BME680BME680BME280BME280BME280DHT12DHT12DHT12
2HTU21Si7021Si7021Si7021Si7021Si7021Si7021Si7021








3HDC1080HDC1080HDC1080HDC1080HDC1080HDC1080HDC1080HDC1080
BME680BME680
SHT85SHT85SHT85SHT31SHT31
4DHT22DHT22DHT22DHT22



see Test i2c humidity sensors#Sensori2caddressesandvoltages

Sensor

address

alt address

Senserion SHT2x0x40 (64)0x41 (65)
Senserion SHT3x0x44 (68)0x45 (69)
Senserion SHT8x0x44 (58)
Meas(1) HTU21D0x40 (64)
Silicon Labs Si70210x40 (64)
Bosch(2) BMEx800x76 (118)0x77 (119)
Bosch(2) BME2800x76 (118)0x77 (119)
Ti(3) HDC10800x40 (64)
AOSONG DHT120x5C (92)
AOSONG AM23200x5C (92)0xB8 ?

1 TE Connectivity Measurement Specialties


Prepare for code


01234567
0SHT25*SHT21SHT21SHT21SHT21SHT20SHT20SHT20
SHT35SHT35SHT31SHT31SHT31SHT31SHT30SHT30
BME680BME680BME280BME280BME280DHT12DHT12DHT12
1HTU21Si7021Si7021Si7021Si7021Si7021Si7021Si7021








2HDC1080HDC1080HDC1080HDC1080HDC1080HDC1080HDC1080HDC1080
BME680BME680
SHT85SHT85SHT85SHT31SHT31
3DHT22






Array to map sensors

demo sketch to debug array with serial

uint8_t multiplexer[4] = {112, 113, 114, 115};
// Type of sensor
const uint8_t EMPTY = 0; /* slot is empty or sensor disabled */
const uint8_t SHT2X = 1; /* include SHT20, SHT21, SHT25, HTU21d*/
const uint8_t SI70XX = 2; /* includes Si7021 */
const uint8_t HDC10xx = 3; /* includes HDC1080 */
const uint8_t SHT3X = 4; /* include SHT30, SHT31, SHT35, SHT88*/
const uint8_t BME280 = 5; /* includes BME280 */
const uint8_t BME680 = 6; /* includes BME680 */
const uint8_t DHT1X = 7; /* includes DHT12 */
const uint8_t DHT2X = 8; /* includes DHT22 */
// indexes name in sensor arrays
const uint8_t get_type = 0; /* indexes name in sensor arrays */
const uint8_t get_collumn = 1; /* indexes name in sensor arrays */
const uint8_t get_address = 2; /* indexes name in sensor arrays */
// Sensor properties by [multiplexor][i2c_bus][number][get_type/get_collumn/get_address]
uint8_t sensor[4][8][3][3] =
{
  {
    {  {SHT2X, 1, 64}, {SHT3X, 2, 68}, {BME680, 3, 119} },
    {  {SHT2X, 1, 64}, {SHT3X, 2, 68}, {BME680, 3, 119} },
    {  {SHT2X, 1, 64}, {SHT3X, 2, 68}, {BME280, 3, 118} },
    {  {SHT2X, 1, 64}, {SHT3X, 2, 68}, {BME280, 3, 118} },
    {  {SHT2X, 1, 64}, {SHT3X, 2, 68}, {BME280, 3, 118} },
    {  {SHT2X, 1, 64}, {SHT3X, 2, 68}, {DHT1X, 3, 92} },
    {  {SHT2X, 1, 64}, {SHT3X, 2, 68}, {DHT1X, 3, 92} },
    {  {SHT2X, 1, 64}, {SHT3X, 2, 68}, {DHT1X, 3, 92} }
  },
  {
    {  {SHT2X, 4, 64}, {EMPTY, 0, 0}, {EMPTY, 0, 0} },
    {  {SI70XX, 4, 64}, {EMPTY, 0, 0}, {EMPTY, 0, 0} },
    {  {SI70XX, 4, 64}, {EMPTY, 0, 0}, {EMPTY, 0, 0} },
    {  {SI70XX, 4, 64}, {EMPTY, 0, 0}, {EMPTY, 0, 0} },
    {  {SI70XX, 4, 64}, {EMPTY, 0, 0}, {EMPTY, 0, 0} },
    {  {SI70XX, 4, 64}, {EMPTY, 0, 0}, {EMPTY, 0, 0} },
    {  {SI70XX, 4, 64}, {EMPTY, 0, 0}, {EMPTY, 0, 0} },
    {  {SI70XX, 4, 64}, {EMPTY, 0, 0}, {EMPTY, 0, 0} }
  },
  {
    {  {HDC10xx, 5, 64}, {BME680, 0, 118}, {EMPTY, 0, 0} },
    {  {HDC10xx, 5, 64}, {BME680, 0, 118}, {EMPTY, 0, 0} },
    {  {HDC10xx, 5, 64}, {EMPTY, 0, 0}, {EMPTY, 0, 0} },
    {  {HDC10xx, 5, 64}, {SHT3X, 6, 68}, {EMPTY, 0, 0} },
    {  {HDC10xx, 5, 64}, {SHT3X, 6, 68}, {EMPTY, 0, 0} },
    {  {HDC10xx, 5, 64}, {SHT3X, 6, 68}, {EMPTY, 0, 0} },
    {  {HDC10xx, 5, 64}, {SHT3X, 6, 68}, {EMPTY, 0, 0} },
    {  {HDC10xx, 5, 64}, {SHT3X, 6, 68}, {EMPTY, 0, 0} }
  },

  {
    {  {DHT2X, 0, 92}, {EMPTY, 0, 0}, {EMPTY, 0, 0} },
    {  {DHT2X, 0, 92}, {EMPTY, 0, 0}, {EMPTY, 0, 0} },
    {  {DHT2X, 0, 92}, {EMPTY, 0, 0}, {EMPTY, 0, 0} },
    {  {DHT2X, 0, 92}, {EMPTY, 0, 0}, {EMPTY, 0, 0} },
    {  {DHT2X, 0, 92}, {EMPTY, 0, 0}, {EMPTY, 0, 0} },
    {  {DHT2X, 0, 92}, {EMPTY, 0, 0}, {EMPTY, 0, 0} },
    {  {DHT2X, 0, 92}, {EMPTY, 0, 0}, {EMPTY, 0, 0} },
    {  {DHT2X, 0, 92}, {EMPTY, 0, 0}, {EMPTY, 0, 0} }
  }
};

void setup() {
  Serial.begin(115200);
}

void loop() {
  for (uint8_t m = 0; m < 4; m++) {
    for (uint8_t b = 0; b < 8; b++) {
      for (uint8_t n = 0; n < 3; n++) {
        for (uint8_t i = 0; i < 3; i++) {
          Serial.print(sensor[m][b][n][i]);
          Serial.print(", ");
          delay (50);
        }
        Serial.print("\t");
        delay (50);
      }
      Serial.println();
      delay (50);
    }
  }
  delay (5000);
}



  • No labels