Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrouch committed Dec 12, 2024
1 parent ff096b8 commit 35cfaa9
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bbn_esp32_sensors_hub.ino
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#include <M5AtomS3.h>
#include <Wire.h>

#include "NmeaXDR.h"
#include "Nmea0183Msg.h"
#include "i2c_sensors.h"

void setup() {
auto cfg = M5.config();
AtomS3.begin(cfg);
Wire.begin();
Serial.begin(115200);
i2c_scan();
}

void loop() {
Expand Down
50 changes: 50 additions & 0 deletions i2c_ads1115.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef i2c_ads1115_h
#define i2c_ads1115_h

#include <M5_ADS1115.h>

#include "NmeaXDR.h"
#include "Nmea0183Msg.h"

/*
* @Hardwares: M5AtomS3 Lite + Unit Vmeter ADS1115
* @Dependent Library:
* M5_ADS1115: https://github.com/m5stack/M5-ADS1115
*/

#define M5_UNIT_VMETER_I2C_ADDR 0x49
#define M5_UNIT_VMETER_EEPROM_I2C_ADDR 0x53
#define M5_UNIT_VMETER_PRESSURE_COEFFICIENT 0.015918958F

ADS1115 i2c_ads1115_sensor;
bool i2c_ads1115_found = false;

float resolution = 0.0;
float calibration_factor = 0.0;

void i2c_ads1115_try_init() {
for (int i = 0; i < 3; i++) {
i2c_ads1115_found = i2c_ads1115_sensor.begin(&Wire, M5_UNIT_VMETER_I2C_ADDR, G2, G1, 100000U);
if (i2c_ads1115_found) {
break;
}
delay(20);
}
if (i2c_ads1115_found) {
gen_nmea0183_msg("$BBTXT,01,01,01,VOLTAGE found ads1115 sensor at address=0x%s", String(M5_UNIT_VMETER_I2C_ADDR, HEX).c_str());
i2c_ads1115_sensor.setEEPROMAddr(M5_UNIT_VMETER_EEPROM_I2C_ADDR);
i2c_ads1115_sensor.setMode(ADS1115_MODE_SINGLESHOT);
i2c_ads1115_sensor.setRate(ADS1115_RATE_8);
i2c_ads1115_sensor.setGain(ADS1115_PGA_512);
// | PGA | Max Input Voltage(V) |
// | PGA_6144 | 128 |
// | PGA_4096 | 64 |
// | PGA_2048 | 32 |
// | PGA_512 | 16 |
// | PGA_256 | 8 |
resolution = i2c_ads1115_sensor.getCoefficient() / M5_UNIT_VMETER_PRESSURE_COEFFICIENT;
calibration_factor = i2c_ads1115_sensor.getFactoryCalibration();
}
}

#endif
10 changes: 10 additions & 0 deletions i2c_sensors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef i2c_sensors_h
#define i2c_sensors_h

#include "i2c_ads1115.h"

void i2c_scan() {
i2c_ads1115_try_init();
}

#endif

0 comments on commit 35cfaa9

Please sign in to comment.