0

$USD

$USD
TUTORIALS ESP32

FireBeetle ESP32 Tutorial: Blinking the on board LED

DFRobot Apr 26 2018 3369

The objective of this post is to explain how to make the DFRobot’s FireBeetle ESP32 board built in LED blink.
 

Introduction

The objective of this FireBeetle ESP32 Tutorial is to explain how to make the DFRobot’s FireBeetle ESP32 board built in LED blink. You can learn more about the FireBeetle ESP32 board on this previous tutorial.
This ESP32 board has a built in LED on pin D9 [1], which we will control using a very simple Arduino program. Please consult this previous post if you haven’t yet enabled the ESP32 support on the Arduino IDE.

The code

The code for this tutorial will be very simple, since it will be kind of a “Hello World” program using the hardware. So we will be basically using the Arduino digitalWrite function, which allows us to control if a digital pin is in a HIGH or LOW state.

Since the pin we are going to control is attached to a LED, then the LED will be on and off as we change the state of the digital pin.
As we stated before, the on board LED is connected to pin D9. Note however that these board pin numbers don’t directly map to the ESP32’s digital pins. So, in reality, pin D9 of the FireBeetle board corresponds to pin 2 of the ESP32 microcontroller.

Nevertheless, an interesting feature of the ESP32 support for the Arduino IDE is that there are some built in constants that we can use to abstract knowing the mappings between different boards and the ESP32 microcontroller. You can check here the source files with the configurations for multiple boards.

So, one of the constants defined is the LED_BUILTIN, which has the value of the on board LED for the board we are using. Naturally, this will only work for boards that are configured in the environment, which is the case of the FireBeetle ESP32.

As for the code, we start by declaring the operating mode of our pin in the setup function. to do so, we use the pinMode function, which receives as arguments the number of the pin we want to configure and the mode.

As stated before, we will pass as first argument the constant LED_BUILTIN and as second OUTPUT, which indicates that the pin will operate in output mode. You can read more about the constants for operating modes that can be passed to the function here.

Then, in the main loop function, we will turn the digital pin on and off by calling the previously mentioned digitalWrite function. This function will receive as input the pin number and the value we want to set.

Again, for the pin number we will use the LED_BUILTIN, and as value we will alternate between HIGH and LOW, so we get the desired blinking effect.

Between each call to the digitalWrite function we will perform a small delay, so the blinking is perceptible to us. To do so, we just need to call the delay function, which receives as input a number of milliseconds to delay. To convert from milliseconds to seconds we just need to multiply the value by 1000.

You can check the final code bellow. I’m using a delay of 2 seconds (2000 milliseconds), but you can change both of the delays to control how much time the LED is on and off.

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}
 
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(2000);
}

Testing the code

To test the code, we need to have the FireBeetle ESP32 board selected on the Tools menu, on the Board entry of the Arduino IDE. Then, we just need to hit the upload button and the code should be compiled and uploaded. You can check in the video bellow the expected result.

Video Link