Skip to content

Commit

Permalink
Update ESP32 wiring for TTGO T-Display board #73
Browse files Browse the repository at this point in the history
  • Loading branch information
laurb9 committed Oct 5, 2020
1 parent d4b4094 commit b14d5c3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
2 changes: 1 addition & 1 deletion examples/PanoController/PanoController.ino
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
48 changes: 26 additions & 22 deletions examples/PanoController/config_esp32.h
Original file line number Diff line number Diff line change
@@ -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 <Arduino.h>

/* 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
2 changes: 1 addition & 1 deletion examples/PanoController/platform_mecha_e1.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 11 additions & 3 deletions src/battery.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<<ADC_BITS)-1, 0, (vcc * (r1 + r2) / r1)/100) * 100;
}

/*
Expand Down

0 comments on commit b14d5c3

Please sign in to comment.