first commit
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
https://lcd4linux.bulix.org/
|
||||
https://lcd4linux.bulix.org/wiki/Displays
|
||||
https://github.com/ZivaVatra/ArduLCD
|
||||
@@ -0,0 +1,150 @@
|
||||
static const int dummyvar = 0; // dummy declaration for older broken IDEs!!!!
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDcharset - simple demonstration to show character set font in LCD
|
||||
// Created by Bill Perry 2018-01-06
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// sketch displays the character for all the character codes 0x00 to 0xff
|
||||
// miniture digits are assigned to the custom character codepoints corresponding
|
||||
// to the codepoint value. i.e.
|
||||
// codepoint 0 is assigned miniture '0' character.
|
||||
// codepoint 1 is assigned miniture '1' character. etc...
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// History
|
||||
// 2018.01.06 bperrybap - Original creation
|
||||
//
|
||||
// @author Bill Perry - bperrybap@opensource.billsworld.billandterrie.com
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#ifndef HD44780_LCDOBJECT
|
||||
|
||||
#error "Special purpose sketch: Use i/o class example wrapper sketch instead."
|
||||
|
||||
/*
|
||||
* If not using a hd44780 library i/o class example wrapper sketch,
|
||||
* you must modify the sketch to include any needed header files for the
|
||||
* intended library and define the lcd object.
|
||||
*
|
||||
* Add your includes and constructor.
|
||||
* The lcd object must be named "lcd"
|
||||
* and comment out the #error message.
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
// ============================================================================
|
||||
// user configurable options below this point
|
||||
// ============================================================================
|
||||
|
||||
|
||||
/*
|
||||
* Define LCD size
|
||||
* 16x2 will work ok on larger displays but if you want the frame rate
|
||||
* for the full LCD geometry, define that here
|
||||
* Note: these can be (and are) overridden by defines in a wrapper sketch.
|
||||
*/
|
||||
#ifndef LCD_COLS
|
||||
#define LCD_COLS 16
|
||||
#endif
|
||||
|
||||
#ifndef LCD_ROWS
|
||||
#define LCD_ROWS 2
|
||||
#endif
|
||||
|
||||
|
||||
// minature digits
|
||||
// To be used for the Custom characters
|
||||
const PROGMEM uint8_t minidigit[10][8] = {
|
||||
{0x07,0x05,0x05,0x05,0x07,0x00,0x00,0x00}, // minature 0
|
||||
{0x02,0x06,0x02,0x02,0x07,0x00,0x00,0x00}, // minature 1
|
||||
{0x03,0x05,0x02,0x04,0x07,0x00,0x00,0x00}, // minature 2
|
||||
{0x07,0x01,0x07,0x01,0x07,0x00,0x00,0x00}, // minature 3
|
||||
{0x05,0x05,0x07,0x01,0x01,0x00,0x00,0x00}, // minature 4
|
||||
{0x07,0x04,0x06,0x01,0x07,0x00,0x00,0x00}, // minature 5
|
||||
{0x07,0x04,0x07,0x05,0x07,0x00,0x00,0x00}, // minature 6
|
||||
{0x07,0x01,0x02,0x04,0x04,0x00,0x00,0x00}, // minature 7
|
||||
{0x07,0x05,0x07,0x05,0x07,0x00,0x00,0x00}, // minature 8
|
||||
{0x07,0x05,0x07,0x01,0x01,0x00,0x00,0x00}, // minature 9
|
||||
};
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
int status;
|
||||
|
||||
// initialize LCD with number of columns and rows:
|
||||
// hd44780 returns a status from begin() that can be used
|
||||
// to determine if initalization failed.
|
||||
// the actual status codes are defined in <hd44780.h>
|
||||
// See the values RV_XXXX
|
||||
//
|
||||
// looking at the return status from begin() is optional
|
||||
// it is being done here to provide feedback should there be an issue
|
||||
//
|
||||
// note:
|
||||
// begin() will automatically turn on the backlight
|
||||
//
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
status = -status; // convert negative status value to positive number
|
||||
|
||||
// begin() failed so blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// initalization was successful, the backlight should be on now
|
||||
if(LCD_COLS > 8)
|
||||
lcd.print("LCD ");
|
||||
|
||||
lcd.print("Charset");
|
||||
|
||||
// Fill in the 8 custom characters with miniture digits
|
||||
// so they can be seen in the character set
|
||||
for(uint8_t i=0; i < 8; i++)
|
||||
lcd.createChar(i, minidigit[i]); // mini digit matching each codepoint
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
void loop(void)
|
||||
{
|
||||
static int c = 0;
|
||||
|
||||
lcd.clear();
|
||||
if(LCD_COLS>15)
|
||||
lcd.print("Codes 0");
|
||||
lcd.print("x");
|
||||
lcd.print(c, HEX);
|
||||
lcd.print("-0x"); lcd.print(c+LCD_COLS-1, HEX);
|
||||
|
||||
if(LCD_ROWS > 1)
|
||||
{
|
||||
lcd.setCursor(0, 1);
|
||||
for(int col = 0; col < LCD_COLS; col++)
|
||||
lcd.write(' ');
|
||||
lcd.setCursor(0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
delay(2000);
|
||||
lcd.clear();
|
||||
}
|
||||
|
||||
|
||||
for(int j=0; j<LCD_COLS; j++)
|
||||
{
|
||||
lcd.write((uint8_t)(c));
|
||||
if(++c > 255)
|
||||
{
|
||||
c = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
delay(4000);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,347 @@
|
||||
static const int dummyvar = 0; // dummy declaration for older broken IDEs!!!!
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDiSpeed - LCD Interface Speed test
|
||||
// Copyright 2012-2020 Bill perry
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// LCDiSpeed is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation version 3 of the License.
|
||||
//
|
||||
// LCDiSpeed is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with LCDiSpeed. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// Sketch to measure and report the speed of the interface to the LCD and
|
||||
// speed of updating the LCD.
|
||||
// It should work on any LCD library that is LiquidCrystal API compatible.
|
||||
//
|
||||
// It runs a Frames/Sec (FPS) test which writes a "frame" of each digit 0-9 to
|
||||
// the display.
|
||||
// A "frame" is a full display of characters.
|
||||
// It is created by positioning the cursor to the begining of each row
|
||||
// and then writing a character to every position on the row, until the
|
||||
// entire display is filled.
|
||||
// The FPS test does a frame of 9's then 8's, .... down to 0's
|
||||
// On fast interfaces it will not normally be seen.
|
||||
//
|
||||
// The sketch will then calculate & report transfer speeds and
|
||||
// LCD update rates to the LCD display.
|
||||
//
|
||||
// Reported Information:
|
||||
// - Single byte transfer speed (ByteXfer)
|
||||
// This is the time it takes for a single character to be sent from
|
||||
// the sketch to the LCD display.
|
||||
//
|
||||
// - Frame/Sec (FPS)
|
||||
// This is the number of times the full display can be updated
|
||||
// in one second.
|
||||
//
|
||||
// - Frame Time (Ftime)
|
||||
// This is the amount of time it takes to update the full LCD display.
|
||||
//
|
||||
// The sketch will also report "independent" FPS and Ftime values.
|
||||
// These are timing values that are independent of the LCD size under test.
|
||||
// Currently they represent the timing for a 16x2 LCD
|
||||
// The value of always having numbers for a 16x2 display
|
||||
// is that these numbers can be compared to each other since they are
|
||||
// independent of the size of the actual LCD display that is running the test.
|
||||
// i.e. you also get 16x2 timing information even if the display is not 16x2
|
||||
//
|
||||
// All times & rates are measured and calculated from what a sketch "sees"
|
||||
// using the LCD library API.
|
||||
// It includes any/all s/w overhead including the time to go through the
|
||||
// Arduino Print class and LCD library.
|
||||
// The actual low level hardware times are obviously lower.
|
||||
//
|
||||
// History
|
||||
// 2018.03.23 bperrybap - bumped default instruction time to 38us
|
||||
// 2016.04.14 bperrybap - slimmed down for inclusion as hd44780 example
|
||||
// 2013.09.01 bperrbap - refactored to make it easier to select interface
|
||||
// 2013.06.01 bperrybap - added support for I2C class and ADAFRUIT i2c/spi board
|
||||
// 2012.03.15 bperrybap - Original creation
|
||||
//
|
||||
// @author Bill Perry - bperrybap@opensource.billsworld.billandterrie.com
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Define your LCD size
|
||||
* 16x2 will work ok on larger displays but if you want the frame rate
|
||||
* for the full LCD geometry, define that here
|
||||
*/
|
||||
#ifndef LCD_COLS
|
||||
#define LCD_COLS 16
|
||||
#endif
|
||||
|
||||
#ifndef LCD_ROWS
|
||||
#define LCD_ROWS 2
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef HD44780_LCDOBJECT
|
||||
|
||||
#error "Special purpose sketch: Use i/o class example wrapper sketch instead."
|
||||
|
||||
/*
|
||||
* If not using a hd44780 library i/o class example wrapper sketch,
|
||||
* you must modify the sketch to include any needed header files for the
|
||||
* intended library and define the lcd object.
|
||||
*
|
||||
* Add your includes and constructor.
|
||||
* The lcd object must be named "lcd"
|
||||
* and comment out the #error message.
|
||||
*/
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
// ============================================================================
|
||||
// user configurable options below this point
|
||||
// ============================================================================
|
||||
|
||||
// if you have a slow display uncomment these defines
|
||||
// to override the default execution times.
|
||||
// CHEXECTIME is the execution time for clear and home commands
|
||||
// INSEXECTIME is the execution time for everything else; cmd/data
|
||||
// times are in Us
|
||||
// NOTE: if using, you must enable both
|
||||
// Although each display can have seperate times, these values will be used
|
||||
// on all displays.
|
||||
|
||||
//#define LCD_CHEXECTIME 2000
|
||||
//#define LCD_INSEXECTIME 38
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*
|
||||
* LCDiSpeed Options (normally should not need to change these)
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
#define FPS_iter 1 // number of iterations to repeat each "frame" within the
|
||||
// test (current frame test is 10 full display frames,
|
||||
// 1 for each digits 0-9)
|
||||
// FPS_iter like 100 will allow the frames to be seen
|
||||
// Note: the only reason other than visual to make this
|
||||
// larger than 1 might be to compensate for Async serial
|
||||
// buffering should a serial interface be tested
|
||||
// even with 1 iteration, 340 bytes are written for a
|
||||
// 16x2 display
|
||||
// bytes written =
|
||||
// FPS_iter * ((LCD_ROWS * LCD_COLS) + LCD_ROWS) * 10
|
||||
|
||||
#define iLCD // calculate speed of "independent" sized display
|
||||
#define iLCD_ROWS 2 // independent FPS row size
|
||||
#define iLCD_COLS 16 // independent FPS col size
|
||||
|
||||
|
||||
#define DELAY_TIME 3500 // delay time to see information on lcd
|
||||
|
||||
// ============================================================================
|
||||
// End of user configurable options
|
||||
// ============================================================================
|
||||
|
||||
unsigned long timeFPS(uint8_t iter, uint8_t cols, uint8_t rows);
|
||||
void showFPS(unsigned long etime, int cols, int rows, const char *fpstype);
|
||||
void showByteXfer(unsigned long FPStime);
|
||||
void fatalError(int ecode);
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
// set up the LCD's number of columns and rows:
|
||||
// with hd44780 library,
|
||||
// set execution times & check for initializatin failure
|
||||
#if defined(hd44780_h)
|
||||
|
||||
// set custom exectution times if configured
|
||||
#if defined(LCD_CHEXECTIME) && defined(LCD_INSEXECTIME)
|
||||
lcd.setExecTimes(LCD_CHEXECTIME, LCD_INSEXECTIME);
|
||||
#endif
|
||||
|
||||
|
||||
if(lcd.begin(LCD_COLS, LCD_ROWS))
|
||||
{
|
||||
// begin() failed so blink the onboard LED if possible
|
||||
fatalError(1); // this never returns
|
||||
}
|
||||
|
||||
// NOTE: Can't check initalization status on other libraries
|
||||
// NOTE: fm's LiquidCrystal_I2C class and other LiquidCrystal_I2C
|
||||
// classes define LiquidCrystal_I2C_h, but they don't initialize the
|
||||
// the same way. We check for I2CIO use when checking for
|
||||
// LiquidCrystal_I2C use to see which "LiquidCrystal_I2C" is
|
||||
// is being used since fm's uses begin() while all the others use init()
|
||||
//
|
||||
#elif defined(LiquidCrystal_I2C_h) && !defined(_I2CIO_H_)
|
||||
lcd.init();
|
||||
lcd.backlight(); // LiquidCrystal_I2C does not turn on backlight by default.
|
||||
#elif defined(LCDISPEED_CALL_CUSTOM_LCDINIT)
|
||||
custom_LCDinit(); // code is in LCDiSpeed wrapper sketch (this is FUGLY!!!)
|
||||
#else
|
||||
lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
#endif
|
||||
|
||||
#ifdef WIRECLOCK
|
||||
#if defined(WIRE_HAS_SETCLOCK) || ((ARDUINO >= 157) && !defined(MPIDE))
|
||||
Wire.setClock(WIRECLOCK); // set i2c clock bit rate, if asked
|
||||
#else
|
||||
#error attempting to use Wire.setClock on IDE that does not support it
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined (WIRE_HAS_GETCLOCK)
|
||||
lcd.print("i2c clock:");
|
||||
lcd.setCursor(0,1);
|
||||
lcd.print(Wire.getClock());
|
||||
lcd.print(" Hz");
|
||||
delay(3000);
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
unsigned long etime;
|
||||
|
||||
delay(10); // delay to ensure no previous commands still pending
|
||||
|
||||
/*
|
||||
* Time an FPS test
|
||||
*/
|
||||
|
||||
etime = timeFPS(FPS_iter, LCD_COLS, LCD_ROWS);
|
||||
|
||||
/*
|
||||
* show the average single byte xfer time during the FPS test
|
||||
*/
|
||||
showByteXfer(etime);
|
||||
|
||||
/*
|
||||
* show FPS rate and Frame update time for this display
|
||||
*/
|
||||
|
||||
showFPS(etime, LCD_COLS, LCD_ROWS, 0);
|
||||
|
||||
#ifdef iLCD
|
||||
/*
|
||||
* If the size of the display is not size of the "standad"
|
||||
* display, calculate Independent FPS and Frame update time
|
||||
* (rate & time for a "standard" display - default of 16x2)
|
||||
* This is simply a matter of scaling the time based on the
|
||||
* ratio of the display sizes.
|
||||
*/
|
||||
|
||||
if((iLCD_COLS != LCD_COLS) || (iLCD_ROWS != LCD_ROWS))
|
||||
{
|
||||
etime = etime *iLCD_ROWS * iLCD_COLS / LCD_ROWS / LCD_COLS;
|
||||
|
||||
/*
|
||||
* show independent FPS rate & Frame update time
|
||||
*/
|
||||
showFPS(etime, iLCD_COLS, iLCD_ROWS, "i");
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
unsigned long timeFPS(uint8_t iter, uint8_t cols, uint8_t rows)
|
||||
{
|
||||
char c;
|
||||
unsigned long stime, etime;
|
||||
|
||||
stime = micros();
|
||||
for(c = '9'; c >= '0'; c--) // do not change this unless you change the FPS/ByteXfer calcuations as well
|
||||
{
|
||||
for(uint8_t i = 0; i < iter; i++)
|
||||
{
|
||||
for(uint8_t row = 0; row < rows; row++)
|
||||
{
|
||||
lcd.setCursor(0, row);
|
||||
for(uint8_t col = 0; col< cols;col++)
|
||||
{
|
||||
lcd.write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
etime = micros();
|
||||
return((etime-stime));
|
||||
}
|
||||
void showFPS(unsigned long etime, int cols, int rows, const char* fpstype)
|
||||
{
|
||||
float fps;
|
||||
|
||||
|
||||
/*
|
||||
* calculate Frame update time and FPS rate
|
||||
* The 10.0 is for the 10 frames done per iteration
|
||||
* one for each digit 0-9
|
||||
*/
|
||||
|
||||
fps = (10.0 * FPS_iter) * 1000000.0/(etime);
|
||||
|
||||
|
||||
lcd.clear();
|
||||
lcd.print(cols);
|
||||
lcd.print('x');
|
||||
lcd.print(rows);
|
||||
if(fpstype)
|
||||
lcd.print(fpstype);
|
||||
lcd.print("FPS:");
|
||||
if(fps < 1000)
|
||||
lcd.print(" ");
|
||||
lcd.print(fps, 2);
|
||||
|
||||
if(LCD_ROWS > 1)
|
||||
{
|
||||
lcd.setCursor(0,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
delay(DELAY_TIME);
|
||||
lcd.clear();
|
||||
}
|
||||
if(fpstype)
|
||||
lcd.print(fpstype);
|
||||
lcd.print("Ftime: ");
|
||||
lcd.print((etime)/10.0/FPS_iter/1000);
|
||||
lcd.print("ms");
|
||||
|
||||
delay(DELAY_TIME);
|
||||
}
|
||||
void showByteXfer(unsigned long FPStime)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("ByteXfer:");
|
||||
|
||||
/*
|
||||
* Calculate average byte xfer time from time of FPS test
|
||||
* This takes into consideration the set cursor position commands (1 per row) which
|
||||
* are single byte commands and take the same amount of time as a data byte write.
|
||||
* The final result is rounded up to an integer.
|
||||
*/
|
||||
lcd.print((int) (FPStime / (FPS_iter * (10.0 * (LCD_COLS * LCD_ROWS + LCD_ROWS)))+0.5));
|
||||
lcd.print("uS");
|
||||
|
||||
delay(DELAY_TIME); // show it for a while
|
||||
}
|
||||
// fatalError() - loop & blink and error code
|
||||
void fatalError(int ecode)
|
||||
{
|
||||
#if defined(hd44780_h)
|
||||
// if using hd44780 library use built in fatalError()
|
||||
hd44780::fatalError(ecode);
|
||||
#else
|
||||
if(ecode){} // dummy if statement to remove warning about not using ecode
|
||||
while(1)
|
||||
{
|
||||
delay(1); // delay to prevent WDT on some cores
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,720 @@
|
||||
static const int dummyvar = 0; // dummy declaration for older broken IDEs!!!!
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDLibTest - LCD library Test sketch
|
||||
// Copyright 2012-2020 Bill perry
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// LCDlibTest is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation version 3 of the License.
|
||||
//
|
||||
// LCDlibTest is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with LCDLibTest. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// Sketch to measure and report the speed of the interface to the LCD and
|
||||
// speed of updating the LCD as well as test some of the library extensions
|
||||
// for hardware control like backlight control.
|
||||
//
|
||||
// It runs a Frames/Sec (FPS) test which writes a "frame" of each digit 0-9 to
|
||||
// the display.
|
||||
// A "frame" is a full display of characters.
|
||||
// It is created by positioning the cursor to the begining of each row
|
||||
// and then writing a character to every position on the row, until the
|
||||
// entire display is filled.
|
||||
// The FPS test does a frame of 9's then 8's, .... down to 0's
|
||||
// On fast interfaces it will not normally be seen.
|
||||
//
|
||||
// The sketch will then calculate & report transfer speeds and
|
||||
// LCD update rates to the LCD display.
|
||||
//
|
||||
// Reported Information:
|
||||
// - Single byte transfer speed (ByteXfer)
|
||||
// This is the time it takes for a single character to be sent from
|
||||
// the sketch to the LCD display.
|
||||
//
|
||||
// - Frame/Sec (FPS)
|
||||
// This is the number of times the full display can be updated
|
||||
// in one second.
|
||||
//
|
||||
// - Frame Time (Ftime)
|
||||
// This is the amount of time it takes to update the full LCD display.
|
||||
//
|
||||
//
|
||||
// The sketch will also report "independent" FPS and Ftime values.
|
||||
// These are timing values that are independent of the size of the LCD under test.
|
||||
// Currently they represent the timing for a 16x2 LCD
|
||||
// The value of always having numbers for a 16x2 display
|
||||
// is that these numbers can be compared to each other since they are
|
||||
// independent of the size of the actual LCD display that is running the test.
|
||||
//
|
||||
// All times & rates are measured and calculeted from what a sketch "sees"
|
||||
// using the LiquidCrystal API.
|
||||
// It includes any/all s/w overhead including the time to go through the
|
||||
// Arduino Print class and LCD library.
|
||||
// The actual low level hardware times are obviously lower.
|
||||
//
|
||||
// History
|
||||
// 2018.03.23 bperrybap - bumped default instruction time to 38us
|
||||
// 2012.04.01 bperrybap - Original creation
|
||||
//
|
||||
// @author Bill Perry - bperrybap@opensource.billsworld.billandterrie.com
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#ifndef HD44780_LCDOBJECT
|
||||
|
||||
#error "Special purpose sketch: Use i/o class example wrapper sketch instead."
|
||||
|
||||
/*
|
||||
* If not using a hd44780 library i/o class example wrapper sketch,
|
||||
* you must modify the sketch to include any needed header files for the
|
||||
* intended library and define the lcd object.
|
||||
*
|
||||
* Add your includes and constructor.
|
||||
* The lcd object must be named "lcd"
|
||||
* and comment out the #error message.
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
// ============================================================================
|
||||
// user configurable options below this point
|
||||
// ============================================================================
|
||||
|
||||
|
||||
/*
|
||||
* Define your LCD size
|
||||
* 16x2 will work ok on larger displays but if you want the frame rate
|
||||
* for the full LCD geometry, define that here
|
||||
* Note: if these can be overridden by defines in a wrapper sketch.
|
||||
*/
|
||||
#ifndef LCD_COLS
|
||||
#define LCD_COLS 16
|
||||
#endif
|
||||
|
||||
#ifndef LCD_ROWS
|
||||
#define LCD_ROWS 2
|
||||
#endif
|
||||
|
||||
// if you have a slow display uncomment these defines
|
||||
// to override the default execution times.
|
||||
// CHEXECTIME is the execution time for clear and home commands
|
||||
// INSEXECTIME is the execution time for everything else; cmd/data
|
||||
// times are in Us
|
||||
// NOTE: if using, you must enable both
|
||||
// Although each display can have seperate times, these values will be used
|
||||
// on all displays.
|
||||
|
||||
//#define LCD_CHEXECTIME 2000
|
||||
//#define LCD_INSEXECTIME 38
|
||||
|
||||
|
||||
/*
|
||||
* LCDlibTest Options (normally shouldn not need to change these)
|
||||
*/
|
||||
|
||||
|
||||
//#define SINGLEWAVE // different "wave" style
|
||||
#define SLOWERWAVE // slow down wave speed
|
||||
#define DELAY_TIME 3500
|
||||
#define DEBUGPRINT // turn on serial debug messages
|
||||
|
||||
#define TIMEBYTE // turn on code that times a byte transfer
|
||||
#define TIMEFPS // turn on code that calculates FPS
|
||||
#define FPS_iter 5 // number of iterations to repeat each frame
|
||||
// FPS_iter larger than about 1 allows the test to be seen
|
||||
#define iLCD_ROWS 2 // independent FPS row size
|
||||
#define iLCD_COLS 16 // independent FPS col size
|
||||
|
||||
#define TRACKTIME // turn on code that displays elapsed time
|
||||
#define STATUSBARS // turn on status bars on left & right
|
||||
|
||||
// ============================================================================
|
||||
// End of user configurable options
|
||||
// ============================================================================
|
||||
|
||||
|
||||
// Turn on extra stuff for certain libraries
|
||||
//
|
||||
|
||||
#if defined(hd44780_h) || defined(LiquidCrystal_I2C_h) || (defined(_LCD_H_) && defined(FOUR_BITS) && defined(BACKLIGHT_ON))
|
||||
#define ONOFFCMDS // If on() and off() commands exist
|
||||
#define SETBACKLIGHTCMD // if setbacklight() exists
|
||||
#define BACKLIGHTCMDS // if backlight()/noBacklight() exist
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
// Data format is for each custom character is 8 bytes
|
||||
// Pixels within the bytes is as follows:
|
||||
// lowest byte is at top, MSB of byte is on right
|
||||
// only lower 5 bits of each byte is used.
|
||||
|
||||
|
||||
// Data for a set of new characters for a bargraph
|
||||
// start with 1 underbar and add additional bars until full 5x8 block
|
||||
|
||||
const uint8_t charBitmap[][8] = {
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f}, // char 0
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f}, // char 1
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f}, // char 2
|
||||
{0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f}, // char 3
|
||||
{0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}, // char 4
|
||||
{0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}, // char 5
|
||||
{0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}, // char 6
|
||||
{0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}, // char 7
|
||||
};
|
||||
/*
|
||||
* prototypes
|
||||
*/
|
||||
|
||||
char animchar(int col, int iter);
|
||||
void showFPS(unsigned long etime, const char *type);
|
||||
unsigned long timeFPS(uint8_t iter, uint8_t cols, uint8_t rows);
|
||||
void showByteXfer(Print &dev, unsigned long FPStime);
|
||||
void fatalError(int ecode);
|
||||
|
||||
void setup()
|
||||
{
|
||||
int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));
|
||||
unsigned long etime;
|
||||
|
||||
|
||||
#ifdef DEBUGPRINT
|
||||
Serial.begin(9600);
|
||||
#if (ARDUINO > 101)
|
||||
do
|
||||
{
|
||||
// wait on serial port to be ready but timout out after 3 seconds
|
||||
// this is for sytems that use virtual serial over USB.
|
||||
if(millis() > 3000) // millis starts at 0 after reset
|
||||
break;
|
||||
delay(10); // easy way to allow some cores to call yield()
|
||||
} while(!Serial);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// set up the LCD's number of columns and rows:
|
||||
// with hd44780 library,
|
||||
// set execution times & check for initializatin failure
|
||||
#if defined(hd44780_h)
|
||||
|
||||
// set custom exectution times if configured
|
||||
#if defined(LCD_CHEXECTIME) && defined(LCD_INSEXECTIME)
|
||||
lcd.setExecTimes(LCD_CHEXECTIME, LCD_INSEXECTIME);
|
||||
#endif
|
||||
|
||||
|
||||
if(lcd.begin(LCD_COLS, LCD_ROWS))
|
||||
{
|
||||
// begin() failed so blink the onboard LED if possible
|
||||
fatalError(1); // this never returns
|
||||
}
|
||||
|
||||
// NOTE: Can't check initalization status on other libraries
|
||||
// NOTE: fm's LiquidCrystal_I2C class and other LiquidCrystal_I2C
|
||||
// classes define LiquidCrystal_I2C_h, but they don't initialize the
|
||||
// the same way. We check for I2CIO use when checking for
|
||||
// LiquidCrystal_I2C use to see which "LiquidCrystal_I2C" is
|
||||
// is being used since fm's uses begin() while all the others use init()
|
||||
//
|
||||
#elif defined(LiquidCrystal_I2C_h) && !defined(_I2CIO_H_)
|
||||
lcd.init();
|
||||
#else
|
||||
lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
#endif
|
||||
|
||||
#ifdef DEBUGPRINT
|
||||
Serial.println("LCD initialized");
|
||||
#endif
|
||||
|
||||
#ifdef WIRECLOCK
|
||||
#if (ARDUINO >= 157) && !defined(MPIDE)
|
||||
Wire.setClock(WIRECLOCK); // set i2c clock bit rate, if asked
|
||||
#else
|
||||
#error attempting to use Wire.setClock on IDE that does not support it
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// create the custom bargraph characters
|
||||
for ( int i = 0; i < charBitmapSize; i++ )
|
||||
{
|
||||
lcd.createChar ( i, (uint8_t *)charBitmap[i] );
|
||||
}
|
||||
|
||||
// must do something like set cursor postion after defining chars
|
||||
// on most libraries (not hd44780)
|
||||
// to reset address back to display ram
|
||||
lcd.setCursor(0,0);
|
||||
|
||||
|
||||
#if defined(TIMEBYTE) || defined(TIMEFPS)
|
||||
#ifdef DEBUGPRINT
|
||||
Serial.println("Byte timing test");
|
||||
#endif
|
||||
delay(10); // delay to ensure no previous commands still pending
|
||||
etime = timeFPS(FPS_iter, LCD_COLS, LCD_ROWS);
|
||||
lcd.clear();
|
||||
#endif
|
||||
|
||||
#ifdef TIMEBYTE
|
||||
// show the average single byte xfer time during the FPS test
|
||||
showByteXfer(lcd, etime);
|
||||
#ifdef DEBUGPRINT
|
||||
showByteXfer(Serial, etime);
|
||||
Serial.println();
|
||||
#endif
|
||||
delay(DELAY_TIME); // show it for a while
|
||||
lcd.clear();
|
||||
#endif
|
||||
|
||||
#ifdef TIMEFPS
|
||||
// calculate Frame update time and FPS rate for this display
|
||||
showFPS(etime, " ");
|
||||
|
||||
/*
|
||||
* If the size of the display is not size of the "standad"
|
||||
* display, calculate Independent FPS and Frame update time
|
||||
* (rate & time for a "standard" display - default of 16x2)
|
||||
* This is simply a matter of scaling the time based on the
|
||||
* ratio of the display sizes.
|
||||
*/
|
||||
|
||||
if((iLCD_COLS != LCD_COLS) || (iLCD_ROWS != LCD_ROWS))
|
||||
{
|
||||
etime = etime *iLCD_ROWS * iLCD_COLS / LCD_ROWS / LCD_COLS;
|
||||
|
||||
/*
|
||||
* show independent FPS rate & Frame update time
|
||||
*/
|
||||
showFPS(etime, "i");
|
||||
}
|
||||
|
||||
|
||||
lcd.clear();
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SETBACKLIGHTCMD
|
||||
|
||||
// If using hd44780 library check to see if controlling backlight is possible
|
||||
#if defined(hd44780_h)
|
||||
|
||||
// try to turn on the backlight
|
||||
// if it fails then backlight control isn't possible
|
||||
if(lcd.setBacklight(-1))
|
||||
{
|
||||
#ifdef DEBUGPRINT
|
||||
Serial.println("LCD API 1.0 setBacklight() not supported");
|
||||
#endif
|
||||
goto skip_dimmingBL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef DEBUGPRINT
|
||||
Serial.println("Dimming Backlight");
|
||||
#endif
|
||||
|
||||
// Print a message to the LCD.
|
||||
lcd.print(" Dimming BL");
|
||||
|
||||
// soft blink the backlight 3 times by ramping down then back up
|
||||
// Hardware that does not support dimming will see the backlight as full on
|
||||
// during this test.
|
||||
for(int times = 0; times < 3; times++)
|
||||
{
|
||||
for(int x = 1; x < 16; x++)
|
||||
{
|
||||
lcd.setBacklight(256-x * 16);
|
||||
delay(45);
|
||||
}
|
||||
for(int x = 1; x < 16; x++)
|
||||
{
|
||||
lcd.setBacklight(x * 16);
|
||||
delay(45);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#ifdef DEBUGPRINT
|
||||
Serial.println("No LCD API 1.0 setBacklight() function");
|
||||
#endif
|
||||
#endif // SETBACKLIGHTCMD
|
||||
|
||||
skip_dimmingBL:
|
||||
|
||||
// Need cursor functions here
|
||||
// ul cusor
|
||||
// blk cursor
|
||||
// ul cursor blink
|
||||
// blk cursor blink
|
||||
// cursorLeft()
|
||||
// cursofRight()
|
||||
lcd.clear();
|
||||
lcd.print("cursor");
|
||||
#ifdef DEBUGPRINT
|
||||
Serial.println("cursor");
|
||||
#endif
|
||||
lcd.cursor();
|
||||
delay(DELAY_TIME); // show it for a while
|
||||
|
||||
lcd.clear();
|
||||
lcd.print("Cursor Blink");
|
||||
#ifdef DEBUGPRINT
|
||||
Serial.println("Cursor Blink");
|
||||
#endif
|
||||
lcd.cursor();
|
||||
lcd.blink();
|
||||
delay(DELAY_TIME); // show it for a while
|
||||
lcd.noCursor();
|
||||
delay(DELAY_TIME); // show it for a while
|
||||
lcd.noBlink();
|
||||
|
||||
|
||||
#ifdef BACKLIGHTCMDS
|
||||
#ifdef DEBUGPRINT
|
||||
Serial.println("Blinking Backlight");
|
||||
#endif
|
||||
// If using hd44780 library check to see if controlling backlight is possible
|
||||
#if defined(hd44780_h)
|
||||
|
||||
// try to turn on the backlight
|
||||
// if it fails then backlight control isn't possible
|
||||
if(lcd.setBacklight(-1))
|
||||
{
|
||||
#ifdef DEBUGPRINT
|
||||
Serial.println("LCD API 1.0 backlight()/noBacklight() not supported");
|
||||
#endif
|
||||
goto skip_blinkBL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
lcd.home();
|
||||
lcd.print(" Blinking BL");
|
||||
for(int x = 1; x < 5; x++)
|
||||
{
|
||||
delay(500);
|
||||
#ifdef DEBUGPRINT
|
||||
Serial.println("Backlight OFF");
|
||||
#endif
|
||||
lcd.noBacklight(); // turns off backlight but leaves pixels on
|
||||
delay(500);
|
||||
#ifdef DEBUGPRINT
|
||||
Serial.println("Backlight On");
|
||||
#endif
|
||||
lcd.backlight();
|
||||
}
|
||||
#else
|
||||
#ifdef DEBUGPRINT
|
||||
Serial.println("No LCD API 1.0 backlight()/noBacklight() functions");
|
||||
#endif
|
||||
#endif // BACKLIGHTCMDS
|
||||
|
||||
skip_blinkBL:
|
||||
|
||||
lcd.home();
|
||||
lcd.print(" Pixels on/off");
|
||||
for(int x = 1; x < 5; x++)
|
||||
{
|
||||
delay(500);
|
||||
lcd.noDisplay(); // turns off display pixels, not backlight
|
||||
delay(500);
|
||||
lcd.display(); // turns on display pixels
|
||||
}
|
||||
|
||||
#ifdef later
|
||||
#ifdef ONOFFCMDS
|
||||
lcd.home();
|
||||
lcd.print(" On/Off Test ");
|
||||
for(int x = 1; x < 5; x++)
|
||||
{
|
||||
delay(500);
|
||||
lcd.off(); // turns off both display pixels and backlight
|
||||
delay(500);
|
||||
lcd.on(); // turns on both display pixels and backlight
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
lcd.clear();
|
||||
lcd.print(" Scroll Right ");
|
||||
delay(700);
|
||||
for(int x = 0; x < LCD_COLS/2; x++)
|
||||
{
|
||||
delay(300);
|
||||
lcd.scrollDisplayRight();
|
||||
}
|
||||
lcd.clear();
|
||||
lcd.print(" Scroll Left ");
|
||||
delay(700);
|
||||
for(int x = 0; x < LCD_COLS/2; x++)
|
||||
{
|
||||
delay(300);
|
||||
lcd.scrollDisplayLeft();
|
||||
}
|
||||
|
||||
#ifdef DEBUGPRINT
|
||||
Serial.println("setup() done");
|
||||
#endif
|
||||
|
||||
lcd.clear();
|
||||
#ifndef TRACKTIME
|
||||
lcd.print(" Animations");
|
||||
#ifdef DEBUGPRINT
|
||||
Serial.println("Animations");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#ifdef TRACKTIME
|
||||
void PrintTime(Print &dev, uint8_t hr, uint8_t min, uint8_t sec)
|
||||
{
|
||||
// print time in HH:MM:SS format
|
||||
// Print class does not support fixed width formatting
|
||||
// so insert a zero if number smaller than 10
|
||||
if(hr < 10)
|
||||
dev.write('0');
|
||||
dev.print((int)hr);
|
||||
dev.write(':');
|
||||
if(min < 10)
|
||||
dev.write('0');
|
||||
dev.print((int)min);
|
||||
dev.write(':');
|
||||
if(sec < 10)
|
||||
dev.write('0');
|
||||
dev.print((int)sec);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
static int loopcount = 0;
|
||||
#ifdef TRACKTIME
|
||||
static unsigned long lastsecs;
|
||||
unsigned long secs;
|
||||
|
||||
secs = millis() / 1000;
|
||||
if(secs != lastsecs)
|
||||
{
|
||||
uint8_t hr;
|
||||
int min;
|
||||
uint8_t sec;
|
||||
|
||||
lastsecs = secs;
|
||||
min = secs / 60;
|
||||
|
||||
hr = min / 60;
|
||||
|
||||
min = min % 60;
|
||||
|
||||
sec = secs % 60;
|
||||
|
||||
lcd.setCursor(4,0);
|
||||
PrintTime(lcd, hr, (uint8_t)min, sec);
|
||||
#ifdef DEBUGPRINT
|
||||
PrintTime(Serial, hr, (uint8_t)min, sec);
|
||||
Serial.println();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef STATUSBARS
|
||||
/*
|
||||
* Update Status "bars"
|
||||
* 2 up/down bars out of phase with each other.
|
||||
*/
|
||||
|
||||
lcd.setCursor(0,0);
|
||||
lcd.write(animchar(0, loopcount/16));
|
||||
lcd.write(animchar(7, loopcount/16));
|
||||
|
||||
lcd.setCursor(LCD_COLS -2,0);
|
||||
lcd.write(animchar(7, loopcount/16));
|
||||
lcd.write(animchar(0, loopcount/16));
|
||||
#endif
|
||||
|
||||
if(LCD_ROWS > 1)
|
||||
{
|
||||
/*
|
||||
* Draw Wave
|
||||
*/
|
||||
lcd.setCursor(0, 1);
|
||||
for ( int c = 0; c < LCD_COLS; c++ )
|
||||
{
|
||||
lcd.write(animchar(c, loopcount));
|
||||
}
|
||||
}
|
||||
#ifdef SLOWERWAVE
|
||||
delay(35);
|
||||
#endif
|
||||
|
||||
loopcount++;
|
||||
|
||||
}
|
||||
|
||||
#if defined(SINGLEWAVE)
|
||||
char animchar(int col, int iter)
|
||||
{
|
||||
int c;
|
||||
|
||||
if(col > 7)
|
||||
{
|
||||
col = (char)( (15 -col) & 7);
|
||||
}
|
||||
|
||||
#if 1
|
||||
if((iter % 64) > 31)
|
||||
{
|
||||
if((iter % 32) > 15)
|
||||
{
|
||||
c = (col + 7 -(iter & 0xf)); // fall down from the edge
|
||||
}
|
||||
else
|
||||
{
|
||||
c = 7 - col -7 + (iter & 0xf); // rise up from the edge
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if((iter % 32) > 15)
|
||||
{
|
||||
c = (7 - col + 7 -(iter & 0xf)); // fall down from the middle
|
||||
}
|
||||
else
|
||||
{
|
||||
c = col -7 + (iter & 0xf); // rise up from the middle
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(c > 7)
|
||||
c = 7;
|
||||
|
||||
if(c < 0)
|
||||
c = 0;
|
||||
|
||||
return(char(c));
|
||||
}
|
||||
#else
|
||||
char animchar(int col, int iter)
|
||||
{
|
||||
int c;
|
||||
col &= 0xf;
|
||||
|
||||
if(col > 7)
|
||||
{
|
||||
col = (char)( (15 -col) & 7);
|
||||
}
|
||||
|
||||
c = (col + (iter & 0xf)) & 0xf;
|
||||
|
||||
if(c > 7)
|
||||
{
|
||||
c = 15 - c;
|
||||
}
|
||||
return((char) c);
|
||||
}
|
||||
#endif
|
||||
|
||||
unsigned long timeFPS(uint8_t iter, uint8_t cols, uint8_t rows)
|
||||
{
|
||||
char c;
|
||||
unsigned long stime, etime;
|
||||
|
||||
stime = micros();
|
||||
for(c = '9'; c >= '0'; c--) // do not change this unless you change the FPS calcuation as well
|
||||
{
|
||||
for(uint8_t i = 0; i < iter; i++)
|
||||
{
|
||||
for(uint8_t row = 0; row < rows; row++)
|
||||
{
|
||||
lcd.setCursor(0, row);
|
||||
for(uint8_t col = 0; col< cols;col++)
|
||||
{
|
||||
lcd.write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
etime = micros();
|
||||
return((etime-stime));
|
||||
}
|
||||
void showFPS(unsigned long etime, const char *type)
|
||||
{
|
||||
float fps;
|
||||
|
||||
|
||||
/*
|
||||
* calculate Frame update time and FPS rate
|
||||
*/
|
||||
|
||||
fps = (10.0 * FPS_iter) * 1000000.0/(etime);
|
||||
|
||||
|
||||
lcd.clear();
|
||||
lcd.print(" ");
|
||||
lcd.print(type);
|
||||
lcd.print("FPS: ");
|
||||
lcd.print(fps);
|
||||
|
||||
if(LCD_ROWS > 1)
|
||||
{
|
||||
lcd.setCursor(0,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
delay(DELAY_TIME);
|
||||
lcd.clear();
|
||||
}
|
||||
lcd.print(type);
|
||||
lcd.print("Ftime: ");
|
||||
lcd.print((etime)/10.0/FPS_iter/1000);
|
||||
lcd.print("ms");
|
||||
|
||||
delay(DELAY_TIME);
|
||||
}
|
||||
void showByteXfer(Print &dev, unsigned long FPStime)
|
||||
{
|
||||
dev.print("ByteXfer:");
|
||||
|
||||
/*
|
||||
* Calculate average byte xfer time from time of FPS test
|
||||
* This takes into consideration the set cursor position commands
|
||||
* (1 per row) which are single byte commands and take the same amount of
|
||||
* time as a data byte write.
|
||||
* The final result is rounded up to an integer.
|
||||
*/
|
||||
dev.print((int) (FPStime / (FPS_iter * (10.0 * (LCD_COLS * LCD_ROWS + LCD_ROWS)))+0.5));
|
||||
dev.print("uS");
|
||||
}
|
||||
|
||||
// fatalError() - loop & blink and error code
|
||||
void fatalError(int ecode)
|
||||
{
|
||||
#if defined(hd44780_h)
|
||||
// if using hd44780 library use built in fatalError()
|
||||
hd44780::fatalError(ecode);
|
||||
#else
|
||||
if(ecode){} // dummy if statement to remove warning about not using ecode
|
||||
while(1)
|
||||
{
|
||||
delay(1); // delay to prevent WDT on some cores
|
||||
}
|
||||
#endif
|
||||
}
|
||||
31
libraries/hd44780/examples/hd44780examples/README.md
Normal file
31
libraries/hd44780/examples/hd44780examples/README.md
Normal file
@@ -0,0 +1,31 @@
|
||||
hd44780examples
|
||||
===============
|
||||
|
||||
The examples in this directory are not really example sketches.<br>
|
||||
**They should not be looked at as examples for how to use the library.**<br>
|
||||
They are special purpose sketches that are used as include files for the i/o class examples.
|
||||
These sketches allow using a "wrapper sketch" to define the lcd object
|
||||
and lcd geometry which then includes the hd44780 example sketch as an
|
||||
alternative to having to edit the actual sketch.
|
||||
While these sketches can be modified to work standalone with any LiquidCrystal API compatible library, their primary purpose, as shipped in the hd44780 library package, is to act as an include file for the i/o class wrapper sketches and are not intended to be used directly.
|
||||
**See the ioClass specific subdirectories for the examples for each ioClass.**
|
||||
|
||||
#### The following special purpose sketches are provided:
|
||||
- `LCDcharset`<br>
|
||||
Shows the entire character set of the LCD.
|
||||
Miniture digits are used to show the custom characters.
|
||||
|
||||
- `LCDisSpeed`<br>
|
||||
Shows the speed of writing characters to the display.
|
||||
It shows the transfer time of an individual character as well as updating
|
||||
the full display. If the geometry is different than 16x2 it will also show what the full display timing would be if the display were 16x2.
|
||||
Since the sketch can work on many different libraries and h/w, it is useful for ccomparing the speed of various libraries and LCD h/w.
|
||||
|
||||
- `LCDlibTest`<br>
|
||||
Tests various API functions and LCD capabilities
|
||||
Diagnostic information is also sent to the serial port.
|
||||
Its primary purpose is for internal library testing & verficiation.
|
||||
|
||||
- `lcdproc`<br>
|
||||
Allows using a hd44780 LCD display with the linux/unix
|
||||
lcdproc system. See the sketch for more details.
|
||||
@@ -0,0 +1,80 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// hd44780 Extensible hd44780 LCD Library
|
||||
//
|
||||
// hd44780 is an open source project for open source projects. Those wishing to
|
||||
// create closed projects should seek an alternate solution.
|
||||
// hd44780 is licensed under the terms of the GNU General Public License v3.0
|
||||
// as opposed to the more liberal licensing terms of the
|
||||
// GNU Lesser General Public License (LGPL), MIT, modified BSD, Apache, etc..
|
||||
//
|
||||
// GPL licensing information can found here: https://www.gnu.org/licenses/
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Overview
|
||||
// ========
|
||||
// The hd44780 arduino library is a library package.
|
||||
// It is more than a simple library to run a specific h/w.
|
||||
// It is actually an expandable library package that can communicate with
|
||||
// many different types of LCD hardware and interfaces.
|
||||
//
|
||||
// The library is designed to allow communication and interfacing with hd44780
|
||||
// LCDs over a variety of h/w interfaces.
|
||||
// Each h/w communication interface has its own C++ i/o class.
|
||||
//
|
||||
// The library currently comes with the following i/o subclasses:
|
||||
//
|
||||
// hd44780_pinIO: control LCD using direct Arduino Pin connections
|
||||
// hd44780_I2Cexp: control LCD using i2c i/o exapander backpack (PCF8574 or MCP23008)
|
||||
// hd44780_I2Clcd: control LCD with native i2c interface (PCF2116, PCF2119x, etc...)
|
||||
// hd44780_NTCU165ECPB: control Noritake CU165ECBP-T2J LCD display over SPI
|
||||
// hd44780_NTCUUserial: control Noritake CU-U Series VFD display in serial mode
|
||||
//
|
||||
// Examples
|
||||
// ========
|
||||
// Because the hd44780 library package is more than a simple library, the
|
||||
// examples are not all together in a single location.
|
||||
// The examples are seperated and grouped in to areas as follows:
|
||||
//
|
||||
// ioClass:
|
||||
// All the hd44780 library package examples are under here.
|
||||
// ioClass contains subdirectories for each included hd44780 i/o class
|
||||
// containing sketches that are specific to the i/o class.
|
||||
// The examples for each i/o class are grouped together in a directory by
|
||||
// the name of the i/o class.
|
||||
// In the Arduino IDE they can be found here:
|
||||
// [File]->Examples->hd44780->ioClass
|
||||
// For example, the examples for the hd44780_I2Cexp i/o class will be
|
||||
// found here:
|
||||
// [File]->Examples->hd44780->ioClass->hd44780_I2Cexp
|
||||
//
|
||||
// otherLibraries:
|
||||
// Contains subdirectories for other (non hd44780) libraries that contain
|
||||
// wrapper sketches for various hd44780examples sketches. This is intended
|
||||
// to allow easy benchmarking of other 3rd party LCD libraries for
|
||||
// comparison purposes.
|
||||
//
|
||||
// See the Documentation sketch for additional information.
|
||||
//
|
||||
// Note:
|
||||
// The library package also includes some special purpose demonstration
|
||||
// sketches that can be found under ioClass and otherLibraries
|
||||
// - LCDcharset
|
||||
// Shows the entire character set of the LCD.
|
||||
// Miniture digits are used to show the custom characters.
|
||||
//
|
||||
// - LCDisSpeed
|
||||
// Shows the speed of writing characters to the display.
|
||||
// It shows the transfer time of an individual character as well as
|
||||
// updating the full display. If the geometry is different than 16x2,
|
||||
// it will also show what the full display timing would be if the
|
||||
// display were 16x2.
|
||||
//
|
||||
// Since the sketch can work on many different libraries and h/w,
|
||||
// it is useful for ccomparing the speed of various libraries and LCD h/w.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// dummy sketch functions
|
||||
void setup(void){}
|
||||
void loop(void){}
|
||||
@@ -0,0 +1,98 @@
|
||||
// vi:ts=4
|
||||
// -----------------------------------------------------------------------
|
||||
// lcdproc hd44780 serial device
|
||||
//
|
||||
// lcdproc is the linux equivilent of Windows LCD Smartie
|
||||
// Information on how to set this up and use it can be found here:
|
||||
// https://milesburton.com/USD_LCD_Display_(HD44780)_Running_on_Linux_via_Arduino
|
||||
// http://lcdproc.omnipotent.net/
|
||||
//
|
||||
// This sketch implments a serial hd44780 interface device which can be
|
||||
// used by lcdproc
|
||||
// This code should work with any LiquidCrystal compatible library.
|
||||
//
|
||||
// While you can modify this sketch to use any "LiquidCrystal" library
|
||||
// and modify the default lcd parametes,
|
||||
// wrapper sketches are included in the hd44780 i/o libraries that
|
||||
// declare the lcd object and the needed defines to do this for you.
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
#ifndef HD44780_LCDOBJECT
|
||||
|
||||
#error "Special purpose sketch: Use i/o class example wrapper sketch instead."
|
||||
|
||||
/*
|
||||
* If not using a hd44780 library i/o class example wrapper sketch,
|
||||
* you must modify the sketch to include any needed header files for the
|
||||
* intended library and define the lcd object.
|
||||
*
|
||||
* Add your includes and constructor.
|
||||
* The lcd object must be named "lcd"
|
||||
* and comment out the #error message.
|
||||
*/
|
||||
|
||||
#endif
|
||||
/*
|
||||
* Define your LCD parameters
|
||||
* These must match what you configured in LCDd.conf on the linux host
|
||||
*/
|
||||
#ifndef LCD_COLS
|
||||
#define LCD_COLS 20
|
||||
#endif
|
||||
|
||||
#ifndef LCD_ROWS
|
||||
#define LCD_ROWS 4
|
||||
#endif
|
||||
|
||||
#ifndef BAUDRATE
|
||||
#define BAUDRATE 9600
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(BAUDRATE);
|
||||
// set up the LCD's number of columns and columns:
|
||||
lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
|
||||
#ifdef WIRECLOCK
|
||||
#if (ARDUINO > 10507) && !defined(MPIDE)
|
||||
Wire.setClock(WIRECLOCK); // set i2c clock bit rate, if asked
|
||||
#endif
|
||||
#endif
|
||||
|
||||
lcd.clear();
|
||||
// print out a banner that indicates lcd proc device
|
||||
// and pramameters like baudrate and geometry
|
||||
lcd.print("LCD Proc:");
|
||||
lcd.print("hd44780");
|
||||
lcd.setCursor(0,1);
|
||||
lcd.print(BAUDRATE);
|
||||
lcd.print(' ');
|
||||
lcd.print(LCD_COLS);
|
||||
lcd.print('x');
|
||||
lcd.print(LCD_ROWS);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
uint8_t serial_getch()
|
||||
{
|
||||
int incoming;
|
||||
|
||||
while (!Serial.available()){ }
|
||||
// read the incoming byte:
|
||||
incoming = Serial.read();
|
||||
|
||||
return (incoming & 0xff);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
uint8_t rxbyte;
|
||||
|
||||
rxbyte = serial_getch(); // Fetch byte
|
||||
|
||||
if(rxbyte==0xFE) // If command
|
||||
lcd.command(serial_getch()); // Pass through raw hd44780 command
|
||||
else
|
||||
lcd.write(rxbyte); //Otherwise send it as text character
|
||||
}
|
||||
Reference in New Issue
Block a user