oled malfunction

Hello i need help
When i add Adafruit_SSD1306.h and run display
BC95Udp.h can't work
Thank you.

Mycode :

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

#include <Arduino.h>
#include <ArduinoJson.h>
#include <AltSoftSerial.h>
#include "BC95Udp.h"
#include "EmonLib.h"
#include <Dns.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

AltSoftSerial bc95serial;

BC95UDP udpclient;
uint8_t buff[64];
DNSClient dns;
IPAddress remoteip;

int x;
void setup() {
    Wire.begin();
    bc95serial.begin(9600);
    BC95.begin(bc95serial);
    BC95.reset();
    
    Serial.begin(9600);
    
    Serial.print(F("Starting"));

    while (!BC95.attachNetwork()) {
        Serial.print(".");
        delay(1000);
    }

    dns.begin();
    dns.getHostByName("ddns name", remoteip);
    
    Serial.print(F("NB-IOT module IP address : "));
    Serial.println(BC95.getIPAddress());
    udpclient.begin(8053);
    udpclient.beginPacket(remoteip, 55555);

    display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize I2C addr 0x3c
    display.clearDisplay(); // clears the screen and buffer
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.println("Thailand");
    display.display();
    
}
void loop() {

  char text[100];
  StaticJsonBuffer<200> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();
  root["S0"] = "50";
  root["S1"] = "69";
  root["S2"] = "99";
  root["S3"] = "78";
  root["S4"] = "25";
  root.printTo(text);
        
        Serial.println("\n\nSending UDP payload : ");
        Serial.print(text);

        udpclient.write(text,strlen(text));
        udpclient.endPacket();
        udpclient.parsePacket();

         size_t len = udpclient.read(buff,64);
         Serial.println(F("\n\nReceive UDP payload : "));
         Serial.println(len);
         printHEX(buff, len);
         delay(2000);
}
String str_char(char val[]){
  String str_a;
  for(int i=0;i<strlen(val);i++){
    str_a += val[i];
  }
  return str_a;
}
void printHEX(uint8_t *buff, size_t len) {
    char myStr[len]; 
    String aaa;
    for (int i=0; i<len; i++) {
        if (buff[i]<16) Serial.print(" 0");
        else Serial.print(" | ");
        Serial.print(buff[i]);
    }
}

Read the how to use the forum-please read sticky to see how to properly post code.

What do you mean by "It doesn't work with the BC95 NB-IOT library". Are there compile errors?

When i add Adafruit_SSD1306.h and run display
BC95Udp.h can't work

And if you try the IOT shield by itself does it work?

It works normally well.
When running the display command, BC95 will be restarted repeatedly.

1024 Bytes of display buffer, 200 Bytes of JSON buffer, and then some more dynamic memory usage by the BC95 library. I wouldn't call it a surprise ...

I would like advice :frowning: :frowning:

My guess is that you're running out of RAM. The display uses more than 50% of the RAM on an Arduino UNO.
The BC95 library seems to be using dynamic memory allocation, that'll fail when there's not enough memory.

What board are you using?

Arduino UNO
what should I adjust?

kintoun75:
what should I adjust?

Nothing. If you need such a large amount of memory, you need a microcontroller that has more memory.

You could try to use smaller buffers where you can, also make the JSON buffer static or global, so the compiler can tell you how much memory you're using.

There are some libraries for the SSD1306 without a RAM buffer, but they don't have as many features.

I just want to show the character Do you have an example of an SSD1306 library that doesn't have RAM?

It works. Thank you.