Building a mini drone use ESP32

I had the same problem, mostly this is due to incorrect wiring of the sensors. For me it was that I had forgotten the SPI Chip-Select pin. This is configured here:

#define HAL_ESP32_SPI_DEVICES \
    {.name= "bmp280", .bus=0, .device=0, .cs=GPIO_NUM_26, .mode = 3, .lspeed=1*MHZ, .hspeed=1*MHZ}, \
    {.name="mpu9250", .bus=0, .device=1, .cs=GPIO_NUM_5,  .mode = 0, .lspeed=2*MHZ, .hspeed=8*MHZ}

So the IMU needs its CS pin connected to GPIO5.

Hello Vabe, You are using the mpu9250, have you tried with MPU6050?

The Buzz firmware is set up for the mpu9250. I also used the 6050 ones but this requires a different setup. The 6050 doesn’t even have SPI so you must use I2C. Here is a setup that uses the GY87 which includes the mpu6050: Discord

Amazing project. Thank @Leon90 for sharing.
And question. I built ardupilot from GitHub scr, flush it to esp32. Reboot. Console log last lines:

I (20320) wifi:mode : softAP (32:ae:a4:96:f4:c4)
I (20322) wifi:Total power save buffer number: 8
I (20322) wifi:Init max length of beacon: 752/752
I (20322) wifi:Init max length of beacon: 752/752
WiFi softAP init finished. SSID: ardupilot123 password: ardupilot123 channel: 1
OK created task _wifi_thread on FASTCPU
AP_Logger_File: buffer size=16384
AnalogIn: adding ardupin:255-> which is adc1_offset:-1
AnalogIn: channel:0 created but using delayed adc and gpio pin configuration
spi device constructed SPI:bmp280:0:0
No Compass backends available
spi device constructed SPI:mpu9250:0:1

Now I have only esp32 board, no any sensors or SD card connected. I try to connect MP and QGC using serial on PC, connect to SoftAP and try to connect MP and QGC on android phone, but without success. This mean that I cant do this without connected to esp32 sensors?
And other question - Ardupilot esp32 console is only for log output? I cant execute any commands via it?
Thanks in advance.

you must connect sensor to connect in MP (need only IMU)
Also when flash firmware you must connect sensor.

1 Like

Hi again guys! I’m going to buy ESC for esp32-ardupilot solution. In this

paper DShot is in ‘Future development’ section. Also, it is in the ‘Old’ section. So the question is whether the firmware supports DShot right now, which ESC should I buy to work with esp32 FW?
Have a nice day!

I assume if DShot doesn’t work you go back to “standard” pwm?
Every modern ESC that supports DShot is also backwards compatible to normal pwm, so there’s no limitation.
I would recommend basically any BLHeli_32 or Bluejay-flashed BLHeli_S ESC

1 Like

Hello,

what a fantastic project and initiative! I would really like to contribute here. Well, maybe with some error logs first. I managed to compile the code for ESP32 and flashed it on my ESP32Dev v4. Worked like a charm. I then connected to the wifi accesspoint. Launched MP and tried to connect via tcp (192.168.4.1 on 5760 with 115200 baud rate).

Unfortunately, without success. MP gives me a timeout. I checked my firewall and disabled it (I’m running on Ubuntu). Still no success.

The tcp seems to be there:

telnet 192.168.4.1 5760

Trying 192.168.4.1...
Connected to 192.168.4.1.
Escape character is '^]'.

This is what ninja monitor gives me:

Anyone knows what is going on? I have no SD-Card reader attached. Could this be the culprit?

Oh and as for the sensors: I use MPU9250 and BMP280 on SPI …

rst:0x1 (POWERON_RESET),boot:0x1a (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4976
load:0x40078000,len:15300
ho 0 tail 12 room 4
load:0x40080400,len:3776
entry 0x40080620
I (559) cpu_start: Multicore app
I (559) cpu_start: Pro cpu up.
I (560) cpu_start: Starting app cpu, entry point is 0x40085698
I (0) cpu_start: App cpu up.
I (577) cpu_start: Pro cpu start user code
I (577) cpu_start: cpu freq: 240000000
I (577) cpu_start: Application information:
I (582) cpu_start: ELF file SHA256:  871207bb39df5054...
I (588) cpu_start: ESP-IDF:          v4.4.6-502-g6897e4e0fa
I (594) cpu_start: Min chip rev:     v0.0
I (599) cpu_start: Max chip rev:     v3.99 
I (604) cpu_start: Chip rev:         v3.0
I (609) heap_init: Initializing. RAM available for dynamic allocation:
I (616) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (622) heap_init: At 3FFC6508 len 00019AF8 (102 KiB): DRAM
I (628) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (634) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (641) heap_init: At 40096508 len 00009AF8 (38 KiB): IRAM
I (648) spi_flash: detected chip: generic
I (652) spi_flash: flash io: qio
I (667) esp_core_dump_uart: Init core dump to UART
I (667) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
virtual void ESP32::Scheduler::init():70 running with CONFIG_FREERTOS_HZ=500
OK created task _main_thread
AnalogIn: eFuse Two Point: NOT supported
AnalogIn: eFuse Vref: Supported
OK created task _timer_thread
oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
OK created task _rcout_thread
RCOե�}ѡɕ��5
OK created task _uart_thread
Mounting sd 
I (757) SD...: Initializing SD card as SDMMC


Init ArduCopter V4.5.0-dev (00a65632)

Free RAM: 110592
OK created task _io_thread
OK created task _storage_thread
Firmware change: erasing EEPROM...
done.
E (785) sdmmc_common: sdmmc_init_ocr: send_op_cond (1) returned 0x107
E (785) vfs_fat_sdmmc: sdmmc_card_init failed (0x107).
sdcard is not mounted
load_all took 2399174us
I (3183) wifi:wifi driver task: 3ffd9800, prio:23, stack:6656, core=0
I (3183) system_api: Base MAC address is not set
I (3183) system_api: read default base MAC address from EFUSE
I (3189) wifi:wifi firmware version: 1fd20f4
I (3193) wifi:wifi certification version: v7.0
I (3197) wifi:config NVS flash: disabled
I (3201) wifi:config nano formating: disabled
I (3205) wifi:Init data frame dynamic rx buffer num: 16
I (3211) wifi:Init static rx mgmt buffer num: 5
I (3215) wifi:Init management short buffer num: 32
I (3219) wifi:Init dynamic tx buffer num: 16
I (3223) wifi:Init static rx buffer size: 1600
I (3227) wifi:Init static rx buffer num: 2
I (3231) wifi:Init dynamic rx buffer num: 16
I (3235) wifi_init: tcpip mbox: 32
I (3239) wifi_init: udp mbox: 6
I (3243) wifi_init: tcp mbox: 6
I (3247) wifi_init: tcp tx win: 5744
I (3251) wifi_init: tcp rx win: 5744
I (3255) wifi_init: tcp mss: 1436
I (3259) wifi_init: WiFi RX IRAM OP enabled
I (3419) phy_init: phy_version 4791,2c4672b,Dec 20 2023,16:06:06
I (3493) wifi:mode : softAP (aa:42:e3:48:f7:0c)
I (3495) wifi:Total power save buffer number: 8
I (3495) wifi:Init max length of beacon: 752/752
I (3495) wifi:Init max length of beacon: 752/752
OK created task _wifi_thread
AnalogIn: adding ardupin:255-> which is adc1_offset:-1
AnalogIn: channel:0 created but using delayed adc and gpio pin configuration
spi device constructed SPI:bmp280:0:0
No Compass backends available
spi device constructed SPI:mpu9250:0:1
Init GyroI (17249) wifi:new:<1,1>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (17249) wifi:station: 52:02:7b:0d:a0:db join, AID=1, bgn, 40U
I (17547) esp_netif_lwip: DHCP server assigned IP to a station, IP is: 192.168.4.2

I am not sure may I understand correct that you try to connect to 192.168.4.1
But your ESP32 seems to be assigned to 192.168.4.2 while 192.168.4.1 is your access point.

1 Like

The ESP creates an AP on 192.168.4.1. The IP address, which appears in the monitor logs (192.168.4.2) is from my connection of my laptop (I join the Wifi, created by the ESP32).

Interestingly, I got it working a couple of minutes ago and the drone appeared in MP, but I couldn’t replicate. Could it be a faulty sensor?

Update on my build: I figured it was the missing SD card. Seems to work fine now. I’m able to connect through MP with tcp. Thanks @Leon90 for details you provided above. That helped a lot to get started!!

Hi @cmb87 greetings, how to upload that three file bootloader.bin,ardupilot.bin , partition_table.bin using espressif flash tool.
because I am using the windows 11. and I successful completed compiling process.

@Leon90 Thank you esp32 porting, I am stuck uploading step. cloud you please tell me how to upload that three file.

bootloader.bin,ardupilot.bin , partition_table.bin

using espressif flash tool
because I am using the windows 11. and I successful completed compiling process.

I used the essprif-sdk under Ubuntu (you find all the instructions in the README.md in AP_HAL_ESP32 dir). As I’m not a Windows guy, some suggestions:

Under Windows 11 install Docker ( Install Docker Desktop on Windows | Docker Docs) and spin up an Ubuntu container. Volume mount your ardupilot repo and usb ports to that container and use
./waf copter --upload

Hope that helps. Good luck.

Thank you for your reply, Mr. Chris P. I hope this will be helpful. Let me work on this and tell you the result.

Hello, @Leon90 any chance to send me the files for rover version to test a project? Thank you in advance . jb132_yo@yahoo.com

Is it working for Rover? I thought so far Copter is only supported?

Thanks guys! This is a really great way to get a cheap Ardupilot compatible controller that you can build yourself and experiment with. It definitely prompted me to also delve deeper into the Ardupilot code to understand, experiment and play with it some more.
Being inspired by @Leon90 and having all the parts (SDCard breakout, MPU9250 and BMP280) laying around, I also gave it a try. Setting up the build environment (on Ubuntu) was straight forward by following the steps at ardupilot/libraries/AP_HAL_ESP32/README.md at master · ArduPilot/ardupilot · GitHub then using the esp32buzz board as target. The master version was 4.6.0-dev

The ESP32 and peripheral was built on a breadboard and firmware flashed using the instructions in the previously mentioned readme file. So far everything seems to work. I managed to connect both via WiFi and using an UART to USB bridge. Using an oscilloscope I probed the motor output pins while doing a motor test in MP and it also seems to work fine, why wouldn’t it :wink:

Anyway, the only thing that worries me at the moment is that MP reports “Main loop slow (132Hz < 400Hz)”.
Is this too slow for proper control? What would the minimum be for Copter?
Leon90 also mentioned that he was concerned about the main loop speed, does anybody have some advice on which features could safely be disabled to improve the rate?

1 Like

Have anybody tried and had success the ESP32-S3?
I gave it (esp32s3devkit) a quick try last night, startup seems fine but telemetry then freezes shortly after the first MAVLink messages appear. Also found a possible bug (related to S3) in RmtSigReader.cpp, in the init() function RMT_CHANNEL_6 should be used as RX only works on channels 4 to 7.
Will give it another shot tonight.

The reason for trying the S3 is to see if it would help solve the slow main loop problem. It seems the problem with ESP32 is not the CPU clock speed but the bus speed at which instructions can be fetched from the external flash. The S3 has the same CPU clock speed but a faster bus and better cache which could allow faster execution. Any thoughts on this?

Please drop your email bro…I want some help related to your project.