|
|
|
|
|
# Introduction to Arduino and C++
|
|
|
|
|
|
The microcontrollers used during this summerschool are ESP32. They can be programmed in the same way as an Arduino UNO, and other common microcontrollers in the maker scene.
|
|
|
|
|
|
You can use the Arduino IDE or VisualStudio Code with the PlatformIO plugin to program them. The Arduino IDE is a user-friendly programming environment that is widely used. In this summerschool, we will use VisualStudio Code with the PlatformIO plugin.
|
|
|
|
|
|
***
|
|
|
|
|
|
# Installing VSCode & PlatformIO plugin
|
|
|
|
|
|
You can download Visual Studio Code for common operating systems here: https://code.visualstudio.com/download
|
|
|
|
|
|
Open VSCode and install the PlatformIO IDE extension.
|
|
|
|
|
|

|
|
|
|
|
|
***
|
|
|
|
|
|
## Creating a Project
|
|
|
|
|
|
In PlatformIO, select **Create project** in the left sidebar.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Choose an appropriate name for your project, select **ESP32 Dev Module** as the board, and **Arduino** as the framework.
|
|
|
|
|
|

|
|
|
|
|
|
***
|
|
|
|
|
|
## PIO Overview
|
|
|
|
|
|

|
|
|
|
|
|
After the project is created, you will land on this page. This is the programming environment where you will work. On the left, you see the folder structure that PlatformIO sets up.
|
|
|
Write your code in the `main.cpp` file located in the `src` folder.
|
|
|
|
|
|
The `platform.ini` file contains the project and microcontroller configuration. Make sure the file looks like this:
|
|
|
|
|
|
```ini
|
|
|
[env:esp32]
|
|
|
platform = espressif32
|
|
|
board = esp32dev
|
|
|
framework = arduino
|
|
|
monitor_speed = 115200 //for the Serial Monitor
|
|
|
```
|
|
|
|
|
|
In the `main.cpp` file, you will find example code that you will recognize from the [Introduction to Arduino](https://i40.fh-aachen.de/intranet/materials/additional/arduino/index.html).
|
|
|
|
|
|
:warning: **If the error message "upload Port not found" appears, the drivers for the ESP are likely missing.**
|
|
|
|
|
|
You can download the drivers from this [link](https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers?tab=downloads): CP210x Universal Windows Driver.
|
|
|
|
|
|
The folder must then be **unzipped**.
|
|
|
|
|
|
The silibser file must be installed with a right-click (Windows).
|
|
|
|
|
|
## Upload Code to the ESP
|
|
|
|
|
|
- In VSCode choose the button **build&upload** in the lower left corner of the IDE.
|
|
|
|
|
|
<img src="images/pio_upload.png" width = "500">
|
|
|
|
|
|
- If the compilation of and the upload of the code to the ESP has been successfull, this message will appear:
|
|
|
|
|
|
<img src="images/pio_upload_success.png" width = "600">
|
|
|
|
|
|
***
|
|
|
|
|
|
## :books: ESP Test
|
|
|
|
|
|
:bulb: If you have access to an ESP32, you can realize this task. If not, no worries, we will provide you with the needed hardware during the summerschool.
|
|
|
|
|
|
To check that the ESP and Platform IO are working, a simple Hello World program will be written.
|
|
|
|
|
|
- Open the `main.cpp` file and delete its contents.
|
|
|
- Copy the following code into the `main.cpp` file.
|
|
|
|
|
|
```cpp
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
void setup(){
|
|
|
Serial.begin(115200);
|
|
|
}
|
|
|
|
|
|
void loop(){
|
|
|
|
|
|
// Output Hello World via Serial
|
|
|
|
|
|
}
|
|
|
```
|
|
|
|
|
|
- With the command `Serial.println("YOUR TEXT")`, you can output text via the serial interface, such as USB.
|
|
|
- Add the line `Serial.println("ESP is alive");` to the loop() function.
|
|
|
- Add a `delay(1000)` underneath it.
|
|
|
- Connect the ESP32 to your computer via USB.
|
|
|
- Upload the code to the ESP32. To do this, select the **Upload** button in the lower left corner of PlatformIO.
|
|
|
- After the upload, open the `Serial Port Monitor` (symbol of a plug).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Back to Self-Learning](/Documentation/Self-Learn/README.md) |