Bluetooth Controller

You will be connecting a wireless game controller to your ESP32 for controlling your robot (i.e. triggering autonomous modes, moving between challenges, and firing your launching mechanism)

That being said, you will not earn points for manually driving your robot through the challenges, as that defeats the purpose of having the sensors.

It is highly recommended that you map autonomous sensors modes (line, color, distance) to specific buttons on the remote controller so that you have more control over your robot’s behavior (i.e. press A -> autonomous color mode, press B -> exit to normal drive mode).

Connecting the Controller

See BluePad32’s official docs if you’d like to see other features.

First you will need to find out what your controller’s Bluetooth address is.

Note that your controller will likely have the address already labeled on it for ease of use, so you can easily jump to Step 4

  1. Plug in your ESP32 and flash it with the starter code
  2. Open the serial monitor
  3. You should see your controller address as a string of octets (something like 98:B6:E1:7C:C3:95) in the serial monitor while trying to connect your controller (press and hold power button on controller until lights slowly and then rapidly move to put it in pairing mode): controller_address :(

  4. Try adding your controller’s Bluetooth address through the serial terminal: add_bluetooth.png :(

  5. Controller should be able to connect now, and the controller data should begin streaming in the serial monitor after connecting

Accessing controller data

In the sample code, there is a handle (i.e. pointer) for your controller called myCtl defined at the top of the loop() function. You can use the ControllerPtr class’s helper functions to read data from the controller into your code logic.

This means you will have to pass the controller handle into functions if you want to use them in there. TODO: do we want to just make the myCtl handle a global var

You must call BP32.update() to update the values being read into your ESP32, and then you call helper functions (i.e. a() or x()) to actually retrieve the controller values.

To see how to access the different peripherals on your controller, check out the sample code’s dumpGamepad() function! Alternatively, you can hover over a function defined by BluePad32 and Ctrl + Left Click to see the actual source code for it. Yet another alternative is to go dig around on the official BluePad32 docs.