Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library gets stuck with OLED SSH1106 and Arduino UNO #2347

Open
Alejandro13C opened this issue Jan 12, 2024 · 8 comments
Open

Library gets stuck with OLED SSH1106 and Arduino UNO #2347

Alejandro13C opened this issue Jan 12, 2024 · 8 comments

Comments

@Alejandro13C
Copy link

Alejandro13C commented Jan 12, 2024

Hi all,

I have connected Arduino UNO with ZDelivery 1,3" OLED Display I2C SSH1106 Chip 128 x 64.
I try to use a simple clock example but when i connect the Ardunio UNO at OLED.

5V --> 5V arduino.
GND--> GND Arduino.
SDA --> A4
SCL --> A5

#include <U8g2lib.h>
#include <Wire.h>

U8G2_SH1106_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,4,5, /* reset=*/ U8X8_PIN_NONE);

void setup(void) {
  Serial.begin(115200);
  u8g2.begin();  
}

uint8_t s = 00;
uint8_t m = 00;
uint8_t h = 00;

char s_str[3];
char m_str[3];
char h_str[3];

void loop(void) {

  strcpy(s_str, u8x8_u8toa(s, 2));		/* convert m to a string with two digits */
  strcpy(m_str, u8x8_u8toa(m, 2));		/* convert m to a string with two digits */
  strcpy(h_str, u8x8_u8toa(h, 2));		/* convert m to a string with two digits */
  u8g2.firstPage();
  do {
    u8g2.setFont(u8g2_font_ncenB10_tr);
    u8g2.drawStr(10,63,h_str);
    u8g2.drawStr(33,63,":");
    u8g2.drawStr(50,63,m_str);
    u8g2.drawStr(73,63,":");
    u8g2.drawStr(90,63,s_str);
    Serial.print("u8g2.nextPage(): "); Serial.println(u8g2.nextPage());
  } while ( u8g2.nextPage() );
  
  delay(1000);
  s++;
  if ( s == 60 )
  {
    s = 0;
    m++;
  }
  if ( m == 60 )
  {
    m = 0;
    h++;
  }
  if (h == 24)
  {
    h = 0;
  } 
}

The program is in stuck at this instruction.
while ( u8g2.nextPage() )
I had the same problem when i use "u8g2.sendBuffer();"
I see the issue onyl when i connect the oled to the Arduino.
I check the same OLED with ESP32 and i do not see any issue.
I check the same OLED with another Arduino UNO i reproduce the issue.
Could you help me?
Thanks!

@olikraus
Copy link
Owner

olikraus commented Jan 12, 2024

Your constructor
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0,4,5, /* reset=*/ U8X8_PIN_NONE);
seems to be wrong.

Use
U8G2_SH1106_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,4,5, /* reset=*/ U8X8_PIN_NONE);
or
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0,/* reset=*/ U8X8_PIN_NONE);

@Alejandro13C
Copy link
Author

Alejandro13C commented Jan 17, 2024

Hi @olikraus

This constructor does not work.
8G2_SH1106_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,4,5, /* reset=*/ U8X8_PIN_NONE);
The code is not running with this.

With the other. U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0,/* reset=*/ U8X8_PIN_NONE);
I see the issue after 15 minutes

Regards

@olikraus
Copy link
Owner

Then? Is your problem solved?

@Alejandro13C
Copy link
Author

Alejandro13C commented Jan 21, 2024

Hi,
No, i still have the issue.
I check that when i disconnect only the SCL pin of the OLED display, the code is running.
Could be possible that the frecuency is not setting properly?

Some new Updates.

I change the wire between OLED and Arduino, i use a longer wire.
If i check the i2c address of the oled i see it:

2:05:40.295 -> Scanning... 12:05:40.295 -> I2C device found at address 0x3C ! 12:05:40.295 -> done

But if i try to run the clock example, the code get stuck at : u8g2.begin();

Thanks!

@olikraus
Copy link
Owner

But if i try to run the clock example, the code get stuck at : u8g2.begin();

Looks like you need a 10K pullup resistor for the I2C bus.

@Alejandro13C
Copy link
Author

Hi,

I use a 10k pullup with external powersupply and the code is stuck at the same point.
:(

Regards,

@olikraus
Copy link
Owner

Hmm.. I never heard, that the "SW_I2C" can cause such trouble. Strange...

@Alejandro13C
Copy link
Author

Alejandro13C commented Oct 22, 2024

Hi Again,
I did again the code with all your indication.
And again i see the same issue.
At hw level i put 2k pull up reistir to SCL and SDA.
I tried to use this but it does not work
U8G2_SH1106_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,4,5, /* reset=*/ U8X8_PIN_NONE);

It seems that i lost the SDA and the Screen get frozen.
I put some prints and i see the issue in this point.
} while ( u8g2.nextPage() );

Code.

U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0,/* reset=*/ U8X8_PIN_NONE);
//U8G2_SH1106_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,4,5, /* reset=*/ U8X8_PIN_NONE);

void setup(void) {
  Serial.begin(115200);
  u8g2_SetI2CAddress(u8g2.getU8g2(), 0x3C * 2);
  u8g2.begin();
  //Display Renault Logo during 3 secs.
  Logo_Renault();

  //Only to test
  Battery_sensor = 780;
  Vdo_sensor = 170;
}

void loop(void) {
  //Only to test.
  Vdo_sensor++;

  // ADC.
  //Battery_sensor = analogRead(A0); //Read Analog battery sensor
  //Vdo_sensor = analogRead(A1); //Read Analog VDO sensor

  /* Conversion of counts --> batery voltage and counts --> oil pressure.*/
  Voltage = Battery_sensor * bit_volt; //Conversion from bit to volts to have the voltage divisor.
  Vbat = Voltage * k_bat; //Conversion from voltage divisor to Battery voltage.
  if(Vdo_sensor < 173 || Vdo_sensor > 800) { Vdo_sensor = 172; } //Limit of sensor 171 samples is 10 ohmios, 800 samples is 184 ohmios.
  Voltage_oil = Vdo_sensor * bit_volt; //Conversion from bit to volts to have the voltage divisor.
  Resistor_VDO = ((50.05*Voltage_oil)/(5.23-Voltage_oil)); // Resistence from the voltage divisor.
  Oil_pressure = (-0.471 + (0.0459*Resistor_VDO) + (3.79*pow(10.0,-5.0))*pow(Resistor_VDO,2.0) + ((1.16*pow(10.0,-7.0))*pow(Resistor_VDO,3.0))); //Funtion to conver resistence into pressure.
  
  SerialLogger();
  u8g2.firstPage();

  do
  {
    u8g2.setFont(u8g2_font_profont22_tf);	// choose a suitable font
    if(Vbat < 12.4) //If the battery is less than 12.4, show battery voltage.
    {
      dtostrf(Vbat, 4, 2, Battery_char); //Converts from float to const char
      u8g2.drawStr(35 , 60, Battery_char);
      u8g2.drawStr(85 , 60 , "V");
      u8g2.drawXBMP(48, 2, 40, 40, BatteryLogo);
    } else { // Else how Oil pressure value.
      dtostrf(Oil_pressure, 4, 2, OP_char);
      u8g2.drawStr(25,60, OP_char);
      u8g2.drawStr(75 , 60 , "Bar");
      u8g2.drawXBMP(48, 10, 32, 32, OilLogo);
    } 
  }while (u8g2.nextPage());
  delay(500);
}

//Functions to display Logos.
void Logo_Renault(void)
{
  // Display Reanult Logo during 10s
  u8g2.clearBuffer();
  u8g2.drawXBMP(0, 16, 128, 34, RenaultLogo);
  u8g2.sendBuffer();
  delay(2000);
  u8g2.clearBuffer(); // clear the internal memory
}

Update, i will check this constructor.

U8G2_SH1106_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants