I am trying to put together an OLED 128x64, BMP280, HMC5883L and a GPS Neo 6M.
The device I am using is an Arduino Nano (328p with old bootloader).
The first time I compile the code I get a warning that does not appear again if I compile again. This is the warning:
In file included from C:\Users\gonza\Documents\Arduino\libraries\Adafruit_HMC5883_Unified\Adafruit_HMC5883_U.cpp:38:0:
C:\Users\gonza\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5\libraries\Wire\src/Wire.h: In member function 'void Adafruit_HMC5883_Unified::read()':
C:\Users\gonza\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5\libraries\Wire\src/Wire.h:69:13: note: candidate 1: uint8_t TwoWire::requestFrom(int, int, int)
uint8_t requestFrom(int, int, int);
^~~~~~~~~~~
C:\Users\gonza\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5\libraries\Wire\src/Wire.h:66:13: note: candidate 2: uint8_t TwoWire::requestFrom(uint8_t, uint8_t, uint8_t)
uint8_t requestFrom(uint8_t, uint8_t, uint8_t);
^~~~~~~~~~~
This is my code: (it crashes before reaching loop)
//Agregamos las librerias necesarias
#include <Adafruit_HMC5883_U.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <Adafruit_BMP280.h>
#include <Adafruit_Sensor.h>
#include <SoftwareSerial.h>
#include <TinyGPSPlus.h>
#include <EasyButton.h>
#include <Wire.h>
//OLED
#define ancho 128
#define alto 64
#define OLED_RESET 0
Adafruit_SSD1306 oled(ancho, alto, &Wire, OLED_RESET);
//Tamaño de letra
#define tam 1
//Fuente de letra
#include <Fonts/FreeSans9pt7b.h>
//Objeto del sensor BMP280
Adafruit_BMP280 bmp;
//GPS NEO 6M
static const int RXPin = 3, TXPin = 4; //Al reves
static const uint32_t GPSBaud = 9600;
//TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);
//Brujula
Adafruit_HMC5883_Unified mag;
//Variable botones
EasyButton botonUP(6,35,false,true);
EasyButton botonDWN(5,35,false,true);
EasyButton botonOK(7,35,false,true);
EasyButton backButton(5,35,false,true);
//Temporizadores
unsigned long tiempo1;
//Variables de los menus
byte menu1 = 1;
byte menu2 = 1;
byte submenu = 1;
void setup()
{
Serial.begin(115200);
//Iniciamos todos los sensores
//Iniciamos OLED
if(!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)){Serial.println(F("Error oled"));}
oled.setTextSize(tam); //Tamano de letra
oled.setFont(&FreeSans9pt7b); //Fuente
oled.setTextColor(SSD1306_WHITE);
//Iniciamos BMP280
bmp.begin();
//Iniciamos GPS
ss.begin(GPSBaud);
//Easybutton
botonUP.begin();
botonUP.onPressed(lecturaUP);
botonDWN.begin();
botonDWN.onPressed(lecturaDWN);
botonOK.begin();
botonOK.onPressed(lecturaOK);
//Brujula
mag.begin();
//Mostramos la animacion de inicio
Inicio();
//Lanzamos la pantalla principal
actualizarMenu();
}
void Inicio()
{
oled.clearDisplay();
oled.setCursor(20,10);
oled.print(F("Animacion"));
Serial.println(F("Iniciado"));
oled.display();
delay(1000);
}
void loop()
{
//Leemos los botones constantemente
botonUP.read();
botonDWN.read();
botonOK.read();
}
void lecturaUP()
{
if(menu1 == 3)
{
menu1 = 0; //Uno menos del que hay
}
menu1++;
actualizarMenu();
Serial.println(menu1);
}
void lecturaDWN()
{
if(menu1 == 1)
{
menu1 = 4; //Uno mas del que hay
}
menu1--;
actualizarMenu();
Serial.println(menu1);
}
void lecturaOK()
{
if(submenu == 2)
{
//Nada, no hay mas submenus
}
else
{
submenu++;
actualizarMenu();
Serial.println(submenu);
}
}
void actualizarMenu()
{
switch(submenu)
{
case 1:
switch(menu1)
{
//menu1 = 1 es el menu principal
case 1: oled.clearDisplay();
oled.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
oled.setCursor(10,10);
oled.print(F("GPS"));
oled.display();
break;
}
case 2: break;
}
}
void backSubmenu()
{
if(submenu == 1)
{
//Nada, es el primer submenu
}
else
{
submenu--;
Serial.println(submenu);
}
}
This is what I have tested so far:
- I have tested them individually and everithing works as it should.
- When connected together I ran I2C scanner and every I2C address showed up.
- I tried to remove every library, compile and, if it worked, added the next, compile again and so on. (It seems to have something to do with compatibility between libraries but I am not sure, as the arduino crashes with different selection of libraries).
- I suspected this may be caused by SRAM so I tried with a Wemos D1 mini (esp8266) but the issue persists. I ordered an Arduino Mega so I can try with it.
- I have checked my code for hours but I can not find any error, also the code is mainly made with other code or examples that already work, I just combined them together.
- The bmp280 sensor works at 3.3v, I have read this may cause issues with the I2C bus but so far it has worked well (tested oled and bmp together).
I think this is all, if I am missing any important info just let me know.
Any thoughts on why this is would be much appreciated. ![]()