http://www.rainbowtechnology.cn/productinfo/1490.html
here is the link of the device
edit: so basically i want to know how to read data from sensor (5 parameters) in i2c bus and to convert it as mentioned below
http://www.rainbowtechnology.cn/productinfo/1490.html
here is the link of the device
edit: so basically i want to know how to read data from sensor (5 parameters) in i2c bus and to convert it as mentioned below
Have you tried the libraries for any of the devices that this is apparently an alternative for ?
No i haven't, i want to read data from scratch so i'm seeking help
1. The Sensor Module is given the 7-bit Slave Address: 1010001 (0x51)
2. Codes to check the presence of the Sesnor.
#include<Wire.h>
#define sAddr 0x51
Wire.beginTransmission(sAddr);
byte busStatus = Wire.endTransmission();
if (busStatus != 0)
{
Serial.print("Sensor is not found!");
while (1); //wait for ever
}
Serial.println("Sensor is found.");
3. Codes to read 13-byte data from Sensor
byte m = Wire.requestFrom(sAddr, 13);
for(int i = 0; i<m; i++)
{
myData[i] = Wire.read();
}
if(myData[0] != 0xFF) //Message Header check
{
Serial.print("Invalid data received!");
while(1); //wait for ever
}
if(myData[3] != 0x00) //Status check
{
Serial.print("Data are in Error!");
while(1);
}
Serial.println("Good data; proceed with processing.");
4. Extract Temperature signal and display.
unsigned myTemp = ((myData[4]<<8 | myData[5])-669)/10;
Serial.print(myTemp, DEC);
Serial.println(" degC");
5. EXtract other information......
the code is working fine but while converting data the values are wrong so can you help me get hex data bit by bit of 13 bits
Here are some changes i made in order to get proper readings please let me know if i'm missing something
#include<Wire.h>
#define Addr 0x51
void setup(){
Wire.begin();
Serial.begin(9600);
Wire.beginTransmission(Addr);
Wire.endTransmission();
}
void loop(){
Wire.beginTransmission(Addr);
byte busStatus = Wire.endTransmission();
if (busStatus != 0)
{
Serial.print("Sensor is not found!");
while (1);
}
Serial.println("Sensor is found.");
byte myData[13];
byte m = Wire.requestFrom(0x51, 13);
for(int i = 0; i<m; i++)
{
myData[i] = Wire.read();
}
for(int i = 0; i<m; i++)
{
Serial.print(myData[i],HEX);
Serial.print(" ");
}
Serial.print("\n");
if(myData[0] == 0xFF) //Message Header check
{
Serial.println("Data received!");
}
if(myData[3] == 0x00) //Status check
{
Serial.println("Good data.");
}
else if(myData[3] == 0x01)
{
Serial.println("Sensor is heating!!");
}
else if(myData[3] == 0x02)
{
Serial.println("Error!");
}
uint16_t Co2 = word(myData[1], myData[2]);
Serial.print(Co2, DEC);
Serial.println(" ppm");
uint16_t Temp = word(myData[4], myData[5]);
Serial.print(float (Temp-669)/10);
Serial.println(" °C");
uint16_t Hum= word(myData[6], myData[7]);
Serial.print((Hum-125)/10);
Serial.println(" %RH");
uint16_t TVOC= word(myData[8], myData[9]);
Serial.print(TVOC,DEC);
Serial.println(" ug/m3");
uint16_t HCHO= word(myData[10], myData[11]);
Serial.print(HCHO, DEC);
Serial.println(" ug/m3");
uint16_t sum=(myData[1]| myData[2]| myData[3]| myData[4]| myData[5]| myData[6]| myData[7]| myData[8]| myData[9]| myData[10]| myData[11]);
Serial.print("Check code :");
Serial.println(sum+1);
delay(10000);
}
Please, use code tags (</>) for your sketch to appear as shown below.
To me, your sketch looks OK! I have just added one line (while(1);) and few inter-spaces.
#include<Wire.h>
#define Addr 0x51
void setup()
{
Wire.begin();
Serial.begin(9600);
Wire.beginTransmission(Addr);
Wire.endTransmission();
}
void loop()
{
Wire.beginTransmission(Addr);
byte busStatus = Wire.endTransmission();
if (busStatus != 0)
{
Serial.print("Sensor is not found!");
while (1);
}
Serial.println("Sensor is found.");
byte myData[13];
byte m = Wire.requestFrom(Addr, 13);
for (int i = 0; i < m; i++)
{
myData[i] = Wire.read();
}
for (int i = 0; i < m; i++)
{
Serial.print(myData[i], HEX);
Serial.print(" ");
}
Serial.print("\n");
if (myData[0] == 0xFF) //Message Header check
{
Serial.println("Data received!");
}
if (myData[3] == 0x00) //Status check
{
Serial.println("Good data.");
}
else if (myData[3] == 0x01)
{
Serial.println("Sensor is heating!!");
}
else if (myData[3] == 0x02)
{
Serial.println("Error!");
while(1); //wait for ever.
}
uint16_t Co2 = word(myData[1], myData[2]);
Serial.print(Co2, DEC);
Serial.println(" ppm");
uint16_t Temp = word(myData[4], myData[5]);
Serial.print(float (Temp - 669) / 10);
Serial.println(" °C");
uint16_t Hum = word(myData[6], myData[7]);
Serial.print((Hum - 125) / 10);
Serial.println(" %RH");
uint16_t TVOC = word(myData[8], myData[9]);
Serial.print(TVOC, DEC);
Serial.println(" ug/m3");
uint16_t HCHO = word(myData[10], myData[11]);
Serial.print(HCHO, DEC);
Serial.println(" ug/m3");
uint16_t sum = (myData[1] | myData[2] | myData[3] | myData[4] | myData[5] |
myData[6] | myData[7] | myData[8] | myData[9] | myData[10] | myData[11]);
Serial.print("Check code :");
Serial.println(sum + 1);
delay(10000);
}
Changes to what ? You have not posted a previous version and to compound things you did not post the code in code tags
I have posted code tags now and the changes were made on the code which @GolamMostafa had sent earlier
I want this data to be sent in JSON format to cloud, can you help me with that
which includes status check and 5 parameters except Check code data
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.