From b14d5c302a29f01a28266c68678f18d0f15c2fae Mon Sep 17 00:00:00 2001 From: Laurentiu Badea Date: Sun, 4 Oct 2020 16:08:51 -0700 Subject: [PATCH] Update ESP32 wiring for TTGO T-Display board #73 Reference: https://github.com/Xinyuan-LilyGO/TTGO-T-Display --- examples/PanoController/PanoController.ino | 2 +- examples/PanoController/config_esp32.h | 48 +++++++++++---------- examples/PanoController/platform_mecha_e1.h | 2 +- src/battery.cpp | 14 ++++-- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/examples/PanoController/PanoController.ino b/examples/PanoController/PanoController.ino index b3f04e4..08be441 100644 --- a/examples/PanoController/PanoController.ino +++ b/examples/PanoController/PanoController.ino @@ -1,7 +1,7 @@ /* * Pano Controller Firmware * - * Copyright (C)2015-2017 Laurentiu Badea + * Copyright (C)2015-2020 Laurentiu Badea * * This file may be redistributed under the terms of the MIT license. * A copy of this license has been included with this distribution in the file LICENSE. diff --git a/examples/PanoController/config_esp32.h b/examples/PanoController/config_esp32.h index be560fb..44b06bf 100644 --- a/examples/PanoController/config_esp32.h +++ b/examples/PanoController/config_esp32.h @@ -1,39 +1,43 @@ /* * Pano Controller Configuration File for ESP32 board - * https://github.com/espressif/arduino-esp32/blob/master/docs/esp32_pinmap.png - * https://desire.giesecke.tk/index.php/2018/07/06/reserved-gpios/ + * Already wired in https://github.com/Xinyuan-LilyGO/TTGO-T-Display + * 19 TFT_MOSI + * 18 TFT_SCLK + * 5 TFT_CS + * 16 TFT_DC + * 4 TFT_BL + * 21 SDA + * 22 SCL + * 34 ADC_IN + * 35 BUTTON1 + * 0 BUTTON2 + * 14 ADC_POWER + * + * Reserved GPIOs + * not as inputs: 0, 2, 6-11, 12, 15, 16, 17 + * not as outputs: 6-11, 16, 17 34-39 + * Reference https://desire.giesecke.tk/index.php/2018/07/06/reserved-gpios/ */ #include -/* SPI (for display) -SPI2 and SPI3 are general purpose SPI controllers, sometimes referred to as HSPI and VSPI -SDA = IO 23 -SCLK = IO 18 -D/C = IO 21 -RST = IO 22 -CS = IO 5 -*/ - // Camera shutter controls -#define CAMERA_FOCUS GPIO_NUM_16 -#define CAMERA_SHUTTER GPIO_NUM_17 +#define CAMERA_FOCUS GPIO_NUM_37 +#define CAMERA_SHUTTER GPIO_NUM_38 // Battery measurement pin R1/R2 -#define BATTERY GPIO_NUM_34 //34 # ADC1 CH0 +#define BATTERY GPIO_NUM_36 // ADC0 // MPU (accel/gyro) // GPIO_NUM_21 I2C SDA // GPIO_NUM_22 I2C SCL -#define MPU_INT GPIO_NUM_2 -#define MPU_VCC GPIO_NUM_4 +#define MPU_INT GPIO_NUM_13 +#define MPU_VCC GPIO_NUM_12 // Future devices //#define COMPASS_DRDY xx -// Stepper drivers control -#define DIR GPIO_NUM_27 -#define VERT_STEP GPIO_NUM_25 +// Stepper drivers control. nENABLE, DIR are connected to both drivers +#define nENABLE GPIO_NUM_33 +#define DIR GPIO_NUM_27 +#define VERT_STEP GPIO_NUM_25 #define HORIZ_STEP GPIO_NUM_26 - -// this should be hooked up to nENABLE on both drivers -#define nENABLE GPIO_NUM_14 diff --git a/examples/PanoController/platform_mecha_e1.h b/examples/PanoController/platform_mecha_e1.h index f13a035..02d91bc 100644 --- a/examples/PanoController/platform_mecha_e1.h +++ b/examples/PanoController/platform_mecha_e1.h @@ -17,7 +17,7 @@ // R1-R2[Ω] is the voltage divider: GND-[R1]-[ADC Input]-[R2]-Vin // measure resistors/pot and enter actual values for more accurate measure -#define BATT_R1 7060 +#define BATT_R1 6674 #define BATT_R2 42600 #endif // PLATFORM_MECHA_E1 diff --git a/src/battery.cpp b/src/battery.cpp index 2617ac3..fcba934 100644 --- a/src/battery.cpp +++ b/src/battery.cpp @@ -1,7 +1,7 @@ /* * Battery status * - * Copyright (C)2016-2017 Laurentiu Badea + * Copyright (C)2016-2020 Laurentiu Badea * * This file may be redistributed under the terms of the MIT license. * A copy of this license has been included with this distribution in the file LICENSE. @@ -13,20 +13,28 @@ Battery::Battery(int battery_pin, int r1, int r2, int vcc) :battery_pin(battery_pin), r1(r1), r2(r2), vcc(vcc) {} +#define ADC_BITS 10 + void Battery::begin(void){ // Configure input pin and ADC for reading battery voltage pinMode(battery_pin, INPUT); #if defined(__MK20DX256__) || defined(__MKL26Z64__) - analogReadRes(10); + analogReadRes(ADC_BITS); analogReadAveraging(32); #endif +#if defined(ESP32) + // ESP32 ADC is non-linear, so the measured voltage not accurate + // https://github.com/espressif/arduino-esp32/issues/1804#issuecomment-475281577 + vcc = 3500; + analogReadResolution(ADC_BITS); // ESP32 default is 12 +#endif } /* * Return battery voltage, in mV */ int Battery::voltage(void){ - return map(analogRead(battery_pin), 0, (1<<10)-1, 0, (vcc * (r1 + r2) / r1)/100) * 100; + return map(analogRead(battery_pin), 1, (1<