NodeMCU crashes when using OLED
Posted: Sat Nov 13, 2021 3:37 am
Hi,
I would like to use an SSD1306 OLED with my NodeMCU project, but I am struggling with crashes. I think it might be related to the pins I am using, but I need some help as I am not an expert.
I am using a NodeMCU board 12E and platform.io as IDE. The project is an Air quality sensor using PMS5003 and MHZ14A (libs: https://github.com/avaldebe/PMserial and https://github.com/WifWaf/MH-Z19)
For the OLED I am using https://github.com/ThingPulse/esp8266-oled-ssd1306
A couple of notes:
This is an extract of the code up to the setup
As soon as the code gets to display.init() it restarts. Occasionally I receive this error
The OLED is not even connected. As soon as I comment the display.init() line out, everything works fine.
I have also tried using GPIO13/15 and I have the same issue (I disconnect the wires during flashing).
Any idea? Other options two use OLED and two serial sensors?
I would like to use an SSD1306 OLED with my NodeMCU project, but I am struggling with crashes. I think it might be related to the pins I am using, but I need some help as I am not an expert.
I am using a NodeMCU board 12E and platform.io as IDE. The project is an Air quality sensor using PMS5003 and MHZ14A (libs: https://github.com/avaldebe/PMserial and https://github.com/WifWaf/MH-Z19)
For the OLED I am using https://github.com/ThingPulse/esp8266-oled-ssd1306
A couple of notes:
- Without the OLED, everything works fine
- The OLED by itself without the sensors works fine on GPIO10/9
This is an extract of the code up to the setup
Code: Select all
#include <Arduino.h>
#include <SoftwareSerial.h>
#include "PMserial.h" // Arduino library for PM sensors with serial interface
#include "wifi.h"
#include "influxdbHelper.h"
#include "MHZ19.h"
#include <Wire.h>
#include "SSD1306Wire.h" // legacy: #include "SSD1306.h"
// References
// http://www.winsen-sensor.com/d/files/infrared-gas-sensor/mh-z14a_co2-manual-v1_01.pdf
// http://www.winsen-sensor.com/d/files/PDF/Infrared%20Gas%20Sensor/NDIR%20CO2%20SENSOR/MH-Z14%20CO2%20V2.4.pdf
// MHZ14A
// connections:
// Check Kicad
#define RX_MHZ_PIN D2 // Rx pin which the MHZ19 Tx pin is attached to
#define TX_MHZ_PIN D1 // Tx pin which the MHZ19 Rx pin is attached to
#define BAUDRATE 9600 // Device to MH-Z19 Serial baudrate (should not be changed)
MHZ19 myMHZ19; // Constructor for library
SoftwareSerial swMHZSerial(RX_MHZ_PIN, TX_MHZ_PIN); // (Uno example) create device to MH-Z19 serial
// PMS5003
// pin for uart reading on the PMS
#define PMS_RX D5 // RX pin on device
#define PMS_TX D6 // TX pin on device
SerialPM pms(PMS5003, PMS_RX, PMS_TX); // PMSx003, RX, TX
// Initialize the OLED display using Arduino Wire:
#define PROJ_SDA 10 // Use different pins rather than standards SDA and SCL for NodeMCU
#define PROJ_SCL 9 // Use different pins rather than standards SDA and SCL for NodeMCU
SSD1306Wire display(0x3c, PROJ_SDA, PROJ_SCL, GEOMETRY_128_32);
void setup()
{
Serial.begin(9600);
initialiseWiFi();
influx.setDb(INFLUXDB_DATABASE);
// MHZ14
swMHZSerial.begin(BAUDRATE); // (Uno example) device to MH-Z19 serial start
myMHZ19.begin(swMHZSerial); // *Serial(Stream) refence must be passed to library begin().
myMHZ19.autoCalibration(); // Turn auto calibration ON (OFF autoCalibration(false))
// PMS5003
pms.init();
// Initialising the UI will init the display too.
Serial.println("Crashing");
display.init();
// display.flipScreenVertically();
// display.setFont(ArialMT_Plain_10);
}
As soon as the code gets to display.init() it restarts. Occasionally I receive this error
Code: Select all
!Error: Timed out waiting for response
!ERROR: Failed to verify connection(1) to sensor.
!ERROR: Initial communication errorCode recieved
!Error: Timed out waiting for response
The OLED is not even connected. As soon as I comment the display.init() line out, everything works fine.
I have also tried using GPIO13/15 and I have the same issue (I disconnect the wires during flashing).
Any idea? Other options two use OLED and two serial sensors?