Skip to content

Commit

Permalink
adafruit pca9546a
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulaScharf committed Dec 4, 2024
1 parent e020016 commit 11ecdb5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
3 changes: 2 additions & 1 deletion senseBox-bike-atrai-v2-2ToF/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ BaseSensor *sensors[] = {
&tempHumiditySensor,
&distanceSensor,
&accelerationSensor,
&batterySensor};
&batterySensor
};

SBDisplay display;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,39 +47,52 @@ bool pending_initial_data = true;

long prevDistanceTime = millis();

byte multiplexAddress = 0x77;
byte channels[] = {0,1};
#define TCAADDR 0x70

void DistanceSensor::tcaselect(uint8_t i) {
if (i > 7) return;

Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}

void DistanceSensor::initSensor()
{
// ------------------------------ setup VL53L8CX ------------------------------
Serial.println("setting up VL53L8CX...");
Wire.begin();

Wire.beginTransmission(0x77);
Wire.write(1 << channels[0]);
Wire.endTransmission();
tcaselect(1);

Wire.setClock(1000000); // Sensor has max I2C freq of 1MHz
// sensor_vl53l8cx_top.vl53l8cx_set_i2c_address(0x51); // need to change address, because default address is shared with other sensor

Serial.println("begin...");
sensor_vl53l8cx_top.begin();
Serial.println("init...");
sensor_vl53l8cx_top.init_sensor();
Serial.println("set range...");
sensor_vl53l8cx_top.vl53l8cx_set_ranging_frequency_hz(30);
Serial.println("set res...");
sensor_vl53l8cx_top.vl53l8cx_set_resolution(VL53L8CX_RESOLUTION_8X8);
Serial.println("start...");
sensor_vl53l8cx_top.vl53l8cx_start_ranging();

Wire.beginTransmission(0x77);
Wire.write(1 << channels[1]);
Wire.endTransmission();
tcaselect(0);

Wire.setClock(1000000); // Sensor has max I2C freq of 1MHz
// sensor_vl53l8cx_top.vl53l8cx_set_i2c_address(0x51); // need to change address, because default address is shared with other sensor

Serial.println("begin...");
sensor_vl53l8cx_top.begin();
Serial.println("init...");
sensor_vl53l8cx_top.init_sensor();
Serial.println("set range...");
sensor_vl53l8cx_top.vl53l8cx_set_ranging_frequency_hz(30);
Serial.println("set res...");
sensor_vl53l8cx_top.vl53l8cx_set_resolution(VL53L8CX_RESOLUTION_8X8);
Serial.println("start...");
sensor_vl53l8cx_top.vl53l8cx_start_ranging();
// -------------------------- setup tensorflow model --------------------------
Serial.println("setting up tensorflow...");
Expand Down Expand Up @@ -128,9 +141,7 @@ void DistanceSensor::initSensor()
bool DistanceSensor::readSensorData()
{
Wire.setClock(1000000); // Sensor has max I2C freq of 1MHz
Wire.beginTransmission(0x77);
Wire.write(1 << channels[1]);
Wire.endTransmission();
tcaselect(1);

// ------------------- RIGHT -------------------
VL53L8CX_ResultsData Results;
Expand Down Expand Up @@ -166,13 +177,14 @@ bool DistanceSensor::readSensorData()
}
distanceRight = (min == 10000.0) ? 0.0 : min;
// Serial.printf("distanceRight: %f\n", distanceRight);
notifyBLERight(distanceRight);
if (sendBLE)
{
notifyBLERight(distanceRight);
}
}
// ------------------- LEFT -------------------

Wire.beginTransmission(0x77);
Wire.write(1 << channels[0]);
Wire.endTransmission();
tcaselect(0);

NewDataReady = 0;
status = sensor_vl53l8cx_top.vl53l8cx_check_data_ready(&NewDataReady);
Expand Down Expand Up @@ -253,6 +265,7 @@ bool DistanceSensor::readSensorData()

if (sendBLE)
{
// Serial.printf("distance: %f, overtaking: %f\n", distance, overtakingPredictionPercentage);
notifyBLE(distance, overtakingPredictionPercentage);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class DistanceSensor : public BaseSensor
void initSensor() override;
void notifyBLE(float distance, float overtakingPredictionPercentage);
void notifyBLERight(float distance);

private:
void tcaselect(uint8_t i);
};

#endif // DISTANCESENSOR_H

0 comments on commit 11ecdb5

Please sign in to comment.