17 KiB
TODO
- The shunt resistor R31 and R32 might need to change the values.
STATUS
BMP280 -- [ WORKING ] GYRO ---- [ WORKING ] RX ------ [ WORKING ] OSD ----- [ ] VMETER -- [ WORKING ] CMETER -- [ WORKING ]
Configurator
Planning to design a web-base for configuring the quad settings and so on. Everything using Javascripts and HTML. This will greatly reduce the need of the configurator to be downloaded. Purely configure by its own.
REFERENCES
+-----------------------+
| O | USB | O |
| ------- |
3V3 | [ ] [ ] | VIN
GND | [ ] [ ] | GND
[ ] Touch3 / HSPI_CS0 / ADC2_3 / GPIO15 | [ ] [ ] | GPIO13 / ADC2_4 / HSPI_ID / Touch4 [ ]
[ ] CS / Touch2 / HSPI_WP / ADC2_2 / GPIO2 | [ ] [ ] | GPIO12 / ADC2_5 / HSPI_Q / Touch5 [ ]
[ ] Touch0 / HSPI_HD / ADC2_0 / GPIO4 | [ ] [ ] | GPIO14 / ADC2_6 / HSPI_CLK / Touch6 [ ]
[ ] U2_RXD / GPIO16 | [ ] [ ] | GPIO27 / ADC2_7 / Touch7 [ ]
[ ] U2_TXD / GPIO17 | [ ] [ ] | GPIO26 / ADC2_9 / DAC2 [ ]
[ ] V_SPI_CS0 / GPIO5 | [ ] ___________ [ ] | GPIO25 / ADC2_8 / DAC1 [ ]
[ ] SCK / V_SPI_CLK / GPIO18 | [ ] | | [ ] | GPIO33 / ADC1_5 / Touch8 / XTAL32 [ ]
[ ] U0_CTS / MSIO / V_SPI_Q / GPIO19 | [ ] | | [ ] | GPIO32 / ADC1_4 / Touch9 / XTAL32 [ ]
[ ] SDA / V_SPI_HD / GPIO21 | [ ] | | [ ] | GPIO35 / ADC1_7 [ ]
[ ] CLK2 / U0_RXD / GPIO3 | [ ] | | [ ] | GPIO34 / ADC1_6 [ ]
[ ] CLK3 / U0_TXD / GPIO1 | [ ] | | [ ] | GPIO39 / ADC1_3 / SensVN [ ]
[ ] SCL / U0_RTS / V_SPI_WP / GPIO22 | [ ] | | [ ] | GPIO36 / ADC1_0 / SensVP [ ]
[ ] MOSI / V_SPI_WP / GPIO23 | [ ] |___________| [ ] | EN
| |
| | | ____ ____ | |
| | | | | | | | |
| |__|__| |__| |__| |
| O O |
+-----------------------+
Power Pins
VIN - VIN pin can be used to directly supply the ESP32 and its peripherals, if you have a regulated 5V voltage source. 3V3 - 3.3V pin is the output of an on-board voltage regulator. This pin can be used to supply power to external components. GND - Ground pin(s)
GPIO Pins
ESP32 development board has 25 GPIO pins which can be assigned to various functions programmatically. Each digital enabled GPIO can be configured to internal pull-up or pull-down, or set to high impedance. When configured as an input, it can also be set to edge-trigger or level-trigger to generate CPU interrupts.
ADC Channels
The board integrates 12-bit SAR ADCs and supports measurements on 15 channels (analog enabled pins). Some of these pins can be used to build a programmable gain amplifier which is used for the measurement of small analog signals. The ESP32 is also designed to measure the voltages while operating in the sleep mode.
DAC Channels
he board features two 8-bit DAC channels to convert digital signals into true analog voltages. This dual DAC can drive other circuits.
Touch Pads
The board offers 9 capacitive sensing GPIOs which detect capacitive variations introduced by the GPIO’s direct contact or close proximity with a finger or other objects.
UART Pins
ESP32 development board has 2 UART interfaces, i.e. UART0 and UART2, which provide asynchronous communication (RS232 and RS485) and IrDA support, and communicate at up to 5 Mbps. UART provides hardware management of the CTS and RTS signals and software flow control (XON and XOFF) as well.
SPI Pins
SPI Pins ESP32 features three SPIs (SPI, HSPI and VSPI) in slave and master modes. These SPIs also support the following general-purpose SPI features:
- 4 timing modes of the SPI format transfer
- Up to 80 MHz and the divided clocks of 80 MHz
- Up to 64-Byte FIFO
- All SPIs can also be used to connect to the external Flash/SRAM and LCD.
PWM Pins
The board has 25 channels (Nearly All GPIO pins) of PWM pins controlled by Pulse Width Modulation (PWM) controller. The PWM output can be used for driving digital motors and LEDs. The controller consists of PWM timers and the PWM operator. Each timer provides timing in synchronous or independent form, and each PWM operator generates the waveform for one PWM channel.
EN Pin
Used to enable ESP32. The chip is enabled when pulled HIGH. When pulled LOW the chip works at minimum power.
GPIO PINS LAYOUT NOTES
+------+--------+--------+--------------------------------------------------------------------------------+ | GPIO | INPUT | OUTPUT | Notes | +------+--------+--------+--------------------------------------------------------------------------------+ | 0 | PULLUP | [OK] | Output PWM signal at boot | | 1 | TX PIN | [OK] | Debug output at boot | | 2 | OK | OK | | | 3 | [OK] | OK | HIGH at boot | | 4 | OK | RX PIN | | | 5 | OK | OK | Output PWM signal at boot | | 12 | [OK] | OK | Boot fail if pulled high | | 13 | OK | OK | | | 14 | OK | OK | Output PWM signal at boot | | 15 | OK | OK | Output PWM signal at boot. If grounded, it will disable the bootup messages. | | 16 | OK | OK | | | 17 | OK | OK | | | 18 | OK | OK | | | 19 | OK | OK | | | 21 | OK | OK | | | 22 | OK | OK | | | 23 | OK | OK | | | 25 | OK | OK | | | 26 | OK | OK | | | 27 | OK | OK | | | 32 | OK | OK | | | 33 | OK | OK | | | 34 | OK | | | | 35 | OK | | | | 36 | OK | | | | 39 | OK | | | +------+--------+--------+--------------------------------------------------------------------------------+
CAPACITIVE TOUCH GPIO
NAME: T0, T1, T2, T3, T4, T5, T6, T7, T8, T9 GPIO: 4, 0, 2, 15, 13, 12, 14, 27, 33, 32
ADC CHANNELS
NAME: ADC1_CH0, ADC1_CH1, ADC1_CH2, ADC1_CH3, ADC1_CH4, ADC1_CH5, ADC1_CH6, ADC1_CH7 GPIO: 36, 37, 38, 39, 32, 33, 34, 35
NAME: ADC2_CH0, ADC2_CH1, ADC2_CH2, ADC2_CH3, ADC2_CH4, ADC2_CH5, ADC2_CH6, ADC2_CH7, ADC2_CH8, ADC2_CH9 GPIO: 4, 0, 2, 15, 13, 12, 14, 27, 25, 26
DIGITAL TO ANALOG CONVERTER (DAC)
NAME: DAC1, DAC2 GPIO: 25, 26
REF
- [PINOUT] https://randomnerdtutorials.com/esp32-pinout-reference-gpios/ https://circuits4you.com/2018/12/31/esp32-hardware-serial2-example/
- [EXAMPLES] https://circuits4you.com/2018/12/31/esp32-hardware-serial2-example/
- [DSHOT] https://github-wiki-see.page/m/betaflight/betaflight/wiki/DSHOT-ESC-Protocol
TODO
- RECEIVER ---------------------------------------------- [ 80% DONE ]
- ESC --------------------------------------------------- [ 80% DONE ]
- Accelerometer ----------------------------------------- [ 50% DONE ]
- Flight Mode ------------------------------------------- [ ]
- Acro ------------------------------------------------ [ ]
- Angle ----------------------------------------------- [ ]
- Fail Safe --------------------------------------------- [ ]
- Baro -------------------------------------------------- [ DONE ]
- GPS --------------------------------------------------- [ ]
- Telemetry --------------------------------------------- [ ]
- OTA --------------------------------------------------- [ DONE ]
- SoftAP ----------------------------------------------- [ DONE ]
- Turtle Mode ------------------------------------------ [ ]
- TRAMP ------------------------------------------------ [ ]
- Voltage Reading -------------------------------------- [ 90% DONE ]
- Ampere Reading --------------------------------------- [ 50% DONE ]
- Kalman Filtering ------------------------------------- [ ]
- PID -------------------------------------------------- [ ]
DSHOT
DSHOT150: 4kHz max DSHOT300: 10.6kHz max (10,6khz is only available on 32khz gyro boards) DSHOT600: 16kHz max DSHOT1200: >32khz max (Currently only KISS24 supports DSHOT1200)
DSHOT Digital Values: 0 : DISARMED 1 to 47 : RESERVED FOR SPECIAL COMMANDS 48: 2047: ACTIVE THROTTLE CONTROL
0 DSHOT_CMD_MOTOR_STOP, // Currently not implemented 1 DSHOT_CMD_BEEP1, // Wait at least length of beep (380ms) before next command 2 DSHOT_CMD_BEEP2, // Wait at least length of beep (380ms) before next command 3 DSHOT_CMD_BEEP3, // Wait at least length of beep (400ms) before next command 4 DSHOT_CMD_BEEP4, // Wait at least length of beep (400ms) before next command 5 DSHOT_CMD_BEEP5, // Wait at least length of beep (400ms) before next command 6 DSHOT_CMD_ESC_INFO, // Currently not implemented 7 DSHOT_CMD_SPIN_DIRECTION_1, // Need 6x, no wait required 8 DSHOT_CMD_SPIN_DIRECTION_2, // Need 6x, no wait required 9 DSHOT_CMD_3D_MODE_OFF, // Need 6x, no wait required 10 DSHOT_CMD_3D_MODE_ON, // Need 6x, no wait required 11 DSHOT_CMD_SETTINGS_REQUEST, // Currently not implemented 12 DSHOT_CMD_SAVE_SETTINGS, // Need 6x, wait at least 12ms before next command 20 DSHOT_CMD_SPIN_DIRECTION_NORMAL, // Need 6x, no wait required 21 DSHOT_CMD_SPIN_DIRECTION_REVERSED, // Need 6x, no wait required 22 DSHOT_CMD_LED0_ON, // Currently not implemented 23 DSHOT_CMD_LED1_ON, // Currently not implemented 24 DSHOT_CMD_LED2_ON, // Currently not implemented 25 DSHOT_CMD_LED3_ON, // Currently not implemented 26 DSHOT_CMD_LED0_OFF, // Currently not implemented 27 DSHOT_CMD_LED1_OFF, // Currently not implemented 28 DSHOT_CMD_LED2_OFF, // Currently not implemented 29 DSHOT_CMD_LED3_OFF, // Currently not implemented DSHOT_CMD_MAX = 47
Frame Structure: Every digital protocol has a structure, also called a frame. It defines which information is at which position in the data stream. And the frame structure of DSHOT is pretty straight forward:
- 11 bit throttle: 2048 possible values. 0 is reserved for disarmed. 1-47 are reserved for special commands. Leaving 48 to 2047 (2000 steps) for the actual throttle value.
- 1 bit telemetry request - if this is set, telemetry data is sent back via a separate channel.
- 4 bit CRC: (Cyclic Redundancy) Check to validate data (throttle and telemetry request bit)
Resulting in a 16 bit (2 byte) frame with the following structure: SSSSSSSSSSSTCCCC
+-------+------------+-------+-------+---------+-----------+ | DSHOT | Bitrate | T1H | T0H | Bit(µs) | Frame(µs) | +-------+------------+-------+-------+---------+-----------+ | 150 | 150kbit/s | 5.00 | 2.50 | 6.67 | 106.72 | | 300 | 300kbit/s | 2.50 | 1.25 | 3.33 | 53.28 | | 600 | 600kbit/s | 1.25 | 0.625 | 1.67 | 26.72 | | 1200 | 1200kbit/s | 0.625 | 0.313 | 0.83 | 13.28 | +-------+------------+-------+-------+---------+-----------+
Signal Pattern (From Oscilloscope):
1.670uS --------------------------------- 400.8064129026064 cycles in total
0.625uS high, 1.045uS low --- 0 --------- 150.0024000384006 cycles HIGH, 250.8040128642058 cycles LOW
1.250uS high, 0.420uS low --- 1 --------- 300.0048000768012 cycles HIGH, 100.8016128258052 cycles LOW
|-|-|
_
- | |
Every data = 16bits
Specs (per bit):
- HIGH time : 1.25 uS
- LOW time : 0.625uS
- Total Time Frame: 1.67 uS
- Max Time Frame : 26.72 uS
Commands 0-36 are only executed when motors are stopped. Some commands need to be sent multiple times in order for the ESC to act on it - those are marked with Needs nx - where n is the amount of times the command has to be sent in order for the ESC to act upon it.
5: 0001 0010 0100 0111 | 00010010010 0 0111 6: 0001 0101 1100 1000 | 00010101110 0 1000 7: 0001 1000 0010 1011 | 00011000001 0 1011 100: 1111 1111 1110 1110 | 11111111111 0 1110
Calculating the CRC: The checksum is calculated over the throttle value and the telemetry bit, so the "first" 12 bits our value in the following example: crc = (value ^ (value >> 4) ^ (value >> 8)) & 0x0F;
Let’s assume we are sending a throttle value of 1046 - which is exactly half throttle and the telemetry bit is not set: value = 100000101100 (>>4) = 000010000010 # right shift value by 4 (^) = 100010101110 # XOR with value (>>8) = 000000001000 # right shift value by 8 (^) = 100010100110 # XOR with previous XOR (0x0F) = 000000001111 # Mask 0x0F (&) = 000000000110 # CRC
So the two bytes transmitted from flight-controller to ESC would be: 1000001011000110
ESP32 CLOCKs: 240MHz clock 240000000 cycles = 1 second 240000 cycles = 1 mili second 240 cycles = 1 micro second 1 cycle = 4.167 nano second
HOWTO UPLOAD
./upgrade.py http://192.168.1.1/update .pio/build/esp32dev/firmware.bin
Flight Controller
- Sequencer Task +> ICM20602 -> BMP280 -> NRF24L01+ -> AT7458 ^ | | | +----------------------------------+
REF:
- https://brushlesswhoop.com/dshot-and-bidirectional-dshot/
- https://github.com/espressif/arduino-esp32/blob/master/libraries/ESP32/examples/FreeRTOS/FreeRTOS.ino (TRY THIS)
- https://www.digikey.at/en/maker/projects/introduction-to-rtos-solution-to-part-12-multicore-systems/369936f5671d4207a2c954c0637e7d50
- BMP280 - https://community.blynk.cc/t/esp32-bmp280-st7735-mcp2301-blynk/38933
PROBLEM
- When BARO class is running, all SPI functions are halted. Unable to receive signals from NRF24L01, Gyro not working.