PlatformIO Espressif 8266 Platform

repository·develop·Indexed 18 days ago

https://github.com/platformio/platform-espressif8266

Development platform for PlatformIO that enables building, compiling, and uploading code to ESP8266-based Wi-Fi microcontrollers. It supports filesystem image creation (SPIFFS, LittleFS), flash erasing, and configurable upload protocols via esptool.py or OTA. The platform integrates with the PlatformIO Library Dependency Finder (LDF) for automatic private library discovery and provides various Arduino and SDK examples.

Tokens
3K
Snippets
14
Records
17
Agent score
62%

What's inside platformio-platform-espressif8266

  1. Build and upload the arduino-asyncudp example

    develop

    To run the arduino-asyncudp example, you must have PlatformIO Core installed. Follow these steps:

    1. Install PlatformIO Core: Ensure the CLI is available in your environment.
    2. Download the platform: Download the development platform ZIP containing examples from the official repository.
    3. Extract and Navigate: Extract the archive and change your working directory to the specific example folder: platform-espressif8266/examples/arduino-asyncudp.
    4. Build, Upload, or Clean: Use the PlatformIO CLI (pio) to manage the project lifecycle.
    # Change directory to example
    cd platform-espressif8266/examples/arduino-asyncudp
    
    # Build project
    pio run
    
    # Upload firmware
    pio run --target upload
    
    # Clean build files
    pio run --target clean
  2. Build and upload the Arduino Webserver example

    develop

    To run the arduino-webserver example, you must have the PlatformIO Core installed. Follow these steps:

    1. Install PlatformIO Core.
    2. Download the development platform archive containing examples.
    3. Extract the archive.
    4. Navigate to the example directory and use the PlatformIO CLI (pio) to build and upload the firmware.

    Note: If you are using a specific board, use the -e flag to specify the environment (e.g., nodemcuv2).

    # Change directory to example
    $ cd platform-espressif8266/examples/arduino-webserver
    
    # Build project
    $ pio run
    
    # Upload firmware
    $ pio run --target upload
    
    # Build specific environment
    $ pio run -e nodemcuv2
    
    # Upload firmware for the specific environment
    $ pio run -e nodemcuv2 --target upload
    
    # Clean build files
    $ pio run --target clean
  3. Build and upload the arduino-blink example

    develop

    To run the arduino-blink example, you must first have the PlatformIO Core installed and the development platform files downloaded. After extracting the platform archive, navigate to the example directory to build, upload, or clean the project using the PlatformIO CLI.

    # Change directory to example
    cd platform-espressif8266/examples/arduino-blink
    
    # Build project
    pio run
    
    # Upload firmware
    pio run --target upload
    
    # Build specific environment
    pio run -e nodemcuv2
    
    # Upload firmware for the specific environment
    pio run -e nodemcuv2 --target upload
    
    # Clean build files
    pio run --target clean
  4. Build and upload the arduino-wifiscan example

    develop

    To run the arduino-wifiscan example on an Espressif 8266 device, follow these steps:

    1. Install PlatformIO Core: Ensure you have the PlatformIO Core installed on your system.
    2. Download the platform: Download the development platform containing examples from the official repository archive.
    3. Extract: Unzip the downloaded archive.
    4. Navigate and Execute: Open a terminal, navigate to the example directory, and use the PlatformIO CLI to build and upload the firmware.
    # Change directory to example
    cd platform-espressif8266/examples/arduino-wifiscan
    
    # Build project
    pio run
    
    # Upload firmware
    pio run --target upload
    
    # Clean build files
    pio run --target clean
  5. Install and use the Espressif 8266 platform

    develop

    To use the ESP8266 platform in PlatformIO, first install the PlatformIO Core. Then, create a new PlatformIO project and specify the platform in your platformio.ini configuration file. You can choose between the stable release from the registry or the latest development version directly from GitHub.

    # For the stable version
    [env:stable]
    platform = espressif8266
    board = ...
    
    # For the development version
    [env:development]
    platform = https://github.com/platformio/platform-espressif8266.git
    board = ...
  6. How to use header files in an ESP8266 project

    develop

    In ESP8266 projects, header files (ending in .h) are used to store C declarations and macro definitions that need to be shared across multiple source files in the src directory.

    To use a header file, use the C preprocessing directive #include within your source file (e.g., main.c). This allows you to maintain declarations in a single location, ensuring consistency across your project and simplifying updates.

    #include "header.h"
    
    int main (void)
    {
     ...
    }
  7. Build and upload filesystem images

    develop

    The Espressif8266 platform supports building filesystem images (SPIFFS or LittleFS) from the $PROJECT_DATA_DIR directory.

    Available targets:

    • buildfs: Compiles the filesystem image into a .bin file using the configured MKFSTOOL (e.g., mkspiffs).
    • uploadfs: Uploads the filesystem image to the device using esptool.py at the offset defined by FS_START.
    • uploadfsota: Uploads the filesystem image via OTA.

    Supported filesystems: spiffs, littlefs.

    # Build the filesystem image
    pio run -t buildfs
    
    # Upload the filesystem image via serial
    pio run -t uploadfs
  8. Organize project-specific private libraries in the lib directory

    develop

    To create private libraries for your project, place the source code for each library in its own subdirectory within the lib/ folder. PlatformIO will automatically compile these as static libraries and link them into your executable.

    Each library must follow this structure:

    • lib/<library_name>/src/: Contains the source files (e.g., .c, .h).
    • lib/<library_name>/docs/ (optional): Documentation for the library.
    • lib/<library_name>/examples/ (optional): Usage examples.
    • lib/<library_name>/library.json (optional): Configuration for custom build options.

    Example directory structure:

    |--lib
    |  |--Bar
    |  |  |--src
    |  |  |  |- Bar.c
    |  |  |  |- Bar.h
    |  |  |  |- library.json
    |  |--Foo
    |  |  |--src
    |  |  |  |- Foo.c
    |  |  |  |- Foo.h
    |--platformio.ini
    |--src
    |  |- main.c
  9. How to use header files in an Espressif 8266 project

    develop

    In PlatformIO projects for Espressif 8266, header files (typically ending in .h) are used to store C declarations and macro definitions that are shared across multiple source files.

    To use a header file in your project source files (located in the src folder), use the #include C preprocessing directive. This allows you to maintain declarations in a single location, ensuring consistency and reducing errors when making changes.

    #include "header.h"
    
    int main (void)
    {
     ...
    }