RobotLabs
  • Welcome
  • ESP32
    • PlatformIO
      • 1.1 Arduino Basics
      • 1.2 Install PlatformIO
      • 2.1 GPIO - LED Blink
      • 2.2 GPIO - LED Multi
      • 2.3 GPIO - LED Button
      • 3.1 PWM - LED Fade
      • 3.2 ADC - Analog Input
      • 4.1 IIC - OLED
    • MicroPython
    • ESP32 Projects
  • ROS
    • ROS2 Jazzy
      • 1.1 Install ROS 2 Jazzy
      • 1.2 Install VS Code
      • 1.3 Save ROS code on GitHub
      • 2.1 Create a Mobile Robot with URDF and Visualize it
      • 2.3 Create Launch Files to Display the URDF in RViz
      • 2.4 Simulation with Gazebo
      • 2.5 Gazebo sensors
      • 2.6 Sensor fusion and SLAM
    • MoveIt2
      • Moveit 2 joint position control with keyboard
      • Moveit2 joint velocity control for Panda robot arm
    • Perception
      • PCL-ROS
  • FOC
    • SimpleFOC
      • Install simpleFOC Lib
  • Template
    • Markdown
    • Interactive blocks
    • OpenAPI
    • Integrations
Powered by GitBook
On this page
  • What is Arduino?
  • Commonly Used Arduino Functions
  • Example program for ESP32 using Arduino IDE
  1. ESP32
  2. PlatformIO

1.1 Arduino Basics

PreviousPlatformIONext1.2 Install PlatformIO

Last updated 5 months ago

What is Arduino?

Arduino is an open-source electronics platform based on easy-to-use hardware and software. It takes the messy details of microcontroller programming and wrap it up in an easy-to-use package. Arduino framework also simplifies the process of working with microcontrollers with build-in libraries.

The language is based on C and can be expanded through C++ libraries.

Commonly Used Arduino Functions

These functions are included with Arduino IDE to be used with the Arduino environment.

Function
What it does

pinMode(pin,mode)

Sets a pin as an input or output

digitalWrite(pin, value)

Sets a digital output pin to HIGH or LOW

digitalRead(pin)

Reads a digital input pin as HIGH or LOW

analogWrite(pin, value)

Sets an analog output pin to a value 0-1023

analogRead(pin)

Reads an analog output pin as a value 0-1023

delay(milliseconds)

Pauses the program for a certain amount of time

Serial.begin(value)

Begins the Serial Monitor with a baud rate of value

Serial.print(value)

Prints the value (variable) to the Serial Monitor.

Example program for ESP32 using Arduino IDE

First, connect ESP32 Development Kit to PC and setup Arduino IDE for ESP32.

Setup ESP32 Add-on in Arduino IDE

To install the ESP32 board in your Arduino IDE, please install Arduino IDE first and then follow the next instructions:

1. In your Arduino IDE 2, go to File > Preferences.

2. Copy and paste the following line to the Additional Boards Manager URLs field.

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

Note: if you already have the ESP8266 boards URL, you can separate the URLs with a comma, as follows:

http://arduino.esp8266.com/stable/package_esp8266com_index.json, https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

3. Open the Boards Manager. You can go to Tools > Board > Boards Manager… or you can simply click the Boards Manager icon in the left-side corner.

4. Search for ESP32 and press the install button for esp32 by Espressif Systems version 3.X.

That’s it. It should be installed after a few seconds.

5. Uploading the Sketch

Select your board before uploading the code. On the top drop-down menu, click on “Select other board and port…“

A new window, as shown below, will open. Search for your ESP32 board model.

Select the ESP32 board model you’re using, and the COM port. Click OK when you’re done.

Now, you just need to click on the Upload button to upload a sketch to your ESP32.

After a few seconds, the upload should be complete.

Note: some ESP32 development boards don’t go into flashing/uploading mode automatically when uploading a new code and you’ll see a lot of dots on the debugging window followed by an error message. If that’s the case, you need to press the ESP32 BOOT button when you start seeing the dots on the debugging window.

6. Serial Monitor

You can click on the Serial Monitor icon to open the Serial Monitor tab. Make sure you select the 115200 baud rate.

That’s it! You’ve installed the ESP32 Boards successfully in Arduino IDE 2.

Then, write a simple sketch for serial communication print in Arduino IDE as follows.

void setup()
{
	Serial.begin(9600);  /* initialise serial communication */
}

void loop()
{
	Serial.println("RobotLabs"); /* print Electronic Wings at new line per second */
	delay(1000);
}

Upload the code using the upload button.

Note: Before uploading the code make sure the ESP32 board is in boot mode, to enter in boot mode press the boot button then press the reset button then release the reset button and then release the boot button, your board will go in boot mode.

ESP32 Boot and Reset Buttons
https://docs.arduino.cc/language-reference/
Logo