I have a vesc motor controller that I am trying to talk to through UART on the RX and TX pins and an OLED 128x64 display I am trying to talk to through I2C. When I try a script only talking to the screen, it works fine. If I run a script only talking to the vesc, it runs fine. But running the following code results in the screen not being about to be initialized.
#include <VescUart.h>
//Screen
#include <Wire.h>
#include <Adafruit_SSD1306.h>
VescUart UART;
Adafruit_SSD1306 display(128, 64);
void setup() {
Serial.begin(115200);
while (!Serial) {;}
UART.setSerialPort(&Serial);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("SSD1306 allocation failed"); //code get stuck here when run
for(;;);
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("Loading...");
delay(1000);
}
void loop() {
if ( UART.getVescValues() ) {
Serial.println(UART.data.rpm);
Serial.println(UART.data.inpVoltage);
Serial.println(UART.data.ampHours);
Serial.println(UART.data.tachometerAbs);
} else {
Serial.println("Failed to get data");
}
display.display();
delay(50);
display.clearDisplay();
}