Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@JChristensen
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JChristensen/745c8fdf8d034314b009 to your computer and use it in GitHub Desktop.
Save JChristensen/745c8fdf8d034314b009 to your computer and use it in GitHub Desktop.
Liquid Crystal Library Benchmark
//Liquid Crystal Library Benchmark
//Jack Christensen 21Jun2014
//Standard Arduino library http://arduino.cc/en/Reference/LiquidCrystal
//FMalpartida library http://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
//AFI library http://github.com/adafruit/LiquidCrystal
//Falcon Four library http://forums.adafruit.com/viewtopic.php?f=19&t=21586&p=113177
//Benchmark results, time to write 2 x 16-character lines to LCD.
//Run on 16MHz Arduino Uno compatible, Arduino v1.0.5.
//Library Mode Time Sketch Size
//Standard native 13ms 5656 bytes
//AFI native 13ms 7324
//FMalpartida native 4ms 6096
//AFI I2C 100kHz 131ms 7074
//Falcon Four I2C 100kHz 44ms 5626
//AFI I2C 400kHz 52ms 7080
//Falcon Four I2C 400kHz 15ms 5632
#include <LiquidCrystal.h> //Standard, FM, or AFI library
#include <LiquidTWI.h> //Falcon Four library
#include <Wire.h> //http://arduino.cc/en/Reference/Wire
#include <Streaming.h> //http://arduiniana.org/libraries/streaming/
//Choose one of the following lines:
LiquidCrystal lcd(5, 6, 7, 8, 9, 10); //Standard Arduino lib, FM lib, or AFI lib in native mode
//LiquidCrystal lcd(0); //AFI I2C -- i2c address 0 (0x20)
//LiquidTWI lcd(0); //falcon four lib -- i2c address 0 (0x20)
void setup(void)
{
unsigned long t1, t2, lcdLapse, serialLapse;
Serial.begin(115200);
lcd.begin(16, 2); //16 col x 2 rows
TWBR = 12; //400kHz I2C SCL
lcd.clear();
delay(1000);
t1 = millis();
lcd << "1234567890123456";
lcd.setCursor(0, 1);
lcd << "abcdefghijklmnop";
t2 = millis();
lcdLapse = t2 - t1; //benchmark time
Serial.println(lcdLapse);
t1 = millis();
Serial.println("1234567890123456");
Serial.println("abcdefghijklmnop");
t2 = millis();
serialLapse = t2 - t1; //serial time for comparison
Serial.println(serialLapse);
delay(1000);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(lcdLapse);
lcd.print(" ms ");
delay(1000);
}
void loop(void)
{
unsigned long t1, t2;
static unsigned long msLast;
unsigned long ms = millis();
if (ms - msLast >= 1000) {
msLast += 1000;
t1 = millis();
lcd.setCursor(0, 0);
lcd.print(ms);
t2 = millis();
lcd.setCursor(0, 1);
lcd.print(t2 - t1);
lcd.print(" ms ");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment