Pro Micro doesn't startup with powerbank

Good morning,

I started a few months ago with Arduino UNO, but now I want to change to Pro Micro and Arduino Micro to make my setup smaller and I have one trouble.

With the UNO I load my code and works perfect, and after disconnect from the PC and connect again to a battery it still works. But with the Pro Micro if I load the code it works, but if I connect to an external battery (doesn't matter if I connect it with the USB or the RAW pin) the board turns the LED on but nothing else happend.

Anybody has some hints about what is happening?

Thanks so much and sorry if I have made any spelling mistakes and/or if is the wrong category :slight_smile:

#include "SSD1306Ascii.h"
#include "SSD1306AsciiAvrI2c.h"
#include "LowPower.h"
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
#include <QMC5883LCompass.h>

#define I2C_ADDRESS 0x3C
#define SerialMonitor Serial

const int SCREEN_WIDTH = 128;
const char* texto1 = "curioseitor v1";
int textPosition1 = (SCREEN_WIDTH - strlen(texto1)) / 4;


QMC5883LCompass compass;

SSD1306AsciiAvrI2c oled;

Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(222);

void setup(void)
{
  pinMode(LED_BUILTIN, OUTPUT);

#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif
  Serial.begin(9600);
  SerialMonitor.begin(9600);
  oled.begin(&Adafruit128x32, I2C_ADDRESS);
  oled.setFont(System5x7);
  oled.clear();

#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif
  Serial.begin(9600);
  Serial.println("Encendido del acelerómetro"); Serial.println("");

  /* Initialise the sensor */
  if (!accel.begin())
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    Serial.println("Acelerómetro ADXL345 no detectado");
    while (1);
  }

  /* Set the range to whatever is appropriate for your project */
  accel.setRange(ADXL345_RANGE_2_G);

  //inicialización de compás
  compass.init();
  Serial.println("Encendido de la brújula"); Serial.println("");

  oled.clear();


  //Pantalla de bienvenida
  oled.println("");
  oled.setCursor(18, 35);
  oled.println("Bienvenida");
  delay(2000);
  oled.clear();
}

void loop(void)
{
  //Modo bajo consumo
  LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF);
  delay(100);

  /* Get a new sensor event */
  sensors_event_t event;
  accel.getEvent(&event);
  compass.init();
  compass.setCalibration(-1483, 1318, -1382, 1951, -997, 1767);

  //Pitch ADXL345
  float Pitch_x = atan(event.acceleration.x / sqrt(pow(event.acceleration.y, 2) + pow(event.acceleration.z, 2))) * (180.0 / M_PI);

  delay(500);

  printGPSInfo();
  smartDelay(100);
  oled.setCursor(0, 0);
}

void printGPSInfo()
{
  sensors_event_t event;
  accel.getEvent(&event);

  //Azimut
  int azimut;
  compass.read();
  azimut = compass.getAzimuth();
  char myArray[3];
  compass.getDirection(myArray, azimut);

  //Pitch ADXL345
  float Pitch_x = atan(event.acceleration.x / sqrt(pow(event.acceleration.y, 2) + pow(event.acceleration.z, 2))) * (180.0 / M_PI);
  float Roll_y = atan(event.acceleration.y / sqrt(pow(event.acceleration.x, 2) + pow(event.acceleration.z, 2))) * (180.0 / M_PI);


  oled.setCursor(0, 10);
  oled.print("Direccion: ");
  oled.print(azimut);
  oled.print(char(128));
  oled.print(" ");
  oled.print(myArray[0]);
  oled.print(myArray[1]);
  oled.print(myArray[2]);
  oled.println("     ");
  oled.print("Cabeceo: ");
  oled.print(Pitch_x, 2);
  oled.print(char(128));
  oled.println("  ");
  oled.print("Alabeo: ");
  oled.print(Roll_y, 2);
  oled.print(char(128));
  oled.println("  ");

  Serial.print("Azimut: ");
  Serial.print(azimut);
  Serial.print("\tCabeceo: ");
  Serial.print(Pitch_x, 2);
  Serial.print("\tAlabeo: ");
  Serial.println(Roll_y, 2);

  delay(10);
  yield();


}
static void smartDelay(unsigned long ms)
{

}

Have you tried the Blink sketch from the IDE Examples?

I suggest you read the forum guide. It is in the sticky post at the top of each forum section.

Start by posting your code and a schematic of your project

The power into the USB port needs to be 5V but in order to use the RAW pin you need to supply between 7V and 12V as it goes through a voltage regulator to provide the required voltage

To complicate things further I believe that the Pro Micro is available in 2 versions, one of which runs at 5V and the other at 3V3. Which do you have ?

Sorry, I made a mesh with the answers :sweat_smile:

I have the 5V version.

I edited the first post with my code.

I tried the blink from Sparkfun and it works perfect.

If you do not have it plugged into the PC, with an available serial port, this line will not exit.

Willem.

Also this, depending on the board type, can happen before the Serial.begin() statement.

If you change that to:
while (!Serial && millis() < 5000); // for Leonardo/Micro/Zero
your sketch will continue even if no USB connection has been established within 5 seconds of power being applied. I'm not sure what will happen if you try Serial.print() without a serial connection but it probably won't be a problem.

Thanks a lot for the help.

It works!! :smiley: :clap: :clap:

That "while" was an infinite loop.