Configure an ESP32 Board (viam-micro-server)

To test your board as you configure it, power it on. If you plan to connect hardware to the board’s pins, connect the hardware while it’s powered off. To configure an esp32 board, navigate to the CONFIGURE tab of your machine’s page in the Viam app and select JSON mode.

Copy the following JSON template and paste it into your configuration inside the "components" array:

{
  "name": "<your-board-name>",
  "model": "esp32",
  "type": "board",
  "namespace": "rdk",
  "attributes": {
    "pins": [
      <int>
    ],
    "analogs": [
      {
        "pin": <int>,
        "name": "<your-analog-name>"
      }
    ],
    "digital_interrupts" : [
        {
         "pin": <int>
        }
    ]
  },
  "depends_on": []
}
{
  "name": "board",
  "model": "esp32",
  "type": "board",
  "namespace": "rdk",
  "attributes": {
    "pins": [15, 34],
    "analogs": [
      {
        "pin": "34",
        "name": "sensor"
      }
    ],
    "digital_interrupts": [
      {
        "pin": 4
      }
    ]
  },
  "depends_on": []
}

Edit and fill in the attributes as applicable. Click the Save button in the top right corner of the page.

The following attributes are available for esp32 boards:

NameTypeRequired?Description
analogsarrayOptionalAttributes of any pins that can be used as analog-to-digital converter (ADC) inputs. See configuration info.
i2csarrayOptionalAny Inter-Integrated Circuit (I2C) pins’ bus index and name. See configuration info.
digital_interruptsarrayOptionalAny digital interrupts’ GPIO number. See configuration info.
pinsarrayOptionalThe GPIO number of any GPIO pins you wish to use as input/output with the board API.

Any pin not specified in either "pins" or "digital_interrupts" cannot be interacted with through the board API. Interaction with digital interrupts is only supported with the board API; these digital interrupts cannot be used as software interrupts in driver implementations.

analogs

The following properties are available for analogs:

NameTypeRequired?Description
namestringRequiredYour name for the analog reader.
pinintegerRequiredThe GPIO number of the ADC’s connection pin, wired to the board.

i2cs

The following properties are available for i2cs:

NameTypeRequired?Description
namestringRequiredname of the I2C bus.
busstringRequiredThe index of the I2C bus. Must be either i2c0 or i2c1.
data_pinintegerOptionalThe GPIO number of the data pin. Default: 11.
clock_pinintegerOptionalThe GPIO number of the clock pin. Default: 6.
baudrate_hzintegerOptionalThe baudrate in HZ of this I2C bus.
Default: 1000000
timeout_nsintegerOptionalTimeout period for this I2C bus in nanoseconds.
Default: 0

digital_interrupts

The following properties are available for digital_interrupts:

NameTypeRequired?Description
pinintegerRequiredThe GPIO number of the board’s GPIO pin that you wish to configure the digital interrupt for.

PWM signals on esp32 pins

You can set PWM frequencies with Viam through the GPIOPin API. Refer to the Espressif documentation for valid frequencies and duty resolutions. A configured esp32 board can support a maximum of four different PWM frequencies simultaneously, as the boards only have four available timers.

For example:

PinPWM Frequency (Hz)
122000
253000
265000
326000

At this point, if you want to add another PWM signal, you must do the following:

  1. Set the PWM frequency before the duty cycle.
  2. Set the PWM frequency to one of the above previously set frequencies.

For example, you can set pin 33 to 2000 Hz:

PinPWM Frequency (Hz)
12, 332000
253000
265000
326000

Then, follow these requirements to change the PWM frequencies of a pin:

  1. If no other pins have a signal of the same frequency (for example, pins 25, 26, and 32), you can freely change their PWM frequency.
  2. If one or more pins are sharing the old frequency (for example, pins 12 and 33):
    1. If there are less than 4 active frequencies, you can change the PWM frequency freely because there will be a timer available.
    2. If there are already 4 active frequencies, changing the PWM frequency of the pin will raise an error because there are no timers available. Free a timer by setting the PWM frequencies of all of the pins to 0.

Troubleshooting

If your board is not working as expected, follow these steps:

  1. Check your machine logs on the LOGS tab to check for errors.
  2. Review this board model’s documentation to ensure you have configured all required attributes.
  3. Check that all wires are securely connected.
  4. Click on the TEST panel on the CONFIGURE or CONTROL tab and test if you can use the board there.

If none of these steps work, reach out to us on the Community Discord and we will be happy to help.

Next steps

For more configuration and usage info, see:

Have questions, or want to meet other people working on robots? Join our Community Discord.

If you notice any issues with the documentation, feel free to file an issue or edit this file.