OLED 2 button set point freezing constantly

I have put together a simple OLED display with an adjustable set point using 2 push buttons that use the internal pull up resistors.

The issue I have is that it will operate for 10-20 seconds then the screen will "freeze" on the set point I am currently at.

I haven't yet added code to view the serial monitor to see if it's the display or the Arduino just hoping there may be some suggestions or others have encountered it before?

I was thinking of setting up the push buttons with external pull up resistors but not entirely sure of any benefit in that if any as far as reliability goes.

Any suggestions would be great. I was thinking a good starting point would be to serial print the button states to verify a display fault.

Hi,
Code and circuit diagram would help.
What are you using to power your project.
Have you checked the supply voltage as the problem occurs?

Links to OLED spec/data and what model Arduino are you using?

Thanks.. Tom... :slight_smile:

Hi Code attached,

I'm using a duinotech LEONARDO.

I changed the circuit to use 2 X 10K resistors to GND and set the Inputs to switch on high. I Also checked the Serial print and I found that it will stay stable at the initial setpoint until either button is pushed, once this occurs it changes set point in the input direction. Once the button is let off the set point will climb by itself and doesn't stop??? If I hold the decrease it stays at the current valve until I let go of the decrease then it climbs again.....

// include OLED Library
#include "U8glib.h"

U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE);  // I2C / TWI 

//Key connections with arduino
const int up_key=3;
const int down_key=2;

 //Base Set Point
int SetPoint=30;


//====================================================================================
//                            SETUP
//====================================================================================

void setup() {

  //Set up Buttons as inputs
  pinMode(up_key,INPUT);
  pinMode(down_key,INPUT);
  
  //Setup for OLED Display
  u8g.setFont(u8g_font_unifont);
  
   // Instructs the display to draw with a pixel on.
  u8g.setColorIndex(1);

  //Initial Display loop for 10 seconds
  u8g.firstPage();
  do {  
    draw();    
  } while( u8g.nextPage() );
  delay(10000); 

  //Initialize Serial comms
  Serial.begin(9600);
  
}
  
void draw(){
  u8g.drawStr( 25, 20, "Sous Vide");

}

//====================================================================================
//                            LOOP
//==================================================================================== 

void loop() {
  //Get user input for setpoints  
  if(digitalRead(down_key)==HIGH)
  {
    if(SetPoint>0)
    {
      SetPoint--;
      delay(100);    
    }
  }
  if(digitalRead(up_key)==HIGH)
  {
    if(SetPoint<150)
    {
      SetPoint++;
      delay(100);
    }
  }
  
  
  u8g.firstPage();
  do {  
    draw2();    
  } while( u8g.nextPage() );
  
   
}
  
  void draw2(){
  u8g.drawStr( 0, 20, "Set Point");
  u8g.setPrintPos(75,20);
  u8g.print(SetPoint);
  delay(100); 
  Serial.println(SetPoint);
  delay(100);
    
}

Hi,
Fine on the code, but we need to see your circuit and how you have wired your components, in particular the buttons.

It looks like you are switching the digital input to 5V to get a HIGH input, do you have a 10K resistor on each of the inputs to gnd to get the input to go LOW when the switch is OFF?

Thanks.. Tom.. :slight_smile:

I have found through testing and adding a Serial print that only when the OLED is in the code there is an issue...

Any thoughts on a possible bug?