Saturday, September 5, 2020

Program ESP32-CAM using FTDI adapter


The AI-Thinker ESP32-CAM support OV2640 and OV7670 camera module, my unit come with OS2640.


With ESP32-S module.

This video show how to program AI-Thinker ESP32-CAM in Arduino IDE (with ESP32 Core), using FTDI adapter. 

It have no USB interface on board, and also no button for downloading firmware. So I have to use a FTDI adapter, and a wire to program it.

The FTDI adapter have option to select 3V3 or 5V for VCC. Somebody suggest using 3V3, somebody else suggest 5V. In my case, 5V seem more stable, so I select option of 5V, and connect its VCC pin to ESP32's 5V pin. FTDI's GND to ESP32's GND.

To program ESP32-CAM, using a wire to short circuit between ESP32's GPIO0 and GND.

ESP32's UOT to FTDI RX.

ESP32's UOR to FTDI TX.

Make sure ESP32 is installed in Arduino IDE. To setup ESP32 on Arduino IDE, refer Install ESP32/ESP8266 to Arduino IDE on Ubuntu 20.04, with setup Pythton & serial.

Select board of AI Thinker ESP32-CAM.


Select the USB port connected to your ESP32-CAM.

Open Example > ESP32 > Camera > CameraWebServer


Modify the code:
Select camera model of CAMERA_MODEL_AI_THINKER,
and change ssid and password for your WiFi network. 


Save as another new file. Verify and Upload to ESP32.

After uploaded,
Un-plug USB from FTDI adapter (power-off).
Remove the wire between GPIO0 and GND.
Re-plug USB to FTDI adapter (power-on), to run the ESP32-CAM.

Open Arduino IDE's Serial Monitor and set Baud Rate to 115200.
After ESP32-CAM connect to WiFi network, mark down the IP address.

Use another device, PC, phone or table..., connect to the same WiFi network.
Open browser to visit the IP shown in Serial Monitor.


Reference:
~ AI-Thinker's ESP32-CAM page (in Chinese)



Remark:

If you run the example fail with error:
[E][camera.c:1113] camera_probe(): Detected camera not supported.
[E][camera.c:1379] esp_camera_init(): Camera probe failed with error 0x20004



Most likely it is caused by inn-correct camera model select. Try to select other camera model. It is CAMERA_MODEL_AI_THINKER for my model.





Monday, August 24, 2020

millis() overflow? BlinkWithoutDelay question?

 Normal if we want to run some code in fixed interval, we will use the following pattern:

void loop() {
	// check if the fixed interval reached
	unsigned long currentMillis = millis();
	if (currentMillis - previousMillis >= interval) {
		//do something in fixed interval
		//...
		
		
	}
}

It's a general practice as show in Arduino BlinkWithoutDelay example.

Where millis() returns the number of milliseconds passed since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days.

So, what will happen if it overflow? Will it be a bug in the statement (currentMillis - previousMillis >= interval)?
The answer is NO.

Lets try the following example, run on Uno.
void setup() {
  Serial.begin(9600);
  while (!Serial) {
  }     // wait for serial port to connect.

  unsigned long i =0;
  unsigned long j = i-1;
  unsigned long k = j+1000;
  
  Serial.print("i = ");
  Serial.println(i);
  Serial.print("j = ");
  Serial.println(j);
  Serial.print("k = ");
  Serial.println(k);

  Serial.print("(k > j) : ");
  Serial.println((k > j) ? "true" : "false");

  Serial.print("k-j : ");
  Serial.println(k-j);
  
  Serial.print("((k-j) >= 1000) : ");
  Serial.println(((k-j) >= 1000) ? "true" : "false");
   
}

void loop() {
  // put your main code here, to run repeatedly:

}

Sunday, August 16, 2020

NodeMCU (ESP8266) + 1.44" 128x128 TFT with ST7735 SPI driver (KMR1441_SPI V2)





This video show how to driver 1.44" 128x128 TFT with ST7735 SPI driver (KMR1441_SPI V2) with NodeMCU (ESP8266) using ssd1306 library. Using Arduino IDE.

- In Arduino IDE, open library manager, search ST7735, and install ssd1306 library.

- Open Example > ssd1306 > demos > st7735_demo

- Connect ESP8266 to LCD
ESP8266 LCD
===================
3V3 VCC
GND GND
D1 A0 (D/C)
D2 CS (CS)
RX RESET (RES)
D7 SDA (DIN)
D5 SCK (CLK)
LED (Open in my test)