Hello,
I'm new here. I'm trying to interface with HDPM01 Barometer/Compass module and I'm getting "-1" all of the time from the compass sensor.
This is the datasheet of the HDPM01 module:
http://www.hoperf.com/upload/sensor/HDPM01.pdf
This is the code I have written for getting angle:
#include<Wire.h>
#include<math.h>
void setup()
{
Serial.begin(9600);
Wire.begin();
}
void loop()
{
int i=0;
Wire.beginTransmission(50);
Wire.write(0);
Wire.write(1);
Wire.endTransmission(50);
delay(10);
Wire.beginTransmission(50);
Wire.write(0);
int array[5];
for(i=0;i<5;i++)
{
Wire.requestFrom(50,1);
while(Wire.available()==0);
array[i]=Wire.read();
}
array[1]=array[1]<<8;
array[3]=array[3]<<8;
int x=array[1]|array[2];
int y=array[3]|array[4];
float angle=atan(y/x);
Serial.println(angle);
delay(500);
}
Can someone help me with this and with the Barometer sensor reading data code from it?