4. Embedded programming

Technical Overview: ESP32-WROOM-32 Module

Overview

The ESP32-WROOM-32 module is a powerful and versatile Wi-Fi and Bluetooth combo module based on the ESP32 SoC (System on a Chip). The module provides reliable and high-performance connectivity and supports a wide range of applications including Internet of Things (IoT), smart home, and wearable devices.

Features

Applications

The ESP32-WROOM-32 module is suitable for a wide range of applications, including:

Development Tools

The ESP32-WROOM-32 module is supported by a wide range of development tools and platforms, including:

Conclusion

The ESP32-WROOM-32 module is a powerful and versatile Wi-Fi and Bluetooth combo module with a wide range of features and applications. Its low power consumption, support for a wide range of interfaces, and easy-to-use development tools make it an ideal choice for IoT and embedded systems projects.

PlattformIO

Introduction

PlatformIO is an open-source ecosystem for IoT development that supports more than 800 microcontrollers and development boards. It provides a unified and user-friendly interface for configuring, building, and uploading code to different microcontroller platforms. PlatformIO includes a powerful and feature-rich development environment that supports multiple programming languages, libraries, and frameworks, as well as integrated debugging tools and a command-line interface for automation and integration with other development workflows.

Setting up the ESP32 with PlatformIO

Here's a step-by-step guide on how to set up the ESP32 with PlatformIO:

  1. Install PlatformIO: You can download and install PlatformIO IDE from their website at https://platformio.org/install. Follow the instructions specific to your operating system to complete the installation process.
  2. Create a new PlatformIO project: Open the PlatformIO IDE and click on "New Project". Enter a name for your project and select "ESP32" as the board type. You can also select a framework if you're planning to use one, such as Arduino or ESP-IDF.
  3. Configure the project settings: PlatformIO will generate a basic project structure with some default files. Open the platformio.ini file and add the following lines to configure the project settings:
                        [env:esp32dev]
                        platform = espressif32
                        board = esp32dev
                        framework = arduino
                    
    These lines set the target environment for the project to the esp32dev board, which is a common ESP32 development board, and set the platform and framework to espressif32 and arduino respectively.
  4. Upload the code: In the PlatformIO IDE, click on the "Upload" button to upload the default code to the board. You can modify the code in the src folder as needed and upload it again to the board.

You can also find more information about using PlatformIO with ESP32 in their documentation at https://docs.platformio.org/en/latest/boards/espressif32/esp32dev.html.

Advantages of PlatformIO over the Arduino IDE

  1. PlatformIO supports a wider range of microcontrollers and development boards than the Arduino IDE, giving you more flexibility when choosing hardware for your projects.
  2. PlatformIO is a more powerful and feature-rich development environment than the Arduino IDE, with advanced features like project management, library management, and multi-platform support.
  3. PlatformIO has a built-in command-line interface (CLI) that makes it easy to automate tasks and integrate it into other development workflows.
  4. PlatformIO provides a powerful project management system that allows you to create and manage complex projects with ease.
  5. PlatformIO includes a built-in library manager that allows you to easily install, manage, and update libraries for your projects.
  6. PlatformIO supports a wide range of microcontroller platforms, including Arduino, ESP-IDF, STM32, and many others.
  7. PlatformIO provides a complete integrated development environment (IDE) that includes a text editor, build tools, debugging tools, and other essential features.
  8. PlatformIO supports continuous integration and deployment (CI/CD), allowing you to automate the process of building, testing, and deploying your code to different environments.
  9. PlatformIO has a large and active community of developers and users who contribute to the development of the platform, provide support to each other, and share their knowledge and experience.

How to make the light intensity of an LED change with a potentiometer and ESP32 on PlatformIO

Here are the steps to change the light intensity of an LED with a potentiometer using ESP32 and PlatformIO and display the values of light intensity and potentiometer on the serial monitor:

  1. Connect the potentiometer and LED to the ESP32: Connect the middle pin of the potentiometer to an analog input pin on the ESP32 (e.g. pin 34). Connect one of the other pins to ground and the other to 3.3V. Connect the anode (positive) leg of the LED to a digital output pin on the ESP32 (e.g. pin 27) with a current-limiting resistor (e.g. 220 ohms) in series. Connect the cathode (negative) leg of the LED to ground.
  2. Set up the code: In your PlatformIO project, open the src/main.cpp file and add the following code:
      
        const int ledPin = 16; // Pin to control the LED
        const int potPin = 34; // Pin to read the potentiometer
        const int ledcChannel = 0; // LEDC channel to use
        const int ledcFreq = 5000; // LEDC frequency in Hz

        void setup() {
        pinMode(ledPin, OUTPUT);
        pinMode(potPin, INPUT);

        // Set up the LEDC module
        ledcSetup(ledcChannel, ledcFreq, 8);
        ledcAttachPin(ledPin, ledcChannel);
        }

        void loop() {
        // Read the voltage from the potentiometer
        int potValue = analogRead(potPin);

        // Map the potentiometer voltage (0-4095) to PWM duty cycle (0-255)
        int pwmDutyCycle = map(potValue, 0, 4095, 0, 255);

        // Set the LED brightness using PWM
        ledcWrite(ledcChannel, pwmDutyCycle);

        // Delay a little bit to make the brightness change visible
        delay(10);
        }

      
    
  1. Upload the code: Connect your ESP32 to your computer and upload the code using the PlatformIO IDE. Once the code is uploaded, open the serial monitor in the PlatformIO IDE (click on the serial monitor icon in the bottom toolbar or go to PlatformIO -> Serial Monitor in the menu bar) to view the potentiometer and brightness values in real-time as you adjust the potentiometer.

After that being done, we should now have a working circuit that changes the LED brightness with the potentiometer using ESP32 and PlatformIO, and displays the potentiometer and brightness values on the serial monitor.

imageA1

Check out our group assignment: Group Assignment