Sunday, March 5, 2023

How I discovered the ESP32 LOLIN C3 Pico and used it to make HTTP requests

 I have always been interested in IoT devices and how they can connect to the internet and communicate with each other. One day, I stumbled upon a website that introduced me to the ESP32 LOLIN C3 Pico, a mini wifi & Bluetooth5 (LE) board based on ESP32-C3FH4, a RISC-V single-core CPU.





I was amazed by its small form factor, which is only 25.4 x 17.8 mm, and its ability to use a lipo battery with 500mA charging. It also has 12 IO pins, 1 WS2812 RGB LED, 1 LOLIN I2C port, and supports ADC, I2C, SPI, UART protocols. It is compatible with MicroPython, Arduino, CircuitPython and ESP-IDF, which means I can program it using different languages and frameworks.

I decided to buy one online and try it out for myself. After receiving it, I followed the instructions on how to install Arduino IDE on my computer and add the ESP32-C3 board support package. Then I wrote some code to connect it to my wifi network and make HTTP requests to a remote server. The code was simple and easy to understand.

I uploaded the code to the board using Arduino IDE and watched the output on the serial monitor. It worked! The board successfully made an HTTP request and printed the response from the server.

I was very happy with my discovery of the ESP32 LOLIN C3 Pico. It is a powerful and versatile board that can be used for many IoT projects. I plan to use it for more applications in the future, such as making an MQTT device or a smart home button.



#include <WiFi.h>
#include <HTTPClient.h>

// Wifi credentials
const char* ssid = "SSID";
const char* password = "PASSWORD";

void setup() {
  // Initialize serial monitor
  Serial.begin(115200);

  // Connect to wifi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  
  // Make HTTP request
  HTTPClient http;
  http.begin("http://example.com");
  int httpCode = http.GET();
  
  // Print response
  if (httpCode > 0) {
    String payload = http.getString();
    Serial.println(payload);
  }
  
  // End connection
  http.end();
}

void loop() {
}        

No comments:

Post a Comment