Skip to content

Strange behaviour with u8g library #1

@igi79

Description

@igi79

I just discovered very strange behaviour in arduino sketch run when libraries AdaEncoder and u8g are used in the same time.
Following testing sketch runs correctly only time after it is written to Atmega328p (ICSP). but only until the AVR is first time turned off. Runs after powercycle seems to hangs in some reset loop in AdaEncoder::addEncoder.
Reset doesn't cause this, only power on/off cycle.
I tested this with 2 different displays (SPI and I2C), multiple arduinos and bare atmega328p avrs and encoder connected many different pin combination. After power cycle, this program always hangs in 'addEncoder' - it newer comes to setup function (tested with LED on digitalWrite(13, HIGH);)
The strange thing is that it works fine after ICSP programming.

#include "U8glib.h"
#include <ooPinChangeInt.h>
#include <AdaEncoder.h>

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);  // I2C / TWI
AdaEncoder encoderA = AdaEncoder('a', 6, 7);

int8_t clicks=0;
char id=0;

void setup()
{
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  u8g.setColorIndex(1);
}

void loop() 
{  
  u8g.firstPage();  
  do {
    draw();
  } while( u8g.nextPage() );
  updateClicks();
}

void updateClicks(){
  AdaEncoder *thisEncoder=NULL;
  thisEncoder=AdaEncoder::genie();
  clicks += thisEncoder->query();
}

void draw(void) {
  u8g.setFont(u8g_font_unifont);
  u8g.setPrintPos(16, 16);
  u8g.print(clicks);
}

(tested with lates u8g and ooPinChangeInt libraries)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions