Incompatibility between libraries ELMduino and adafruits?

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.

Maybe send the OLED display.print() to Serial.print() to compare what you see and what you expect to see.

If is not unusual to have library clashes. I generally recommend just switching out one of the offenders; personally, I would look to replace the Adafruit library. In the past, I have included Adafruit code in IDE tabs and hacked it all into submission ... but it was painful :crazy_face:

Maybe helpful:
ssd1306 - Arduino Libraries

For lean ESP projects w/1306, I have used:

First of all: SoftwareSerial library will not run at 115200 baudrate, it not supports speeds over 38400, better yet 9600.
And second - what is your arduino board?

Hello, my board is an arduino uno, regarding the speed of the SoftwareSerial, I defined it like this since in the documentation of the ELMduino library the author recommends that and I was also talking to him and it turns out that the hardware I have is the same as that he uses. Regarding the topic in general, I think I know what the problem is in my code, however I would like someone to explain to me better how to solve it. According to what I investigated, the problem arises from establishing a serial communication and an i2c one simultaneously, since the serial communication defined by my SoftwareSerial library is not based on interruptions, but on constantly looking at the data buffer which makes it impossible to carry out other communications. I also found that the arduino uno, due to lack of hardware, cannot maintain both communications simultaneously in the same project, but to be honest I'm not sure how true that is. I was planning to buy an esp 32 that has up to 3 separate communication channels and see if I can get this program to work.

Sorry, but the author of the library explicitly recommended to lowering the baudrate in case of connection problems:

If you're having difficulty in connecting/keeping connection to your ELM327, try using 38400 baud instead of 115200.

But I have no problems with the connection with the obd2, that is, I set the baud rate at 115200 and the obd responds correctly with the request that is made to it. The problem I have is that I cannot initialize the i2c screen, having previously initialized the serial communication, therefore I cannot display the information on the oled screen. That is my problem to which I am looking for a solution.

Your topic has been moved to a more suitable location on the forum.

Kindly go througj it and edit your post accordingly

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.