Source code for LCD_Print_Class
Note this project came to a grinding halt due to an issue I don't understand when trying to inherit the print libraries. I will complete the page when I can resolve those issues. However the project does have 3 forms of the write( ) method which will enable me to use the LCD to display intermediate results in a later project.
Include file:LCD_Print_Class.h
Constructor: LCD_Print_Class(int p1,.....int p7).
7 pins: (VCC,GND,SCE,RESET,DC,SDIN,SCLK);
Defaults to pins 2,3,4,5,6,7,8
Public Methods: begin( ) Initialises pins as above.
Initialises the LCD
write( ); Three forms: Value, String, Array
///print( );Inherits standard print( ) structures - couldn't get this to work
clear( );Clears screen
setX( ),setY( ),setXY( );sets cursor
Summary: This project enhances the LCD_Init_Class that interfaced a Cpp Class to a 84 x 48 Dot Matrix LCD Display. That method included a char2lcd( ) for testing. This project will add the write method for a string an array and inherit the the Print class from the Arduino Library that will allow printing on the LCD numbers in various formats.
Possible Audience: Readers who just wish to use the LCD can go to the final code. Programmers who are interested in developing and using Cpp code can read the detail.
Keywords: Arduino UNO, Dot Matrix LCD Display, Module XC-4616, Cpp Implementation file, Cpp Header file, Cpp Class, Cpp Inheritance, Arduino Library, Print class
Components: Arduino Uno, Dot Matrix Display (Jaycar XC-4616), Two 8-pin wire wrap sockets/headers
Required Libraries: LCD_Init_Class. Arduino Print library
This project is concerned with using the 84x48 dot matrix display. These displays are sold by Jaycar as the XC-4616 and are identical to displays found in old Nokia phones. They feature the PCD8544 chipset. The thrust for this project is to use the display in other projects and to use the display in a project where the serial monitor was not available for debugging.
This project builds on two previous projects as illustrated. Note in code write(char) has been changed to char2lcd(char)
LCD_ROM_Class developed code that generated the patterns for the characters 0x20 through 0x7F (0x41 represents 'A', 0x42 'B' etc).
LCD_Init_Class developed code that initialised the LCD.
For testing the LCD_Init_Class included a write(char) or write(value) method. This was later changed to char2lcd(char)
This project will (i) enhance the write(char) method for a string an an array, and (ii) inherit the Arduino Print class to enable printing to the LCD in many formats.
This project will require the LCD_Init_Class library that in turn inherits LCD_ROM_Class. If these are not available in the users libraries folder the safest method is to generate the library rather than attempting to copy files.
See appendix.
Possible starting code is given below**:
//LCD_Print_Class.ino Client or test code#include "LCD_Print_Class.h"void setup() {}void loop() {}The client/test code and the implementation file both include the header file LCD_Print_Class.h.
The header file includes a wrapper to ensure it is included in a project one only.
At this point the project should compile and run. (Possible errors will be the UNO board or the correct Port are not selected.)
**The *.ino file is created using file-->new while to create the other two files use the inverted triangle on the IDE and chose new_tab. Both files must have the same name/label but extensions *.cpp and *.h.
At this point a class LCD_Print_Class can be declared. Note the format to include a previous class LCD_Init_Class.
Further use sketch-->include library--> and go to contributed libraries and select LCD_Init_Class. It will be along way down the list of files.**
**Also in that list of contributed libraries should be LCD_ROM_Class that LCD_Init_Class inherits. No action is required but if compiling gives an error a missing library might be the reason.
The constructor is concerned with the LCD wiring. The test circuit is as shown:
The LCD_Init_Class had two options
1. LCD_Init_Class( ) where the wiring as given is used by default, and
2. LCD_Int_Class(7 arguments) where the wiring could be specified.
These two options (overloading) will be retained in this project. The new header file will become:
And the implementation code:
In operation the compiler will select which version to use and at run time the program will go to the LCD_Print_Class constructor that will call the LCD_Init_Class constructor.
To test the following code should be added to the client program**^^:
This program should continually print characters up to character (51) ie 's'
**Note: I found that if I used LCD_Print_Class LCD( ); with parenthesis it appeared to compile/link correctly but later when I tried to use a member "begin" I received the following error message: request for member 'begin' in 'LCD', which is of non-class type 'LCD_Print_Class()' The internet suggested that with parenthesis it was being treated as a function call returning type LCD_Print_Class.
^^ There is no new begin( ) method for LCD_Print_Class. The compiler will look for a begin( ) in LCD_Init_Class - that is the inherited class.
The program to this point has simply duplicated the LCD_Init_Class. To test that class/library a write(value) routine was included.
The objective of this project is to add additional write methods and to inherit the Arduino inbuilt Print operations. This is illustrated in the following diagram where all of the methods/functions ultimately call the write(char) method.
Originally in the library LCD_Init_Class there was a method called write(value). At this point of this project there were some problems and it seemed better to give the original write( ) a unique name - hence the name/label char2lcd (character to LCD). The write(value) method from this project will simply call the char2lcd( ) method.
This section will expand the class by adding the two public methods write(array) and write(string) - legally write(*array,length) and write(*char);.
The new code becomes:
The test or client code
//LCD_Print_Class.ino Client or test code#include "LCD_Print_Class.h"LCD_Print_Class LCD; byte test_array[ ] ={0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x20};gave the following result verifying the operation^^.
^^write(len+32) does not display the length - it only displays the character represented by the number len+32. That is character ";".
To use the Print library all that needs to be done is to include it in the class definition. That is :
Famous last words: This creates a compiler error error "cannot declare variable 'LCD' to be of abstract type 'LCD_Print_Class'"
A search of the internet suggests that adding "public Print" as above to the class is all that is required.
This is my second project using the Print library. In the first I wrote all of the code (LCD_ROM_Class, LCD_Init_Class and LCD_Print_Class) as one big library (or flat file) and added the "public Print" and it worked. I thought it was better to write the code as several (vertical) libraries (these pages LCD_ROM_Class, LCD_Init_Class and LCD_Print_Class) expecting everything to be straight forward. But no - there is something wrong or something that I need to change that I cannot see.
I am putting sorting out this problem on hold and moving to other projects. One such project will use the LCD for debugging WiFi and I believe the three write( ) methods will satisfy my needs.
Sorry - It doesn't make me very happy leaving something unfinished. Have I made a silly mistake or is there something I do not understand?
Adding libraries before commencing this project start here.
This project will require the LCD_Init_Class library that in turn inherits LCD_ROM_Class. If these are not available in the users libraries folder the safest method is to generate the library by implementing those projects rather than attempting to copy files.
1. Create a new project by opening a new file: ie file-->new. Give it the name/label LCD_ROM_Class. The Arduino IDE will give it the extension *.ino.
2. In the Arduino IDE use the inverted triangle near the top right and create two new_tabs. Give these the labels LCD_ROM_Class.cpp and LCD_ROM_Class.h - note the extensions
3. From the folder LCD_ROM_Class_code on this site copy the source code LCD_ROM_Class.ino, LCD_ROM_Class.cpp and LCD_ROM_Class.h
4. Check that the project will compile. If necessary remove any embedded printing characters.
Making a library for this project start here - for the filename read LCD_Print_Class
5. Using for example Windows Explorer create a *.zip file of the *.cpp and *.h files. It will have the label LCD_ROM_Class.zip
6. In the Arduino IDE use sketch-->Include Library-->Add *.zip library and select LCD_ROM_Class.zip. LCD_ROM_Class. is now available as a contributed library.
The file structure is shown below where in this example "This_Project" is LCD_ROM_Class. Under the sketchbook folder there will be a sub-directory LCD_ROM_Class that contains the three files of the same name with extensions *ino, *.cpp and *.h. This is where the files are found to make a *.zip copy.
Following the include library operation there will be copies of the *.cpp and *.h files under the folder LCD_ROM_Class that is in turn a sub folder of the folder LCD_ROM_Class.
It will be necessary to repeat the procedure for LCD_Init_Class