Skip to content

akashdip2001/IDE-setup-for-IOT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ArduinoIDE & PlatformIO setup

also this repo has a PlatformIO project


ArduinoIDE

Prefecences

Screenshot (272)




Screenshot (273) Screenshot (275)

Image 1 Image 2

Screenshot (277)


SAMPLE CODE

Here's the simple code for ESP8266 NodeMCU as a Wi-Fi Access Point, hosts a web interface, and toggle the onboard LED (D4 / GPIO2) from mobile browser.


πŸ”§ Hardware Required:

  • ESP8266 NodeMCU
  • Micro USB cable
  • Mobile or laptop with Wi-Fi

βœ… Code: ESP8266 Web Interface as Access Point (LED Control)

#include <ESP8266WiFi.h>

// Set up access point credentials
const char *ssid = "ESP8266-LED";  // Wi-Fi Name
const char *password = "12345678"; // Wi-Fi Password (min 8 chars)

// Set the onboard LED pin
const int ledPin = 2; // D4 on NodeMCU is GPIO2 (active LOW)

// Create server on port 80
WiFiServer server(80);

void setup() {
  // Start serial communication
  Serial.begin(115200);

  // Set LED pin as output
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH); // Turn OFF initially (active LOW)

  // Start the access point
  WiFi.softAP(ssid, password);
  Serial.println("Access Point Started!");
  Serial.print("Connect to: "); Serial.println(ssid);
  Serial.print("IP address: "); Serial.println(WiFi.softAPIP());

  // Start the server
  server.begin();
}

void loop() {
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  Serial.println("Client connected!");
  while (!client.available()) {
    delay(1);
  }

  // Read HTTP request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();

  // LED control logic
  if (request.indexOf("/LED=ON") != -1) {
    digitalWrite(ledPin, LOW); // Turn ON (active LOW)
  }
  if (request.indexOf("/LED=OFF") != -1) {
    digitalWrite(ledPin, HIGH); // Turn OFF
  }

  // Webpage HTML
  String html = "<!DOCTYPE html><html>";
  html += "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">";
  html += "<style>body{font-family:sans-serif;text-align:center;}button{padding:16px;font-size:20px;}</style></head>";
  html += "<body><h2>ESP8266 LED Control</h2>";
  html += "<p><a href=\"/LED=ON\"><button>Turn ON</button></a></p>";
  html += "<p><a href=\"/LED=OFF\"><button>Turn OFF</button></a></p>";
  html += "</body></html>";

  // Send response
  client.print("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
  client.print(html);

  delay(1);
  Serial.println("Client disconnected");
}

πŸ“± How to Use:

  1. Upload the code to your ESP8266 using Arduino IDE.
  2. Open Serial Monitor @ 115200 baud to see debug info.
  3. On your mobile or PC:
    • Go to Wi-Fi settings
    • Connect to ESP8266-LED (password: 12345678)
  4. Open a browser and visit 192.168.4.1
  5. Click "Turn ON" or "Turn OFF" to control the onboard LED.



⭐ Projects ⭐

Screenshot_14-4-2025_163550_www youtube com


for Pro Users

Welcome to PlatformIO β€” it's a powerful extension for Visual Studio Code that offers a modern and more professional workflow for embedded development (like ESP8266). If you are good to using the Arduino IDE, you’ll find some things familiar, and others a bit new but more flexible.


βœ… Step-by-Step Guide: Setup PlatformIO in VS Code (for ESP8266)


🧰 1. Install Visual Studio Code (VS Code)

If you haven't already:


βš™οΈ 2. Install the PlatformIO Extension

  1. Open VS Code.
  2. Go to Extensions (Ctrl + Shift + X).
  3. Search for PlatformIO IDE.
  4. Click Install.

πŸ’‘ This will also install Python if it's not already installed (required by PlatformIO).

Image 1 Image 2

Screenshot 2025-04-15 014729


🌐 3. Create a New Project in PlatformIO

  1. Click on the PlatformIO alien icon πŸ›Έ in the left sidebar.
  2. Click "New Project".
  3. Fill in:
    • Name: ESP8266_LED_Control
    • Board: Search and select NodeMCU 1.0 (ESP-12E Module)
    • Framework: Select Arduino
    • Leave location as default.
  4. Click "Finish".

PlatformIO will now generate a project structure and install the necessary platform files.

Image 1 Image 2


πŸ“ 4. Understand the Project Structure

Here's what PlatformIO creates:

ESP8266_LED_Control/
β”œβ”€β”€ include/       β†’ Header files (.h)
β”œβ”€β”€ lib/           β†’ Custom libraries
β”œβ”€β”€ src/           β†’ Your main code (like Arduino .ino files)
β”‚   └── main.cpp   β†’ Your main code file
β”œβ”€β”€ platformio.ini β†’ Project config file

Screenshot (285)


πŸ“ 5. Write Your Code

Open src/main.cpp and paste your existing code there.

PlatformIO uses .cpp files, so wrap your Arduino code like this:

#include <Arduino.h>
#include <ESP8266WiFi.h>

// Your existing code...

Also, make sure setup() and loop() are present and not inside a class or function.


βš™οΈ 6. Update platformio.ini (Optional but Recommended)

Open platformio.ini and ensure it looks like this:

[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
monitor_speed = 115200

You can add more options later (like libraries, OTA, etc.).


πŸ”Œ 7. Connect & Upload to ESP8266

  1. Plug in your NodeMCU.
  2. Hit "Upload" (checkmark/arrow icon in the bottom toolbar).
  3. PlatformIO will:
    • Compile your code.
    • Upload it to your board.
    • Open the Serial Monitor (if you click the plug icon).

πŸ” 8. Monitor Serial Output

  • To see your Serial.println() outputs:
    • Click the "Monitor" icon (plug symbol), or use shortcut Ctrl + Alt + M.

🧼 9. Common Shortcuts

Task Shortcut / Button
Build Ctrl + Alt + B
Upload Ctrl + Alt + U
Monitor Ctrl + Alt + M
Clean Ctrl + Alt + C

🧠 10. Differences from Arduino IDE (Quick Tips)

Arduino IDE PlatformIO
.ino file .cpp with setup() & loop()
Sketchbook folder Full project structure
Libraries added via Library Manager Use lib_deps in platformio.ini
Serial Monitor Built-in, customizable

Screenshot (286)

code for PlatformIO

#include <Arduino.h>
#include <ESP8266WiFi.h>

// Set up access point credentials
const char *ssid = "ESP8266-LED";  // Wi-Fi Name
const char *password = "12345678"; // Wi-Fi Password (min 8 chars)

// Set the onboard LED pin
const int ledPin = 2; // D4 on NodeMCU is GPIO2 (active LOW)

// Create server on port 80
WiFiServer server(80);

void setup() {
  // Start serial communication
  Serial.begin(115200);

  // Set LED pin as output
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH); // Turn OFF initially (active LOW)

  // Start the access point
  WiFi.softAP(ssid, password);
  Serial.println("Access Point Started!");
  Serial.print("Connect to: "); Serial.println(ssid);
  Serial.print("IP address: "); Serial.println(WiFi.softAPIP());

  // Start the server
  server.begin();
}

void loop() {
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  Serial.println("Client connected!");
  while (!client.available()) {
    delay(1);
  }

  // Read HTTP request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();

  // LED control logic
  if (request.indexOf("/LED=ON") != -1) {
    digitalWrite(ledPin, LOW); // Turn ON (active LOW)
  }
  if (request.indexOf("/LED=OFF") != -1) {
    digitalWrite(ledPin, HIGH); // Turn OFF
  }

  // Webpage HTML
  String html = "<!DOCTYPE html><html>";
  html += "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">";
  html += "<style>body{font-family:sans-serif;text-align:center;}button{padding:16px;font-size:20px;}</style></head>";
  html += "<body><h2>ESP8266 LED Control</h2>";
  html += "<p><a href=\"/LED=ON\"><button>Turn ON</button></a></p>";
  html += "<p><a href=\"/LED=OFF\"><button>Turn OFF</button></a></p>";
  html += "</body></html>";

  // Send response
  client.print("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
  client.print(html);

  delay(1);
  Serial.println("Client disconnected");
}

Screenshot (290) Screenshot (292)

update for ESP 32

see the main code in the src & platformio.ini and I can maintion all changes.

Absolutely! Here's what you need to change when moving your project from ESP8266 to ESP32 (ESP-WROOM-32):


πŸ”§ 1. Change the platformio.ini file

Replace:

[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino

With:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200

πŸ”§ 2. Update GPIO Pin Numbers in Code

If you were using pins like D1, D2, etc. on ESP8266, change them to ESP32 GPIOs.

For example:

βœ… Before (for ESP8266):

#define FRONT_LED D1
#define BACK_LED  D2
#define LEFT_LED  D3
#define RIGHT_LED D4

πŸ” After (for ESP32):

Replace them with real GPIO numbers:

#define FRONT_LED 18
#define BACK_LED  19
#define LEFT_LED  21
#define RIGHT_LED 22

🧠 You can use any GPIOs like 2, 4, 5, 18, 19, 21, 22, 23 β€” just avoid pins like 6–11 (used for flash).


πŸ”§ 3. No Change Needed for setup() and loop()

Your usual Arduino code stays the same:

void setup() {
  pinMode(FRONT_LED, OUTPUT);
  pinMode(BACK_LED, OUTPUT);
  pinMode(LEFT_LED, OUTPUT);
  pinMode(RIGHT_LED, OUTPUT);
}

void loop() {
  digitalWrite(FRONT_LED, HIGH);
  delay(1000);
  digitalWrite(FRONT_LED, LOW);
  delay(1000);
}

complete Updated Code

#include <Arduino.h>
// #include <ESP8266WiFi.h>
#include <WiFi.h> // Use this for ESP32

// Set up access point credentials
const char *ssid = "ESP8266-LED";  // Wi-Fi Name
const char *password = "12345678"; // Wi-Fi Password (min 8 chars)

// Set the onboard LED pin
const int ledPin = 2; // D4 on NodeMCU is GPIO2 (active LOW) & GPIO2 is commonly onboard LED in ESP32 also

// Create server on port 80
WiFiServer server(80);

void setup() {
  // Start serial communication
  Serial.begin(115200);

  // Set LED pin as output
  pinMode(ledPin, OUTPUT);
  // digitalWrite(ledPin, HIGH); // Turn OFF initially (active LOW)
  digitalWrite(ledPin, LOW); // ESP32 onboard LED usually active HIGH

  // Start the access point
  WiFi.softAP(ssid, password);
  Serial.println("Access Point Started!");
  Serial.print("Connect to: "); Serial.println(ssid);
  Serial.print("IP address: "); Serial.println(WiFi.softAPIP());

  // Start the server
  server.begin();
}

void loop() {
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  Serial.println("Client connected!");
  while (!client.available()) {
    delay(1);
  }

  // Read HTTP request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();

  // LED control logic
  if (request.indexOf("/LED=ON") != -1) {
    // digitalWrite(ledPin, LOW); // Turn ON (active LOW) ESP 8266
    digitalWrite(ledPin, HIGH); // Turn ON (active HIGH on ESP32)
  }
  if (request.indexOf("/LED=OFF") != -1) {
    // digitalWrite(ledPin, HIGH); // Turn OFF - 8266
    digitalWrite(ledPin, LOW); // Turn OFF - ESP32
  }

  // Webpage HTML
  String html = "<!DOCTYPE html><html>";
  html += "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">";
  html += "<style>body{font-family:sans-serif;text-align:center;}button{padding:16px;font-size:20px;}</style></head>";
  html += "<body><h2>ESP8266 LED Control</h2>";
  html += "<p><a href=\"/LED=ON\"><button>Turn ON</button></a></p>";
  html += "<p><a href=\"/LED=OFF\"><button>Turn OFF</button></a></p>";
  html += "</body></html>";

  // Send response
  client.print("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
  client.print(html);

  delay(1);
  Serial.println("Client disconnected");
}

Image 1 Image 2

How to see the IP address of ESP-WROOM-32 (Access Point mode) after uploading the code:


πŸ” Steps to View IP Address in PlatformIO Serial Monitor:

  1. Open the Serial Monitor:

    • Click the "plug" icon πŸ”Œ at the bottom bar of VS Code (or go to Terminal > New Terminal and run):
      pio device monitor
      
    • Or use the shortcut: Ctrl + Alt + M (Windows/Linux) or Cmd + Alt + M (Mac).
  2. Wait for Boot Logs:

    • After uploading, the ESP32 reboots and prints messages like:
      Access Point Started!
      Connect to: ESP32-LED
      IP address: 192.168.4.1
      
  3. Connect to Wi-Fi on Phone/Laptop:

    • Go to Wi-Fi settings on your phone/laptop.
    • Connect to the Wi-Fi network: ESP32-LED with password 12345678.
  4. Open Browser:


🧠 Tip:

If the Serial Monitor is not showing any output, make sure:

  • You have Serial.begin(115200); in your code (you do βœ…).
  • monitor_speed = 115200 is set correctly in your platformio.ini.
  • You don’t have multiple monitors open.

Screenshot (295)


βš™οΈπŸ“Œ Upload in GitHub without Login

If you want to push just this one project folder to a different GitHub account/repo (temporarily) using my personal access token, without affecting your existing projects or GitHub account setup in VS Code.


βœ… Steps to Upload This Folder to That Repo (Temporarily)

🐦 1. Open terminal in the project folder

cd path/to/ARDUINO-with-OLED-Display

🐦 2. Set Git user for just that project:

Open the terminal in that project folder and run:

git config user.name "Their Name"
git config user.email "[email protected]"

This overrides your global Git identity only for this repo. So your commits will look like they came from them (or from whoever should be listed as contributor).

🐦 3. Initialize Git (if not already)

git init

🐦 4. Add and commit all files

git add .
git commit -m "Initial commit for OLED project"

🐦 5. Add the remote with token (for one-time push)

Screenshot (328)

Replace <YOUR_TOKEN_HERE> with your actual Personal Access Token:

git remote add origin https://<YOUR_TOKEN_HERE>@github.com/Arkadip2007/ARDUINO-with-OLED-Display.git

Important: Don’t put <> around the token when actually typing.

βœ… Example:

git remote add origin https://[email protected]/Arkadip2007/ARDUINO-with-OLED-Display.git

This way it won’t ask for username/password and uses your token directly.

🐦 6. Set the branch name (if needed)

git branch -M main

πŸš€ 6. Push to GitHub

git push -u origin main

βœ… Optional: Clean up after push (secure)

After you're done, you can remove the remote with token to avoid accidentally leaking it:

git remote set-url origin https://github.com/Arkadip2007/ARDUINO-with-OLED-Display.git

Or just delete the .git folder if this was a one-time thing:

rm -rf .git

About

setup guide for Arduino-IDE & PlatformIO in VS Code

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages