Skip to content

Firmware for esp32 that accepts a bluetooth connection from e.g. a dualshock 3 controller

License

Notifications You must be signed in to change notification settings

zero-ones-given/bluetooth-robot-firmware

Repository files navigation

Zero Ones Given Bluetooth remote controlled robot

  • Clone the project with submodules: git clone --recurse-submodules [email protected]:zero-ones-given/bluetooth-robot-firmware.git
  • Install ESP-IDF 4.4.5
  • Configure python virtual env etc by running: . $HOME/esp/esp-idf/export.sh
  • Build idf.py build
  • If you get build errors after changing ESP-IDF version, try running idf.py fullclean and building again
  • Press the EN button on the ESP32 to enable programming mode
  • Flash and monitor: idf.py -p /dev/cu.usbserial-0001 flash monitor (replace the port with the appropriate one)
  • See pairing instructions for your controller
    • If you're using a DS3 controller, find out the bluetooth mac address (should be printed out to console during startup) and use sixaxispairer or some other tool to write the mac address to the controller
    • ./bin/sixaxispairing xx:xx:xx:xx:xx:xx

Controls

  1. You can use either analog stick to control the robot.
  2. If you want to use both sticks, you can use the other to control turning and the other for controlling the speed forwards / backwards.
  3. The dpad can also be used to control the robot
  4. If the robot does not drive straight, you can hold the start / home button while pressing left or right on the dpad. This compensates the balance of the motors to favor the direction you pressed. The maximum compensation is reached after 10 button presses. This setting does not persist after a restart.
  5. You can reset the motor balance by holding the start / home button and pressing up or down on the dpad.

Original readme of the template project below:

ESP-IDF + Arduino + Bluepad32 template app

discord

logo

This is a template application to be used with Espressif IoT Development Framework.

Please check ESP-IDF docs for getting started instructions.

Requires ESP-IDF v4.4 or newer.

Includes the following ESP-IDF components, with a pre-configured sdkconfig file:

How to compile it

For Windows

  1. Install ESP-IDF v4.4. For further info, read: ESP-IDF Getting Started for Windows

    • Either the Online or Offline version should work
    • When asked which components to install, don't change anything. Default options are Ok.
    • When asked whether ESP can modify the system, answer "Yes"
  2. Launch the "ESP-IDF v4.4 CMD" (type that in the Windows search box)

  3. From the ESP-IDF cmd, clone the template

    git clone --recursive https://gitlab.com/ricardoquesada/esp-idf-arduino-bluepad32-template.git my_project
  4. Compile it

    # Compile it
    cd my_project
    idf.py build
    
    # Flash + open debug terminal
    idf.py flash monitor

For Linux / macOS

  1. Requirements and permissions

    Install ESP-IDF dependencies (taken from here):

    # For Ubuntu / Debian
    sudo apt-get install git wget flex bison gperf python3 python3-pip python3-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0

    And in case you don't have permissions to open /dev/ttyUSB0, do: (taken from here)

    # You MUST logout/login (or in some cases reboot Linux) after running this command
    sudo usermod -a -G dialout $USER
  2. Install and setup ESP-IDF

    # Needs to be done just once
    # Clone the ESP-IDF git repo
    mkdir ~/esp && cd ~/esp
    git clone -b release/v4.4 --recursive https://github.com/espressif/esp-idf.git
    
    # Then install the toolchain
    cd ~/esp/esp-idf
    ./install.sh
  3. Compile the template

    Clone the template:

    # Do it everytime you want to start a new project
    # Clone the template somewhere
    mkdir ~/src && cd ~/src
    git clone --recursive https://gitlab.com/ricardoquesada/esp-idf-arduino-bluepad32-template.git my_project

    Export the ESP-IDF environment variables in your shell:

    # Do it everytime you open a new shell
    # Optional: add it in your ~/.bashrc or ~/.profile
    source ~/esp/esp-idf/export.sh

    And finally compile and install your project.

    # Compile it
    cd ~/src/my_project
    idf.py build
    
    # Flash + open debug terminal
    idf.py flash monitor

Using 3rd party Arduino libraries

To include 3rd party Arduino libraries in your project, you have to:

  • Add them to the components folder.
  • Add CMakeLists.txt file inside the component's folder

Let's use a real case as an example:

Example: Adding ESP32Servo

Suppose you want to use ESP32Servo project. The first thing to notice is that the source files are placed in the src folder. We have to create a CMakeLists.txt file that tells ESP-IDF to look for the sources in the src folder.

Example:

# 1) We clone ESP32Servo into components folder
cd components
git clone https://github.com/madhephaestus/ESP32Servo.git
cd ESP32Servo

And now create these files inside components/ESP32Servo folder:

# 2) Create CMakeLists.txt file
# Copy & paste the following lines to the terminal:
cat << EOF > CMakeLists.txt
idf_component_register(SRC_DIRS "src"
                    INCLUDE_DIRS "src"
                    REQUIRES "arduino")
EOF

Finally, update the dependencies in the main/CMakeLists.txt. E.g:

cd main
edit CMakeLists.txt

...and append ESP32Servo to REQUIRES. The main/CMakeLists.txt should look like this:

idf_component_register(SRCS "${srcs}"
                    INCLUDE_DIRS "."
                    REQUIRES "${requires}" "ESP32Servo")

And that's it. Now you can include ESP32Servo from your code. E.g:

// Add this include in your arduino_main.cpp file
#include <ESP32Servo.h>

IDE

Arduino IDE is not supported, but you can use Visual Studio Code + ESP-IDF plugin.

You can do:

  • All the regular Visual Studio Code regular features
  • ...plus configure, build, flash and monitor your project
  • ...and much more

ide

Subjective opinion: VSCode + ESP-IDF plugin is muuuuuch better than Arduino IDE. Highly recommended!

Further info

Support

  • Discord: any question? Ask them on our Discord server.

About

Firmware for esp32 that accepts a bluetooth connection from e.g. a dualshock 3 controller

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published