schoolpost/BlueMagic32

ESP32 Boot Loop and Not Connecting to Camera

Opened this issue · 0 comments

I have recently gotten a BMPCC4K and I have ESP32 modules. I found your library and though it was a great idea. However, when I try even just to implement a simple record toggle, the ESP32 doesn't even connect or attempt to connect to the camera. The board also decides to keep rebooting and throws errors. It just reboots and doesn't ask for a pin. I have the ESP32 board library at version 1.0.5. I have found no other way to fix it other than to try and code something from scratch (and I barely know anything about C or C++). Is there a way someone could help? Thanks.

Serial Monitor Output:
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4
Serial connection established
Interrupt Attached To Rotary Pins
Display powered and recognized
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x400931eb PS : 0x00060b33 A0 : 0x800926bf A1 : 0x3ffbd040
A2 : 0x3ffba4a0 A3 : 0x3ffbd1c4 A4 : 0x00000001 A5 : 0x00000001
A6 : 0x00060b23 A7 : 0x00000000 A8 : 0x00000000 A9 : 0x3ffba4a0
A10 : 0x3ffba4a0 A11 : 0x00060023 A12 : 0x00060021 A13 : 0x00000020
A14 : 0x00000020 A15 : 0x00000000 SAR : 0x00000000 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000004 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0x00000000

ELF file SHA256: 0000000000000000

Backtrace: 0x400931eb:0x3ffbd040 0x400926bc:0x3ffbd060 0x40090fe7:0x3ffbd080 0x40091065:0x3ffbd0a0 0x40092d32:0x3ffbd0c0 0x40092e0f:0x3ffbd100 0x40090886:0x3ffbd130

Rebooting...

Code For ESP32:

#include <BlueMagic32.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// Define screen constants
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// Initialize camera data variables
bool recording;
int shutter;
int FrameRate;
int ISO;
int WB;
int resolutionX;
int resolutionY;

String recordingState;
String shutterAngle;
String FPS;
String currentIso;
String currentWB;
String Resolution1;
String Resolution2;
String FinalRes;

// Initialize rotary encoder variables
const int rotaryClock = 11;
const int rotaryData = 12;
const int rotarySwitch = 13;
int rotaryCounter = 0;
int currentStateCLK;
int lastStateCLK;
unsigned long lastButtonPress = 0;

// Initialize setup of screen and BMD connection
void setup() {

// Set pinMode of rotary encoder pins and get initial state of rotary clock
pinMode(rotaryClock, INPUT);
pinMode(rotaryData, INPUT);
pinMode(rotarySwitch, INPUT_PULLUP);
lastStateCLK = digitalRead(rotaryClock);

// Begin serial connection
Serial.begin(115200);
Serial.println("Serial connection established");

// Attach interrupt to pins
attachInterrupt(rotaryClock, getRotary, CHANGE);
attachInterrupt(rotaryData, getRotary, CHANGE);
attachInterrupt(rotarySwitch, cursorSelect, LOW);
Serial.println("Interrupt Attached To Rotary Pins");

// Get proper display power and throw error if it doesn't. Also double check address
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
Serial.println("Display powered and recognized");
delay(2000);

// Display 'logo' on OLED
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,25);
display.cp437(true); // Use full 256 char 'Code Page 437' font
display.println("BMPCC 4K Remote");
display.display();
delay(1500);
display.clearDisplay();
display.display();
Serial.println("OLED Initialization Complete");

// Setup BLE connection with BMPCC
BMDConnection.begin("BlueMagic32");
Serial.println("Starting BLE Service");
BMDControl = BMDConnection.connect();
Serial.println("BMD Connection Setup");

pushCameraUpdate();

Serial.println("Finished Setup");

}

void loop() {
pushCameraUpdate();
cursorLocation();
}

void updateCameraStats() {
if (BMDConnection.available()) {

// Get recording state
recording = BMDControl->isRecording();

// Get the current shutter angle
shutter = BMDControl->getShutter();

// Get current frame rate
FrameRate =  BMDControl->getFrameRate();

// Get current iso
ISO = BMDControl->getIso();

// Get current whitebalance
WB = BMDControl->getWhiteBalance();

// Get resolution
resolutionX = BMDControl->getFrameWidth();
resolutionY = BMDControl->getFrameHeight();

}
}

void concatStats() {
// Concatenate string with camera value
recordingState = "Recording: " + recording;
shutterAngle = "Angle: " + shutter;
FPS = "FPS: " + FrameRate;
currentIso = "ISO: " + ISO;
currentWB = "WB: " + WB;
Resolution1 = "Res: " + resolutionX;
Resolution2 = "x" + resolutionY;
FinalRes = Resolution1 + Resolution2;
}

void printStats() {
// Print current settings
display.clearDisplay();
display.setCursor(0,0);
display.println(recordingState);
display.println(shutterAngle);
display.println(FPS);
display.println(currentIso);
display.println(currentWB);
display.println(FinalRes);
display.display();
}

void pushCameraUpdate() {
updateCameraStats();
concatStats();
printStats();
}

void getRotary() {

// Read the current state of the clock
currentStateCLK = digitalRead(rotaryClock);

// If last and current state of CLK are different, then pulse occurred
// React to only 1 state change to avoid double count
if (currentStateCLK != lastStateCLK && currentStateCLK == 1) {

// If the DT state is different than the CLK state then
// the encoder is rotating CCW so decrement
if (digitalRead(rotaryData) != currentStateCLK) {
  rotaryCounter --;
  if (rotaryCounter < 0) {
    rotaryCounter = 0;
  }
} else {
  // Encoder is rotating CW so increment
  rotaryCounter ++;
  if (rotaryCounter > 4) {
    rotaryCounter == 0;
  }
}

}

// Remeber last CLK state
lastStateCLK = currentStateCLK;

// Put in a slight delay to help debounce the reading
delay(10);
}

void cursorLocation() {
if (rotaryCounter == 0) {
printStats();
display.setCursor(100, 0);
display.print("<");
display.display();
} else if (rotaryCounter == 1) {
printStats();
display.setCursor(100, 10);
display.print("<");
display.display();
} else if (rotaryCounter == 2) {
printStats();
display.setCursor(100, 20);
display.print("<");
display.display();
} else if (rotaryCounter == 3) {
printStats();
display.setCursor(100, 30);
display.print("<");
display.display();
} else if (rotaryCounter == 4) {
printStats();
display.setCursor(100, 40);
display.print("<");
display.display();
}
}

void cursorSelect() {

// Record toggle
if (rotaryCounter == 0) {
if (recording == false) {
BMDControl->record(true);
} else {
BMDControl->record(false);
}
}

// Shutter angle control from 90 to 360 in 90 degree increments
if (rotaryCounter == 1) {
if ((shutter + 90) > 360) {
BMDControl->shutterAngle(90);
} else {
BMDControl->shutterAngle(shutter + 90);
}
}

// Set frame rate depending on resolution
if (rotaryCounter == 2) {

// Frame rate for 4K DCI 24, 30, 60
if (resolutionX == 4096) {
  if (FrameRate == 24) {
    BMDControl->frameRate(30);
  } else if (FrameRate == 30) {
    BMDControl->frameRate(60);
  }else {
    BMDControl->frameRate(24);
  }
}

// Frame rate for HD 24, 30, 60, 120
if (resolutionX == 1920) {
  if (FrameRate == 24) {
    BMDControl->frameRate(30);
  } else if (FrameRate == 30) {
    BMDControl->frameRate(60);
  }else if (FrameRate == 60) {
    BMDControl->frameRate(120);
  }
}

}

// ISO Control
if (rotaryCounter == 3) {
if ((ISO + 100) > 6000) {
BMDControl->iso(100);
} else {
BMDControl->iso(ISO + 100);
}
}

// Whitebalance control
if (rotaryCounter == 4) {
if ((WB+100) > 7000) {
BMDControl->whiteBalance(4000, 20);
} else {
BMDControl->whiteBalance(WB+100, 20);
}
}
}