tdk-invn-oss / ultrasonic.arduino.CHx01

Arduino Driver for TDK InvenSense consumer ultrasonic sensor family CHx01
https://invensense.tdk.com/smartsonic
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

CH101 sensor not giving different distance values #3

Open Imran-patan opened 2 weeks ago

Imran-patan commented 2 weeks ago

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

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.

rbuisson-invn commented 2 weeks ago

Hello @Imran-patan,

Please use the CHx01 official Arduino library. Documentation is here: https://github.com/tdk-invn-oss/ultrasonic.arduino.CHx01 And have a look to the CH101_TargetDetection sketch which does exactly what you want. Please note that this library works with Arduino Zero board.

Regards,

Imran-patan commented 2 weeks ago

@rbuisson-invn ...I have tried dumping the target detection code in arduino uno and mega boards but it is showing memory insufficient and data section exceeds memory section. what changes do I need to do to work the ch101 target detection code in arduino uno and mega boards? Could you please guide me the steps to follow? Thanks and regards, Imran Pathan.

rbuisson-invn commented 2 weeks ago

Hello @Imran-patan , Working with CH101 sensors requires the use of a dedicated library which need a certain amount of memory. Would you consider upgrading your Arduino board to Arduino Zero?