Categories
ESP32 ESP8266 (ESP-01/01S) Microcontrollers

Storing Data SPIFFS

Requirements

  • DHT11 Temperature and Humidity
  • USB to UART ESP01 Programmer
  • ESP8266 ESP01/01s (512KB / 1 Mbyte)
  • File System Uploader plug-in installed

Circuity

Code

#include "FS.h"
#include "DHT.h"

#define DHTPIN 2 // the digital pin we are connected to
#define DHTTYPE DHT11 // define type of DHT sensor we are using

DHT dht(DHTPIN, DHTTYPE); // create DHT object

void setup() {
  Serial.begin(115200);
  dht.begin(); // intialize DHT object
  
  // always use this to "mount" the filesystem
  bool ok = SPIFFS.begin();
  if (ok) {
    Serial.println("SPIFFS initialized successfully");
  }
  else{
    Serial.println("SPIFFS intialization error");
  }
  
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);
  //read temperature as Celcius
  float t = dht.readTemperature(); 
  
  // Check if any reads failed and exit early (to try again).
  if (isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  //open log.txt file 
  File f = SPIFFS.open("/log.txt", "a");
  if (!f) {
    Serial.println("file open failed");
  }
  // save temperature reading
  f.print(t);
  f.println("deg C");
  //close file
  f.close();
  delay(8000);
}

Resources

https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html

https://thebigpotatoe.github.io/Effortless-SPIFFS/

https://www.arduino.cc/reference/en/libraries/effortless-spiffs/

Categories
ESP32 ESP8266 (ESP-01/01S) Microcontrollers

Reading Digital Signal (GPIO Pin)

GPIO pin can be used to read values off from sensor devices and monitor sensor data.

Serial console to display the read of the value from GND/3.3V pins of ESP8266

Requirements

  • Breadboard
  • Jumper wires
  • USB cable
  • ESP8266 D1 Wemos Mini
  • CH340 Driver (USB-UART)
  • Arduino IDE (ESP8266 Library / Board : Lolin D1 Mini)

Layout

D1 Wemos Mini (GPIO 5 – D1 and GND)

Arduino IDE Sketch Code

// Setup the GPIO 5 Pin
// D1 Wemos Mini pin GPIO5
 
int inputPin = 5;
int val = 0;

void setup() {
  // Setup the serial console baud speed
  Serial.begin(115200);
  pinMode(inputPin, INPUT);
}

void loop() {
  // Read the value off GPIO 5 Pin
  val = digitalRead(inputPin);

  // Display state of input pin
  Serial.println(val);
  delay(1000);
}
Arduino IDE’s Serial console output (reading from GND pin)

Resource

https://www.wemos.cc/en/latest/d1/d1_mini.html

https://arduino-esp8266.readthedocs.io/en/latest/

Categories
ESP32 ESP8266 (ESP-01/01S) Microcontrollers Security

MAC Address Randomization

Resources

https://source.android.com/devices/tech/connect/wifi-mac-randomization#:~:text=MAC%20randomization%20prevents%20listeners%20from,and%20Wi%2DFi%20RTT%20operations.

Categories
ESP32 Microcontrollers MicroPython

Flash MicroPython Firmware

Download firmware for Generic ESP32 module

https://micropython.org/download/esp32/

Install esptool.py

pip install esptool

Assumed the USB-Serial chip driver has been installed. Check the Operating System platform (Win/MacOS/Linux) port assignment for the attached MCU board via USB port.

On MacOS (Intel) : sudo ls -al /dev/tty.*

Erase the firmware (flash)

esptool.py --port /dev/tty.SLAB_USBtoUART erase_flash

Deploy the new firmware (recent downloaded esp32-xxx-xxx.bin file) to flash address 0x1000

esptool.py --chip esp32 --port /dev/tty.SLAB_USBtoUART write_flash  -z 0x1000 esp32-20180511-v1.9.4.bin

Test MicroPython (REPL)

On MacOS (Intel): screen command

screen /dev/tty.SLAB_USBtoUART 1152000

>>>

Ctrl + a and Ctrl + k and y to kill the terminal session

Resources

https://docs.micropython.org/en/v1.15/esp32/tutorial/intro.html

Categories
ESP32

Setup Arduino IDE for ESP32

URL: “https://dl.espressif.com/dl/package_esp32_index.json” into the “Additional Board Manager URLs” box

In the board manager dialog box, click on the search bar. Then type “ESP32” and hit enter. Now select and click on the install button for “ESP32 by Espressif systems”