update with scani2cdevice

This commit is contained in:
Kyle Gabriel 2019-08-25 20:55:00 -04:00
parent 27dc8c2cd0
commit e7c53e4d34
3 changed files with 47 additions and 7 deletions

View File

@ -96,7 +96,7 @@ void ttn_register(void (*callback)(uint8_t message));
// OLED // OLED
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#define OLED_ADDRESS 0x3C #define SSD1306_ADDRESS 0x3C
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// GPS // GPS

View File

@ -29,6 +29,7 @@
#ifdef T_BEAM_V10 #ifdef T_BEAM_V10
#include "axp20x.h" #include "axp20x.h"
AXP20X_Class axp; AXP20X_Class axp;
bool ssd1306_found = false;
bool axp192_found = false; bool axp192_found = false;
bool pmu_irq = false; bool pmu_irq = false;
String baChStatus = "No charging"; String baChStatus = "No charging";
@ -134,14 +135,53 @@ uint32_t get_count() {
return count; return count;
} }
void scanI2Cdevice(void)
{
byte err, addr;
int nDevices = 0;
for (addr = 1; addr < 127; addr++) {
Wire.beginTransmission(addr);
err = Wire.endTransmission();
if (err == 0) {
Serial.print("I2C device found at address 0x");
if (addr < 16)
Serial.print("0");
Serial.print(addr, HEX);
Serial.println(" !");
nDevices++;
if (addr == SSD1306_ADDRESS) {
ssd1306_found = true;
Serial.println("ssd1306 display found");
}
if (addr == AXP192_SLAVE_ADDRESS) {
axp192_found = true;
Serial.println("axp192 PMU found");
}
} else if (err == 4) {
Serial.print("Unknow error at address 0x");
if (addr < 16)
Serial.print("0");
Serial.println(addr, HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
}
void setup() { void setup() {
// Debug // Debug
#ifdef DEBUG_PORT #ifdef DEBUG_PORT
DEBUG_PORT.begin(SERIAL_BAUD); DEBUG_PORT.begin(SERIAL_BAUD);
#endif #endif
delay(1000);
#ifdef T_BEAM_V10 #ifdef T_BEAM_V10
Wire.begin(I2C_SDA, I2C_SCL); Wire.begin(I2C_SDA, I2C_SCL);
scanI2Cdevice();
axp192_found = true; axp192_found = true;
if (axp192_found) { if (axp192_found) {
if (!axp.begin(Wire, AXP192_SLAVE_ADDRESS)) { if (!axp.begin(Wire, AXP192_SLAVE_ADDRESS)) {

View File

@ -93,7 +93,7 @@ void screen_update() {
void screen_setup() { void screen_setup() {
// Display instance // Display instance
display = new SSD1306Wire(OLED_ADDRESS, I2C_SDA, I2C_SCL); display = new SSD1306Wire(SSD1306_ADDRESS, I2C_SDA, I2C_SCL);
display->init(); display->init();
display->flipScreenVertically(); display->flipScreenVertically();
display->setFont(Custom_ArialMT_Plain_10); display->setFont(Custom_ArialMT_Plain_10);