Create modules for ESP32 microcontrollers | Set up an ESP32

Create modules for ESP32 microcontrollers

If no existing modules support your hardware or software, you can create your own. You’ll write it in Rust and then embed it in the firmware you flash onto your device.

Create a new module for ESP32

To create a new module compatible with the Micro-RDK, follow these steps:

  1. Set up your development environment following the development setup instructions.

  2. Generate a new module skeleton from this template:

    cargo generate --git https://github.com/viamrobotics/micro-rdk.git
    

    Select templates/module when prompted, give the module a name of your choice, and answer any additional prompts.

    The CLI automatically initializes a git repository in the generated module directory.

  3. Navigate into the generated module directory:

    cd <path-to/your-module-directory>
    
  4. Develop the module by defining structs which implement the necessary traits. The required traits are determined by the API you chose to implement.

For example, to implement the sensor API, you need to implement Readings, SensorT<f64> and Status traits.

Example implementation

The following example src/lib.rs file implements the sensor API to return random numbers:


For more examples, see the example module implementation walkthrough.

Test your module

To use your module with your ESP32, follow the Build and flash custom firmware workflow in a separate directory.