Hi All,
I am working with ch101 sensor along with arduino uno which is giving only one value i.e.,2562.0 as distance irrespective of object at different positions but my concern is to get different positional values of ch101 sensor.
I would request everyone to support me and modify the code to get different values for the below code:
#include <Wire.h>
#define Chirp_ADDR 0x45 // or I used 0x45
//there was not any mention of register address in chirp's data sheet. so I just used 0
#define Chirp_REG_TMEP 0
#define ANSWERSIZE 2 // I used 2 byte arbitrarily
int rstPin = 13;
int progPin = 12;
int intPin = 11;
void setup()
{
Wire.begin();
Serial.begin(115200);
// Serial.println("\nI2C Scanner");
pinMode(rstPin, OUTPUT);
pinMode(progPin, OUTPUT);
pinMode(intPin, INPUT_PULLUP);
//-----------------------------
digitalWrite(rstPin, LOW); //rset the device
delay(200);
digitalWrite(rstPin, HIGH);
//-------------------------
digitalWrite(progPin, LOW); //don't know the what value for progPin?
}
void loop() {
float distance = GetDistance();
Serial.print("distance : ");
Serial.print(distance, 2);
Serial.println();
delay(1000);
}
float GetDistance()
{
Wire.beginTransmission(Chirp_ADDR);
Wire.write(Chirp_REG_TMEP);
Wire.endTransmission();
Wire.requestFrom(Chirp_ADDR, ANSWERSIZE);
byte firstByte = Wire.read();
byte secondByte = Wire.read();
int sumByte = ((int)firstByte << 8) | (int)secondByte;
float distanceValue = (float) sumByte;
return distanceValue;
}
Thanks and regards,
Imran Pathan.