Open energy monitor EmonLib and Adafruit_SSD1306 issue

Hi all,

I am Designing one project using Arduino Nano, OLED SSD1306 128X64, GSM Modem, Current sensor 100A Sct-013-000 Non-Invasive Ac Current Clamp Sensor.

The issue is while included the library file EmonLib by openenergy monitor, the OLED display becomes black out. without EmonLib OLED displays the contents.

/*******************GSM SIM A7670C 5V MODULE BASED SECURITY SYSTEM***********************/
//HEADER FILES
#include <EmonLib.h>
#include <EEPROM.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
/************************************************************************************/
//OLED SIZE
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
//INPUTS
#define MENU 2
#define UP 3
#define DOWN 4
#define SET 5
//OUTPUTS
#define RLY 10
//ANALOG
#define PH1V A0  // Analog input pin for the Voltage Sensor. If cutoff circiut used read 0 or 1024 analog value for logic
#define PH2V A1  // Analog input pin for the Voltage Sensor. If cutoff circiut used read 0 or 1024 analog value for logic
#define PH3V A2  // Analog input pin for the Voltage Sensor. If cutoff circiut used read 0 or 1024 analog value for logic
#define PH1A A3  // Analog input pin for the Current Sensor. If cutoff circuit used read 0 or 1024 analog value for logic
#define PH2A A6  // Analog input pin for the Current Sensor. If cutoff circuit used read 0 or 1024 analog value for logic
#define PH3A A7  // Analog input pin for the Current Sensor. If cutoff circuit used read 0 or 1024 analog value for logic
/************************************************************************************/
//CONFIGURE DISPLAY AND SERIAL COMMUNICATION
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
/************************************************************************************/
//VARIABLES AND ARRAYS DECLARATION
byte m = 0;
byte n = 0;
byte a, b, i, indel, outdel, sms, numb, nomob, mobloc = 1, sirentime;
byte sv, hl, ll, col, row;
byte col1, col2, col3, row1, row2, fn, ln;
byte k[51];
char _buffer[11];
int mst, hlve, hv, lv, hlae, ha, la, id, drte, drt, mre, mt, sse, dbt, shlv, shla, mode, stype, phase;
int error, error1, error2, error3, error4, error5, error6, error7, error8, error9, error10, error11, error12, menumem;

//char message1[5];
const unsigned long eventInterval = 10000;
unsigned long previousTime = 0;

const unsigned int MAX_MESSAGE_LENGTH = 12;

float voltagevalue1, voltagevalue2, voltagevalue3;  // variable to store the value coming from the Voltage sensor
float currentvalue1, currentvalue2, currentvalue3;  // variable to store the value coming from the Current sensor

EnergyMonitor emon1, emon2, emon3;

unsigned long previousMillis = 0;
const long interval = 5000;
int dp = 0;  //dp is display page number

/************************************************************************************/
//CONTROLLER SETUP
void setup() {
  // put your setup code here, to run once:
  Wire.begin(0x3C);
  Serial.begin(9600);
  
  //Wire.setClock(400000L);
  //pinMode(BUZZ, OUTPUT);
  pinMode(RLY, OUTPUT);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // Clear the buffer.
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE, BLACK);
  display.setCursor(0, 0);
  display.print("MCS GSM Based");
  display.setCursor(0, 20);
  display.print("3PH Motor Controller");
  display.display();

  emon1.voltage(PH1V, 234.26, 1.7); //Voltage: input pin, calibrtion, phase_shift
  emon2.voltage(PH2V, 234.26, 1.7); //Voltage: input pin, calibrtion, phase_shift
  emon3.voltage(PH3V, 234.26, 1.7); //Voltage: input pin, calibrtion, phase_shift
  emon1.current(PH1A, 60.6);       //Current: input pin, calibrtion
  emon2.current(PH2A, 60.6);       //Current: input pin, calibrtion
  emon3.current(PH3A, 60.6);       //Current: input pin, calibrtion

  readmemory();
  //digitalWrite(BUZZ, LOW);
  digitalWrite(RLY, LOW);
  //delay(30000);
  Serial.print("AT\r");
  delay(1000);
  Serial.print("ATE0\r");
  delay(1000);
  Serial.print("AT+CMGF=1\r");
  delay(1000);
  Serial.print("AT+CMGD=4\r");
  delay(1000);
  Serial.print("AT&W\r");
  delay(1000);
}

void loop() {
  // put your main code here, to run repeatedly:

  if (digitalRead(MENU) == 1) {
    menu();
  }
}

The program is larger so i paste small part only

Looking for guidence
Thanks in advance

Paste the entire program, we can't really help you otherwise.

hi thanks for reply

instead of using this library

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

now i am using this

#include <SSD1306Ascii.h>
#include <SSD1306AsciiWire.h>
#include <SSD1306init.h>

now display works

as per this webpage

https://medium.com/@barryperalta/energy-monitoring-935e8537ef55

Unfortunately the Adafruit_SSD1306 library does not make clear that it needs 1024 bytes of ram at run-time for the display buffer (or 512 bytes for a 128x32 display). This memory does not show up in the total dynamic memory usage shown by the compiler, so the sketch will compile and upload without any indication of a problem, but as soon as you initialize the display the buffer gets allocated and overwrites memory already in use.

1 Like

i modified the program so unable to upload that

thanks for the reply,
can you suggest any other display which consume less memory, only text is used in my program

The "text only" SSD1306 library does not require or allocate the 1024 byte buffer.

yes this library is best one.
i am looking for Bigger Size Display
thank you

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