Digole UART/I2C/SPI Display Library


#512

@bartjenniskens, the displays are from Digole :stuck_out_tongue:


#513

as @peekay123 posted they are from Digole, and I can highly recommend them, the colour OLED arrived absurdly fast… only 4 days from Canada to UK !


#514

I get errors if I copy-pase to WEB-IDE demo code


#515

@ryotsuke, which code are you copy-pasting to the web IDE? Which Digole display are you using?


#516

Recent github one. I located both errors.
Demo code uses digole.begin() but UART .h declaration is void begin(displayDims size), there is no displayDims mentions anywhere but in this line, so changing .h file to void begin(void) makes it compile
Demo code uses DigoleSerialDisp digole(115200); and it should be DigoleSerialDisp digole(&Serial1, 115200); to work


#517

@ryotsuke, when you “recent github one”, was that off my repo? Mine needs a slight fix in the demo for the include path. Timothy’s is somewhat dated and he is not longer maintaining it. Nonetheless, glad you got it working!


#518

By recent I mean one in top messag by @timb. Perhaps it(post) needs updating.


#519

@ryotsuke, @timb is no longer involved and is not maintaining the library. Timothy and I worked on the original. I’ll create an IDE version of my updated library and post it. Thanks for the heads up! BTW, Digole just introduced a new touch screen version of their color LCD displays. Check it out!


#520

Sorry to revive this thread again.

From the help here, I did eventually create a fully working system with menu using the Digole 16x2 LCD display

in UART mode/connection, this works really nicely but I thought I would try and pimp the system up and use my Digole full colour OLED Display which is also connected in UART mode… I get the most horrendous flickering with my code on this OLED.
Even with code stripped right down to test with just a couple of print lines and delays between I still get flicker
Have tried changing Baud rate right down as far as 9600…but still no luck.
Also tried it on an Arduino micro and have exactly the same problem

Has anyone got any ideas or seen anything similar ?

Cheers,
mala


#521

@mala, there could be a few reasons for the flicker, especially if you are using clearScreen() a lot instead of selective area fills. I have one of those displays. If you can share your code, I would be glad to take a look :smiley:


#522

Hi @peekay123 peeKay

I learnt the lesson with clearScreen() so not using it except in setup after the display starts up, so I can get rid of the digole start screen.
Instead I’m using a little “blanking” string of spaces to clear areas where there are variables that are frequently updated as user selects a value.

It will take a while for me to get code sample together as I had moved this project over to a arduino micro as I needed more i/o and had no real need for wi-fi. So I also am using just the arduino library "DigoleSerial"
supplied by digole not your DigoleGeo library.

more soon…


#523

@mala, I have used selective area fills to erase areas. I will have to benchmark which is faster (fill vs blanks). There is a new library from Digole due to the new larger color LCD displays which also include touch (!) I will be porting the geometry extensions to this new library since the display coordinates now require two bytes instead of one. Other members have voiced interest in a menu system so sharing yours would be great! :smiley:


#524

@peekay123 I am using the menubackend library at the moment and in reality only about 6 of the functions in it… so nothing special.
Having just got the spark out of a draw to sort this code , the damn thing won’t connect to my wifi now!

I may be some time…


#525

@mala, the forum is here if you need help :wink:


#526

Doh! had forgotten I had changed wifi channel on router months ago when my neighbour got some fullspectrum BT deathstar of a router and parked it 2m from my desk!

connected now :wink:


#527

Right here’s a test, using your DigoleGeo.cpp and .h , not that I think this is essentially any different to me using the digole serial library on the arduino… i.e I don’t think the library is the problem.More likely my terrible skills!

Two things shown here:
1- to avoid flickering as much as possible i put the first bit of text writing in the setup and then just update the values that change (I can not do that in the actual full code of course as there are many menus and variables within to change) if you connect some buttons and play it may seem to work but look closely at numbers on teh second line when they get over 3 figures.

2- there is a basic print test (uncomment and comment out areas shwon) with large delays between each line… this flickers like mad and shows what basically happens in my main application code when using the OLED but not the 16x2 LCD…

code:

//Digole OLED TestSketch

#define _Digole_Serial_UART_
#include "DigoleGeo.h"                           // Digole Display Comms settings
DigoleSerialDisp mydisp(&Serial1, 115200);

// button pin def
const int leftButton = D0;
const int rightButton = D1;
const int enterButton = D2;
const int escButton = D3;

// variables

int outSelect = 0;
int outValue = 0;
int lastOutValue = 0;
int lastOutSelect = 0;

// Button input variables - for debouncing mostly

bool right;
bool left;
bool enter;
bool escape;

int lastButtonPushed = 0;
bool lastEnterState = LOW;
bool lastEscState = LOW;
bool lastLeftState = LOW;
bool lastRightState = LOW;

long lastEnterDebounceTime = 0;
long lastEscDebounceTime = 0;
long lastLeftDebounceTime = 0;
long lastRightDebounceTime = 0;
long debounceDelay = 100;

long lastLeftHoldTime = 0;
long lastRightHoldTime = 0;
long holdDelay = 2500;

bool rightButtonHeld = HIGH;
bool leftButtonHeld = HIGH;
bool lastLeftHeldState = HIGH;
bool lastRightHeldState = HIGH;

//Menu-Helper
bool osLineHelp = 0;
const char milliBlank[] = "     ";



 //////////////////////////////////////////////////////////   
 
void setup() 
{   
    pinMode(leftButton, INPUT_PULLUP);
    pinMode(rightButton, INPUT_PULLUP);
    pinMode(enterButton, INPUT_PULLUP);
    pinMode(escButton, INPUT_PULLUP);
    
   
    mydisp.begin();                             // Start display up
    mydisp.clearScreen();                       // Get rid of Digole Start up Screen
    
    
    mydisp.drawStr(0,0, "OUTPUT");              // some basic starting text + values
    mydisp.setPrintPos(10,0);
    mydisp.print(outSelect);
    mydisp.drawStr(0,1, "Level");
    mydisp.setPrintPos(10,1);
    mydisp.print(outValue);
    
    
    
    //mydisp.clearScreen();   // uncomment for "pure print test"
}

////////////////////////////////////////////////////////////

void loop() {
    
    readButtons ();  //comment out for "pure print test"
    changeValues();  //comment out for "pure print test"
    //printTest();            // uncomment to use
}


///////////////////////////////////////////////////////
void printTest() {
delay(150);                                      // I don't want these delays, but just to demo that it flickers even with a large delay between print calls
  mydisp.drawStr(0,0,"Testing");
  delay(150);
  mydisp.drawStr(0,1,"One");
  delay(150);
  mydisp.drawStr(0,2,"Two");
}

/////////////////////////////////////////////////////////

void changeValues() {
  
  byte stepSize = 1;
  
  if(osLineHelp == 0) {              // line help -- press enter button and we jump to editing values on next line
      if(right == true) {
        if(outSelect == 11) {        // roll the values over / round
          outSelect = 0;
        }else {
          outSelect ++ ;
        }
      }else if(left == true) {
        if(outSelect == 0) {
          outSelect = 11;
        }else {
          outSelect -- ;
        } 
      }else if(enter == true) {
        osLineHelp = 1;
      }else if(escape == true) {
        osLineHelp = 0;
      }
      
  }else if(osLineHelp == 1) {
        if(right == true) {
          if(((outValue % 10) == 0) && (rightButtonHeld == LOW)) {      // if we are on a number divisible by 10 AND button is held start steeping in 10's
            stepSize = 10;
          }else stepSize = 1;
          if(outValue == 1000) {
            outValue = 0;
          }else {
            outValue = outValue + stepSize ;
          }
        }else if(left == true) {
          if(((outValue % 10) == 0) && (leftButtonHeld == LOW)) {
            stepSize = 10;
          }else stepSize = 1;
          if(outValue ==  0) {
            outValue = 1000;
          }else {
            outValue = outValue - stepSize;
          }
        }else if(enter == true) {
          osLineHelp = 0;
        }else if(escape == true) {
          osLineHelp = 0;
        }
   }if(outSelect != lastOutSelect) {
    mydisp.setPrintPos(10,0);
    mydisp.print(milliBlank);
    mydisp.setPrintPos(10,0);
    mydisp.print(outSelect);
  }if(outValue != lastOutValue) {
    mydisp.setPrintPos(10,1);
    mydisp.print(milliBlank);
    mydisp.setPrintPos(10,1);
    mydisp.print(outValue);
  } 
  
  lastOutValue = outValue;
  lastOutSelect = outSelect;
 
}

//////////////////////////////////////////////////////////////

void readButtons() {
  
  
  int reading;
  bool buttonEnterState = HIGH;
  bool buttonEscState = HIGH;
  bool buttonLeftState = HIGH;
  bool buttonRightState = HIGH;
  
  
  //Enter button
  reading = digitalRead(enterButton);                            // read the button
  if(reading != lastEnterState) {                          // see if its state has changed since last time
    lastEnterDebounceTime = millis();                            // if it has changed state then restart timer at current time
  }
  
  if((millis() - lastEnterDebounceTime) > debounceDelay) {        // if current time minus the time we last checked is greater than debounce delay
    buttonEnterState = reading;                                   // then current reading of the button is it's intended state ... i.e it was a button press and not bouncing
    lastEnterDebounceTime = millis();                             // reset saved time/check to current time for next time
  }
  lastEnterState = reading;                                 // save the state of the button for next time round
  
  
  //Esc button
  reading = digitalRead(escButton);
  if(reading != lastEscState) {
    lastEscDebounceTime = millis();
  }
  
  if ((millis() - lastEscDebounceTime) > debounceDelay) {
    buttonEscState = reading;
    lastEscDebounceTime = millis();
  }
  lastEscState = reading;
  
  
  //Right (or Down)Button
  reading = digitalRead(rightButton);                    
  if(reading != lastRightState) {                  
   lastRightDebounceTime = millis();                                                         
  } 
  if ((millis() - lastRightDebounceTime) > debounceDelay) {          
    buttonRightState = reading;                                     
    lastRightDebounceTime = millis();                                
  }
  lastRightState = reading;                                    
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  reading = digitalRead(rightButton);                               //Total bodge to get a button "Held" output, to then use for increment/decrement in 10's
  if(reading != lastRightHeldState) {
    rightButtonHeld = !reading;
    lastRightHoldTime = millis();
  }
  if((millis() - lastRightHoldTime) > holdDelay) {
    rightButtonHeld = reading;
    lastRightHoldTime = millis();
  }
  lastRightHeldState = reading;
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////                                
  
  
  //Left ( or Up) Button
  reading = digitalRead(leftButton);
  if(reading != lastLeftState)  {
    lastLeftDebounceTime = millis();
  }
  if((millis() - lastLeftDebounceTime) > debounceDelay) {
    buttonLeftState = reading;
    lastLeftDebounceTime = millis();
  }
  lastLeftState = reading;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
  reading = digitalRead(leftButton);                           //Total bodge to get a button "Held" output, to then use for increment/decrement in 10's
  if(reading != lastLeftHeldState) {                           
    leftButtonHeld = !reading;
    lastLeftHoldTime = millis();
  }
  if((millis() - lastLeftHoldTime) > holdDelay) {
    leftButtonHeld = reading;
    lastLeftHoldTime = millis();
  }
  lastLeftHeldState = reading;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
  
  // Record which button has been pressed
  if(buttonEnterState == LOW) {
    lastButtonPushed = enterButton;
    enter = true;
    escape = false;
    right = false;
    left = false;
    
  }else if(buttonEscState == LOW) {
    lastButtonPushed = escButton;
    enter = false;
    escape = true;
    right = false;
    left = false;
    
  }else if(buttonRightState == LOW) {
    lastButtonPushed = rightButton;
    enter = false;
    escape = false;
    right = true;
    left = false;
    
  }else if(buttonLeftState == LOW) {
    lastButtonPushed = leftButton;
    enter = false;
    escape = false;
    right = false;
    left = true;
    
  }else {
    lastButtonPushed = 0 ;
    enter = false;
    escape = false;
    right = false;
    left = false;
  }
  
} 

Please point out where i’m being stupid! :smile:

ah … my widescreen comments make a bit of mess of that sorry!


#528

@mala, I’ll take a look tonight to see what I can find :smile:


#529

@mala, I ran your code on a Core with the code as is. Without the print test, there was no flickering whatsoever when changing values. I removed the blocking delay() from printTest() and call it using a non-blocking delay in loop() like this:

void loop() {
    readButtons ();  //comment out for "pure print test"
        changeValues();  //comment out for "pure print test"
        if(millis() - del >= 150) {
          printTest();            // uncomment to use
          del = millis();
        }
}

This created less flicker on the text being displayed via printTest(). So why does the menu text not flicker but printTest() does? You already have the answer:

  1. Like your change value code, only refresh display items which have changed
  2. Don’t update your display at the speed of loop(). In my code, I update some items faster than others and then only when their value changes. I use non-blocking timers (as above) to create 100ms, 500ms and 1sec timers that update different parts of the screen at different intervals. By staggering your updates in time, less data goes to the Digole meaning its receive buffer doesn’t have a chance to overflow so display operation will be smooth.

Also remember that you are debouncing your keys for 100ms so any display items related to that should not be refreshed any faster than that.

As far as using drawBox() versus printing spaces to erase areas prior to refreshing them, you will have to determine what’s best for you. The drawBox() command uses less chars to send and lets me clear an entire area in one command. I lay out my display data accordingly to make things simper. :smile:

BTW: You can use drawBox() and set use setMode("^") (XOR) to draw an inverting box around the menu item text to show it is selected. Very easy to use.


#530

@peekay123, thank you for having a look and the advice.

testing the no-blocking delay example with the printTest, I’m still getting a bit of jittery flickering on the OLED… it is an improvement, though I’m quite surprised that the buffer on the OLED seems so small and unable to cope, in comparison to the LCD backpack version… even with these very basic and pretty slow screen updates.

I will go through my main code now and work your advice in to how I update the display and investigate using the drawBox rather than spaces to erase areas.

Thanks!
mala


#531

@mala, The Digole input buffer is 2048 bytes but you also have to consider the command processing time. If you want to share your code, I can take a look and make suggestions. :smile: