Hello, I am working on a project for my car, to make a clock in which the ECU data is shown in real time, for that I was using the ELMduino library to obtain these variables using an elm327. The problem occurs when I want to simultaneously execute both the library, such as the adafruits library called Adafruit_SSD1306 and Adafruit_GFX.h, to display the variables on a 128x64 pixel oled screen. What happens is that the oled screen does not refresh the screen and shows absolutely nothing.
I was also testing in another scketch only the adafruit library to verify its programming and the status of my screen (if it was broken or not) and as a result everything worked, however I couldn't get the adafruits libraries to run simultaneously with that of the ELMduino.
I've attached my code so you can see what I've been trying to test.
#include "ELMduino.h"
#include <SoftwareSerial.h>
#include <Wire.h> // libreria para bus I2C
#include <Adafruit_GFX.h> // libreria para pantallas graficas
#include <Adafruit_SSD1306.h> // libreria para controlador SSD1306
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
SoftwareSerial mySerial(2, 3); // RX, TX
#define ELM_PORT mySerial
ELM327 myELM327;
uint32_t rpm = 0;
void setup()
{
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //init the oled screen
display.clearDisplay();//clear the oled screen
#if LED_BUILTIN
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
#endif
Serial.begin(115200);
ELM_PORT.begin(115200);
Serial.println("Attempting to connect to ELM327...");
if (!myELM327.begin(ELM_PORT, true, 2000))
{
Serial.println("Couldn't connect to OBD scanner");
while (1);
}
Serial.println("Connected to ELM327");
display.clearDisplay();
display.setTextColor(WHITE);
display.setCursor(0,0);
display.setTextSize(2);
display.print("Connected to ELM327");
display.display();
}
void loop()
{
float tempRPM = myELM327.rpm();
if (myELM327.nb_rx_state == ELM_SUCCESS)
{
rpm = (uint32_t)tempRPM;
Serial.print("RPM: "); Serial.println(rpm);
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
myELM327.printError();
}
Does anyone know how I can solve this problem, or what other libraries I can use as an alternative to ensure proper functioning of my oled screen.