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 ![]()
#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)
{
}