From e7c53e4d346c8bd684eeca7937e4736aa283b338 Mon Sep 17 00:00:00 2001 From: Kyle Gabriel Date: Sun, 25 Aug 2019 20:55:00 -0400 Subject: [PATCH] update with scani2cdevice --- main/configuration.h | 12 ++++++------ main/main.ino | 40 ++++++++++++++++++++++++++++++++++++++++ main/screen.ino | 2 +- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/main/configuration.h b/main/configuration.h index 022db6b..88e3c53 100644 --- a/main/configuration.h +++ b/main/configuration.h @@ -45,7 +45,7 @@ void ttn_register(void (*callback)(uint8_t message)); // Select the payload format. Change on TTN as well. Only uncomment one. #define PAYLOAD_USE_FULL -//#define PAYLOAD_USE_CAYENNE +// #define PAYLOAD_USE_CAYENNE #define DEBUG_PORT Serial // Serial debug port #define SERIAL_BAUD 115200 // Serial debug baud rate @@ -96,7 +96,7 @@ void ttn_register(void (*callback)(uint8_t message)); // OLED // ----------------------------------------------------------------------------- -#define OLED_ADDRESS 0x3C +#define SSD1306_ADDRESS 0x3C // ----------------------------------------------------------------------------- // GPS @@ -107,11 +107,11 @@ void ttn_register(void (*callback)(uint8_t message)); #define USE_GPS 1 #if defined(T_BEAM_V07) -#define GPS_RX_PIN 12 -#define GPS_TX_PIN 15 +#define GPS_RX_PIN 12 +#define GPS_TX_PIN 15 #elif defined(T_BEAM_V10) -#define GPS_RX_PIN 34 -#define GPS_TX_PIN 12 +#define GPS_RX_PIN 34 +#define GPS_TX_PIN 12 #endif // ----------------------------------------------------------------------------- diff --git a/main/main.ino b/main/main.ino index a7ef624..f8c0f7c 100644 --- a/main/main.ino +++ b/main/main.ino @@ -29,6 +29,7 @@ #ifdef T_BEAM_V10 #include "axp20x.h" AXP20X_Class axp; +bool ssd1306_found = false; bool axp192_found = false; bool pmu_irq = false; String baChStatus = "No charging"; @@ -134,14 +135,53 @@ uint32_t get_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() { // Debug #ifdef DEBUG_PORT DEBUG_PORT.begin(SERIAL_BAUD); #endif + delay(1000); + #ifdef T_BEAM_V10 Wire.begin(I2C_SDA, I2C_SCL); + scanI2Cdevice(); axp192_found = true; if (axp192_found) { if (!axp.begin(Wire, AXP192_SLAVE_ADDRESS)) { diff --git a/main/screen.ino b/main/screen.ino index 3cecc15..f6ab07b 100644 --- a/main/screen.ino +++ b/main/screen.ino @@ -93,7 +93,7 @@ void screen_update() { void screen_setup() { // Display instance - display = new SSD1306Wire(OLED_ADDRESS, I2C_SDA, I2C_SCL); + display = new SSD1306Wire(SSD1306_ADDRESS, I2C_SDA, I2C_SCL); display->init(); display->flipScreenVertically(); display->setFont(Custom_ArialMT_Plain_10);