From 5ee5b3e7944091e952910a1b81944d85341fdb51 Mon Sep 17 00:00:00 2001 From: Kyle Gabriel Date: Sun, 25 Aug 2019 12:57:37 -0400 Subject: [PATCH] Add code for Rev1 T-Beam --- README.md | 24 ++++++++++--------- main/configuration.h | 2 +- main/main.ino | 56 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 68 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 1272b54..c0faa76 100644 --- a/README.md +++ b/README.md @@ -7,21 +7,23 @@ Uploads GPS data from the TTGO T-Beam to [The Things Network](https://www.thethi This is a LoRaWAN node based on the [TTGO T-Beam](https://github.com/LilyGO/TTGO-T-Beam) development platform using the SSD1306 I2C OLED display. It uses a RFM95 by HopeRF and the MCCI LoRaWAN LMIC stack. This sample code is configured to connect to The Things Network using the US 915 MHz frequency by default, but can be changed to EU 868 MHz. -To start, install the dependencies and board, below, to your Arduino IDE. Then edit ```src/credentials.h``` to use either ```USE_ABP``` or ```USE_OTAA``` and add the Keys/EUIs for your Application's Device from The Things Network. Add the TTN Mapper integration to your Application (and optionally the Data Storage integration if you want to access the GPS location information yourself), then add the Decoder code, below. Compile the Arduino code and upload it to your TTGO T-Beam. Turn on the device and once a GPS lock is acquired, the device will start sending data to TTN and TTn Mapper. +NOTE: There are now 2 versions of the TTGO T-BEAM, the first version (Rev0) and a newer version (Rev1). The GPS module on Rev1 is connected to different pins than Rev0. This code has been successfully tested on REV0, and is in the process of being tested on REV1. See the end of this README for photos of eah board. -I also developed The [Things Network Tracker (TTN-Tracker)](https://github.com/kizniche/ttn-tracker), a web app that pulls GPS data from TTN and displays it on a map in real-time (TTN Mapper is not real-time). +#### Setup -#### Arduino IDE Board +1. Follow the directions at [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) to install the board to the Arduino IDE and use board 'Heltec_WIFI_LoRa_32'. -Follow the directions at [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) and use board 'Heltec_WIFI_LoRa_32'. +2. Install the Arduino IDE libraries: -#### Arduino IDE Library Dependencies + * [mcci-catena/arduino-lmic](https://github.com/mcci-catena/arduino-lmic) + * [mikalhart/TinyGPSPlus](https://github.com/mikalhart/TinyGPSPlus) + * [ThingPulse/esp8266-oled-ssd1306](https://github.com/ThingPulse/esp8266-oled-ssd1306) - - [mcci-catena/arduino-lmic](https://github.com/mcci-catena/arduino-lmic) - - [mikalhart/TinyGPSPlus](https://github.com/mikalhart/TinyGPSPlus) - - [ThingPulse/esp8266-oled-ssd1306](https://github.com/ThingPulse/esp8266-oled-ssd1306) +3. Edit arduino-lmic/project_config/lmic_project_config.h and uncomment the proper frequency for your region. -#### TTN Payload Decoder +4. Edit ```main/credentials.h``` to use either ```USE_ABP``` or ```USE_OTAA``` and add the Keys/EUIs for your Application's Device from The Things Network. + +5. Add the TTN Mapper integration to your Application (and optionally the Data Storage integration if you want to access the GPS location information yourself), then add the Decoder code: ```C function Decoder(bytes, port) { @@ -45,9 +47,9 @@ function Decoder(bytes, port) { } ``` -### The TTGO T-Beam development platform +Compile the Arduino code and upload it to your TTGO T-Beam. Turn on the device and once a GPS lock is acquired, the device will start sending data to TTN and TTN Mapper. -Note: There are now two versions, the first version (Rev0) and a newer version (Rev1). The GPS module on Rev1 is connected to different pins than Rev0. This code has been successfully tested on REV0, and is in the process of being tested on REV1. +I also developed The [Things Network Tracker (TTN-Tracker)](https://github.com/kizniche/ttn-tracker), a web app that pulls GPS data from TTN and displays it on a map in real-time (TTN Mapper is not real-time). ### Rev0 diff --git a/main/configuration.h b/main/configuration.h index 8cdab1e..8a9f2b2 100644 --- a/main/configuration.h +++ b/main/configuration.h @@ -126,7 +126,7 @@ void ttn_register(void (*callback)(uint8_t message)); // Rev1-specific options // ----------------------------------------------------------------------------- -#if defined(T_BEAM_V10) +#ifdef T_BEAM_V10 #define GPS_POWER_CTRL_CH 3 #define LORA_POWER_CTRL_CH 2 #endif diff --git a/main/main.ino b/main/main.ino index 51f2a7b..ecef653 100644 --- a/main/main.ino +++ b/main/main.ino @@ -129,10 +129,62 @@ uint32_t get_count() { } void setup() { + // Serial.begin(115200); + // Debug -#ifdef DEBUG_PORT + #ifdef DEBUG_PORT DEBUG_PORT.begin(SERIAL_BAUD); -#endif + #endif + + #ifdef T_BEAM_V10 + axp192_found = 1; + if (axp192_found) { + if (!axp.begin(Wire, AXP192_SLAVE_ADDRESS)) { + Serial.println("AXP192 Begin PASS"); + } else { + Serial.println("AXP192 Begin FAIL"); + } + // axp.setChgLEDMode(LED_BLINK_4HZ); + // Serial.printf("DCDC1: %s\n", axp.isDCDC1Enable() ? "ENABLE" : "DISABLE"); + // Serial.printf("DCDC2: %s\n", axp.isDCDC2Enable() ? "ENABLE" : "DISABLE"); + // Serial.printf("LDO2: %s\n", axp.isLDO2Enable() ? "ENABLE" : "DISABLE"); + // Serial.printf("LDO3: %s\n", axp.isLDO3Enable() ? "ENABLE" : "DISABLE"); + // Serial.printf("DCDC3: %s\n", axp.isDCDC3Enable() ? "ENABLE" : "DISABLE"); + // Serial.printf("Exten: %s\n", axp.isExtenEnable() ? "ENABLE" : "DISABLE"); + // Serial.println("----------------------------------------"); + + axp.setPowerOutPut(AXP192_LDO2, AXP202_ON); + axp.setPowerOutPut(AXP192_LDO3, AXP202_ON); + axp.setPowerOutPut(AXP192_DCDC2, AXP202_ON); + axp.setPowerOutPut(AXP192_EXTEN, AXP202_ON); + axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON); + axp.setDCDC1Voltage(3300); + + // Serial.printf("DCDC1: %s\n", axp.isDCDC1Enable() ? "ENABLE" : "DISABLE"); + // Serial.printf("DCDC2: %s\n", axp.isDCDC2Enable() ? "ENABLE" : "DISABLE"); + // Serial.printf("LDO2: %s\n", axp.isLDO2Enable() ? "ENABLE" : "DISABLE"); + // Serial.printf("LDO3: %s\n", axp.isLDO3Enable() ? "ENABLE" : "DISABLE"); + // Serial.printf("DCDC3: %s\n", axp.isDCDC3Enable() ? "ENABLE" : "DISABLE"); + // Serial.printf("Exten: %s\n", axp.isExtenEnable() ? "ENABLE" : "DISABLE"); + + pinMode(PMU_IRQ, INPUT_PULLUP); + attachInterrupt(PMU_IRQ, [] { + pmu_irq = true; + }, FALLING); + + axp.adc1Enable(AXP202_BATT_CUR_ADC1, 1); + axp.enableIRQ(AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ | AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ, 1); + axp.clearIRQ(); + + if (axp.isChargeing()) { + baChStatus = "Charging"; + } + } else { + // Serial.println("AXP192 not found"); + } + + Serial1.begin(GPS_BANUD_RATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN); + #endif // Buttons & LED pinMode(BUTTON_PIN, INPUT_PULLUP);