-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |