You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
167 lines
2.9 KiB
167 lines
2.9 KiB
5 years ago
|
---
|
||
|
title: ESP32 PlatformIO
|
||
|
description: Microcontroller development project setup / template
|
||
|
date: 2020-05-03
|
||
5 years ago
|
#tags: ["esp32", "project", "platformio", "microcontroller", "programming"]
|
||
5 years ago
|
categories: ["tutorial"]
|
||
|
author: hendrik
|
||
|
license: WTFPL
|
||
|
---
|
||
|
|
||
|
![ESP32 Lora Board](esp-lora-board.jpg)
|
||
|
|
||
|
## Install PlatformIO
|
||
|
|
||
|
```shell
|
||
|
apt install platformio
|
||
|
platformio platform update
|
||
|
```
|
||
|
|
||
|
## Project setup
|
||
|
|
||
|
Choose your development board from the list. You can see all supported boards with the command: `platformio boards espressif32`
|
||
|
|
||
|
Now create your new project:
|
||
|
|
||
|
```shell
|
||
|
cd ~/Projects/esp32/
|
||
|
mkdir new_project
|
||
|
cd new_project
|
||
|
platformio project init --board esp-wrover-kit
|
||
|
```
|
||
|
|
||
|
## Configuration
|
||
|
|
||
|
#### platformio.ini:
|
||
5 years ago
|
```ini {linenos=table}
|
||
5 years ago
|
[env:esp-wrover-kit]
|
||
|
platform = espressif32
|
||
|
board = esp-wrover-kit
|
||
|
framework = arduino
|
||
|
monitor_speed = 115200
|
||
|
|
||
|
#build_flags =
|
||
|
# -DBOARD_HAS_PSRAM
|
||
|
# -mfix-esp32-psram-cache-issue
|
||
|
# -DCONFIG_SPIRAM_CACHE_WORKAROUND
|
||
|
# -DCORE_DEBUG_LEVEL=5
|
||
|
#
|
||
|
#board_build.partitions = huge_app.csv
|
||
|
#
|
||
|
#lib_deps =
|
||
|
# TFT_eSPI
|
||
|
```
|
||
|
|
||
|
## Code
|
||
|
|
||
|
#### src/main.cpp:
|
||
5 years ago
|
```c++ {linenos=table}
|
||
5 years ago
|
/**
|
||
|
* Blink
|
||
|
*
|
||
|
* Turns on an LED on for one second,
|
||
|
* then off for one second, repeatedly.
|
||
|
*/
|
||
5 years ago
|
#include <Arduino.h>
|
||
5 years ago
|
|
||
|
#ifndef LED_BUILTIN
|
||
|
#define LED_BUILTIN 13
|
||
|
#endif
|
||
|
|
||
|
void setup()
|
||
|
{
|
||
|
// initialize LED digital pin as an output.
|
||
|
pinMode(LED_BUILTIN, OUTPUT);
|
||
|
}
|
||
|
|
||
|
void loop()
|
||
|
{
|
||
|
// turn the LED on (HIGH is the voltage level)
|
||
|
digitalWrite(LED_BUILTIN, HIGH);
|
||
|
|
||
|
// wait for a second
|
||
|
delay(1000);
|
||
|
|
||
|
// turn the LED off by making the voltage LOW
|
||
|
digitalWrite(LED_BUILTIN, LOW);
|
||
|
|
||
|
// wait for a second
|
||
|
delay(1000);
|
||
|
}
|
||
|
```
|
||
|
|
||
|
now compile and upload your program
|
||
|
|
||
|
```shell
|
||
|
platformio run
|
||
|
platformio run --target upload
|
||
|
platformio device monitor
|
||
|
```
|
||
|
|
||
|
## SPIFFS
|
||
5 years ago
|
```shell
|
||
|
mkdir data/
|
||
|
```
|
||
|
|
||
|
place your files in the directory `data/`
|
||
5 years ago
|
|
||
|
```shell
|
||
|
platformio run --target uploadfs
|
||
|
```
|
||
|
|
||
|
## Git
|
||
|
|
||
|
#### .gitignore:
|
||
|
```
|
||
|
.pio
|
||
|
```
|
||
|
|
||
|
and push to your project on github or gitlab:
|
||
|
|
||
|
```shell
|
||
|
touch README.md
|
||
|
git init
|
||
|
git commit -m "first commit"
|
||
|
git remote add origin https://gitlab.com/username/new_project.git
|
||
|
git push -u origin master
|
||
|
```
|
||
|
|
||
|
## License
|
||
|
|
||
|
#### LICENSE:
|
||
|
```
|
||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||
|
|
||
|
Version 2, December 2004
|
||
|
|
||
|
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||
|
|
||
|
Everyone is permitted to copy and distribute verbatim or modified copies of
|
||
|
this license document, and changing it is allowed as long as the name is changed.
|
||
|
|
||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||
|
|
||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||
|
|
||
|
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||
|
```
|
||
5 years ago
|
|
||
|
## Project structure
|
||
|
|
||
|
```text {hl_lines=["2-5",7]}
|
||
|
new_project/
|
||
|
├── README.md
|
||
|
├── LICENSE
|
||
|
├── platformio.ini
|
||
|
├── .gitignore
|
||
|
├── src
|
||
|
│ └── main.cpp
|
||
|
├── data
|
||
|
├── include
|
||
|
│ └── README
|
||
|
├── lib
|
||
|
│ └── README
|
||
|
└── test
|
||
|
└── README
|
||
|
```
|