I found a way to get the LCD KeyPad to cooperate with my program. Sadly, it involves modifying a pin on the LCD (relocating RS data pin 8->3). I will post the program and some pics on what to modify soon.
/*******************************************************
This program will sample a 50-150hz signal depending on ethanol
content, and output a 0-5V signal via PWM.
Connect PWM output to NEMU Breakoutboard on ADC0-3, and tune
the "FLEX FUEL SETUP" tab accordingly. NOTE: Lowpass filter to
be used on output.
Input pin 8 (PB0) ICP1 on Atmega328
Output pin 3 PWM
If LCD Keypad shield is used, solder jumper from Pin 8 - Pin 2,
and snip leg from pin 8 http://i.imgur.com/KdlLmye.png
********************************************************/
// include the library code:
#include//LCD plugin
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 9, 4, 5, 6, 7); //LCD Keypad Shield
int inpPin = 8; //define input pin to 8
int outPin = 11; //define PWM output, possible pins with LCD are 3, 10 and 11 (UNO)
//int outPin2 = 3; //temporary PWM, for simulating 489HZ
//Define global variables
volatile uint16_t revTick; //Ticks per revolution
uint16_t pwm_output = 0; //integer for storing PWM value (0-255 value)
int HZ = 0; //unsigned 16bit integer for storing HZ input
int ethanol = 0; //Store ethanol percentage here
uint16_t voltage = 0; //store display millivoltage here (0-5000)
void setupTimer() // setup timer1
{
TCCR1A = 0; // normal mode
TCCR1B = 132; // (10000100) Falling edge trigger, Timer = CPU Clock/256, noise cancellation on
TCCR1C = 0; // normal mode
TIMSK1 = 33; // (00100001) Input capture and overflow interupts enabled
TCNT1 = 0; // start from 0
}
ISR(TIMER1_CAPT_vect) // PULSE DETECTED! (interrupt automatically triggered, not called by main program)
{
revTick = ICR1; // save duration of last revolution
TCNT1 = 0; // restart timer for next revolution
}
ISR(TIMER1_OVF_vect) // counter overflow/timeout
{ revTick = 0; } // Ticks per second = 0
void setup()
{
setupTimer();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Initial screen formatting
lcd.setCursor(0, 0);
lcd.print("Ethanol: %");
lcd.setCursor(0, 1);
lcd.print(" Hz mV");
}
void loop()
{
if (revTick > 0) // Avoid dividing by zero, sample in the HZ
{HZ = 62200 / revTick;} // 3456000ticks per minute, 57600 per second
else // 62200 per seconmd seems to be more accurate?
{HZ = 0;} //needs real sensor test to determine correct tickrate
//calculate ethanol percentage
if (HZ > 50) // Avoid dividing by zero
{ethanol = HZ-50;}
else
{ethanol = 0;}
if (ethanol > 100) // Avoid overflow in PWM
{ethanol = 100;}
//Screen calculations
pwm_output = 255 * (ethanol*0.01); //calculate output PWM for NEMU
voltage = ethanol*50; //calculate voltage (mV) for display
lcd.setCursor(10, 0);
lcd.print(ethanol);
lcd.setCursor(1, 1);
lcd.print(HZ);
lcd.setCursor(8, 1);
lcd.print(voltage);
//PWM output
analogWrite(outPin, pwm_output); //write the PWM value to output pin
//analogWrite(outPin2, 40); //489.9Hz test output
delay(100); //make screen more easily readable by not updating it too often
}