added ttgo board en pins

This commit is contained in:
2021-01-12 16:53:11 +01:00
parent e8724575f0
commit 40a64daf8a
10 changed files with 108 additions and 49 deletions

BIN
.DS_Store vendored

Binary file not shown.

BIN
CAD/t18_v3.0.pdf Normal file

Binary file not shown.

View File

@@ -9,7 +9,16 @@
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[platformio] [platformio]
default_envs = heltec_wifi_lora_32_V2 default_envs = ttgo-t18
[env]
lib_deps =
#heltecautomation/Heltec ESP32 Dev-Boards@^1.1.0
ericksimoes/Ultrasonic@^3.0.0
256dpi/MQTT@^2.4.8
http://192.168.2.3/Bonobo.Git.Server/OLEDDisplay.git
bluerobotics/ping-arduino@^0.0.2
[env:heltec_wifi_lora_32_V2] [env:heltec_wifi_lora_32_V2]
platform = espressif32 platform = espressif32
@@ -17,11 +26,6 @@ board = heltec_wifi_lora_32_V2
tasks = tasks =
framework = arduino framework = arduino
build_flags = -D ENVIRONMENT=1 build_flags = -D ENVIRONMENT=1
lib_deps =
#heltecautomation/Heltec ESP32 Dev-Boards@^1.1.0
ericksimoes/Ultrasonic@^3.0.0
256dpi/MQTT@^2.4.8
http://192.168.2.3/Bonobo.Git.Server/OLEDDisplay.git
monitor_speed = 115200 monitor_speed = 115200
@@ -30,19 +34,12 @@ platform = espressif32
board = lolin32 board = lolin32
framework = arduino framework = arduino
build_flags = -D ENVIRONMENT=2 build_flags = -D ENVIRONMENT=2
lib_deps =
ericksimoes/Ultrasonic@^3.0.0
256dpi/MQTT@^2.4.8
http://192.168.2.3/Bonobo.Git.Server/OLEDDisplay.git
monitor_speed = 115200 monitor_speed = 115200
[env:ttgo-t18] [env:ttgo-t18]
platform = espressif32 platform = espressif32
board = ttgo-t1 board = ttgo-t1
framework = arduino framework = arduino
build_flags = -D ENVIRONMENT=3 build_flags = -D ENVIRONMENT=3
lib_deps =
ericksimoes/Ultrasonic@^3.0.0
256dpi/MQTT@^2.4.8
http://192.168.2.3/Bonobo.Git.Server/OLEDDisplay.git
monitor_speed = 115200 monitor_speed = 115200

View File

@@ -13,8 +13,20 @@ SSD1306Wire *display;
bool initOK = false; bool initOK = false;
char buf[128]; char buf[128];
void displayOff(void)
{
//display->setBrightness(64);
//display->displayOff();
}
void displayOn(void)
{
//display->displayOn();
}
void displayDrawBatt(uint16_t voltage, bool sleep) void displayDrawBatt(uint16_t voltage, bool sleep)
{ {
Serial.println("get vbatt");
voltage = powerGetVbatt(); voltage = powerGetVbatt();
uint16_t xstart = 104; uint16_t xstart = 104;
uint16_t ystart = 30; uint16_t ystart = 30;
@@ -131,7 +143,7 @@ void displayInit(void)
return; return;
} }
initOK = display->init(); initOK = display->init();
display->setBrightness(255); display->setBrightness(128);
display->flipScreenVertically(); display->flipScreenVertically();
display->setFont(ArialMT_Plain_10); display->setFont(ArialMT_Plain_10);
display->drawString(0, 0, "OLED initial done!"); display->drawString(0, 0, "OLED initial done!");

View File

@@ -6,6 +6,8 @@ void displayInit(void);
void displayUpdate(void); void displayUpdate(void);
void displayDrawBatt(uint16_t voltage, bool sleep); void displayDrawBatt(uint16_t voltage, bool sleep);
void displayDrawShutdown(void); void displayDrawShutdown(void);
void displayOff(void);
void displayOn(void);

View File

@@ -56,11 +56,16 @@
#define SCL_OLED 4 #define SCL_OLED 4
#define RST_OLED 17 #define RST_OLED 17
#define US100 //alternative sonar
#define TRIGGER 13 #define TRIGGER 13
#define ECHO 14 #define ECHO 14
#define VBATT ADC2_CHANNEL_1 #define VBATT ADC1_CHANNEL_7
#define VEXT 21 #define VEXT 21
#define MAILLED 21
#define BUTTON 22
#define DOORSW 23
#endif #endif
#endif //HALH #endif //HALH

View File

@@ -1,6 +1,7 @@
#include "Arduino.h" #include "Arduino.h"
#include "mailbox.h" #include "mailbox.h"
#include "sensor.h" #include "sensor.h"
#include "hal.h"
#define MAILCOUNTERFILTER 10 //minimum samples should be equal before triggering mail alert #define MAILCOUNTERFILTER 10 //minimum samples should be equal before triggering mail alert
#define MAILCOUNTERTHRESHOLT 2 //minimum delta distance in cm #define MAILCOUNTERTHRESHOLT 2 //minimum delta distance in cm
@@ -10,6 +11,14 @@ uint8_t mailcounter = 0;
bool mailFlag = false; bool mailFlag = false;
bool mailDetected = false; bool mailDetected = false;
void mailboxInit(void)
{
pinMode(MAILLED, OUTPUT);
pinMode(BUTTON, INPUT_PULLUP);
pinMode(DOORSW, INPUT_PULLUP);
}
void mailboxhandler(void) void mailboxhandler(void)
{ {
uint8_t currentDistance = sensorGetDistance(); uint8_t currentDistance = sensorGetDistance();
@@ -44,3 +53,8 @@ bool mailboxGetMailDetected(void)
{ {
return mailDetected; return mailDetected;
} }
void mailboxCleared(void)
{
}

View File

@@ -7,7 +7,7 @@
#include "power.h" #include "power.h"
#include "mailbox.h" #include "mailbox.h"
#define TIME_TO_SLEEP 1 /* Time ESP32 will go to sleep (in seconds) */ #define TIME_TO_SLEEP 10 /* Time ESP32 will go to sleep (in seconds) */
void serialInit(void) void serialInit(void)
{ {
@@ -24,7 +24,7 @@ void setup()
sensorInit(); sensorInit();
//netInit(); //netInit();
powerInit(); powerInit();
//sleepInit(TIME_TO_SLEEP); sleepInit(TIME_TO_SLEEP);
displayUpdate(); displayUpdate();
} }
@@ -34,6 +34,6 @@ void loop()
sensorUpdateDistance(); sensorUpdateDistance();
displayUpdate(); displayUpdate();
mailboxhandler(); mailboxhandler();
//sleepStart(); sleepStart();
delay(1000); delay(1000);
} }

View File

@@ -5,7 +5,15 @@
#include <driver/adc.h> #include <driver/adc.h>
#include "display.h" #include "display.h"
#if (ENVIRONMENT == TTGO_T18)
#define VOLTAGE_DIVIDER 2 // ttgo has 100/100k voltage divider so need to reverse that reduction via (220k+100k)/100k on vbat GPIO37 or ADC1_1 (early revs were GPIO13 or ADC2_4 but do NOT use with WiFi.begin())
#define VOLTAGEREF 3787 // measured 2,0474 / 2214 ticks (mv)
#else
#define VOLTAGE_DIVIDER 2.08 // Lora has 220k/100k voltage divider so need to reverse that reduction via (220k+100k)/100k on vbat GPIO37 or ADC1_1 (early revs were GPIO13 or ADC2_4 but do NOT use with WiFi.begin()) #define VOLTAGE_DIVIDER 2.08 // Lora has 220k/100k voltage divider so need to reverse that reduction via (220k+100k)/100k on vbat GPIO37 or ADC1_1 (early revs were GPIO13 or ADC2_4 but do NOT use with WiFi.begin())
#endif
#define DEFAULT_VREF 1100 // Default VREF use if no e-fuse calibration #define DEFAULT_VREF 1100 // Default VREF use if no e-fuse calibration
#define VBATT_SAMPLE 500 // Battery sample rate in ms #define VBATT_SAMPLE 500 // Battery sample rate in ms
#define VBATT_SMOOTH 20 // Number of averages in sample #define VBATT_SMOOTH 20 // Number of averages in sample
@@ -15,7 +23,6 @@
uint16_t Sample(); uint16_t Sample();
esp_adc_cal_characteristics_t *adc_chars; esp_adc_cal_characteristics_t *adc_chars;
uint16_t voltage = 666; uint16_t voltage = 666;
@@ -27,6 +34,11 @@ void powerInit(void)
esp_adc_cal_value_t val_type = esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_6, ADC_WIDTH_BIT_12, DEFAULT_VREF, adc_chars); esp_adc_cal_value_t val_type = esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_6, ADC_WIDTH_BIT_12, DEFAULT_VREF, adc_chars);
adc1_config_width(ADC_WIDTH_BIT_12); adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(VBATT, ADC_ATTEN_DB_6); adc1_config_channel_atten(VBATT, ADC_ATTEN_DB_6);
#elif (ENVIRONMENT == TTGO_T18)
//nothing
adc_chars = (esp_adc_cal_characteristics_t *)calloc(1, sizeof(esp_adc_cal_characteristics_t));
esp_adc_cal_value_t val_type = esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_6, ADC_WIDTH_BIT_12, DEFAULT_VREF, adc_chars);
adc1_config_channel_atten(VBATT, ADC_ATTEN_DB_6);
#else #else
// Use this for older V2.0 with VBatt reading wired to GPIO13 // Use this for older V2.0 with VBatt reading wired to GPIO13
adc_chars = (esp_adc_cal_characteristics_t *)calloc(1, sizeof(esp_adc_cal_characteristics_t)); adc_chars = (esp_adc_cal_characteristics_t *)calloc(1, sizeof(esp_adc_cal_characteristics_t));
@@ -64,7 +76,6 @@ void powerInit(void)
Serial.println("Power init done"); Serial.println("Power init done");
} }
uint16_t powerGetVbatt(void) uint16_t powerGetVbatt(void)
{ {
return voltage; return voltage;
@@ -75,31 +86,30 @@ void powerHandler(void)
voltage = Sample(); voltage = Sample();
//displayDrawBatt(voltage, voltage < LIGHT_SLEEP_VOLTAGE); //displayDrawBatt(voltage, voltage < LIGHT_SLEEP_VOLTAGE);
if (voltage < MINBATT) // if (voltage < MINBATT)
{ // Low Voltage cut off shut down to protect battery as long as possible // { // Low Voltage cut off shut down to protect battery as long as possible
displayDrawShutdown(); // displayDrawShutdown();
delay(2000); // delay(2000);
#if defined(__DEBUG) && __DEBUG > 0 // #if defined(__DEBUG) && __DEBUG > 0
Serial.printf(" !! Shutting down...low battery volotage: %dmV.\n", voltage); // Serial.printf(" !! Shutting down...low battery volotage: %dmV.\n", voltage);
delay(10); // delay(10);
#endif // #endif
esp_sleep_enable_timer_wakeup(LO_BATT_SLEEP_TIME); // esp_sleep_enable_timer_wakeup(LO_BATT_SLEEP_TIME);
esp_deep_sleep_start(); // esp_deep_sleep_start();
} // }
else if (voltage < LIGHT_SLEEP_VOLTAGE) // else if (voltage < LIGHT_SLEEP_VOLTAGE)
{ // Use light sleep once on battery // { // Use light sleep once on battery
uint64_t s = VBATT_SAMPLE; // uint64_t s = VBATT_SAMPLE;
#if defined(__DEBUG) && __DEBUG > 0 // #if defined(__DEBUG) && __DEBUG > 0
Serial.printf(" - Light Sleep (%dms)...battery volotage: %dmV.\n", (int)s, voltage); // Serial.printf(" - Light Sleep (%dms)...battery volotage: %dmV.\n", (int)s, voltage);
delay(20); // delay(20);
#endif // #endif
esp_sleep_enable_timer_wakeup(s * 1000); // Light Sleep does not flush buffer // esp_sleep_enable_timer_wakeup(s * 1000); // Light Sleep does not flush buffer
esp_light_sleep_start(); // esp_light_sleep_start();
} // }
delay(ADC_READ_STABILIZE); delay(ADC_READ_STABILIZE);
} }
// Heltec WiFi LoRa V2 battery read example // Heltec WiFi LoRa V2 battery read example
// by Jeff McClain jeff@themcclains.net // by Jeff McClain jeff@themcclains.net
// //
@@ -107,27 +117,40 @@ void powerHandler(void)
// Poll the proper ADC for VBatt on Heltec Lora 32 with GPIO21 toggled // Poll the proper ADC for VBatt on Heltec Lora 32 with GPIO21 toggled
uint16_t ReadVBatt() uint16_t ReadVBatt()
{ {
Serial.println("start read batt");
int reading = 666; int reading = 666;
uint16_t rawVoltage;
#if (defined(HELTEC_V2_1))
digitalWrite(VEXT, LOW); // ESP32 Lora v2.1 reads on GPIO37 when GPIO21 is low digitalWrite(VEXT, LOW); // ESP32 Lora v2.1 reads on GPIO37 when GPIO21 is low
delay(ADC_READ_STABILIZE); // let GPIO stabilize delay(ADC_READ_STABILIZE); // let GPIO stabilize
#if (defined(HELTEC_V2_1))
pinMode(VBATT, OPEN_DRAIN); // ADC GPIO37 pinMode(VBATT, OPEN_DRAIN); // ADC GPIO37
reading = adc1_get_raw(VBATT); reading = adc1_get_raw(VBATT);
pinMode(VBATT, INPUT); // Disconnect ADC before GPIO goes back high so we protect ADC from direct connect to VBATT (i.e. no divider) pinMode(VBATT, INPUT); // Disconnect ADC before GPIO goes back high so we protect ADC from direct connect to VBATT (i.e. no divider)
#else uint16_t rawVoltage = esp_adc_cal_raw_to_voltage(reading, adc_chars);
#elif (ENVIRONMENT == TTGO_T18)
pinMode(VBATT, ANALOG); // ADC GPIO13
reading = analogRead(35);
Serial.printf("battery analogread = %i\n", reading);
rawVoltage = float(VOLTAGEREF / 4096) * reading;
Serial.printf("raw voltage = %i\n", rawVoltage);
//pinMode(VBATT, INPUT); // Disconnect ADC before GPIO goes back high so we protect ADC from direct connect to VBATT (i.e. no divider
#elif (ENVIRONMENT == LOLIN32)
digitalWrite(VEXT, LOW); // ESP32 Lora v2.1 reads on GPIO37 when GPIO21 is low
delay(ADC_READ_STABILIZE); // let GPIO stabilize
pinMode(VBATT, OPEN_DRAIN); // ADC GPIO13 pinMode(VBATT, OPEN_DRAIN); // ADC GPIO13
adc2_get_raw(VBATT, ADC_WIDTH_BIT_12, &reading); adc2_get_raw(VBATT, ADC_WIDTH_BIT_12, &reading);
pinMode(VBATT, INPUT); // Disconnect ADC before GPIO goes back high so we protect ADC from direct connect to VBATT (i.e. no divider pinMode(VBATT, INPUT); // Disconnect ADC before GPIO goes back high so we protect ADC from direct connect to VBATT (i.e. no divider
rawVoltage = esp_adc_cal_raw_to_voltage(reading, adc_chars);
#endif #endif
uint16_t rawVoltage = esp_adc_cal_raw_to_voltage(reading, adc_chars);
//Serial.printf("battery rawvoltage = %i\n", rawVoltage); //Serial.printf("battery rawvoltage = %i\n", rawVoltage);
rawVoltage *= VOLTAGE_DIVIDER; rawVoltage *= VOLTAGE_DIVIDER;
//Serial.printf("battery sample = %i\n", rawVoltage); Serial.printf("battery sample = %i\n", rawVoltage);
//digitalWrite(VEXT, HIGH); // ESP32 Lora v2.1 reads on GPIO37 when GPIO21 is low //digitalWrite(VEXT, HIGH); // ESP32 Lora v2.1 reads on GPIO37 when GPIO21 is low
return rawVoltage; return rawVoltage;
} }
// Use a buffer to average/sample ADC // Use a buffer to average/sample ADC

View File

@@ -1,5 +1,6 @@
#include "arduino.h" #include "arduino.h"
#include "sleep.h" #include "sleep.h"
#include "display.h"
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */ #define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */
@@ -65,7 +66,12 @@ void sleepStart()
Serial.flush(); Serial.flush();
Serial.println("Going to sleep now"); Serial.println("Going to sleep now");
Serial.flush(); Serial.flush();
displayOff();
delay(100); delay(100);
esp_light_sleep_start(); esp_light_sleep_start();
displayOn();
Serial.println("Woke"); Serial.println("Woke");
} }