Arduino for ODROID-GO - I2C
- Make sure that you've followed these guides.
- Refer to the Arduino official documents. This tells us useful common functions with great instructions.
- Refer to the ESP32 official programming guide. Most of ESP32 specific functions introduced here.
- The hardware, LCD with I2C interface is not for sale. But with this guide you can get to know how to control the external I2C devices.
We will learn that how to display “Hello world” on the 16×2 LCD via external I2C interface.
Hardware setup
First of all, you should connect the 16×2 LCD to your ODROID-GO's P2(expansion connector) as follows.
P2, ODROID-GO | 16×2 LCD |
---|---|
GND(Pin #1) | GND |
IO15(Pin #4) | SDA |
IO4(Pin #5) | SCL |
P3V3(Pin #6) | VCC |
- Download Fritzing example file: odroid-go-i2clcd.fzz
- ODROID-GO: fritzing_odroid-go.fzpz
- 16×2 LCD: 16x2lcd.fzpz
- I2C-LCD module: 16x2lcdi2c.fzpz
Import library
You have to clone the library to use it properly.
Enter the following codes to clone it from the Github repository.
Windows
Open Git Bash program to enter the following commands.
- host
cd $USERPROFILE/Documents/Arduino/libraries git clone https://github.com/marcoschwartz/LiquidCrystal_I2C
Linux
Open a Terminal window to enter the following command.
- host
git clone https://github.com/marcoschwartz/LiquidCrystal_I2C ~/Arduino/libraries/LiquidCrystal_I2C
I2C on Arduino
Using I2C is simple on the Arduino IDE; The ESP32's Wire library could help us.
We're already know that the ports for I2C communication are 15 for SDA, 4 for SCL.
Define as a pre-processor them and use Wire.begin() function. you can put only 2 parameters, pin number for SDA and SCL.
#define PIN_I2C_SDA 15 #define PIN_I2C_SCL 4 void setup() { // put your setup code here, to run once: Wire.begin(PIN_I2C_SDA, PIN_I2C_SCL); } void loop() { // put your main code here, to run repeatedly: }
And add a code for set the LCD up.
Include LiquidCrystal_I2C.h library to show a message on that easily.
Create a instance for control the LCD with LiquidCrystal_I2C lcd(LCD_ADDR, 16, 2) line. Given parameters are the LCD ADDR, cols and rows for 16×2 LCD.
Do init(), turn on the backlit with backlight(), set cursor to specify a point to write down with setCursor().
And print().
#include <LiquidCrystal_I2C.h> #define PIN_I2C_SDA 15 #define PIN_I2C_SCL 4 const uint8_t LCD_ADDR = 0x3f; LiquidCrystal_I2C lcd(LCD_ADDR, 16, 2); void setup() { // put your setup code here, to run once: Wire.begin(PIN_I2C_SDA, PIN_I2C_SCL); lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); lcd.print("Hello, ODROID-GO"); } void loop() { // put your main code here, to run repeatedly: }
Press CTRL-U to compile and upload the sketch to show a message on the LCD.