Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SSD1306 not working at same time as pcf8574
#1
Does anyone know anything about the u8g2 library for the SSD1306 librarry onflicting with pcf8574?  It seems that as soon as I write to the display the inputs connected to pcf8574 controllers stop working.

I am just using standard sample code for u8g2 from this site.  But have included it in a much larger sketch.  With the u8g2 firstpage / nextpage loop my pcf8574 inputs work fine.  But as soon as I include those commands the inputs stop working.
Reply
#2
it can work well at the same time, no problem , check your code.
Reply
#3
Have you tried running an I²C scanner with and without the display code? That might show if the PCF8574 is dropping off the bus once u8g2 writes to the SSD1306.
Reply
#4
(12-05-2025, 01:49 AM)Eggman Wrote: Does anyone know anything about the u8g2 library for the SSD1306 librarry onflicting with pcf8574?  It seems that as soon as I write to the display the inputs connected to pcf8574 controllers stop working.

I am just using standard sample code for u8g2 from this site.  But have included it in a much larger sketch.  With the u8g2 firstpage / nextpage loop my pcf8574 inputs work fine.  But as soon as I include those commands the inputs stop working.

Did you manage to resolve the compatibility issue?
I also came across that the 2 libraries do not work together.
Reply
#5
which board model you are using?
Reply
#6
(02-23-2026, 10:46 PM)admin Wrote: which board model you are using?

I use KC868-A6. I can provide a sketch.
Reply
#7
you can test with this arduino code, SSD1306 and PCF8574 can work at the same time.
Code:
#include <Wire.h>
#include <DS18B20.h>
#include "RTClib.h"
DS18B20 ds1(32);  //channel-1-DS18b20
DS18B20 ds2(33);  //channel-2-DS18b20

RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

#include "Arduino.h"
#include "PCF8574.h"

#define ANALOG_A1   36
#define ANALOG_A2   39
#define ANALOG_A3   34
#define ANALOG_A4   35

// Set i2c address
PCF8574 pcf8574o(0x24);
PCF8574 pcf8574i(0x22);

#define s2 0

void setup()
{
  Wire.begin(4, 15);   // ✅ 设置 IIC SDA = GPIO4, SCL = GPIO15
  Serial1.begin(9600, SERIAL_8N1, 16, 17);  // 初始化 RS232
  Serial2.begin(9600, SERIAL_8N1, 14, 27);  // 初始化 RS485
  Serial1.println();

  pinMode(s2,INPUT);

  // Set pinMode to OUTPUT
  pcf8574o.pinMode(P0, OUTPUT);
  pcf8574o.pinMode(P1, OUTPUT);
  pcf8574o.pinMode(P2, OUTPUT);
  pcf8574o.pinMode(P3, OUTPUT);
  pcf8574o.pinMode(P4, OUTPUT);
  pcf8574o.pinMode(P5, OUTPUT);
  pcf8574o.pinMode(P6, OUTPUT);
  pcf8574o.pinMode(P7, OUTPUT);

  Serial1.print("Init pcf8574o...");
  if (pcf8574o.begin()){
    Serial1.println("OK");
  }else{
    Serial1.println("KO");
  }
 
pcf8574i.pinMode(P0, INPUT);
pcf8574i.pinMode(P1, INPUT);
pcf8574i.pinMode(P2, INPUT);
pcf8574i.pinMode(P3, INPUT);
pcf8574i.pinMode(P4, INPUT);
pcf8574i.pinMode(P5, INPUT);
pcf8574i.pinMode(P6, INPUT);
pcf8574i.pinMode(P7, INPUT);

  Serial1.print("Init pcf8574i...");
  if (pcf8574i.begin()){
    Serial1.println("OK");
  }else{
    Serial1.println("KO");
  }


  Serial1.print("T1:");
  Serial1.print(ds1.getTempC());
  Serial1.print(" C /\n");
  Serial1.print("T2:");
  Serial1.print(ds2.getTempC());
  Serial1.print(" C /\n");

pcf8574o.digitalWrite(P0, HIGH);
pcf8574o.digitalWrite(P1, HIGH);
pcf8574o.digitalWrite(P2, HIGH);
pcf8574o.digitalWrite(P3, HIGH);
pcf8574o.digitalWrite(P4, HIGH);
pcf8574o.digitalWrite(P5, HIGH);
pcf8574o.digitalWrite(P6, HIGH);
pcf8574o.digitalWrite(P7, HIGH);

  pcf8574o.digitalWrite(P0, LOW);
  delay (100);
  pcf8574o.digitalWrite(P1, LOW);
  delay (100);
  pcf8574o.digitalWrite(P2, LOW);
  delay (100);
  pcf8574o.digitalWrite(P3, LOW);
  delay (100);
  pcf8574o.digitalWrite(P4, LOW);
  delay (100);
  pcf8574o.digitalWrite(P5, LOW);
  delay (100);
  pcf8574o.digitalWrite(P5, HIGH);
  delay (100);
  pcf8574o.digitalWrite(P4, HIGH);
  delay (100);
  pcf8574o.digitalWrite(P3, HIGH);
  delay (100);
  pcf8574o.digitalWrite(P2, HIGH);
  delay (100);
  pcf8574o.digitalWrite(P1, HIGH);
  delay (100);
  pcf8574o.digitalWrite(P0, HIGH);
 

   if (! rtc.begin()) {
    Serial1.println("Couldn't find RTC");
    Serial1.flush();
    while (1) delay(10);
  }

  if (! rtc.isrunning()) {
    Serial1.println("RTC is NOT running, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }

    DateTime now = rtc.now();

    Serial1.print(now.year(), DEC);
    Serial1.print('/');
    Serial1.print(now.month(), DEC);
    Serial1.print('/');
    Serial1.print(now.day(), DEC);
    Serial1.print(" (");
    Serial1.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial1.print(") ");
    Serial1.print(now.hour(), DEC);
    Serial1.print(':');
    Serial1.print(now.minute(), DEC);
    Serial1.print(':');
    Serial1.print(now.second(), DEC);
    Serial1.println();

Serial2.println("485 send is OK!");

dacWrite(DAC1, 127);  //DAC1=5V
dacWrite(DAC2, 127);  //DAC2=5V

  Serial1.printf("Current Reading A1 on Pin(%d)=%d\n",ANALOG_A1,analogRead(ANALOG_A1));
  Serial1.printf("Current Reading A2 on Pin(%d)=%d\n",ANALOG_A2,analogRead(ANALOG_A2));
  Serial1.printf("Current Reading A3 on Pin(%d)=%d\n",ANALOG_A3,analogRead(ANALOG_A3));
  Serial1.printf("Current Reading A4 on Pin(%d)=%d\n",ANALOG_A4,analogRead(ANALOG_A4));

}

void loop()
{

int Value = 127; //255= 10V

uint8_t val1 = pcf8574i.digitalRead(P0);
uint8_t val2 = pcf8574i.digitalRead(P1);
uint8_t val3 = pcf8574i.digitalRead(P2);
uint8_t val4 = pcf8574i.digitalRead(P3);
uint8_t val5 = pcf8574i.digitalRead(P4);
uint8_t val6 = pcf8574i.digitalRead(P5);
uint8_t val7 = pcf8574i.digitalRead(P6);
uint8_t val8 = pcf8574i.digitalRead(P7);
uint8_t val_s2 = digitalRead(s2);


//------------------------------------
if (val1==LOW) pcf8574o.digitalWrite(P0, LOW); else pcf8574o.digitalWrite(P0, HIGH);
if (val2==LOW) pcf8574o.digitalWrite(P1, LOW); else pcf8574o.digitalWrite(P1, HIGH);
if (val3==LOW) pcf8574o.digitalWrite(P2, LOW); else pcf8574o.digitalWrite(P2, HIGH);
if (val4==LOW) pcf8574o.digitalWrite(P3, LOW); else pcf8574o.digitalWrite(P3, HIGH);
if (val5==LOW) pcf8574o.digitalWrite(P4, LOW); else pcf8574o.digitalWrite(P4, HIGH);
if (val6==LOW) pcf8574o.digitalWrite(P5, LOW); else pcf8574o.digitalWrite(P5, HIGH);
if (val7==LOW) pcf8574o.digitalWrite(P6, LOW); else pcf8574o.digitalWrite(P6, HIGH);
if (val8==LOW) pcf8574o.digitalWrite(P7, LOW); else pcf8574o.digitalWrite(P7, HIGH);
if (val_s2==LOW)
   {
     Serial1.println("Download key is OK !");
   }

//-------------------------------------
  if (analogRead(ANALOG_A1)>0) Serial1.printf("Current Reading A1 on Pin(%d)=%d\n",ANALOG_A1,analogRead(ANALOG_A1));
  if (analogRead(ANALOG_A2)>0) Serial1.printf("Current Reading A2 on Pin(%d)=%d\n",ANALOG_A2,analogRead(ANALOG_A2));
  if (analogRead(ANALOG_A3)>0) Serial1.printf("Current Reading A3 on Pin(%d)=%d\n",ANALOG_A3,analogRead(ANALOG_A3));
  if (analogRead(ANALOG_A4)>0) Serial1.printf("Current Reading A4 on Pin(%d)=%d\n",ANALOG_A4,analogRead(ANALOG_A4));
  delay(30);
//-------------------------------
  // 如果 RS232 收到数据
  if (Serial1.available()) {
    int data1 = Serial1.read();   // 读取一个字节
    Serial1.write(data1);         // 原样发回
  }

//--------------------------------
  // 如果 RS485 收到数据
  if (Serial2.available()) {
    int data2 = Serial2.read();   // 读取一个字节
    Serial2.write(data2);         // 原样发回
  }


}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)