Arduino Uno, 0.96" I2C OLED Display running too slow to capture button Presses

Hello all,

I am looking for a little guidance. I am an armature at programming. I am working on making an arduino powered box mod for vaping. I am using an Uno and an I2C oled display and have the display library and ButtonClick library included. The problem I am experiencing is that when the various regions of the display are all enabled and updating, the code is running too slowly (it appears) to capture the button presses. As I disable one section at a time, the serial output speeds up and starts catching some of the button presses, and when the majority are disabled it works fine. Ive tried this code on a mega to rule out memory issues and I experience the same problems. What could be causing this?

And the code is?

Usually best way to speed up things is to not display something if it has not changed. Are you testing for this or always displaying everything in the loop?

I am an armature at programming.

Do you expect to progress to rotor and then alternator?

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

Every time you refresh the display, you have to push over 1KiB of data over the I²C connection. This takes a lot of time. You can reduce the time by increasing the I²C clock speed:
https://www.arduino.cc/en/Reference/WireSetClock

Pieter

Thank you all for your suggestions.

J-M-L:
And the code is?

Usually best way to speed up things is to not display something if it has not changed. Are you testing for this or always displaying everything in the loop?

Could you please show me an example of how to implement this?

PieterP:
Every time you refresh the display, you have to push over 1KiB of data over the I²C connection. This takes a lot of time. You can reduce the time by increasing the I²C clock speed:
Arduino - WireSetClock

Pieter

Thank you, I will be reading up on this later tonight.

Here is a snippet of the code displaying. the function is in loop and i can see how its constantly updating.

void DisplayBattery() {
//code for displaying battery 1 and 2 "battery bars"
 myOLED.drawRect(4, 53, 53, 57); //batt 1 rect      X,Y,x,y
 myOLED.drawRect(54, 54, 55, 56);  //batt1 nub
  myOLED.drawRect(4, 59, 53, 63); //batt 2 rect      X,Y,x,y
 myOLED.drawRect(54, 60, 55, 62);  //batt 2 nub
 myOLED.update();


//batt1
if (Batt1Percent >= 0 && Batt1Percent <= 10) {

myOLED.clrLine(5,54,53,54);
myOLED.clrLine(5,55,53,55);
myOLED.clrLine(5,56,53,56);   //print 0 battery block

myOLED.update();
}


else if (Batt1Percent > 10 && Batt1Percent <= 40) {
myOLED.drawLine(5,54,16,54);
myOLED.drawLine(5,55,16,55);  //batt1 bar
myOLED.drawLine(5,56,16,56);
  
myOLED.clrLine(17,54,53,54);
myOLED.clrLine(17,55,53,55);
myOLED.clrLine(17,56,53,56);                                    //print 1 battery blocks

myOLED.update();
}


else if (Batt1Percent > 40 && Batt1Percent <= 60) {

myOLED.drawLine(5,54,28,54);
myOLED.drawLine(5,55,28,55);  //batt1 bar
myOLED.drawLine(5,56,28,56);
  
myOLED.clrLine(29,54,53,54);
myOLED.clrLine(29,55,53,55);
myOLED.clrLine(29,56,53,56);                                      //print 2 battery blocks

myOLED.update();
}

else if (Batt1Percent > 60 && Batt1Percent <= 80) {
myOLED.drawLine(5,54,40,54);
myOLED.drawLine(5,55,40,55);  //batt1 bar
myOLED.drawLine(5,56,40,56);                                    

myOLED.clrLine(41,54,53,54);
myOLED.clrLine(41,55,53,55);
myOLED.clrLine(41,56,53,56);

myOLED.update() ;                                   //print 3 battery blocks
}

else if (Batt1Percent > 80 && Batt1Percent <= 100) {

myOLED.drawLine(5,54,53,54);
myOLED.drawLine(5,55,53,55);  //batt1 bar
myOLED.drawLine(5,56,53,56);   //print 4 battery blocks
myOLED.update();
}



//batt 2
if (Batt2Percent >= 0 && Batt2Percent <= 10) {
                    //print 0 battery block
myOLED.clrLine(5,60,53,60);
myOLED.clrLine(5,61,53,61);
myOLED.clrLine(5,62,53,62);
myOLED.update();
                    
}
else if (Batt2Percent > 10 && Batt2Percent <= 40) {

myOLED.drawLine(5,60,16,60);
myOLED.drawLine(5,61,16,61);   //bat2 bar
myOLED.drawLine(5,62,16,62);

myOLED.clrLine(17,60,53,60);
myOLED.clrLine(17,61,53,61);
myOLED.clrLine(17,62,53,62);

myOLED.update();
   //print 1 battery blocks
}


else if (Batt2Percent > 40 && Batt2Percent <= 60) {
myOLED.drawLine(5,60,28,60);
myOLED.drawLine(5,61,28,61);   //bat2 bar
myOLED.drawLine(5,62,28,62);

myOLED.clrLine(29,60,53,60);
myOLED.clrLine(29,61,53,61);
myOLED.clrLine(29,62,53,62);

myOLED.update();                                //print 2 battery blocks
}

Here is a very terrible schematic of the design. =)

Hi,
We need to see your complete code.
If it is too big fr code tags, please attach it as an .ino file.

Can I suggest you forget trying use a graphics program, and get pen and paper out and draw your circuit, label all components and connections. Keep your wires as straight lines and do not use diagonal wires.
This may take time, but worth it.

What does your code do?

Thanks.. Tom... :slight_smile:

My code is largely incomplete as its still in its infancy stage. I started out making the basic functions and have yet to put them together for the most part. I am also still waiting for parts for testing and am still trying out button libraries and I2C libraries. That is when I hit this “dead end” I am working on.

I will attach it. Maybe you can provide me some insight.

Basically the code monitors battery voltage through a voltage divider and will check the amps of the coil (this part is not written yet) and calculate the ohms of the coil. The user will select a preferred wattage which i am hoping to store in eeprom. For input there will be three buttons. an up button, a down button, and a fire button. The Fire button will “fire” if held, store wattage, wake the display, and poll the amps on single clicks, three clicks will lock the wattage from being adjusted accidentally, and 5 clicks will sleep the device. the up and down buttons are for selecting the wattage and will increase the rate that numbers increment the longer its held.

upon firing the code will calculate the correct voltage to pwm to make the output the desired watts. A number of safety checks will be implement as well. For instance it will not fire if the coil is shorted or open, it will shutdown if the battery becomes critically low, and it will not allow it to fire for longer than 10 seconds as that usually happens in the users pockets.

Asgard_v1.00.ino (20.1 KB)