From 29a6849d821279dccac3348e03b91bedb470423f Mon Sep 17 00:00:00 2001 From: "fourstix@gmail.com" Date: Sun, 2 Sep 2018 14:15:36 -0400 Subject: [PATCH] Create OpenLCD library --- src/Sparkfun_OpenLCD/Sparkfun_OpenLCD.cpp | 615 ++++++++++++++++++ src/Sparkfun_OpenLCD/Sparkfun_OpenLCD.h | 121 ++++ .../examples/Autoscroll/Autoscroll.ino | 92 +++ .../examples/Backlight/Backlight.ino | 107 +++ .../examples/Basic_I2C/Basic_I2C.ino | 86 +++ .../examples/Basic_SPI/Basic_SPI.ino | 73 +++ .../examples/Basic_Serial/Basic_Serial.ino | 67 ++ src/Sparkfun_OpenLCD/examples/Blink/Blink.ino | 77 +++ .../examples/Cursor/Cursor.ino | 78 +++ .../CustomCharacter/CustomCharacter.ino | 169 +++++ .../examples/Display/Display.ino | 82 +++ .../examples/HelloWorld/HelloWorld.ino | 77 +++ .../examples/MoveCursor/MoveCursor.ino | 95 +++ .../examples/Scroll/Scroll.ino | 106 +++ .../examples/SerialDisplay/SerialDisplay.ino | 85 +++ .../examples/TextDirection/TextDirection.ino | 106 +++ .../examples/setCursor/setCursor.ino | 92 +++ src/Sparkfun_OpenLCD/keywords.txt | 42 ++ 18 files changed, 2170 insertions(+) create mode 100644 src/Sparkfun_OpenLCD/Sparkfun_OpenLCD.cpp create mode 100644 src/Sparkfun_OpenLCD/Sparkfun_OpenLCD.h create mode 100644 src/Sparkfun_OpenLCD/examples/Autoscroll/Autoscroll.ino create mode 100644 src/Sparkfun_OpenLCD/examples/Backlight/Backlight.ino create mode 100644 src/Sparkfun_OpenLCD/examples/Basic_I2C/Basic_I2C.ino create mode 100644 src/Sparkfun_OpenLCD/examples/Basic_SPI/Basic_SPI.ino create mode 100644 src/Sparkfun_OpenLCD/examples/Basic_Serial/Basic_Serial.ino create mode 100644 src/Sparkfun_OpenLCD/examples/Blink/Blink.ino create mode 100644 src/Sparkfun_OpenLCD/examples/Cursor/Cursor.ino create mode 100644 src/Sparkfun_OpenLCD/examples/CustomCharacter/CustomCharacter.ino create mode 100644 src/Sparkfun_OpenLCD/examples/Display/Display.ino create mode 100644 src/Sparkfun_OpenLCD/examples/HelloWorld/HelloWorld.ino create mode 100644 src/Sparkfun_OpenLCD/examples/MoveCursor/MoveCursor.ino create mode 100644 src/Sparkfun_OpenLCD/examples/Scroll/Scroll.ino create mode 100644 src/Sparkfun_OpenLCD/examples/SerialDisplay/SerialDisplay.ino create mode 100644 src/Sparkfun_OpenLCD/examples/TextDirection/TextDirection.ino create mode 100644 src/Sparkfun_OpenLCD/examples/setCursor/setCursor.ino create mode 100644 src/Sparkfun_OpenLCD/keywords.txt diff --git a/src/Sparkfun_OpenLCD/Sparkfun_OpenLCD.cpp b/src/Sparkfun_OpenLCD/Sparkfun_OpenLCD.cpp new file mode 100644 index 0000000..4e56d98 --- /dev/null +++ b/src/Sparkfun_OpenLCD/Sparkfun_OpenLCD.cpp @@ -0,0 +1,615 @@ +/* + * OpenLCD library for Sparkfun RGB 3.3v Serial Open LCD display + * + * By: Gaston R. Williams + * Date: Sept 1, 2018 + * + * License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). + * + + * This library is based heavily on the LiquidCrystal_I2C library and the sample code provided with + * the Sparkfun Serial OpenLCD display. The original LiquidCrystal library by David A. Mellis and + * modified by Limor Fried and the OpenLCD code by Nathan Seidle at Sparkfun. + * + * The LiquidCrystal_I2C library was based on the work by DFRobot. + * (That's the only attribution I found in the code I have. If anyone can provide better information, + * Plese let me know and I'll be happy to give credit where credit is due.) + * + * The OpenLCD display information is based based on code by + * Nathan Seidle + * SparkFun Electronics + * Date: April 19th, 2015 + * + * License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). + * OpenLCD gives the user multiple interfaces (serial, I2C, and SPI) to control an LCD. SerLCD was the original + * serial LCD from SparkFun that ran on the PIC 16F88 with only a serial interface and limited feature set. + * This is an updated serial LCD. + * + * Command cheat sheet: + * ASCII / DEC / HEX + * '|' / 124 / 0x7C - Put into setting mode + * Ctrl+c / 3 / 0x03 - Change width to 20 + * Ctrl+d / 4 / 0x04 - Change width to 16 + * Ctrl+e / 5 / 0x05 - Change lines to 4 + * Ctrl+f / 6 / 0x06 - Change lines to 2 + * Ctrl+g / 7 / 0x07 - Change lines to 1 + * Ctrl+h / 8 / 0x08 - Software reset of the system + * Ctrl+i / 9 / 0x09 - Enable/disable splash screen + * Ctrl+j / 10 / 0x0A - Save currently displayed text as splash + * Ctrl+k / 11 / 0x0B - Change baud to 2400bps + * Ctrl+l / 12 / 0x0C - Change baud to 4800bps + * Ctrl+m / 13 / 0x0D - Change baud to 9600bps + * Ctrl+n / 14 / 0x0E - Change baud to 14400bps + * Ctrl+o / 15 / 0x0F - Change baud to 19200bps + * Ctrl+p / 16 / 0x10 - Change baud to 38400bps + * Ctrl+q / 17 / 0x11 - Change baud to 57600bps + * Ctrl+r / 18 / 0x12 - Change baud to 115200bps + * Ctrl+s / 19 / 0x13 - Change baud to 230400bps + * Ctrl+t / 20 / 0x14 - Change baud to 460800bps + * Ctrl+u / 21 / 0x15 - Change baud to 921600bps + * Ctrl+v / 22 / 0x16 - Change baud to 1000000bps + * Ctrl+w / 23 / 0x17 - Change baud to 1200bps + * Ctrl+x / 24 / 0x18 - Change the contrast. Follow Ctrl+x with number 0 to 255. 120 is default. + * Ctrl+y / 25 / 0x19 - Change the TWI address. Follow Ctrl+x with number 0 to 255. 114 (0x72) is default. + * Ctrl+z / 26 / 0x1A - Enable/disable ignore RX pin on startup (ignore emergency reset) + * '-' / 45 / 0x2D - Clear display. Move cursor to home position. + * / 128-157 / 0x80-0x9D - Set the primary backlight brightness. 128 = Off, 157 = 100%. + * / 158-187 / 0x9E-0xBB - Set the green backlight brightness. 158 = Off, 187 = 100%. + * / 188-217 / 0xBC-0xD9 - Set the blue backlight brightness. 188 = Off, 217 = 100%. + * + * For example, to change the baud rate to 115200 send 124 followed by 18. + * + */ +#include "Sparkfun_OpenLCD.h" + +//<> setup using defaults +Sparkfun_OpenLCD::Sparkfun_OpenLCD(){ +} + +//<> +Sparkfun_OpenLCD::~Sparkfun_OpenLCD(){/*nothing to destruct*/} + +/* + * Set up the i2c communication with the SerLCD. + * wirePort - TwoWire port + * ic2_addr - I2C address + */ +void Sparkfun_OpenLCD::begin(TwoWire &wirePort, byte i2c_addr) { + _i2cAddr = i2c_addr; + + begin(wirePort); +} // begin + +/* + * Set up the i2c communication with the SerLCD. + */ +void Sparkfun_OpenLCD::begin(TwoWire &wirePort) { + _i2cPort = &wirePort; //Grab which port the user wants us to use + _serialPort = NULL; //Set to null to be safe + _spiPort = NULL; //Set to null to be safe + + //We expect caller to begin their I2C port, with the speed of their choice external to the library + //But if they forget, we start the hardware here. + _i2cPort->begin(); + + //Call init function since display may have been left in unknown state + init(); +} // begin +/* + * Set up the serial communication with the SerLCD. + */ +void Sparkfun_OpenLCD::begin(Stream &serialPort) { + _serialPort = &serialPort; //Grab which port the user wants us to use + _i2cPort = NULL; //Set to null to be safe + _spiPort = NULL; //Set to null to be safe + + //Call init function since display may have been left in unknown state + init(); +} // begin +//Only available in Arduino 1.6 or later +#ifdef SPI_HAS_TRANSACTION +/* + * Set up the SPI communication with the SerLCD using SPI transactions + * + * NB we pass SPISettings by value, since many of the examples for the SPI + * transactions create the settings object in the function call, and that only + * works if the function passes the object by value. + */ +void Sparkfun_OpenLCD::begin(SPIClass &spiPort, byte csPin, SPISettings spiSettings) { + _spiSettings = spiSettings; + _spiTransaction = true; + + begin(spiPort, csPin); +} // begin +#endif +/* + * Set up the SPI communication with the SerLCD. + */ +void Sparkfun_OpenLCD::begin(SPIClass &spiPort, byte csPin) { + _csPin = csPin; + + pinMode(csPin, OUTPUT); //set pin to output, in case user forgot + digitalWrite(csPin, HIGH); //deselect dispaly, in case user forgot + + _spiPort = &spiPort; //Grab the port the user wants us to use + _i2cPort = NULL; //Set to null to be safe + _serialPort = NULL; //Set to null to be safe + + _spiPort->begin(); //call begin, in case the user forgot + + //Call init function since display may have been left in unknown state + init(); +} // begin +//private functions for serial transmission +/* + * Begin transmission to the device + */ +void Sparkfun_OpenLCD::beginTransmission() { + //do nothing if using serialPort + if (_i2cPort) { + _i2cPort->beginTransmission(_i2cAddr); // transmit to device + } else if (_spiPort) { +#ifdef SPI_HAS_TRANSACTION + if (_spiTransaction) { + _spiPort->beginTransaction(_spiSettings); //gain control of the SPI bus + } //if _spiSettings +#endif + digitalWrite(_csPin, LOW); + delay(10); //wait a bit for display to enable + } // if-else +} //beginTransmission +/* + * Send data to the device + * + * data - byte to send + */ + void Sparkfun_OpenLCD::transmit(uint8_t data) { + if (_i2cPort) { + _i2cPort->write(data); // transmit to device + } else if (_serialPort){ + _serialPort->write(data); + } else if (_spiPort) { + _spiPort->transfer(data); + } // if-else + } //transmit +/* + * Begin transmission to the device + */ +void Sparkfun_OpenLCD::endTransmission() { + //do nothing if using Serial port + if (_i2cPort) { + _i2cPort->endTransmission(); // transmit to device + } else if (_spiPort) { + digitalWrite(_csPin, HIGH); //disable display +#ifdef SPI_HAS_TRANSACTION + if (_spiTransaction) { + _spiPort->endTransaction(); //let go of the SPI bus + } //if _spiSettings +#endif + delay(10); //wait a bit for display to disable + } // if-else +} //beginTransmission +/* + * Initialize the display + * + */ +void Sparkfun_OpenLCD::init() { + beginTransmission(); + transmit(SPECIAL_COMMAND); //Send special command character + transmit(LCD_DISPLAYCONTROL | _displayControl); //Send the display command + transmit(SPECIAL_COMMAND); //Send special command character + transmit(LCD_ENTRYMODESET | _displayMode); //Send the entry mode command + transmit(SETTING_COMMAND); //Put LCD into setting mode + transmit(CLEAR_COMMAND); //Send clear display command + endTransmission(); //Stop transmission + delay(50); //let things settle a bit + } //init + /* + * Send a command to the display. + * Used by other functions. + * + * byte command to send + */ + void Sparkfun_OpenLCD::command(byte command) { + beginTransmission(); // transmit to device + transmit(SETTING_COMMAND); //Put LCD into setting mode + transmit(command); //Send the command code + endTransmission(); //Stop transmission + + delay(10); //Hang out for a bit +} + +/* + * Send a special command to the display. Used by other functions. + * + * byte command to send + */ +void Sparkfun_OpenLCD::specialCommand(byte command) { + beginTransmission(); // transmit to device + transmit(SPECIAL_COMMAND); //Send special command character + transmit(command); //Send the command code + endTransmission(); //Stop transmission + + delay(50); //Wait a bit longer for special display commands +} +/* + * Send multiple special commands to the display. + * Used by other functions. + * + * byte command to send + * byte count number of times to send + */ +void Sparkfun_OpenLCD::specialCommand(byte command, byte count) { + beginTransmission(); // transmit to device + + for (int i = 0; i < count; i++) { + transmit(SPECIAL_COMMAND); //Send special command character + transmit(command); //Send command code + } // for + endTransmission(); //Stop transmission + + delay(50); //Wait a bit longer for special display commands +} + +/* + * Send the clear command to the display. This clears the + * display and forces the cursor to return to the beginning + * of the display. + */ +void Sparkfun_OpenLCD::clear() { + command(CLEAR_COMMAND); + delay(10); // a little extra delay after clear +} +/* + * Send the home command to the display. This returns the cursor + * to return to the beginning of the display, without clearing + * the display. + */ +void Sparkfun_OpenLCD::home() { + specialCommand(LCD_RETURNHOME); +} +/* + * Set the cursor position to a particular column and row. + * + * column - byte 0 to 19 + * row - byte 0 to 3 + * + * returns: boolean true if cursor set. + */ +void Sparkfun_OpenLCD::setCursor(byte col, byte row) { + int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; + + //kepp variables in bounds + row = max(0, row); //row cannot be less than 0 + row = min(row, MAX_ROWS-1); //row cannot be greater than max rows + + //send the command + specialCommand(LCD_SETDDRAMADDR | (col + row_offsets[row])); +} // setCursor + +/* + * Create a customer character + * byte location - character number 0 to 7 + * byte[] charmap - byte array for character + */ +void Sparkfun_OpenLCD::createChar(byte location, byte charmap[]) { + location &= 0x7; // we only have 8 locations 0-7 + beginTransmission(); + //Semd request to create a customer character + transmit(SETTING_COMMAND); //Put LCD into setting mode + transmit(27 + location); + for (int i = 0; i < 8; i++) { + transmit(charmap[i]); + } // for + endTransmission(); + delay(50); //This takes a bit longer +} +/* + * Write a customer character to the display + * + * byte location - character number 0 to 7 + */ +void Sparkfun_OpenLCD::writeChar(byte location) { + location &= 0x7; // we only have 8 locations 0-7 + + command(35 + location); +} + +/* + * Write a byte to the display. + * Required for Print. + */ +size_t Sparkfun_OpenLCD::write(uint8_t b) { + beginTransmission(); // transmit to device + transmit(b); + endTransmission(); //Stop transmission + delay(10); // wait a bit + } // write +/* + * Write a character buffer to the display. + * Required for Print. + */ +size_t Sparkfun_OpenLCD::write(const uint8_t *buffer, size_t size) { + size_t n = 0; + beginTransmission(); // transmit to device + while (size--) { + transmit(*buffer++); + n++; + } //while + endTransmission(); //Stop transmission + delay(10); // + return n; +} //write +/* + * Write a string to the display. + * Required for Print. + */ + size_t Sparkfun_OpenLCD::write(const char *str) { + if (str == NULL) return 0; + return write((const uint8_t *)str, strlen(str)); +} + + /* + * Turn the display off quickly. + */ + void Sparkfun_OpenLCD::noDisplay(){ + _displayControl &= ~LCD_DISPLAYON; + specialCommand(LCD_DISPLAYCONTROL | _displayControl); + } // noDisplay + +/* + * Turn the display on quickly. + */ +void Sparkfun_OpenLCD::display() { + _displayControl |= LCD_DISPLAYON; + specialCommand(LCD_DISPLAYCONTROL | _displayControl); + } // display + /* + * Turn the underline cursor off. + */ + void Sparkfun_OpenLCD::noCursor(){ + _displayControl &= ~LCD_CURSORON; + specialCommand(LCD_DISPLAYCONTROL | _displayControl); + } // noCursor + +/* + * Turn the underline cursor on. + */ +void Sparkfun_OpenLCD::cursor() { + _displayControl |= LCD_CURSORON; + specialCommand(LCD_DISPLAYCONTROL | _displayControl); + } // cursor + + /* + * Turn the blink cursor off. + */ + void Sparkfun_OpenLCD::noBlink(){ + _displayControl &= ~LCD_BLINKON; + specialCommand(LCD_DISPLAYCONTROL | _displayControl); + } // noBlink + +/* + * Turn the blink cursor on. + */ +void Sparkfun_OpenLCD::blink() { + _displayControl |= LCD_BLINKON; + specialCommand(LCD_DISPLAYCONTROL | _displayControl); + } // blink + +/* + * Scroll the display one character to the left, without + * changing the text + */ +void Sparkfun_OpenLCD::scrollDisplayLeft() { + specialCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT); + } // scrollDisplayLeft + +/* + * Scroll the display multiple characters to the left, without + * changing the text + * + * count byte - number of characters to scroll + */ +void Sparkfun_OpenLCD::scrollDisplayLeft(byte count) { + specialCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT, count); + } // scrollDisplayLeft + +/* + * Scroll the display one character to the right, without + * changing the text + */ +void Sparkfun_OpenLCD::scrollDisplayRight() { + specialCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT); + } // scrollDisplayRight + +/* + * Scroll the display multiple characters to the right, without + * changing the text + * + * count byte - number of characters to scroll + */ +void Sparkfun_OpenLCD::scrollDisplayRight(byte count) { + specialCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT, count); + } // scrollDisplayRight + +/* + * Move the cursor one character to the left. + */ +void Sparkfun_OpenLCD::moveCursorLeft() { + specialCommand(LCD_CURSORSHIFT | LCD_CURSORMOVE | LCD_MOVELEFT); +} // moveCursorLeft + +/* + * Move the cursor multiple characters to the left. + * + * count byte - number of characters to move + */ +void Sparkfun_OpenLCD::moveCursorLeft(byte count) { + specialCommand(LCD_CURSORSHIFT | LCD_CURSORMOVE | LCD_MOVELEFT, count); +} // moveCursorLeft + +/* + * Move the cursor one character to the right. + */ +void Sparkfun_OpenLCD::moveCursorRight() { + specialCommand(LCD_CURSORSHIFT | LCD_CURSORMOVE | LCD_MOVERIGHT); +} // moveCursorRight + +/* + * Move the cursor multiple characters to the right. + * + * count byte - number of characters to move + */ +void Sparkfun_OpenLCD::moveCursorRight(byte count) { + specialCommand(LCD_CURSORSHIFT | LCD_CURSORMOVE | LCD_MOVERIGHT, count); +} // moveCursorRight + + + +/* + * Use a standard hex rgb value (0x00000000 to 0x00FFFFFF) to set + * the backlight color. + * + * The encoded long value has form (0x00RRGGBB) where RR, GG and BB + * are red, green, blue byte values in hex. The remaining two most + * significant bytes of the long value are ignored. + * + * rgb - unsigned long hex encoded rgb value. + */ +void Sparkfun_OpenLCD::setBacklight(unsigned long rgb) { + // convert from hex triplet to byte values + byte r = (rgb >> 16) & 0x0000FF; + byte g = (rgb >> 8) & 0x0000FF; + byte b = rgb & 0x0000FF; + + setBacklight(r, g, b); +} + +#ifdef FIRMWARE_HAS_RGB_COMMAND +/* + * Uses a standard rgb byte triplit eg. (255, 0, 255) to + * set the backlight color. + * + * This function requires newer firmware with the set rgb command + */ +void Sparkfun_OpenLCD::setBacklight(byte r, byte g, byte b) { + //send commands to the display to set backlights + beginTransmission(); // transmit to device + transmit(SETTING_COMMAND); //Send special command character + transmit(SET_RGB_COMMAND); //Send the set RGB character '+' or plus + transmit(r); //Send the red value + transmit(g); //Send the green value + transmit(b); //Send the blue value + endTransmission(); //Stop transmission + delay(10); + } // setBacklight +#else +/* + * Uses a standard rgb byte triplit eg. (255, 0, 255) to + * set the backlight color. + * + * This function uses only original firmware commands + */ +void Sparkfun_OpenLCD::setBacklight(byte r, byte g, byte b) { + // map the byte value range to backlight command range + byte red = 128 + map(r, 0, 255, 0, 29); + byte green = 158 + map(g, 0, 255, 0, 29); + byte blue = 188 + map(b, 0, 255, 0, 29); + + + //send commands to the display to set backlights + beginTransmission(); // transmit to device + + //Turn display off to hide confirmation messages + _displayControl &= ~LCD_DISPLAYON; + transmit(SPECIAL_COMMAND); //Send special command character + transmit(LCD_DISPLAYCONTROL | _displayControl); + + //Set the red, green and blue values + transmit(SETTING_COMMAND); //Set red backlight amount + transmit(red); + transmit(SETTING_COMMAND); //Set green backlight amount + transmit(green); + transmit(SETTING_COMMAND); //Set blue backlight amount + transmit(blue); + + //Turn display back on and end + _displayControl |= LCD_DISPLAYON; + transmit(SPECIAL_COMMAND); //Send special command character + transmit(LCD_DISPLAYCONTROL | _displayControl); //Turn display on as before + endTransmission(); //Stop transmission + delay(50); //This one is a bit slow +} // setBacklight +#endif + +/* + * Set the text to flow from left to right. This is the direction + * that is common to most Western languages. + */ +void Sparkfun_OpenLCD::leftToRight() { + _displayMode |= LCD_ENTRYLEFT; + specialCommand(LCD_ENTRYMODESET | _displayMode); +} // leftToRight + +/* + * Set the text to flow from right to left. + */ +void Sparkfun_OpenLCD::rightToLeft() { + _displayMode &= ~LCD_ENTRYLEFT; + specialCommand(LCD_ENTRYMODESET | _displayMode); +} //rightToLeft + +/* + * Turn autoscrolling on. This will 'right justify' text from + * the cursor. + */ +void Sparkfun_OpenLCD::autoscroll() { + _displayMode |= LCD_ENTRYSHIFTINCREMENT; + specialCommand(LCD_ENTRYMODESET | _displayMode); +} //autoscroll +/* + * Turn autoscrolling off. + */ +void Sparkfun_OpenLCD::noAutoscroll() { + _displayMode &= ~LCD_ENTRYSHIFTINCREMENT; + specialCommand(LCD_ENTRYMODESET | _displayMode); +} //noAutoscroll + +/* + * Change the contrast from 0 to 255. 120 is default. + * + * byte new_val - new contrast value + */ +void Sparkfun_OpenLCD::setContrast(byte new_val) { + //send commands to the display to set backlights + beginTransmission(); // transmit to device + transmit(SETTING_COMMAND); //Send contrast command + transmit(CONTRAST_COMMAND); //0x18 + transmit(new_val); //Send new contrast value + endTransmission(); //Stop transmission + + delay(10); //Wait a little bit +} //setContrast + +/* + * Change the I2C Address. 0x72 is the default. + * Note that this change is persistent. If anything + * goes wrong you may need to do a hardware reset + * to unbrick the display. + * + * byte new_addr - new i2c address + */ +void Sparkfun_OpenLCD::setAddress(byte new_addr) { + //send commands to the display to set backlights + beginTransmission(); // transmit to device on old address + transmit(SETTING_COMMAND); //Send contrast command + transmit(ADDRESS_COMMAND); //0x19 + transmit(new_addr); //Send new contrast value + endTransmission(); //Stop transmission + + //Update our own address so we can still talk to the display + _i2cAddr = new_addr; + + + delay(50); //This may take awhile +} //setContrast \ No newline at end of file diff --git a/src/Sparkfun_OpenLCD/Sparkfun_OpenLCD.h b/src/Sparkfun_OpenLCD/Sparkfun_OpenLCD.h new file mode 100644 index 0000000..fe2c1e0 --- /dev/null +++ b/src/Sparkfun_OpenLCD/Sparkfun_OpenLCD.h @@ -0,0 +1,121 @@ +#ifndef SPARKFUN_OPEN_LCD_H +#define SPARKFUN_OPEN_LCD_H + +#include +#include +#include +#include + +//Uncomment next line to use the RGB backlight command in newer firmware, comment next line if using originl firmware without command +#define FIRMWARE_HAS_RGB_COMMAND + +#define DISPLAY_ADDRESS1 0x72 //This is the default address of the OpenLCD +#define MAX_ROWS 4 +#define MAX_COLUMNS 20 + +//OpenLCD command characters +#define SPECIAL_COMMAND 254 //Magic number for sending a special command +#define SETTING_COMMAND 0x7C //124, |, the pipe character: The command to change settings: baud, lines, width, backlight, splash, etc + +//OpenLCD commands +#define CLEAR_COMMAND 0x2D //45, -, the dash character: command to clear and home the display +#define CONTRAST_COMMAND 0x18 //Command to change the contrast setting +#define ADDRESS_COMMAND 0x19 //Command to change the i2c address +#define SET_RGB_COMMAND 0x2B //43, +, the plus character: command to set backlight RGB value + + +// special commands +#define LCD_RETURNHOME 0x02 +#define LCD_ENTRYMODESET 0x04 +#define LCD_DISPLAYCONTROL 0x08 +#define LCD_CURSORSHIFT 0x10 +#define LCD_SETDDRAMADDR 0x80 + +// flags for display entry mode +#define LCD_ENTRYRIGHT 0x00 +#define LCD_ENTRYLEFT 0x02 +#define LCD_ENTRYSHIFTINCREMENT 0x01 +#define LCD_ENTRYSHIFTDECREMENT 0x00 + +// flags for display on/off control +#define LCD_DISPLAYON 0x04 +#define LCD_DISPLAYOFF 0x00 +#define LCD_CURSORON 0x02 +#define LCD_CURSOROFF 0x00 +#define LCD_BLINKON 0x01 +#define LCD_BLINKOFF 0x00 + +// flags for display/cursor shift +#define LCD_DISPLAYMOVE 0x08 +#define LCD_CURSORMOVE 0x00 +#define LCD_MOVERIGHT 0x04 +#define LCD_MOVELEFT 0x00 + +class Sparkfun_OpenLCD : public Print { + +public: + Sparkfun_OpenLCD(); + ~Sparkfun_OpenLCD(); + void begin(TwoWire &wirePort); + void begin(TwoWire &wirePort, byte i2c_addr); + void begin(Stream &serial); + void begin(SPIClass &spiPort, byte csPin); +//Only available for Arduino 1.6 and greater +#ifdef SPI_HAS_TRANSACTION + //pass SPISettings by value to allow settings object creation in fucntion call like examples + void begin(SPIClass &spiPort, byte csPin, SPISettings spiSettings); +#endif + void clear(); + void home(); + void setCursor(byte col, byte row); + void createChar(byte location, byte charmap[]); + void writeChar(byte location); + virtual size_t write(uint8_t); + virtual size_t write(const uint8_t *buffer, size_t size); + virtual size_t write(const char *str); + void noDisplay(); + void display(); + void noCursor(); + void cursor(); + void noBlink(); + void blink(); + void scrollDisplayLeft(); + void scrollDisplayRight(); + void scrollDisplayLeft(byte count); + void scrollDisplayRight(byte count); + void moveCursorLeft(); + void moveCursorRight(); + void moveCursorLeft(byte count); + void moveCursorRight(byte count); + void setBacklight(unsigned long rgb); + void setBacklight(byte r, byte g, byte b); + void leftToRight(); + void rightToLeft(); + void autoscroll(); + void noAutoscroll(); + void setContrast(byte new_val); + void setAddress(byte new_addr); + void command(byte command); + void specialCommand(byte command); + void specialCommand(byte command, byte count); +private: + TwoWire *_i2cPort = NULL; //The generic connection to user's chosen I2C hardware + Stream *_serialPort = NULL; //The generic connection to user's chosen serial hardware + SPIClass *_spiPort = NULL; //The generic connection to user's chosen spi hardware + +//SPI transactions only available for Arduino 1.6 and later +#ifdef SPI_HAS_TRANSACTION + SPISettings _spiSettings = SPISettings(100000, MSBFIRST, SPI_MODE0); + bool _spiTransaction = false; //since we pass by value, we need a flag +#endif + byte _csPin = 10; + byte _i2cAddr = DISPLAY_ADDRESS1; + byte _displayControl = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; + byte _displayMode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; + void init(); + void beginTransmission(); + void transmit(byte data); + void endTransmission(); +}; + +#endif \ No newline at end of file diff --git a/src/Sparkfun_OpenLCD/examples/Autoscroll/Autoscroll.ino b/src/Sparkfun_OpenLCD/examples/Autoscroll/Autoscroll.ino new file mode 100644 index 0000000..ff9ebf6 --- /dev/null +++ b/src/Sparkfun_OpenLCD/examples/Autoscroll/Autoscroll.ino @@ -0,0 +1,92 @@ +/* + Sparkfun_OpenLCD Library - Autoscroll + + Demonstrates the use of a Sparkfun AVR-Based Serial Enabled LCD + display with a Qwiic adapter. + + This sketch demonstrates the use of the autoscroll() + and noAutoscroll() functions to make new text scroll or not. + + The circuit: + * Sparkfun RGB OpenLCD Serial display connected through + * a Sparkfun Qwiic adpater to an Ardruino with a + * Qwiic shield or a Sparkfun Blackboard with Qwiic built in. + * + * The Qwiic adapter should be attached to the display as follows: + * + * Display Qwiic Qwiic Cable Color + * GND GND Black + * RAW 3.3V Red + * SDA SDA Blue + * SCL SCL Yellow + * + * Note: If you connect directly to a 5V Arduino instead, you *MUST* use + * a level-shifter to convert the i2c voltage levels down to 3.3V for the display. + + Based on the LiquidCrystal code originally by David A. Mellis + and the OpenLCD code by Nathan Seidle at Sparkfun. + + Libray modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + modified 29 Aug 2018 + by Gaston Williams + + This example code is in the public domain. + http://www.arduino.cc/en/Tutorial/LiquidCrystalAutoscroll + + More info on Qwiic here: + https://www.sparkfun.com/qwiic + + AVR-Based Serial Enabled LCDs Hookup Guide + https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide + +*/ + +// include the Sparkfun OpenLCD library code: +#include + +// initialize the library with default i2c address 0x72 +Sparkfun_OpenLCD lcd; + + +void setup() { + //Setup Wire + Wire.begin(); + //By default .begin() will set I2C SCL to Standard Speed mode of 100kHz + Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz + + // set up the LCD for I2C + lcd.begin(Wire); +} + +void loop() { + // set the cursor to (0,0): + lcd.setCursor(0, 0); + // print from 0 to 9: + for (int thisChar = 0; thisChar < 10; thisChar++) { + lcd.print(thisChar); + delay(500); + } + + // set the cursor to (16,1): + lcd.setCursor(16, 1); + // set the display to automatically scroll: + lcd.autoscroll(); + // print from 0 to 9: + for (int thisChar = 0; thisChar < 10; thisChar++) { + lcd.print(thisChar); + delay(500); + } + // turn off automatic scrolling + lcd.noAutoscroll(); + + // clear screen for the next loop: + lcd.clear(); +} + diff --git a/src/Sparkfun_OpenLCD/examples/Backlight/Backlight.ino b/src/Sparkfun_OpenLCD/examples/Backlight/Backlight.ino new file mode 100644 index 0000000..894bb97 --- /dev/null +++ b/src/Sparkfun_OpenLCD/examples/Backlight/Backlight.ino @@ -0,0 +1,107 @@ +/* + Sparkfun_OpenLCD Library - Backlight + + Demonstrates the use of a Sparkfun AVR-Based Serial Enabled LCD + display with a Qwiic adapter. + + This sketch changes the backlight color and displays text using + the OpenLCD functions. + + The circuit: + * Sparkfun RGB OpenLCD Serial display connected through + * a Sparkfun Qwiic adpater to an Ardruino with a + * Qwiic shield or a Sparkfun Blackboard with Qwiic built in. + * + * The Qwiic adapter should be attached to the display as follows: + * + * Display Qwiic Qwiic Cable Color + * GND GND Black + * RAW 3.3V Red + * SDA SDA Blue + * SCL SCL Yellow + * + * Note: If you connect directly to a 5V Arduino instead, you *MUST* use + * a level-shifter to convert the i2c voltage levels down to 3.3V for the display. + + + Based on the LiquidCrystal code originally by David A. Mellis + and the OpenLCD code by Nathan Seidle at Sparkfun. + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example created 23 Aug 2018 + by Gaston Williams + modified 29 Aug 2018 + by Gaston Williams + + This example code is in the public domain. + + More info on Qwiic here: + https://www.sparkfun.com/qwiic + + AVR-Based Serial Enabled LCDs Hookup Guide + https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide + +*/ + +// include the Sparkfun OpenLCD library code: +#include + +// initialize the library with default i2c address 0x72 +Sparkfun_OpenLCD lcd; + +void setup() { + //Setup Wire + Wire.begin(); + //By default .begin() will set I2C SCL to Standard Speed mode of 100kHz + Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz + + // set up the LCD for I2C + lcd.begin(Wire); +} + +void loop() { + //change the backlight color to various colors + lcd.setBacklight(0, 0, 0); //black is off + lcd.clear(); + lcd.print("Black (off)"); + delay(3000); + lcd.setBacklight(255, 0, 0); //bright red + lcd.clear(); + lcd.print("Red"); + delay(3000); + lcd.setBacklight(0xFF8C00); //orange + lcd.clear(); + lcd.print("Orange"); + delay(3000); + lcd.setBacklight(255, 255, 0); //bright yellow + lcd.clear(); + lcd.print("Yellow"); + delay(3000); + lcd.setBacklight(0, 255, 0); //bright green + lcd.clear(); + lcd.print("Green"); + delay(3000); + lcd.setBacklight(0, 0, 255); //bright blue + lcd.clear(); + lcd.print("Blue"); + delay(3000); + lcd.setBacklight(0x4B0082); //indigo, a kind of dark purplish blue + lcd.clear(); + lcd.print("Indigo"); + delay(3000); + lcd.setBacklight(0xA020F0); //violet + lcd.clear(); + lcd.print("Violet"); + delay(3000); + lcd.setBacklight(0x808080); //grey + lcd.clear(); + lcd.print("Grey"); + delay(3000); + lcd.setBacklight(255, 255, 255); //bright white + lcd.clear(); + lcd.print("White"); + delay(3000); +} diff --git a/src/Sparkfun_OpenLCD/examples/Basic_I2C/Basic_I2C.ino b/src/Sparkfun_OpenLCD/examples/Basic_I2C/Basic_I2C.ino new file mode 100644 index 0000000..a62abb1 --- /dev/null +++ b/src/Sparkfun_OpenLCD/examples/Basic_I2C/Basic_I2C.ino @@ -0,0 +1,86 @@ +/* + Sparkfun_OpenLCD Library - Basic I2C + + This is example code that shows how to send data over I2C to the display. + + OpenLCD is an LCD with Serial/I2C/SPI interfaces. + By: Nathan Seidle + SparkFun Electronics + Date: April 19th, 2015 + License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). + + Note: This code expects the display to be listening at the default I2C address. If your display is not at 0x72, you can + do a hardware reset. Tie the RX pin to ground and power up OpenLCD. You should see the splash screen + then "System reset Power cycle me" and the backlight will begin to blink. Now power down OpenLCD and remove + the RX/GND jumper. OpenLCD is now reset. + + To get this code to work, attached an OpenLCD to an Arduino Uno using the following pins: + SCL (OpenLCD) to A5 (Arduino) + SDA to A4 + VIN to 5V (3.3v to 9v) + GND to GND + + You can also use a Sparkfun RGB OpenLCD Serial display connected through + a Sparkfun Qwiic adpater to an Ardruino with a Qwiic shield or a Sparkfun Blackboard + with Qwiic built in. + + The Qwiic adapter should be attached to the display as follows: + Display Qwiic Qwiic Cable Color + GND GND Black + RAW 3.3V Red + SDA SDA Blue + SCL SCL Yellow + + Note: If you connect directly to a 5V Arduino instead, you *MUST* use + a level-shifter to convert the i2c voltage levels down to 3.3V for the display. + + AVR-Based Serial Enabled LCDs Hookup Guide + https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide + + The Sparkfun_OpenLCD library is based on the LiquidCrystal code originally by David A. Mellis + and the OpenLCD code by Nathan Seidle at Sparkfun. + + Sparkfun_OpenLCD library + Created 29 Aug 2018 + by Gaston Williams + + License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license) +*/ +#include +#include + +#define DISPLAY_ADDRESS1 0x72 //This is the default address of the OpenLCD + +int cycles = 0; + +// initialize the library +Sparkfun_OpenLCD lcd; + +void setup() +{ + Wire.begin(); //Join the bus as master + + //By default .begin() will set I2C SCL to Standard Speed mode of 100kHz + Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz + + Serial.begin(9600); //Start serial communication at 9600 for debug statements + Serial.println("OpenLCD Basic I2C Example Code"); + + // set up the LCD for I2C with specified address + lcd.begin(Wire,DISPLAY_ADDRESS1); + //lcd.begin(Wire); //This way uses the default address 0x72 +} + +void loop() +{ + cycles++; //Counting cycles! Yay! + //clear display- this forces the cursor to return to the beginning of the display + lcd.clear(); + lcd.print("Cycle: "); //These serial.print statements take multiple miliseconds + lcd.print(cycles); + + + delay(250); //The maximum update rate of OpenLCD is about 100Hz (10ms). A smaller delay will cause flicker +} + + diff --git a/src/Sparkfun_OpenLCD/examples/Basic_SPI/Basic_SPI.ino b/src/Sparkfun_OpenLCD/examples/Basic_SPI/Basic_SPI.ino new file mode 100644 index 0000000..933d470 --- /dev/null +++ b/src/Sparkfun_OpenLCD/examples/Basic_SPI/Basic_SPI.ino @@ -0,0 +1,73 @@ +/* + Sparkfun_OpenLCD Library - Basic SPI + + This is example code that shows how to send data over SPI to the display + using the Sparkfun_OpenLCD library. + + OpenLCD is an LCD with Serial/I2C/SPI interfaces. + By: Nathan Seidle + SparkFun Electronics + Date: April 19th, 2015 + License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). + + To get this code to work, attached an OpenLCD to an Arduino Uno using the following pins: + CS (OpenLCD) to 10 (Arduino) + SDI to 11 + SDO to 12 (optional) + SCK to 13 + VIN to 5V (3.3v to 9v) + GND to GND + + Note: Use a 3.3v Arudino, like the Pro-Mini, or if you use a 5V Arduino instead, + you *MUST* use a level-shifter to convert the SPI voltage levels down to 3.3V for the display. + + AVR-Based Serial Enabled LCDs Hookup Guide + https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide + + The Sparkfun_OpenLCD library is based on the LiquidCrystal code originally by David A. Mellis + and the OpenLCD code by Nathan Seidle at Sparkfun. + + Sparkfun_OpenLCD library + Created 29 Aug 2018 + by Gaston Williams + + License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license) +*/ +// include the Qwiic OpenLCD library code: +#include +#include + +int csPin = 10; //You can use any output pin but for this example we use 10 + +int cycles = 0; + +// initialize the library +Sparkfun_OpenLCD lcd; +void setup() +{ + pinMode(csPin, OUTPUT); + digitalWrite(csPin, HIGH); //By default, don't be selecting OpenLCD + + SPI.begin(); //Start SPI communication + + lcd.begin(SPI, csPin, SPISettings(100000, MSBFIRST, SPI_MODE0)); +//For Arduino versions before 1.6, use the two lines below instead +// SPI.setClockDivider(SPI_CLOCK_DIV128); //Slow down the master a bit +// lcd.begin(SPI, csPin); +} + +void loop() +{ + cycles++; //Counting cycles! Yay! + + lcd.clear(); + char tempString[50]; //Needs to be large enough to hold the entire string with up to 5 digits + sprintf(tempString, "Cycles: %d", cycles); + + lcd.print(tempString); + + //250ms works well + delay(250); +} + + diff --git a/src/Sparkfun_OpenLCD/examples/Basic_Serial/Basic_Serial.ino b/src/Sparkfun_OpenLCD/examples/Basic_Serial/Basic_Serial.ino new file mode 100644 index 0000000..e595d78 --- /dev/null +++ b/src/Sparkfun_OpenLCD/examples/Basic_Serial/Basic_Serial.ino @@ -0,0 +1,67 @@ +/* + Sparkfun_OpenLCD Library - Basic Serial + + This is example code that shows how to send data over Serial interface to the display + using the Sparkfun_OpenLCD library. + + OpenLCD is an LCD with Serial/I2C/SPI interfaces. + By: Nathan Seidle + SparkFun Electronics + Date: April 19th, 2015 + License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). + + To get this code to work, attached an OpenLCD to an Arduino Uno using the following pins: + RX (OpenLCD) to 7 (Arduino) + TX to 6 (optional) + VIN to 5V (3.3v to 9v) + GND to GND + + Note: Use a 3.3v Arudino, like the Pro-Mini, or if you use a 5V Arduino instead, + you *MUST* use a level-shifter to convert the voltage levels down to 3.3V for the display. + + AVR-Based Serial Enabled LCDs Hookup Guide + https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide + + The Sparkfun_OpenLCD library is based on the LiquidCrystal code originally by David A. Mellis + and the OpenLCD code by Nathan Seidle at Sparkfun. + + Sparkfun_OpenLCD library + Created 29 Aug 2018 + by Gaston Williams + + License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license) +*/ +#include +#include + +SoftwareSerial mySerial(6, 7); //RX, TX + +byte counter = 0; + +// initialize the library +Sparkfun_OpenLCD lcd; + +void setup() +{ + Serial.begin(9600); //Start serial communication at 9600 for debug statements + Serial.println("OpenLCD Basic Serial Example Code"); + + //Set up Software Serial + mySerial.begin(9600); + //Start communication with OpenLCD + lcd.begin(mySerial); +} + +void loop() +{ + //Send the clear command to the display - this returns the cursor to the beginning of the display + lcd.clear(); + + lcd.print("Hello World!"); + lcd.setCursor(0, 1); + lcd.print("Counter: "); + + lcd.print(counter++); + + delay(250); //Hang out for a bit +} diff --git a/src/Sparkfun_OpenLCD/examples/Blink/Blink.ino b/src/Sparkfun_OpenLCD/examples/Blink/Blink.ino new file mode 100644 index 0000000..fdf03bc --- /dev/null +++ b/src/Sparkfun_OpenLCD/examples/Blink/Blink.ino @@ -0,0 +1,77 @@ +/* + Sparkfun_OpenLCD Library - Blink + + Demonstrates the use of a Sparkfun AVR-Based Serial Enabled LCD + display with a Qwiic adapter. + + This sketch prints "Hello World!" to the LCD and makes the + cursor block blink. + + The circuit: + * Sparkfun RGB OpenLCD Serial display connected through + * a Sparkfun Qwiic adpater to an Ardruino with a + * Qwiic shield or a Sparkfun Blackboard with Qwiic built in. + * + * The Qwiic adapter should be attached to the display as follows: + * + * Display Qwiic Qwiic Cable Color + * GND GND Black + * RAW 3.3V Red + * SDA SDA Blue + * SCL SCL Yellow + * + * Note: If you connect directly to a 5V Arduino instead, you *MUST* use + * a level-shifter to convert the i2c voltage levels down to 3.3V for the display. + + Based on the LiquidCrystal code originally by David A. Mellis + and the OpenLCD code by Nathan Seidle at Sparkfun. + + Library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + modified 29 Aug 2018 + by Gaston Williams + + This example code is in the public domain. + http://www.arduino.cc/en/Tutorial/LiquidCrystalBlink + + More info on Qwiic here: + https://www.sparkfun.com/qwiic + + AVR-Based Serial Enabled LCDs Hookup Guide + https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide + +*/ + +// include the Sparkfun OpenLCD library code: +#include + +// initialize the library with default i2c address 0x72 +Sparkfun_OpenLCD lcd; + +void setup() { + //Setup Wire + Wire.begin(); + //By default .begin() will set I2C SCL to Standard Speed mode of 100kHz + Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz + + // set up the LCD for I2C + lcd.begin(Wire); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the blinking cursor: + lcd.noBlink(); + delay(3000); + // Turn on the blinking cursor: + lcd.blink(); + delay(3000); +} + diff --git a/src/Sparkfun_OpenLCD/examples/Cursor/Cursor.ino b/src/Sparkfun_OpenLCD/examples/Cursor/Cursor.ino new file mode 100644 index 0000000..bf4df21 --- /dev/null +++ b/src/Sparkfun_OpenLCD/examples/Cursor/Cursor.ino @@ -0,0 +1,78 @@ +/* + Sparkfun_OpenLCD Library - Cursor + + Demonstrates the use of a Sparkfun AVR-Based Serial Enabled LCD + display with a Qwiic adapter. + + This sketch prints "Hello World!" to the LCD and + uses the cursor() and noCursor() methods to turn + on and off the cursor. + + The circuit: + * Sparkfun RGB OpenLCD Serial display connected through + * a Sparkfun Qwiic adpater to an Ardruino with a + * Qwiic shield or a Sparkfun Blackboard with Qwiic built in. + * + * The Qwiic adapter should be attached to the display as follows: + * + * Display Qwiic Qwiic Cable Color + * GND GND Black + * RAW 3.3V Red + * SDA SDA Blue + * SCL SCL Yellow + * + * Note: If you connect directly to a 5V Arduino instead, you *MUST* use + * a level-shifter to convert the i2c voltage levels down to 3.3V for the display. + + Based on the LiquidCrystal code originally by David A. Mellis + and the OpenLCD code by Nathan Seidle at Sparkfun. + + Library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + modified 29 Aug 2018 + by Gaston Williams + + This example code is in the public domain. + http://www.arduino.cc/en/Tutorial/LiquidCrystalCursor + + More info on Qwiic here: + https://www.sparkfun.com/qwiic + + AVR-Based Serial Enabled LCDs Hookup Guide + https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide + +*/ + +// include the Sparkfun OpenLCD library code: +#include + +// initialize the library with default i2c address 0x72 +Sparkfun_OpenLCD lcd; + +void setup() { + //Setup Wire + Wire.begin(); + //By default .begin() will set I2C SCL to Standard Speed mode of 100kHz + Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz + + // set up the LCD for I2C + lcd.begin(Wire); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the cursor: + lcd.noCursor(); + delay(500); + // Turn on the cursor: + lcd.cursor(); + delay(500); +} + diff --git a/src/Sparkfun_OpenLCD/examples/CustomCharacter/CustomCharacter.ino b/src/Sparkfun_OpenLCD/examples/CustomCharacter/CustomCharacter.ino new file mode 100644 index 0000000..94266c1 --- /dev/null +++ b/src/Sparkfun_OpenLCD/examples/CustomCharacter/CustomCharacter.ino @@ -0,0 +1,169 @@ +/* + Sparkfun_OpenLCD Library - Custom Characters + + Demonstrates the use of a Sparkfun AVR-Based Serial Enabled LCD + display with a Qwiic adapter. + + This sketch prints "I Qwiic!" and a little dancing man + to the LCD. Since the Serial OpenLCD display uses a serial command + to display a customer character, the writeChar() function was added + for this function. + + The circuit: + * Sparkfun RGB OpenLCD Serial display connected through + * a Sparkfun Qwiic adpater to an Ardruino with a + * Qwiic shield or a Sparkfun Blackboard with Qwiic built in. + * + * 10K poterntiometer on pin A0 of arduino or blackboard + * + * The Qwiic adapter should be attached to the display as follows: + * + * Display Qwiic Qwiic Cable Color + * GND GND Black + * RAW 3.3V Red + * SDA SDA Blue + * SCL SCL Yellow + * + * Note: If you connect directly to a 5V Arduino instead, you *MUST* use + * a level-shifter to convert the i2c voltage levels down to 3.3V for the display. + + Based on the LiquidCrystal code originally by David A. Mellis + and the OpenLCD code by Nathan Seidle at Sparkfun. + + Library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example created 21 Mar 2011 + by Tom Igoe + modified 11 Nov 2013 + by Scott Fitzgerald + modified 7 Nov 2016 + by Arturo Guadalupi + modified 29 Aug 2018 + by Gaston Williams + + + Based on Adafruit's example at + https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde + + This example code is in the public domain. + http://www.arduino.cc/en/Tutorial/LiquidCrystalCustomCharacter + + Also useful: + http://icontexto.com/charactercreator/ + + More info on Qwiic here: + https://www.sparkfun.com/qwiic + + AVR-Based Serial Enabled LCDs Hookup Guide + https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide + +*/ + +// include the Sparkfun OpenLCD library code: +#include + +// initialize the library with default i2c address 0x72 +Sparkfun_OpenLCD lcd; + +// make some custom characters: +byte heart[8] = { + 0b00000, + 0b01010, + 0b11111, + 0b11111, + 0b11111, + 0b01110, + 0b00100, + 0b00000 +}; + +byte smiley[8] = { + 0b00000, + 0b00000, + 0b01010, + 0b00000, + 0b00000, + 0b10001, + 0b01110, + 0b00000 +}; + +byte frownie[8] = { + 0b00000, + 0b00000, + 0b01010, + 0b00000, + 0b00000, + 0b00000, + 0b01110, + 0b10001 +}; + +byte armsDown[8] = { + 0b00100, + 0b01010, + 0b00100, + 0b00100, + 0b01110, + 0b10101, + 0b00100, + 0b01010 +}; + +byte armsUp[8] = { + 0b00100, + 0b01010, + 0b00100, + 0b10101, + 0b01110, + 0b00100, + 0b00100, + 0b01010 +}; + +void setup() { + //Setup Wire + Wire.begin(); + //By default .begin() will set I2C SCL to Standard Speed mode of 100kHz + Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz + + // set up the LCD for I2C + lcd.begin(Wire); + + // create a new character + lcd.createChar(0, heart); + // create a new character + lcd.createChar(1, smiley); + // create a new character + lcd.createChar(2, frownie); + // create a new character + lcd.createChar(3, armsDown); + // create a new character + lcd.createChar(4, armsUp); + + // set the cursor to the top left + lcd.setCursor(0, 0); + + // Print a message to the lcd. + lcd.print("I "); + lcd.writeChar(0); // have to use writeChar since it's a serial display + lcd.print(" Qwiic! "); + lcd.writeChar(1); // have to use writeChar since it's a serial display + +} + +void loop() { + // read the potentiometer on A0: + int sensorReading = analogRead(A0); + // map the result to 200 - 1000: + int delayTime = map(sensorReading, 0, 1023, 200, 1000); + // set the cursor to the bottom row, 5th position: + lcd.setCursor(4, 1); + // draw the little man, arms down: + lcd.writeChar(3); // have to use writeChar since it's a serial display + delay(delayTime); + lcd.setCursor(4, 1); + // draw him arms up: + lcd.writeChar(4); // have to use writeChar since it's a serial display + delay(delayTime); +} diff --git a/src/Sparkfun_OpenLCD/examples/Display/Display.ino b/src/Sparkfun_OpenLCD/examples/Display/Display.ino new file mode 100644 index 0000000..8f078a0 --- /dev/null +++ b/src/Sparkfun_OpenLCD/examples/Display/Display.ino @@ -0,0 +1,82 @@ +/* + Sparkfun_OpenLCD Library - display() and noDisplay() + + Demonstrates the use of a Sparkfun AVR-Based Serial Enabled LCD + display with a Qwiic adapter. + + This sketch prints "Hello World!" to the LCD and uses the + display() and noDisplay() functions to turn on and off + the display. + + The circuit: + * Sparkfun RGB OpenLCD Serial display connected through + * a Sparkfun Qwiic adpater to an Ardruino with a + * Qwiic shield or a Sparkfun Blackboard with Qwiic built in. + * + * The Qwiic adapter should be attached to the display as follows: + * + * Display Qwiic Qwiic Cable Color + * GND GND Black + * RAW 3.3V Red + * SDA SDA Blue + * SCL SCL Yellow + * + * Note: If you connect directly to a 5V Arduino instead, you *MUST* use + * a level-shifter to convert the i2c voltage levels down to 3.3V for the display. + + + Based on the LiquidCrystal code originally by David A. Mellis + and the OpenLCD code by Nathan Seidle at Sparkfun. + + Created 18 Apr 2008 + by David A. Mellis + modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + modified 29 Aug 2018 + by Gaston Williams + + This example code is in the public domain. + http://www.arduino.cc/en/Tutorial/LiquidCrystalDisplay + + More info on Qwiic here: + https://www.sparkfun.com/qwiic + + AVR-Based Serial Enabled LCDs Hookup Guide + https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide + +*/ + +// include the Sparkfun OpenLCD library code: +#include + +// initialize the library with default i2c address 0x72 +Sparkfun_OpenLCD lcd; + +void setup() { + //Setup Wire + Wire.begin(); + //By default .begin() will set I2C SCL to Standard Speed mode of 100kHz + Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz + + // set up the LCD for I2C + lcd.begin(Wire); + + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the display: + lcd.noDisplay(); + delay(500); + // Turn on the display: + lcd.display(); + delay(500); +} + diff --git a/src/Sparkfun_OpenLCD/examples/HelloWorld/HelloWorld.ino b/src/Sparkfun_OpenLCD/examples/HelloWorld/HelloWorld.ino new file mode 100644 index 0000000..e053033 --- /dev/null +++ b/src/Sparkfun_OpenLCD/examples/HelloWorld/HelloWorld.ino @@ -0,0 +1,77 @@ +/* + Sparkfun_OpenLCD Library - Hello World + + Demonstrates the use of a Sparkfun AVR-Based Serial Enabled LCD + display with a Qwiic adapter. + + This sketch prints "Hello World!" to the LCD + and shows the time. + + The circuit: + * Sparkfun RGB OpenLCD Serial display connected through + * a Sparkfun Qwiic adpater to an Ardruino with a + * Qwiic shield or a Sparkfun Blackboard with Qwiic built in. + * + * The Qwiic adapter should be attached to the display as follows: + * + * Display Qwiic Qwiic Cable Color + * GND GND Black + * RAW 3.3V Red + * SDA SDA Blue + * SCL SCL Yellow + * + * Note: If you connect directly to a 5V Arduino instead, you *MUST* use + * a level-shifter to convert the i2c voltage levels down to 3.3V for the display. + + + Based on the LiquidCrystal code originally by David A. Mellis + and the OpenLCD code by Nathan Seidle at Sparkfun. + + modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + modified 29 Aug 2018 + by Gaston Williams + + This example code is in the public domain. + http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld + + More info on Qwiic here: + https://www.sparkfun.com/qwiic + + AVR-Based Serial Enabled LCDs Hookup Guide + https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide +*/ + +// include the Sparkfun OpenLCD library code: +#include +#include + +// initialize the library with default i2c address 0x72 +Sparkfun_OpenLCD lcd; + +void setup() { + //Setup Wire + Wire.begin(); + //By default .begin() will set I2C SCL to Standard Speed mode of 100kHz + Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz + + // set up the LCD for I2C + lcd.begin(Wire); + // Print a message to the LCD. + lcd.print("Hello, World!"); +} + +void loop() { + // set the cursor to column 0, line 1 + // (note: line 1 is the second row, since counting begins with 0): + lcd.setCursor(0, 1); + // print the number of seconds since reset: + lcd.print(millis() / 1000); +} + diff --git a/src/Sparkfun_OpenLCD/examples/MoveCursor/MoveCursor.ino b/src/Sparkfun_OpenLCD/examples/MoveCursor/MoveCursor.ino new file mode 100644 index 0000000..21c3a0e --- /dev/null +++ b/src/Sparkfun_OpenLCD/examples/MoveCursor/MoveCursor.ino @@ -0,0 +1,95 @@ +/* + Sparkfun_OpenLCD Library - Move Cursor + + Demonstrates the use of a Sparkfun AVR-Based Serial Enabled LCD + display with a Qwiic adapter. + + This sketch displays text and then moves the cursor back and forth. These + functions are not usually part of the LiquidCrystal library, but the functions + are available in the Serial OpenLCD display, so I created functions for it. + + The circuit: + * Sparkfun RGB OpenLCD Serial display connected through + * a Sparkfun Qwiic adpater to an Ardruino with a + * Qwiic shield or a Sparkfun Blackboard with Qwiic built in. + * + * The Qwiic adapter should be attached to the display as follows: + * + * Display Qwiic Qwiic Cable Color + * GND GND Black + * RAW 3.3V Red + * SDA SDA Blue + * SCL SCL Yellow + * + * Note: If you connect directly to a 5V Arduino instead, you *MUST* use + * a level-shifter to convert the i2c voltage levels down to 3.3V for the display. + + + Based on the LiquidCrystal code originally by David A. Mellis + and the OpenLCD code by Nathan Seidle at Sparkfun. + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example created 22 Aug 2018 + by Gaston Williams + modified 29 Aug 2018 + by Gaston Williams + + This example code is in the public domain. + + More info on Qwiic here: + https://www.sparkfun.com/qwiic + + AVR-Based Serial Enabled LCDs Hookup Guide + https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide + +*/ + +// include the Sparkfun OpenLCD library code: +#include + +// initialize the library with default i2c address 0x72 +Sparkfun_OpenLCD lcd; + +void setup() { + //Setup Wire + Wire.begin(); + //By default .begin() will set I2C SCL to Standard Speed mode of 100kHz + Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz + + // set up the LCD for I2C + lcd.begin(Wire); + + // clear the screen + lcd.clear(); + lcd.cursor(); + lcd.print("Watch the cursor!"); +} + +void loop() { + //move cursor left in 3 steps + lcd.moveCursorLeft(); + delay(500); + lcd.moveCursorLeft(); + delay(500); + lcd.moveCursorLeft(); + delay(500); + + //move back in one step + lcd.moveCursorRight(3); + delay(500); + + //move cursor ahead 3 places in 1 step + lcd.moveCursorRight(3); + delay(500); + + //move back in 3 steps + lcd.moveCursorLeft(); + delay(500); + lcd.moveCursorLeft(); + delay(500); + lcd.moveCursorLeft(); + delay(500); +} //loop diff --git a/src/Sparkfun_OpenLCD/examples/Scroll/Scroll.ino b/src/Sparkfun_OpenLCD/examples/Scroll/Scroll.ino new file mode 100644 index 0000000..7c57985 --- /dev/null +++ b/src/Sparkfun_OpenLCD/examples/Scroll/Scroll.ino @@ -0,0 +1,106 @@ +/* + Sparkfun_OpenLCD Library - scrollDisplayLeft() and scrollDisplayRight() + + Demonstrates the use of a Sparkfun AVR-Based Serial Enabled LCD + display with a Qwiic adapter. + + This sketch prints "Hello World!" to the LCD and uses the + scrollDisplayLeft() and scrollDisplayRight() methods to scroll + the text. + + The circuit: + * Sparkfun RGB OpenLCD Serial display connected through + * a Sparkfun Qwiic adpater to an Ardruino with a + * Qwiic shield or a Sparkfun Blackboard with Qwiic built in. + * + * The Qwiic adapter should be attached to the display as follows: + * + * Display Qwiic Qwiic Cable Color + * GND GND Black + * RAW 3.3V Red + * SDA SDA Blue + * SCL SCL Yellow + * + * Note: If you connect directly to a 5V Arduino instead, you *MUST* use + * a level-shifter to convert the i2c voltage levels down to 3.3V for the display. + + Based on the LiquidCrystal code originally by David A. Mellis + and the OpenLCD code by Nathan Seidle at Sparkfun. + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + modified 29 Aug 2018 + by Gaston Williams + + This example code is in the public domain. + http://www.arduino.cc/en/Tutorial/LiquidCrystalScroll + + More info on Qwiic here: + https://www.sparkfun.com/qwiic + + AVR-Based Serial Enabled LCDs Hookup Guide + https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide + +*/ + +// include the Sparkfun OpenLCD library code: +#include + +// initialize the library with default i2c address 0x72 +Sparkfun_OpenLCD lcd; + +void setup() { + //Setup Wire + Wire.begin(); + //By default .begin() will set I2C SCL to Standard Speed mode of 100kHz + Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz + + // set up the LCD for I2C + lcd.begin(Wire); + + // Print a message to the LCD. + lcd.print("hello, world!"); + delay(1000); +} + +void loop() { + // scroll 13 positions (string length) to the left + // to move it offscreen left: + for (int positionCounter = 0; positionCounter < 13; positionCounter++) { + // scroll one position left: + lcd.scrollDisplayLeft(); + // wait a bit: + delay(150); + } + + // scroll 29 positions (string length + display length) to the right + // to move it offscreen right: + for (int positionCounter = 0; positionCounter < 29; positionCounter++) { + // scroll one position right: + lcd.scrollDisplayRight(); + // wait a bit: + delay(150); + } + + // scroll 16 positions (display length + string length) to the left + // to move it back to center: + for (int positionCounter = 0; positionCounter < 16; positionCounter++) { + // scroll one position left: + lcd.scrollDisplayLeft(); + // wait a bit: + delay(150); + } + + // delay at the end of the full loop: + delay(1000); + +} + diff --git a/src/Sparkfun_OpenLCD/examples/SerialDisplay/SerialDisplay.ino b/src/Sparkfun_OpenLCD/examples/SerialDisplay/SerialDisplay.ino new file mode 100644 index 0000000..ba169dd --- /dev/null +++ b/src/Sparkfun_OpenLCD/examples/SerialDisplay/SerialDisplay.ino @@ -0,0 +1,85 @@ +/* + Sparkfun_OpenLCD Library - Serial Input + + Demonstrates the use of a Sparkfun AVR-Based Serial Enabled LCD + display with a Qwiic adapter. + + This sketch displays text sent over the serial port + (e.g. from the Serial Monitor) on an attached LCD. + + The circuit: + * Sparkfun RGB OpenLCD Serial display connected through + * a Sparkfun Qwiic adpater to an Ardruino with a + * Qwiic shield or a Sparkfun Blackboard with Qwiic built in. + * + * The Qwiic adapter should be attached to the display as follows: + * + * Display Qwiic Qwiic Cable Color + * GND GND Black + * RAW 3.3V Red + * SDA SDA Blue + * SCL SCL Yellow + * + * Note: If you connect directly to a 5V Arduino instead, you *MUST* use + * a level-shifter to convert the i2c voltage levels down to 3.3V for the display. + + Based on the LiquidCrystal code originally by David A. Mellis + and the OpenLCD code by Nathan Seidle at Sparkfun. + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + modified 29 Aug 2018 + by Gaston Williams + + This example code is in the public domain. + http://www.arduino.cc/en/Tutorial/LiquidCrystalSerialDisplay + + More info on Qwiic here: + https://www.sparkfun.com/qwiic + + AVR-Based Serial Enabled LCDs Hookup Guide + https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide + +*/ + +// include the Sparkfun OpenLCD library code: +#include + +// initialize the library with default i2c address 0x72 +Sparkfun_OpenLCD lcd; + +void setup() { + //Setup Wire + Wire.begin(); + //By default .begin() will set I2C SCL to Standard Speed mode of 100kHz + Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz + + // set up the LCD for I2C + lcd.begin(Wire); + + // initialize the serial communications: + Serial.begin(9600); +} + +void loop() { + // when characters arrive over the serial port... + if (Serial.available()) { + // wait a bit for the entire message to arrive + delay(100); + // clear the screen + lcd.clear(); + // read all the available characters + while (Serial.available() > 0) { + // display each character to the LCD + lcd.write(Serial.read()); + } + } +} diff --git a/src/Sparkfun_OpenLCD/examples/TextDirection/TextDirection.ino b/src/Sparkfun_OpenLCD/examples/TextDirection/TextDirection.ino new file mode 100644 index 0000000..650964e --- /dev/null +++ b/src/Sparkfun_OpenLCD/examples/TextDirection/TextDirection.ino @@ -0,0 +1,106 @@ +/* + Sparkfun_OpenLCD Library - TextDirection + + Demonstrates the use of a Sparkfun AVR-Based Serial Enabled LCD + display with a Qwiic adapter. + + This sketch demonstrates how to use leftToRight() and rightToLeft() + to move the cursor. + + The circuit: + * Sparkfun RGB OpenLCD Serial display connected through + * a Sparkfun Qwiic adpater to an Ardruino with a + * Qwiic shield or a Sparkfun Blackboard with Qwiic built in. + * + * The Qwiic adapter should be attached to the display as follows: + * + * Display Qwiic Qwiic Cable Color + * GND GND Black + * RAW 3.3V Red + * SDA SDA Blue + * SCL SCL Yellow + * + * Note: If you connect directly to a 5V Arduino instead, you *MUST* use + * a level-shifter to convert the i2c voltage levels down to 3.3V for the display. + + Based on the LiquidCrystal code originally by David A. Mellis + and the OpenLCD code by Nathan Seidle at Sparkfun. + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + modified 29 Aug 2018 + by Gaston Williams + + This example code is in the public domain. + http://www.arduino.cc/en/Tutorial/LiquidCrystalTextDirection + + More info on Qwiic here: + https://www.sparkfun.com/qwiic + +AVR-Based Serial Enabled LCDs Hookup Guide +https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide + +*/ + +// include the Sparkfun OpenLCD library code: +#include + +// initialize the library with default i2c address 0x72 +Sparkfun_OpenLCD lcd; + +int thisChar = 'a'; + +void setup() { + //Setup Wire + Wire.begin(); + //By default .begin() will set I2C SCL to Standard Speed mode of 100kHz + Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz + + // set up the LCD for I2C + lcd.begin(Wire); + + // turn on the cursor: + lcd.cursor(); +} + +void loop() { + // reverse directions at 'm': + if (thisChar == 'm') { + // go right for the next letter + lcd.rightToLeft(); + } + // reverse again at 's': + if (thisChar == 's') { + // go left for the next letter + lcd.leftToRight(); + } + // reset at 'z': + if (thisChar > 'z') { + // go to (0,0): + lcd.home(); + // start again at 0 + thisChar = 'a'; + } + // print the character + lcd.write(thisChar); + // wait a second: + delay(1000); + // increment the letter: + thisChar++; +} + + + + + + + + diff --git a/src/Sparkfun_OpenLCD/examples/setCursor/setCursor.ino b/src/Sparkfun_OpenLCD/examples/setCursor/setCursor.ino new file mode 100644 index 0000000..aad5737 --- /dev/null +++ b/src/Sparkfun_OpenLCD/examples/setCursor/setCursor.ino @@ -0,0 +1,92 @@ +/* + Sparkfun_OpenLCD Library - setCursor + + Demonstrates the use of a Sparkfun AVR-Based Serial Enabled LCD + display with a Qwiic adapter. + + This sketch prints to all the positions of the LCD using the + setCursor() method. + + The circuit: + * Sparkfun RGB OpenLCD Serial display connected through + * a Sparkfun Qwiic adpater to an Ardruino with a + * Qwiic shield or a Sparkfun Blackboard with Qwiic built in. + * + * The Qwiic adapter should be attached to the display as follows: + * + * Display Qwiic Qwiic Cable Color + * GND GND Black + * RAW 3.3V Red + * SDA SDA Blue + * SCL SCL Yellow + * + * Note: If you connect directly to a 5V Arduino instead, you *MUST* use + * a level-shifter to convert the i2c voltage levels down to 3.3V for the display. + + Based on the LiquidCrystal code originally by David A. Mellis + and the OpenLCD code by Nathan Seidle at Sparkfun. + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + modified 29 Aug 2018 + by Gaston Williams + + This example code is in the public domain. + http://www.arduino.cc/en/Tutorial/LiquidCrystalSetCursor + + More info on Qwiic here: + https://www.sparkfun.com/qwiic + + AVR-Based Serial Enabled LCDs Hookup Guide + https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide +*/ +// include the Sparkfun OpenLCD library code: +#include + +// initialize the library with default i2c address 0x72 +Sparkfun_OpenLCD lcd; + +// these constants won't change. But you can change the size of +// your LCD using them: +const int numRows = 2; +const int numCols = 16; +//const int numRows = 4; +//const int numCols = 20; + + +void setup() { + //Setup Wire + Wire.begin(); + //By default .begin() will set I2C SCL to Standard Speed mode of 100kHz + Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz + + // set up the LCD for I2C + lcd.begin(Wire); +} + +void loop() { + // loop from ASCII 'a' to ASCII 'z': + for (int thisLetter = 'a'; thisLetter <= 'z'; thisLetter++) { + // loop over the columns: + for (int thisRow = 0; thisRow < numRows; thisRow++) { + // loop over the rows: + for (int thisCol = 0; thisCol < numCols; thisCol++) { + // set the cursor position: + lcd.setCursor(thisCol, thisRow); + // print the letter: + lcd.write(thisLetter); + delay(200); + } + } + } +} + + diff --git a/src/Sparkfun_OpenLCD/keywords.txt b/src/Sparkfun_OpenLCD/keywords.txt new file mode 100644 index 0000000..25e3d11 --- /dev/null +++ b/src/Sparkfun_OpenLCD/keywords.txt @@ -0,0 +1,42 @@ +####################################### +# Syntax Coloring Map For CharacterOLED +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +Sparkfun_OpenLCD KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +begin KEYWORD2 +clear KEYWORD2 +home KEYWORD2 +print KEYWORD2 +write KEYWORD2 +setCursor KEYWORD2 +cursor KEYWORD2 +noCursor KEYWORD2 +blink KEYWORD2 +noBlink KEYWORD2 +display KEYWORD2 +noDisplay KEYWORD2 +autoscroll KEYWORD2 +noAutoscroll KEYWORD2 +leftToRight KEYWORD2 +rightToLeft KEYWORD2 +scrollDisplayLeft KEYWORD2 +scrollDisplayRight KEYWORD2 +createChar KEYWORD2 +writeChar KEYWORD2 +moveCursorLeft KEYWORD2 +moveCursorRight KEYWORD2 +setBacklight KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### +