Use I2C_LCD to Debug Your Project
by Seeed Studio in Circuits > Arduino
5522 Views, 22 Favorites, 0 Comments
Use I2C_LCD to Debug Your Project



The serial monitor is a useful debugger for arduino, it can print logs on the computer screen. so that, if you want to get running informations of you project, you need to take a computer with you anywhere. Now, you can use I2C_LCD to get running logs anywhere, it will be more convenient.
I2C_LCD(With universal Grove cable): http://www.seeedstudio.com/item_detail.html?p_id=2601
I2C_LCD(With conversion Grove cable): https://www.seeedstudio.com/item_detail.html?p_id=2600
Install the Arduino Library for I2C_LCD.
You can download from here: http://www.seeedstudio.com/wiki/images/e/ef/I2C_LC...
How to install the library? please refer to the "How to use?" section of WIKI page: http://www.seeedstudio.com/wiki/I2C_LCD
Connect I2C_LCD to the I2C Port of Your Arduino Board.

We recommend you to use Seeeduino or Seeeduino Lotus.
If you use I2C_LCD with traditional Arduino boards ( The boards with female connectors, like Arduino Uno and so on ), please refer to another version of I2C_LCD (With 4 pin female jumper to Grove 4 pin conversion cable).
To Use LCD.print() Function As Serial.print().
The following are extracted from: https://www.arduino.cc/en/Serial/Print
LCD.print()
Description
Prints data to the I2C_LCD as human-readable ASCII text. This command can take many forms. Numbers are printed using an ASCII character for each digit. Floats are similarly printed as ASCII digits, defaulting to two decimal places. Bytes are sent as a single character. Characters and strings are sent as is. For example:
LCD.print(78) gives "78"
LCD.print(1.23456) gives "1.23"
LCD.print('N') gives "N"
LCD.print("Hello world.") gives "Hello world."
An optional second parameter specifies the base (format) to use; permitted values are BIN (binary, or base 2), OCT (octal, or base 8), DEC (decimal, or base 10), HEX (hexadecimal, or base 16). For floating point numbers, this parameter specifies the number of decimal places to use. For example:
LCD.print(78, BIN) gives "1001110"
LCD.print(78, OCT) gives "116"
LCD.print(78, DEC) gives "78"
LCD.print(78, HEX) gives "4E"
LCD.println(1.23456, 0) gives "1"
LCD.println(1.23456, 2) gives "1.23"
LCD.println(1.23456, 4) gives "1.2346"
You can pass flash-memory based strings to LCD.print() by wrapping them with F(). For example :
LCD.print(F(Hello World )
To send a single byte, use LCD.write().
Syntax
LCD.print(val)
LCD.print(val, format)
Parameters
val: the value to print - any data type
format: specifies the number base (for integral data types) or number of decimal places (for floating point types)
Returns
size_t (long): print() returns the number of bytes written, though reading that number is optional
NOTE:
Different from Serial.print(), you need to set the position coordinates before print:
LCD.CharGotoXY(0,20);
LCD.print("Hello world.") ;
Example.

#include<Wire.h>
#include<I2C_LCD.h>//For detials of the function useage, please refer to "I2C_LCD User Manual". //You can download the "I2C_LCD User Manual" from I2C_LCD WIKI page: http://www.seeedstudio.com/wiki/I2C_LCD
I2C_LCD LCD; uint8_t I2C_LCD_ADDRESS = 0x51; //Device address setting, default: 0x51
void setup(void) { Wire.begin(); //I2C controler init. }
void loop(void) { LCD.CleanAll(WHITE); //Erase all. delay(1000); //Delay for 1s.
//8*16 font size, auto new line, black character on white back ground. LCD.FontModeConf(Font_6x8, FM_ANL_AAA, BLACK_BAC); //Set the start coordinate. LCD.CharGotoXY(0, 0); //Print string on I2C_LCD at the start coordinate. LCD.print("Hello, World!");
//Set the start coordinate. LCD.CharGotoXY(0, 10); LCD.print(78); //gives "78" LCD.print('N'); //gives "N" LCD.print(1.23456); //gives "1.23"
//Set the start coordinate. LCD.CharGotoXY(0, 20); LCD.print(78, BIN); //gives "1001110" LCD.print(' '); //gives " " LCD.print(78, OCT); //gives "116" LCD.print(' '); //gives " " LCD.print(78, DEC); //gives "78" LCD.print(' '); //gives " " LCD.print(78, HEX); //gives "4E" LCD.print(' '); //gives " "
//Set the start coordinate. LCD.CharGotoXY(0, 30); LCD.println(1.23456, 0); //gives "1" LCD.println(1.23456, 2); //gives "1.23" LCD.println(1.23456, 4); //gives "1.2346"
LCD.print("Debug with Arduino.");
while(1); //Wait for ever. }
Enjoy yourself!