Reply to topic  [ 1 post ] 
I2C Library for Hobby Components SmartLCD (HCMODU0122) 
Author Message
Site Admin

Joined: Sun Aug 05, 2012 4:02 pm
Posts: 650
Post I2C Library for Hobby Components SmartLCD (HCMODU0122)
Image




Arduino I2C library for the Hobby Components Smart LCD.
Products currently supported by this library:

Hobby Components 1602 Smart LCD (HCMODU0122) available from hobbycomponents.com

Optional:

Hobby Components SmartLCD Keypad kit (HCKITS0058)


You will need to download (please log in to download the library) and unzip this library to the Arduino development environments library area.

On Windows:
My Documents\Arduino\libraries\

On Mac:
Documents/Arduino/libraries/

Linux:
Usually found within the users home area under /Arduino/libraries/


Using the SMARTLCDI2C library


To use the library just include the SMARTLCDI2C .h header file and then create an instance of the library. E.g:


Code:
#include <SMARTLCDI2C.h>
SmartLCD SmartLCD(I2C_Add);



Where I2C_Add is the I2C address of the SmartLCD (default is 0x27).


To initialise the library add the following line to the setup() section of your sketch:


Code:
SmartLCD.init();





The following functions are available with this library:

void PrintChar(char Character);

Prints a single ASCII character to the screen starting at the current cursor position where:
Character is the ASCII encoded character to print

Example:

Code:
SmartLCD.PrintChar('A');





void Print(char *String);

Prints a string of ASCII text to the screen starting at the current cursor position where:
String is an ASCII string with null terminator containing the text to print

Example:

Code:
SmartLCD.Print("Hello World!");





void Print(int Value);

Prints a signed integer number to the screen starting at the current cursor position where:
Value is the signed integer to print

Example:

Code:
SmartLCD.Print(-1234);





void Clear(void);

Clears the screen of any printed text and positions the cursor to row 0, column 0 (top left hand corner)

Example:

Code:
SmartLCD.Clear();





void CurPos(byte Row, byte Col);

Positions the cursor on the screen where:
Row is the text row number - valid values are 0 to 4 (only 0 to 1 visible on 1602 version)

Col is the text column number - valid values are 0 to 79 (only 0 to 15 visible on 1602 version)

Example:

Code:
SmartLCD.CurPos(0,0);





void DispState(byte State);

Turns the LCD on or off where:
State is required state to set the screen to. Valid values are
OFF (screen is turned off)
ON (screen is turned on)

Note that any text on the screen and the backlight state are not affected.

Example:

Code:
SmartLCD.DispState(ON);





void DispCursor(byte State);

Turns the cursor on or off where:
State is required state to set the cursor to. Valid values are
OFF (cursor is turned off)
ON (cursor is turned on)

Example:

Code:
SmartLCD.DispCursor(ON);





void CursorBlink(byte State);

Turns cursor blinking on or off where:
State is required state to set the cursor blink to. Valid values are
OFF (cursor blinking is turned off)
ON (cursor blinking is turned on)

Example:

Code:
SmartLCD.CursorBlink(ON);





void Backlight(uint8_t Level);

Sets the brightness level for the back light where:
Level is the required brightness in 10% increments. Valid values are
0 (off) to 10 (100%)

Example:

Code:
SmartLCD.Backlight(10);





void PrintCustChar(byte CharIndex);

Prints one of the 8 custom characters to the screen where:
CharIndex specifies which custom character (0 to 7) to print.

Example:

Code:
SmartLCD.PrintCustChar(0);





void DefCustChar(uint8_t CharIndex, uint8_t *Data);

Defines one of the 8 custom characters by writing a 5x8 pixel bitmap to it where:
CharIndex specifies which custom character (0 to 7) to write the bitmap to.

Data is an 8 byte array containing the bitmap data.

See the Smart LCD manual for more information on bitmap format.

Note after issuing this function you must reposition the cursor before printing any text using the SmartLCD.CurPos(Row, Col) function.

Example:

Code:
byte Bitmap[] = {0x0E,0x1F,0x11,0x11,0x11,0x11,0x11,0x1F};
SmartLCD.DefCustChar(0, Bitmap);
SmartLCD.PrintCustChar(0);





void CursorDir(uint8_t Dir);

Sets which direction the cursor will move when printing text where:
Dir is the direction the cursor will move. Valid values are
LTOR - cursor will move from left to right
RTOL - cursor will move from right to left

Example:

Code:
SmartLCD.CursorDir(LTOR);





void I2CInit(void);

Initialises the LCD setting it to its default power on state. If the backlight was off it will also be set to the default on state.

Example:

Code:
SmartLCD.I2CInit();





void ClearButton(void);

Clears the last button pressed state by reseting it to 0

Example:

Code:
SmartLCD.ClearButton();





void PlayNote(byte Note, byte Time);

Plays one of 12 musical notes for a specified duration where:
Note is which of the 12 notes to play (0 to 11). Predefined values for note:
NOTE_C 0
NOTE_CS 1
NOTE_D 2
NOTE_DS 3
NOTE_E 4
NOTE_F 5
NOTE_FS 6
NOTE_G 7
NOTE_GS 8
NOTE_A 9
NOTE_A# 10
NOTE_B 11

Time is the duration of the note in 10ms increments (1 = 10ms to 255 = 2.55s)

Note: Requires the optional keypad and speaker accessory to be connected to the Smart LCD.

This command is none blocking - i.e. it will not wait for the note to finish playing.

Example:

Code:
SmartLCD.PlayNote(NOTE_C, 100);





void Address(byte Address);

Changes the I2C slave address for the Smart LCD where:
Address is the new I2C address. Valid values are
0x08 to 0x77 (default =0x27)

Note: Once this command is issued the display will immediately respond to commands sent to the new slave address and will no longer respond to the original address. This command will also update the current I2C address stored within the library so you can continue to issue commands without needing to re-initialise the library.

Example:

Code:
SmartLCD.Address(0x27);





void Contrast(byte Level);

Sets the contrast level of the screen where:
Level is the required contrast level. Valid values are
0 (maximum contrast) to 255 (minimum contrast).

Example:

Code:
SmartLCD.Contrast(0);





void Version(void);

Shows the version of firmware flashed into the Smart LCD by displaying it to the LCD.

Example:

Code:
SmartLCD.Version();





void ClearError(void);

Clears the error flag in the status register.

Example:

Code:
SmartLCD.ClearError();





void WaitBar(byte Row, byte Col, byte Length, byte Percent);

Draws a horizontal wait bar to the screen where:
Row is the text row number to position the wait bar.

Col is the text col number to position the left side of the wait bar.

Length is the length in characters of the wait bar

Percent specifies what part of the wait bar to fill in percent (0 to 100)

Example:

Code:
SmartLCD.WaitBar(0, 0, 16, 50)





boolean Busy(void);

Returns the busy status flag where
false = SmartLCD is not busy and can accept new commands
true = SmartLCD is busy and cannot accept new commands

Note that all the functions within this library use the busy command and will not finish executing until the SmartLCD has finished processing the current command. Therefore you do not need to use this function to check if it is ok to send another command when using the functions within this library.

Example:

Code:
while(SmartLCD.Busy());





boolean Error(void);

Returns the command error flag where
false = Last command executed without error
true = There was an error with executing or receiving the last command.

Note that if the error flag is set it will not automatically clear. Therefore you must clear the flag using the SmartLCD.ClearError() function.

Example:

Code:
if(SmartLCD.Error())
    Serial.print("Error!");
else
    Serial.print("OK");





boolean ButtonState(void);

Returns the keypad button pressed status where
false = No buttons are currently pressed on the external keypad.
true = A button on the external keypad is currently being pressed.

Note: Requires the optional keypad and speaker accessory to be connected to the Smart LCD.

Example:

Code:
if(SmartLCD.ButtonState())
    Serial.print("Button pressed");





byte Button(void);

Returns the last button number to be pressed on the external keypad where
KEYPAD_NONE = No buttons have been pressed
KEYPAD_BACK = The back button has been pressed
KEYPAD_SELECT = The select button has been pressed
KEYPAD_DOWN = The down button has been pressed
KEYPAD_RIGHT = The right button has been pressed
KEYPAD_UP = The up button has been pressed
KEYPAD_LEFT = The left button has been pressed

After reading the button state the current status can been cleared by issuing the SmartLCD.ClearButton() function.

Note: Requires the optional keypad and speaker accessory to be connected to the Smart LCD

Example:

Code:
if(SmartLCD.ButtonState() == true && SmartLCD.Button() != KEYPAD_NONE)
  {
    switch(SmartLCD.Button())   
    {
      case(KEYPAD_LEFT):
        SmartLCD.Print(" LEFT ");
        break;

      case(KEYPAD_UP):
        SmartLCD.Print("  UP  ");
        break;

      case(KEYPAD_RIGHT):
        SmartLCD.Print("RIGHT ");
        break;
       
      case(KEYPAD_BACK):
        SmartLCD.Print(" BACK ");
        break;

       case(KEYPAD_DOWN):
        SmartLCD.Print(" DOWN ");
        break;
       
      case(KEYPAD_SELECT):
        SmartLCD.Print("SELECT");
        break;
    }

    SmartLCD.ClearButton();
  }





byte ReadADC(void);

Returns an 8 bit byte representing the state of the 8 bit ADC connected to the 'S' pin of the keypad header where:
0 = 0V (GND) and 255 = 5V (VCC)

Note this pin is used by the SmartLCD keypad for button sensing but if the SmartLCD keypad is not required this pin can be used as an 8 bit ADC input (5V max).

Example:

Code:
byte Value = SmartLCD.ReadADC()
    Serial.println(Value);





byte Status(void);

Returns an 8 bit byte containing the current state from the I2C status register.

See SmartLCD manual for an explanation of the I2C status register

Example:

Code:
byte Status = SmartLCD.Status()
    Serial.println(Status, BIN);





Image

Code:
#include "SmartLCDI2C.h"      //Include the SmartLCD I2C Library

#define I2C_ADD 0x27          //I2C address of the Smart LCD

SmartLCD SmartLCD(I2C_ADD);   //Create an instance of the library



void setup()
{
  SmartLCD.init();            //Initiliases the library
}



void loop()                 
{
  SmartLCD.Clear();           //Clear the screen
 
  SmartLCD.CurPos(0, 5);      //Set the cursor to row 0 column 5
  SmartLCD.Print("Hello");    //Print some text
 
  SmartLCD.CurPos(1, 4);      //Set the cursor to row 1 column 4
  SmartLCD.Print("World !");  //Print some text

  while(1);                   //Do nothing
}




Image

Attachment:
SmartLCDI2C.zip



Diagrams, libraries, and example code are provided as an additional free service by Hobby Components and are not sold as part of this product. We do no provide any guarantees or warranties as to their accuracy or fitness for purpose.

Descriptions and diagrams on this page are copyright Hobby Components Ltd and may not be reproduced without permission.


You do not have the required permissions to view the files attached to this post.


Thu Jul 13, 2017 10:32 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Thank you to phpBB.com & phpBB.ro.
Design created by Florea Cosmin Ionut.
© 2011 All contents of this site are © Hobby Components LTD