Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Rojj
#92822 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:
    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?
User avatar
By Rojj
#92826 I tested it with a different NodeMCU (that looked exactly the same) and it worked so I thought it was just a damaged MCU. On closer inspection though, the components seems to be slightly different:

Not working NodeMCU
Voltage regulator: AMS1117 (H1618) - I do not know what the second number is
USB2Serial: CP2102 (1806+)
Capacitor? (yellow component): 107J H110C

Working one
Voltage regulator: AMS1117 (H1938)
USB2Serial: CP2102 (1916+)
Capacitor? (yellow component): 107J 33F2

Could this be the reason?
User avatar
By QuickFix
#92836
Rojj wrote:Could this be the reason?

I doubt it: the values between brackets appear to be production dates (year-week format).
The actual component designations are identical.

You can check it by looking at the NodeMCU schematics