first commit
This commit is contained in:
125
libraries/hd44780/examples/Documentation/Documentation.ino
Normal file
125
libraries/hd44780/examples/Documentation/Documentation.ino
Normal file
@@ -0,0 +1,125 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// hd44780 Extensible hd44780 LCD Library Version 1.3.2
|
||||
//
|
||||
// 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/
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// hd44780 Library ReadMe: file://./docs/README.html
|
||||
//
|
||||
// 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_HC1627_I2C: control LCD with native i2c interface (Tsingtek Display HC1627)
|
||||
// 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_NTCU20025ECPB_pinIO: control Noritake CU20025ECPB using direct Arduino pin connections
|
||||
// hd44780_NTCUUserial: control Noritake CU-U Series VFD display in serial mode
|
||||
// hd44780_pinIO: control LCD using direct Arduino Pin connections
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// hd44780examples:
|
||||
// These are not really example sketches. They should not be looked at as
|
||||
// examples for how to use the library. They are special purpose sketches
|
||||
// that are used as include files for the i/o class examples.
|
||||
// See the ioClass specific examples for each ioClass.
|
||||
//
|
||||
// See the readme files under the examples directory and the wiki for
|
||||
// additional information about the examples.
|
||||
//
|
||||
// Custom Character creation tools
|
||||
// ===============================
|
||||
// https://kakedev.github.io/GlyphGenerator/
|
||||
// http://www.quinapalus.com/hd44780udg.html
|
||||
// https://omerk.github.io/lcdchargen
|
||||
//
|
||||
// Github links
|
||||
// ============
|
||||
// Version 1.3.2 repository: https://github.com/duinoWitchery/hd44780/tree/1.3.2
|
||||
// Latest respository: https://github.com/duinoWitchery/hd44780
|
||||
// hd44780 wiki: https://github.com/duinoWitchery/hd44780/wiki
|
||||
// (note: Latest repository & wiki may be different from installed version)
|
||||
//
|
||||
// Arduino Links
|
||||
// =============
|
||||
// Arduino LiquidCrystal API: https://www.arduino.cc/en/Reference/LiquidCrystal
|
||||
// Arduino: http://arduino.cc
|
||||
// Arduino Forum: http://www.arduino.cc/forum/
|
||||
// Arduino Software: https://www.arduino.cc/en/Main/Software
|
||||
// Installing Libraries: https://www.arduino.cc/en/Guide/Libraries
|
||||
// Arduino Playground: http://playground.arduino.cc/
|
||||
//
|
||||
// Technical Information Links:
|
||||
// ============================
|
||||
//
|
||||
// https://en.wikipedia.org/wiki/Hitachi_HD44780_LCD_controller
|
||||
//
|
||||
// hd44780 datasheet:
|
||||
// http://fab.cba.mit.edu/classes/863.06/11.13/44780.pdf
|
||||
// https://www.sparkfun.com/datasheets/LCD/HD44780.pdf
|
||||
//
|
||||
// hd44780 internal RAM addressing:
|
||||
// http://web.alfredstate.edu/faculty/weimandn/lcd/lcd_addressing/lcd_addressing_index.html
|
||||
//
|
||||
// Arduino board Pinouts:
|
||||
// Various Popular Arduino boards:
|
||||
// http://www.pighixxx.com/test/pinoutspg/boards/
|
||||
// https://github.com/Bouni/Arduino-Pinout
|
||||
// Teensy boards:
|
||||
// https://www.pjrc.com/teensy/pinout.html
|
||||
// Various esp8266 based boards:
|
||||
// https://iotbytes.wordpress.com/esp8266-pinouts/
|
||||
// https://iotbytes.wordpress.com/nodemcu-pinout/
|
||||
// https://learn.adafruit.com/adafruit-feather-huzzah-esp8266/pinouts
|
||||
//
|
||||
// PCF8574 datasheet:
|
||||
// https://www.aurel32.net/elec/pcf8574.pdf
|
||||
// http://www.ti.com/lit/ds/symlink/pcf8574.pdf
|
||||
//
|
||||
// MCP23008 datasheet:
|
||||
// http://ww1.microchip.com/downloads/en/DeviceDoc/21919e.pdf
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// dummy sketch functions
|
||||
void setup(void){}
|
||||
void loop(void){}
|
||||
4
libraries/hd44780/examples/Documentation/README.md
Normal file
4
libraries/hd44780/examples/Documentation/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
Documenation sketch
|
||||
===================
|
||||
The Documenation.ino sketch is not really an example sketch.
|
||||
It is a dummy sketch used to allow documentation to be accessed through the IDE when the sketched is loaded into the IDE.
|
||||
848
libraries/hd44780/examples/Documentation/docs/README.html
Normal file
848
libraries/hd44780/examples/Documentation/docs/README.html
Normal file
File diff suppressed because one or more lines are too long
1
libraries/hd44780/examples/Documentation/docs/readme.txt
Normal file
1
libraries/hd44780/examples/Documentation/docs/readme.txt
Normal file
@@ -0,0 +1 @@
|
||||
documenation will be placed here
|
||||
22
libraries/hd44780/examples/README.md
Normal file
22
libraries/hd44780/examples/README.md
Normal file
@@ -0,0 +1,22 @@
|
||||
hd44780 examples
|
||||
================
|
||||
The hd44780 library package inclues many examples that demonstrate the capabilities of the library.
|
||||
|
||||
#### The examples are broken up into various sub directories.
|
||||
|
||||
* `Documenatation`<br>
|
||||
The Documenation sketch is not really an example sketch.
|
||||
It is a dummy sketch used to allow documentation to be accessed through the IDE when the sketched is loaded into the IDE.
|
||||
|
||||
* `ioClass`<br>
|
||||
Contains subdirectories for each included hd44780 i/o class containing example sketches
|
||||
that are specific to the i/o class. They also contain wrapper sketches for the special purpose sketches mentioned above.
|
||||
|
||||
* `otherLibraries`<br>
|
||||
Contains subdirectories for other (non hd44780) libraries that contain wrapper sketches for various special purpose hd44780examples sketches.
|
||||
Its primary purpose is to provide easy benchmarking of other libraries for comparison purposes by using LCDiSpeed.
|
||||
|
||||
**The sketches in the hd44780examples area are special purpose sketches that are used as include files for the i/o class examples.
|
||||
They should not be looked at as examples for how to use the library.**
|
||||
While the hd44780examples 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.**
|
||||
@@ -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
|
||||
}
|
||||
9
libraries/hd44780/examples/ioClass/README.md
Normal file
9
libraries/hd44780/examples/ioClass/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
ioClass
|
||||
=======
|
||||
|
||||
This directory contains a subdirectory for each i/o class that contains
|
||||
examples for that specific i/o class.
|
||||
|
||||
The hd44780examples directory under each i/o class subdirectory contains
|
||||
i/o class specific wrapper sketches for the special purpose sketches under
|
||||
examples/hd44780examples.
|
||||
@@ -0,0 +1,117 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// HelloWorld - simple demonstration of lcd
|
||||
// Created by Bill Perry 2020-06-26
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCD devices like the Tsingtek Display HC1627 modules
|
||||
// in i2c mode. Devices such as HC1627-B-LWH-I2C-30 or HC1627-SYH-I2C-30
|
||||
// These devices have a native I2C interface rather than use a simple I2C
|
||||
// i/o expander chip such as a PCF8574 or MCP23008.
|
||||
//
|
||||
// NOTE:
|
||||
// These devices usually need external pullups as they typically are not on
|
||||
// the module.
|
||||
// WARNING:
|
||||
// Use caution when using 3v only processors like arm and ESP8266 processors
|
||||
// when interfacing with 5v modules as not doing proper level shifting or
|
||||
// incorrectly hooking things up can damage the processor.
|
||||
//
|
||||
// Sketch prints "Hello, World!" on the lcd
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// While not all modules use the same pinout,
|
||||
// Be VERY careful and check your datasheet
|
||||
//
|
||||
// This pin table is for the Tsingtek Display HC1627-SYH-I2C-30 or
|
||||
// HC1627-SYH-I2C-30 module when it is strapped for i2c mode operation
|
||||
//
|
||||
// pin 14 is the pin closest to the edge of the PCB
|
||||
// 14 - connect to gnd
|
||||
// 13 - connect to vcc
|
||||
// 12 - ID0 --- controls bit 1 of 7 bit i2c address, strap accordingly
|
||||
// 11 - ID1 --- controls bit 2 of 7 bit i2c address, strap accordingly
|
||||
// 10 - not connected
|
||||
// 9 - not connected
|
||||
// 8 - SCL
|
||||
// 7 - SDA
|
||||
// 6 - connect to gnd
|
||||
// 5 - connect to gnd
|
||||
// 4 - connect to gnd
|
||||
// 3 - Vo Contrast Voltage input
|
||||
// 2 - VCC (5v)
|
||||
// 1 - LCD gnd
|
||||
// 15 - Backlight Anode (+5v)
|
||||
// 16 - Backlight Cathode (Gnd)
|
||||
//
|
||||
// I2C IDx address table
|
||||
// ID1 ID0 ADDR
|
||||
// L L 0x38/0x39
|
||||
// L H 0x3A/0x3B
|
||||
// H L 0x3C/0x3D
|
||||
// H H 0x3E/0x3F
|
||||
//
|
||||
// library only needs to know the base address (the lower address)
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// LiquidCrystal compability:
|
||||
// Since hd44780 is LiquidCrystal API compatible, most existing LiquidCrystal
|
||||
// sketches should work with hd44780 hd44780_HC1627_I2C i/o class once the
|
||||
// includes are changed to use hd44780 and the lcd object constructor is
|
||||
// changed to use the hd44780_HC1627_I2C i/o class.
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_HC1627_I2C.h> // i2c LCD i/o class header
|
||||
|
||||
// Note, i2c address can be specified or automatically located
|
||||
// If you wish to use a specific address comment out this constructor
|
||||
// and use the constructor below that specifies the address
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_HC1627_I2C lcd;
|
||||
|
||||
//
|
||||
// manually enter base address of LCD.
|
||||
// Base Addresses
|
||||
// - 0x38, 0x3A, 0x3C, or 0x3E
|
||||
|
||||
// declare i2c address and constructor for specified i2c address
|
||||
//const int i2c_addr = 0x38;
|
||||
//hd44780_HC1627_I2C lcd(i2c_addr); // use device at this address
|
||||
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
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
|
||||
//
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// begin() failed so blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// Print a message to the LCD
|
||||
lcd.print("Hello, World!");
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
@@ -0,0 +1,388 @@
|
||||
static const int dummyvar = 0; // dummy declaration for older broken IDEs!!!!
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDCustomChars - simple demonstration of lcd custom characters
|
||||
// Created by Bill Perry 2020-06-26
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCD devices like the Tsingtek Display HC1627 modules
|
||||
// in i2c mode. Devices such as HC1627-B-LWH-I2C-30 or HC1627-SYH-I2C-30
|
||||
// These devices have a native I2C interface rather than use a simple I2C
|
||||
// i/o expander chip such as a PCF8574 or MCP23008.
|
||||
//
|
||||
// NOTE:
|
||||
// These devices usually need external pullups as they typically are not on
|
||||
// the module.
|
||||
// WARNING:
|
||||
// Use caution when using 3v only processors like arm and ESP8266 processors
|
||||
// when interfacing with 5v modules as not doing proper level shifting or
|
||||
// incorrectly hooking things up can damage the processor.
|
||||
//
|
||||
// Sketch demonstrates how to assign custom characters to the eight hd44780
|
||||
// custom character codepoints and how to display on the LCD using
|
||||
// write() and print()
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// While not all modules use the same pinout,
|
||||
// Be VERY careful and check your datasheet if you are not using that exact
|
||||
// display.
|
||||
//
|
||||
// This pin table is for the Tsingtek Display HC1627-SYH-I2C-30 or
|
||||
// HC1627-SYH-I2C-30 module when it is strapped for i2c mode operation
|
||||
//
|
||||
// pin 14 is the pin closest to the edge of the PCB
|
||||
// 14 - connect to gnd
|
||||
// 13 - connect to vcc
|
||||
// 12 - ID0 --- controls bit 1 of 7 bit i2c address, strap accordingly
|
||||
// 11 - ID1 --- controls bit 2 of 7 bit i2c address, strap accordingly
|
||||
// 10 - not connected
|
||||
// 9 - not connected
|
||||
// 8 - SCL
|
||||
// 7 - SDA
|
||||
// 6 - connect to gnd
|
||||
// 5 - connect to gnd
|
||||
// 4 - connect to gnd
|
||||
// 3 - Vo Contrast Voltage input
|
||||
// 2 - VCC (5v)
|
||||
// 1 - LCD gnd
|
||||
// 15 - Backlight Anode (+5v)
|
||||
// 16 - Backlight Cathode (Gnd)
|
||||
//
|
||||
// I2C IDx address table
|
||||
// ID1 ID0 ADDR
|
||||
// L L 0x38/0x39
|
||||
// L H 0x3A/0x3B
|
||||
// H L 0x3C/0x3D
|
||||
// H H 0x3E/0x3F
|
||||
//
|
||||
// library only needs to know the base address (the lower address)
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// You can create your own custom characters.
|
||||
// Here are a couple of web pages that have a tool that will generate the data
|
||||
// values needed for custom character.
|
||||
// https://kakedev.github.io/GlyphGenerator/
|
||||
// http://www.quinapalus.com/hd44780udg.html
|
||||
// https://omerk.github.io/lcdchargen
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h> // include hd44780 library header file
|
||||
#include <hd44780ioClass/hd44780_HC1627_I2C.h> // i2c LCD i/o class header
|
||||
|
||||
// Note, i2c address can be specified or automatically located
|
||||
// If you wish to use a specific address comment out this constructor
|
||||
// and use the constructor below that specifies the address
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_HC1627_I2C lcd;
|
||||
|
||||
//
|
||||
// manually enter base address of LCD.
|
||||
// Base Addresses
|
||||
// - 0x38, 0x3A, 0x3C, or 0x3E
|
||||
|
||||
// declare i2c address and constructor for specified i2c address
|
||||
//const int i2c_addr = 0x38;
|
||||
//hd44780_HC1627_I2C lcd(i2c_addr); // use device at this address
|
||||
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
const int LongDelay = 5000;
|
||||
const int ShortDelay = 800;
|
||||
|
||||
int customcharRow = 1; // default to printing custom chars on row 1
|
||||
|
||||
// Below are some custom characters for demonstration
|
||||
|
||||
// You can ensure that the data for these custom characters is only
|
||||
// in flash and not in RAM by using the const qualifier.
|
||||
// However....
|
||||
// If using the AVR part, the AVR proprietary PROGMEM directive must be used.
|
||||
// PROGMEM is only required on AVR parts since the AVR parts cannot directly
|
||||
// access const data stored in flash like all the other processors.
|
||||
// PROGMEM is an AVR specific proprietary kludge that tells the linker and
|
||||
// startup code to handle the data differently.
|
||||
// PROGMEM is only used by the AVR and not required by any other processor.
|
||||
//
|
||||
// Most non AVR cores provide AVR compatibilty by providing support (emulation)
|
||||
// for the AVR proprietary PROGMEM directive and corresponding access functions,
|
||||
// but some do not.
|
||||
//
|
||||
// Because of this AVR const data and PROGMEM issue, there is no way to
|
||||
// guarantee code portability across all cores when using const data.
|
||||
//
|
||||
//
|
||||
// the hd44780 library assumes that if a const qualifier is used on the AVR
|
||||
// processor that the data has been stored in flash using the PROGMEM directive.
|
||||
// There is no way for the hd44780 library to know or detect if PROGMEM has
|
||||
// been used.
|
||||
// So if the const qualifer is used but the PROGMEM directive is not used on
|
||||
// an AVR processor, the custom char will be garbage.
|
||||
//
|
||||
// Examples:
|
||||
// For all processors other than AVR:
|
||||
// const char bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const uint8_ bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
//
|
||||
// For AVR: (and non AVR cores that have AVR PROGMEM emulation)
|
||||
// const char bell[8] PROGMEM = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const uint8_t bell[8] PROGMEM = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// OR
|
||||
// const PROGMEM char bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const PROGMEM uint8_t bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// NOTE:
|
||||
// if PROGMEM is used on older AVR compilers it generates a warning.
|
||||
//
|
||||
|
||||
uint8_t bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
uint8_t note[8] = {0x02,0x03,0x02,0x0e,0x1e,0x0c,0x00,0x00};
|
||||
uint8_t clockface[8] = {0x00,0x0e,0x15,0x17,0x11,0x0e,0x00,0x00};
|
||||
uint8_t heart[8] = {0x00,0x0a,0x1f,0x1f,0x0e,0x04,0x00,0x00};
|
||||
uint8_t duck[8] = {0x00,0x0c,0x1d,0x0f,0x0f,0x06,0x00,0x00};
|
||||
uint8_t check[8] = {0x00,0x01,0x03,0x16,0x1c,0x08,0x00,0x00};
|
||||
uint8_t cross[8] = {0x00,0x1b,0x0e,0x04,0x0e,0x1b,0x00,0x00};
|
||||
uint8_t smile[8] = {0x00,0x0a,0x0a,0x00,0x00,0x11,0x0e,0x00};
|
||||
|
||||
uint8_t opnheart[8] = {0x00,0x0a,0x15,0x11,0x0a,0x04,0x00,0x00};
|
||||
|
||||
uint8_t uparrow[8] = {0x04,0x0e,0x1f,0x0e,0x0e,0x0e,0x00,0x00};
|
||||
uint8_t ruparrow[8] = {0x00,0x0f,0x03,0x05,0x09,0x10,0x00,0x00};
|
||||
uint8_t luparrow[8] = {0x00,0x1e,0x18,0x14,0x12,0x01,0x00,0x00};
|
||||
uint8_t dnarrow[8] = {0x00,0x0e,0x0e,0x0e,0x1f,0x0e,0x04,0x00};
|
||||
uint8_t rdnarrow[8] = {0x00,0x10,0x09,0x05,0x03,0x0f,0x00,0x00};
|
||||
uint8_t ldnarrow[8] = {0x00,0x01,0x12,0x14,0x18,0x1e,0x00,0x00};
|
||||
uint8_t retarrow[8] = {0x01,0x01,0x05,0x09,0x1f,0x08,0x04,0x00};
|
||||
|
||||
uint8_t hourglass[8] = {0x1f,0x11,0x0a,0x04,0x0a,0x11,0x1f,0x00};
|
||||
uint8_t degreeSymbol[8]= {0x06,0x09,0x09,0x06,0x00,0x00,0x00,0x00};
|
||||
uint8_t degreeC[8] = {0x18,0x18,0x03,0x04,0x04,0x04,0x03,0x00};
|
||||
uint8_t degreeF[8] = {0x18,0x18,0x07,0x04,0x07,0x04,0x04,0x00};
|
||||
|
||||
const PROGMEM uint8_t vsigbar[][8] = {
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0 bars, same as <space>
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x1F}, // 1 bars
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x1F,0x1F}, // 2 bars
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F}, // 3 bars
|
||||
{0x00, 0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F}, // 4 bars
|
||||
{0x00, 0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x1F}, // 5 bars
|
||||
{0x00, 0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 6 bars
|
||||
{0x00, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 7 bars
|
||||
{0x1F, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 8 bars
|
||||
};
|
||||
|
||||
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
|
||||
{
|
||||
// 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
|
||||
}
|
||||
void loop(void)
|
||||
{
|
||||
lcd.clear();
|
||||
|
||||
lcd.print("Custom Chars");
|
||||
|
||||
// create custom characters
|
||||
// int rval = createChar(charval, charmap[]);
|
||||
//
|
||||
// createChar() creates a custom character
|
||||
// for the character at the charval codepoint.
|
||||
// It returns zero if successful.
|
||||
//
|
||||
// to display the custom character, simply call write()
|
||||
// with the charval use in createChar()
|
||||
//
|
||||
// The display must be initialized *before* you attempt
|
||||
// to create custom characters.
|
||||
//
|
||||
// Note: On hd44780 displays there are 8 custom characters.
|
||||
// They are assigned to character codepoint values 0x00 to 0x07
|
||||
// The codepoints 0x08 to 0x0f are duplicates for 0x00 to 0x07
|
||||
// i.e. 0x08 is the same as 0x00, 0x09 same as 0x01, etc...
|
||||
|
||||
// create 8 custom characters
|
||||
lcd.createChar(0, bell);
|
||||
lcd.createChar(1, note);
|
||||
lcd.createChar(2, clockface);
|
||||
lcd.createChar(3, heart);
|
||||
lcd.createChar(4, duck);
|
||||
lcd.createChar(5, check);
|
||||
lcd.createChar(6, cross);
|
||||
lcd.createChar(7, smile);
|
||||
|
||||
// prepare to display the custom characters
|
||||
// on multi line displays the custom characters will be
|
||||
// displayed on the 2nd line
|
||||
// on single line displays, delay a bit to see the initial display,
|
||||
// then clear the display to display the custom characters on the top line
|
||||
if(LCD_ROWS < 2)
|
||||
{
|
||||
customcharRow = 0;
|
||||
delay(LongDelay);
|
||||
lcd.clear();
|
||||
}
|
||||
|
||||
lcd.setCursor(0, customcharRow);
|
||||
|
||||
// write() or print() can be used to display custom characters.
|
||||
//
|
||||
// To use write() pass the charval of the desired custom character.
|
||||
// lcd.write(charval);
|
||||
// NOTE:
|
||||
// The Print class has an issue that does not allow 0 (zero) to be used
|
||||
// on write() without casting it. The Arduino team refuses to fix this.
|
||||
// hd44780 has a work around in it to remove this issue so you can call
|
||||
// write() with a constant value of 0 without having to cast it.
|
||||
//
|
||||
// write() can also be used with literal characters that contain
|
||||
// an octal (base 8) escape seuence.
|
||||
// lcd.write('\###');
|
||||
//
|
||||
// To use print() pass in the charval of the desired custom character
|
||||
// as a character *not* an integer.
|
||||
// This requires using a literal character with an octal escape sequence.
|
||||
// lcd.print('\###');
|
||||
//
|
||||
|
||||
// Since both write() & print() both accept octal escaped literal characters
|
||||
// it is the most compatible & portable way of sending custom characters
|
||||
|
||||
// display all 8 custom characters.
|
||||
|
||||
// write() with character codepoint values
|
||||
lcd.write(0); // casting to an uint8_t or byte not needed with hd44780
|
||||
lcd.write(1);
|
||||
|
||||
// write() & print() with octal escaped literal characters
|
||||
lcd.write('\002'); // this is an octal escaped literal character
|
||||
lcd.write('\003'); // this is an octal escaped literal character
|
||||
lcd.print('\004'); // this is an octal escaped literal character
|
||||
lcd.print('\005'); // this is an octal escaped literal character
|
||||
|
||||
// can also drop the leading zeros on small litereal values like these
|
||||
lcd.print('\06'); // this is an octal escaped literal character
|
||||
lcd.print('\7'); // this is an octal escaped literal character
|
||||
|
||||
delay(LongDelay);
|
||||
|
||||
// You can also insert custom character codepoints into C strings.
|
||||
// To do so, insert the character codepoint value as an octal constant.
|
||||
// However,
|
||||
// because zero indicates the end of string in C you cannot use zero.
|
||||
// Example:
|
||||
// lcd.print("charval #1: \001"); // prints custom character at codepoint 1
|
||||
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code1: \001");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code2: \002");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code3: \003");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code4: \004");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code5: \005");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code6: \006");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code7: \007");
|
||||
delay(ShortDelay);
|
||||
|
||||
// Another nifty trick is that you can modify custom characters on the
|
||||
// display without having to re-write the characters on the display.
|
||||
// To do this, simply create a new character for a codepoint.
|
||||
// All characters on the display which have that codepoint will "magically"
|
||||
// change to the new custom character.
|
||||
// So for example, if the entire display was written with custom character
|
||||
// zero and character zero was a bell, if you called createChar() to
|
||||
// redefine character codepoint zero to be a duck,
|
||||
// the entire display would turn to ducks without having to send any
|
||||
// characters to the display.
|
||||
|
||||
// create the initial custom character
|
||||
lcd.createChar(0, bell);
|
||||
|
||||
// fill the custom character line with the custom character.
|
||||
lcd.setCursor(0,customcharRow);
|
||||
for(uint8_t col=0; col<LCD_COLS; col++)
|
||||
lcd.write(0);
|
||||
|
||||
delay(ShortDelay);
|
||||
|
||||
// change the single custom character previously written on the row
|
||||
// and all the characters on the row will change
|
||||
// without having to re-write the characters.
|
||||
lcd.createChar(0, note);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, clockface);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, heart);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, duck);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, check);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, cross);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, smile);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeSymbol);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeC);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeF);
|
||||
delay(ShortDelay);
|
||||
|
||||
// show multiple vertical bars rising
|
||||
// by changing the single custom character that is already written
|
||||
// to the entire row on the display
|
||||
for(int i = 0; i < 9; i++)
|
||||
{
|
||||
lcd.createChar(0, vsigbar[i]);
|
||||
delay(ShortDelay);
|
||||
}
|
||||
|
||||
delay(LongDelay);
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LineWrap - simple demonstration of automatic linewrap functionality
|
||||
// Created by Bill Perry 2020-06-26
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCD devices like the Tsingtek Display HC1627 modules
|
||||
// in i2c mode. Devices such as HC1627-B-LWH-I2C-30 or HC1627-SYH-I2C-30
|
||||
// These devices have a native I2C interface rather than use a simple I2C
|
||||
// i/o expander chip such as a PCF8574 or MCP23008.
|
||||
//
|
||||
// NOTE:
|
||||
// These devices usually need external pullups as they typically are not on
|
||||
// the module.
|
||||
// WARNING:
|
||||
// Use caution when using 3v only processors like arm and ESP8266 processors
|
||||
// when interfacing with 5v modules as not doing proper level shifting or
|
||||
// incorrectly hooking things up can damage the processor.
|
||||
//
|
||||
// Sketch demonstrates hd44780 library automatic line wrapping functionality.
|
||||
//
|
||||
// Background:
|
||||
// hd44780 LCDs do not use linear continuous memory for the characters
|
||||
// on the lines on the display.
|
||||
// This means that simply sending continuous characters to the
|
||||
// display will not fill lines and wrap appropriately as might be expected.
|
||||
// The hd44780 library solves this issue by adding a line wrapping capability
|
||||
// in s/w that can be enabled & disabled.
|
||||
// This allows the host to send characters to the display continuously and they
|
||||
// will wrap to the next lower line when the end of the visible line has been
|
||||
// reached. When on the bottom line it will wrap back to the top line.
|
||||
//
|
||||
// (Configure LCD_COLS & LCD_ROWS if desired/needed)
|
||||
// Expected behavior of the sketch:
|
||||
// - display a banner announcing the test.
|
||||
// - print the configured LCD geometry
|
||||
// - print a long text string to demostrate automatic line wrapping
|
||||
// - print lots of characters (slowly) to show how the full wrapping works.
|
||||
// (loop)
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED with the initalization error
|
||||
// code.
|
||||
//
|
||||
// Special note for certain 16x1 displays:
|
||||
// Some 16x1 displays are actually a 8x2 display that have both lines on
|
||||
// a single line on the display.
|
||||
// If you have one of these displays, simply set the geometry to 8x2 instead
|
||||
// of 16x1.
|
||||
// In normal sketches, lineWrap() mode will allow this type of display to
|
||||
// properly function as a 16x1 display in that it will allow printing up to
|
||||
// 16 characters on the display without having to manually set the cursor
|
||||
// position to print the right characters on the half of the display.
|
||||
// However, when using this 8x2 display as a 16x1 display,
|
||||
// scrollDisplayLeft() and scrollDisplayRight() will not work as intended.
|
||||
// They will shift the two halves of the display rather than the entire display.
|
||||
// This is because the hd44780 chip is doing the shift and chip is hard coded
|
||||
// internally for two lines.
|
||||
// ----------------------------------------------------------------------------
|
||||
// While not all modules use the same pinout,
|
||||
// Be VERY careful and check your datasheet.
|
||||
//
|
||||
// This pin table is for the Tsingtek Display HC1627-SYH-I2C-30 or
|
||||
// HC1627-SYH-I2C-30 module when it is strapped for i2c mode operation
|
||||
//
|
||||
// pin 14 is the pin closest to the edge of the PCB
|
||||
// 14 - connect to gnd
|
||||
// 13 - connect to vcc
|
||||
// 12 - ID0 --- controls bit 1 of 7 bit i2c address, strap accordingly
|
||||
// 11 - ID1 --- controls bit 2 of 7 bit i2c address, strap accordingly
|
||||
// 10 - not connected
|
||||
// 9 - not connected
|
||||
// 8 - SCL
|
||||
// 7 - SDA
|
||||
// 6 - connect to gnd
|
||||
// 5 - connect to gnd
|
||||
// 4 - connect to gnd
|
||||
// 3 - Vo Contrast Voltage input
|
||||
// 2 - VCC (5v)
|
||||
// 1 - LCD gnd
|
||||
// 15 - Backlight Anode (+5v)
|
||||
// 16 - Backlight Cathode (Gnd)
|
||||
//
|
||||
// I2C IDx address table
|
||||
// ID1 ID0 ADDR
|
||||
// L L 0x38/0x39
|
||||
// L H 0x3A/0x3B
|
||||
// H L 0x3C/0x3D
|
||||
// H H 0x3E/0x3F
|
||||
//
|
||||
// library only needs to know the base address (the lower address)
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
// include the needed headers.
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_HC1627_I2C.h> // i2c LCD i/o class header
|
||||
|
||||
// Note, i2c address can be specified or automatically located
|
||||
// If you wish to use a specific address comment out this constructor
|
||||
// and use the constructor below that specifies the address
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_HC1627_I2C lcd;
|
||||
|
||||
//
|
||||
// manually enter base address of LCD.
|
||||
// Base Addresses
|
||||
// - 0x38, 0x3A, 0x3C, or 0x3E
|
||||
|
||||
// declare i2c address and constructor for specified i2c address
|
||||
//const int i2c_addr = 0x38;
|
||||
//hd44780_HC1627_I2C lcd(i2c_addr); // use device at this address
|
||||
|
||||
|
||||
// LCD geometry
|
||||
// while 16x2 will work on most displays even if the geometry is different,
|
||||
// for actual wrap testing of a particular LCD it is best to use the correct
|
||||
// geometry.
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
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>
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// begin() failed so blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// turn on automatic line wrapping
|
||||
// which automatically wraps lines to the next lower line and wraps back
|
||||
// to the top when at the bottom line
|
||||
// NOTE:
|
||||
// noLineWrap() can be used to disable automatic line wrapping.
|
||||
// _write() can be called instead of write() to send data bytes
|
||||
// to the display bypassing any special character or line wrap processing.
|
||||
lcd.lineWrap();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("WrapTest");
|
||||
delay(2000);
|
||||
lcd.clear();
|
||||
|
||||
//print the configured LCD geometry
|
||||
lcd.print(LCD_COLS);
|
||||
lcd.print("x");
|
||||
lcd.print(LCD_ROWS);
|
||||
delay(3000);
|
||||
lcd.clear();
|
||||
|
||||
// print a long text string
|
||||
// without line wrapping enabled, the text would not wrap properly
|
||||
// to the next line.
|
||||
|
||||
if(LCD_COLS == 8)
|
||||
lcd.print("A long text line");
|
||||
else
|
||||
lcd.print("This is a very long line of text");
|
||||
delay(3000);
|
||||
|
||||
lcd.clear();
|
||||
|
||||
// now print 2 full displays worth of characters to show
|
||||
// the full wrapping.
|
||||
|
||||
lcd.cursor(); // turn on cursor so you can see where it is
|
||||
|
||||
char c = '0'; // start at the character for the number zero
|
||||
for(int i = 2*LCD_COLS*LCD_ROWS; i; i--)
|
||||
{
|
||||
lcd.print(c++);
|
||||
delay(200); // slow things down to watch the printing & wrapping
|
||||
|
||||
if(c > 0x7e) // wrap back to beginning of printable ASCII chars
|
||||
c = '!';
|
||||
}
|
||||
delay(3000);
|
||||
lcd.noCursor(); // turn off cursor
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
hd44780_HC1627 examples
|
||||
=======================
|
||||
|
||||
The examples included in this directory are for the hd44780_HC1627 i/o class.<br>
|
||||
The hd44780_HC1627 i/o class controls an LCD with a native i2c interface like the Tsingtek Display HC1627-SYH-I2C-30
|
||||
|
||||
#### The following examples are included:
|
||||
|
||||
- `HelloWorld`<br>
|
||||
Prints "Hello, World!" on the lcd
|
||||
|
||||
- `LCDCustomChars`<br>
|
||||
Demonstrates using custom characters
|
||||
|
||||
- `LineWrap`<br>
|
||||
Demonstrates automatic linewrap functionality
|
||||
|
||||
- `Serial2LCD`<br>
|
||||
Displays a message read from the serial port on the lcd.
|
||||
|
||||
- `UpTime`<br>
|
||||
Prints the amount of time since the Arduino has been reset.
|
||||
|
||||
- `hd44780examples`<br>
|
||||
The hd44780examples subdirectory contains
|
||||
hd44780_HC1627 class specific wrapper sketches for sketches under
|
||||
examples/hd44780examples.
|
||||
@@ -0,0 +1,173 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// Serial2LCD - simple demonstration printing characters from serial port
|
||||
// Created by Bill Perry 2020-06-28
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCD devices like the Tsingtek Display HC1627 modules
|
||||
// in i2c mode. Devices such as HC1627-B-LWH-I2C-30 or HC1627-SYH-I2C-30
|
||||
// These devices have a native I2C interface rather than use a simple I2C
|
||||
// i/o expander chip such as a PCF8574 or MCP23008.
|
||||
//
|
||||
// Sketch demonstrates hd44780 how to read a message of characters from
|
||||
// serial port and display it on the LCD.
|
||||
// It takes advantage of the hd44780 library automatic line
|
||||
// wrapping capability.
|
||||
// See the LineWrap sketch for details about line wrapping.
|
||||
//
|
||||
// NOTE:
|
||||
// These devices usually need external pullups as they typically are not on
|
||||
// the module.
|
||||
// WARNING:
|
||||
// Use caution when using 3v only processors like arm and ESP8266 processors
|
||||
// when interfacing with 5v modules as not doing proper level shifting or
|
||||
// incorrectly hooking things up can damage the processor.
|
||||
//
|
||||
// Configure LCD_COLS, LCD_ROWS and BAUDRATE if desired/needed
|
||||
// Expected behavior of the sketch:
|
||||
// - characters received from serial port are displayed on LCD
|
||||
// - CR and LF are ignored/dropped
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED with the initalization error
|
||||
// code.
|
||||
//
|
||||
// Some 16x1 displays are actually a 8x2 display that have both lines on
|
||||
// a single line on the display.
|
||||
// If you have one of these displays, simply set the geometry to 8x2 instead
|
||||
// of 16x1.
|
||||
// ----------------------------------------------------------------------------
|
||||
// While not all modules use the same pinout,
|
||||
// Be VERY careful and check your datasheet.
|
||||
//
|
||||
// This pin table is for the Tsingtek Display HC1627-SYH-I2C-30 or
|
||||
// HC1627-SYH-I2C-30 module when it is strapped for i2c mode operation
|
||||
//
|
||||
// pin 14 is the pin closest to the edge of the PCB
|
||||
// 14 - connect to gnd
|
||||
// 13 - connect to vcc
|
||||
// 12 - ID0 --- controls bit 1 of 7 bit i2c address, strap accordingly
|
||||
// 11 - ID1 --- controls bit 2 of 7 bit i2c address, strap accordingly
|
||||
// 10 - not connected
|
||||
// 9 - not connected
|
||||
// 8 - SCL
|
||||
// 7 - SDA
|
||||
// 6 - connect to gnd
|
||||
// 5 - connect to gnd
|
||||
// 4 - connect to gnd
|
||||
// 3 - Vo Contrast Voltage input
|
||||
// 2 - VCC (5v)
|
||||
// 1 - LCD gnd
|
||||
// 15 - Backlight Anode (+5v)
|
||||
// 16 - Backlight Cathode (Gnd)
|
||||
//
|
||||
// I2C IDx address table
|
||||
// ID1 ID0 ADDR
|
||||
// L L 0x38/0x39
|
||||
// L H 0x3A/0x3B
|
||||
// H L 0x3C/0x3D
|
||||
// H H 0x3E/0x3F
|
||||
//
|
||||
// library only needs to know the base address (the lower address)
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
// include the needed headers.
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_HC1627_I2C.h> // i2c LCD i/o class header
|
||||
|
||||
// Note, i2c address can be specified or automatically located
|
||||
// If you wish to use a specific address comment out this constructor
|
||||
// and use the constructor below that specifies the address
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_HC1627_I2C lcd;
|
||||
|
||||
//
|
||||
// manually enter base address of LCD.
|
||||
// Base Addresses
|
||||
// - 0x38, 0x3A, 0x3C, or 0x3E
|
||||
|
||||
// declare i2c address and constructor for specified i2c address
|
||||
//const int i2c_addr = 0x38;
|
||||
//hd44780_HC1627_I2C lcd(i2c_addr); // use device at this address
|
||||
|
||||
|
||||
// LCD geometry
|
||||
// while 16x2 will work on most displays even if the geometry is different,
|
||||
// for actual wrap testing of a particular LCD it is best to use the correct
|
||||
// geometry.
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
const int BAUDRATE = 9600;
|
||||
|
||||
void setup()
|
||||
{
|
||||
int status;
|
||||
|
||||
// initalize Serial port
|
||||
Serial.begin(BAUDRATE);
|
||||
|
||||
// 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>
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// begin() failed
|
||||
|
||||
Serial.print("LCD initalization failed: ");
|
||||
Serial.println(status);
|
||||
|
||||
// blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// turn on automatic line wrapping
|
||||
// which automatically wraps lines to the next lower line and wraps back
|
||||
// to the top when at the bottom line
|
||||
// NOTE:
|
||||
// noLineWrap() can be used to disable automatic line wrapping.
|
||||
// _write() can be called instead of write() to send data bytes
|
||||
// to the display bypassing any special character or line wrap processing.
|
||||
lcd.lineWrap();
|
||||
|
||||
lcd.print("Serial2LCD");
|
||||
if(LCD_ROWS > 1)
|
||||
{
|
||||
lcd.setCursor(0,1);
|
||||
lcd.print("Baud:");
|
||||
lcd.print(BAUDRATE);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
// check to see if characters available
|
||||
// indicating a message is coming in
|
||||
if (Serial.available())
|
||||
{
|
||||
// wait some time for rest of message to arrive
|
||||
delay(100);
|
||||
|
||||
// Clear the display before showing the new message
|
||||
lcd.clear();
|
||||
|
||||
// print the message on the LCD
|
||||
while (Serial.available() > 0)
|
||||
{
|
||||
char c;
|
||||
c = Serial.read();
|
||||
if(c != '\r' && c != '\n') // drop CR and LF characters
|
||||
lcd.write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// UpTime - simple demonstration of lcd
|
||||
// Created by Bill Perry 2020-06-26
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCD devices like the Tsingtek Display HC1627 modules
|
||||
// in i2c mode. Devices such as HC1627-B-LWH-I2C-30 or HC1627-SYH-I2C-30
|
||||
// These devices have a native I2C interface rather than use a simple I2C
|
||||
// i/o expander chip such as a PCF8574 or MCP23008.
|
||||
//
|
||||
// NOTE:
|
||||
// These devices usually need external pullups as they typically are not on
|
||||
// the module.
|
||||
// WARNING:
|
||||
// Use caution when using 3v only processors like arm and ESP8266 processors
|
||||
// when interfacing with 5v modules as not doing proper level shifting or
|
||||
// incorrectly hooking things up can damage the processor.
|
||||
//
|
||||
// Sketch will print "UpTime" on top row of lcd
|
||||
// and will print the amount of time since the Arduino has been reset
|
||||
// on the second row.
|
||||
//
|
||||
// If initialization of the LCD fails or any output fails,
|
||||
// and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// While not all modules use the same pinout,
|
||||
// Be VERY careful and check your datasheet.
|
||||
//
|
||||
// This pin table is for the Tsingtek Display HC1627-SYH-I2C-30 or
|
||||
// HC1627-SYH-I2C-30 module when it is strapped for i2c mode operation
|
||||
//
|
||||
// pin 14 is the pin closest to the edge of the PCB
|
||||
// 14 - connect to gnd
|
||||
// 13 - connect to vcc
|
||||
// 12 - ID0 --- controls bit 1 of 7 bit i2c address, strap accordingly
|
||||
// 11 - ID1 --- controls bit 2 of 7 bit i2c address, strap accordingly
|
||||
// 10 - not connected
|
||||
// 9 - not connected
|
||||
// 8 - SCL
|
||||
// 7 - SDA
|
||||
// 6 - connect to gnd
|
||||
// 5 - connect to gnd
|
||||
// 4 - connect to gnd
|
||||
// 3 - Vo Contrast Voltage input
|
||||
// 2 - VCC (5v)
|
||||
// 1 - LCD gnd
|
||||
// 15 - Backlight Anode (+5v)
|
||||
// 16 - Backlight Cathode (Gnd)
|
||||
//
|
||||
// I2C IDx address table
|
||||
// ID1 ID0 ADDR
|
||||
// L L 0x38/0x39
|
||||
// L H 0x3A/0x3B
|
||||
// H L 0x3C/0x3D
|
||||
// H H 0x3E/0x3F
|
||||
//
|
||||
// library only needs to know the base address (the lower address)
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_HC1627_I2C.h> // i2c LCD i/o class header
|
||||
|
||||
// Note, i2c address can be specified or automatically located
|
||||
// If you wish to use a specific address comment out this constructor
|
||||
// and use the constructor below that specifies the address
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_HC1627_I2C lcd;
|
||||
|
||||
//
|
||||
// manually enter base address of LCD.
|
||||
// Base Addresses
|
||||
// - 0x38, 0x3A, 0x3C, or 0x3E
|
||||
|
||||
// declare i2c address and constructor for specified i2c address
|
||||
//const int i2c_addr = 0x38;
|
||||
//hd44780_HC1627_I2C lcd(i2c_addr); // use device at this address
|
||||
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
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
|
||||
//
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// hd44780 has a fatalError() routine that blinks an led if possible
|
||||
// begin() failed so call fatalError() with the error code.
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// Print a message to the LCD
|
||||
lcd.print(" UpTime");
|
||||
|
||||
if(LCD_ROWS < 2)
|
||||
delay(3000);
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
static unsigned long lastsecs = -1; // pre-initialize with non zero value
|
||||
unsigned long secs;
|
||||
int status;
|
||||
|
||||
secs = millis() / 1000;
|
||||
|
||||
// see if 1 second has passed
|
||||
// so the display is only updated once per second
|
||||
if(secs != lastsecs)
|
||||
{
|
||||
lastsecs = secs; // keep track of last seconds
|
||||
|
||||
// set the cursor position to column 0, row 1
|
||||
// note: row 1 is the second row from top,
|
||||
// since row counting begins with 0
|
||||
// if display has only 1 line, it will appear on that line
|
||||
status = lcd.setCursor(0, 1);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// setCursor() failed so call fatalError() with the error code.
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// print uptime on lcd device: (time since last reset)
|
||||
PrintUpTime(lcd, secs);
|
||||
}
|
||||
}
|
||||
|
||||
// PrintUpTime(outdev, secs) - print uptime in HH:MM:SS format
|
||||
// outdev - the device to send output
|
||||
// secs - the total number of seconds uptime
|
||||
//
|
||||
// This is a fancy output routine.
|
||||
// outdev is a Print class object which indicates
|
||||
// where the output should be sent.
|
||||
// PrintUpTime can be used with any object that uses the Print class.
|
||||
// This code works with Serial objects, as well as the the hd44780 lcd objects.
|
||||
// i.e. you can call with Serial: PrintUpTime(Serial, seconds);
|
||||
|
||||
void PrintUpTime(Print &outdev, unsigned long secs)
|
||||
{
|
||||
unsigned int hr, mins, sec;
|
||||
|
||||
// convert total seconds to hours, mins, seconds
|
||||
mins = secs / 60; // how many total minutes
|
||||
hr = mins / 60; // how many total hours
|
||||
mins = mins % 60; // how many minutes within the hour
|
||||
sec = secs % 60; // how many seconds within the minute
|
||||
|
||||
// print uptime in HH:MM:SS format
|
||||
|
||||
if(hr > 99)
|
||||
hr %= 100; // limit hr to 0-99
|
||||
|
||||
// Print class does not support fixed width formatting
|
||||
// so insert a zero if number smaller than 10
|
||||
|
||||
if(hr < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)hr);
|
||||
outdev.write(':');
|
||||
if(mins < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)mins);
|
||||
outdev.write(':');
|
||||
if(sec < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)sec);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDcharset - Display LCD character set
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example LCDcharset.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or example
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in hd44780 examples:
|
||||
// hd44780/examples/hd44780examples/LCDcharset/LCDcharset.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDcharset
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_HC1627_I2C.h> // include i/o class header
|
||||
|
||||
// define the LCD geometry
|
||||
#define LCD_COLS 16
|
||||
#define LCD_ROWS 2
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_HC1627_I2C lcd;
|
||||
|
||||
// declare i2c address and constructor for specified i2c base address
|
||||
//const int i2c_addr = 0x3b;
|
||||
//hd44780_HC1627_I2C lcd(i2c_addr); // use device at this address
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library LCDcharset sketch source code
|
||||
#include <examples/hd44780examples/LCDcharset/LCDcharset.ino>
|
||||
@@ -0,0 +1,33 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDiSpeed - LCD Interface Speed test
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example LCDiSpeed.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or example
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in hd44780 examples:
|
||||
// hd44780/examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDiSpeed
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_HC1627_I2C.h> // include i/o class header
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_HC1627_I2C lcd;
|
||||
|
||||
// declare i2c address and constructor for specified i2c base address
|
||||
//const int i2c_addr = 0x3b;
|
||||
//hd44780_HC1627_I2C lcd(i2c_addr); // use device at this address
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library LCDiSpeed sketch source code
|
||||
#include <examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino>
|
||||
@@ -0,0 +1,40 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDiSpeed - LCD Interface Speed test
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example LCDiSpeed.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or example
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in hd44780 examples:
|
||||
// hd44780/examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDiSpeed
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_HC1627_I2C.h>
|
||||
|
||||
#if ARDUINO < 157
|
||||
#error "This sketch Requires Arduino 1.5.7 or higher"
|
||||
#endif
|
||||
|
||||
// NOTE: uses API that only works on IDE 1.5.7 and up
|
||||
#define WIRECLOCK 400000L // tell hd44780 example to use this i2c clock rate
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_HC1627_I2C lcd;
|
||||
|
||||
// declare i2c address and constructor for specified i2c base address
|
||||
//const int i2c_addr = 0x3b;
|
||||
//hd44780_HC1627_I2C lcd(i2c_addr); // use device at this address
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library LCDiSpeed sketch source code
|
||||
#include <examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino>
|
||||
@@ -0,0 +1,33 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDLibTest - LCD library test sketch
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/LCDlibTest/LCDlibTest.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDlibTest
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_HC1627_I2C.h> // include i/o class header
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_HC1627_I2C lcd;
|
||||
|
||||
// declare i2c address and constructor for specified i2c base address
|
||||
//const int i2c_addr = 0x3b;
|
||||
//hd44780_HC1627_I2C lcd(i2c_addr); // use device at this address
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/LCDlibTest/LCDlibTest.ino>
|
||||
@@ -0,0 +1,40 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDLibTest - LCD library test sketch
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/LCDlibTest/LCDlibTest.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDlibTest
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_HC1627_I2C.h> // include i/o class header
|
||||
|
||||
#if ARDUINO < 157
|
||||
#error "This sketch Requires Arduino 1.5.7 or higher"
|
||||
#endif
|
||||
|
||||
// NOTE: uses API that only works on IDE 1.5.7 and up
|
||||
#define WIRECLOCK 400000L // tell hd44780 example to use this i2c clock rate
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_HC1627_I2C lcd;
|
||||
|
||||
// declare i2c address and constructor for specified i2c base address
|
||||
//const int i2c_addr = 0x3b;
|
||||
//hd44780_HC1627_I2C lcd(i2c_addr); // use device at this address
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/LCDlibTest/LCDlibTest.ino>
|
||||
@@ -0,0 +1,33 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// lcdproc - LCD library lcdproc wrapper sketch
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/lcdproc/lcdproc.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/lcdproc
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_HC1627_I2C.h> // include i/o class header
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_HC1627_I2C lcd;
|
||||
|
||||
// declare i2c address and constructor for specified i2c base address
|
||||
//const int i2c_addr = 0x3b;
|
||||
//hd44780_HC1627_I2C lcd(i2c_addr); // use device at this address
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/lcdproc/lcdproc.ino>
|
||||
@@ -0,0 +1,40 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// lcdproc - LCD library lcdproc wrapper sketch
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/lcdproc/lcdproc.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/lcdproc
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_HC1627_I2C.h> // include i/o class header
|
||||
|
||||
#if ARDUINO < 157
|
||||
#error "This sketch Requires Arduino 1.5.7 or higher"
|
||||
#endif
|
||||
|
||||
// NOTE: uses API that only works on IDE 1.5.7 and up
|
||||
#define WIRECLOCK 400000L // tell hd44780 example to use this i2c clock rate
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_HC1627_I2C lcd;
|
||||
|
||||
// declare i2c address and constructor for specified i2c base address
|
||||
//const int i2c_addr = 0x3b;
|
||||
//hd44780_HC1627_I2C lcd(i2c_addr); // use device at this address
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/lcdproc/lcdproc.ino>
|
||||
@@ -0,0 +1,94 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// HelloWorld - simple demonstration of lcd
|
||||
// Created by Bill Perry 2016-07-02
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCDs with PCF8574 or MCP23008 chip based backpacks
|
||||
// WARNING:
|
||||
// Use caution when using 3v only processors like arm and ESP8266 processors
|
||||
// when interfacing with 5v modules as not doing proper level shifting or
|
||||
// incorrectly hooking things up can damage the processor.
|
||||
//
|
||||
// Sketch prints "Hello, World!" on the lcd
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED.
|
||||
//
|
||||
// NOTE:
|
||||
// If the sketch fails to produce the expected results, or blinks the LED,
|
||||
// run the included I2CexpDiag sketch to test the i2c signals and the LCD.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// LiquidCrystal compability:
|
||||
// Since hd44780 is LiquidCrystal API compatible, most existing LiquidCrystal
|
||||
// sketches should work with hd44780 hd44780_I2Cexp i/o class once the
|
||||
// includes are changed to use hd44780 and the lcd object constructor is
|
||||
// changed to use the hd44780_I2Cexp i/o class.
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
|
||||
|
||||
hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto config expander chip
|
||||
|
||||
// If you wish to use an i/o expander at a specific address, you can specify the
|
||||
// i2c address and let the library auto configure it. If you don't specify
|
||||
// the address, or use an address of zero, the library will search for the
|
||||
// i2c address of the device.
|
||||
// hd44780_I2Cexp lcd(i2c_address); // specify a specific i2c address
|
||||
//
|
||||
// It is also possible to create multiple/seperate lcd objects
|
||||
// and the library can still automatically locate them.
|
||||
// Example:
|
||||
// hd4480_I2Cexp lcd1;
|
||||
// hd4480_I2Cexp lcd2;
|
||||
// The individual lcds would be referenced as lcd1 and lcd2
|
||||
// i.e. lcd1.home() or lcd2.clear()
|
||||
//
|
||||
// It is also possible to specify the i2c address
|
||||
// when declaring the lcd object.
|
||||
// Example:
|
||||
// hd44780_I2Cexp lcd1(0x20);
|
||||
// hd44780_I2Cexp lcd2(0x27);
|
||||
// This ensures that each each lcd object is assigned to a specific
|
||||
// lcd device rather than letting the library automatically asign it.
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
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
|
||||
{
|
||||
// hd44780 has a fatalError() routine that blinks an led if possible
|
||||
// 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
|
||||
|
||||
// Print a message to the LCD
|
||||
lcd.print("Hello, World!");
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,315 @@
|
||||
static const int dummyvar = 0; // dummy declaration for older broken IDEs!!!!
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDCustomChars - simple demonstration of lcd custom characters
|
||||
// Created by Bill Perry 2016-10-06
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCDs with PCF8574 or MCP23008 chip based backpacks
|
||||
// WARNING:
|
||||
// Use caution when using 3v only processors like arm and ESP8266 processors
|
||||
// when interfacing with 5v modules as not doing proper level shifting or
|
||||
// incorrectly hooking things up can damage the processor.
|
||||
//
|
||||
// Sketch demonstrates how to assign custom characters to the eight hd44780
|
||||
// custom character codepoints and how to display on the LCD using
|
||||
// write() and print()
|
||||
//
|
||||
// You can create your own custom characters.
|
||||
// Here are a couple of web pages that have a tool that will generate the data
|
||||
// values needed for custom character.
|
||||
// https://kakedev.github.io/GlyphGenerator/
|
||||
// http://www.quinapalus.com/hd44780udg.html
|
||||
// https://omerk.github.io/lcdchargen
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h> // include hd44780 library header file
|
||||
#include <hd44780ioClass/hd44780_I2Cexp.h> // i/o expander/backpack class
|
||||
hd44780_I2Cexp lcd; // auto detect backpack and pin mappings
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
const int LongDelay = 5000;
|
||||
const int ShortDelay = 800;
|
||||
|
||||
int customcharRow = 1; // default to printing custom chars on row 1
|
||||
|
||||
// Below are some custom characters for demonstration
|
||||
|
||||
// You can ensure that the data for these custom characters is only
|
||||
// in flash and not in RAM by using the const qualifier.
|
||||
// However....
|
||||
// If using the AVR part, the AVR proprietary PROGMEM directive must be used.
|
||||
// PROGMEM is only required on AVR parts since the AVR parts cannot directly
|
||||
// access const data stored in flash like all the other processors.
|
||||
// PROGMEM is an AVR specific proprietary kludge that tells the linker and
|
||||
// startup code to handle the data differently.
|
||||
// PROGMEM is only used by the AVR and not required by any other processor.
|
||||
//
|
||||
// Most non AVR cores provide AVR compatibilty by providing support (emulation)
|
||||
// for the AVR proprietary PROGMEM directive and corresponding access functions,
|
||||
// but some do not.
|
||||
//
|
||||
// Because of this AVR const data and PROGMEM issue, there is no way to
|
||||
// guarantee code portability across all cores when using const data.
|
||||
//
|
||||
//
|
||||
// the hd44780 library assumes that if a const qualifier is used on the AVR
|
||||
// processor that the data has been stored in flash using the PROGMEM directive.
|
||||
// There is no way for the hd44780 library to know or detect if PROGMEM has
|
||||
// been used.
|
||||
// So if the const qualifer is used but the PROGMEM directive is not used on
|
||||
// an AVR processor, the custom char will be garbage.
|
||||
//
|
||||
// Examples:
|
||||
// For all processors other than AVR:
|
||||
// const char bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const uint8_ bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
//
|
||||
// For AVR: (and non AVR cores that have AVR PROGMEM emulation)
|
||||
// const char bell[8] PROGMEM = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const uint8_t bell[8] PROGMEM = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// OR
|
||||
// const PROGMEM char bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const PROGMEM uint8_t bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// NOTE:
|
||||
// if PROGMEM is used on older AVR compilers it generates a warning.
|
||||
//
|
||||
|
||||
uint8_t bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
uint8_t note[8] = {0x02,0x03,0x02,0x0e,0x1e,0x0c,0x00,0x00};
|
||||
uint8_t clockface[8] = {0x00,0x0e,0x15,0x17,0x11,0x0e,0x00,0x00};
|
||||
uint8_t heart[8] = {0x00,0x0a,0x1f,0x1f,0x0e,0x04,0x00,0x00};
|
||||
uint8_t duck[8] = {0x00,0x0c,0x1d,0x0f,0x0f,0x06,0x00,0x00};
|
||||
uint8_t check[8] = {0x00,0x01,0x03,0x16,0x1c,0x08,0x00,0x00};
|
||||
uint8_t cross[8] = {0x00,0x1b,0x0e,0x04,0x0e,0x1b,0x00,0x00};
|
||||
uint8_t smile[8] = {0x00,0x0a,0x0a,0x00,0x00,0x11,0x0e,0x00};
|
||||
|
||||
uint8_t degreeSymbol[8]= {0x06,0x09,0x09,0x06,0x00,0x00,0x00,0x00};
|
||||
uint8_t degreeC[8] = {0x18,0x18,0x03,0x04,0x04,0x04,0x03,0x00};
|
||||
uint8_t degreeF[8] = {0x18,0x18,0x07,0x04,0x07,0x04,0x04,0x00};
|
||||
|
||||
const PROGMEM uint8_t vsigbar[][8] = {
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0 bars, same as <space>
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x1F}, // 1 bars
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x1F,0x1F}, // 2 bars
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F}, // 3 bars
|
||||
{0x00, 0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F}, // 4 bars
|
||||
{0x00, 0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x1F}, // 5 bars
|
||||
{0x00, 0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 6 bars
|
||||
{0x00, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 7 bars
|
||||
{0x1F, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 8 bars
|
||||
};
|
||||
|
||||
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
|
||||
{
|
||||
// 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
|
||||
}
|
||||
void loop(void)
|
||||
{
|
||||
lcd.clear();
|
||||
|
||||
lcd.print("Custom Chars");
|
||||
|
||||
// create custom characters
|
||||
// int rval = createChar(charval, charmap[]);
|
||||
//
|
||||
// createChar() creates a custom character
|
||||
// for the character at the charval codepoint.
|
||||
// It returns zero if successful.
|
||||
//
|
||||
// to display the custom character, simply call write()
|
||||
// with the charval use in createChar()
|
||||
//
|
||||
// The display must be initialized *before* you attempt
|
||||
// to create custom characters.
|
||||
//
|
||||
// Note: On hd44780 displays there are 8 custom characters.
|
||||
// They are assigned to character codepoint values 0x00 to 0x07
|
||||
// The codepoints 0x08 to 0x0f are duplicates for 0x00 to 0x07
|
||||
// i.e. 0x08 is the same as 0x00, 0x09 same as 0x01, etc...
|
||||
|
||||
// create 8 custom characters
|
||||
lcd.createChar(0, bell);
|
||||
lcd.createChar(1, note);
|
||||
lcd.createChar(2, clockface);
|
||||
lcd.createChar(3, heart);
|
||||
lcd.createChar(4, duck);
|
||||
lcd.createChar(5, check);
|
||||
lcd.createChar(6, cross);
|
||||
lcd.createChar(7, smile);
|
||||
|
||||
// prepare to display the custom characters
|
||||
// on multi line displays the custom characters will be
|
||||
// displayed on the 2nd line
|
||||
// on single line displays, delay a bit to see the initial display,
|
||||
// then clear the display to display the custom characters on the top line
|
||||
if(LCD_ROWS < 2)
|
||||
{
|
||||
customcharRow = 0;
|
||||
delay(LongDelay);
|
||||
lcd.clear();
|
||||
}
|
||||
|
||||
lcd.setCursor(0, customcharRow);
|
||||
|
||||
// write() or print() can be used to display custom characters.
|
||||
//
|
||||
// To use write() pass the charval of the desired custom character.
|
||||
// lcd.write(charval);
|
||||
// NOTE:
|
||||
// The Print class has an issue that does not allow 0 (zero) to be used
|
||||
// on write() without casting it. The Arduino team refuses to fix this.
|
||||
// hd44780 has a work around in it to remove this issue so you can call
|
||||
// write() with a constant value of 0 without having to cast it.
|
||||
//
|
||||
// write() can also be used with literal characters that contain
|
||||
// an octal (base 8) escape seuence.
|
||||
// lcd.write('\###');
|
||||
//
|
||||
// To use print() pass in the charval of the desired custom character
|
||||
// as a character *not* an integer.
|
||||
// This requires using a literal character with an octal escape sequence.
|
||||
// lcd.print('\###');
|
||||
//
|
||||
|
||||
// Since both write() & print() both accept octal escaped literal characters
|
||||
// it is the most compatible & portable way of sending custom characters
|
||||
|
||||
// display all 8 custom characters.
|
||||
|
||||
// write() with character codepoint values
|
||||
lcd.write(0); // casting to an uint8_t or byte not needed with hd44780
|
||||
lcd.write(1);
|
||||
|
||||
// write() & print() with octal escaped literal characters
|
||||
lcd.write('\002'); // this is an octal escaped literal character
|
||||
lcd.write('\003'); // this is an octal escaped literal character
|
||||
lcd.print('\004'); // this is an octal escaped literal character
|
||||
lcd.print('\005'); // this is an octal escaped literal character
|
||||
|
||||
// can also drop the leading zeros on small litereal values like these
|
||||
lcd.print('\06'); // this is an octal escaped literal character
|
||||
lcd.print('\7'); // this is an octal escaped literal character
|
||||
|
||||
delay(LongDelay);
|
||||
|
||||
// You can also insert custom character codepoints into C strings.
|
||||
// To do so, insert the character codepoint value as an octal constant.
|
||||
// However,
|
||||
// because zero indicates the end of string in C you cannot use zero.
|
||||
// Example:
|
||||
// lcd.print("charval #1: \001"); // prints custom character at codepoint 1
|
||||
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code1: \001");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code2: \002");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code3: \003");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code4: \004");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code5: \005");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code6: \006");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code7: \007");
|
||||
delay(ShortDelay);
|
||||
|
||||
// Another nifty trick is that you can modify custom characters on the
|
||||
// display without having to re-write the characters on the display.
|
||||
// To do this, simply create a new character for a codepoint.
|
||||
// All characters on the display which have that codepoint will "magically"
|
||||
// change to the new custom character.
|
||||
// So for example, if the entire display was written with custom character
|
||||
// zero and character zero was a bell, if you called createChar() to
|
||||
// redefine character codepoint zero to be a duck,
|
||||
// the entire display would turn to ducks without having to send any
|
||||
// characters to the display.
|
||||
|
||||
// create the initial custom character
|
||||
lcd.createChar(0, bell);
|
||||
|
||||
// fill the custom character line with the custom character.
|
||||
lcd.setCursor(0,customcharRow);
|
||||
for(uint8_t col=0; col<LCD_COLS; col++)
|
||||
lcd.write(0);
|
||||
|
||||
delay(ShortDelay);
|
||||
|
||||
// change the single custom character previously written on the row
|
||||
// and all the characters on the row will change
|
||||
// without having to re-write the characters.
|
||||
lcd.createChar(0, note);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, clockface);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, heart);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, duck);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, check);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, cross);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, smile);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeSymbol);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeC);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeF);
|
||||
delay(ShortDelay);
|
||||
|
||||
// show multiple vertical bars rising
|
||||
// by changing the single custom character that is already written
|
||||
// to the entire row on the display
|
||||
for(int i = 0; i < 9; i++)
|
||||
{
|
||||
lcd.createChar(0, vsigbar[i]);
|
||||
delay(ShortDelay);
|
||||
}
|
||||
|
||||
delay(LongDelay);
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LineWrap - simple demonstration of automatic linewrap functionality
|
||||
// Created by Bill Perry 2017-05-10
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCDs with PCF8574 or MCP23008 chip based backpacks
|
||||
//
|
||||
// WARNING:
|
||||
// Use caution when using 3v only processors like arm and ESP8266 processors
|
||||
// when interfacing with 5v modules as not doing proper level shifting or
|
||||
// incorrectly hooking things up can damage the processor.
|
||||
//
|
||||
// Sketch demonstrates hd44780 library automatic line wrapping functionality.
|
||||
//
|
||||
// Background:
|
||||
// hd44780 LCDs do not use linear continuous memory for the characters
|
||||
// on the lines on the display.
|
||||
// This means that simply sending continuous characters to the
|
||||
// display will not fill lines and wrap appropriately as might be expected.
|
||||
// The hd44780 library solves this issue by adding a line wrapping capability
|
||||
// in s/w that can be enabled & disabled.
|
||||
// This allows the host to send characters to the display continuously and they
|
||||
// will wrap to the next lower line when the end of the visible line has been
|
||||
// reached. When on the bottom line it will wrap back to the top line.
|
||||
//
|
||||
// (Configure LCD_COLS & LCD_ROWS if desired/needed)
|
||||
// Expected behavior of the sketch:
|
||||
// - display a banner announcing the test.
|
||||
// - print the configured LCD geometry
|
||||
// - print a long text string to demostrate automatic line wrapping
|
||||
// - print lots of characters (slowly) to show how the full wrapping works.
|
||||
// (loop)
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED with the initalization error
|
||||
// code.
|
||||
//
|
||||
// NOTE:
|
||||
// If the sketch fails to produce the expected results, or blinks the LED,
|
||||
// run the included I2CexpDiag sketch to test the i2c signals and the LCD.
|
||||
//
|
||||
// Special note for certain 16x1 displays:
|
||||
// Some 16x1 displays are actually a 8x2 display that have both lines on
|
||||
// a single line on the display.
|
||||
// If you have one of these displays, simply set the geometry to 8x2 instead
|
||||
// of 16x1.
|
||||
// In normal sketches, lineWrap() mode will allow this type of display to
|
||||
// properly function as a 16x1 display in that it will allow printing up to
|
||||
// 16 characters on the display without having to manually set the cursor
|
||||
// position to print the right characters on the half of the display.
|
||||
// However, when using this 8x2 display as a 16x1 display,
|
||||
// scrollDisplayLeft() and scrollDisplayRight() will not work as intended.
|
||||
// They will shift the two halves of the display rather than the entire display.
|
||||
// This is because the hd44780 chip is doing the shift and chip is hard coded
|
||||
// internally for two lines.
|
||||
|
||||
// include the needed headers.
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
|
||||
|
||||
hd44780_I2Cexp lcd; // declare lcd object: auto locate & config exapander chip
|
||||
|
||||
// LCD geometry
|
||||
// while 16x2 will work on most displays even if the geometry is different,
|
||||
// for actual wrap testing of a particular LCD it is best to use the correct
|
||||
// geometry.
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
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>
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// begin() failed so blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// turn on automatic line wrapping
|
||||
// which automatically wraps lines to the next lower line and wraps back
|
||||
// to the top when at the bottom line
|
||||
// NOTE:
|
||||
// noLineWrap() can be used to disable automatic line wrapping.
|
||||
// _write() can be called instead of write() to send data bytes
|
||||
// to the display bypassing any special character or line wrap processing.
|
||||
lcd.lineWrap();
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("WrapTest");
|
||||
delay(2000);
|
||||
lcd.clear();
|
||||
|
||||
//print the configured LCD geometry
|
||||
lcd.print(LCD_COLS);
|
||||
lcd.print("x");
|
||||
lcd.print(LCD_ROWS);
|
||||
delay(3000);
|
||||
lcd.clear();
|
||||
|
||||
// print a long text string
|
||||
// without line wrapping enabled, the text would not wrap properly
|
||||
// to the next line.
|
||||
|
||||
if(LCD_COLS == 8)
|
||||
lcd.print("A long text line");
|
||||
else
|
||||
lcd.print("This is a very long line of text");
|
||||
delay(3000);
|
||||
|
||||
lcd.clear();
|
||||
|
||||
// now print 2 full displays worth of characters to show
|
||||
// the full wrapping.
|
||||
|
||||
lcd.cursor(); // turn on cursor so you can see where it is
|
||||
|
||||
char c = '0'; // start at the character for the number zero
|
||||
for(int i = 2*LCD_COLS*LCD_ROWS; i; i--)
|
||||
{
|
||||
lcd.print(c++);
|
||||
delay(200); // slow things down to watch the printing & wrapping
|
||||
|
||||
if(c > 0x7e) // wrap back to beginning of printable ASCII chars
|
||||
c = '!';
|
||||
}
|
||||
delay(3000);
|
||||
lcd.noCursor(); // turn off cursor
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// MultiDisplay - simple demonstration of accessing multiple lcds
|
||||
// Created by Bill Perry 2016-07-02
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCDs with PCF8574 or MCP23008 chip based backpacks
|
||||
// WARNING:
|
||||
// Use caution when using 3v only processors like arm and ESP8266 processors
|
||||
// when interfacing with 5v modules as not doing proper level shifting or
|
||||
// incorrectly hooking things up can damage the processor.
|
||||
//
|
||||
// Sketch will print lcd instance number on top line with i2c address
|
||||
// and will print the amount of time since the Arduino has been reset
|
||||
// on the second row.
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED.
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
|
||||
|
||||
// All displays will be assumed to be 16x2
|
||||
// Even if display is larger the sketch should still work correctly
|
||||
const int LCD_ROWS = 2;
|
||||
const int LCD_COLS = 16;
|
||||
|
||||
|
||||
// this lcd[] array declares an array of lcd objects.
|
||||
// an array makes using multiple lcd easy as you can acces the object
|
||||
// by using the lcds instance number as in index into the array.
|
||||
// This really only works if all the lcds are the same.
|
||||
//
|
||||
|
||||
hd44780_I2Cexp lcd[16]; // auto locate & configure up to 16 displays
|
||||
int NumLcd; // number of LCD displays found.
|
||||
|
||||
// It is also possible to create multiple/seperate lcd objects
|
||||
// and the library can still automatically locate them.
|
||||
// Example:
|
||||
// hd4480_I2Cexp lcd1;
|
||||
// hd4480_I2Cexp lcd2;
|
||||
// The individual lcds would be referenced as lcd1 and lcd2
|
||||
// i.e. lcd1.home() or lcd2.clear()
|
||||
//
|
||||
// It is also possible to specify the i2c address
|
||||
// when defining the lcd object.
|
||||
// Example:
|
||||
// hd44780_I2Cexp lcd1(0x20);
|
||||
// hd44780_I2Cexp lcd2(0x27);
|
||||
// This ensures that each each lcd object is assigned to a specific
|
||||
// lcd device rather than letting the library automatically asign it.
|
||||
|
||||
void setup()
|
||||
{
|
||||
/*
|
||||
* Locate all the displays by attempting to intialize each one
|
||||
*/
|
||||
for(NumLcd = 0; NumLcd < 16; NumLcd++)
|
||||
{
|
||||
/*
|
||||
* If begin fails, then assume we have no more displays
|
||||
*/
|
||||
if(lcd[NumLcd].begin(LCD_ROWS, LCD_COLS) != 0)
|
||||
break;
|
||||
}
|
||||
if(NumLcd == 0)
|
||||
{
|
||||
// no LCD devices found, blink the onboard LED if possible
|
||||
|
||||
fatalError(1); // this never returns
|
||||
}
|
||||
|
||||
for(int n = 0; n < NumLcd; n++)
|
||||
{
|
||||
|
||||
/*
|
||||
* Label the display with its instance number
|
||||
* and i2c address
|
||||
*/
|
||||
lcd[n].setCursor(0, 0);
|
||||
lcd[n].print("LCD:");
|
||||
lcd[n].print(n);
|
||||
|
||||
lcd[n].print(" (0x");
|
||||
lcd[n].print(lcd[n].getProp(hd44780_I2Cexp::Prop_addr), HEX);
|
||||
lcd[n].print(")");
|
||||
}
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
static unsigned long lastsecs = -1; // pre-initialize with non zero value
|
||||
unsigned long secs;
|
||||
|
||||
secs = millis() / 1000;
|
||||
|
||||
// see if 1 second has passed
|
||||
// so the display is only updated once per second
|
||||
if(secs != lastsecs)
|
||||
{
|
||||
lastsecs = secs; // keep track of last seconds
|
||||
|
||||
// write the 'uptime' to each display found
|
||||
for(int n = 0; n < NumLcd; n++)
|
||||
{
|
||||
// set the cursor to column 0, line 1
|
||||
// (note: line 1 is the second row, counting begins with 0):
|
||||
lcd[n].setCursor(0, 1);
|
||||
// print uptime on lcd device: (time since last reset)
|
||||
PrintUpTime(lcd[n], secs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PrintUpTime(outdev, secs) - print uptime in HH:MM:SS format
|
||||
// outdev - the device to send output
|
||||
// secs - the total number of seconds uptime
|
||||
void PrintUpTime(Print &outdev, unsigned long secs)
|
||||
{
|
||||
unsigned int hr, mins, sec;
|
||||
|
||||
// convert total seconds to hours, mins, seconds
|
||||
mins = secs / 60; // how many total minutes
|
||||
hr = mins / 60; // how many total hours
|
||||
mins = mins % 60; // how many minutes within the hour
|
||||
sec = secs % 60; // how many seconds within the minute
|
||||
|
||||
|
||||
// print uptime 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)
|
||||
outdev.write('0');
|
||||
outdev.print((int)hr);
|
||||
outdev.write(':');
|
||||
if(mins < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)mins);
|
||||
outdev.write(':');
|
||||
if(sec < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)sec);
|
||||
}
|
||||
|
||||
// fatalError() - loop & blink an error code
|
||||
void fatalError(int ecode)
|
||||
{
|
||||
hd44780::fatalError(ecode); // does not return
|
||||
}
|
||||
44
libraries/hd44780/examples/ioClass/hd44780_I2Cexp/README.md
Normal file
44
libraries/hd44780/examples/ioClass/hd44780_I2Cexp/README.md
Normal file
@@ -0,0 +1,44 @@
|
||||
hd44780_I2Cexp examples
|
||||
=======================
|
||||
|
||||
The examples included in this directory are for the hd44780_I2Cexp i/o class.<br>
|
||||
The hd44780_I2Cexp i/o class controls an LCD using an i2c i/o exapander backpack (PCF8574 or MCP23008)
|
||||
|
||||
|
||||
#### The following examples are included:
|
||||
|
||||
- `HelloWorld`<br>
|
||||
Prints "Hello, World!" on the lcd
|
||||
|
||||
- `I2CexpDiag`<br>
|
||||
Verifies configuation & operation of hd44780 LCDs based
|
||||
on the Hitachi HD44780 and compatible chipsets using I2C extension
|
||||
backpacks that use a simple I2C i/o expander chip. (PCF8574 or MCP23008)
|
||||
Sketch supports testing of multiple displays at once.
|
||||
|
||||
- `LCDCustomChars`<br>
|
||||
Demonstrates using custom characters
|
||||
|
||||
- `LineWrap`<br>
|
||||
Demonstrates automatic linewrap functionality
|
||||
|
||||
- `MultiDisplay`<br>
|
||||
Displays information on multiple displays at once.
|
||||
|
||||
- `ReadWrite`<br>
|
||||
Demonstrates the ability to read data from the LCD.
|
||||
|
||||
- `Serial2LCD`<br>
|
||||
Displays a message read from the serial port on the lcd.
|
||||
|
||||
- `SoftwareWire`<br>
|
||||
Demonstrates how to use the SoftwareWire library to allow using different pins
|
||||
for SDA and SCL signals.
|
||||
|
||||
- `UpTime`<br>
|
||||
Prints the amount of time since the Arduino has been reset.
|
||||
|
||||
- `hd44780examples`<br>
|
||||
The hd44780examples subdirectory contains
|
||||
hd44780_I2Cexp class specific wrapper sketches for sketches under
|
||||
examples/hd44780examples.
|
||||
@@ -0,0 +1,142 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// ReadWrite - simple demonstration reading data from LCD
|
||||
// Created by Bill Perry 2016-08-19
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCDs with PCF8574 or MCP23008 chip based backpacks
|
||||
// WARNING:
|
||||
// Use caution when using 3v only processors like arm and ESP8266 processors
|
||||
// when interfacing with 5v modules as not doing proper level shifting or
|
||||
// incorrectly hooking things up can damage the processor.
|
||||
//
|
||||
// The purpose of the sketch is to demonstrate the ability to read data from
|
||||
// the LCD.
|
||||
//
|
||||
// Sketch will print the amount of time since the Arduino has been reset
|
||||
// on the top row and then read the data from the LCD to print it on the
|
||||
// second row
|
||||
//
|
||||
// If there are errors and the arduino supports a built in LED,
|
||||
// an error status code will blink on the built in LED.
|
||||
// Error codes:
|
||||
// (1) lcd device initalization failed
|
||||
// (2) lcd device does not support reads
|
||||
// (3) error reading data from lcd device
|
||||
// (4) error writing data to lcd device
|
||||
// (5) read data mismatch
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Cexp.h>
|
||||
|
||||
hd44780_I2Cexp lcd; // declare lcd object: auto locate & config exapander chip
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_ROWS = 2;
|
||||
const int LCD_COLS = 16;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// initialize LCD with number of columns and rows:
|
||||
if( lcd.begin(LCD_COLS, LCD_ROWS))
|
||||
{
|
||||
// begin() failed so blink the onboard LED if possible
|
||||
fatalError(1);
|
||||
}
|
||||
|
||||
// check to see if device can read by attempting to read
|
||||
// the lcd status register. If it fails then assume it was
|
||||
// because the lcd device does not support reads.
|
||||
if(lcd.status() < 0)
|
||||
{
|
||||
lcd.print("No Read Support");
|
||||
fatalError(2);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static unsigned long lastsecs = -1; // pre-initialize with non zero value
|
||||
unsigned long secs;
|
||||
|
||||
secs = millis() / 1000;
|
||||
|
||||
// see if 1 second has passed
|
||||
// so the display is only updated once per second
|
||||
if(secs != lastsecs)
|
||||
{
|
||||
lastsecs = secs; // keep track of last seconds
|
||||
|
||||
// set the cursor position to top line: column 0, row 0
|
||||
lcd.setCursor(0, 0);
|
||||
|
||||
// print uptime on lcd device: (time since last reset)
|
||||
PrintUpTime(lcd, secs);
|
||||
|
||||
// Now copy the characters from the top line to the 2nd line
|
||||
// This is done character by character by:
|
||||
// - setting the character position to read
|
||||
// - reading a character
|
||||
// - setting the character position to write
|
||||
// - writing the charcter read
|
||||
for(int col = 0; col < LCD_COLS; col++)
|
||||
{
|
||||
int c;
|
||||
|
||||
lcd.setCursor(col, 0);
|
||||
if((c = lcd.read()) < 0) // if a read error, bomb out
|
||||
fatalError(3);
|
||||
|
||||
// check for ':' characters in col 2 and 5
|
||||
// if not there, consider it a fatal read error
|
||||
if((col == 2 || col == 5) && c != ':')
|
||||
fatalError(5);
|
||||
|
||||
lcd.setCursor(col, 1);
|
||||
if(lcd.write((uint8_t) c) != 1)
|
||||
fatalError(4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PrintUpTime(outdev, secs) - print uptime in HH:MM:SS format
|
||||
// outdev - the device to send output
|
||||
// secs - the total number of seconds uptime
|
||||
void PrintUpTime(Print &outdev, unsigned long secs)
|
||||
{
|
||||
unsigned int hr, mins, sec;
|
||||
|
||||
// convert total seconds to hours, mins, seconds
|
||||
mins = secs / 60; // how many total minutes
|
||||
hr = mins / 60; // how many total hours
|
||||
mins = mins % 60; // how many minutes within the hour
|
||||
sec = secs % 60; // how many seconds within the minute
|
||||
|
||||
|
||||
// print uptime 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)
|
||||
outdev.write('0');
|
||||
outdev.print((int)hr);
|
||||
outdev.write(':');
|
||||
if(mins < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)mins);
|
||||
outdev.write(':');
|
||||
if(sec < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)sec);
|
||||
}
|
||||
|
||||
// fatalError() - loop & blink and error code
|
||||
void fatalError(int ecode)
|
||||
{
|
||||
hd44780::fatalError(ecode); // does not return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// Serial2LCD - simple demonstration printing characters from serial port
|
||||
// Created by Bill Perry 2020-06-28
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCDs with PCF8574 or MCP23008 chip based backpacks
|
||||
//
|
||||
// Sketch demonstrates hd44780 how to read a message of characters from
|
||||
// serial port and display it on the LCD.
|
||||
// It takes advantage of the hd44780 library automatic line
|
||||
// wrapping capability.
|
||||
// See the LineWrap sketch for details about line wrapping.
|
||||
//
|
||||
// WARNING:
|
||||
// Use caution when using 3v only processors like arm and ESP8266 processors
|
||||
// when interfacing with 5v modules as not doing proper level shifting or
|
||||
// incorrectly hooking things up can damage the processor.
|
||||
//
|
||||
// Configure LCD_COLS, LCD_ROWS and BAUDRATE if desired/needed
|
||||
// Expected behavior of the sketch:
|
||||
// - characters received from serial port are displayed on LCD
|
||||
// - CR and LF are ignored/dropped
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED with the initalization error
|
||||
// code.
|
||||
//
|
||||
// NOTE:
|
||||
// If the sketch fails to produce the expected results, or blinks the LED,
|
||||
// run the included I2CexpDiag sketch to test the i2c signals and the LCD.
|
||||
//
|
||||
// Some 16x1 displays are actually a 8x2 display that have both lines on
|
||||
// a single line on the display.
|
||||
// If you have one of these displays, simply set the geometry to 8x2 instead
|
||||
// of 16x1.
|
||||
|
||||
// include the needed headers.
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
|
||||
|
||||
hd44780_I2Cexp lcd; // declare lcd object: auto locate & config exapander chip
|
||||
|
||||
// LCD geometry
|
||||
// while 16x2 will work on most displays even if the geometry is different,
|
||||
// for actual wrap testing of a particular LCD it is best to use the correct
|
||||
// geometry.
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
const int BAUDRATE = 9600;
|
||||
|
||||
void setup()
|
||||
{
|
||||
int status;
|
||||
|
||||
// initalize Serial port
|
||||
Serial.begin(BAUDRATE);
|
||||
|
||||
// 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>
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// begin() failed
|
||||
|
||||
Serial.print("LCD initalization failed: ");
|
||||
Serial.println(status);
|
||||
|
||||
// blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// turn on automatic line wrapping
|
||||
// which automatically wraps lines to the next lower line and wraps back
|
||||
// to the top when at the bottom line
|
||||
// NOTE:
|
||||
// noLineWrap() can be used to disable automatic line wrapping.
|
||||
// _write() can be called instead of write() to send data bytes
|
||||
// to the display bypassing any special character or line wrap processing.
|
||||
lcd.lineWrap();
|
||||
|
||||
lcd.print("Serial2LCD");
|
||||
if(LCD_ROWS > 1)
|
||||
{
|
||||
lcd.setCursor(0,1);
|
||||
lcd.print("Baud:");
|
||||
lcd.print(BAUDRATE);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
// check to see if characters available
|
||||
// indicating a message is coming in
|
||||
if (Serial.available())
|
||||
{
|
||||
// wait some time for rest of message to arrive
|
||||
delay(100);
|
||||
|
||||
// Clear the display before showing the new message
|
||||
lcd.clear();
|
||||
|
||||
// print the message on the LCD
|
||||
while (Serial.available() > 0)
|
||||
{
|
||||
char c;
|
||||
c = Serial.read();
|
||||
if(c != '\r' && c != '\n') // drop CR and LF characters
|
||||
lcd.write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// SoftwareWire - how to use SoftwareWire library with hd44780_I2Cexp
|
||||
// Created by Bill Perry 2020-01-01
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Demonstrates how to use the SoftwareWire library to allow using different
|
||||
// Arduino pins for SDA and SCL signals.
|
||||
//
|
||||
// Sketch prints "Hello, World!" on the lcd
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED.
|
||||
//
|
||||
// WARNING:
|
||||
// The SoftWareWire developers made a major change to the library June 2018
|
||||
// which is in the subsequent 1.5.1 release that causes it be unusable by
|
||||
// the hd44780 library.
|
||||
// Until this change is backed out, you will not be able to use
|
||||
// SoftWareWire beyond version 1.5.0 with the hd44780 library.
|
||||
// This sketh will do a check to try to detect the incompatibilty issue
|
||||
// and will error off with a compiler error when detected.
|
||||
// See this github issue for details:
|
||||
// https://github.com/Testato/SoftwareWire/issues/28
|
||||
//
|
||||
// NOTE:
|
||||
// Using the SoftwareWire library is not necessary on the espXXXX platform as
|
||||
// that platform already has the ability to configure the pins used in the
|
||||
// Wire library.
|
||||
// On the esp platforms, include <Wire.h> and set the pins by passing them to
|
||||
// Wire.begin(sda, scl) *before* calling lcd.begin()
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// define the Arduino pins you want to use for sda and scl signals
|
||||
// use any Arduino pins you want,
|
||||
// this uses same pins as the i2c h/w pins (SDA, SCL)
|
||||
const int sda=SDA, scl=SCL;
|
||||
|
||||
#include <SoftwareWire.h> // make sure to not use beyond version 1.5.0
|
||||
// Check for "new" SoftwareWire that breaks things
|
||||
#if defined(TwoWire_h)
|
||||
#error incompatible version of SoftwareWire library (use version 1.5.0)
|
||||
#endif
|
||||
|
||||
SoftwareWire Wire(sda,scl); // Create Wire object using desired Arduino pins
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Cexp.h>
|
||||
hd44780_I2Cexp lcd; // declare lcd object and let it auto-configure everything.
|
||||
|
||||
void setup()
|
||||
{
|
||||
int istatus;
|
||||
|
||||
istatus = lcd.begin(16,2);
|
||||
if(istatus)
|
||||
{
|
||||
// LCD initalization failed.
|
||||
// handle it anyway you want
|
||||
lcd.fatalError(istatus); // blinks error code on built in LED
|
||||
}
|
||||
lcd.print("Hello, World!");
|
||||
lcd.setCursor(0,1);
|
||||
lcd.print("SoftwareWire");
|
||||
}
|
||||
|
||||
void loop() { }
|
||||
@@ -0,0 +1,141 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// UpTime - simple demonstration of lcd
|
||||
// Created by Bill Perry 2017-05-11
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCDs with PCF8574 or MCP23008 chip based backpacks
|
||||
//
|
||||
// WARNING:
|
||||
// Use caution when using 3v only processors like arm and ESP8266 processors
|
||||
// when interfacing with 5v modules as not doing proper level shifting or
|
||||
// incorrectly hooking things up can damage the processor.
|
||||
//
|
||||
// Sketch will print "UpTime" on top row of lcd
|
||||
// and will print the amount of time since the Arduino has been reset
|
||||
// on the second row.
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED.
|
||||
//
|
||||
// NOTE:
|
||||
// If the sketch fails to produce the expected results, or blinks the LED,
|
||||
// run the included I2CexpDiag sketch to test the i2c signals and the LCD.
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
|
||||
|
||||
hd44780_I2Cexp lcd; // declare lcd object: auto locate & config exapander chip
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
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
|
||||
{
|
||||
// hd44780 has a fatalError() routine that blinks an led if possible
|
||||
// begin() failed so call fatalError() with the error code.
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
// initalization was successful, the backlight should be on now
|
||||
|
||||
// Print a message to the LCD
|
||||
lcd.print(" UpTime");
|
||||
|
||||
if(LCD_ROWS < 2)
|
||||
delay(3000);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static unsigned long lastsecs = -1; // pre-initialize with non zero value
|
||||
unsigned long secs;
|
||||
int status;
|
||||
|
||||
secs = millis() / 1000;
|
||||
|
||||
// see if 1 second has passed
|
||||
// so the display is only updated once per second
|
||||
if(secs != lastsecs)
|
||||
{
|
||||
lastsecs = secs; // keep track of last seconds
|
||||
|
||||
// set the cursor position to column 0, row 1
|
||||
// note: row 1 is the second row from top,
|
||||
// since row counting begins with 0
|
||||
// if display has only 1 line, it will appear on that line
|
||||
status = lcd.setCursor(0, 1);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// setCursor() failed so call fatalError() with the error code.
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// print uptime on lcd device: (time since last reset)
|
||||
PrintUpTime(lcd, secs);
|
||||
}
|
||||
}
|
||||
|
||||
// PrintUpTime(outdev, secs) - print uptime in HH:MM:SS format
|
||||
// outdev - the device to send output
|
||||
// secs - the total number of seconds uptime
|
||||
//
|
||||
// This is a fancy output routine.
|
||||
// outdev is a Print class object which indicates
|
||||
// where the output should be sent.
|
||||
// PrintUpTime can be used with any object that uses the Print class.
|
||||
// This code works with Serial objects, as well as the the hd44780 lcd objects.
|
||||
// i.e. you can call with Serial: PrintUpTime(Serial, seconds);
|
||||
|
||||
void PrintUpTime(Print &outdev, unsigned long secs)
|
||||
{
|
||||
unsigned int hr, mins, sec;
|
||||
|
||||
// convert total seconds to hours, mins, seconds
|
||||
mins = secs / 60; // how many total minutes
|
||||
hr = mins / 60; // how many total hours
|
||||
mins = mins % 60; // how many minutes within the hour
|
||||
sec = secs % 60; // how many seconds within the minute
|
||||
|
||||
// print uptime in HH:MM:SS format
|
||||
|
||||
if(hr > 99)
|
||||
hr %= 100; // limit hr to 0-99
|
||||
|
||||
// Print class does not support fixed width formatting
|
||||
// so insert a zero if number smaller than 10
|
||||
|
||||
if(hr < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)hr);
|
||||
outdev.write(':');
|
||||
if(mins < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)mins);
|
||||
outdev.write(':');
|
||||
if(sec < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)sec);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDcharset - Display LCD character set
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example LCDcharset.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or example
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in hd44780 examples:
|
||||
// hd44780/examples/hd44780examples/LCDcharset/LCDcharset.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDcharset
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Cexp.h> // include i/o class header
|
||||
|
||||
// define the LCD geometry
|
||||
#define LCD_COLS 16
|
||||
#define LCD_ROWS 2
|
||||
|
||||
// declare the lcd object
|
||||
hd44780_I2Cexp lcd; // auto locate and autoconfig interface pins
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library LCDcharset sketch source code
|
||||
#include <examples/hd44780examples/LCDcharset/LCDcharset.ino>
|
||||
@@ -0,0 +1,29 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDiSpeed - LCD Interface Speed test for hd44780 hd44780_I2Cexp i/o class
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example LCDiSpeed.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or example
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in hd44780 examples:
|
||||
// hd44780/examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDiSpeed
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Cexp.h> // include i/o class header
|
||||
|
||||
// declare the lcd object
|
||||
hd44780_I2Cexp lcd; // auto locate and autoconfig interface pins
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library LCDiSpeed sketch source code
|
||||
#include <examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino>
|
||||
@@ -0,0 +1,36 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDiSpeed - LCD Interface Speed test for hd44780 hd44780_I2Cexp i/o class
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example LCDiSpeed.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or example
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in hd44780 examples:
|
||||
// hd44780/examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDiSpeed
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Cexp.h> // include i/o class header
|
||||
|
||||
#if ARDUINO < 157
|
||||
#error "This sketch Requires Arduino 1.5.7 or higher"
|
||||
#endif
|
||||
|
||||
// NOTE: uses API that only works on IDE 1.5.7 and up
|
||||
#define WIRECLOCK 400000L // tell hd44780 example to use this i2c clock rate
|
||||
|
||||
// declare the lcd object
|
||||
hd44780_I2Cexp lcd; // auto locate and autoconfig interface pins
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library LCDiSpeed sketch source code
|
||||
#include <examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino>
|
||||
@@ -0,0 +1,29 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDLibTest - LCD library test sketch for hd44780 hd44780_I2Cexp i/o class
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/LCDlibTest/LCDlibTest.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDlibTest
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Cexp.h> // include i/o class header
|
||||
|
||||
// declare the lcd object
|
||||
hd44780_I2Cexp lcd; // auto locate and autoconfig interface pins
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/LCDlibTest/LCDlibTest.ino>
|
||||
@@ -0,0 +1,36 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDLibTest - LCD library test sketch for hd44780 hd44780_I2Cexp i/o class
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/LCDlibTest/LCDlibTest.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDlibTest
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Cexp.h> // include i/o class header
|
||||
|
||||
#if ARDUINO < 157
|
||||
#error "This sketch Requires Arduino 1.5.7 or higher"
|
||||
#endif
|
||||
|
||||
// NOTE: uses API that only works on IDE 1.5.7 and up
|
||||
#define WIRECLOCK 400000L // tell hd44780 example to use this i2c clock rate
|
||||
|
||||
// declare the lcd object
|
||||
hd44780_I2Cexp lcd; // auto locate and autoconfig interface pins
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/LCDlibTest/LCDlibTest.ino>
|
||||
@@ -0,0 +1,29 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// lcdproc - LCD library lcdproc wrapper sketch for hd44780_I2Cexp i/o class
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/lcdproc/lcdproc.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/lcdproc
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Cexp.h> // include i/o class header
|
||||
|
||||
// declare the lcd object
|
||||
hd44780_I2Cexp lcd; // auto locate and autoconfig interface pins
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/lcdproc/lcdproc.ino>
|
||||
@@ -0,0 +1,36 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// lcdproc - LCD library lcdproc wrapper sketch for hd44780_I2Cexp i/o class
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/lcdproc/lcdproc.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/lcdproc
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Cexp.h> // include i/o class header
|
||||
|
||||
#if ARDUINO < 157
|
||||
#error "This sketch Requires Arduino 1.5.7 or higher"
|
||||
#endif
|
||||
|
||||
// NOTE: uses API that only works on IDE 1.5.7 and up
|
||||
#define WIRECLOCK 400000L // tell hd44780 example to use this i2c clock rate
|
||||
|
||||
// declare the lcd object
|
||||
hd44780_I2Cexp lcd; // auto locate and autoconfig interface pins
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/lcdproc/lcdproc.ino>
|
||||
@@ -0,0 +1,85 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// HelloWorld - simple demonstration of lcd
|
||||
// Created by Bill Perry 2016-07-02
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCD modules that have a native I2C interface such as
|
||||
// PCF2119x, PCF2116, or certain RayStar LCDs rather than those LCD modules that
|
||||
// use an i/o expander chip based based backpack.
|
||||
// NOTE:
|
||||
// These devices usually need external pullups as they typically are not on
|
||||
// the module.
|
||||
// WARNING:
|
||||
// Use caution when using 3v only processors like arm and ESP8266 processors
|
||||
// when interfacing with 5v modules as not doing proper level shifting or
|
||||
// incorrectly hooking things up can damage the processor.
|
||||
//
|
||||
// Sketch prints "Hello, World!" on the lcd
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// LiquidCrystal compability:
|
||||
// Since hd44780 is LiquidCrystal API compatible, most existing LiquidCrystal
|
||||
// sketches should work with hd44780 hd44780_I2Clcd i/o class once the
|
||||
// includes are changed to use hd44780 and the lcd object constructor is
|
||||
// changed to use the hd44780_I2Clcd i/o class.
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Clcd.h> // i2c LCD i/o class header
|
||||
|
||||
// Note, i2c address can be specified or automatically located
|
||||
// If you wish to use a specific address comment out this constructor
|
||||
// and use the constructor below that specifies the address
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_I2Clcd lcd;
|
||||
|
||||
//
|
||||
// enter address of LCD.
|
||||
// Addresses seen so far include:
|
||||
// - 0x3a, 0x3b (PCF2119x)
|
||||
// - 0x3c (unknwon chip)
|
||||
// - 0x3d (unknwon chip)
|
||||
// - 0x3e (unknwon chip)
|
||||
// - 0x3f (unknwon chip)
|
||||
|
||||
// declare i2c address and constructor for specified i2c address
|
||||
//const int i2c_addr = 0x3e;
|
||||
//hd44780_I2Clcd lcd(i2c_addr); // use device at this address
|
||||
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
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
|
||||
//
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// begin() failed so blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// Print a message to the LCD
|
||||
lcd.print("Hello, World!");
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
@@ -0,0 +1,350 @@
|
||||
static const int dummyvar = 0; // dummy declaration for older broken IDEs!!!!
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDCustomChars - simple demonstration of lcd custom characters
|
||||
// Created by Bill Perry 2016-10-06
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCD modules that have a native I2C interface such as
|
||||
// PCF2119x, PCF2116, or certain RayStar LCDs rather than those LCD modules that
|
||||
// use an i/o expander chip based based backpack.
|
||||
// NOTE:
|
||||
// These devices usually need external pullups as they typically are not on
|
||||
// the module.
|
||||
// WARNING:
|
||||
// Use caution when using 3v only processors like arm and ESP8266 processors
|
||||
// when interfacing with 5v modules as not doing proper level shifting or
|
||||
// incorrectly hooking things up can damage the processor.
|
||||
//
|
||||
// Sketch demonstrates how to assign custom characters to the eight hd44780
|
||||
// custom character codepoints and how to display on the LCD using
|
||||
// write() and print()
|
||||
//
|
||||
// You can create your own custom characters.
|
||||
// Here are a couple of web pages that have a tool that will generate the data
|
||||
// values needed for custom character.
|
||||
// https://kakedev.github.io/GlyphGenerator/
|
||||
// http://www.quinapalus.com/hd44780udg.html
|
||||
// https://omerk.github.io/lcdchargen
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h> // include hd44780 library header file
|
||||
#include <hd44780ioClass/hd44780_I2Clcd.h> // i2c LCD i/o class header
|
||||
|
||||
// Note, i2c address can be specified or automatically located
|
||||
// If you wish to use a specific address comment out this constructor
|
||||
// and use the constructor below that specifies the address
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_I2Clcd lcd;
|
||||
|
||||
//
|
||||
// enter address of LCD.
|
||||
// Addresses seen so far include:
|
||||
// - 0x3a, 0x3b (PCF2119x)
|
||||
// - 0x3c (unknwon chip)
|
||||
// - 0x3d (unknwon chip)
|
||||
// - 0x3e (unknwon chip)
|
||||
// - 0x3f (unknwon chip)
|
||||
|
||||
// declare i2c address and constructor for specified i2c address
|
||||
//const int i2c_addr = 0x3e;
|
||||
//hd44780_I2Clcd lcd(i2c_addr); // use device at this address
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
const int LongDelay = 5000;
|
||||
const int ShortDelay = 800;
|
||||
|
||||
int customcharRow = 1; // default to printing custom chars on row 1
|
||||
|
||||
// Below are some custom characters for demonstration
|
||||
|
||||
// You can ensure that the data for these custom characters is only
|
||||
// in flash and not in RAM by using the const qualifier.
|
||||
// However....
|
||||
// If using the AVR part, the AVR proprietary PROGMEM directive must be used.
|
||||
// PROGMEM is only required on AVR parts since the AVR parts cannot directly
|
||||
// access const data stored in flash like all the other processors.
|
||||
// PROGMEM is an AVR specific proprietary kludge that tells the linker and
|
||||
// startup code to handle the data differently.
|
||||
// PROGMEM is only used by the AVR and not required by any other processor.
|
||||
//
|
||||
// Most non AVR cores provide AVR compatibilty by providing support (emulation)
|
||||
// for the AVR proprietary PROGMEM directive and corresponding access functions,
|
||||
// but some do not.
|
||||
//
|
||||
// Because of this AVR const data and PROGMEM issue, there is no way to
|
||||
// guarantee code portability across all cores when using const data.
|
||||
//
|
||||
//
|
||||
// the hd44780 library assumes that if a const qualifier is used on the AVR
|
||||
// processor that the data has been stored in flash using the PROGMEM directive.
|
||||
// There is no way for the hd44780 library to know or detect if PROGMEM has
|
||||
// been used.
|
||||
// So if the const qualifer is used but the PROGMEM directive is not used on
|
||||
// an AVR processor, the custom char will be garbage.
|
||||
//
|
||||
// Examples:
|
||||
// For all processors other than AVR:
|
||||
// const char bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const uint8_ bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
//
|
||||
// For AVR: (and non AVR cores that have AVR PROGMEM emulation)
|
||||
// const char bell[8] PROGMEM = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const uint8_t bell[8] PROGMEM = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// OR
|
||||
// const PROGMEM char bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const PROGMEM uint8_t bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// NOTE:
|
||||
// if PROGMEM is used on older AVR compilers it generates a warning.
|
||||
//
|
||||
|
||||
uint8_t bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
uint8_t note[8] = {0x02,0x03,0x02,0x0e,0x1e,0x0c,0x00,0x00};
|
||||
uint8_t clockface[8] = {0x00,0x0e,0x15,0x17,0x11,0x0e,0x00,0x00};
|
||||
uint8_t heart[8] = {0x00,0x0a,0x1f,0x1f,0x0e,0x04,0x00,0x00};
|
||||
uint8_t duck[8] = {0x00,0x0c,0x1d,0x0f,0x0f,0x06,0x00,0x00};
|
||||
uint8_t check[8] = {0x00,0x01,0x03,0x16,0x1c,0x08,0x00,0x00};
|
||||
uint8_t cross[8] = {0x00,0x1b,0x0e,0x04,0x0e,0x1b,0x00,0x00};
|
||||
uint8_t smile[8] = {0x00,0x0a,0x0a,0x00,0x00,0x11,0x0e,0x00};
|
||||
|
||||
uint8_t opnheart[8] = {0x00,0x0a,0x15,0x11,0x0a,0x04,0x00,0x00};
|
||||
|
||||
uint8_t uparrow[8] = {0x04,0x0e,0x1f,0x0e,0x0e,0x0e,0x00,0x00};
|
||||
uint8_t ruparrow[8] = {0x00,0x0f,0x03,0x05,0x09,0x10,0x00,0x00};
|
||||
uint8_t luparrow[8] = {0x00,0x1e,0x18,0x14,0x12,0x01,0x00,0x00};
|
||||
uint8_t dnarrow[8] = {0x00,0x0e,0x0e,0x0e,0x1f,0x0e,0x04,0x00};
|
||||
uint8_t rdnarrow[8] = {0x00,0x10,0x09,0x05,0x03,0x0f,0x00,0x00};
|
||||
uint8_t ldnarrow[8] = {0x00,0x01,0x12,0x14,0x18,0x1e,0x00,0x00};
|
||||
uint8_t retarrow[8] = {0x01,0x01,0x05,0x09,0x1f,0x08,0x04,0x00};
|
||||
|
||||
uint8_t hourglass[8] = {0x1f,0x11,0x0a,0x04,0x0a,0x11,0x1f,0x00};
|
||||
uint8_t degreeSymbol[8]= {0x06,0x09,0x09,0x06,0x00,0x00,0x00,0x00};
|
||||
uint8_t degreeC[8] = {0x18,0x18,0x03,0x04,0x04,0x04,0x03,0x00};
|
||||
uint8_t degreeF[8] = {0x18,0x18,0x07,0x04,0x07,0x04,0x04,0x00};
|
||||
|
||||
const PROGMEM uint8_t vsigbar[][8] = {
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0 bars, same as <space>
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x1F}, // 1 bars
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x1F,0x1F}, // 2 bars
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F}, // 3 bars
|
||||
{0x00, 0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F}, // 4 bars
|
||||
{0x00, 0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x1F}, // 5 bars
|
||||
{0x00, 0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 6 bars
|
||||
{0x00, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 7 bars
|
||||
{0x1F, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 8 bars
|
||||
};
|
||||
|
||||
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
|
||||
{
|
||||
// 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
|
||||
}
|
||||
void loop(void)
|
||||
{
|
||||
lcd.clear();
|
||||
|
||||
lcd.print("Custom Chars");
|
||||
|
||||
// create custom characters
|
||||
// int rval = createChar(charval, charmap[]);
|
||||
//
|
||||
// createChar() creates a custom character
|
||||
// for the character at the charval codepoint.
|
||||
// It returns zero if successful.
|
||||
//
|
||||
// to display the custom character, simply call write()
|
||||
// with the charval use in createChar()
|
||||
//
|
||||
// The display must be initialized *before* you attempt
|
||||
// to create custom characters.
|
||||
//
|
||||
// Note: On hd44780 displays there are 8 custom characters.
|
||||
// They are assigned to character codepoint values 0x00 to 0x07
|
||||
// The codepoints 0x08 to 0x0f are duplicates for 0x00 to 0x07
|
||||
// i.e. 0x08 is the same as 0x00, 0x09 same as 0x01, etc...
|
||||
|
||||
// create 8 custom characters
|
||||
lcd.createChar(0, bell);
|
||||
lcd.createChar(1, note);
|
||||
lcd.createChar(2, clockface);
|
||||
lcd.createChar(3, heart);
|
||||
lcd.createChar(4, duck);
|
||||
lcd.createChar(5, check);
|
||||
lcd.createChar(6, cross);
|
||||
lcd.createChar(7, smile);
|
||||
|
||||
// prepare to display the custom characters
|
||||
// on multi line displays the custom characters will be
|
||||
// displayed on the 2nd line
|
||||
// on single line displays, delay a bit to see the initial display,
|
||||
// then clear the display to display the custom characters on the top line
|
||||
if(LCD_ROWS < 2)
|
||||
{
|
||||
customcharRow = 0;
|
||||
delay(LongDelay);
|
||||
lcd.clear();
|
||||
}
|
||||
|
||||
lcd.setCursor(0, customcharRow);
|
||||
|
||||
// write() or print() can be used to display custom characters.
|
||||
//
|
||||
// To use write() pass the charval of the desired custom character.
|
||||
// lcd.write(charval);
|
||||
// NOTE:
|
||||
// The Print class has an issue that does not allow 0 (zero) to be used
|
||||
// on write() without casting it. The Arduino team refuses to fix this.
|
||||
// hd44780 has a work around in it to remove this issue so you can call
|
||||
// write() with a constant value of 0 without having to cast it.
|
||||
//
|
||||
// write() can also be used with literal characters that contain
|
||||
// an octal (base 8) escape seuence.
|
||||
// lcd.write('\###');
|
||||
//
|
||||
// To use print() pass in the charval of the desired custom character
|
||||
// as a character *not* an integer.
|
||||
// This requires using a literal character with an octal escape sequence.
|
||||
// lcd.print('\###');
|
||||
//
|
||||
|
||||
// Since both write() & print() both accept octal escaped literal characters
|
||||
// it is the most compatible & portable way of sending custom characters
|
||||
|
||||
// display all 8 custom characters.
|
||||
|
||||
// write() with character codepoint values
|
||||
lcd.write(0); // casting to an uint8_t or byte not needed with hd44780
|
||||
lcd.write(1);
|
||||
|
||||
// write() & print() with octal escaped literal characters
|
||||
lcd.write('\002'); // this is an octal escaped literal character
|
||||
lcd.write('\003'); // this is an octal escaped literal character
|
||||
lcd.print('\004'); // this is an octal escaped literal character
|
||||
lcd.print('\005'); // this is an octal escaped literal character
|
||||
|
||||
// can also drop the leading zeros on small litereal values like these
|
||||
lcd.print('\06'); // this is an octal escaped literal character
|
||||
lcd.print('\7'); // this is an octal escaped literal character
|
||||
|
||||
delay(LongDelay);
|
||||
|
||||
// You can also insert custom character codepoints into C strings.
|
||||
// To do so, insert the character codepoint value as an octal constant.
|
||||
// However,
|
||||
// because zero indicates the end of string in C you cannot use zero.
|
||||
// Example:
|
||||
// lcd.print("charval #1: \001"); // prints custom character at codepoint 1
|
||||
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code1: \001");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code2: \002");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code3: \003");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code4: \004");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code5: \005");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code6: \006");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code7: \007");
|
||||
delay(ShortDelay);
|
||||
|
||||
// Another nifty trick is that you can modify custom characters on the
|
||||
// display without having to re-write the characters on the display.
|
||||
// To do this, simply create a new character for a codepoint.
|
||||
// All characters on the display which have that codepoint will "magically"
|
||||
// change to the new custom character.
|
||||
// So for example, if the entire display was written with custom character
|
||||
// zero and character zero was a bell, if you called createChar() to
|
||||
// redefine character codepoint zero to be a duck,
|
||||
// the entire display would turn to ducks without having to send any
|
||||
// characters to the display.
|
||||
|
||||
// create the initial custom character
|
||||
lcd.createChar(0, bell);
|
||||
|
||||
// fill the custom character line with the custom character.
|
||||
lcd.setCursor(0,customcharRow);
|
||||
for(uint8_t col=0; col<LCD_COLS; col++)
|
||||
lcd.write(0);
|
||||
|
||||
delay(ShortDelay);
|
||||
|
||||
// change the single custom character previously written on the row
|
||||
// and all the characters on the row will change
|
||||
// without having to re-write the characters.
|
||||
lcd.createChar(0, note);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, clockface);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, heart);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, duck);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, check);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, cross);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, smile);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeSymbol);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeC);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeF);
|
||||
delay(ShortDelay);
|
||||
|
||||
// show multiple vertical bars rising
|
||||
// by changing the single custom character that is already written
|
||||
// to the entire row on the display
|
||||
for(int i = 0; i < 9; i++)
|
||||
{
|
||||
lcd.createChar(0, vsigbar[i]);
|
||||
delay(ShortDelay);
|
||||
}
|
||||
|
||||
delay(LongDelay);
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LineWrap - simple demonstration of automatic linewrap functionality
|
||||
// Created by Bill Perry 2017-05-10
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCD modules that have a native I2C interface such as
|
||||
// PCF2119x, PCF2116, or certain RayStar LCDs rather than those LCD modules that
|
||||
// use an i/o expander chip based based backpack.
|
||||
//
|
||||
// NOTE:
|
||||
// These devices usually need external pullups as they typically are not on
|
||||
// the module.
|
||||
// WARNING:
|
||||
// Use caution when using 3v only processors like arm and ESP8266 processors
|
||||
// when interfacing with 5v modules as not doing proper level shifting or
|
||||
// incorrectly hooking things up can damage the processor.
|
||||
//
|
||||
// Sketch demonstrates hd44780 library automatic line wrapping functionality.
|
||||
//
|
||||
// Background:
|
||||
// hd44780 LCDs do not use linear continuous memory for the characters
|
||||
// on the lines on the display.
|
||||
// This means that simply sending continuous characters to the
|
||||
// display will not fill lines and wrap appropriately as might be expected.
|
||||
// The hd44780 library solves this issue by adding a line wrapping capability
|
||||
// in s/w that can be enabled & disabled.
|
||||
// This allows the host to send characters to the display continuously and they
|
||||
// will wrap to the next lower line when the end of the visible line has been
|
||||
// reached. When on the bottom line it will wrap back to the top line.
|
||||
//
|
||||
// (Configure LCD_COLS & LCD_ROWS if desired/needed)
|
||||
// Expected behavior of the sketch:
|
||||
// - display a banner announcing the test.
|
||||
// - print the configured LCD geometry
|
||||
// - print a long text string to demostrate automatic line wrapping
|
||||
// - print lots of characters (slowly) to show how the full wrapping works.
|
||||
// (loop)
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED with the initalization error
|
||||
// code.
|
||||
//
|
||||
// Special note for certain 16x1 displays:
|
||||
// Some 16x1 displays are actually a 8x2 display that have both lines on
|
||||
// a single line on the display.
|
||||
// If you have one of these displays, simply set the geometry to 8x2 instead
|
||||
// of 16x1.
|
||||
// In normal sketches, lineWrap() mode will allow this type of display to
|
||||
// properly function as a 16x1 display in that it will allow printing up to
|
||||
// 16 characters on the display without having to manually set the cursor
|
||||
// position to print the right characters on the half of the display.
|
||||
// However, when using this 8x2 display as a 16x1 display,
|
||||
// scrollDisplayLeft() and scrollDisplayRight() will not work as intended.
|
||||
// They will shift the two halves of the display rather than the entire display.
|
||||
// This is because the hd44780 chip is doing the shift and chip is hard coded
|
||||
// internally for two lines.
|
||||
|
||||
|
||||
// include the needed headers.
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_I2Clcd.h> // i2c LCD i/o class header
|
||||
|
||||
// Note, i2c address can be specified or automatically located
|
||||
// If you wish to use a specific address comment out this constructor
|
||||
// and use the constructor below that specifies the address
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_I2Clcd lcd;
|
||||
|
||||
//
|
||||
// enter address of LCD.
|
||||
// Addresses seen so far include:
|
||||
// - 0x3a, 0x3b (PCF2119x)
|
||||
// - 0x3c (unknwon chip)
|
||||
// - 0x3d (unknwon chip)
|
||||
// - 0x3e (unknwon chip)
|
||||
// - 0x3f (unknwon chip)
|
||||
|
||||
// declare i2c address and constructor for specified i2c address
|
||||
//const int i2c_addr = 0x3e;
|
||||
//hd44780_I2Clcd lcd(i2c_addr); // use device at this address
|
||||
|
||||
|
||||
// LCD geometry
|
||||
// while 16x2 will work on most displays even if the geometry is different,
|
||||
// for actual wrap testing of a particular LCD it is best to use the correct
|
||||
// geometry.
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
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>
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// begin() failed so blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// turn on automatic line wrapping
|
||||
// which automatically wraps lines to the next lower line and wraps back
|
||||
// to the top when at the bottom line
|
||||
// NOTE:
|
||||
// noLineWrap() can be used to disable automatic line wrapping.
|
||||
// _write() can be called instead of write() to send data bytes
|
||||
// to the display bypassing any special character or line wrap processing.
|
||||
lcd.lineWrap();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("WrapTest");
|
||||
delay(2000);
|
||||
lcd.clear();
|
||||
|
||||
//print the configured LCD geometry
|
||||
lcd.print(LCD_COLS);
|
||||
lcd.print("x");
|
||||
lcd.print(LCD_ROWS);
|
||||
delay(3000);
|
||||
lcd.clear();
|
||||
|
||||
// print a long text string
|
||||
// without line wrapping enabled, the text would not wrap properly
|
||||
// to the next line.
|
||||
|
||||
if(LCD_COLS == 8)
|
||||
lcd.print("A long text line");
|
||||
else
|
||||
lcd.print("This is a very long line of text");
|
||||
delay(3000);
|
||||
|
||||
lcd.clear();
|
||||
|
||||
// now print 2 full displays worth of characters to show
|
||||
// the full wrapping.
|
||||
|
||||
lcd.cursor(); // turn on cursor so you can see where it is
|
||||
|
||||
char c = '0'; // start at the character for the number zero
|
||||
for(int i = 2*LCD_COLS*LCD_ROWS; i; i--)
|
||||
{
|
||||
lcd.print(c++);
|
||||
delay(200); // slow things down to watch the printing & wrapping
|
||||
|
||||
if(c > 0x7e) // wrap back to beginning of printable ASCII chars
|
||||
c = '!';
|
||||
}
|
||||
delay(3000);
|
||||
lcd.noCursor(); // turn off cursor
|
||||
}
|
||||
27
libraries/hd44780/examples/ioClass/hd44780_I2Clcd/README.md
Normal file
27
libraries/hd44780/examples/ioClass/hd44780_I2Clcd/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
hd44780_I2Clcd examples
|
||||
=======================
|
||||
|
||||
The examples included in this directory are for the hd44780_I2Clcd i/o class.<br>
|
||||
The hd44780_I2Clcd i/o class controls an LCD with a native i2c interface that uses chips like the PCF2116, PCF2119x etc...
|
||||
|
||||
#### The following examples are included:
|
||||
|
||||
- `HelloWorld`<br>
|
||||
Prints "Hello, World!" on the lcd
|
||||
|
||||
- `LCDCustomChars`<br>
|
||||
Demonstrates using custom characters
|
||||
|
||||
- `LineWrap`<br>
|
||||
Demonstrates automatic linewrap functionality
|
||||
|
||||
- `Serial2LCD`<br>
|
||||
Displays a message read from the serial port on the lcd.
|
||||
|
||||
- `UpTime`<br>
|
||||
Prints the amount of time since the Arduino has been reset.
|
||||
|
||||
- `hd44780examples`<br>
|
||||
The hd44780examples subdirectory contains
|
||||
hd44780_I2Clcd class specific wrapper sketches for sketches under
|
||||
examples/hd44780examples.
|
||||
@@ -0,0 +1,139 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// Serial2LCD - simple demonstration printing characters from serial port
|
||||
// Created by Bill Perry 2020-06-28
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCD modules that have a native I2C interface such as
|
||||
// PCF2119x, PCF2116, or certain RayStar LCDs rather than those LCD modules that
|
||||
// use an i/o expander chip based based backpack.
|
||||
//
|
||||
// Sketch demonstrates hd44780 how to read a message of characters from
|
||||
// serial port and display it on the LCD.
|
||||
// It takes advantage of the hd44780 library automatic line
|
||||
// wrapping capability.
|
||||
// See the LineWrap sketch for details about line wrapping.
|
||||
//
|
||||
// NOTE:
|
||||
// These devices usually need external pullups as they typically are not on
|
||||
// the module.
|
||||
// WARNING:
|
||||
// Use caution when using 3v only processors like arm and ESP8266 processors
|
||||
// when interfacing with 5v modules as not doing proper level shifting or
|
||||
// incorrectly hooking things up can damage the processor.
|
||||
//
|
||||
// Configure LCD_COLS, LCD_ROWS and BAUDRATE if desired/needed
|
||||
// Expected behavior of the sketch:
|
||||
// - characters received from serial port are displayed on LCD
|
||||
// - CR and LF are ignored/dropped
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED with the initalization error
|
||||
// code.
|
||||
//
|
||||
// Some 16x1 displays are actually a 8x2 display that have both lines on
|
||||
// a single line on the display.
|
||||
// If you have one of these displays, simply set the geometry to 8x2 instead
|
||||
// of 16x1.
|
||||
|
||||
// include the needed headers.
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_I2Clcd.h> // i2c LCD i/o class header
|
||||
|
||||
// Note, i2c address can be specified or automatically located
|
||||
// If you wish to use a specific address comment out this constructor
|
||||
// and use the constructor below that specifies the address
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_I2Clcd lcd;
|
||||
|
||||
//
|
||||
// enter address of LCD.
|
||||
// Addresses seen so far include:
|
||||
// - 0x3a, 0x3b (PCF2119x)
|
||||
// - 0x3c (unknwon chip)
|
||||
// - 0x3d (unknwon chip)
|
||||
// - 0x3e (unknwon chip)
|
||||
// - 0x3f (unknwon chip)
|
||||
|
||||
// declare i2c address and constructor for specified i2c address
|
||||
//const int i2c_addr = 0x3e;
|
||||
//hd44780_I2Clcd lcd(i2c_addr); // use device at this address
|
||||
|
||||
// LCD geometry
|
||||
// while 16x2 will work on most displays even if the geometry is different,
|
||||
// for actual wrap testing of a particular LCD it is best to use the correct
|
||||
// geometry.
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
const int BAUDRATE = 9600;
|
||||
|
||||
void setup()
|
||||
{
|
||||
int status;
|
||||
|
||||
// initalize Serial port
|
||||
Serial.begin(BAUDRATE);
|
||||
|
||||
// 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>
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// begin() failed
|
||||
|
||||
Serial.print("LCD initalization failed: ");
|
||||
Serial.println(status);
|
||||
|
||||
// blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// turn on automatic line wrapping
|
||||
// which automatically wraps lines to the next lower line and wraps back
|
||||
// to the top when at the bottom line
|
||||
// NOTE:
|
||||
// noLineWrap() can be used to disable automatic line wrapping.
|
||||
// _write() can be called instead of write() to send data bytes
|
||||
// to the display bypassing any special character or line wrap processing.
|
||||
lcd.lineWrap();
|
||||
|
||||
lcd.print("Serial2LCD");
|
||||
if(LCD_ROWS > 1)
|
||||
{
|
||||
lcd.setCursor(0,1);
|
||||
lcd.print("Baud:");
|
||||
lcd.print(BAUDRATE);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
// check to see if characters available
|
||||
// indicating a message is coming in
|
||||
if (Serial.available())
|
||||
{
|
||||
// wait some time for rest of message to arrive
|
||||
delay(100);
|
||||
|
||||
// Clear the display before showing the new message
|
||||
lcd.clear();
|
||||
|
||||
// print the message on the LCD
|
||||
while (Serial.available() > 0)
|
||||
{
|
||||
char c;
|
||||
c = Serial.read();
|
||||
if(c != '\r' && c != '\n') // drop CR and LF characters
|
||||
lcd.write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// UpTime - simple demonstration of lcd
|
||||
// Created by Bill Perry 2017-05-11
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCD modules that have a native I2C interface such as
|
||||
// PCF2119x, PCF2116, or certain RayStar LCDs rather than those LCD modules that
|
||||
// use an i/o expander chip based based backpack.
|
||||
//
|
||||
// NOTE:
|
||||
// These devices usually need external pullups as they typically are not on
|
||||
// the module.
|
||||
// WARNING:
|
||||
// Use caution when using 3v only processors like arm and ESP8266 processors
|
||||
// when interfacing with 5v modules as not doing proper level shifting or
|
||||
// incorrectly hooking things up can damage the processor.
|
||||
//
|
||||
// Sketch will print "UpTime" on top row of lcd
|
||||
// and will print the amount of time since the Arduino has been reset
|
||||
// on the second row.
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED.
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_I2Clcd.h> // i2c LCD i/o class header
|
||||
|
||||
// Note, i2c address can be specified or automatically located
|
||||
// If you wish to use a specific address comment out this constructor
|
||||
// and use the constructor below that specifies the address
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_I2Clcd lcd;
|
||||
|
||||
//
|
||||
// enter address of LCD.
|
||||
// Addresses seen so far include:
|
||||
// - 0x3a, 0x3b (PCF2119x)
|
||||
// - 0x3c (unknwon chip)
|
||||
// - 0x3d (unknwon chip)
|
||||
// - 0x3e (unknwon chip)
|
||||
// - 0x3f (unknwon chip)
|
||||
|
||||
// declare i2c address and constructor for specified i2c address
|
||||
//const int i2c_addr = 0x3e;
|
||||
//hd44780_I2Clcd lcd(i2c_addr); // use device at this address
|
||||
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
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
|
||||
//
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// hd44780 has a fatalError() routine that blinks an led if possible
|
||||
// begin() failed so call fatalError() with the error code.
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// Print a message to the LCD
|
||||
lcd.print(" UpTime");
|
||||
|
||||
if(LCD_ROWS < 2)
|
||||
delay(3000);
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
static unsigned long lastsecs = -1; // pre-initialize with non zero value
|
||||
unsigned long secs;
|
||||
int status;
|
||||
|
||||
secs = millis() / 1000;
|
||||
|
||||
// see if 1 second has passed
|
||||
// so the display is only updated once per second
|
||||
if(secs != lastsecs)
|
||||
{
|
||||
lastsecs = secs; // keep track of last seconds
|
||||
|
||||
// set the cursor position to column 0, row 1
|
||||
// note: row 1 is the second row from top,
|
||||
// since row counting begins with 0
|
||||
// if display has only 1 line, it will appear on that line
|
||||
status = lcd.setCursor(0, 1);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// setCursor() failed so call fatalError() with the error code.
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// print uptime on lcd device: (time since last reset)
|
||||
PrintUpTime(lcd, secs);
|
||||
}
|
||||
}
|
||||
|
||||
// PrintUpTime(outdev, secs) - print uptime in HH:MM:SS format
|
||||
// outdev - the device to send output
|
||||
// secs - the total number of seconds uptime
|
||||
//
|
||||
// This is a fancy output routine.
|
||||
// outdev is a Print class object which indicates
|
||||
// where the output should be sent.
|
||||
// PrintUpTime can be used with any object that uses the Print class.
|
||||
// This code works with Serial objects, as well as the the hd44780 lcd objects.
|
||||
// i.e. you can call with Serial: PrintUpTime(Serial, seconds);
|
||||
|
||||
void PrintUpTime(Print &outdev, unsigned long secs)
|
||||
{
|
||||
unsigned int hr, mins, sec;
|
||||
|
||||
// convert total seconds to hours, mins, seconds
|
||||
mins = secs / 60; // how many total minutes
|
||||
hr = mins / 60; // how many total hours
|
||||
mins = mins % 60; // how many minutes within the hour
|
||||
sec = secs % 60; // how many seconds within the minute
|
||||
|
||||
// print uptime in HH:MM:SS format
|
||||
|
||||
if(hr > 99)
|
||||
hr %= 100; // limit hr to 0-99
|
||||
|
||||
// Print class does not support fixed width formatting
|
||||
// so insert a zero if number smaller than 10
|
||||
|
||||
if(hr < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)hr);
|
||||
outdev.write(':');
|
||||
if(mins < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)mins);
|
||||
outdev.write(':');
|
||||
if(sec < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)sec);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDcharset - Display LCD character set
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example LCDcharset.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or example
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in hd44780 examples:
|
||||
// hd44780/examples/hd44780examples/LCDcharset/LCDcharset.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDcharset
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Clcd.h> // include i/o class header
|
||||
|
||||
// define the LCD geometry
|
||||
#define LCD_COLS 16
|
||||
#define LCD_ROWS 2
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_I2Clcd lcd;
|
||||
|
||||
// declare i2c address and constructor for specified i2c address
|
||||
//const int i2c_addr = 0x3e;
|
||||
//hd44780_I2Clcd lcd(i2c_addr); // use device at this address
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library LCDcharset sketch source code
|
||||
#include <examples/hd44780examples/LCDcharset/LCDcharset.ino>
|
||||
@@ -0,0 +1,33 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDiSpeed - LCD Interface Speed test
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example LCDiSpeed.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or example
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in hd44780 examples:
|
||||
// hd44780/examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDiSpeed
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Clcd.h> // include i/o class header
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_I2Clcd lcd;
|
||||
|
||||
// declare i2c address and constructor for specified i2c address
|
||||
//const int i2c_addr = 0x3e;
|
||||
//hd44780_I2Clcd lcd(i2c_addr); // use device at this address
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library LCDiSpeed sketch source code
|
||||
#include <examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino>
|
||||
@@ -0,0 +1,40 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDiSpeed - LCD Interface Speed test
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example LCDiSpeed.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or example
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in hd44780 examples:
|
||||
// hd44780/examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDiSpeed
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Clcd.h>
|
||||
|
||||
#if ARDUINO < 157
|
||||
#error "This sketch Requires Arduino 1.5.7 or higher"
|
||||
#endif
|
||||
|
||||
// NOTE: uses API that only works on IDE 1.5.7 and up
|
||||
#define WIRECLOCK 400000L // tell hd44780 example to use this i2c clock rate
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_I2Clcd lcd;
|
||||
|
||||
// declare i2c address and constructor for specified i2c address
|
||||
//const int i2c_addr = 0x3e;
|
||||
//hd44780_I2Clcd lcd(i2c_addr); // use device at this address
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library LCDiSpeed sketch source code
|
||||
#include <examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino>
|
||||
@@ -0,0 +1,33 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDLibTest - LCD library test sketch
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/LCDlibTest/LCDlibTest.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDlibTest
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Clcd.h> // include i/o class header
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_I2Clcd lcd;
|
||||
|
||||
// declare i2c address and constructor for specified i2c address
|
||||
//const int i2c_addr = 0x3e;
|
||||
//hd44780_I2Clcd lcd(i2c_addr); // use device at this address
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/LCDlibTest/LCDlibTest.ino>
|
||||
@@ -0,0 +1,40 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDLibTest - LCD library test sketch
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/LCDlibTest/LCDlibTest.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDlibTest
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Clcd.h> // include i/o class header
|
||||
|
||||
#if ARDUINO < 157
|
||||
#error "This sketch Requires Arduino 1.5.7 or higher"
|
||||
#endif
|
||||
|
||||
// NOTE: uses API that only works on IDE 1.5.7 and up
|
||||
#define WIRECLOCK 400000L // tell hd44780 example to use this i2c clock rate
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_I2Clcd lcd;
|
||||
|
||||
// declare i2c address and constructor for specified i2c address
|
||||
//const int i2c_addr = 0x3e;
|
||||
//hd44780_I2Clcd lcd(i2c_addr); // use device at this address
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/LCDlibTest/LCDlibTest.ino>
|
||||
@@ -0,0 +1,33 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// lcdproc - LCD library lcdproc wrapper sketch
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/lcdproc/lcdproc.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/lcdproc
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Clcd.h> // include i/o class header
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_I2Clcd lcd;
|
||||
|
||||
// declare i2c address and constructor for specified i2c address
|
||||
//const int i2c_addr = 0x3e;
|
||||
//hd44780_I2Clcd lcd(i2c_addr); // use device at this address
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/lcdproc/lcdproc.ino>
|
||||
@@ -0,0 +1,40 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// lcdproc - LCD library lcdproc wrapper sketch
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/lcdproc/lcdproc.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/lcdproc
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Clcd.h> // include i/o class header
|
||||
|
||||
#if ARDUINO < 157
|
||||
#error "This sketch Requires Arduino 1.5.7 or higher"
|
||||
#endif
|
||||
|
||||
// NOTE: uses API that only works on IDE 1.5.7 and up
|
||||
#define WIRECLOCK 400000L // tell hd44780 example to use this i2c clock rate
|
||||
|
||||
// declare the lcd object for auto i2c address location
|
||||
hd44780_I2Clcd lcd;
|
||||
|
||||
// declare i2c address and constructor for specified i2c address
|
||||
//const int i2c_addr = 0x3e;
|
||||
//hd44780_I2Clcd lcd(i2c_addr); // use device at this address
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/lcdproc/lcdproc.ino>
|
||||
@@ -0,0 +1,92 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// HelloWorld - simple demonstration of lcd
|
||||
// Created by Bill Perry 2016-07-02
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for the Nortake CU165ECBP-T2J display
|
||||
//
|
||||
// Sketch prints "Hello, World!" on the LCD
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED.
|
||||
//
|
||||
// Datasheet can be found here:
|
||||
// http://www.blog.zapro.dk/wp-content/CU165.pdf
|
||||
// Full datasheet/release notes:
|
||||
// http://www.blog.zapro.dk/wp-content/CU165ECPB_T2J_specification.pdf
|
||||
//
|
||||
// The device uses SPI for communication.
|
||||
// Pinout:
|
||||
// 1 Vcc
|
||||
// 2 GND
|
||||
// 3 /CS (SS) - Digital Pin 10 on Uno
|
||||
// 4 CLK (SCK) - Digital Pin 13 on Uno
|
||||
// 5 DATA (MOSI) - Digital Pin 11 on Uno
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// LiquidCrystal compability:
|
||||
// Since hd44780 is LiquidCrystal API compatible, most existing LiquidCrystal
|
||||
// sketches should work with hd44780 hd44780_NTCU165ECPB i/o class once the
|
||||
// includes are changed to use hd44780 and the lcd object constructor is
|
||||
// changed to use the hd44780_I2CNTCU165ECPB i/o class/
|
||||
|
||||
#include <SPI.h> // optional, include to use h/w spi
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_NTCU165ECPB.h> // include io class header
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// will not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCU165ECPB lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_ROWS = 1;
|
||||
const int LCD_COLS = 16;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Special Note:
|
||||
// =============
|
||||
// Since this device uses a write only SPI interface, there is no way for
|
||||
// the library/sketch to know if the device is present or if there is any
|
||||
// type of issue communicating with the device.
|
||||
// So while begin() returns a status as to whether it was successful,
|
||||
// the library will never report a failure since it has no way of detecting
|
||||
// a communication or initialization issue.
|
||||
|
||||
// initialize LCD with number of columns and rows:
|
||||
lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
|
||||
// Print a message to the LCD
|
||||
lcd.print("Hello, World!");
|
||||
}
|
||||
|
||||
void loop(){}
|
||||
@@ -0,0 +1,361 @@
|
||||
static const int dummyvar = 0; // dummy declaration for older broken IDEs!!!!
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDCustomChars - simple demonstration of lcd custom characters
|
||||
// Created by Bill Perry 2016-10-06
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for the Nortake CU165ECBP-T2J display
|
||||
//
|
||||
// Sketch demonstrates how to assign custom characters to the eight hd44780
|
||||
// custom character codepoints and how to display on the LCD using
|
||||
// write() and print()
|
||||
//
|
||||
// You can create your own custom characters.
|
||||
// Here are a couple of web pages that have a tool that will generate the data
|
||||
// values needed for custom character.
|
||||
// https://kakedev.github.io/GlyphGenerator/
|
||||
// http://www.quinapalus.com/hd44780udg.html
|
||||
// https://omerk.github.io/lcdchargen
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED.
|
||||
//
|
||||
// Datasheet can be found here:
|
||||
// http://www.blog.zapro.dk/wp-content/CU165.pdf
|
||||
// Full datasheet/release notes:
|
||||
// http://www.blog.zapro.dk/wp-content/CU165ECPB_T2J_specification.pdf
|
||||
//
|
||||
// The device uses SPI for communication.
|
||||
// Pinout:
|
||||
// 1 Vcc
|
||||
// 2 GND
|
||||
// 3 /CS (SS) - Digital Pin 10 on Uno
|
||||
// 4 CLK (SCK) - Digital Pin 13 on Uno
|
||||
// 5 DATA (MOSI) - Digital Pin 11 on Uno
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// LiquidCrystal compability:
|
||||
// Since hd44780 is LiquidCrystal API compatible, most existing LiquidCrystal
|
||||
// sketches should work with hd44780 hd44780_NTCU165ECPB i/o class once the
|
||||
// includes are changed to use hd44780 and the lcd object constructor is
|
||||
// changed to use the hd44780_I2CNTCU165ECPB i/o class/
|
||||
|
||||
#include <SPI.h> // optional, include to use h/w spi
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_NTCU165ECPB.h> // include io class header
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// will not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCU165ECPB lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 1;
|
||||
|
||||
const int LongDelay = 5000;
|
||||
const int ShortDelay = 800;
|
||||
|
||||
int customcharRow = 1; // default to printing custom chars on row 1
|
||||
|
||||
// Below are some custom characters for demonstration
|
||||
|
||||
// You can ensure that the data for these custom characters is only
|
||||
// in flash and not in RAM by using the const qualifier.
|
||||
// However....
|
||||
// If using the AVR part, the AVR proprietary PROGMEM directive must be used.
|
||||
// PROGMEM is only required on AVR parts since the AVR parts cannot directly
|
||||
// access const data stored in flash like all the other processors.
|
||||
// PROGMEM is an AVR specific proprietary kludge that tells the linker and
|
||||
// startup code to handle the data differently.
|
||||
// PROGMEM is only used by the AVR and not required by any other processor.
|
||||
//
|
||||
// Most non AVR cores provide AVR compatibilty by providing support (emulation)
|
||||
// for the AVR proprietary PROGMEM directive and corresponding access functions,
|
||||
// but some do not.
|
||||
//
|
||||
// Because of this AVR const data and PROGMEM issue, there is no way to
|
||||
// guarantee code portability across all cores when using const data.
|
||||
//
|
||||
//
|
||||
// the hd44780 library assumes that if a const qualifier is used on the AVR
|
||||
// processor that the data has been stored in flash using the PROGMEM directive.
|
||||
// There is no way for the hd44780 library to know or detect if PROGMEM has
|
||||
// been used.
|
||||
// So if the const qualifer is used but the PROGMEM directive is not used on
|
||||
// an AVR processor, the custom char will be garbage.
|
||||
//
|
||||
// Examples:
|
||||
// For all processors other than AVR:
|
||||
// const char bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const uint8_ bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
//
|
||||
// For AVR: (and non AVR cores that have AVR PROGMEM emulation)
|
||||
// const char bell[8] PROGMEM = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const uint8_t bell[8] PROGMEM = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// OR
|
||||
// const PROGMEM char bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const PROGMEM uint8_t bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// NOTE:
|
||||
// if PROGMEM is used on older AVR compilers it generates a warning.
|
||||
//
|
||||
|
||||
uint8_t bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
uint8_t note[8] = {0x02,0x03,0x02,0x0e,0x1e,0x0c,0x00,0x00};
|
||||
uint8_t clockface[8] = {0x00,0x0e,0x15,0x17,0x11,0x0e,0x00,0x00};
|
||||
uint8_t heart[8] = {0x00,0x0a,0x1f,0x1f,0x0e,0x04,0x00,0x00};
|
||||
uint8_t duck[8] = {0x00,0x0c,0x1d,0x0f,0x0f,0x06,0x00,0x00};
|
||||
uint8_t check[8] = {0x00,0x01,0x03,0x16,0x1c,0x08,0x00,0x00};
|
||||
uint8_t cross[8] = {0x00,0x1b,0x0e,0x04,0x0e,0x1b,0x00,0x00};
|
||||
uint8_t smile[8] = {0x00,0x0a,0x0a,0x00,0x00,0x11,0x0e,0x00};
|
||||
|
||||
uint8_t degreeSymbol[8]= {0x06,0x09,0x09,0x06,0x00,0x00,0x00,0x00};
|
||||
uint8_t degreeC[8] = {0x18,0x18,0x03,0x04,0x04,0x04,0x03,0x00};
|
||||
uint8_t degreeF[8] = {0x18,0x18,0x07,0x04,0x07,0x04,0x04,0x00};
|
||||
|
||||
const PROGMEM uint8_t vsigbar[][8] = {
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0 bars, same as <space>
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x1F}, // 1 bars
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x1F,0x1F}, // 2 bars
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F}, // 3 bars
|
||||
{0x00, 0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F}, // 4 bars
|
||||
{0x00, 0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x1F}, // 5 bars
|
||||
{0x00, 0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 6 bars
|
||||
{0x00, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 7 bars
|
||||
{0x1F, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 8 bars
|
||||
};
|
||||
|
||||
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
|
||||
{
|
||||
// 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
|
||||
}
|
||||
void loop(void)
|
||||
{
|
||||
lcd.clear();
|
||||
|
||||
lcd.print("Custom Chars");
|
||||
|
||||
// create custom characters
|
||||
// int rval = createChar(charval, charmap[]);
|
||||
//
|
||||
// createChar() creates a custom character
|
||||
// for the character at the charval codepoint.
|
||||
// It returns zero if successful.
|
||||
//
|
||||
// to display the custom character, simply call write()
|
||||
// with the charval use in createChar()
|
||||
//
|
||||
// The display must be initialized *before* you attempt
|
||||
// to create custom characters.
|
||||
//
|
||||
// Note: On hd44780 displays there are 8 custom characters.
|
||||
// They are assigned to character codepoint values 0x00 to 0x07
|
||||
// The codepoints 0x08 to 0x0f are duplicates for 0x00 to 0x07
|
||||
// i.e. 0x08 is the same as 0x00, 0x09 same as 0x01, etc...
|
||||
|
||||
// create 8 custom characters
|
||||
lcd.createChar(0, bell);
|
||||
lcd.createChar(1, note);
|
||||
lcd.createChar(2, clockface);
|
||||
lcd.createChar(3, heart);
|
||||
lcd.createChar(4, duck);
|
||||
lcd.createChar(5, check);
|
||||
lcd.createChar(6, cross);
|
||||
lcd.createChar(7, smile);
|
||||
|
||||
// prepare to display the custom characters
|
||||
// on multi line displays the custom characters will be
|
||||
// displayed on the 2nd line
|
||||
// on single line displays, delay a bit to see the initial display,
|
||||
// then clear the display to display the custom characters on the top line
|
||||
if(LCD_ROWS < 2)
|
||||
{
|
||||
customcharRow = 0;
|
||||
delay(LongDelay);
|
||||
lcd.clear();
|
||||
}
|
||||
|
||||
lcd.setCursor(0, customcharRow);
|
||||
|
||||
// write() or print() can be used to display custom characters.
|
||||
//
|
||||
// To use write() pass the charval of the desired custom character.
|
||||
// lcd.write(charval);
|
||||
// NOTE:
|
||||
// The Print class has an issue that does not allow 0 (zero) to be used
|
||||
// on write() without casting it. The Arduino team refuses to fix this.
|
||||
// hd44780 has a work around in it to remove this issue so you can call
|
||||
// write() with a constant value of 0 without having to cast it.
|
||||
//
|
||||
// write() can also be used with literal characters that contain
|
||||
// an octal (base 8) escape seuence.
|
||||
// lcd.write('\###');
|
||||
//
|
||||
// To use print() pass in the charval of the desired custom character
|
||||
// as a character *not* an integer.
|
||||
// This requires using a literal character with an octal escape sequence.
|
||||
// lcd.print('\###');
|
||||
//
|
||||
|
||||
// Since both write() & print() both accept octal escaped literal characters
|
||||
// it is the most compatible & portable way of sending custom characters
|
||||
|
||||
// display all 8 custom characters.
|
||||
|
||||
// write() with character codepoint values
|
||||
lcd.write(0); // casting to an uint8_t or byte not needed with hd44780
|
||||
lcd.write(1);
|
||||
|
||||
// write() & print() with octal escaped literal characters
|
||||
lcd.write('\002'); // this is an octal escaped literal character
|
||||
lcd.write('\003'); // this is an octal escaped literal character
|
||||
lcd.print('\004'); // this is an octal escaped literal character
|
||||
lcd.print('\005'); // this is an octal escaped literal character
|
||||
|
||||
// can also drop the leading zeros on small litereal values like these
|
||||
lcd.print('\06'); // this is an octal escaped literal character
|
||||
lcd.print('\7'); // this is an octal escaped literal character
|
||||
|
||||
delay(LongDelay);
|
||||
|
||||
// You can also insert custom character codepoints into C strings.
|
||||
// To do so, insert the character codepoint value as an octal constant.
|
||||
// However,
|
||||
// because zero indicates the end of string in C you cannot use zero.
|
||||
// Example:
|
||||
// lcd.print("charval #1: \001"); // prints custom character at codepoint 1
|
||||
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code1: \001");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code2: \002");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code3: \003");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code4: \004");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code5: \005");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code6: \006");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code7: \007");
|
||||
delay(ShortDelay);
|
||||
|
||||
// Another nifty trick is that you can modify custom characters on the
|
||||
// display without having to re-write the characters on the display.
|
||||
// To do this, simply create a new character for a codepoint.
|
||||
// All characters on the display which have that codepoint will "magically"
|
||||
// change to the new custom character.
|
||||
// So for example, if the entire display was written with custom character
|
||||
// zero and character zero was a bell, if you called createChar() to
|
||||
// redefine character codepoint zero to be a duck,
|
||||
// the entire display would turn to ducks without having to send any
|
||||
// characters to the display.
|
||||
|
||||
// create the initial custom character
|
||||
lcd.createChar(0, bell);
|
||||
|
||||
// fill the custom character line with the custom character.
|
||||
lcd.setCursor(0,customcharRow);
|
||||
for(uint8_t col=0; col<LCD_COLS; col++)
|
||||
lcd.write(0);
|
||||
|
||||
delay(ShortDelay);
|
||||
|
||||
// change the single custom character previously written on the row
|
||||
// and all the characters on the row will change
|
||||
// without having to re-write the characters.
|
||||
lcd.createChar(0, note);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, clockface);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, heart);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, duck);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, check);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, cross);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, smile);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeSymbol);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeC);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeF);
|
||||
delay(ShortDelay);
|
||||
|
||||
// show multiple vertical bars rising
|
||||
// by changing the single custom character that is already written
|
||||
// to the entire row on the display
|
||||
for(int i = 0; i < 9; i++)
|
||||
{
|
||||
lcd.createChar(0, vsigbar[i]);
|
||||
delay(ShortDelay);
|
||||
}
|
||||
|
||||
delay(LongDelay);
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LineWrap - simple demonstration of automatic linewrap functionality
|
||||
// Created by Bill Perry 2017-05-10
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for the Nortake CU165ECBP-T2J display
|
||||
//
|
||||
// Sketch demonstrates hd44780 library automatic line wrapping functionality.
|
||||
//
|
||||
// (Configure LCD_COLS & LCD_ROWS if desired/needed)
|
||||
// Expected behavior of the sketch:
|
||||
// - display a banner announcing the test.
|
||||
// - print the configured LCD geometry
|
||||
// - print a long text string to demostrate automatic line wrapping
|
||||
// - print lots of characters (slowly) to show how the full wrapping works.
|
||||
// (loop)
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED with the initalization error
|
||||
// code.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Datasheet can be found here:
|
||||
// http://www.blog.zapro.dk/wp-content/CU165.pdf
|
||||
// Full datasheet/release notes:
|
||||
// http://www.blog.zapro.dk/wp-content/CU165ECPB_T2J_specification.pdf
|
||||
//
|
||||
// The device uses SPI for communication.
|
||||
// Pinout:
|
||||
// 1 Vcc
|
||||
// 2 GND
|
||||
// 3 /CS (SS) - Digital Pin 10 on Uno
|
||||
// 4 CLK (SCK) - Digital Pin 13 on Uno
|
||||
// 5 DATA (MOSI) - Digital Pin 11 on Uno
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// include the needed headers
|
||||
#include <SPI.h> // optional, include to use h/w spi
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_NTCU165ECPB.h> // include io class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// will not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCU165ECPB lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 1;
|
||||
|
||||
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>
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// begin() failed so blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// turn on automatic line wrapping
|
||||
// which automatically wraps lines to the next lower line and wraps back
|
||||
// to the top when at the bottom line
|
||||
// NOTE:
|
||||
// noLineWrap() can be used to disable automatic line wrapping.
|
||||
// _write() can be called instead of write() to send data bytes
|
||||
// to the display bypassing any special character or line wrap processing.
|
||||
lcd.lineWrap();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("WrapTest");
|
||||
delay(2000);
|
||||
lcd.clear();
|
||||
|
||||
//print the configured LCD geometry
|
||||
lcd.print(LCD_COLS);
|
||||
lcd.print("x");
|
||||
lcd.print(LCD_ROWS);
|
||||
delay(3000);
|
||||
lcd.clear();
|
||||
|
||||
// print a long text string
|
||||
// without line wrapping enabled, the text would not wrap properly
|
||||
// to the next line.
|
||||
|
||||
if(LCD_COLS == 8)
|
||||
lcd.print("A long text line");
|
||||
else
|
||||
lcd.print("This is a very long line of text");
|
||||
delay(3000);
|
||||
|
||||
lcd.clear();
|
||||
|
||||
// now print 2 full displays worth of characters to show
|
||||
// the full wrapping.
|
||||
|
||||
lcd.cursor(); // turn on cursor so you can see where it is.
|
||||
|
||||
char c = '0'; // start at the character for the number zero
|
||||
for(int i = 2*LCD_COLS*LCD_ROWS; i; i--)
|
||||
{
|
||||
lcd.print(c++);
|
||||
delay(200); // slow things down to watch the printing & wrapping
|
||||
|
||||
if(c > 0x7e) // wrap back to beginning of printable ASCII chars
|
||||
c = '!';
|
||||
}
|
||||
delay(3000);
|
||||
lcd.noCursor(); // turn off cursor
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
hd44780_NTCU165ECPB examples
|
||||
=======================
|
||||
|
||||
The examples included in this directory are for the hd44780_NTCU165ECPB i/o class.<br>
|
||||
The hd44780_NTCU165ECPB i/o class is used to control a Noritake CU165ECBP-T2J LCD display over SPI
|
||||
|
||||
|
||||
#### The following examples are included:
|
||||
|
||||
- `HelloWorld`<br>
|
||||
Prints "Hello, World!" on the lcd
|
||||
|
||||
- `LCDCustomChars`<br>
|
||||
Demonstrates using custom characters
|
||||
|
||||
- `LineWrap`<br>
|
||||
Demonstrates automatic linewrap functionality
|
||||
|
||||
- `Serial2LCD`<br>
|
||||
Displays a message read from the serial port on the lcd.
|
||||
|
||||
- `UpTime`<br>
|
||||
Prints the amount of time since the Arduino has been reset.
|
||||
|
||||
- `hd44780examples`<br>
|
||||
The hd44780examples subdirectory contains
|
||||
hd44780_NTCU165ECPB class specific wrapper sketches for sketches under
|
||||
examples/hd44780examples.
|
||||
@@ -0,0 +1,157 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// Serial2LCD - simple demonstration printing characters from serial port
|
||||
// Created by Bill Perry 2020-06-28
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for the Nortake CU165ECBP-T2J display
|
||||
//
|
||||
// Sketch demonstrates hd44780 how to read a message of characters from
|
||||
// serial port and display it on the LCD.
|
||||
// It takes advantage of the hd44780 library automatic line
|
||||
// wrapping capability.
|
||||
// See the LineWrap sketch for details about line wrapping.
|
||||
//
|
||||
//
|
||||
// Configure BAUDRATE if desired/needed
|
||||
// Expected behavior of the sketch:
|
||||
// - characters received from serial port are displayed on LCD
|
||||
// - CR and LF are ignored/dropped
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED with the initalization error
|
||||
// code.
|
||||
//
|
||||
// NOTE:
|
||||
// If the sketch fails to produce the expected results, or blinks the LED,
|
||||
// run the included I2CexpDiag sketch to test the i2c signals and the LCD.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Datasheet can be found here:
|
||||
// http://www.blog.zapro.dk/wp-content/CU165.pdf
|
||||
// Full datasheet/release notes:
|
||||
// http://www.blog.zapro.dk/wp-content/CU165ECPB_T2J_specification.pdf
|
||||
//
|
||||
// The device uses SPI for communication.
|
||||
// Pinout:
|
||||
// 1 Vcc
|
||||
// 2 GND
|
||||
// 3 /CS (SS) - Digital Pin 10 on Uno
|
||||
// 4 CLK (SCK) - Digital Pin 13 on Uno
|
||||
// 5 DATA (MOSI) - Digital Pin 11 on Uno
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// include the needed headers
|
||||
#include <SPI.h> // optional, include to use h/w spi
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_NTCU165ECPB.h> // include io class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// will not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCU165ECPB lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
// LCD geometry
|
||||
// while 16x2 will work on most displays even if the geometry is different,
|
||||
// for actual wrap testing of a particular LCD it is best to use the correct
|
||||
// geometry.
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 1;
|
||||
|
||||
const int BAUDRATE = 9600;
|
||||
|
||||
void setup()
|
||||
{
|
||||
int status;
|
||||
|
||||
// initalize Serial port
|
||||
Serial.begin(BAUDRATE);
|
||||
|
||||
// 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>
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// begin() failed
|
||||
|
||||
Serial.print("LCD initalization failed: ");
|
||||
Serial.println(status);
|
||||
|
||||
// blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// turn on automatic line wrapping
|
||||
// which automatically wraps lines to the next lower line and wraps back
|
||||
// to the top when at the bottom line
|
||||
// NOTE:
|
||||
// noLineWrap() can be used to disable automatic line wrapping.
|
||||
// _write() can be called instead of write() to send data bytes
|
||||
// to the display bypassing any special character or line wrap processing.
|
||||
lcd.lineWrap();
|
||||
|
||||
lcd.print("Serial2LCD");
|
||||
if(LCD_ROWS > 1)
|
||||
{
|
||||
lcd.setCursor(0,1);
|
||||
lcd.print("Baud:");
|
||||
lcd.print(BAUDRATE);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
// check to see if characters available
|
||||
// indicating a message is coming in
|
||||
if (Serial.available())
|
||||
{
|
||||
// wait some time for rest of message to arrive
|
||||
delay(100);
|
||||
|
||||
// Clear the display before showing the new message
|
||||
lcd.clear();
|
||||
|
||||
// print the message on the LCD
|
||||
while (Serial.available() > 0)
|
||||
{
|
||||
char c;
|
||||
c = Serial.read();
|
||||
if(c != '\r' && c != '\n') // drop CR and LF characters
|
||||
lcd.write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// UpTime - simple demonstration of lcd
|
||||
// Created by Bill Perry 2017-05-11
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for the Nortake CU165ECBP-T2J display
|
||||
//
|
||||
// Sketch will print "UpTime" on the lcd,
|
||||
// wait a few seconds, and then print the amount of time since
|
||||
// the Arduino has been reset.
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED.
|
||||
//
|
||||
// Datasheet can be found here:
|
||||
// http://www.blog.zapro.dk/wp-content/CU165.pdf
|
||||
// Full datasheet/release notes:
|
||||
// http://www.blog.zapro.dk/wp-content/CU165ECPB_T2J_specification.pdf
|
||||
//
|
||||
// The device uses SPI for communication.
|
||||
// Pinout:
|
||||
// 1 Vcc
|
||||
// 2 GND
|
||||
// 3 /CS (SS) - Digital Pin 10 on Uno
|
||||
// 4 CLK (SCK) - Digital Pin 13 on Uno
|
||||
// 5 DATA (MOSI) - Digital Pin 11 on Uno
|
||||
//
|
||||
|
||||
#include <SPI.h> // optional, include to use h/w spi
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_NTCU165ECPB.h> // include io class header
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// will not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCU165ECPB lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 1;
|
||||
|
||||
void setup()
|
||||
{
|
||||
int status;
|
||||
|
||||
// Special Note:
|
||||
// =============
|
||||
// Since this device uses a write only SPI interface, there is no way for
|
||||
// the library/sketch to know if the device is present or if there is any
|
||||
// type of issue communicating with the device.
|
||||
//
|
||||
|
||||
// initialize LCD with number of columns and rows:
|
||||
lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
|
||||
// Print banner message to the LCD
|
||||
lcd.print("UpTime:");
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static unsigned long lastsecs = -1; // pre-initialize with non zero value
|
||||
unsigned long secs;
|
||||
int status;
|
||||
|
||||
secs = millis() / 1000;
|
||||
|
||||
// see if 1 second has passed
|
||||
// so the display is only updated once per second
|
||||
if(secs != lastsecs)
|
||||
{
|
||||
lastsecs = secs; // keep track of last seconds
|
||||
|
||||
// set the cursor position to column 8, row 0
|
||||
// note: row 0 is the top line
|
||||
// since row counting begins with 0
|
||||
status = lcd.setCursor(8, 0);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// setCursor() failed so call fatalError() with the error code.
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// print uptime on lcd device: (time since last reset)
|
||||
PrintUpTime(lcd, secs);
|
||||
}
|
||||
}
|
||||
|
||||
// PrintUpTime(outdev, secs) - print uptime in HH:MM:SS format
|
||||
// outdev - the device to send output
|
||||
// secs - the total number of seconds uptime
|
||||
//
|
||||
// This is a fancy output routine.
|
||||
// outdev is a Print class object which indicates
|
||||
// where the output should be sent.
|
||||
// PrintUpTime can be used with any object that uses the Print class.
|
||||
// This code works with Serial objects, as well as the the hd44780 lcd objects.
|
||||
// i.e. you can call with Serial: PrintUpTime(Serial, seconds);
|
||||
|
||||
void PrintUpTime(Print &outdev, unsigned long secs)
|
||||
{
|
||||
unsigned int hr, mins, sec;
|
||||
|
||||
// convert total seconds to hours, mins, seconds
|
||||
mins = secs / 60; // how many total minutes
|
||||
hr = mins / 60; // how many total hours
|
||||
mins = mins % 60; // how many minutes within the hour
|
||||
sec = secs % 60; // how many seconds within the minute
|
||||
|
||||
// print uptime in HH:MM:SS format
|
||||
|
||||
if(hr > 99)
|
||||
hr %= 100; // limit hr to 0-99
|
||||
|
||||
// Print class does not support fixed width formatting
|
||||
// so insert a zero if number smaller than 10
|
||||
|
||||
if(hr < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)hr);
|
||||
outdev.write(':');
|
||||
if(mins < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)mins);
|
||||
outdev.write(':');
|
||||
if(sec < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)sec);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDcharset - Display LCD character set for hd44780 hd44780_NTCU165ECPB i/o class
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example LCDcharset.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or example
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in hd44780 examples:
|
||||
// hd44780/examples/hd44780examples/LCDcharset/LCDcharset.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDcharset
|
||||
//
|
||||
|
||||
#include <SPI.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_NTCU165ECPB.h>
|
||||
|
||||
// define the LCD geometry
|
||||
#define LCD_COLS 16
|
||||
#define LCD_ROWS 1
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// will not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCU165ECPB lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library LCDcharset sketch source code
|
||||
#include <examples/hd44780examples/LCDcharset/LCDcharset.ino>
|
||||
@@ -0,0 +1,58 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDiSpeed - LCD Interface Speed test for hd44780_NTCU165ECPB i/o class
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o sub library.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDiSpeed
|
||||
//
|
||||
|
||||
#include <SPI.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_NTCU165ECPB.h>
|
||||
|
||||
#define LCD_ROWS 1
|
||||
#define LCD_COLS 16
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// will not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCU165ECPB lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino>
|
||||
@@ -0,0 +1,58 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDLibTest - LCD library test sketch for hd44780_NTCU165ECPB i/o class
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o sub library.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/LCDlibTest/LCDlibTest.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDlibTest
|
||||
//
|
||||
|
||||
#include <SPI.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_NTCU165ECPB.h>
|
||||
|
||||
#define LCD_ROWS 1
|
||||
#define LCD_COLS 16
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// will not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCU165ECPB lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/LCDlibTest/LCDlibTest.ino>
|
||||
@@ -0,0 +1,82 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// HelloWorld - simple demonstration of lcd
|
||||
// Created by Bill Perry 2019-11-23
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for Noritake CU-U series displays like the
|
||||
// Noritake CU20025ECPB-U1J or CU20025ECPB-W1J
|
||||
// The Noritake CU20025ECPB display is a 20x2 line VFD display.
|
||||
// It is not a hd44780 display but is nearly fully compatible with a hd44780
|
||||
// display. The only real difference is the backlight control.
|
||||
// So while this device is supported by the hd44780 library,
|
||||
// the subclass will do its best to emulatate hd44780 functions and map
|
||||
// them to equivalent functionality when possible.
|
||||
//
|
||||
// Sketch prints "Hello, World!" on the lcd
|
||||
//
|
||||
// See below for configuring the Arduino pins used.
|
||||
//
|
||||
// Noritake CU-U series LCD module pins
|
||||
// 1 - LCD gnd
|
||||
// 2 - VCC (5v)
|
||||
// 3 - not connected
|
||||
// 4 - RS Register Select (rs) --- connect to Arduino pin
|
||||
// 5 - Read/Write ------ connect to gnd
|
||||
// 6 - Enable (en) ----- connect to Arduino pin
|
||||
// 7 - Data 0 (db0) ----
|
||||
// 8 - Data 1 (db1) |-------- Not used in 4 bit mode
|
||||
// 9 - Data 2 (db2) |
|
||||
// 10 - Data 3 (db3) ----
|
||||
// 11 - Data 4 (db4) ---- connect to Arduino pin
|
||||
// 12 - Data 5 (db5) ---- connect to Arduino pin
|
||||
// 13 - Data 6 (db6) ---- connect to Arduino pin
|
||||
// 14 - Data 7 (db7) ---- connect to Arduino pin
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// LiquidCrystal compability:
|
||||
// Since hd44780 is LiquidCrystal API compatible, most existing LiquidCrystal
|
||||
// sketches should work with hd44780 hd44780_NTCU20025ECPB_pinIO i/o class
|
||||
// once the includes are changed to use hd44780 and the lcd object constructor
|
||||
// is changed to use the hd44780_NTCU20025ECPB_pinIO class.
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_NTCU20025ECPB_pinIO.h> // Arduino pin i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
// The parameters used by hd44780_NTCU20025ECPB_pinIO are the same as those
|
||||
// used by the IDE bundled LiquidCrystal library
|
||||
// note that ESP8266 based arduinos must use the Dn defines rather than
|
||||
// raw pin numbers.
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // for esp8266 devices
|
||||
#else
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // for all other devices
|
||||
#endif
|
||||
hd44780_NTCU20025ECPB_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 20;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// initialize LCD with number of columns and rows:
|
||||
//
|
||||
// note:
|
||||
// begin() will automatically turn on the backlight if backlight
|
||||
// control is specified in the lcd object constructor
|
||||
//
|
||||
lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
|
||||
// if backlight control was specified, the backlight should be on now
|
||||
|
||||
// Print a message to the LCD
|
||||
lcd.print("Hello, World!");
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
@@ -0,0 +1,353 @@
|
||||
static const int dummyvar = 0; // dummy declaration for older broken IDEs!!!!
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDCustomChars - simple demonstration of lcd custom characters
|
||||
// Created by Bill Perry 2019-11-23
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for Noritake CU-U series displays like the
|
||||
// Noritake CU20025ECPB-U1J or CU20025ECPB-W1J
|
||||
// The Noritake CU20025ECPB display is a 20x2 line VFD display.
|
||||
// It is not a hd44780 display but is nearly fully compatible with a hd44780
|
||||
// display. The only real difference is the backlight control.
|
||||
// So while this device is supported by the hd44780 library,
|
||||
// the subclass will do its best to emulatate hd44780 functions and map
|
||||
// them to equivalent functionality when possible.
|
||||
//
|
||||
// Sketch demonstrates how to assign custom characters to the eight hd44780
|
||||
// custom character codepoints and how to display on the LCD using
|
||||
// write() and print()
|
||||
//
|
||||
// You can create your own custom characters.
|
||||
// Here are a couple of web pages that have a tool that will generate the data
|
||||
// values needed for custom character.
|
||||
// https://kakedev.github.io/GlyphGenerator/
|
||||
// http://www.quinapalus.com/hd44780udg.html
|
||||
// https://omerk.github.io/lcdchargen
|
||||
//
|
||||
// See below for configuring the Arduino pins used.
|
||||
//
|
||||
// Noritake CU-U series LCD module pins
|
||||
// 1 - LCD gnd
|
||||
// 2 - VCC (5v)
|
||||
// 3 - not connected
|
||||
// 4 - RS Register Select (rs) --- connect to Arduino pin
|
||||
// 5 - Read/Write ------ connect to gnd
|
||||
// 6 - Enable (en) ----- connect to Arduino pin
|
||||
// 7 - Data 0 (db0) ----
|
||||
// 8 - Data 1 (db1) |-------- Not used in 4 bit mode
|
||||
// 9 - Data 2 (db2) |
|
||||
// 10 - Data 3 (db3) ----
|
||||
// 11 - Data 4 (db4) ---- connect to Arduino pin
|
||||
// 12 - Data 5 (db5) ---- connect to Arduino pin
|
||||
// 13 - Data 6 (db6) ---- connect to Arduino pin
|
||||
// 14 - Data 7 (db7) ---- connect to Arduino pin
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// LiquidCrystal compability:
|
||||
// Since hd44780 is LiquidCrystal API compatible, most existing LiquidCrystal
|
||||
// sketches should work with NTCU20025ECPB_pinIO i/o class once the
|
||||
// includes are changed to use hd44780 and the lcd object constructor is
|
||||
// changed to use the NTCU20025ECPB_pinIO class.
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_NTCU20025ECPB_pinIO.h> // Arduino pin i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
// The parameters used by hd44780_NTCU20025ECPB_pinIO are the same as those
|
||||
// used by the IDE bundled LiquidCrystal library
|
||||
// note that ESP8266 based arduinos must use the Dn defines rather than
|
||||
// raw pin numbers.
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // for esp8266 devices
|
||||
#else
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // for all other devices
|
||||
#endif
|
||||
hd44780_NTCU20025ECPB_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 20;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
const int LongDelay = 5000;
|
||||
const int ShortDelay = 800;
|
||||
|
||||
int customcharRow = 1; // default to printing custom chars on row 1
|
||||
|
||||
// Below are some custom characters for demonstration
|
||||
|
||||
// You can ensure that the data for these custom characters is only
|
||||
// in flash and not in RAM by using the const qualifier.
|
||||
// However....
|
||||
// If using the AVR part, the AVR proprietary PROGMEM directive must be used.
|
||||
// PROGMEM is only required on AVR parts since the AVR parts cannot directly
|
||||
// access const data stored in flash like all the other processors.
|
||||
// PROGMEM is an AVR specific proprietary kludge that tells the linker and
|
||||
// startup code to handle the data differently.
|
||||
// PROGMEM is only used by the AVR and not required by any other processor.
|
||||
//
|
||||
// Most non AVR cores provide AVR compatibilty by providing support (emulation)
|
||||
// for the AVR proprietary PROGMEM directive and corresponding access functions,
|
||||
// but some do not.
|
||||
//
|
||||
// Because of this AVR const data and PROGMEM issue, there is no way to
|
||||
// guarantee code portability across all cores when using const data.
|
||||
//
|
||||
//
|
||||
// the hd44780 library assumes that if a const qualifier is used on the AVR
|
||||
// processor that the data has been stored in flash using the PROGMEM directive.
|
||||
// There is no way for the hd44780 library to know or detect if PROGMEM has
|
||||
// been used.
|
||||
// So if the const qualifer is used but the PROGMEM directive is not used on
|
||||
// an AVR processor, the custom char will be garbage.
|
||||
//
|
||||
// Examples:
|
||||
// For all processors other than AVR:
|
||||
// const char bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const uint8_ bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
//
|
||||
// For AVR: (and non AVR cores that have AVR PROGMEM emulation)
|
||||
// const char bell[8] PROGMEM = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const uint8_t bell[8] PROGMEM = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// OR
|
||||
// const PROGMEM char bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const PROGMEM uint8_t bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// NOTE:
|
||||
// if PROGMEM is used on older AVR compilers it generates a warning.
|
||||
//
|
||||
|
||||
uint8_t bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
uint8_t note[8] = {0x02,0x03,0x02,0x0e,0x1e,0x0c,0x00,0x00};
|
||||
uint8_t clockface[8] = {0x00,0x0e,0x15,0x17,0x11,0x0e,0x00,0x00};
|
||||
uint8_t heart[8] = {0x00,0x0a,0x1f,0x1f,0x0e,0x04,0x00,0x00};
|
||||
uint8_t duck[8] = {0x00,0x0c,0x1d,0x0f,0x0f,0x06,0x00,0x00};
|
||||
uint8_t check[8] = {0x00,0x01,0x03,0x16,0x1c,0x08,0x00,0x00};
|
||||
uint8_t cross[8] = {0x00,0x1b,0x0e,0x04,0x0e,0x1b,0x00,0x00};
|
||||
uint8_t smile[8] = {0x00,0x0a,0x0a,0x00,0x00,0x11,0x0e,0x00};
|
||||
|
||||
uint8_t degreeSymbol[8]= {0x06,0x09,0x09,0x06,0x00,0x00,0x00,0x00};
|
||||
uint8_t degreeC[8] = {0x18,0x18,0x03,0x04,0x04,0x04,0x03,0x00};
|
||||
uint8_t degreeF[8] = {0x18,0x18,0x07,0x04,0x07,0x04,0x04,0x00};
|
||||
|
||||
const PROGMEM uint8_t vsigbar[][8] = {
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0 bars, same as <space>
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x1F}, // 1 bars
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x1F,0x1F}, // 2 bars
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F}, // 3 bars
|
||||
{0x00, 0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F}, // 4 bars
|
||||
{0x00, 0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x1F}, // 5 bars
|
||||
{0x00, 0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 6 bars
|
||||
{0x00, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 7 bars
|
||||
{0x1F, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 8 bars
|
||||
};
|
||||
|
||||
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
|
||||
{
|
||||
// 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
|
||||
}
|
||||
void loop(void)
|
||||
{
|
||||
lcd.clear();
|
||||
|
||||
lcd.print("Custom Chars");
|
||||
|
||||
// create custom characters
|
||||
// int rval = createChar(charval, charmap[]);
|
||||
//
|
||||
// createChar() creates a custom character
|
||||
// for the character at the charval codepoint.
|
||||
// It returns zero if successful.
|
||||
//
|
||||
// to display the custom character, simply call write()
|
||||
// with the charval use in createChar()
|
||||
//
|
||||
// The display must be initialized *before* you attempt
|
||||
// to create custom characters.
|
||||
//
|
||||
// Note: On hd44780 displays there are 8 custom characters.
|
||||
// They are assigned to character codepoint values 0x00 to 0x07
|
||||
// The codepoints 0x08 to 0x0f are duplicates for 0x00 to 0x07
|
||||
// i.e. 0x08 is the same as 0x00, 0x09 same as 0x01, etc...
|
||||
|
||||
// create 8 custom characters
|
||||
lcd.createChar(0, bell);
|
||||
lcd.createChar(1, note);
|
||||
lcd.createChar(2, clockface);
|
||||
lcd.createChar(3, heart);
|
||||
lcd.createChar(4, duck);
|
||||
lcd.createChar(5, check);
|
||||
lcd.createChar(6, cross);
|
||||
lcd.createChar(7, smile);
|
||||
|
||||
// prepare to display the custom characters
|
||||
// on multi line displays the custom characters will be
|
||||
// displayed on the 2nd line
|
||||
// on single line displays, delay a bit to see the initial display,
|
||||
// then clear the display to display the custom characters on the top line
|
||||
if(LCD_ROWS < 2)
|
||||
{
|
||||
customcharRow = 0;
|
||||
delay(LongDelay);
|
||||
lcd.clear();
|
||||
}
|
||||
|
||||
lcd.setCursor(0, customcharRow);
|
||||
|
||||
// write() or print() can be used to display custom characters.
|
||||
//
|
||||
// To use write() pass the charval of the desired custom character.
|
||||
// lcd.write(charval);
|
||||
// NOTE:
|
||||
// The Print class has an issue that does not allow 0 (zero) to be used
|
||||
// on write() without casting it. The Arduino team refuses to fix this.
|
||||
// hd44780 has a work around in it to remove this issue so you can call
|
||||
// write() with a constant value of 0 without having to cast it.
|
||||
//
|
||||
// write() can also be used with literal characters that contain
|
||||
// an octal (base 8) escape seuence.
|
||||
// lcd.write('\###');
|
||||
//
|
||||
// To use print() pass in the charval of the desired custom character
|
||||
// as a character *not* an integer.
|
||||
// This requires using a literal character with an octal escape sequence.
|
||||
// lcd.print('\###');
|
||||
//
|
||||
|
||||
// Since both write() & print() both accept octal escaped literal characters
|
||||
// it is the most compatible & portable way of sending custom characters
|
||||
|
||||
// display all 8 custom characters.
|
||||
|
||||
// write() with character codepoint values
|
||||
lcd.write(0); // casting to an uint8_t or byte not needed with hd44780
|
||||
lcd.write(1);
|
||||
|
||||
// write() & print() with octal escaped literal characters
|
||||
lcd.write('\002'); // this is an octal escaped literal character
|
||||
lcd.write('\003'); // this is an octal escaped literal character
|
||||
lcd.print('\004'); // this is an octal escaped literal character
|
||||
lcd.print('\005'); // this is an octal escaped literal character
|
||||
|
||||
// can also drop the leading zeros on small litereal values like these
|
||||
lcd.print('\06'); // this is an octal escaped literal character
|
||||
lcd.print('\7'); // this is an octal escaped literal character
|
||||
|
||||
delay(LongDelay);
|
||||
|
||||
// You can also insert custom character codepoints into C strings.
|
||||
// To do so, insert the character codepoint value as an octal constant.
|
||||
// However,
|
||||
// because zero indicates the end of string in C you cannot use zero.
|
||||
// Example:
|
||||
// lcd.print("charval #1: \001"); // prints custom character at codepoint 1
|
||||
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code1: \001");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code2: \002");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code3: \003");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code4: \004");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code5: \005");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code6: \006");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code7: \007");
|
||||
delay(ShortDelay);
|
||||
|
||||
// Another nifty trick is that you can modify custom characters on the
|
||||
// display without having to re-write the characters on the display.
|
||||
// To do this, simply create a new character for a codepoint.
|
||||
// All characters on the display which have that codepoint will "magically"
|
||||
// change to the new custom character.
|
||||
// So for example, if the entire display was written with custom character
|
||||
// zero and character zero was a bell, if you called createChar() to
|
||||
// redefine character codepoint zero to be a duck,
|
||||
// the entire display would turn to ducks without having to send any
|
||||
// characters to the display.
|
||||
|
||||
// create the initial custom character
|
||||
lcd.createChar(0, bell);
|
||||
|
||||
// fill the custom character line with the custom character.
|
||||
lcd.setCursor(0,customcharRow);
|
||||
for(uint8_t col=0; col<LCD_COLS; col++)
|
||||
lcd.write(0);
|
||||
|
||||
delay(ShortDelay);
|
||||
|
||||
// change the single custom character previously written on the row
|
||||
// and all the characters on the row will change
|
||||
// without having to re-write the characters.
|
||||
lcd.createChar(0, note);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, clockface);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, heart);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, duck);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, check);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, cross);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, smile);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeSymbol);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeC);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeF);
|
||||
delay(ShortDelay);
|
||||
|
||||
// show multiple vertical bars rising
|
||||
// by changing the single custom character that is already written
|
||||
// to the entire row on the display
|
||||
for(int i = 0; i < 9; i++)
|
||||
{
|
||||
lcd.createChar(0, vsigbar[i]);
|
||||
delay(ShortDelay);
|
||||
}
|
||||
|
||||
delay(LongDelay);
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LineWrap - simple demonstration of automatic linewrap functionality
|
||||
// Created by Bill Perry 2019-11-23
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for Noritake CU-U series displays like the
|
||||
// Noritake CU20025ECPB-U1J or CU20025ECPB-W1J
|
||||
// The Noritake CU20025ECPB display is a 20x2 line VFD display.
|
||||
// It is not a hd44780 display but is nearly fully compatible with a hd44780
|
||||
// display. The only real difference is the backlight control.
|
||||
// So while this device is supported by the hd44780 library,
|
||||
// the subclass will do its best to emulatate hd44780 functions and map
|
||||
// them to equivalent functionality when possible.
|
||||
//
|
||||
// Sketch demonstrates hd44780 library automatic line wrapping functionality.
|
||||
//
|
||||
// Background:
|
||||
// hd44780 LCDs do not use linear continuous memory for the characters
|
||||
// on the lines on the display.
|
||||
// This means that simply sending continuous characters to the
|
||||
// display will not fill lines and wrap appropriately as might be expected.
|
||||
// The hd44780 library solves this issue by adding a line wrapping capability
|
||||
// in s/w that can be enabled & disabled.
|
||||
// This allows the host to send characters to the display continuously and they
|
||||
// will wrap to the next lower line when the end of the visible line has been
|
||||
// reached. When on the bottom line it will wrap back to the top line.
|
||||
//
|
||||
// (Configure LCD_COLS & LCD_ROWS if desired/needed)
|
||||
// Expected behavior of the sketch:
|
||||
// - display a banner announcing the test.
|
||||
// - print the configured LCD geometry
|
||||
// - print a long text string to demostrate automatic line wrapping
|
||||
// - print lots of characters (slowly) to show how the full wrapping works.
|
||||
// (loop)
|
||||
//
|
||||
// See below for configuring the Arduino pins used.
|
||||
//
|
||||
// Noritake CU-U series LCD module pins
|
||||
// 1 - LCD gnd
|
||||
// 2 - VCC (5v)
|
||||
// 3 - not connected
|
||||
// 4 - RS Register Select (rs) --- connect to Arduino pin
|
||||
// 5 - Read/Write ------ connect to gnd
|
||||
// 6 - Enable (en) ----- connect to Arduino pin
|
||||
// 7 - Data 0 (db0) ----
|
||||
// 8 - Data 1 (db1) |-------- Not used in 4 bit mode
|
||||
// 9 - Data 2 (db2) |
|
||||
// 10 - Data 3 (db3) ----
|
||||
// 11 - Data 4 (db4) ---- connect to Arduino pin
|
||||
// 12 - Data 5 (db5) ---- connect to Arduino pin
|
||||
// 13 - Data 6 (db6) ---- connect to Arduino pin
|
||||
// 14 - Data 7 (db7) ---- connect to Arduino pin
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED with the initalization error
|
||||
// code.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// pinout:
|
||||
// 1 - LCD gnd
|
||||
// 2 - VCC (5v)
|
||||
// 3 - not connected
|
||||
// 4 - RS Register Select (rs)
|
||||
// 5 - Read/Write
|
||||
// 6 - Enable (en)
|
||||
// 7 - Data 0 (db0) ----
|
||||
// 8 - Data 1 (db1) |-------- Not used in 4 bit mode
|
||||
// 9 - Data 2 (db2) |
|
||||
// 10 - Data 3 (db3) ----
|
||||
// 11 - Data 4 (db4)
|
||||
// 12 - Data 5 (db5)
|
||||
// 13 - Data 6 (db6)
|
||||
// 14 - Data 7 (db7)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_NTCU20025ECPB_pinIO.h> // Arduino pin i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // for esp8266 devices
|
||||
#else
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // for all other devices
|
||||
#endif
|
||||
hd44780_NTCU20025ECPB_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 20;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
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>
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// begin() failed so blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// turn on automatic line wrapping
|
||||
// which automatically wraps lines to the next lower line and wraps back
|
||||
// to the top when at the bottom line
|
||||
// NOTE:
|
||||
// noLineWrap() can be used to disable automatic line wrapping.
|
||||
// _write() can be called instead of write() to send data bytes
|
||||
// to the display bypassing any special character or line wrap processing.
|
||||
lcd.lineWrap();
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("WrapTest");
|
||||
delay(2000);
|
||||
lcd.clear();
|
||||
|
||||
//print the configured LCD geometry
|
||||
lcd.print(LCD_COLS);
|
||||
lcd.print("x");
|
||||
lcd.print(LCD_ROWS);
|
||||
delay(3000);
|
||||
lcd.clear();
|
||||
|
||||
// print a long text string
|
||||
// without line wrapping enabled, the text would not wrap properly
|
||||
// to the next line.
|
||||
|
||||
if(LCD_COLS == 8)
|
||||
lcd.print("A long text line");
|
||||
else
|
||||
lcd.print("This is a very long line of text");
|
||||
delay(3000);
|
||||
|
||||
lcd.clear();
|
||||
|
||||
// now print 2 full displays worth of characters to show
|
||||
// the full wrapping.
|
||||
|
||||
lcd.cursor(); // turn on cursor so you can see where it is
|
||||
|
||||
char c = '0'; // start at the character for the number zero
|
||||
for(int i = 2*LCD_COLS*LCD_ROWS; i; i--)
|
||||
{
|
||||
lcd.print(c++);
|
||||
delay(200); // slow things down to watch the printing & wrapping
|
||||
|
||||
if(c > 0x7e) // wrap back to beginning of printable ASCII chars
|
||||
c = '!';
|
||||
}
|
||||
delay(3000);
|
||||
lcd.noCursor(); // turn off cursor
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
hd44780_NTCU20025ECPB_pinIOexamples
|
||||
===================================
|
||||
|
||||
The examples included in this directory are for the hd44780_NTCU20025ECPB_pinIO i/o class.<br>
|
||||
The hd44780_NTCU20025ECPB_pinIO i/o class is used to control Noritake
|
||||
CU-U series displays like the Noritake CU20025ECPB-U1J or CU20025ECPB-W1J
|
||||
The Noritake CU20025ECPB display is a 20x2 line VFD display.
|
||||
It is not a hd44780 display but is nearly fully compatible with a hd44780
|
||||
display. The only real difference is the backlight control.
|
||||
So while this device is supported by the hd44780 library,
|
||||
the subclass will do its best to emulatate hd44780 functions and map
|
||||
them to equivalent functionality when possible.
|
||||
|
||||
#### The following examples are included:
|
||||
|
||||
- `HelloWorld`<br>
|
||||
Prints "Hello, World!" on the lcd
|
||||
|
||||
- `LCDKeypadCheck`<br>
|
||||
Tests lcd keypad shields for bad backlight circuitry
|
||||
|
||||
- `LCDCustomChars`<br>
|
||||
Demonstrates using custom characters
|
||||
|
||||
- `LineWrap`<br>
|
||||
Demonstrates automatic linewrap functionality
|
||||
|
||||
- `ReadWrite`<br>
|
||||
Demonstrate the ability to read data from the LCD.
|
||||
|
||||
- `Serial2LCD`<br>
|
||||
Displays a message read from the serial port on the lcd.
|
||||
|
||||
- `UpTime`<br>
|
||||
Prints the amount of time since the Arduino has been reset.
|
||||
|
||||
- `hd44780examples`<br>
|
||||
The hd44780examples subdirectory contains
|
||||
hd44780_NTCU20025ECPB_pinIOclass specific wrapper sketches for sketches under
|
||||
examples/hd44780examples.
|
||||
@@ -0,0 +1,188 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// ReadWrite - simple demonstration reading data from LCD
|
||||
// Created by Bill Perry 2016-08-19
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for Noritake CU-U series displays like the
|
||||
// Noritake CU20025ECPB-U1J or CU20025ECPB-W1J
|
||||
// The Noritake CU20025ECPB display is a 20x2 line VFD display.
|
||||
// It is not a hd44780 display but is nearly fully compatible with a hd44780
|
||||
// display. The only real difference is the backlight control.
|
||||
// So while this device is supported by the hd44780 library,
|
||||
// the subclass will do its best to emulatate hd44780 functions and map
|
||||
// them to equivalent functionality when possible.
|
||||
//
|
||||
// The purpose of the sketch is demonstrate the ability to read data from
|
||||
// the LCD. As such, it requires an extra Arduino pin to control the R/W LCD
|
||||
// pin. See below for configuring the Arduino pins used.
|
||||
//
|
||||
// Sketch will print the amount of time since the Arduino has been reset
|
||||
// on the top row and then read the data from the LCD to print it on the
|
||||
// second row
|
||||
//
|
||||
// If there are errors and the arduino supports a built in LED,
|
||||
// an error status code will blink on the built in LED.
|
||||
// Error codes:
|
||||
// (1) lcd device initalization failed
|
||||
// (2) lcd device does not support reads
|
||||
// (3) error reading data from lcd device
|
||||
// (4) error writing data to lcd device
|
||||
// (5) read data mismatch
|
||||
//
|
||||
// See below for configuring the Arduino pins used.
|
||||
//
|
||||
// Noritake CU-U series LCD module pins
|
||||
// 1 - LCD gnd
|
||||
// 2 - VCC (5v)
|
||||
// 3 - not connected
|
||||
// 4 - RS Register Select (rs) --- connect to Arduino pin
|
||||
// 5 - Read/Write ------ connect to Arduino pin
|
||||
// 6 - Enable (en) ----- connect to Arduino pin
|
||||
// 7 - Data 0 (db0) ----
|
||||
// 8 - Data 1 (db1) |-------- Not used in 4 bit mode
|
||||
// 9 - Data 2 (db2) |
|
||||
// 10 - Data 3 (db3) ----
|
||||
// 11 - Data 4 (db4) ---- connect to Arduino pin
|
||||
// 12 - Data 5 (db5) ---- connect to Arduino pin
|
||||
// 13 - Data 6 (db6) ---- connect to Arduino pin
|
||||
// 14 - Data 7 (db7) ---- connect to Arduino pin
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_NTCU20025ECPB_pinIO.h> // Arduino pin i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
// The parameters used by hd44780_NTCU20025ECPB_pinIO are the same as those
|
||||
// used by the IDE bundled LiquidCrystal library
|
||||
// note that ESP8266 based arduinos must use the Dn defines rather than
|
||||
// raw pin numbers.
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, rw=A0, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // for esp8266 devices
|
||||
#else
|
||||
const int rs=8, rw=A0, en=9, db4=4, db5=5, db6=6, db7=7; // for all other devices
|
||||
#endif
|
||||
hd44780_NTCU20025ECPB_pinIO lcd(rs, rw, en, db4, db5, db6, db7);
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_ROWS = 2;
|
||||
const int LCD_COLS = 20;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// initialize LCD with number of columns and rows:
|
||||
if( lcd.begin(LCD_COLS, LCD_ROWS))
|
||||
{
|
||||
// begin() failed so blink the onboard LED if possible
|
||||
fatalError(1);
|
||||
}
|
||||
|
||||
// check to see if device can read by attempting to read
|
||||
// the lcd status register. If it fails then assume it was
|
||||
// because the lcd device does not support reads.
|
||||
if(lcd.status() < 0)
|
||||
{
|
||||
lcd.print("No Read Support");
|
||||
fatalError(2);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static unsigned long lastsecs = -1; // pre-initialize with non zero value
|
||||
unsigned long secs;
|
||||
|
||||
secs = millis() / 1000;
|
||||
|
||||
// see if 1 second has passed
|
||||
// so the display is only updated once per second
|
||||
if(secs != lastsecs)
|
||||
{
|
||||
lastsecs = secs; // keep track of last seconds
|
||||
|
||||
// set the cursor position to top line: column 0, row 0
|
||||
lcd.setCursor(0, 0);
|
||||
|
||||
// print uptime on lcd device: (time since last reset)
|
||||
PrintUpTime(lcd, secs);
|
||||
|
||||
// Now copy the characters from the top line to the 2nd line
|
||||
// This is done character by character by:
|
||||
// - setting the character position to read
|
||||
// - reading a character
|
||||
// - setting the character position to write
|
||||
// - writing the charcter read
|
||||
for(int col = 0; col < LCD_COLS; col++)
|
||||
{
|
||||
int c;
|
||||
|
||||
lcd.setCursor(col, 0);
|
||||
if((c = lcd.read()) < 0) // if a read error, bomb out
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("read fail");
|
||||
fatalError(3);
|
||||
}
|
||||
|
||||
// check for ':' characters in col 2 and 5
|
||||
// if not there, consider it a fatal read error
|
||||
if((col == 2 || col == 5) && c != ':')
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("read fail");
|
||||
fatalError(5);
|
||||
}
|
||||
|
||||
lcd.setCursor(col, 1);
|
||||
if(lcd.write((uint8_t) c) != 1)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("write fail");
|
||||
fatalError(4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PrintUpTime(outdev, secs) - print uptime in HH:MM:SS format
|
||||
// outdev - the device to send output
|
||||
// secs - the total number of seconds uptime
|
||||
void PrintUpTime(Print &outdev, unsigned long secs)
|
||||
{
|
||||
unsigned int hr, mins, sec;
|
||||
|
||||
// convert total seconds to hours, mins, seconds
|
||||
mins = secs / 60; // how many total minutes
|
||||
hr = mins / 60; // how many total hours
|
||||
mins = mins % 60; // how many minutes within the hour
|
||||
sec = secs % 60; // how many seconds within the minute
|
||||
|
||||
|
||||
// print uptime 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)
|
||||
outdev.write('0');
|
||||
outdev.print((int)hr);
|
||||
outdev.write(':');
|
||||
if(mins < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)mins);
|
||||
outdev.write(':');
|
||||
if(sec < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)sec);
|
||||
}
|
||||
|
||||
// fatalError() - loop & blink and error code
|
||||
void fatalError(int ecode)
|
||||
{
|
||||
hd44780::fatalError(ecode); // does not return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// Serial2LCD - simple demonstration printing characters from serial port
|
||||
// Created by Bill Perry 2020-06-28
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for Noritake CU-U series displays like the
|
||||
// Noritake CU20025ECPB-U1J or CU20025ECPB-W1J
|
||||
// The Noritake CU20025ECPB display is a 20x2 line VFD display.
|
||||
// It is not a hd44780 display but is nearly fully compatible with a hd44780
|
||||
// display. The only real difference is the backlight control.
|
||||
// So while this device is supported by the hd44780 library,
|
||||
// the subclass will do its best to emulatate hd44780 functions and map
|
||||
// them to equivalent functionality when possible.
|
||||
//
|
||||
// Sketch demonstrates how to read a message of characters from
|
||||
// serial port and display it on the LCD.
|
||||
// It takes advantage of the hd44780 library automatic line
|
||||
// wrapping capability.
|
||||
// See the LineWrap sketch for details about line wrapping.
|
||||
//
|
||||
// Configure LCD_COLS, LCD_ROWS and BAUDRATE if desired/needed
|
||||
// Expected behavior of the sketch:
|
||||
// - characters received from serial port are displayed on LCD
|
||||
// - CR and LF are ignored/dropped
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED with the initalization error
|
||||
// code.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// See below for configuring the Arduino pins used.
|
||||
//
|
||||
// Noritake CU-U series LCD module pins
|
||||
// 1 - LCD gnd
|
||||
// 2 - VCC (5v)
|
||||
// 3 - not connected
|
||||
// 4 - RS Register Select (rs) --- connect to Arduino pin
|
||||
// 5 - Read/Write ------ connect to gnd
|
||||
// 6 - Enable (en) ----- connect to Arduino pin
|
||||
// 7 - Data 0 (db0) ----
|
||||
// 8 - Data 1 (db1) |-------- Not used in 4 bit mode
|
||||
// 9 - Data 2 (db2) |
|
||||
// 10 - Data 3 (db3) ----
|
||||
// 11 - Data 4 (db4) ---- connect to Arduino pin
|
||||
// 12 - Data 5 (db5) ---- connect to Arduino pin
|
||||
// 13 - Data 6 (db6) ---- connect to Arduino pin
|
||||
// 14 - Data 7 (db7) ---- connect to Arduino pin
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_NTCU20025ECPB_pinIO.h> // Arduino pin i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // for esp8266 devices
|
||||
#else
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // for all other devices
|
||||
#endif
|
||||
hd44780_NTCU20025ECPB_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
const int BAUDRATE = 9600;
|
||||
|
||||
void setup()
|
||||
{
|
||||
int status;
|
||||
|
||||
// initalize Serial port
|
||||
Serial.begin(BAUDRATE);
|
||||
|
||||
// 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>
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// begin() failed
|
||||
|
||||
Serial.print("LCD initalization failed: ");
|
||||
Serial.println(status);
|
||||
|
||||
// blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// turn on automatic line wrapping
|
||||
// which automatically wraps lines to the next lower line and wraps back
|
||||
// to the top when at the bottom line
|
||||
// NOTE:
|
||||
// noLineWrap() can be used to disable automatic line wrapping.
|
||||
// _write() can be called instead of write() to send data bytes
|
||||
// to the display bypassing any special character or line wrap processing.
|
||||
lcd.lineWrap();
|
||||
|
||||
lcd.print("Serial2LCD");
|
||||
if(LCD_ROWS > 1)
|
||||
{
|
||||
lcd.setCursor(0,1);
|
||||
lcd.print("Baud:");
|
||||
lcd.print(BAUDRATE);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
// check to see if characters available
|
||||
// indicating a message is coming in
|
||||
if (Serial.available())
|
||||
{
|
||||
// wait some time for rest of message to arrive
|
||||
delay(100);
|
||||
|
||||
// Clear the display before showing the new message
|
||||
lcd.clear();
|
||||
|
||||
// print the message on the LCD
|
||||
while (Serial.available() > 0)
|
||||
{
|
||||
char c;
|
||||
c = Serial.read();
|
||||
if(c != '\r' && c != '\n') // drop CR and LF characters
|
||||
lcd.write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// UpTime - simple demonstration of lcd
|
||||
// Created by Bill Perry 2019-11-23
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for Noritake CU-U series displays like the
|
||||
// Noritake CU20025ECPB-U1J or CU20025ECPB-W1J
|
||||
// The Noritake CU20025ECPB display is a 20x2 line VFD display.
|
||||
// It is not a hd44780 display but is nearly fully compatible with a hd44780
|
||||
// display. The only real difference is the backlight control.
|
||||
// So while this device is supported by the hd44780 library,
|
||||
// the subclass will do its best to emulatate hd44780 functions and map
|
||||
// them to equivalent functionality when possible.
|
||||
//
|
||||
// Sketch will print "UpTime" on top row of lcd
|
||||
// and will print the amount of time since the Arduino has been reset
|
||||
// on the second row.
|
||||
//
|
||||
//
|
||||
// See below for configuring the Arduino pins used.
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED.
|
||||
//
|
||||
// See below for configuring the Arduino pins used.
|
||||
//
|
||||
// Noritake CU-U series LCD module pins
|
||||
// 1 - LCD gnd
|
||||
// 2 - VCC (5v)
|
||||
// 3 - not connected
|
||||
// 4 - RS Register Select (rs) --- connect to Arduino pin
|
||||
// 5 - Read/Write ------ connect to gnd
|
||||
// 6 - Enable (en) ----- connect to Arduino pin
|
||||
// 7 - Data 0 (db0) ----
|
||||
// 8 - Data 1 (db1) |-------- Not used in 4 bit mode
|
||||
// 9 - Data 2 (db2) |
|
||||
// 10 - Data 3 (db3) ----
|
||||
// 11 - Data 4 (db4) ---- connect to Arduino pin
|
||||
// 12 - Data 5 (db5) ---- connect to Arduino pin
|
||||
// 13 - Data 6 (db6) ---- connect to Arduino pin
|
||||
// 14 - Data 7 (db7) ---- connect to Arduino pin
|
||||
// ----------------------------------------------------------------------------
|
||||
// LiquidCrystal compability:
|
||||
// Since hd44780 is LiquidCrystal API compatible, most existing LiquidCrystal
|
||||
// sketches should work with hd44780 hd44780_NTCU20025ECPB_pinIO i/o class
|
||||
// once the includes are changed to use hd44780 and the lcd object constructor
|
||||
// is changed to use the hd44780_NTCU20025ECPB_pinIO class.
|
||||
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_NTCU20025ECPB_pinIO.h> // Arduino pin i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
// Note: this can be with or without backlight control:
|
||||
|
||||
// without backlight control:
|
||||
// The parameters used by hd44780_NTCU20025ECPB_pinIO are the same as those used by
|
||||
// the IDE bundled LiquidCrystal library
|
||||
// note that ESP8266 based arduinos must use the Dn defines rather than
|
||||
// raw pin numbers.
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // for esp8266 devices
|
||||
#else
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // for all other devices
|
||||
#endif
|
||||
hd44780_NTCU20025ECPB_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
//with backlight control:
|
||||
// backlight control requires two additional parameters
|
||||
// - an additional pin to control the backlight
|
||||
// - backlight active level which tells the library the level
|
||||
// needed to turn on the backlight.
|
||||
// note: If the backlight control pin supports PWM, dimming can be done
|
||||
// WARNING: some lcd keypads have a broken backlight circuit
|
||||
// If you have a lcd keypad, it is recommended that you first run the
|
||||
// LCDKeypadCheck sketch to verify that the backlight circuitry
|
||||
// is ok before enabling backlight control.
|
||||
//
|
||||
//const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7, bl=10, blLevel=HIGH;
|
||||
//hd44780_NTCU20025ECPB_pinIO lcd(rs, en, db4, db5, db6, db7, bl, blLEvel);
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 20;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
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>
|
||||
//
|
||||
// note:
|
||||
// begin() will automatically turn on the backlight if backlight
|
||||
// control is specified in the lcd object constructor
|
||||
//
|
||||
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// hd44780 has a fatalError() routine that blinks an led if possible
|
||||
// begin() failed so call fatalError() with the error code.
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// if backlight control was specified, the backlight should be on now
|
||||
|
||||
// Print a message to the LCD
|
||||
lcd.print(" UpTime");
|
||||
|
||||
if(LCD_ROWS < 2)
|
||||
delay(3000);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static unsigned long lastsecs = -1; // pre-initialize with non zero value
|
||||
unsigned long secs;
|
||||
int status;
|
||||
|
||||
secs = millis() / 1000;
|
||||
|
||||
// see if 1 second has passed
|
||||
// so the display is only updated once per second
|
||||
if(secs != lastsecs)
|
||||
{
|
||||
lastsecs = secs; // keep track of last seconds
|
||||
|
||||
// set the cursor position to column 0, row 1
|
||||
// note: row 1 is the second row from top,
|
||||
// since row counting begins with 0
|
||||
// if display has only 1 line, it will appear on that line
|
||||
status = lcd.setCursor(0, 1);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// setCursor() failed so call fatalError() with the error code.
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// print uptime on lcd device: (time since last reset)
|
||||
PrintUpTime(lcd, secs);
|
||||
}
|
||||
}
|
||||
|
||||
// PrintUpTime(outdev, secs) - print uptime in HH:MM:SS format
|
||||
// outdev - the device to send output
|
||||
// secs - the total number of seconds uptime
|
||||
//
|
||||
// This is a fancy output routine.
|
||||
// outdev is a Print class object which indicates
|
||||
// where the output should be sent.
|
||||
// PrintUpTime can be used with any object that uses the Print class.
|
||||
// This code works with Serial objects, as well as the the hd44780 lcd objects.
|
||||
// i.e. you can call with Serial: PrintUpTime(Serial, seconds);
|
||||
|
||||
void PrintUpTime(Print &outdev, unsigned long secs)
|
||||
{
|
||||
unsigned int hr, mins, sec;
|
||||
|
||||
// convert total seconds to hours, mins, seconds
|
||||
mins = secs / 60; // how many total minutes
|
||||
hr = mins / 60; // how many total hours
|
||||
mins = mins % 60; // how many minutes within the hour
|
||||
sec = secs % 60; // how many seconds within the minute
|
||||
|
||||
// print uptime in HH:MM:SS format
|
||||
|
||||
if(hr > 99)
|
||||
hr %= 100; // limit hr to 0-99
|
||||
|
||||
// Print class does not support fixed width formatting
|
||||
// so insert a zero if number smaller than 10
|
||||
|
||||
if(hr < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)hr);
|
||||
outdev.write(':');
|
||||
if(mins < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)mins);
|
||||
outdev.write(':');
|
||||
if(sec < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)sec);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDcharset - Display character set for hd44780_NTCU20025ECPB_pinIO i/o class
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example LCDcharset.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or example
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in hd44780 examples:
|
||||
// hd44780/examples/hd44780examples/LCDcharset/LCDcharset.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDcharset
|
||||
//
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_NTCU20025ECPB_pinIO.h> // include i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // for esp8266 devices
|
||||
#else
|
||||
//const int rs=12, en=11, db4=5, db5=4, db6=3, db7=2; // IDE LiquidCrystal pins
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // lcd keypad shield pins
|
||||
#endif
|
||||
hd44780_NTCU20025ECPB_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
#define LCD_COLS 20
|
||||
#define LCD_ROWS 2
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/LCDcharset/LCDcharset.ino>
|
||||
@@ -0,0 +1,39 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// LCDiSpeed - Speed test for hd44780 hd44780_NTCU20025ECPB_pinIO i/o class
|
||||
// ------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDiSpeed
|
||||
//
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_NTCU20025ECPB_pinIO.h> // include i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // for esp8266 devices
|
||||
#else
|
||||
//const int rs=12, en=11, db4=5, db5=4, db6=3, db7=2; // IDE LiquidCrystal pins
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // lcd keypad shield pins
|
||||
#endif
|
||||
hd44780_NTCU20025ECPB_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
#define LCD_COLS 20
|
||||
#define LCD_ROWS 2
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino>
|
||||
@@ -0,0 +1,39 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
// LCDLibTest - library test for hd44780 hd44780_NTCU20025ECPB_pinIO i/o class
|
||||
// ---------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/LCDlibTest/LCDlibTest.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDlibTest
|
||||
//
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_NTCU20025ECPB_pinIO.h> // include i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // for esp8266 devices
|
||||
#else
|
||||
//const int rs=12, en=11, db4=5, db5=4, db6=3, db7=2; // IDE LiquidCrystal pins
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // lcd keypad shield pins
|
||||
#endif
|
||||
hd44780_NTCU20025ECPB_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
#define LCD_COLS 20
|
||||
#define LCD_ROWS 2
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/LCDlibTest/LCDlibTest.ino>
|
||||
@@ -0,0 +1,39 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// lcdproc - lcdproc sketch for hd44780 hd44780_NTCU20025ECPB_pinIO i/o class
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/lcdproc/lcdproc.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/lcdproc
|
||||
//
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_NTCU20025ECPB_pinIO.h> // include i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // for esp8266 devices
|
||||
#else
|
||||
//const int rs=12, en=11, db4=5, db5=4, db6=3, db7=2; // IDE LiquidCrystal pins
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // lcd keypad shield pins
|
||||
#endif
|
||||
hd44780_NTCU20025ECPB_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
#define LCD_COLS 20
|
||||
#define LCD_ROWS 2
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/lcdproc/lcdproc.ino>
|
||||
@@ -0,0 +1,101 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// HelloWorld - simple demonstration of lcd
|
||||
// Created by Bill Perry 2016-07-02
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for the Noritake CU-U series VFDs, in native serial mode
|
||||
//
|
||||
// Sketch prints "Hello, World!" on the lcd
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED.
|
||||
//
|
||||
// The application note for CU-U series boards is here:
|
||||
// https://www.noritake-elec.com/includes/documents/brochure/CU-U_Application_Note.pdf
|
||||
// Datasheets for specific boards, code samples, and more can be found here:
|
||||
// https://www.noritake-elec.com/products/vfd-display-module/character-display/cu-u-series
|
||||
//
|
||||
//
|
||||
// The device uses a kind of 3-wire SPI for communication.
|
||||
// Pinout:
|
||||
// 1 VCC
|
||||
// 2 SI/SO (DATA) MOSI - Digital Pin 11 on Uno & Leonardo
|
||||
// 3 GND
|
||||
// 4 STB (CS) SS - Digital Pin 10 on Uno & Leonardo
|
||||
// 5 SCK (CLK) SCK - Digital Pin 13 on Uno & Leonardo
|
||||
// 6 NC
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// LiquidCrystal compability:
|
||||
// Since hd44780 is LiquidCrystal API compatible, most existing LiquidCrystal
|
||||
// sketches should work with hd44780 hd44780_NTCUUserial i/o class once the
|
||||
// includes are changed to use hd44780 and the lcd object constructor is
|
||||
// changed to use the hd44780_NTCUUserial i/o class.
|
||||
//
|
||||
|
||||
#include <SPI.h> // optional, include to use h/w spi
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_NTCUUserial.h> // Noritake CU-U serial i/o class header
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCUUserial lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
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
|
||||
//
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// begin() failed so blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// Print a message to the LCD
|
||||
lcd.print("Hello, World!");
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
@@ -0,0 +1,358 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDCustomChars - simple demonstration of lcd custom characters
|
||||
// Created by Bill Perry 2016-10-06
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for the Noritake CU-U series VFDs, in native serial mode
|
||||
//
|
||||
// Sketch demonstrates how to assign custom characters to the eight hd44780
|
||||
// custom character codepoints and how to display on the LCD using
|
||||
// write() and print()
|
||||
//
|
||||
// You can create your own custom characters.
|
||||
// Here are a couple of web pages that have a tool that will generate the data
|
||||
// values needed for custom character.
|
||||
// https://kakedev.github.io/GlyphGenerator/
|
||||
// http://www.quinapalus.com/hd44780udg.html
|
||||
// https://omerk.github.io/lcdchargen
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED.
|
||||
//
|
||||
//
|
||||
// The device uses a kind of 3-wire SPI for communication.
|
||||
// Pinout:
|
||||
// 1 VCC
|
||||
// 2 SI/SO (DATA) MOSI - Digital Pin 11 on Uno & Leonardo
|
||||
// 3 GND
|
||||
// 4 STB (CS) SS - Digital Pin 10 on Uno & Leonardo
|
||||
// 5 SCK (CLK) SCK - Digital Pin 13 on Uno & Leonardo
|
||||
// 6 NC
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// LiquidCrystal compability:
|
||||
// Since hd44780 is LiquidCrystal API compatible, most existing LiquidCrystal
|
||||
// sketches should work with hd44780 hd44780_NTCUUserial i/o class once the
|
||||
// includes are changed to use hd44780 and the lcd object constructor is
|
||||
// changed to use the hd44780_NTCUUserial i/o class.
|
||||
//
|
||||
|
||||
#include <SPI.h> // optional, include to use h/w spi
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_NTCUUserial.h> // Noritake CU-U serial i/o class header
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCUUserial lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
const int LongDelay = 5000;
|
||||
const int ShortDelay = 800;
|
||||
|
||||
int customcharRow = 1; // default to printing custom chars on row 1
|
||||
|
||||
// Below are some custom characters for demonstration
|
||||
|
||||
// You can ensure that the data for these custom characters is only
|
||||
// in flash and not in RAM by using the const qualifier.
|
||||
// However....
|
||||
// If using the AVR part, the AVR proprietary PROGMEM directive must be used.
|
||||
// PROGMEM is only required on AVR parts since the AVR parts cannot directly
|
||||
// access const data stored in flash like all the other processors.
|
||||
// PROGMEM is an AVR specific proprietary kludge that tells the linker and
|
||||
// startup code to handle the data differently.
|
||||
// PROGMEM is only used by the AVR and not required by any other processor.
|
||||
//
|
||||
// Most non AVR cores provide AVR compatibilty by providing support (emulation)
|
||||
// for the AVR proprietary PROGMEM directive and corresponding access functions,
|
||||
// but some do not.
|
||||
//
|
||||
// Because of this AVR const data and PROGMEM issue, there is no way to
|
||||
// guarantee code portability across all cores when using const data.
|
||||
//
|
||||
//
|
||||
// the hd44780 library assumes that if a const qualifier is used on the AVR
|
||||
// processor that the data has been stored in flash using the PROGMEM directive.
|
||||
// There is no way for the hd44780 library to know or detect if PROGMEM has
|
||||
// been used.
|
||||
// So if the const qualifer is used but the PROGMEM directive is not used on
|
||||
// an AVR processor, the custom char will be garbage.
|
||||
//
|
||||
// Examples:
|
||||
// For all processors other than AVR:
|
||||
// const char bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const uint8_ bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
//
|
||||
// For AVR: (and non AVR cores that have AVR PROGMEM emulation)
|
||||
// const char bell[8] PROGMEM = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const uint8_t bell[8] PROGMEM = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// OR
|
||||
// const PROGMEM char bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const PROGMEM uint8_t bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// NOTE:
|
||||
// if PROGMEM is used on older AVR compilers it generates a warning.
|
||||
//
|
||||
|
||||
uint8_t bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
uint8_t note[8] = {0x02,0x03,0x02,0x0e,0x1e,0x0c,0x00,0x00};
|
||||
uint8_t clockface[8] = {0x00,0x0e,0x15,0x17,0x11,0x0e,0x00,0x00};
|
||||
uint8_t heart[8] = {0x00,0x0a,0x1f,0x1f,0x0e,0x04,0x00,0x00};
|
||||
uint8_t duck[8] = {0x00,0x0c,0x1d,0x0f,0x0f,0x06,0x00,0x00};
|
||||
uint8_t check[8] = {0x00,0x01,0x03,0x16,0x1c,0x08,0x00,0x00};
|
||||
uint8_t cross[8] = {0x00,0x1b,0x0e,0x04,0x0e,0x1b,0x00,0x00};
|
||||
uint8_t smile[8] = {0x00,0x0a,0x0a,0x00,0x00,0x11,0x0e,0x00};
|
||||
|
||||
uint8_t degreeSymbol[8]= {0x06,0x09,0x09,0x06,0x00,0x00,0x00,0x00};
|
||||
uint8_t degreeC[8] = {0x18,0x18,0x03,0x04,0x04,0x04,0x03,0x00};
|
||||
uint8_t degreeF[8] = {0x18,0x18,0x07,0x04,0x07,0x04,0x04,0x00};
|
||||
|
||||
const PROGMEM uint8_t vsigbar[][8] = {
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0 bars, same as <space>
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x1F}, // 1 bars
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x1F,0x1F}, // 2 bars
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F}, // 3 bars
|
||||
{0x00, 0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F}, // 4 bars
|
||||
{0x00, 0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x1F}, // 5 bars
|
||||
{0x00, 0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 6 bars
|
||||
{0x00, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 7 bars
|
||||
{0x1F, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 8 bars
|
||||
};
|
||||
|
||||
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
|
||||
{
|
||||
// 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
|
||||
}
|
||||
void loop(void)
|
||||
{
|
||||
lcd.clear();
|
||||
|
||||
lcd.print("Custom Chars");
|
||||
|
||||
// create custom characters
|
||||
// int rval = createChar(charval, charmap[]);
|
||||
//
|
||||
// createChar() creates a custom character
|
||||
// for the character at the charval codepoint.
|
||||
// It returns zero if successful.
|
||||
//
|
||||
// to display the custom character, simply call write()
|
||||
// with the charval use in createChar()
|
||||
//
|
||||
// The display must be initialized *before* you attempt
|
||||
// to create custom characters.
|
||||
//
|
||||
// Note: On hd44780 displays there are 8 custom characters.
|
||||
// They are assigned to character codepoint values 0x00 to 0x07
|
||||
// The codepoints 0x08 to 0x0f are duplicates for 0x00 to 0x07
|
||||
// i.e. 0x08 is the same as 0x00, 0x09 same as 0x01, etc...
|
||||
|
||||
// create 8 custom characters
|
||||
lcd.createChar(0, bell);
|
||||
lcd.createChar(1, note);
|
||||
lcd.createChar(2, clockface);
|
||||
lcd.createChar(3, heart);
|
||||
lcd.createChar(4, duck);
|
||||
lcd.createChar(5, check);
|
||||
lcd.createChar(6, cross);
|
||||
lcd.createChar(7, smile);
|
||||
|
||||
// prepare to display the custom characters
|
||||
// on multi line displays the custom characters will be
|
||||
// displayed on the 2nd line
|
||||
// on single line displays, delay a bit to see the initial display,
|
||||
// then clear the display to display the custom characters on the top line
|
||||
if(LCD_ROWS < 2)
|
||||
{
|
||||
customcharRow = 0;
|
||||
delay(LongDelay);
|
||||
lcd.clear();
|
||||
}
|
||||
|
||||
lcd.setCursor(0, customcharRow);
|
||||
|
||||
// write() or print() can be used to display custom characters.
|
||||
//
|
||||
// To use write() pass the charval of the desired custom character.
|
||||
// lcd.write(charval);
|
||||
// NOTE:
|
||||
// The Print class has an issue that does not allow 0 (zero) to be used
|
||||
// on write() without casting it. The Arduino team refuses to fix this.
|
||||
// hd44780 has a work around in it to remove this issue so you can call
|
||||
// write() with a constant value of 0 without having to cast it.
|
||||
//
|
||||
// write() can also be used with literal characters that contain
|
||||
// an octal (base 8) escape seuence.
|
||||
// lcd.write('\###');
|
||||
//
|
||||
// To use print() pass in the charval of the desired custom character
|
||||
// as a character *not* an integer.
|
||||
// This requires using a literal character with an octal escape sequence.
|
||||
// lcd.print('\###');
|
||||
//
|
||||
|
||||
// Since both write() & print() both accept octal escaped literal characters
|
||||
// it is the most compatible & portable way of sending custom characters
|
||||
|
||||
// display all 8 custom characters.
|
||||
|
||||
// write() with character codepoint values
|
||||
lcd.write(0); // casting to an uint8_t or byte not needed with hd44780
|
||||
lcd.write(1);
|
||||
|
||||
// write() & print() with octal escaped literal characters
|
||||
lcd.write('\002'); // this is an octal escaped literal character
|
||||
lcd.write('\003'); // this is an octal escaped literal character
|
||||
lcd.print('\004'); // this is an octal escaped literal character
|
||||
lcd.print('\005'); // this is an octal escaped literal character
|
||||
|
||||
// can also drop the leading zeros on small litereal values like these
|
||||
lcd.print('\06'); // this is an octal escaped literal character
|
||||
lcd.print('\7'); // this is an octal escaped literal character
|
||||
|
||||
delay(LongDelay);
|
||||
|
||||
// You can also insert custom character codepoints into C strings.
|
||||
// To do so, insert the character codepoint value as an octal constant.
|
||||
// However,
|
||||
// because zero indicates the end of string in C you cannot use zero.
|
||||
// Example:
|
||||
// lcd.print("charval #1: \001"); // prints custom character at codepoint 1
|
||||
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code1: \001");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code2: \002");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code3: \003");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code4: \004");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code5: \005");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code6: \006");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code7: \007");
|
||||
delay(ShortDelay);
|
||||
|
||||
// Another nifty trick is that you can modify custom characters on the
|
||||
// display without having to re-write the characters on the display.
|
||||
// To do this, simply create a new character for a codepoint.
|
||||
// All characters on the display which have that codepoint will "magically"
|
||||
// change to the new custom character.
|
||||
// So for example, if the entire display was written with custom character
|
||||
// zero and character zero was a bell, if you called createChar() to
|
||||
// redefine character codepoint zero to be a duck,
|
||||
// the entire display would turn to ducks without having to send any
|
||||
// characters to the display.
|
||||
|
||||
// create the initial custom character
|
||||
lcd.createChar(0, bell);
|
||||
|
||||
// fill the custom character line with the custom character.
|
||||
lcd.setCursor(0,customcharRow);
|
||||
for(uint8_t col=0; col<LCD_COLS; col++)
|
||||
lcd.write(0);
|
||||
|
||||
delay(ShortDelay);
|
||||
|
||||
// change the single custom character previously written on the row
|
||||
// and all the characters on the row will change
|
||||
// without having to re-write the characters.
|
||||
lcd.createChar(0, note);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, clockface);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, heart);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, duck);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, check);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, cross);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, smile);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeSymbol);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeC);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeF);
|
||||
delay(ShortDelay);
|
||||
|
||||
// show multiple vertical bars rising
|
||||
// by changing the single custom character that is already written
|
||||
// to the entire row on the display
|
||||
for(int i = 0; i < 9; i++)
|
||||
{
|
||||
lcd.createChar(0, vsigbar[i]);
|
||||
delay(ShortDelay);
|
||||
}
|
||||
|
||||
delay(LongDelay);
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LineWrap - simple demonstration of automatic linewrap functionality
|
||||
// Created by Bill Perry 2017-05-10
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for the Noritake CU-U series VFDs, in native serial mode
|
||||
//
|
||||
// Sketch demonstrates hd44780 library automatic line wrapping functionality.
|
||||
//
|
||||
// Background:
|
||||
// hd44780 LCDs do not use linear continuous memory for the characters
|
||||
// on the lines on the display.
|
||||
// This means that simply sending continuous characters to the
|
||||
// display will not fill lines and wrap appropriately as might be expected.
|
||||
// The hd44780 library solves this issue by adding a line wrapping capability
|
||||
// in s/w that can be enabled & disabled.
|
||||
// This allows the host to send characters to the display continuously and they
|
||||
// will wrap to the next lower line when the end of the visible line has been
|
||||
// reached. When on the bottom line it will wrap back to the top line.
|
||||
//
|
||||
// (Configure LCD_COLS & LCD_ROWS if desired/needed)
|
||||
// Expected behavior of the sketch:
|
||||
// - display a banner announcing the test.
|
||||
// - print the configured LCD geometry
|
||||
// - print a long text string to demostrate automatic line wrapping
|
||||
// - print lots of characters (slowly) to show how the full wrapping works.
|
||||
// (loop)
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED with the initalization error
|
||||
// code.
|
||||
//
|
||||
// Special note for certain 16x1 displays:
|
||||
// Some 16x1 displays are actually a 8x2 display that have both lines on
|
||||
// a single line on the display.
|
||||
// If you have one of these displays, simply set the geometry to 8x2 instead
|
||||
// of 16x1.
|
||||
// In normal sketches, lineWrap() mode will allow this type of display to
|
||||
// properly function as a 16x1 display in that it will allow printing up to
|
||||
// 16 characters on the display without having to manually set the cursor
|
||||
// position to print the right characters on the half of the display.
|
||||
// However, when using this 8x2 display as a 16x1 display,
|
||||
// scrollDisplayLeft() and scrollDisplayRight() will not work as intended.
|
||||
// They will shift the two halves of the display rather than the entire display.
|
||||
// This is because the hd44780 chip is doing the shift and chip is hard coded
|
||||
// internally for two lines.
|
||||
|
||||
#include <SPI.h> // optional, include to use h/w spi
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_NTCUUserial.h> // Noritake CU-U serial i/o class header
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCUUserial lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
// LCD geometry
|
||||
// while 16x2 will work on most displays even if the geometry is different,
|
||||
// for actual wrap testing of a particular LCD it is best to use the correct
|
||||
// geometry.
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
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>
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// begin() failed so blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// turn on automatic line wrapping
|
||||
// which automatically wraps lines to the next lower line and wraps back
|
||||
// to the top when at the bottom line
|
||||
// NOTE:
|
||||
// noLineWrap() can be used to disable automatic line wrapping.
|
||||
// _write() can be called instead of write() to send data bytes
|
||||
// to the display bypassing any special character or line wrap processing.
|
||||
lcd.lineWrap();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("WrapTest");
|
||||
delay(2000);
|
||||
lcd.clear();
|
||||
|
||||
//print the configured LCD geometry
|
||||
lcd.print(LCD_COLS);
|
||||
lcd.print("x");
|
||||
lcd.print(LCD_ROWS);
|
||||
delay(3000);
|
||||
lcd.clear();
|
||||
|
||||
// print a long text string
|
||||
// without line wrapping enabled, the text would not wrap properly
|
||||
// to the next line.
|
||||
|
||||
if(LCD_COLS == 8)
|
||||
lcd.print("A long text line");
|
||||
else
|
||||
lcd.print("This is a very long line of text");
|
||||
delay(3000);
|
||||
|
||||
lcd.clear();
|
||||
|
||||
// now print 2 full displays worth of characters to show
|
||||
// the full wrapping.
|
||||
|
||||
lcd.cursor(); // turn on cursor so you can see where it is
|
||||
|
||||
char c = '0'; // start at the character for the number zero
|
||||
for(int i = 2*LCD_COLS*LCD_ROWS; i; i--)
|
||||
{
|
||||
lcd.print(c++);
|
||||
delay(200); // slow things down to watch the printing & wrapping
|
||||
|
||||
if(c > 0x7e) // wrap back to beginning of printable ASCII chars
|
||||
c = '!';
|
||||
}
|
||||
delay(3000);
|
||||
lcd.noCursor(); // turn off cursor
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
hd44780_NTCUUserial examples
|
||||
=======================
|
||||
|
||||
The examples included in this directory are for the hd44780_NTCUUserial i/o class.<br>
|
||||
The hd44780_NTCUUserial i/o class controls the Noritake CU-U series VFD with a native serial interface
|
||||
|
||||
|
||||
#### The following examples are included:
|
||||
|
||||
- `HelloWorld`<br>
|
||||
Prints "Hello, World!" on the vfd
|
||||
|
||||
- `LCDCustomChars`<br>
|
||||
Demonstrates using custom characters
|
||||
|
||||
- `LineWrap`<br>
|
||||
Demonstrates automatic linewrap functionality
|
||||
|
||||
- `ReadWrite`<br>
|
||||
Demonstrates the ability to read data from the VFD.
|
||||
|
||||
- `Serial2LCD`<br>
|
||||
Displays a message read from the serial port on the lcd.
|
||||
|
||||
- `UpTime`<br>
|
||||
Prints the amount of time since the Arduino has been reset.
|
||||
|
||||
- `hd44780examples`<br>
|
||||
The hd44780examples subdirectory contains
|
||||
hd44780_NTCUUserial class specific wrapper sketches for sketches under
|
||||
examples/hd44780examples.
|
||||
@@ -0,0 +1,176 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// ReadWrite - simple demonstration reading data from LCD
|
||||
// Created by Bill Perry 2016-08-19
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for the Noritake CU-U series VFDs, in native serial mode
|
||||
//
|
||||
// The purpose of the sketch is to demonstrate the ability to read data from
|
||||
// the LCD.
|
||||
//
|
||||
// Sketch will print the amount of time since the Arduino has been reset
|
||||
// on the top row and then read the data from the LCD to print it on the
|
||||
// second row
|
||||
//
|
||||
// If there are errors and the arduino supports a built in LED,
|
||||
// an error status code will blink on the built in LED.
|
||||
// Error codes:
|
||||
// (1) lcd device initalization failed
|
||||
// (2) lcd device does not support reads
|
||||
// (3) error reading data from lcd device
|
||||
// (4) error writing data to lcd device
|
||||
//
|
||||
|
||||
#include <SPI.h> // optional, include to use h/w spi
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_NTCUUserial.h> // Noritake CU-U serial i/o class header
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCUUserial lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_ROWS = 2;
|
||||
const int LCD_COLS = 16;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// initialize LCD with number of columns and rows:
|
||||
if( lcd.begin(LCD_COLS, LCD_ROWS))
|
||||
{
|
||||
// begin() failed so blink the onboard LED if possible
|
||||
fatalError(1);
|
||||
}
|
||||
|
||||
// check to see if device can read by attempting to read
|
||||
// the lcd status register. If it fails then assume it was
|
||||
// because the lcd device does not support reads.
|
||||
if(lcd.status() < 0)
|
||||
{
|
||||
lcd.print("No Read Support");
|
||||
fatalError(2);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static unsigned long lastsecs = -1; // pre-initialize with non zero value
|
||||
unsigned long secs;
|
||||
|
||||
secs = millis() / 1000;
|
||||
|
||||
// see if 1 second has passed
|
||||
// so the display is only updated once per second
|
||||
if(secs != lastsecs)
|
||||
{
|
||||
lastsecs = secs; // keep track of last seconds
|
||||
|
||||
// set the cursor position to top line: column 0, row 0
|
||||
lcd.setCursor(0, 0);
|
||||
|
||||
// print uptime on lcd device: (time since last reset)
|
||||
PrintUpTime(lcd, secs);
|
||||
|
||||
// Now copy the characters from the top line to the 2nd line
|
||||
// This is done character by character by:
|
||||
// - setting the character position to read
|
||||
// - reading a character
|
||||
// - setting the character position to write
|
||||
// - writing the charcter read
|
||||
for(int col = 0; col < LCD_COLS; col++)
|
||||
{
|
||||
int c;
|
||||
|
||||
lcd.setCursor(col, 0);
|
||||
if((c = lcd.read()) < 0) // if a read error, bomb out
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("read fail");
|
||||
fatalError(3);
|
||||
}
|
||||
|
||||
// check for ':' characters in col 2 and 5
|
||||
// if not there, consider it a fatal read error
|
||||
if((col == 2 || col == 5) && c != ':')
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("read fail");
|
||||
fatalError(3);
|
||||
}
|
||||
|
||||
lcd.setCursor(col, 1);
|
||||
if(lcd.write((uint8_t) c) != 1)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("write fail");
|
||||
fatalError(4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PrintUpTime(outdev, secs) - print uptime in HH:MM:SS format
|
||||
// outdev - the device to send output
|
||||
// secs - the total number of seconds uptime
|
||||
void PrintUpTime(Print &outdev, unsigned long secs)
|
||||
{
|
||||
unsigned int hr, mins, sec;
|
||||
|
||||
// convert total seconds to hours, mins, seconds
|
||||
mins = secs / 60; // how many total minutes
|
||||
hr = mins / 60; // how many total hours
|
||||
mins = mins % 60; // how many minutes within the hour
|
||||
sec = secs % 60; // how many seconds within the minute
|
||||
|
||||
|
||||
// print uptime 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)
|
||||
outdev.write('0');
|
||||
outdev.print((int)hr);
|
||||
outdev.write(':');
|
||||
if(mins < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)mins);
|
||||
outdev.write(':');
|
||||
if(sec < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)sec);
|
||||
}
|
||||
|
||||
// fatalError() - loop & blink an error code
|
||||
void fatalError(int ecode)
|
||||
{
|
||||
hd44780::fatalError(ecode); // does not return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// Serial2LCD - simple demonstration printing characters from serial port
|
||||
// Created by Bill Perry 2020-06-28
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for the Noritake CU-U series VFDs, in native serial mode
|
||||
//
|
||||
// Sketch demonstrates hd44780 how to read a message of characters from
|
||||
// serial port and display it on the LCD.
|
||||
// It takes advantage of the hd44780 library automatic line
|
||||
// wrapping capability.
|
||||
// See the LineWrap sketch for details about line wrapping.
|
||||
//
|
||||
// Configure LCD_COLS, LCD_ROWS and BAUDRATE if desired/needed
|
||||
// Expected behavior of the sketch:
|
||||
// - characters received from serial port are displayed on LCD
|
||||
// - CR and LF are ignored/dropped
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED with the initalization error
|
||||
// code.
|
||||
//
|
||||
// Some 16x1 displays are actually a 8x2 display that have both lines on
|
||||
// a single line on the display.
|
||||
// If you have one of these displays, simply set the geometry to 8x2 instead
|
||||
// of 16x1.
|
||||
|
||||
#include <SPI.h> // optional, include to use h/w spi
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_NTCUUserial.h> // Noritake CU-U serial i/o class header
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCUUserial lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
const int BAUDRATE = 9600;
|
||||
|
||||
void setup()
|
||||
{
|
||||
int status;
|
||||
|
||||
// initalize Serial port
|
||||
Serial.begin(BAUDRATE);
|
||||
|
||||
// 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>
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// begin() failed
|
||||
|
||||
Serial.print("LCD initalization failed: ");
|
||||
Serial.println(status);
|
||||
|
||||
// blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// turn on automatic line wrapping
|
||||
// which automatically wraps lines to the next lower line and wraps back
|
||||
// to the top when at the bottom line
|
||||
// NOTE:
|
||||
// noLineWrap() can be used to disable automatic line wrapping.
|
||||
// _write() can be called instead of write() to send data bytes
|
||||
// to the display bypassing any special character or line wrap processing.
|
||||
lcd.lineWrap();
|
||||
|
||||
lcd.print("Serial2LCD");
|
||||
if(LCD_ROWS > 1)
|
||||
{
|
||||
lcd.setCursor(0,1);
|
||||
lcd.print("Baud:");
|
||||
lcd.print(BAUDRATE);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
// check to see if characters available
|
||||
// indicating a message is coming in
|
||||
if (Serial.available())
|
||||
{
|
||||
// wait some time for rest of message to arrive
|
||||
delay(100);
|
||||
|
||||
// Clear the display before showing the new message
|
||||
lcd.clear();
|
||||
|
||||
// print the message on the LCD
|
||||
while (Serial.available() > 0)
|
||||
{
|
||||
char c;
|
||||
c = Serial.read();
|
||||
if(c != '\r' && c != '\n') // drop CR and LF characters
|
||||
lcd.write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// UpTime - simple demonstration of lcd
|
||||
// Created by Bill Perry 2017-05-11
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for the Noritake CU-U series VFDs, in native serial mode
|
||||
//
|
||||
// Sketch will print "UpTime" on top row of lcd
|
||||
// and will print the amount of time since the Arduino has been reset
|
||||
// on the second row.
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED.
|
||||
//
|
||||
|
||||
#include <SPI.h> // optional, include to use h/w spi
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_NTCUUserial.h> // Noritake CU-U serial i/o class header
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCUUserial lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
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
|
||||
//
|
||||
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// hd44780 has a fatalError() routine that blinks an led if possible
|
||||
// begin() failed so call fatalError() with the error code.
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// Print a message to the LCD
|
||||
lcd.print(" UpTime");
|
||||
|
||||
if(LCD_ROWS < 2)
|
||||
delay(3000);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static unsigned long lastsecs = -1; // pre-initialize with non zero value
|
||||
unsigned long secs;
|
||||
int status;
|
||||
|
||||
secs = millis() / 1000;
|
||||
|
||||
// see if 1 second has passed
|
||||
// so the display is only updated once per second
|
||||
if(secs != lastsecs)
|
||||
{
|
||||
lastsecs = secs; // keep track of last seconds
|
||||
|
||||
// set the cursor position to column 0, row 1
|
||||
// note: row 1 is the second row from top,
|
||||
// since row counting begins with 0
|
||||
// if display has only 1 line, it will appear on that line
|
||||
status = lcd.setCursor(0, 1);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// setCursor() failed so call fatalError() with the error code.
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// print uptime on lcd device: (time since last reset)
|
||||
PrintUpTime(lcd, secs);
|
||||
}
|
||||
}
|
||||
|
||||
// PrintUpTime(outdev, secs) - print uptime in HH:MM:SS format
|
||||
// outdev - the device to send output
|
||||
// secs - the total number of seconds uptime
|
||||
//
|
||||
// This is a fancy output routine.
|
||||
// outdev is a Print class object which indicates
|
||||
// where the output should be sent.
|
||||
// PrintUpTime can be used with any object that uses the Print class.
|
||||
// This code works with Serial objects, as well as the the hd44780 lcd objects.
|
||||
// i.e. you can call with Serial: PrintUpTime(Serial, seconds);
|
||||
|
||||
void PrintUpTime(Print &outdev, unsigned long secs)
|
||||
{
|
||||
unsigned int hr, mins, sec;
|
||||
|
||||
// convert total seconds to hours, mins, seconds
|
||||
mins = secs / 60; // how many total minutes
|
||||
hr = mins / 60; // how many total hours
|
||||
mins = mins % 60; // how many minutes within the hour
|
||||
sec = secs % 60; // how many seconds within the minute
|
||||
|
||||
// print uptime in HH:MM:SS format
|
||||
|
||||
if(hr > 99)
|
||||
hr %= 100; // limit hr to 0-99
|
||||
|
||||
// Print class does not support fixed width formatting
|
||||
// so insert a zero if number smaller than 10
|
||||
|
||||
if(hr < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)hr);
|
||||
outdev.write(':');
|
||||
if(mins < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)mins);
|
||||
outdev.write(':');
|
||||
if(sec < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)sec);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDcharset - Display LCD character set for hd44780 hd44780_NTCUUserial i/o class
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example LCDcharset.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or example
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in hd44780 examples:
|
||||
// hd44780/examples/hd44780examples/LCDcharset/LCDcharset.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDcharset
|
||||
//
|
||||
|
||||
#include <SPI.h> // optional, include to use h/w spi
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_NTCUUserial.h> // Noritake CU-U serial i/o class header
|
||||
|
||||
// define the LCD geometry
|
||||
#define LCD_COLS 16
|
||||
#define LCD_ROWS 2
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCUUserial lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library LCDcharset sketch source code
|
||||
#include <examples/hd44780examples/LCDcharset/LCDcharset.ino>
|
||||
@@ -0,0 +1,55 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDiSpeed - LCD Interface Speed test
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example LCDiSpeed.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or example
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in hd44780 examples:
|
||||
// hd44780/examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDiSpeed
|
||||
//
|
||||
|
||||
#include <SPI.h> // optional, include to use h/w spi
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_NTCUUserial.h> // Noritake CU-U serial i/o class header
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCUUserial lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library LCDiSpeed sketch source code
|
||||
#include <examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino>
|
||||
@@ -0,0 +1,55 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDLibTest - LCD library test sketch
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/LCDlibTest/LCDlibTest.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDlibTest
|
||||
//
|
||||
|
||||
#include <SPI.h> // optional, include to use h/w spi
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_NTCUUserial.h> // Noritake CU-U serial i/o class header
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCUUserial lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/LCDlibTest/LCDlibTest.ino>
|
||||
@@ -0,0 +1,55 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// lcdproc - LCD library lcdproc wrapper sketch
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/lcdproc/lcdproc.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/lcdproc
|
||||
//
|
||||
|
||||
#include <SPI.h> // optional, include to use h/w spi
|
||||
#include <hd44780.h> // main hd44780 header
|
||||
#include <hd44780ioClass/hd44780_NTCUUserial.h> // Noritake CU-U serial i/o class header
|
||||
|
||||
// constructor parameters:
|
||||
// lcd([cs], [clock, data])
|
||||
// If no parameters, then library will use SS, SCK, and MOSI pins
|
||||
// If cs parameter specified, then use it for chip select then SCK and MOSI
|
||||
// If <SPI.h> is included and clock & data pins match h/w SPI pins SCK and MOSI,
|
||||
// h/w spi will be used
|
||||
// If h/w spi is not possible, then the code will fall back to bit banging.
|
||||
//
|
||||
// NOTE:
|
||||
// - Leonardo h/w is "stupid" and does not bring out SS
|
||||
// (it only drives an LED)
|
||||
// - Leonardo does not bring SPI signals to female headers,
|
||||
// they are only on 6 pin ISP header.
|
||||
// - ESP8266 is does not use naked constants for digital pin numbers
|
||||
//
|
||||
//
|
||||
// To work around these pin issues in this sketch,
|
||||
// Leonardo will use uno digital pins for SPI h/w which means it will
|
||||
// not use h/w spi. All the other boards will use the h/w SPI pins.
|
||||
// Consult board pinout diagram to see where SS, SCK, and MOSI are available.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO_AVR_LEONARDO) || ( (USB_VID == 0x2341) && (USB_PID == 0x8036) )
|
||||
const int cs=10, clk=13, data=11; // uno SPI pins (s/w bit banging will be used)
|
||||
#else
|
||||
const int cs=SS, clk=SCK, data=MOSI; // use h/w SPI pins on all other boards
|
||||
#endif
|
||||
hd44780_NTCUUserial lcd(cs, clk, data); // declare lcd object
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/lcdproc/lcdproc.ino>
|
||||
@@ -0,0 +1,116 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// HelloWorld - simple demonstration of lcd
|
||||
// Created by Bill Perry 2016-07-02
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCDs that are directly controlled with Arduino pins.
|
||||
//
|
||||
// Sketch prints "Hello, World!" on the lcd
|
||||
//
|
||||
// See below for configuring the Arduino pins used.
|
||||
//
|
||||
// While not all hd44780 use the same pinout, here is the one that most use:
|
||||
// pin 1 is the pin closest to the edge of the PCB
|
||||
// 1 - LCD gnd
|
||||
// 2 - VCC (5v)
|
||||
// 3 - Vo Contrast Voltage
|
||||
// 4 - RS Register Select (rs)
|
||||
// 5 - Read/Write
|
||||
// 6 - Enable (en)
|
||||
// 7 - Data 0 (db0) ----
|
||||
// 8 - Data 1 (db1) |-------- Not used in 4 bit mode
|
||||
// 9 - Data 2 (db2) |
|
||||
// 10 - Data 3 (db3) ----
|
||||
// 11 - Data 4 (db4)
|
||||
// 12 - Data 5 (db5)
|
||||
// 13 - Data 6 (db6)
|
||||
// 14 - Data 7 (db7)
|
||||
// 15 - Backlight Anode (+5v)
|
||||
// 16 - Backlight Cathode (Gnd)
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// LiquidCrystal compability:
|
||||
// Since hd44780 is LiquidCrystal API compatible, most existing LiquidCrystal
|
||||
// sketches should work with hd44780 hd44780_pinIO i/o class once the
|
||||
// includes are changed to use hd44780 and the lcd object constructor is
|
||||
// changed to use the hd44780_pinIO class.
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_pinIO.h> // Arduino pin i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
// Note: this can be with or without backlight control:
|
||||
|
||||
// without backlight control:
|
||||
// The parameters used by hd44780_pinIO are the same as those used by
|
||||
// the IDE bundled LiquidCrystal library
|
||||
// note that ESP8266 based arduinos must use the Dn defines rather than
|
||||
// raw pin numbers.
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
// esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7;
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// esp32 espduino32 D1 R32 (uno form factor)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14;
|
||||
#else
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // for all other devices
|
||||
#endif
|
||||
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
//with backlight control:
|
||||
// backlight control requires two additional parameters
|
||||
// - an additional pin to control the backlight
|
||||
// - backlight active level which tells the library the level
|
||||
// needed to turn on the backlight.
|
||||
// note: If the backlight control pin supports PWM, dimming can be done
|
||||
// using setBacklight(dimvalue);
|
||||
//
|
||||
// WARNING: some lcd keypads have a broken backlight circuit
|
||||
// If you have a lcd keypad, it is recommended that you first run the
|
||||
// LCDKeypadCheck sketch to verify that the backlight circuitry
|
||||
// is ok before enabling backlight control.
|
||||
// However, the hd44780_PinIO class will autodetect the issue and
|
||||
// work around it in s/w. If the backlight circuitry is broken,
|
||||
// dimming will not be possible even if the backlight pin supports PWM.
|
||||
//
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
// esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
//const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7, bl=D10, blLevel=HIGH;
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// esp32 espduino32 D1 R32 (uno form factor)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
// Dimming will not work on esp32 as it does not have analogWrite()
|
||||
//const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14, bl=5, blLevel=HIGH;
|
||||
#else
|
||||
//const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7, bl=10, blLevel=HIGH;
|
||||
#endif
|
||||
//hd44780_pinIO lcd(rs, en, db4, db5, db6, db7, bl, blLevel);
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// initialize LCD with number of columns and rows:
|
||||
//
|
||||
// note:
|
||||
// begin() will automatically turn on the backlight if backlight
|
||||
// control is specified in the lcd object constructor
|
||||
//
|
||||
lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
|
||||
// if backlight control was specified, the backlight should be on now
|
||||
|
||||
// Print a message to the LCD
|
||||
lcd.print("Hello, World!");
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
@@ -0,0 +1,385 @@
|
||||
static const int dummyvar = 0; // dummy declaration for older broken IDEs!!!!
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDCustomChars - simple demonstration of lcd custom characters
|
||||
// Created by Bill Perry 2016-10-06
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCDs that are directly controlled with Arduino pins.
|
||||
//
|
||||
// Sketch demonstrates how to assign custom characters to the eight hd44780
|
||||
// custom character codepoints and how to display on the LCD using
|
||||
// write() and print()
|
||||
//
|
||||
// You can create your own custom characters.
|
||||
// Here are a couple of web pages that have a tool that will generate the data
|
||||
// values needed for custom character.
|
||||
// https://kakedev.github.io/GlyphGenerator/
|
||||
// http://www.quinapalus.com/hd44780udg.html
|
||||
// https://omerk.github.io/lcdchargen
|
||||
//
|
||||
// See below for configuring the Arduino pins used.
|
||||
//
|
||||
// While not all hd44780 use the same pinout, here is the one that most use:
|
||||
// pin 1 is the pin closest to the edge of the PCB
|
||||
// 1 - LCD gnd
|
||||
// 2 - VCC (5v)
|
||||
// 3 - Contrast Voltage (Vo) (use center pin of contrast pot)
|
||||
// 4 - Register Select (rs)
|
||||
// 5 - Read/Write
|
||||
// 6 - Enable (en)
|
||||
// 7 - Data 0 (db0) ----
|
||||
// 8 - Data 1 (db1) |-------- Not used in 4 bit mode
|
||||
// 9 - Data 2 (db2) |
|
||||
// 10 - Data 3 (db3) ----
|
||||
// 11 - Data 4 (db4)
|
||||
// 12 - Data 5 (db5)
|
||||
// 13 - Data 6 (db6)
|
||||
// 14 - Data 7 (db7)
|
||||
// 15 - Backlight Anode (+5v)
|
||||
// 16 - Backlight Cathode (Gnd)
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// LiquidCrystal compability:
|
||||
// Since hd44780 is LiquidCrystal API compatible, most existing LiquidCrystal
|
||||
// sketches should work with hd44780 hd44780_pinIO i/o class once the
|
||||
// includes are changed to use hd44780 and the lcd object constructor is
|
||||
// changed to use the hd44780_pinIO class.
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_pinIO.h> // Arduino pin i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
// Note: this can be with or without backlight control:
|
||||
|
||||
// without backlight control:
|
||||
// The parameters used by hd44780_pinIO are the same as those used by
|
||||
// the IDE bundled LiquidCrystal library
|
||||
// note that ESP8266 based arduinos must use the Dn defines rather than
|
||||
// raw pin numbers.
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14; // esp32 espduino32 D1 R32 (uno form factor)
|
||||
#else
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // for all other devices
|
||||
#endif
|
||||
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
//with backlight control:
|
||||
// backlight control requires two additional parameters
|
||||
// - an additional pin to control the backlight
|
||||
// - backlight active level which tells the library the level
|
||||
// needed to turn on the backlight.
|
||||
// note: If the backlight control pin supports PWM, dimming can be done
|
||||
// using setBacklight(dimvalue);
|
||||
//
|
||||
// WARNING: some lcd keypads have a broken backlight circuit
|
||||
// If you have a lcd keypad, it is recommended that you first run the
|
||||
// LCDKeypadCheck sketch to verify that the backlight circuitry
|
||||
// is ok before enabling backlight control.
|
||||
// However, the hd44780_PinIO class will autodetect the issue and
|
||||
// work around it in s/w. If the backlight circuitry is broken,
|
||||
// dimming will not be possible even if the backlight pin supports PWM.
|
||||
//
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
// esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
//const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7, bl=D10, blLevel=HIGH;
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// esp32 espduino32 D1 R32 (uno form factor)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
// Dimming will not work on esp32 as it does not have analogWrite()
|
||||
//const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14, bl=5, blLevel=HIGH;
|
||||
#else
|
||||
//const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7, bl=10, blLevel=HIGH;
|
||||
#endif
|
||||
//hd44780_pinIO lcd(rs, en, db4, db5, db6, db7, bl, blLevel);
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
const int LongDelay = 5000;
|
||||
const int ShortDelay = 800;
|
||||
|
||||
int customcharRow = 1; // default to printing custom chars on row 1
|
||||
|
||||
// Below are some custom characters for demonstration
|
||||
|
||||
// You can ensure that the data for these custom characters is only
|
||||
// in flash and not in RAM by using the const qualifier.
|
||||
// However....
|
||||
// If using the AVR part, the AVR proprietary PROGMEM directive must be used.
|
||||
// PROGMEM is only required on AVR parts since the AVR parts cannot directly
|
||||
// access const data stored in flash like all the other processors.
|
||||
// PROGMEM is an AVR specific proprietary kludge that tells the linker and
|
||||
// startup code to handle the data differently.
|
||||
// PROGMEM is only used by the AVR and not required by any other processor.
|
||||
//
|
||||
// Most non AVR cores provide AVR compatibilty by providing support (emulation)
|
||||
// for the AVR proprietary PROGMEM directive and corresponding access functions,
|
||||
// but some do not.
|
||||
//
|
||||
// Because of this AVR const data and PROGMEM issue, there is no way to
|
||||
// guarantee code portability across all cores when using const data.
|
||||
//
|
||||
//
|
||||
// the hd44780 library assumes that if a const qualifier is used on the AVR
|
||||
// processor that the data has been stored in flash using the PROGMEM directive.
|
||||
// There is no way for the hd44780 library to know or detect if PROGMEM has
|
||||
// been used.
|
||||
// So if the const qualifer is used but the PROGMEM directive is not used on
|
||||
// an AVR processor, the custom char will be garbage.
|
||||
//
|
||||
// Examples:
|
||||
// For all processors other than AVR:
|
||||
// const char bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const uint8_ bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
//
|
||||
// For AVR: (and non AVR cores that have AVR PROGMEM emulation)
|
||||
// const char bell[8] PROGMEM = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const uint8_t bell[8] PROGMEM = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// OR
|
||||
// const PROGMEM char bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// const PROGMEM uint8_t bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
// NOTE:
|
||||
// if PROGMEM is used on older AVR compilers it generates a warning.
|
||||
//
|
||||
|
||||
uint8_t bell[8] = {0x04,0x0e,0x0e,0x0e,0x1f,0x00,0x04,0x00};
|
||||
uint8_t note[8] = {0x02,0x03,0x02,0x0e,0x1e,0x0c,0x00,0x00};
|
||||
uint8_t clockface[8] = {0x00,0x0e,0x15,0x17,0x11,0x0e,0x00,0x00};
|
||||
uint8_t heart[8] = {0x00,0x0a,0x1f,0x1f,0x0e,0x04,0x00,0x00};
|
||||
uint8_t duck[8] = {0x00,0x0c,0x1d,0x0f,0x0f,0x06,0x00,0x00};
|
||||
uint8_t check[8] = {0x00,0x01,0x03,0x16,0x1c,0x08,0x00,0x00};
|
||||
uint8_t cross[8] = {0x00,0x1b,0x0e,0x04,0x0e,0x1b,0x00,0x00};
|
||||
uint8_t smile[8] = {0x00,0x0a,0x0a,0x00,0x00,0x11,0x0e,0x00};
|
||||
|
||||
uint8_t degreeSymbol[8]= {0x06,0x09,0x09,0x06,0x00,0x00,0x00,0x00};
|
||||
uint8_t degreeC[8] = {0x18,0x18,0x03,0x04,0x04,0x04,0x03,0x00};
|
||||
uint8_t degreeF[8] = {0x18,0x18,0x07,0x04,0x07,0x04,0x04,0x00};
|
||||
|
||||
const PROGMEM uint8_t vsigbar[][8] = {
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0 bars, same as <space>
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x1F}, // 1 bars
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x00,0x1F,0x1F}, // 2 bars
|
||||
{0x00, 0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F}, // 3 bars
|
||||
{0x00, 0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F}, // 4 bars
|
||||
{0x00, 0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x1F}, // 5 bars
|
||||
{0x00, 0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 6 bars
|
||||
{0x00, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 7 bars
|
||||
{0x1F, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, // 8 bars
|
||||
};
|
||||
|
||||
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
|
||||
{
|
||||
// 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
|
||||
}
|
||||
void loop(void)
|
||||
{
|
||||
lcd.clear();
|
||||
|
||||
lcd.print("Custom Chars");
|
||||
|
||||
// create custom characters
|
||||
// int rval = createChar(charval, charmap[]);
|
||||
//
|
||||
// createChar() creates a custom character
|
||||
// for the character at the charval codepoint.
|
||||
// It returns zero if successful.
|
||||
//
|
||||
// to display the custom character, simply call write()
|
||||
// with the charval use in createChar()
|
||||
//
|
||||
// The display must be initialized *before* you attempt
|
||||
// to create custom characters.
|
||||
//
|
||||
// Note: On hd44780 displays there are 8 custom characters.
|
||||
// They are assigned to character codepoint values 0x00 to 0x07
|
||||
// The codepoints 0x08 to 0x0f are duplicates for 0x00 to 0x07
|
||||
// i.e. 0x08 is the same as 0x00, 0x09 same as 0x01, etc...
|
||||
|
||||
// create 8 custom characters
|
||||
lcd.createChar(0, bell);
|
||||
lcd.createChar(1, note);
|
||||
lcd.createChar(2, clockface);
|
||||
lcd.createChar(3, heart);
|
||||
lcd.createChar(4, duck);
|
||||
lcd.createChar(5, check);
|
||||
lcd.createChar(6, cross);
|
||||
lcd.createChar(7, smile);
|
||||
|
||||
// prepare to display the custom characters
|
||||
// on multi line displays the custom characters will be
|
||||
// displayed on the 2nd line
|
||||
// on single line displays, delay a bit to see the initial display,
|
||||
// then clear the display to display the custom characters on the top line
|
||||
if(LCD_ROWS < 2)
|
||||
{
|
||||
customcharRow = 0;
|
||||
delay(LongDelay);
|
||||
lcd.clear();
|
||||
}
|
||||
|
||||
lcd.setCursor(0, customcharRow);
|
||||
|
||||
// write() or print() can be used to display custom characters.
|
||||
//
|
||||
// To use write() pass the charval of the desired custom character.
|
||||
// lcd.write(charval);
|
||||
// NOTE:
|
||||
// The Print class has an issue that does not allow 0 (zero) to be used
|
||||
// on write() without casting it. The Arduino team refuses to fix this.
|
||||
// hd44780 has a work around in it to remove this issue so you can call
|
||||
// write() with a constant value of 0 without having to cast it.
|
||||
//
|
||||
// write() can also be used with literal characters that contain
|
||||
// an octal (base 8) escape seuence.
|
||||
// lcd.write('\###');
|
||||
//
|
||||
// To use print() pass in the charval of the desired custom character
|
||||
// as a character *not* an integer.
|
||||
// This requires using a literal character with an octal escape sequence.
|
||||
// lcd.print('\###');
|
||||
//
|
||||
|
||||
// Since both write() & print() both accept octal escaped literal characters
|
||||
// it is the most compatible & portable way of sending custom characters
|
||||
|
||||
// display all 8 custom characters.
|
||||
|
||||
// write() with character codepoint values
|
||||
lcd.write(0); // casting to an uint8_t or byte not needed with hd44780
|
||||
lcd.write(1);
|
||||
|
||||
// write() & print() with octal escaped literal characters
|
||||
lcd.write('\002'); // this is an octal escaped literal character
|
||||
lcd.write('\003'); // this is an octal escaped literal character
|
||||
lcd.print('\004'); // this is an octal escaped literal character
|
||||
lcd.print('\005'); // this is an octal escaped literal character
|
||||
|
||||
// can also drop the leading zeros on small litereal values like these
|
||||
lcd.print('\06'); // this is an octal escaped literal character
|
||||
lcd.print('\7'); // this is an octal escaped literal character
|
||||
|
||||
delay(LongDelay);
|
||||
|
||||
// You can also insert custom character codepoints into C strings.
|
||||
// To do so, insert the character codepoint value as an octal constant.
|
||||
// However,
|
||||
// because zero indicates the end of string in C you cannot use zero.
|
||||
// Example:
|
||||
// lcd.print("charval #1: \001"); // prints custom character at codepoint 1
|
||||
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code1: \001");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code2: \002");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code3: \003");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code4: \004");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code5: \005");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code6: \006");
|
||||
delay(ShortDelay);
|
||||
|
||||
lcd.setCursor(0,customcharRow);
|
||||
lcd.print("code7: \007");
|
||||
delay(ShortDelay);
|
||||
|
||||
// Another nifty trick is that you can modify custom characters on the
|
||||
// display without having to re-write the characters on the display.
|
||||
// To do this, simply create a new character for a codepoint.
|
||||
// All characters on the display which have that codepoint will "magically"
|
||||
// change to the new custom character.
|
||||
// So for example, if the entire display was written with custom character
|
||||
// zero and character zero was a bell, if you called createChar() to
|
||||
// redefine character codepoint zero to be a duck,
|
||||
// the entire display would turn to ducks without having to send any
|
||||
// characters to the display.
|
||||
|
||||
// create the initial custom character
|
||||
lcd.createChar(0, bell);
|
||||
|
||||
// fill the custom character line with the custom character.
|
||||
lcd.setCursor(0,customcharRow);
|
||||
for(uint8_t col=0; col<LCD_COLS; col++)
|
||||
lcd.write(0);
|
||||
|
||||
delay(ShortDelay);
|
||||
|
||||
// change the single custom character previously written on the row
|
||||
// and all the characters on the row will change
|
||||
// without having to re-write the characters.
|
||||
lcd.createChar(0, note);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, clockface);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, heart);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, duck);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, check);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, cross);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, smile);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeSymbol);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeC);
|
||||
delay(ShortDelay);
|
||||
lcd.createChar(0, degreeF);
|
||||
delay(ShortDelay);
|
||||
|
||||
// show multiple vertical bars rising
|
||||
// by changing the single custom character that is already written
|
||||
// to the entire row on the display
|
||||
for(int i = 0; i < 9; i++)
|
||||
{
|
||||
lcd.createChar(0, vsigbar[i]);
|
||||
delay(ShortDelay);
|
||||
}
|
||||
|
||||
delay(LongDelay);
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
//
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDKeypadCheck - LCD keypad shield backlight circuitry test
|
||||
// Copyright 2013-2020 Bill Perry
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// LCDKeypadCheck 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.
|
||||
//
|
||||
// LCDKeypadCheck 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 LCDKeypadCheck. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// sketch to test lcd keypad shields for bad backlight circuitry
|
||||
//
|
||||
// See this Arduino forum thread for a discussion about the isue:
|
||||
// http://forum.arduino.cc//index.php?topic=96747
|
||||
//
|
||||
// NOTE:
|
||||
// As of 2016-11-12 in release 0.8.1 the hd44780_pinIO class now
|
||||
// automatically detects broken backlight circuits and will use backlight
|
||||
// control methods to protect the Arduino processor. The sketch can simply
|
||||
// use all the backlight API functions setbacklight(), backlight(), and
|
||||
// noBacklight() without concern.
|
||||
//
|
||||
// To use this sketch, fill in the proper pin assignements if they are
|
||||
// different from below.
|
||||
//
|
||||
// upload the sketch.
|
||||
// The LCD display will show whether the backlight circuit is good/bad.
|
||||
//
|
||||
// If the LCD shows that the backlight circuit is bad,
|
||||
// it means that the backlight control circuit on the shield is a bad design
|
||||
// and has a short circuit issue on the Arduino pin that controls the
|
||||
// backlight circuit. (usually digital pin 10)
|
||||
// This means that you need to be careful not to ever set the backlight control
|
||||
// pin (D10) to HIGH as the high current draw could damage the Arduino processor.
|
||||
//
|
||||
// All is not lost, the shield can still be used and the backlight can still
|
||||
// be controlled. Just keep in mind that unless the hardware is
|
||||
// modified, some precautions must be taken when controlling the backlight.
|
||||
// The main thing is that backlight control pin (digital pin 10) should
|
||||
// never be set to HIGH.
|
||||
// This means that PWM or analogWrite() cannot be used to dim the backlight.
|
||||
//
|
||||
// If you are happy with the backlight on all the time, then nothing needs to
|
||||
// be done and you can use the LCD without backlight control.
|
||||
//
|
||||
// A simple software only solution for backlight on/off control
|
||||
// is to set the backlight pin to INPUT to turn on the backlight and set the
|
||||
// backlight pin to OUTPUT mode to turn the backlight off.
|
||||
// If using hd44780 library 0.8.1 or newer the library will automatically
|
||||
// do this for the sketch when the backlight API functions are used.
|
||||
//
|
||||
// History
|
||||
// 2018.09.18 bperrybap - updated comments to clarify what
|
||||
// "BL Circuit BAD" means
|
||||
// 2017.01.07 bperrybap - updated comments to reflect that library now
|
||||
// automatically detects bad backlight circuits
|
||||
// 2016.11.08 bperrybap - updated for inclusion in hd44780 library
|
||||
// 2013.10.29 bperrybap - Original creation
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_pinIO.h> // Arduino pin i/o class header
|
||||
|
||||
// initialize the library with the numbers of the interface pins
|
||||
// note that ESP8266 based arduinos must use the Dn defines rather than
|
||||
// raw pin numbers.
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // for esp8266 devices
|
||||
const int pin_BL = D10; // arduino pin wired to LCD backlight circuit
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// esp32 espduino32 D1 R32 (uno form factor)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14;
|
||||
const int pin_BL=5; // gpio pin # wired to LCD backlight circuit
|
||||
#else
|
||||
const int rs = 8; // arduino pin wired to LCD RS
|
||||
const int en = 9; // arduino pin wired to LCD EN
|
||||
const int db4 = 4;// arduino pin wired to LCD db4
|
||||
const int db5 = 5;// arduino pin wired to LCD db5
|
||||
const int db6 = 6;// arduino pin wired to LCD db6
|
||||
const int db7 = 7;// arduino pin wired to LCD db7
|
||||
const int pin_BL = 10; // arduino pin wired to LCD backlight circuit
|
||||
#endif
|
||||
|
||||
hd44780_pinIO lcd( rs, en, db4, db5, db6, db7);
|
||||
|
||||
|
||||
/*
|
||||
* Macros to safely turn on the backlight even with back BL hardware
|
||||
* These assume that the BL pin is not touched or used after RESET other
|
||||
* than by these macros.
|
||||
*/
|
||||
|
||||
#define SafeBLon(pin) pinMode(pin, INPUT)
|
||||
#define SafeBLoff(pin) pinMode(pin, OUTPUT)
|
||||
|
||||
int status;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
|
||||
status = pinTest(pin_BL); // only run the actual test once
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
lcd.clear();
|
||||
if(status)
|
||||
{
|
||||
/*
|
||||
* Shield has BL circuit issue
|
||||
*/
|
||||
lcd.print("BL Circuit BAD");
|
||||
safeBlink(pin_BL, 5); // safely blink the backlight
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Shield is OK (no BL circuit issue)
|
||||
*/
|
||||
lcd.print("BL Circuit GOOD");
|
||||
softBlink(pin_BL, 2); // soft blink the backlight (uses PWM)
|
||||
}
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function to test a backlight pin
|
||||
* Returns non-zero if test fails (bad circuit design)
|
||||
*/
|
||||
int pinTest(int pin)
|
||||
{
|
||||
int val;
|
||||
|
||||
/*
|
||||
* Check to see if there
|
||||
* is a problem in the backlight circuit
|
||||
* So far, the "broken" designs connected D10
|
||||
* directly to the base of a NPN transistor,
|
||||
* this will cause a short when D10 is set to HIGH
|
||||
* as there is no current limiting resistor in the path
|
||||
* between D10 to the base and the emitter to ground.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Set the pin to an input with pullup disabled.
|
||||
* This should be safe on all shields.
|
||||
* The reason for the digitalWrite() first is that
|
||||
* only the newer Arduino cores disable the pullup
|
||||
* when setting the pin to INPUT.
|
||||
* On boards that have a pullup on the transistor base,
|
||||
* this should cause the backlight to be on.
|
||||
*/
|
||||
digitalWrite(pin, LOW);
|
||||
pinMode(pin, INPUT);
|
||||
|
||||
/*
|
||||
* Set the backlight pin to an output.
|
||||
* since the pullup was turned off above by
|
||||
* setting the pin to input mode,
|
||||
* it should drive the pin LOW which should
|
||||
* be safe given the known design flaw.
|
||||
*/
|
||||
pinMode(pin, OUTPUT);
|
||||
|
||||
|
||||
/*
|
||||
* Set the backlight pin to HIGH
|
||||
* NOTE: This is NOT a safe thing to do
|
||||
* on the broken designs. The code will minimize
|
||||
* the time this is done to prevent any potential damage.
|
||||
*/
|
||||
|
||||
digitalWrite(pin, HIGH);
|
||||
|
||||
|
||||
/*
|
||||
* Now read back the pin value to
|
||||
* See if a short is pulling down the HIGH output.
|
||||
*/
|
||||
|
||||
delayMicroseconds(5); // give some time for the signal to droop
|
||||
|
||||
val = digitalRead(pin); // read the level on the pin
|
||||
|
||||
/*
|
||||
* Restore the pin to a safe state
|
||||
* Input with pullup turned off
|
||||
*/
|
||||
digitalWrite(pin, LOW);
|
||||
pinMode(pin, INPUT);
|
||||
|
||||
/*
|
||||
* If the level read back is not HIGH
|
||||
* Then there is a problem because the pin is
|
||||
* being driven HIGH by the Arduino processor.
|
||||
*/
|
||||
if (val != HIGH)
|
||||
return(-1); // test failed
|
||||
else
|
||||
return(0); // all is ok.
|
||||
}
|
||||
|
||||
void safeBlink(int pin, int count)
|
||||
{
|
||||
/*
|
||||
* Safely blink the backlight on LCD shields that have
|
||||
* broken BL hardware
|
||||
* Uses the SafeBL macros defined above.
|
||||
*/
|
||||
|
||||
while(count--)
|
||||
{
|
||||
delay(200);
|
||||
SafeBLoff(pin); // turn on the backlight (safe to use for all shields)
|
||||
delay(50);
|
||||
SafeBLon(pin); // turn off the backlight (safe to use for all shields)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* soft blink the backlight.
|
||||
* NOTE: this should not be used on a shield
|
||||
* with a bad backlight circuit
|
||||
*/
|
||||
void softBlink(int pin, int count)
|
||||
{
|
||||
// note: esp32 core does not support analogWrite()
|
||||
#if !defined(ARDUINO_ARCH_ESP32)
|
||||
// soft blink the backlight by ramping down then back up
|
||||
pinMode(pin, OUTPUT);
|
||||
for(int times = 0; times < count; times++)
|
||||
{
|
||||
for(int x = 1; x < 16; x++)
|
||||
{
|
||||
analogWrite(pin, 256-x * 16);
|
||||
delay(50);
|
||||
}
|
||||
for(int x = 1; x < 16; x++)
|
||||
{
|
||||
analogWrite(pin, x * 16);
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// LineWrap - simple demonstration of automatic linewrap functionality
|
||||
// Created by Bill Perry 2017-05-10
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCDs that are directly controlled with Arduino pins.
|
||||
//
|
||||
// Sketch demonstrates hd44780 library automatic line wrapping functionality.
|
||||
//
|
||||
// Background:
|
||||
// hd44780 LCDs do not use linear continuous memory for the characters
|
||||
// on the lines on the display.
|
||||
// This means that simply sending continuous characters to the
|
||||
// display will not fill lines and wrap appropriately as might be expected.
|
||||
// The hd44780 library solves this issue by adding a line wrapping capability
|
||||
// in s/w that can be enabled & disabled.
|
||||
// This allows the host to send characters to the display continuously and they
|
||||
// will wrap to the next lower line when the end of the visible line has been
|
||||
// reached. When on the bottom line it will wrap back to the top line.
|
||||
//
|
||||
// (Configure LCD_COLS & LCD_ROWS if desired/needed)
|
||||
// Expected behavior of the sketch:
|
||||
// - display a banner announcing the test.
|
||||
// - print the configured LCD geometry
|
||||
// - print a long text string to demostrate automatic line wrapping
|
||||
// - print lots of characters (slowly) to show how the full wrapping works.
|
||||
// (loop)
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED with the initalization error
|
||||
// code.
|
||||
//
|
||||
// Special note for certain 16x1 displays:
|
||||
// Some 16x1 displays are actually a 8x2 display that have both lines on
|
||||
// a single line on the display.
|
||||
// If you have one of these displays, simply set the geometry to 8x2 instead
|
||||
// of 16x1.
|
||||
// In normal sketches, lineWrap() mode will allow this type of display to
|
||||
// properly function as a 16x1 display in that it will allow printing up to
|
||||
// 16 characters on the display without having to manually set the cursor
|
||||
// position to print the right characters on the half of the display.
|
||||
// However, when using this 8x2 display as a 16x1 display,
|
||||
// scrollDisplayLeft() and scrollDisplayRight() will not work as intended.
|
||||
// They will shift the two halves of the display rather than the entire display.
|
||||
// This is because the hd44780 chip is doing the shift and chip is hard coded
|
||||
// internally for two lines.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// While not all hd44780 use the same pinout, here is the one that most use:
|
||||
// pin 1 is the pin closest to the edge of the PCB
|
||||
// 1 - LCD gnd
|
||||
// 2 - VCC (5v)
|
||||
// 3 - Vo Contrast Voltage
|
||||
// 4 - RS Register Select (rs)
|
||||
// 5 - Read/Write
|
||||
// 6 - Enable (en)
|
||||
// 7 - Data 0 (db0) ----
|
||||
// 8 - Data 1 (db1) |-------- Not used in 4 bit mode
|
||||
// 9 - Data 2 (db2) |
|
||||
// 10 - Data 3 (db3) ----
|
||||
// 11 - Data 4 (db4)
|
||||
// 12 - Data 5 (db5)
|
||||
// 13 - Data 6 (db6)
|
||||
// 14 - Data 7 (db7)
|
||||
// 15 - Backlight Anode (+5v)
|
||||
// 16 - Backlight Cathode (Gnd)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_pinIO.h> // Arduino pin i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
// Note: this can be with or without backlight control:
|
||||
|
||||
// without backlight control:
|
||||
// note that ESP8266 based arduinos must use the Dn defines rather than
|
||||
// raw pin numbers.
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14; // esp32 espduino32 D1 R32 (uno form factor)
|
||||
#else
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // for all other devices
|
||||
#endif
|
||||
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
//with backlight control:
|
||||
// backlight control requires two additional parameters
|
||||
// - an additional pin to control the backlight
|
||||
// - backlight active level which tells the library the level
|
||||
// needed to turn on the backlight.
|
||||
// note: If the backlight control pin supports PWM, dimming can be done
|
||||
// using setBacklight(dimvalue);
|
||||
//
|
||||
// WARNING: some lcd keypads have a broken backlight circuit
|
||||
// If you have a lcd keypad, it is recommended that you first run the
|
||||
// LCDKeypadCheck sketch to verify that the backlight circuitry
|
||||
// is ok before enabling backlight control.
|
||||
// However, the hd44780_PinIO class will autodetect the issue and
|
||||
// work around it in s/w. If the backlight circuitry is broken,
|
||||
// dimming will not be possible even if the backlight pin supports PWM.
|
||||
//
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
// esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
//const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7, bl=D10, blLevel=HIGH;
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// esp32 espduino32 D1 R32 (uno form factor)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
// Dimming will not work on esp32 as it does not have analogWrite()
|
||||
//const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14, bl=5, blLevel=HIGH;
|
||||
#else
|
||||
//const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7, bl=10, blLevel=HIGH;
|
||||
#endif
|
||||
//hd44780_pinIO lcd(rs, en, db4, db5, db6, db7, bl, blLevel);
|
||||
|
||||
// LCD geometry
|
||||
// while 16x2 will work on most displays even if the geometry is different,
|
||||
// for actual wrap testing of a particular LCD it is best to use the correct
|
||||
// geometry.
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
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>
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// begin() failed so blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// turn on automatic line wrapping
|
||||
// which automatically wraps lines to the next lower line and wraps back
|
||||
// to the top when at the bottom line
|
||||
// NOTE:
|
||||
// noLineWrap() can be used to disable automatic line wrapping.
|
||||
// _write() can be called instead of write() to send data bytes
|
||||
// to the display bypassing any special character or line wrap processing.
|
||||
lcd.lineWrap();
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("WrapTest");
|
||||
delay(2000);
|
||||
lcd.clear();
|
||||
|
||||
//print the configured LCD geometry
|
||||
lcd.print(LCD_COLS);
|
||||
lcd.print("x");
|
||||
lcd.print(LCD_ROWS);
|
||||
delay(3000);
|
||||
lcd.clear();
|
||||
|
||||
// print a long text string
|
||||
// without line wrapping enabled, the text would not wrap properly
|
||||
// to the next line.
|
||||
|
||||
if(LCD_COLS == 8)
|
||||
lcd.print("A long text line");
|
||||
else
|
||||
lcd.print("This is a very long line of text");
|
||||
delay(3000);
|
||||
|
||||
lcd.clear();
|
||||
|
||||
// now print 2 full displays worth of characters to show
|
||||
// the full wrapping.
|
||||
|
||||
lcd.cursor(); // turn on cursor so you can see where it is
|
||||
|
||||
char c = '0'; // start at the character for the number zero
|
||||
for(int i = 2*LCD_COLS*LCD_ROWS; i; i--)
|
||||
{
|
||||
lcd.print(c++);
|
||||
delay(200); // slow things down to watch the printing & wrapping
|
||||
|
||||
if(c > 0x7e) // wrap back to beginning of printable ASCII chars
|
||||
c = '!';
|
||||
}
|
||||
delay(3000);
|
||||
lcd.noCursor(); // turn off cursor
|
||||
}
|
||||
33
libraries/hd44780/examples/ioClass/hd44780_pinIO/README.md
Normal file
33
libraries/hd44780/examples/ioClass/hd44780_pinIO/README.md
Normal file
@@ -0,0 +1,33 @@
|
||||
hd44780_pinIO examples
|
||||
=======================
|
||||
|
||||
The examples included in this directory are for the hd44780_pinIO i/o class.<br>
|
||||
The hd44780_pinIO i/o class is used to control an LCD using direct Arduino pin connections.
|
||||
|
||||
#### The following examples are included:
|
||||
|
||||
- `HelloWorld`<br>
|
||||
Prints "Hello, World!" on the lcd
|
||||
|
||||
- `LCDKeypadCheck`<br>
|
||||
Tests lcd keypad shields for bad backlight circuitry
|
||||
|
||||
- `LCDCustomChars`<br>
|
||||
Demonstrates using custom characters
|
||||
|
||||
- `LineWrap`<br>
|
||||
Demonstrates automatic linewrap functionality
|
||||
|
||||
- `ReadWrite`<br>
|
||||
Demonstrate the ability to read data from the LCD.
|
||||
|
||||
- `Serial2LCD`<br>
|
||||
Displays a message read from the serial port on the lcd.
|
||||
|
||||
- `UpTime`<br>
|
||||
Prints the amount of time since the Arduino has been reset.
|
||||
|
||||
- `hd44780examples`<br>
|
||||
The hd44780examples subdirectory contains
|
||||
hd44780_pinIO class specific wrapper sketches for sketches under
|
||||
examples/hd44780examples.
|
||||
@@ -0,0 +1,195 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// ReadWrite - simple demonstration reading data from LCD
|
||||
// Created by Bill Perry 2016-08-19
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCDs that are directly controlled with Arduino pins.
|
||||
//
|
||||
// The purpose of the sketch is demonstrate the ability to read data from
|
||||
// the LCD. As such, it requires an extra Arduino pin to control the R/W LCD
|
||||
// pin. See below for configuring the Arduino pins used.
|
||||
//
|
||||
// Sketch will print the amount of time since the Arduino has been reset
|
||||
// on the top row and then read the data from the LCD to print it on the
|
||||
// second row
|
||||
//
|
||||
// If there are errors and the arduino supports a built in LED,
|
||||
// an error status code will blink on the built in LED.
|
||||
// Error codes:
|
||||
// (1) lcd device initalization failed
|
||||
// (2) lcd device does not support reads
|
||||
// (3) error reading data from lcd device
|
||||
// (4) error writing data to lcd device
|
||||
// (5) read data mismatch
|
||||
//
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_pinIO.h> // Arduino pin i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
// Note: this can be with or without backlight control:
|
||||
|
||||
// without backlight control:
|
||||
// note that ESP8266 based arduinos must use the Dn defines rather than
|
||||
// raw pin numbers.
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, rw=A0, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
const int rs=12, rw=A0, en=13, db4=17, db5=16, db6=27, db7=14; // esp32 espduino32 D1 R32 (uno form factor)
|
||||
#else
|
||||
const int rs=8, rw=A0, en=9, db4=4, db5=5, db6=6, db7=7; // for all other devices
|
||||
#endif
|
||||
hd44780_pinIO lcd(rs, rw, en, db4, db5, db6, db7);
|
||||
|
||||
//with backlight control:
|
||||
// backlight control requires two additional parameters
|
||||
// - an additional pin to control the backlight
|
||||
// - backlight active level which tells the library the level
|
||||
// needed to turn on the backlight.
|
||||
// note: If the backlight control pin supports PWM, dimming can be done
|
||||
// using setBacklight(dimvalue);
|
||||
//
|
||||
// WARNING: some lcd keypads have a broken backlight circuit
|
||||
// If you have a lcd keypad, it is recommended that you first run the
|
||||
// LCDKeypadCheck sketch to verify that the backlight circuitry
|
||||
// is ok before enabling backlight control.
|
||||
// However, the hd44780_PinIO class will autodetect the issue and
|
||||
// work around it in s/w. If the backlight circuitry is broken,
|
||||
// dimming will not be possible even if the backlight pin supports PWM.
|
||||
//
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
// esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
//const int rs=D8, rw=A0, en=D9, db4=D4, db5=D5, db6=D6, db7=D7, bl=D10, blLevel=HIGH;
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// esp32 espduino32 D1 R32 (uno form factor)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
// Dimming will not work on esp32 as it does not have analogWrite()
|
||||
//const int rs=12, rw=A0, en=13, db4=17, db5=16, db6=27, db7=14, bl=5, blLevel=HIGH;
|
||||
#else
|
||||
//const int rs=8, rw=A0, en=9, db4=4, db5=5, db6=6, db7=7, bl=10, blLevel=HIGH;
|
||||
#endif
|
||||
//hd44780_pinIO lcd(rs, rw, en, db4, db5, db6, db7, bl, blLevel);
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_ROWS = 2;
|
||||
const int LCD_COLS = 16;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// initialize LCD with number of columns and rows:
|
||||
if( lcd.begin(LCD_COLS, LCD_ROWS))
|
||||
{
|
||||
// begin() failed so blink the onboard LED if possible
|
||||
fatalError(1);
|
||||
}
|
||||
|
||||
// check to see if device can read by attempting to read
|
||||
// the lcd status register. If it fails then assume it was
|
||||
// because the lcd device does not support reads.
|
||||
if(lcd.status() < 0)
|
||||
{
|
||||
lcd.print("No Read Support");
|
||||
fatalError(2);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static unsigned long lastsecs = -1; // pre-initialize with non zero value
|
||||
unsigned long secs;
|
||||
|
||||
secs = millis() / 1000;
|
||||
|
||||
// see if 1 second has passed
|
||||
// so the display is only updated once per second
|
||||
if(secs != lastsecs)
|
||||
{
|
||||
lastsecs = secs; // keep track of last seconds
|
||||
|
||||
// set the cursor position to top line: column 0, row 0
|
||||
lcd.setCursor(0, 0);
|
||||
|
||||
// print uptime on lcd device: (time since last reset)
|
||||
PrintUpTime(lcd, secs);
|
||||
|
||||
// Now copy the characters from the top line to the 2nd line
|
||||
// This is done character by character by:
|
||||
// - setting the character position to read
|
||||
// - reading a character
|
||||
// - setting the character position to write
|
||||
// - writing the charcter read
|
||||
for(int col = 0; col < LCD_COLS; col++)
|
||||
{
|
||||
int c;
|
||||
|
||||
lcd.setCursor(col, 0);
|
||||
if((c = lcd.read()) < 0) // if a read error, bomb out
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("read fail");
|
||||
fatalError(3);
|
||||
}
|
||||
|
||||
// check for ':' characters in col 2 and 5
|
||||
// if not there, consider it a fatal read error
|
||||
if((col == 2 || col == 5) && c != ':')
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("read fail");
|
||||
fatalError(5);
|
||||
}
|
||||
|
||||
lcd.setCursor(col, 1);
|
||||
if(lcd.write((uint8_t) c) != 1)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("write fail");
|
||||
fatalError(4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PrintUpTime(outdev, secs) - print uptime in HH:MM:SS format
|
||||
// outdev - the device to send output
|
||||
// secs - the total number of seconds uptime
|
||||
void PrintUpTime(Print &outdev, unsigned long secs)
|
||||
{
|
||||
unsigned int hr, mins, sec;
|
||||
|
||||
// convert total seconds to hours, mins, seconds
|
||||
mins = secs / 60; // how many total minutes
|
||||
hr = mins / 60; // how many total hours
|
||||
mins = mins % 60; // how many minutes within the hour
|
||||
sec = secs % 60; // how many seconds within the minute
|
||||
|
||||
|
||||
// print uptime 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)
|
||||
outdev.write('0');
|
||||
outdev.print((int)hr);
|
||||
outdev.write(':');
|
||||
if(mins < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)mins);
|
||||
outdev.write(':');
|
||||
if(sec < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)sec);
|
||||
}
|
||||
|
||||
// fatalError() - loop & blink and error code
|
||||
void fatalError(int ecode)
|
||||
{
|
||||
hd44780::fatalError(ecode); // does not return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// Serial2LCD - simple demonstration printing characters from serial port
|
||||
// Created by Bill Perry 2020-06-28
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCDs that are directly controlled with Arduino pins.
|
||||
//
|
||||
// Sketch demonstrates hd44780 how to read a message of characters from
|
||||
// serial port and display it on the LCD.
|
||||
// It takes advantage of the hd44780 library automatic line
|
||||
// wrapping capability.
|
||||
// See the LineWrap sketch for details about line wrapping.
|
||||
//
|
||||
// Configure LCD_COLS, LCD_ROWS and BAUDRATE if desired/needed
|
||||
// Expected behavior of the sketch:
|
||||
// - characters received from serial port are displayed on LCD
|
||||
// - CR and LF are ignored/dropped
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED with the initalization error
|
||||
// code.
|
||||
//
|
||||
// Some 16x1 displays are actually a 8x2 display that have both lines on
|
||||
// a single line on the display.
|
||||
// If you have one of these displays, simply set the geometry to 8x2 instead
|
||||
// of 16x1.
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// pinout:
|
||||
// 1 - LCD gnd
|
||||
// 2 - VCC (5v)
|
||||
// 3 - not connected
|
||||
// 4 - RS Register Select (rs)
|
||||
// 5 - Read/Write
|
||||
// 6 - Enable (en)
|
||||
// 7 - Data 0 (db0) ----
|
||||
// 8 - Data 1 (db1) |-------- Not used in 4 bit mode
|
||||
// 9 - Data 2 (db2) |
|
||||
// 10 - Data 3 (db3) ----
|
||||
// 11 - Data 4 (db4)
|
||||
// 12 - Data 5 (db5)
|
||||
// 13 - Data 6 (db6)
|
||||
// 14 - Data 7 (db7)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_pinIO.h> // Arduino pin i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
// Note: this can be with or without backlight control:
|
||||
|
||||
// without backlight control:
|
||||
// note that ESP8266 based arduinos must use the Dn defines rather than
|
||||
// raw pin numbers.
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14; // esp32 espduino32 D1 R32 (uno form factor)
|
||||
#else
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // for all other devices
|
||||
#endif
|
||||
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
//with backlight control:
|
||||
// backlight control requires two additional parameters
|
||||
// - an additional pin to control the backlight
|
||||
// - backlight active level which tells the library the level
|
||||
// needed to turn on the backlight.
|
||||
// note: If the backlight control pin supports PWM, dimming can be done
|
||||
// using setBacklight(dimvalue);
|
||||
//
|
||||
// WARNING: some lcd keypads have a broken backlight circuit
|
||||
// If you have a lcd keypad, it is recommended that you first run the
|
||||
// LCDKeypadCheck sketch to verify that the backlight circuitry
|
||||
// is ok before enabling backlight control.
|
||||
// However, the hd44780_PinIO class will autodetect the issue and
|
||||
// work around it in s/w. If the backlight circuitry is broken,
|
||||
// dimming will not be possible even if the backlight pin supports PWM.
|
||||
//
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
// esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
//const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7, bl=D10, blLevel=HIGH;
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// esp32 espduino32 D1 R32 (uno form factor)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
// Dimming will not work on esp32 as it does not have analogWrite()
|
||||
//const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14, bl=5, blLevel=HIGH;
|
||||
#else
|
||||
//const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7, bl=10, blLevel=HIGH;
|
||||
#endif
|
||||
//hd44780_pinIO lcd(rs, en, db4, db5, db6, db7, bl, blLevel);
|
||||
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
const int BAUDRATE = 9600;
|
||||
|
||||
void setup()
|
||||
{
|
||||
int status;
|
||||
|
||||
// initalize Serial port
|
||||
Serial.begin(BAUDRATE);
|
||||
|
||||
// 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>
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// begin() failed
|
||||
|
||||
Serial.print("LCD initalization failed: ");
|
||||
Serial.println(status);
|
||||
|
||||
// blink error code using the onboard LED if possible
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// turn on automatic line wrapping
|
||||
// which automatically wraps lines to the next lower line and wraps back
|
||||
// to the top when at the bottom line
|
||||
// NOTE:
|
||||
// noLineWrap() can be used to disable automatic line wrapping.
|
||||
// _write() can be called instead of write() to send data bytes
|
||||
// to the display bypassing any special character or line wrap processing.
|
||||
lcd.lineWrap();
|
||||
|
||||
lcd.print("Serial2LCD");
|
||||
if(LCD_ROWS > 1)
|
||||
{
|
||||
lcd.setCursor(0,1);
|
||||
lcd.print("Baud:");
|
||||
lcd.print(BAUDRATE);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
// check to see if characters available
|
||||
// indicating a message is coming in
|
||||
if (Serial.available())
|
||||
{
|
||||
// wait some time for rest of message to arrive
|
||||
delay(100);
|
||||
|
||||
// Clear the display before showing the new message
|
||||
lcd.clear();
|
||||
|
||||
// print the message on the LCD
|
||||
while (Serial.available() > 0)
|
||||
{
|
||||
char c;
|
||||
c = Serial.read();
|
||||
if(c != '\r' && c != '\n') // drop CR and LF characters
|
||||
lcd.write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
// vi:ts=4
|
||||
// ----------------------------------------------------------------------------
|
||||
// UpTime - simple demonstration of lcd
|
||||
// Created by Bill Perry 2017-05-11
|
||||
// bperrybap@opensource.billsworld.billandterrie.com
|
||||
//
|
||||
// This example code is unlicensed and is released into the public domain
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// This sketch is for LCDs that are directly controlled with Arduino pins.
|
||||
//
|
||||
// Sketch will print "UpTime" on top row of lcd
|
||||
// and will print the amount of time since the Arduino has been reset
|
||||
// on the second row.
|
||||
//
|
||||
//
|
||||
// See below for configuring the Arduino pins used.
|
||||
//
|
||||
// If initialization of the LCD fails and the arduino supports a built in LED,
|
||||
// the sketch will simply blink the built in LED.
|
||||
//
|
||||
// While not all hd44780 use the same pinout, here is the one that most use:
|
||||
// pin 1 is the pin closest to the edge of the PCB
|
||||
// 1 - LCD gnd
|
||||
// 2 - VCC (5v)
|
||||
// 3 - Vo Contrast Voltage
|
||||
// 4 - RS Register Select (rs)
|
||||
// 5 - Read/Write
|
||||
// 6 - Enable (en)
|
||||
// 7 - Data 0 (db0) ----
|
||||
// 8 - Data 1 (db1) |-------- Not used in 4 bit mode
|
||||
// 9 - Data 2 (db2) |
|
||||
// 10 - Data 3 (db3) ----
|
||||
// 11 - Data 4 (db4)
|
||||
// 12 - Data 5 (db5)
|
||||
// 13 - Data 6 (db6)
|
||||
// 14 - Data 7 (db7)
|
||||
// 15 - Backlight Anode (+5v)
|
||||
// 16 - Backlight Cathode (Gnd)
|
||||
// ----------------------------------------------------------------------------
|
||||
// LiquidCrystal compability:
|
||||
// Since hd44780 is LiquidCrystal API compatible, most existing LiquidCrystal
|
||||
// sketches should work with hd44780 hd44780_pinIO i/o class once the
|
||||
// includes are changed to use hd44780 and the lcd object constructor is
|
||||
// changed to use the hd44780_pinIO class.
|
||||
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_pinIO.h> // Arduino pin i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
// Note: this can be with or without backlight control:
|
||||
|
||||
// without backlight control:
|
||||
// The parameters used by hd44780_pinIO are the same as those used by
|
||||
// the IDE bundled LiquidCrystal library
|
||||
// note that ESP8266 based arduinos must use the Dn defines rather than
|
||||
// raw pin numbers.
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14; // esp32 espduino32 D1 R32 (uno form factor)
|
||||
#else
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // for all other devices
|
||||
#endif
|
||||
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
//with backlight control:
|
||||
// backlight control requires two additional parameters
|
||||
// - an additional pin to control the backlight
|
||||
// - backlight active level which tells the library the level
|
||||
// needed to turn on the backlight.
|
||||
// note: If the backlight control pin supports PWM, dimming can be done
|
||||
// using setBacklight(dimvalue);
|
||||
//
|
||||
// WARNING: some lcd keypads have a broken backlight circuit
|
||||
// If you have a lcd keypad, it is recommended that you first run the
|
||||
// LCDKeypadCheck sketch to verify that the backlight circuitry
|
||||
// is ok before enabling backlight control.
|
||||
// However, the hd44780_PinIO class will autodetect the issue and
|
||||
// work around it in s/w. If the backlight circuitry is broken,
|
||||
// dimming will not be possible even if the backlight pin supports PWM.
|
||||
//
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
// esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
//const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7, bl=D10, blLevel=HIGH;
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// esp32 espduino32 D1 R32 (uno form factor)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
// Dimming will not work on esp32 as it does not have analogWrite()
|
||||
//const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14, bl=5, blLevel=HIGH;
|
||||
#else
|
||||
//const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7, bl=10, blLevel=HIGH;
|
||||
#endif
|
||||
//hd44780_pinIO lcd(rs, en, db4, db5, db6, db7, bl, blLevel);
|
||||
|
||||
// LCD geometry
|
||||
const int LCD_COLS = 16;
|
||||
const int LCD_ROWS = 2;
|
||||
|
||||
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>
|
||||
//
|
||||
// note:
|
||||
// begin() will automatically turn on the backlight if backlight
|
||||
// control is specified in the lcd object constructor
|
||||
//
|
||||
|
||||
status = lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// hd44780 has a fatalError() routine that blinks an led if possible
|
||||
// begin() failed so call fatalError() with the error code.
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// if backlight control was specified, the backlight should be on now
|
||||
|
||||
// Print a message to the LCD
|
||||
lcd.print(" UpTime");
|
||||
|
||||
if(LCD_ROWS < 2)
|
||||
delay(3000);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static unsigned long lastsecs = -1; // pre-initialize with non zero value
|
||||
unsigned long secs;
|
||||
int status;
|
||||
|
||||
secs = millis() / 1000;
|
||||
|
||||
// see if 1 second has passed
|
||||
// so the display is only updated once per second
|
||||
if(secs != lastsecs)
|
||||
{
|
||||
lastsecs = secs; // keep track of last seconds
|
||||
|
||||
// set the cursor position to column 0, row 1
|
||||
// note: row 1 is the second row from top,
|
||||
// since row counting begins with 0
|
||||
// if display has only 1 line, it will appear on that line
|
||||
status = lcd.setCursor(0, 1);
|
||||
if(status) // non zero status means it was unsuccesful
|
||||
{
|
||||
// setCursor() failed so call fatalError() with the error code.
|
||||
hd44780::fatalError(status); // does not return
|
||||
}
|
||||
|
||||
// print uptime on lcd device: (time since last reset)
|
||||
PrintUpTime(lcd, secs);
|
||||
}
|
||||
}
|
||||
|
||||
// PrintUpTime(outdev, secs) - print uptime in HH:MM:SS format
|
||||
// outdev - the device to send output
|
||||
// secs - the total number of seconds uptime
|
||||
//
|
||||
// This is a fancy output routine.
|
||||
// outdev is a Print class object which indicates
|
||||
// where the output should be sent.
|
||||
// PrintUpTime can be used with any object that uses the Print class.
|
||||
// This code works with Serial objects, as well as the the hd44780 lcd objects.
|
||||
// i.e. you can call with Serial: PrintUpTime(Serial, seconds);
|
||||
|
||||
void PrintUpTime(Print &outdev, unsigned long secs)
|
||||
{
|
||||
unsigned int hr, mins, sec;
|
||||
|
||||
// convert total seconds to hours, mins, seconds
|
||||
mins = secs / 60; // how many total minutes
|
||||
hr = mins / 60; // how many total hours
|
||||
mins = mins % 60; // how many minutes within the hour
|
||||
sec = secs % 60; // how many seconds within the minute
|
||||
|
||||
// print uptime in HH:MM:SS format
|
||||
|
||||
if(hr > 99)
|
||||
hr %= 100; // limit hr to 0-99
|
||||
|
||||
// Print class does not support fixed width formatting
|
||||
// so insert a zero if number smaller than 10
|
||||
|
||||
if(hr < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)hr);
|
||||
outdev.write(':');
|
||||
if(mins < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)mins);
|
||||
outdev.write(':');
|
||||
if(sec < 10)
|
||||
outdev.write('0');
|
||||
outdev.print((int)sec);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDcharset - Display LCD character set for hd44780 hd44780_pinIO i/o class
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example LCDcharset.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or example
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in hd44780 examples:
|
||||
// hd44780/examples/hd44780examples/LCDcharset/LCDcharset.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDcharset
|
||||
//
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_pinIO.h>
|
||||
|
||||
// define the LCD geometry
|
||||
#define LCD_COLS 16
|
||||
#define LCD_ROWS 2
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
// Note: this can be with or without backlight control:
|
||||
|
||||
// without backlight control:
|
||||
// note that ESP8266 based arduinos must use the Dn defines rather than
|
||||
// raw pin numbers.
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14; // esp32 espduino32 D1 R32 (uno form factor)
|
||||
#else
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // for all other devices
|
||||
#endif
|
||||
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
//with backlight control:
|
||||
// backlight control requires two additional parameters
|
||||
// - an additional pin to control the backlight
|
||||
// - backlight active level which tells the library the level
|
||||
// needed to turn on the backlight.
|
||||
// note: If the backlight control pin supports PWM, dimming can be done
|
||||
// using setBacklight(dimvalue);
|
||||
//
|
||||
// WARNING: some lcd keypads have a broken backlight circuit
|
||||
// If you have a lcd keypad, it is recommended that you first run the
|
||||
// LCDKeypadCheck sketch to verify that the backlight circuitry
|
||||
// is ok before enabling backlight control.
|
||||
// However, the hd44780_PinIO class will autodetect the issue and
|
||||
// work around it in s/w. If the backlight circuitry is broken,
|
||||
// dimming will not be possible even if the backlight pin supports PWM.
|
||||
//
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
// esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
//const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7, bl=D10, blLevel=HIGH;
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// esp32 espduino32 D1 R32 (uno form factor)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
//const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14, bl=5, blLevel=HIGH;
|
||||
#else
|
||||
//const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7, bl=10, blLevel=HIGH;
|
||||
#endif
|
||||
//hd44780_pinIO lcd(rs, en, db4, db5, db6, db7, bl, blLevel);
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library LCDcharset sketch source code
|
||||
#include <examples/hd44780examples/LCDcharset/LCDcharset.ino>
|
||||
@@ -0,0 +1,71 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDiSpeed - LCD Interface Speed test for hd44780 hd44780_pinIO i/o class
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDiSpeed
|
||||
//
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_pinIO.h>
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
// Note: this can be with or without backlight control:
|
||||
|
||||
// without backlight control:
|
||||
// note that ESP8266 based arduinos must use the Dn defines rather than
|
||||
// raw pin numbers.
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14; // esp32 espduino32 D1 R32 (uno form factor)
|
||||
#else
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // for all other devices
|
||||
#endif
|
||||
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
//with backlight control:
|
||||
// backlight control requires two additional parameters
|
||||
// - an additional pin to control the backlight
|
||||
// - backlight active level which tells the library the level
|
||||
// needed to turn on the backlight.
|
||||
// note: If the backlight control pin supports PWM, dimming can be done
|
||||
// using setBacklight(dimvalue);
|
||||
//
|
||||
// WARNING: some lcd keypads have a broken backlight circuit
|
||||
// If you have a lcd keypad, it is recommended that you first run the
|
||||
// LCDKeypadCheck sketch to verify that the backlight circuitry
|
||||
// is ok before enabling backlight control.
|
||||
// However, the hd44780_PinIO class will autodetect the issue and
|
||||
// work around it in s/w. If the backlight circuitry is broken,
|
||||
// dimming will not be possible even if the backlight pin supports PWM.
|
||||
//
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
// esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
//const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7, bl=D10, blLevel=HIGH;
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// esp32 espduino32 D1 R32 (uno form factor)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
//const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14, bl=5, blLevel=HIGH;
|
||||
#else
|
||||
//const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7, bl=10, blLevel=HIGH;
|
||||
#endif
|
||||
//hd44780_pinIO lcd(rs, en, db4, db5, db6, db7, bl, blLevel);
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino>
|
||||
@@ -0,0 +1,56 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDLibTest - LCD library test sketch for hd44780 hd44780_pinIO i/o class
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/LCDlibTest/LCDlibTest.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDlibTest
|
||||
//
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_pinIO.h> // include i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
// Note: this can be with or without backlight control:
|
||||
|
||||
// without backlight control:
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
//const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// esp32 espduino32 D1 R32 (uno form factor)
|
||||
// note: espduino32 GPIO12 needs a pulldown resistor
|
||||
//const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14;
|
||||
#else
|
||||
//const int rs=12, en=11, db4=5, db5=4, db6=3, db7=2; // IDE LiquidCrystal pins
|
||||
//const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // lcd keypad shield pins
|
||||
|
||||
#endif
|
||||
//hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
// esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7, bl=D10, blLevel=HIGH;
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// esp32 espduino32 D1 R32 (uno form factor)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14, bl=5, blLevel=HIGH;
|
||||
#else
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7, bl=10, blLevel=HIGH;
|
||||
#endif
|
||||
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7, bl, blLevel);
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/LCDlibTest/LCDlibTest.ino>
|
||||
@@ -0,0 +1,69 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// lcdproc - LCD library lcdproc wrapper sketch for hd44780_pinIO i/o class
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or exmaple
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/lcdproc/lcdproc.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/lcdproc
|
||||
//
|
||||
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_pinIO.h> // include i/o class header
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
// Note: this can be with or without backlight control:
|
||||
|
||||
// without backlight control:
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14; // esp32 espduino32 D1 R32 (uno form factor)
|
||||
#else
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // for all other devices
|
||||
#endif
|
||||
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
//with backlight control:
|
||||
// backlight control requires two additional parameters
|
||||
// - an additional pin to control the backlight
|
||||
// - backlight active level which tells the library the level
|
||||
// needed to turn on the backlight.
|
||||
// note: If the backlight control pin supports PWM, dimming can be done
|
||||
// using setBacklight(dimvalue);
|
||||
//
|
||||
// WARNING: some lcd keypads have a broken backlight circuit
|
||||
// If you have a lcd keypad, it is recommended that you first run the
|
||||
// LCDKeypadCheck sketch to verify that the backlight circuitry
|
||||
// is ok before enabling backlight control.
|
||||
// However, the hd44780_PinIO class will autodetect the issue and
|
||||
// work around it in s/w. If the backlight circuitry is broken,
|
||||
// dimming will not be possible even if the backlight pin supports PWM.
|
||||
//
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
// esp8266 Lolin/Wemos D1 R1 (uno form factor)
|
||||
//const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7, bl=D10, blLevel=HIGH;
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// esp32 espduino32 D1 R32 (uno form factor)
|
||||
// note: GPIO12 needs a pulldown resistor
|
||||
//const int rs=12, en=13, db4=17, db5=16, db6=27, db7=14, bl=5, blLevel=HIGH;
|
||||
#else
|
||||
//const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7, bl=10, blLevel=HIGH;
|
||||
#endif
|
||||
//hd44780_pinIO lcd(rs, en, db4, db5, db6, db7, bl, blLevel);
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/lcdproc/lcdproc.ino>
|
||||
@@ -0,0 +1,40 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// LCDiSpeed - LCD Interface Speed test for AdaFruit_LiquidCrystal in 4bit mode
|
||||
// ----------------------------------------------------------------------------
|
||||
// This sketch is a wrapper sketch for the hd44780 library example.
|
||||
// Note:
|
||||
// This is not a normal sketch and should not be used as model or example
|
||||
// of hd44780 library sketches.
|
||||
// This sketch is simple wrapper that declares the needed lcd object for the
|
||||
// hd44780 library sketch.
|
||||
// It is provided as a convenient way to run a pre-configured sketch for
|
||||
// the i/o class.
|
||||
// The source code for this sketch lives in the hd44780 examples.
|
||||
// hd44780/examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino
|
||||
// From IDE:
|
||||
// [File]->Examples-> hd44780/hd44780examples/LCDiSpeed
|
||||
//
|
||||
|
||||
#include <Adafruit_LiquidCrystal.h>
|
||||
|
||||
// ugliness to allow this sketch to locate the hd44780 example sketch
|
||||
// note: hd44780.h is not needed, it is only included to get its directory on the include path
|
||||
#include <hd44780.h>
|
||||
#undef hd44780_h // undefine this so the example sketch does not think hd44780 is being used.
|
||||
|
||||
// cols and rows don't have to be exact to still get accurate transfer numbers
|
||||
#define LCD_COLS 16
|
||||
#define LCD_ROWS 2
|
||||
|
||||
// declare Arduino pins used for LCD functions
|
||||
// and the lcd object
|
||||
|
||||
//const int rs=12, en=11, db4=5, db5=4, db6=3, db7=2; // pins used by IDE LiquidCrystal examples
|
||||
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // lcd keypad shield pins
|
||||
Adafruit_LiquidCrystal lcd(rs, en, db4, db5, db6, db7);
|
||||
|
||||
// tell the hd44780 sketch the lcd object has been declared
|
||||
#define HD44780_LCDOBJECT
|
||||
|
||||
// include the hd44780 library sketch source code
|
||||
#include <examples/hd44780examples/LCDiSpeed/LCDiSpeed.ino>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user