LCD16X2 breaks interrupts on Leonardo R3 board

Started by kc4ums, July 23, 2014, 06:17:55 PM

Previous topic - Next topic

kc4ums

I have a Arduino Leonardo R3 board with the following test code for an interrupt.  The interrupt works fine until the LCD16x2 is plugged in. The LCD16x2 is working when messages are written to it. 

Am I missing something ??

Thanks Tim



int iPinIn1 = 2; // Digital Input pin 2
int iPinOut1 = 8; // Digital Output pin 8

void setup(){
  pinMode(iPinIn1, INPUT_PULLUP);
  pinMode(iPinOut1, OUTPUT);     
  digitalWrite(iPinOut1, HIGH);
  attachInterrupt(3, pinChange, CHANGE);
}

//ISR
void pinChange(){
  digitalWrite(iPinOut1, LOW);
}

void loop(){
  delay(3000);
  digitalWrite(iPinOut1, HIGH);
}

LubOlimex

Hello kc4ums,

Did you test with the default Arduino demo pack for the board? It might be downloaded from here: https://www.olimex.com/Products/Duino/Shields/SHIELD-LCD16x2/resources/Olimexino-328+LCD16x2.zip

There are instructions inside on where the files should be placed.

Best regards,
Lub/OLIMEX
Technical support and documentation manager at Olimex

kc4ums

Yes the demos work fine.  It is only when I try to use an interrupt do I notice any problems.  When it exits the interrupt the main loop will not pick-up where it was interrupted (the main loop is not restarted).   This occurs with the above test program and when using one of the demos and adding an interrupt to the code.
The attached code works fine until the interrupt occurs by bringing pin 2 low.  The reset button must then be pressed on the Arduino to get it working again.   

Thanks Tim 


#include <LCD16x2.h>
#include <Wire.h>

LCD16x2 lcd;

int buttons;
int iPinIn1 = 2; // Digital Input pin 2
int iPinOut1 = 8; // Digital Output pin 8

void setup(){
 
   Wire.begin();

  lcd.lcdClear();
 
  lcd.lcdGoToXY(2,1);
  lcd.lcdWrite("BUT1:");
 
  lcd.lcdGoToXY(10,1);
  lcd.lcdWrite("BUT2:");
 
  lcd.lcdGoToXY(2,2);
  lcd.lcdWrite("BUT3:");
 
  lcd.lcdGoToXY(10,2);
  lcd.lcdWrite("BUT4:");
 
  pinMode(iPinIn1, INPUT_PULLUP);
  pinMode(iPinOut1, OUTPUT);     
  digitalWrite(iPinOut1, HIGH);
  attachInterrupt(3, pinChange, CHANGE);
}

//ISR                             
void pinChange(){
  digitalWrite(iPinOut1, LOW);
}

void loop(){
 
   
  digitalWrite(iPinOut1, HIGH);
 
  buttons = lcd.readButtons();
 
  lcd.lcdGoToXY(7,1);
  if(buttons & 0x01) 
    lcd.lcdWrite("0");
  else
    lcd.lcdWrite("1");
   
  lcd.lcdGoToXY(15,1);
  if(buttons & 0x02) 
    lcd.lcdWrite("0");
  else
    lcd.lcdWrite("1");
   
  lcd.lcdGoToXY(7,2);
  if(buttons & 0x04) 
    lcd.lcdWrite("0");
  else
    lcd.lcdWrite("1");
   
  lcd.lcdGoToXY(15,2);
  if(buttons & 0x08) 
    lcd.lcdWrite("0");
  else
    lcd.lcdWrite("1");
   
  delay(100);

 
}