Why is this flapping high and low?

Using a ESP32Cam as a slave to the ESP master to serially send a photo.

I want to wake the ESP32Cam slave from sleeping with the master sending GPIO Pin 12 high.

I have check out the pins that I can used as I am not using a SDcard so 12 or 13 can be used.

My question is it was working for some time but now that I have hardwired the slave/master together I am getting strange results.

I have common gnd, and check the wiring several times.

Took the code back to very basic and simply checking the state which is low as expected. When I tested with the wire to enable esp_sleep_enable_ext0_wakeup(GPIO_PIN_WAKEUP, HIGH); it seems to flap HIGH and LOW. If I touch the Pin 12 it goes high.

Reading here https://github.com/raphaelbs/esp32-cam-ai-thinker/blob/master/docs/esp32cam-pin-notes.md I see it can be a capactive touch pin so does this mean to stop it flapping I need a pull down resistor? Say 10k?

In summary I just need to wake the ESP32Cam remotely via GPIO12.

22:11:04.226 -> pirCAM is LOW
22:11:05.228 -> pirCAM is LOW
22:11:06.246 -> pirCAM is LOW
22:11:07.240 -> pirCAM is LOW
22:11:08.234 -> pirCAM is LOW
22:11:09.236 -> pirCAM is LOW
22:11:10.240 -> pirCAM is LOW
22:11:11.243 -> pirCAM is LOW
22:11:12.245 -> pirCAM is LOW
22:11:13.247 -> pirCAM is LOW
22:11:14.248 -> pirCAM is LOW
22:11:15.251 -> pirCAM is LOW
22:11:16.254 -> pirCAM is LOW
22:11:17.203 -> pirCAM is LOW
22:11:18.207 -> pirCAM is LOW
22:11:19.240 -> pirCAM is HIGH
22:11:20.229 -> pirCAM is HIGH
22:11:21.213 -> pirCAM is HIGH
22:11:22.218 -> pirCAM is HIGH
22:11:23.242 -> pirCAM is LOW
22:11:24.220 -> pirCAM is LOW
#define DEBUG_ESP              // Comment out to deactivate debug console

#ifdef DEBUG_ESP
  #define pDBGln(x) Serial.println(x)
  #define pDBG(x)   Serial.print(x)
#else 
  #define pDBG(...)
  #define pDBGln(...)
#endif

#include "esp_camera.h"
#include "Arduino.h"
#include "soc/soc.h"           // Disable brownout problems
#include "soc/rtc_cntl_reg.h"  // Disable brownout problems
#include "driver/rtc_io.h"
#include "SerialTransfer.h"

#define SIOD_GPIO_NUM     26
#define SIOC_GPIO_NUM     27

// Pin definition for CAMERA_MODEL_AI_THINKER
#define PWDN_GPIO_NUM     32
#define RESET_GPIO_NUM    -1
#define XCLK_GPIO_NUM      0

#define Y9_GPIO_NUM       35
#define Y8_GPIO_NUM       34
#define Y7_GPIO_NUM       39
#define Y6_GPIO_NUM       36
#define Y5_GPIO_NUM       21
#define Y4_GPIO_NUM       19
#define Y3_GPIO_NUM       18
#define Y2_GPIO_NUM        5
#define VSYNC_GPIO_NUM    25
#define HREF_GPIO_NUM     23
#define PCLK_GPIO_NUM     22

#define GPIO_PIN_WAKEUP GPIO_NUM_12
//#define GPIO_PIN_WAKEUP GPIO_NUM_13
int wakeupPinState = LOW;

SerialTransfer myTransfer;
HardwareSerial Comm(1);
struct img_meta_data{
  uint16_t counter;
  uint16_t imSize;
  uint16_t numLoops;
  uint16_t sizeLastLoop;
} ImgMetaData;
const uint16_t PIXELS_PER_PACKET = MAX_PACKET_SIZE - sizeof(ImgMetaData);

void setup(){
  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); // Disable brownout detector
 
  Serial.begin(115200);                     // Define and start serial monitor
  Comm.begin(962100, SERIAL_8N1, 15, 14);    // Define and start Comm serial port
  myTransfer.begin(Comm);
 
  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG;
 
  config.frame_size = FRAMESIZE_SVGA;
  config.jpeg_quality = 12;
  config.fb_count = 1;
 
  // Init Camera
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK){
    Serial.printf("Camera init failed with error 0x%x", err);
    return;
  }

  // Setup wake-up pin
  pinMode(GPIO_PIN_WAKEUP, INPUT);
}

void loop(){
  wakeupPinState = digitalRead(GPIO_PIN_WAKEUP);

  if (wakeupPinState == HIGH) {
    Serial.println("wakeupPinState is HIGH");
    wakeUpCamera();
    delay(60000); // Allow for a single transfer then go to sleep
  } else {
    Serial.println("wakeupPinState is LOW");
    goToSleep();
  }
}

void wakeUpCamera() {
  Serial.println("Camera waking up...");

  // Turns off the ESP32-CAM white on-board LED (flash) connected to GPIO 4
  pinMode(4, OUTPUT); // Flashes the on-board LED
  digitalWrite(4, HIGH);
  delay(100); // Flash on-board LED
  digitalWrite(4, LOW);
  delay(100); // Flash on-board LED
  digitalWrite(4, HIGH);
  delay(100); // Flash on-board LED
  digitalWrite(4, LOW);
  rtc_gpio_hold_en(GPIO_NUM_4); // Deep sleep mode to prevent the pin configuration from changing

  uint16_t startIndex = 0;
  camera_fb_t *fb = NULL;
  // Take Picture with Camera
  fb = esp_camera_fb_get(); 

  ImgMetaData.imSize = fb->len;
  ImgMetaData.numLoops = (fb->len / PIXELS_PER_PACKET) + 1;
  ImgMetaData.sizeLastLoop = fb->len % PIXELS_PER_PACKET;

  for (ImgMetaData.counter = 1; ImgMetaData.counter <= ImgMetaData.numLoops; ImgMetaData.counter++) {
    myTransfer.txObj(ImgMetaData, sizeof(ImgMetaData));
    stuffPixels(fb->buf, startIndex, sizeof(ImgMetaData), PIXELS_PER_PACKET);
    myTransfer.sendData(MAX_PACKET_SIZE);

    pDBGln(F("Sent:"));
    pDBG(F("img.counter: "));      pDBGln((uint16_t)((myTransfer.txBuff[1] << 8) | myTransfer.txBuff[0]));
    pDBG(F("img.imSize: "));       pDBGln((uint16_t)((myTransfer.txBuff[3] << 8) | myTransfer.txBuff[2]));
    pDBG(F("img.numLoops: "));     pDBGln((uint16_t)((myTransfer.txBuff[5] << 8) | myTransfer.txBuff[4]));
    pDBG(F("img.sizeLastLoop: ")); pDBGln((uint16_t)((myTransfer.txBuff[7] << 8) | myTransfer.txBuff[6]));

    startIndex += PIXELS_PER_PACKET;
    delay(100);
  }
  
  esp_camera_fb_return(fb);   // Clear camera memory

  // Onboard RED LED
  pinMode(33, OUTPUT);
  digitalWrite(33, LOW);
  Serial.println("Waiting 60s for serial transfer to finish...");
}

void stuffPixels(const uint8_t *pixelBuff, const uint16_t &bufStartIndex, const uint16_t &txStartIndex, const uint16_t &len) {
  uint16_t txi = txStartIndex;
  for (uint16_t i = bufStartIndex; i < (bufStartIndex + len); i++) {
    myTransfer.txBuff[txi] = pixelBuff[i];
    txi++;
  }
}

void goToSleep() {
  Serial.println("Going to sleep now...");
  esp_sleep_enable_ext0_wakeup(GPIO_PIN_WAKEUP, HIGH);
  esp_deep_sleep_start();
}

It is perfectly normal behaviour if the pin is not connected to anything. Try to searh the forum on "pin floating"

yes, give that a try..
let us know if it still gives you grief..

good luck.. ~q

Thanks port flipping has stopped which is good but has not solved my issue.

Added the 10k to ground and the port goes high when expected.

these two sentences are contradictive

port goes high when expected says : issue solved

but you are writing

You will have to specify very detailed what your issue is.

best regards Stefan

It happens when a pin is floating. In such cases usually we need to pull up or pull down the particular pin in the setup function.

Sorry the port flipping was a issue but hasnt resolved my issue.

I need to be able to wake up a ESP32Cam (slave) via a GPIO pin (12) but the pin was flapping. Add the 10k resistor to ground and no longer flapping.

The ESP32Cam from a deep sleep doesnt seem to always want to wake is where my issue is.

For example it will wake 2-3 times then hang.

17:07:31.406 -> rst:0x10 (RTCWDT_RTC_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
17:07:31.406 -> flash read err, 1000
17:07:31.406 -> ets_main.c 371 
17:07:31.735 -> ets Jun  8 2016 00:22:57
17:07:31.735 -> 
17:07:31.735 -> rst:0x10 (RTCWDT_RTC_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
17:07:31.735 -> flash read err, 1000
17:07:31.735 -> ets_main.c 371 
17:07:32.155 -> ets Jun  8 2016 00:22:57
17:07:32.155 -> 
17:07:32.155 -> rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
17:07:32.155 -> configsip: 0, SPIWP:0xee
17:07:32.155 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
17:07:32.155 -> mode:DIO, clock div:1
17:07:32.155 -> load:0x3fff0018,len:4
17:07:32.155 -> load:0x3fff001c,len:1216
17:07:32.155 -> ho 0 tail 12 room 4
17:07:32.155 -> load:0x40078000,len:10944
17:07:32.155 -> load:0x40080400,len:6388
17:07:32.155 -> entry 0x400806b4
17:07:33.755 -> 
17:07:35.159 -> ......
17:07:37.693 -> WiFi connected

In summary I just need to be able to wake from deep sleep the ESP32Cam pin 12.

My question that I need to understand is how to wake the slave from a master when on two different power sources with a common ground.

Below is when it works

16:42:47.795 -> entry 0x400806b4
16:42:49.087 -> Going to sleep now...
16:42:49.087 -> WAKEUP Pin is LOW
16:44:04.722 -> ets Jun  8 2016 00:22:57
16:44:04.722 -> 
16:44:04.722 -> rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
16:44:04.722 -> configsip: 0, SPIWP:0xee
16:44:04.722 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
16:44:04.722 -> mode:DIO, clock div:1
16:44:04.722 -> load:0x3fff0018,len:4
16:44:04.722 -> load:0x3fff001c,len:1216
16:44:04.722 -> ho 0 tail 12 room 4
16:44:04.722 -> load:0x40078000,len:10944
16:44:04.722 -> load:0x40080400,len:6388
16:44:04.722 -> entry 0x400806b4
16:44:05.988 -> Camera waking Up: WAKEUP Pin is HIGH
16:44:06.342 -> Sent:
16:44:06.342 -> img.counter: 1
16:44:06.342 -> img.imSize: 27153
16:44:06.342 -> img.numLoops: 111
16:44:06.342 -> img.sizeLastLoop: 93
16:44:06.443 -> Sent:
16:44:06.443 -> img.counter: 2


random nerd tutorial says about IO-pin 12
boot fails if pulled high, strapping pin
image

I think waking up from deep-sleep is the same as a "cold" boot from power-on

So try a different IO-pin

best regards Stefan

Thanks, funny how it makes sense now. I wrote the original code after the strapping a 10k resistor between GPIO12 to ground as it looked like it was flipping.

What I was seeing was the master ESP not booting or sometimes the code would work and the slave would wake from sleep send the image and master then uploads. Try it again different result guessing due to the GPIO12 going high or low.

The ESP32Cam has a limited number of pins you can use for remote wake up which 12 or 13 presented the same result.

In short it now works but this was my cause GPIO 12 (must be LOW during boot). Again funny that I never saw this issue until I hard wired the ESP to then box.

GPIO12 - HS2_DATA2

  • ESP32_S datasheet reference: MTDI
  • Hint: use the SD-Card 1bit mode trick described on GPIO4 to use this pin!
  • used as strapping pin - ESP32_S datasheet, default:pull-down selects voltage (3.3v:0, 1.8v:1)
  • Supports Capactive Sensing T5 (see ESP32_S datasheet section 4.1.5 "Touch Sensor")
  • JTAG, ADC2_CH5- 12bit SAR ADC
  • Signal HSPIQ - Parallel QSPI
  • Signal: EMAC_TXD3 - Ethernet MAC MII/RII interface
  • also RTC_GPIO15
  • MTDI (GPIO12) is used as a bootstrapping pin to select the output voltage of an internal regulator (VDD_SDIO) which powers the flash chip.
  • when connected as SDA (for I2C) causes "RTCWDT_RTC_REST"exception ets_main.c 371 at boot due to flash voltage not being set properly.
  • To resolve: it is (Recommended) by EspressIf to Burn the flash voltage selection eFuses. This will permanently configure the internal regulator’s output voltage to 3.3 V, and GPIO12 will not be used as a bootstrapping pin. After that, connect a pull-up resistor to GPIO12

Also from this change I had a issue where after uploading the code I would almost every time see a CRC error between the ESP slave and master, assuming that the slave was awake when the CRC didnt add up. Hoping this other issue is resolved as well.

Revised setup to use GPIO 13 due to the boot issue, now it seems obvious where I was going wrong.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.