Hello,
I am trying to program 2 I2C Honeywell Pressure sensors using an Arduino Uno, 2 SEK001 shields, and 2 pressure sensors (HSCDANN150PG2A5). The sensors have the same I2C address so I am using an Adafruit TCA9548A 1-to-8 I2C Multiplexer Breakout. I took inspiration from the example code provided on the Adafruit webpage of the multiplexer, and I obviously manipulated the code to include the Honeywell sensors.
Here is the code:
/*
The purpose of this program is to take
the readings of two I2C Honeywell
pressure sensors and display the data
on the Serial Monitor.
*/
#include "Wire.h"
#include "Arduino.h"
#define TCA_Addr 0x70 // Address of the multiplexer
#define OUTPUT_MIN 1638.4 // 1638 counts (10% of 2^14 counts or 0x0666)
#define OUTPUT_MAX 14745.6 // 14745 counts (90% of 2^14 counts or 0x3999)
#define PRESSURE_MIN 0 // min is 0 for sensors that give absolute values
#define PRESSURE_MAX 150 // 1.6bar (I want results in bar)
uint8_t sensor1 = 3;
uint8_t sensor2 = 7;
/* Initialize I2C buses using TCA9548A I2C Multiplexer
*/
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCA_Addr);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup() {
Wire.begin(); // start I2C bus
delay(500);
Serial.begin(115200); // start Serial connection
/* Initialize the 1st sensor */
tcaselect(sensor1);
if (!sensor1)
{
/* Check for errors */
Serial.println("Sensor not detected...Check your wiring!");
while (1);
}
/* Initialize the 2nd sensor */
tcaselect(sensor2);
if (!sensor2)
{
/* Check for errors */
Serial.println("Sensor not detected...Check your wiring!");
while (1);
}
}
void loop() {
float pressure;
float temperature;
int bridge_data;
int temperature_data;
byte status;
tcaselect(sensor1);
delay(20);
Wire.requestFrom(TCA_Addr, 4);
while (Wire.available() == 0);
byte a = Wire.read();
byte b = Wire.read();
byte c = Wire.read();
byte d = Wire.read();
// Serial.print("a: ");
// Serial.println(a, BIN);
// delay(500);
// Serial.print("b: ");
// Serial.println(b, BIN);
// delay(500);
// Serial.print("c: ");
// Serial.println(c, BIN);
// delay(500);
// Serial.print("d: ");
// Serial.println(d, BIN);
// delay(500);
status = (a & 0xc0) >> 6; // first 2 bits from first byte
// Serial.println(status, BIN);
// delay(500);
bridge_data = ((a & 0x3f) << 8) + b;
temperature_data = ((c << 8) + (d & 0xe0)) >> 5;
if (temperature_data == 65535) {
Serial.println("err HSCDANN150PG2A5 sensor missing");
/* Command mode is used for programming the sensor.
This mode should not be seen during normal operation. */
if (status == 1) {
Serial.println("Warn command mode ");
// Serial.println(status, BIN);
}
if (status == 2) {
Serial.println("Warn Stale Data "); // if data has already been feched since the last measurement cycle
// Serial.println(statues, BIN)l
}
if (status == 3) {
Serial.println("err diagnostic fault "); // When the two status bits are "11", one of the above mentioned diagnostic faults is indicated.
// Serial.println(status, BIN);
}
pressure = 1.0 * (bridge_data - OUTPUT_MIN) * (PRESSURE_MAX - PRESSURE_MIN) / (OUTPUT_MAX - OUTPUT_MIN) + PRESSURE_MIN;
temperature = (temperature_data * 0.0977) - 50;
Serial.print("status ");
Serial.println(status, BIN);
Serial.print("bridge_data ");
Serial.println(bridge_data, DEC);
Serial.print("temp_data ");
Serial.println(temperature_data, DEC);
Serial.println("");
Serial.print("pressure (BAR) ");
Serial.println(pressure);
Serial.print("temperature (C) ");
Serial.println(temperature);
Serial.println("");
delay (500);
tcaselect(sensor2);
Wire.requestFrom(TCA_Addr, 4);
while (Wire.available() == 0);
byte a = Wire.read();
byte b = Wire.read();
byte c = Wire.read();
byte d = Wire.read();
// Serial.print("a: ");
// Serial.println(a, BIN);
// delay(500);
// Serial.print("b: ");
// Serial.println(b, BIN);
// delay(500);
// Serial.print("c: ");
// Serial.println(c, BIN);
// delay(500);
// Serial.print("d: ");
// Serial.println(d, BIN);
// delay(500);
status = (a & 0xc0) >> 6; // first 2 bits from first byte
// Serial.println(status, BIN);
// delay(500);
bridge_data = ((a & 0x3f) << 8) + b;
temperature_data = ((c << 8) + (d & 0xe0)) >> 5;
if (temperature_data == 65535) {
Serial.println("err HSCDANN150PG2A5 sensor missing");
/* Command mode is used for programming the sensor.
This mode should not be seen during normal operation. */
if (status == 1) {
Serial.println("Warn command mode ");
// Serial.println(status, BIN);
}
if (status == 2) {
Serial.println("Warn Stale Data "); // if data has already been feched since the last measurement cycle
// Serial.println(statues, BIN)l
}
if (status == 3) {
Serial.println("err diagnostic fault "); // When the two status bits are "11", one of the above mentioned diagnostic faults is indicated.
// Serial.println(status, BIN);
}
pressure = 1.0 * (bridge_data - OUTPUT_MIN) * (PRESSURE_MAX - PRESSURE_MIN) / (OUTPUT_MAX - OUTPUT_MIN) + PRESSURE_MIN;
temperature = (temperature_data * 0.0977) - 50;
Serial.print("status ");
Serial.println(status, BIN);
Serial.print("bridge_data ");
Serial.println(bridge_data, DEC);
Serial.print("temp_data ");
Serial.println(temperature_data, DEC);
Serial.println("");
Serial.print("pressure (BAR) ");
Serial.println(pressure);
Serial.print("temperature (C) ");
Serial.println(temperature);
Serial.println("");
delay (500);
}
}
}
The data will not appear on the Serial Monitor. My wiring is correct. It is a very simple wiring job so I know my wiring is fine.
Any suggestion would be tremendous - Thank you