@mala, the forum is here if you need help
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
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!
ah ⦠my widescreen comments make a bit of mess of that sorry!
@mala, Iāll take a look tonight to see what I can find
@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:
- Like your change value code, only refresh display items which have changed
- 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.
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.
@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
@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.
@peekay123 Thanks for the help and offer of more!
Been very busy, so first chance to look at it properly today.
I worked through all the code of my project and basically re-jigged the main structure of it from your suggestionsā¦
It does 99.9% work flicker free now, with the small irritation being if I am updating a number that is more than one digit, for example stepping through 10 -> 18, then ā1ā will flicker whilst the 0 -> 8 are being updated.
This is of course is because Iām clearing the whole 2 digit space each time before writing the updated digit, I can see whatās causing it, so hopefully wonāt take me too long to figure out a fix.
This flicker becomes very noticable (to me) when dialing through large numbers, so iāll have to find a fix or itāll drive me mad
Cheers,
mala
@mala, if you share that portion of the code, I can try to advise
Hello,
I am new to the Photon world, and I just bought a Digole Color screen (1.44"). I used the DigoleSerialDisp library, and tried to use my screen. It kind of works The only thing is that when I print some text, it also prints the command (TT) before the string. Also, the ClearScreen command does not work and only prints "CL" on the screen. A small photo is worth a thousand words:
Have you ever seen that kind of problems or is it obvious that I missed something essential?
Here is my code for the setup part:
void setup()
{
Serial.begin(9600);
pinMode(A1, INPUT);
digole.begin();
delay(500);
digole.clearScreen();
delay(50);
digole.print("Hello World!");
delay(500);
digole.clearScreen();
delay(500);
digole.print("Second line test");
}
Thank you guys!
Pierre
@PierreKill, the Digole libraries have changed since the one you are using was last posted. Since the display resolution is larger now, their library uses 2 bytes per coordinate instead of one. I still have on my to-do list to port and post the latest. I may be able to do that this weekend.
Thank you @peekay123 ! That is a relief, it was making me crazy! The following code in the loop:
digole.print("Test");
delay(50);
digole.clearScreen();
delay(50);
gives this:
It is artistic in a way but definitely not what I was expecting!
Is it difficult to change the coordinate dimensions? How can I give a hand? Thanks again anyway!
Hi everybody.
I bought this article from digole : 2.6"--2.6" Serial: UART/I2C/SPI 320x240 IPS Display+Touchscreen DS320240CIPS-66T(CN)...
I can write and draw on the screen, all this work perfect but i'm unable to get touch position from it.
As soon as i send "RPNXYI" "RPNXYW" or "RPNXYC" the screen go darker and after dont want take any other command.
Here is a very small code that i use to do my test, no library, just the minimal :
void setup() {
//initialisation, backlight ON, ClearScreen
Wire.begin();
Wire.beginTransmission('\x27');
Wire.write("BL1");
Wire.write("CL");
Wire.endTransmission();
// Write HELLO WORLD on position 13,0
Wire.beginTransmission('\x27');
Wire.write("TP");
Wire.write(13);
Wire.write(0);
Wire.write("TTHELLO WORLD");
Wire.write(0);
Wire.endTransmission();
//Read a touchscreen click
Wire.beginTransmission('\x27');
Wire.write('RPNXYC');
Wire.endTransmission();
//Get position of click
Wire.requestFrom('\x27', 4); // request 6 bytes from slave device #2
while(Wire.available()) // slave may send less than requested
{
char c = Wire.read(); // receive a byte as character
}
// Write again HELLO WORLD on position 13,6
Wire.beginTransmission('\x27'); // transmit to slave device 27
Wire.write("TP");
Wire.write(13);
Wire.write(6);
Wire.write("TTHELLO WORLD");
Wire.write(0);
Wire.endTransmission();
}
void loop() {
}
any help welcome (and sry if my english is bad)
sry, i forgot to say that i work with Core.
I had same issue when the 0 caractĆØre was not send after the text.
the command is āTTā then the text then 0, if 0 not send, CL is like a text and is printed.
I have troubles making DigoleSerialDisp working with SPI ( https://github.com/pkourany/DigoleGeo )
It works perfectly as SoftwareSPI as DigoleSerialDisp mydisp(A4, A3, A2); but wont do anything with same wiring with hardware SPI
Any hint on that? Iām using mono OLED 128x64 0.96āā