At first I connected them to a Arduino nano, to see if they would work. I found some code here :
#include "Wire.h"
#define iaqaddress 0x5A
uint16_t predict;
uint8_t statu;
int32_t resistance;
uint16_t tvoc;
void setup()
{
Serial.begin(9600);
Wire.begin();
}
void loop()
{
readAllBytes();
checkStatus();
Serial.print("CO2:");
Serial.print(predict);
Serial.print(", Status:");
Serial.print(statu, HEX);
Serial.print(", Resistance:");
Serial.print(resistance);
Serial.print(", TVoC:");
Serial.println(tvoc);
delay(2000);
}
void readAllBytes()
{
Wire.requestFrom(iaqaddress, 9);
predict = (Wire.read()<< 8 | Wire.read());
statu = Wire.read();
resistance = (Wire.read()& 0x00)| (Wire.read()<<16)| (Wire.read()<<8| Wire.read());
tvoc = (Wire.read()<<8 | Wire.read());
}
void checkStatus()
{
if(statu == 0x10)
{
Serial.println("Warming up...");
}
else if(statu == 0x00)
{
Serial.println("Ready");
}
else if(statu == 0x01)
{
Serial.println("Busy");
}
else if(statu == 0x80)
{
Serial.println("Error");
}
else
Serial.println("No Status, check module");
}
It worked like a charm, so i hooked the sensor to a esp-12 and uploaded the exact same code.
Unfortunately, with the ESP, I don't get any proper results from the sensors. The above code only gives me "No Status, check module", so aparantly, the module is not returning one of the expected statusses
Acording to the data sheet, it should give me one of these:
0x00: OK (data valid)
0x10: RUNIN (module in warm up phase)
0x01: BUSY (re-read multi byte data!)
0x80: ERROR (if constant: replace sensor)
I tried to go back to just a minimal script to get the status, the status should be the 3th byte returned by the sensor, so I wrote this:
#include "Wire.h"
#define iaqaddress 0x5A
uint8_t a;
uint8_t b;
uint8_t c;
void setup()
{
Serial.begin(115200);
Wire.begin();
Wire.beginTransmission(iaqaddress);
Wire.write(0xB5); // Write reset command
Wire.endTransmission();
delay(15); // Default = 15ms
}
void loop()
{
Wire.requestFrom(iaqaddress, 3);
delay(1000);
a = Wire.read();
b = Wire.read();
c = Wire.read();
Serial.println(a,HEX);
Serial.println(b,HEX);
Serial.println(c,HEX);
}
unfortunately, all I get is FF FF FF
Any idea why the sensor would work on the arduino, but not on the ESP?
If I run a i2c scanner, the sensor is detected with address 0x5A
both the arduino and the ESP feed it with 3.3v (as required)
Other i2c devices do work on the same ESP without any problems