Go Down

Topic: Understanding I2C readings on Arduino MEGA 2560 with Honeywell air flow sensor (Read 709 times) previous topic - next topic

berlabdu

I've connected a Honeywell air flow sensor (HAFBLF0200C4AX3) to my Arduino MEGA 2560:
pin 1 to SCL, pin 2 to 3.3 V, pin 3 to ground, pin 4 to SDA.

I am receiving readings from it, but they don't seem to correspond to anything. With no flow, the values always begins with "96, 64,32" then stays constant at 32.  Additionally, when I put an air flow of about 0.08 Liters per minute through it, the values fluctuate greatly between seemingly random numbers. (readings attached)

I have tried to change my code, specifically the number of bytes requested but the values seem to stay the same. (code attached)


What could be the issue?

Thanks in advance.

Product sheet: http://sensing.honeywell.com/honeywell-sensing-zephyr-digital-airflow-sensors-haf-series-high-accuracy-10slpm-to-300slpm-product-sheet-008268-4-en2.pdf

Code:
#include <Wire.h>
//#include <i2c_t3.h>

 void setup()
    {
      Serial.begin(9600);
      Wire.begin();
      delay(300);
      Serial.print("setup complete");
     
    }

 void loop()
 {

//  send a request
  Wire.beginTransmission(0x49);
  delay(100);
  Wire.write(0);
  Wire.endTransmission();

 //read information from teensy
 
  Wire.requestFrom(0x49, 1); // request 1 byte from slave

  while(Wire.available()==0);    // slave may send less than requested
 { Serial.print(" connected ");
    byte d  = Wire.read(); // receive a byte as character

    delay(1000);
 
 Serial.println(d);         // print the character
 delay(100);
 }
 }

Koepel

Please read number 7 about code tags : http://forum.arduino.cc/index.php/topic,148850.0.html
With code tags we can read you sketch.

Manufacturer's page : http://sensing.honeywell.com/HAFBLF0200C4AX3-Airflow-Sensors

I don't know where you got that code, but the delay(100) after Wire.transmission() has no influence on the I2C bus. Also the "while(Wire.available()" is wrong. It will work though.

The Arduino Mega 2560 has a 5V I2C bus, and your sensor is a 3.3V sensor. You may not connect the SDA and the SCL of the sensor to the SDA and SCL of the Arduino board.
Use a I2C level shifter, or get the 5V version of that sensor, or use a 3.3V Arduino board.
A I2C level shifter costs 25 cents on AliExpress.

Are there examples for this sensor ? Or is there documentation how to program this sensor ? The information in the so called "Datasheet" is very confusion for me.
Do you have 4 pins ? According to the "Datasheet" there should be 6 pins.


snorren

If anyone else would come here in search for the code for this sensor I have made it and posting some methods below.

The sensor will respond to the first two requests after being powered with its serial number so keep that in mind. The sensor expects 3v (not 3.3v) on the i2c bus but it can be exceeded if the max sink current wont exceed 3 mA. If you use 5v on the i2c bus the internal protection diodes will not protect the device so make sure you wire it correctly.

Code: [Select]

#include <Wire.h>
byte X0, X1;
const int flowRange = 50;


float getChecksum(){  //Verify the EEPROM checksum against factory configuration.
   Wire.beginTransmission(0x49);
   Wire.write(0x03);
   delay(1);
   Wire.requestFrom(0x49,0x02); // Request the transmitted two bytes from the two registers
   delay(1);
     if(Wire.available()<=2) {  //
     X0 = Wire.read(); // Reads the data from the register
     X1 = Wire.read();   
   }
   Wire.endTransmission();
   float checksum = word(X0, X1); //Combine two bytes recieved.
   if (checksum == 52389){ //##From datasheet
       Serial.println("EEPROM Checksum match!");
       }
    else if (checksum == 52368){ //##From datasheet
        Serial.println("EEPROM Checksum error");
   }
 }

 float getFlowReading(){
   Wire.beginTransmission(0x49);
   Wire.requestFrom(0x49,0x02); // Request the transmitted two bytes from the two registers
   delay(1);
     if(Wire.available()<=2) {  //
     X0 = Wire.read(); // Reads the data from the register
     X1 = Wire.read();   
   }
   Wire.endTransmission();
   float output = word(X0, X1); //Combine two bytes recieved.
   float flow=flowRange * ((output/16384) - 0.1)/0.8; // From datasheet
   float conversionFactor = ( (273.15/293.15)*(14.696/14.504) ); //Converting SLPM to NLPM;
   flow= flow*conversionFactor;
   return flow;
}


float getError(float flow){ //#Calculate error for readings lower and higher than 12.5% of flowrange. (Datasheet spec)
       float TEB;
       if (flow < flowRange*0.125){
           TEB=flowRange*0.005;
           }
       else  {
           TEB=0.04*flow;
       }
     return TEB;
}

void printSensorData(){
 float flow = getFlowReading();
 float error = getError(flow);
 Serial.print(flow);
 Serial.print(" ± ");
 Serial.println(error);
}

Go Up