h3ndrik.de
  • Blog
  • Projekte
  • Schnipsel
  • Rezepte
  • Über

blog/snippets/platformio



ESP32 Lora Board

Install PlatformIO


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:

cd ~/Projects/esp32/
mkdir new_project
cd new_project
platformio project init --board esp-wrover-kit


Configuration


platformio.ini:

[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:

/**
* Blink
*
* Turns on an LED on for one second,
* then off for one second, repeatedly.
*/
#include <Arduino.h>
#include <WiFi.h>

#ifndef LED_BUILTIN
#define LED_BUILTIN 5
#endif

unsigned long previousMillis = 0;  // will store last time LED was updated
const long interval = 1000;  // interval at which to blink (milliseconds)
int ledState = LOW;  // ledState used to save state of the LED

void setup()
{
  // initialize serial
  Serial.begin(115200);
  // initialize LED digital pin as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  // connect to WiFi
  Serial.print("Connecting to WiFi ..");
  WiFi.begin("ssid", "password");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(500);
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop()
{
  // get current time
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }
    // set the LED with the ledState of the variable:
    digitalWrite(LED_BUILTIN, ledState);
  }
}


now compile and upload your program

platformio run
platformio run --target upload
platformio device monitor


SPIFFS

mkdir data/


place your files in the directory data/

platformio run --target uploadfs


Git


.gitignore:

.pio


and push to your project on github or gitlab:

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.


Project structure


new_project/
├── README.md
├── LICENSE
├── platformio.ini
├── .gitignore
├── src
│   └── main.cpp
├── data
├── include
│   └── README
├── lib
│   └── README
└── test
    └── README

© 2024 h3ndrik Recent Changes