Fox82
August 1, 2017, 4:02pm
#1
Dear Forum,
this is the standard code to use the display. This one is working.
#include <Arduino.h>
#include <SPI.h>
#include <U8g2lib.h>
U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=/ U8X8_PIN_NONE, / clock=/ SCL, / data=*/ SDA);
void setup(void) {
u8g2.begin();
}
void loop(void) {
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.drawStr(0,20,"Hello World!");
} while ( u8g2.nextPage() );
delay(1000);
}
Problem is, when I use the code outside of main for example in int vector like this then it is not working and the display is freezing.
ISR(INT1_vect) {
int display_test (void){
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.firstPage();
do {
u8g2.drawStr(0,20,"INT1 on");
} while( u8g2.nextPage() );
}
}
I didn’t had the problem with the old lib u8g. I also asked the u8g2lib developer. But he said it is a code issue by arduino.
opened 07:56AM - 23 Jul 17 UTC
closed 06:19PM - 28 Jul 17 UTC
Dear u8g2 supporters,
Why is this code for me working,
`
#include <Arduin… o.h>
#include <SPI.h>
#include <U8g2lib.h>
U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA);
void setup(void) {
u8g2.begin();
}
void loop(void) {
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.drawStr(0,20,"Hello World!");
} while ( u8g2.nextPage() );
delay(1000);
}
`
and this one is not working! Display is blank. This is a big issue for me because with the switch from u8g to u8g2lib Display is not woring any more for my project.
`
#include <Arduino.h>
#include <SPI.h>
#include <U8g2lib.h>
U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA);
int main (void) {
u8g2.begin();
while(1){
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.drawStr(0,20,"Hello World1");
} while ( u8g2.nextPage() );
delay(1000);
}
}
`
What do I wrong?
One reason could be this:
If the above display output requires 150ms and your interrupt is generated evey 100ms, then it will not work: A new interrupt is already generated before the previous interrupt finished.
Oliver