Problems when used with LiquidCrystal
Alftron opened this issue · 1 comments
I've got an issue using this library with the LiquidCrystal library. Below is the .ino file that I have uploaded to my Uno.
I'm getting corrupt/cycling data showing on the LCD after calling gen.Begin(). I've removed the section that sorts out the generator which fixes the problem, and reintroduced just the gen.Begin() line which messes up the LCD again.
I'm pretty sure i've got everything wired up as it should be. Is it a case of the two libraries clashing somehow? I'm a bit confused by it.
Thanks
#include <AD9833.h>
#include <digitalWriteFast.h>
#include <LiquidCrystal.h>
#define FNC_PIN 10
LiquidCrystal lcd(12, 7, 5, 4, 3, 2);
int Htime; //integer for storing high time
int Ltime; //integer for storing low time
float Ttime; // integer for storing total time of a cycle
float frequency; //storing frequency
// Declare the AD9833 object
AD9833 gen(FNC_PIN); // Defaults to 25MHz internal reference frequency
void setup()
{
pinMode(8,INPUT);
lcd.begin(16, 2);
gen.Begin(); // The loaded defaults are 1000Hz SINE_WAVE using REG0 with the output off
gen.SetWaveform(REG0,SQUARE_WAVE);
gen.SetFrequency(REG0,1000.0);
gen.EnableOutput(true); // Turn ON the output
}
void loop()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Frequency:");
Htime=pulseIn(8,HIGH); //read high time
Ltime=pulseIn(8,LOW); //read low time
Ttime = Htime+Ltime;
frequency=1000000/Ttime; //getting frequency with Ttime is in Micro seconds
lcd.setCursor(0,1);
lcd.print(frequency);
lcd.print(" Hz");
delay(2000);
}
Never mind, I've just figured it out. I believe it was because the LCD was using pin 12 which happens to be the MISO pin of the Uno. So when I was calling gen.Begin() which initialises all the SPI business, it caused this MISO pin to do SPI stuff which affected my LCD.
Changing LCD pin 12 to 9 has fixed my problem.
Thanks anyway.