What is embedded system?
Microcontrollers and microprocessors
What is microprocessor?
What is microcontroller??
Tasks
This week has following tasks:
Difference between Microprocessor and microcontroller
Exploring ESP32 Wroom
In this week I explored ESP32 wroom to send data of temperature and humidity to MATLAB Thingspeak.
What is ESP32?
The ESP32 is a cost-effective System on Chip (SoC) microcontroller developed by Espressif Systems, known for creating the popular ESP8266 SoC. It serves as an upgrade to the ESP8266 and is available in single-core and dual-core versions, utilizing Tensilica's 32-bit Xtensa LX6 microprocessor. The ESP32 integrates Wi-Fi and Bluetooth capabilities, similar to the ESP8266. One of its advantages is the inclusion of RF components such as Power Amplifier, Low-Noise Receive Amplifier, Antenna Switch, Filters, and RF Balun, simplifying hardware design by reducing the need for external components.
Specifications of ESP32
Exploring ESP32 and DHT11 for sending data to MATLAB Thingspeak
Exploring ESP32 and DHT11 for sending data to MATLAB Thingspeak involves using the ESP32 microcontroller along with the DHT11 temperature and humidity sensor to collect data. This data is then sent to MATLAB Thingspeak, a platform for collecting, visualizing, and analyzing IoT data. This project combines hardware and software to create a simple IoT application that can be used for monitoring environmental conditions.
How to Stream real-time data to ThingSpeak?
This project is a basic IoT application where temperature data from an ESP-32 microcontroller is sent to the ThingSpeak server. This setup allows users to remotely monitor room temperature from anywhere in the world via the internet. The data transmission is facilitated through the use of ThingSpeak's API. API stands for Application Programming Interface and it is the link between our software application and the website. If we want data from website to use in our application then we need the API.
What is thingspeak?
ThingSpeak is an IoT cloud platform service that enables the visualization of live data streams in the cloud. It allows us to send data from our devices to ThingSpeak, where we can create real-time visualizations of the data.
Circuit Diagram
Procedure
1.Open Arduino IDE software.
2. Go to File -> Preferences -> and paste https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json .This will download ESP32 compatibility with Arduino IDE
3. From library install ThingSpeak by MathWorks.
4. From library install DHT11 by adafruit.
5. From internet, download CP2102 driver and extract from zipped folder and update through device manager (since our ESP32 node has cp2102 compatibility), Arduino IDE to detect ESP32.
6.Select board as ESP WROOM32: Go to Tools Board manager ->ESP32 -> ESP32 WRROM DA Module.
7.In the program, SSID and password are the hotspot device name and password from which Wifi is connected to both the ESP and laptop/mobile.
8. Login/Create account in ThingSpeak (MathWorks), using active internet connection.
9. Create a new channel and name it according to the sensor. Then create fields (e.g. Temperature -field 1 and Humidity-field 2)
10. Write API key is to be taken from ThingSpeak API Keys of the individual and pasted in the program.
11. In ThingSpeak software MATLAB Visualization and select template required for graph and click create (run program and then visuals will start to appear in the private tab).
ARDUINO PROGRAMMING
Compiling and uploading program
ESP32 and PC is connected to wifi
#include <WiFi.h> #include <HTTPClient.h> #include "DHT.h" #define DHTPIN 5 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); const char* ssid = "*******"; const char* password = "********"; // Domain Name with full URL Path for HTTP POST Request const char* serverName = "http://api.thingspeak.com/update"; // write API Key provided by thingspeak String apiKey = "*5*R*0*8A*C4****"; void setup() { Serial.begin(115200); WiFi.begin(ssid, password); dht.begin(); Serial.println("Connecting"); while(WiFi.status() != WL_CONNECTED) { delay(2000); Serial.print("."); } Serial.println(""); Serial.print("Connected to WiFi network with IP Address: "); Serial.println(WiFi.localIP()); } void loop() { if(WiFi.status()== WL_CONNECTED){ WiFiClient client; HTTPClient http; delay(10000); // wait for 10 seconds //float h = dht.readHumidity(); float t = dht.readTemperature(); float h = dht.readHumidity(); if (isnan(t)) { Serial.println(F("Failed to read from DHT sensor!")); return; } // Your Domain name with URL path or IP address with path http.begin(client, serverName); // Specify content-type header http.addHeader("Content-Type", "application/x-www-form-urlencoded"); // Data to send with HTTP POST String httpRequestData = "api_key=" + apiKey + "&field1=" + String(t) + "&field2=" + String(h); // Send HTTP POST request int httpResponseCode = http.POST(httpRequestData); /* // If you need an HTTP request with a content type: application/json, use the following: http.addHeader("Content-Type", "application/json"); // JSON data to send with HTTP POST String httpRequestData = "{\"api_key\":\"" + apiKey + "\",\"field1\":\"" + String(random(40)) + "\"}"; // Send HTTP POST request int httpResponseCode = http.POST(httpRequestData);*/ Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); http.end(); } else { Serial.println("WiFi Disconnected"); } }
Temperature and humidity readings and visualizations
Exploring XIAO-RP2040
I also tried LED blinking of RP2040.I have prepared its PCB in fourth week and then I soldered RP2040 on it.
// LED_BUILTIN in connected to pin 25 of the RP2040 chip. // It controls the on board LED, at the top-left corner. void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop() { digitalWrite(LED_BUILTIN, LOW); delay(1000); digitalWrite(LED_BUILTIN, HIGH); delay(500); }
Exploring ESP32 and ADXL345