An error in my serial monitor failed to capture image

Question/Issue:
I have already created a module in Arduino by taking some images for fire detection. It works fine, then I have integrated a servo motor to the code and it is still work fine. Then I have added a compass QM58831 and now in serial monitor it says no object detected for 2 times and then it says failed to capture images. I was thinking if this is because of the initiazltions timing, but do not know how to solve it. The code of the setup void and the compass is provided. Please note that I do not want to use FOMO code format. Also, each code alone works perfectly
Project ID:

Context/Use case:

void setup()
{

myservo.attach(servoPin);
startTime = millis();
// pinMode(LED, OUTPUT);
// put your setup code here, to run once:
Serial.begin(115200);
// comment out the below line to start inference immediately after upload
while (!Serial)
    ;
Serial.println("Edge Impulse Inferencing Demo");
if (ei_camera_init() == false)
{
    ei_printf("Failed to initialize Camera!\r\n");
}
else
{
    ei_printf("Camera initialized\r\n");
}

ei_printf("\nStarting continuous inference in 2 seconds...\n");
unsigned long startMillis = millis();
while (millis() - startMillis < 2000)
{
    // You can add other non-blocking initializations or tasks here

    // For example, you can check a condition and break the loop early if needed
    // if (someCondition) {
    //     break;
    // }


}

// Rest of your setup code...

delay (2500);
compass.init();
}

void com() {

unsigned long currentMillis = millis();

// Replace delay(200) with millis() for 200ms delay
if (currentMillis - previousMillis200 >= interval200)
{
    int x_value, y_value, z_value, azimuth, bearing;
    char direction[strlen("NNE") + 1];
    char buffer[strlen("X=-99999 | Y=-99999 | Z=-99999 | A=259° | B=15 | D=NNE") + 1];

    compass.read();
    x_value = compass.getX();
    y_value = compass.getY();
    z_value = compass.getZ();
    azimuth = compass.getAzimuth();
    bearing = compass.getBearing(azimuth);
    compass.getDirection(direction, azimuth);
    direction[3] = '\0';



             sprintf(buffer,
            "X=%6d | Y=%6d | Z=%6d | A=%3d° | B=%02hu | %s",
            x_value,
            y_value,
            z_value,
            azimuth,
            bearing,
            direction);
     Serial.println(buffer);

    previousMillis200 = currentMillis;
}

}

Then I am calling com(); in void loop along with fire codes.

1 Like

Hi @ShelBy

On first look it would appear that the Servo, “Compass”, (is it the QMC5883L?) and Arduino are causing too much of a draw for the power supply. You may need a higher quality cable or additional power source.

Also check your wiring you may have some short happening.

QMC5883L Compass Arduino Nano V3.0


 VCC           --->     5V
 GND           --->     GND
 SCL           --->     A5
 SDA           --->     A4
 DRDY (Opt.)   --->     Digital Pin (Optional)

See more on the wiring and power specs here:

If you need more specifics please also post in the Arduino forum as they will be able to help more on the wiring and spec for that device.

Best

Eoin