Components and supplies
Male/Male Jumper Wires
Standard LCD - 16x2 White on Blue
Male/Female Jumper Wires
Pushbutton switch 12mm
Resistor 330 ohm
Resistor 10k ohm
Arduino Nano R3
Buzzer
5 mm LED: Red
5 mm LED: Green
Resistor 221 ohm
PCBWay Custom PCB
Tools and machines
Electric Drill
Rotary Tool
Project Box
Ruler
Glue Gun and Hot Glue
Digital Caliper
Step Drill Bit
Apps and platforms
Arduino IDE
TinkerCad
Project description
Code
LiquidCrystal_PCF8574.h
h
1/// 2/// \\file LiquidCrystal_PCF8574.h 3/// \\brief LiquidCrystal library with PCF8574 I2C adapter. 4/// 5/// \\author Matthias Hertel, http://www.mathertel.de 6/// \\copyright Copyright (c) 2014 by Matthias Hertel.\ 7 8/// This work is licensed under a BSD style license.\ 9 10/// See http://www.mathertel.de/License.aspx 11/// 12/// Copyright (c) 2005-2012 by Matthias Hertel, http://www.mathertel.de/ 13/// All rights reserved. 14/// 15/// * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 16/// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 17/// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the 18/// documentation and/or other materials provided with the distribution. Neither the name of the copyright owners nor the names of its 19/// contributors may be used to endorse or promote products derived from this software without specific prior written permission. 20/// 21/// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22/// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23/// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24/// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25/// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26/// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28 29/// \\details 30/// This is a library for driving LiquidCrystal displays (LCD) by using the I2C bus and an PCF8574 I2C adapter. 31/// This library is derived from the original Arduino LiquidCrystal library and uses the original Wire library for communication. 32/// 33/// ChangeLog: 34/// -------- 35/// * 19.10.2013 created. 36/// * 24.05.2015 Arduino Library Manager compatible. 37/// * 20.12.2016 circuito.io: 38/// * Added scrolling multiple chars to scrolling functions 39/// * Added selectLine function, same as setCursor(0, line - 1) 40/// * Added checkI2CConnection - prints to the serial monitor if connection faild. it is called inside begin. 41 42 43 44#ifndef LiquidCrystal_PCF8574_h 45#define LiquidCrystal_PCF8574_h 46 47#include <inttypes.h> 48#include "Print.h" 49 50// commands 51#define LCD_CLEARDISPLAY 0x01 52#define LCD_RETURNHOME 0x02 53#define LCD_ENTRYMODESET 0x04 54#define LCD_DISPLAYCONTROL 0x08 55#define LCD_CURSORSHIFT 0x10 56#define LCD_FUNCTIONSET 0x20 57#define LCD_SETCGRAMADDR 0x40 58#define LCD_SETDDRAMADDR 0x80 59 60// flags for display entry mode 61#define LCD_ENTRYRIGHT 0x00 62#define LCD_ENTRYLEFT 0x02 63#define LCD_ENTRYSHIFTINCREMENT 0x01 64#define LCD_ENTRYSHIFTDECREMENT 0x00 65 66// flags for display on/off control 67#define LCD_DISPLAYON 0x04 68#define LCD_DISPLAYOFF 0x00 69#define LCD_CURSORON 0x02 70#define LCD_CURSOROFF 0x00 71#define LCD_BLINKON 0x01 72#define LCD_BLINKOFF 0x00 73 74// flags for display/cursor shift 75#define LCD_DISPLAYMOVE 0x08 76#define LCD_CURSORMOVE 0x00 77#define LCD_MOVERIGHT 0x04 78#define LCD_MOVELEFT 0x00 79 80// flags for function set 81#define LCD_8BITMODE 0x10 82#define LCD_4BITMODE 0x00 83#define LCD_2LINE 0x08 84#define LCD_1LINE 0x00 85#define LCD_5x10DOTS 0x04 86#define LCD_5x8DOTS 0x00 87 88class LiquidCrystal_PCF8574 : public Print { 89public: 90 91 LiquidCrystal_PCF8574(); 92 LiquidCrystal_PCF8574(uint8_t addr); 93 94 void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); 95 void begin(uint8_t cols, uint8_t lines, uint8_t addr, uint8_t backlight); 96 bool checkI2CConnection(); 97 98 void clear(); 99 void home(); 100 101 void noDisplay(); 102 void display(); 103 void noBlink(); 104 void blink(); 105 void noCursor(); 106 void cursor(); 107 void scrollDisplayLeft(int charsToScroll, int scrollSpeed); 108 void scrollDisplayRight(int charsToScroll, int scrollSpeed); 109 void leftToRight(); 110 void rightToLeft(); 111 void autoscroll(); 112 void noAutoscroll(); 113 114 void setBacklight(uint8_t brightness); 115 116 void createChar(uint8_t, uint8_t[]); 117 void setCursor(uint8_t col, uint8_t row); 118 void selectLine(uint8_t line); 119 120 virtual size_t write(uint8_t); 121 using Print::write; 122 123private: 124 // low level functions 125 void _command(uint8_t); 126 void _send(uint8_t value, uint8_t mode); 127 void _sendNibble(uint8_t halfByte, uint8_t mode); 128 void _write2Wire(uint8_t halfByte, uint8_t mode, uint8_t enable); 129 130// NEW: 131 uint8_t _Addr; ///< Wire Address of the LCD 132 uint8_t _backlight; ///< the backlight intensity 133 134 uint8_t _displayfunction; ///< lines and dots mode 135 uint8_t _displaycontrol; ///< cursor, display, blink flags 136 uint8_t _displaymode; ///< left2right, autoscroll 137 138 uint8_t _numlines; ///< The number of rows the display supports. 139}; 140 141#endif 142
Doggie Water Bowl Refill Indicator/Monitor Project File
arduino
1#include "Arduino.h" 2#include "LiquidCrystal_PCF8574.h" 3#define 4 LCD_ADDRESS 0x27 5#define LCD_ROWS 2 6#define LCD_COLUMNS 16 7#define SCROLL_DELAY 8 150 9#define BACKLIGHT 255 10int LED1 = 2; 11int LED2 = 3; 12int BUZZ = 4; 13int 14 RST = RST; 15int switchPinCounter = 0; 16int switchPinState = 0; 17int lastSwitchPinState 18 = 0; 19 20LiquidCrystal_PCF8574 LCDi2C; 21 22const byte switchPin = 8; 23 24void 25 setup () 26{ 27 Serial.begin (115200); 28 pinMode (switchPin, INPUT); 29 pinMode 30 (RST, INPUT_PULLUP); 31 pinMode (LED1, OUTPUT); 32 pinMode (LED2, OUTPUT); 33 34 pinMode (BUZZ, OUTPUT); 35 LCDi2C.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, 36 BACKLIGHT); 37} 38 39void loop () { 40 41 switchPinState = digitalRead(switchPin); 42 43 LCDi2C.setCursor(0, 0); 44 LCDi2C.print("Refill Count: "); 45 LCDi2C.print(switchPinCounter); 46 47 48 if (switchPinState != lastSwitchPinState) { 49 if (digitalRead (switchPin) 50 == LOW) { 51 52 switchPinCounter++; 53 digitalWrite (LED1, HIGH); 54 55 digitalWrite (LED2, LOW); 56 LCDi2C.selectLine(2); 57 LCDi2C.print("Water 58 Lvl = SAFE"); 59 noTone (BUZZ); 60 } 61 lastSwitchPinState = switchPinState; 62 63 64 if (digitalRead (switchPin) == HIGH) 65 { 66 67 digitalWrite (LED2, 68 HIGH); 69 digitalWrite (LED1, LOW); 70 LCDi2C.selectLine(2); 71 LCDi2C.print("Time 72 To REFILL!!"); 73 tone (BUZZ, 1000); 74 } 75 } 76} 77
LiquidCrystal_PCF8574.h
h
1/// 2/// \\file LiquidCrystal_PCF8574.h 3/// \\brief LiquidCrystal 4 library with PCF8574 I2C adapter. 5/// 6/// \\author Matthias Hertel, http://www.mathertel.de 7/// 8 \\copyright Copyright (c) 2014 by Matthias Hertel.\ 9 10/// This work is licensed 11 under a BSD style license.\ 12 13/// See http://www.mathertel.de/License.aspx 14/// 15 16/// Copyright (c) 2005-2012 by Matthias Hertel, http://www.mathertel.de/ 17/// 18 All rights reserved. 19/// 20/// * Redistribution and use in source and binary 21 forms, with or without modification, are permitted provided that the following conditions 22 are met: 23/// * Redistributions of source code must retain the above copyright 24 notice, this list of conditions and the following disclaimer. 25/// * Redistributions 26 in binary form must reproduce the above copyright notice, this list of conditions 27 and the following disclaimer in the 28/// documentation and/or other materials 29 provided with the distribution. Neither the name of the copyright owners nor the 30 names of its 31/// contributors may be used to endorse or promote products derived 32 from this software without specific prior written permission. 33/// 34/// THIS 35 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 36 EXPRESS OR IMPLIED WARRANTIES, 37/// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 38 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 39 40/// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY 41 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 42/// EXEMPLARY, OR CONSEQUENTIAL DAMAGES 43 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 44 OF USE, DATA, OR PROFITS; 45/// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 46 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 47/// 48 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 49 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 50 51 52/// \\details 53/// 54 This is a library for driving LiquidCrystal displays (LCD) by using the I2C bus 55 and an PCF8574 I2C adapter. 56/// This library is derived from the original Arduino 57 LiquidCrystal library and uses the original Wire library for communication. 58/// 59/// 60 ChangeLog: 61/// -------- 62/// * 19.10.2013 created. 63/// * 24.05.2015 Arduino 64 Library Manager compatible. 65/// * 20.12.2016 circuito.io: 66/// * 67 Added scrolling multiple chars to scrolling functions 68/// * Added 69 selectLine function, same as setCursor(0, line - 1) 70/// * Added 71 checkI2CConnection - prints to the serial monitor if connection faild. it is called 72 inside begin. 73 74 75 76#ifndef LiquidCrystal_PCF8574_h 77#define LiquidCrystal_PCF8574_h 78 79#include 80 <inttypes.h> 81#include "Print.h" 82 83// commands 84#define LCD_CLEARDISPLAY 85 0x01 86#define LCD_RETURNHOME 0x02 87#define LCD_ENTRYMODESET 0x04 88#define 89 LCD_DISPLAYCONTROL 0x08 90#define LCD_CURSORSHIFT 0x10 91#define LCD_FUNCTIONSET 92 0x20 93#define LCD_SETCGRAMADDR 0x40 94#define LCD_SETDDRAMADDR 0x80 95 96// 97 flags for display entry mode 98#define LCD_ENTRYRIGHT 0x00 99#define LCD_ENTRYLEFT 100 0x02 101#define LCD_ENTRYSHIFTINCREMENT 0x01 102#define LCD_ENTRYSHIFTDECREMENT 103 0x00 104 105// flags for display on/off control 106#define LCD_DISPLAYON 0x04 107#define 108 LCD_DISPLAYOFF 0x00 109#define LCD_CURSORON 0x02 110#define LCD_CURSOROFF 0x00 111#define 112 LCD_BLINKON 0x01 113#define LCD_BLINKOFF 0x00 114 115// flags for display/cursor 116 shift 117#define LCD_DISPLAYMOVE 0x08 118#define LCD_CURSORMOVE 0x00 119#define 120 LCD_MOVERIGHT 0x04 121#define LCD_MOVELEFT 0x00 122 123// flags for function set 124#define 125 LCD_8BITMODE 0x10 126#define LCD_4BITMODE 0x00 127#define LCD_2LINE 0x08 128#define 129 LCD_1LINE 0x00 130#define LCD_5x10DOTS 0x04 131#define LCD_5x8DOTS 0x00 132 133class 134 LiquidCrystal_PCF8574 : public Print { 135public: 136 137 LiquidCrystal_PCF8574(); 138 139 LiquidCrystal_PCF8574(uint8_t addr); 140 141 void begin(uint8_t cols, uint8_t 142 rows, uint8_t charsize = LCD_5x8DOTS); 143 void begin(uint8_t cols, uint8_t lines, 144 uint8_t addr, uint8_t backlight); 145 bool checkI2CConnection(); 146 147 void 148 clear(); 149 void home(); 150 151 void noDisplay(); 152 void display(); 153 154 void noBlink(); 155 void blink(); 156 void noCursor(); 157 void cursor(); 158 159 void scrollDisplayLeft(int charsToScroll, int scrollSpeed); 160 void scrollDisplayRight(int 161 charsToScroll, int scrollSpeed); 162 void leftToRight(); 163 void rightToLeft(); 164 165 void autoscroll(); 166 void noAutoscroll(); 167 168 void setBacklight(uint8_t 169 brightness); 170 171 void createChar(uint8_t, uint8_t[]); 172 void setCursor(uint8_t 173 col, uint8_t row); 174 void selectLine(uint8_t line); 175 176 virtual size_t write(uint8_t); 177 178 using Print::write; 179 180private: 181 // low level functions 182 void _command(uint8_t); 183 184 void _send(uint8_t value, uint8_t mode); 185 void _sendNibble(uint8_t halfByte, 186 uint8_t mode); 187 void _write2Wire(uint8_t halfByte, uint8_t mode, uint8_t enable); 188 189// 190 NEW: 191 uint8_t _Addr; ///< Wire Address of the LCD 192 uint8_t _backlight; 193 ///< the backlight intensity 194 195 uint8_t _displayfunction; ///< lines and 196 dots mode 197 uint8_t _displaycontrol; ///< cursor, display, blink flags 198 uint8_t 199 _displaymode; ///< left2right, autoscroll 200 201 uint8_t _numlines; ///< 202 The number of rows the display supports. 203}; 204 205#endif 206
LiquidCrystal_PCF8574.cpp
c_cpp
1/// 2/// \\file LiquidCrystal_PCF8574.cpp 3/// \\brief LiquidCrystal (LCD) library with PCF8574 I2C adapter. 4/// 5/// \\author Matthias Hertel, http://www.mathertel.de 6/// \\copyright Copyright (c) 2014 by Matthias Hertel.\ 7 8/// This work is licensed under a BSD style license.\ 9 10/// See http://www.mathertel.de/License.aspx 11/// 12/// \\details 13/// This is a library for driving LiquidCrystal displays (LCD) by using the I2C bus and an PCF8574 I2C adapter. 14/// This library is derived from the original Arduino LiquidCrystal library and uses the original Wire library for communication. 15/// 16/// More documentation and source code is available at http://www.mathertel.de/Arduino 17/// 18/// ChangeLog see: LiquidCrystal_PCF8574.h 19 20#include "LiquidCrystal_PCF8574.h" 21 22#include <stdio.h> 23#include <string.h> 24#include <inttypes.h> 25#include "Arduino.h" 26#include <Wire.h> 27 28/// Definitions on how the PCF8574 is connected to the LCD 29 30/// These are Bit-Masks for the special signals and background light 31#define PCF_RS 0x01 32#define PCF_RW 0x02 33#define PCF_EN 0x04 34#define PCF_BACKLIGHT 0x08 35 36// Definitions on how the PCF8574 is connected to the LCD 37// These are Bit-Masks for the special signals and Background 38#define RSMODE_CMD 0 39#define RSMODE_DATA 1 40 41 42// When the display powers up, it is configured as follows: 43// 44// 1. Display clear 45// 2. Function set: 46// DL = 1; 8-bit interface data 47// N = 0; 1-line display 48// F = 0; 5x8 dot character font 49// 3. Display on/off control: 50// D = 0; Display off 51// C = 0; Cursor off 52// B = 0; Blinking off 53// 4. Entry mode set: 54// I/D = 1; Increment by 1 55// S = 0; No shift 56// 57// Note, however, that resetting the Arduino doesn't reset the LCD, so we 58// can't assume that its in that state when a sketch starts (and the 59// LiquidCrystal constructor is called). 60 61// modification: 62// don't use ports from Arduino, but use ports from Wire 63 64// a nibble is a half Byte 65 66// NEW: http://playground.arduino.cc//Code/LCDAPI 67// NEW: setBacklight 68 69LiquidCrystal_PCF8574::LiquidCrystal_PCF8574() 70{ 71 //_backlight = 255; 72} // LiquidCrystal_PCF8574 73 74LiquidCrystal_PCF8574::LiquidCrystal_PCF8574(uint8_t addr) 75{ 76 _Addr = addr; 77 _backlight = 0; 78} // LiquidCrystal_PCF8574 79 80void LiquidCrystal_PCF8574::begin(uint8_t cols, uint8_t lines, uint8_t addr, uint8_t backlight) 81{ 82 _backlight = backlight; 83 _Addr = addr; 84 begin(cols, lines); 85} 86 87void LiquidCrystal_PCF8574::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { 88 // cols ignored ! 89 _numlines = lines; 90 91 _displayfunction = 0; 92 93 if (lines > 1) { 94 _displayfunction |= LCD_2LINE; 95 } 96 97 // for some 1 line displays you can select a 10 pixel high font 98 if ((dotsize != 0) && (lines == 1)) { 99 _displayfunction |= LCD_5x10DOTS; 100 } 101 102 // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! 103 // according to datasheet, we need at least 40ms after power rises above 2.7V 104 // before sending commands. Arduino can turn on way befor 4.5V so we'll wait 50 105 Wire.begin(); 106 107 // initializing th display 108 _write2Wire(0x00, LOW, false); 109 delayMicroseconds(50000); 110 111 // put the LCD into 4 bit mode according to the hitachi HD44780 datasheet figure 26, pg 47 112 _sendNibble(0x03, RSMODE_CMD); 113 delayMicroseconds(4500); 114 _sendNibble(0x03, RSMODE_CMD); 115 delayMicroseconds(4500); 116 _sendNibble(0x03, RSMODE_CMD); 117 delayMicroseconds(150); 118 // finally, set to 4-bit interface 119 _sendNibble(0x02, RSMODE_CMD); 120 121 // finally, set # lines, font size, etc. 122 _command(LCD_FUNCTIONSET | _displayfunction); 123 124 // turn the display on with no cursor or blinking default 125 _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; 126 display(); 127 128 // clear it off 129 clear(); 130 131 // Initialize to default text direction (for romance languages) 132 _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; 133 // set the entry mode 134 _command(LCD_ENTRYMODESET | _displaymode); 135 136 setBacklight(_backlight); 137 checkI2CConnection(); 138} 139 140/********** high level commands, for the user! */ 141void LiquidCrystal_PCF8574::clear() 142{ 143 _command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero 144 delayMicroseconds(2000); // this command takes a long time! 145} 146 147void LiquidCrystal_PCF8574::home() 148{ 149 _command(LCD_RETURNHOME); // set cursor position to zero 150 delayMicroseconds(2000); // this command takes a long time! 151} 152 153 154/// Set the cursor to a new position. 155void LiquidCrystal_PCF8574::setCursor(uint8_t col, uint8_t row) 156{ 157 int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; 158 if ( row >= _numlines ) { 159 row = _numlines-1; // we count rows starting w/0 160 } 161 162 _command(LCD_SETDDRAMADDR | (col + row_offsets[row])); 163} 164 165/** select begining of line 166 * line - 1 for first row, 2 for second row 167 * 168 */ 169void LiquidCrystal_PCF8574::selectLine(uint8_t line) 170{ 171 setCursor(0, line - 1); 172} 173 174// Turn the display on/off (quickly) 175void LiquidCrystal_PCF8574::noDisplay() { 176 _displaycontrol &= ~LCD_DISPLAYON; 177 _command(LCD_DISPLAYCONTROL | _displaycontrol); 178} 179void LiquidCrystal_PCF8574::display() { 180 _displaycontrol |= LCD_DISPLAYON; 181 _command(LCD_DISPLAYCONTROL | _displaycontrol); 182} 183 184// Turns the underline cursor on/off 185void LiquidCrystal_PCF8574::noCursor() { 186 _displaycontrol &= ~LCD_CURSORON; 187 _command(LCD_DISPLAYCONTROL | _displaycontrol); 188} 189void LiquidCrystal_PCF8574::cursor() { 190 _displaycontrol |= LCD_CURSORON; 191 _command(LCD_DISPLAYCONTROL | _displaycontrol); 192} 193 194// Turn on and off the blinking cursor 195void LiquidCrystal_PCF8574::noBlink() { 196 _displaycontrol &= ~LCD_BLINKON; 197 _command(LCD_DISPLAYCONTROL | _displaycontrol); 198} 199void LiquidCrystal_PCF8574::blink() { 200 _displaycontrol |= LCD_BLINKON; 201 _command(LCD_DISPLAYCONTROL | _displaycontrol); 202} 203 204/** These commands scroll the display without changing the RAM 205 * charsToScroll - how many chars to scroll left 206 * scrollSpeed - define scrolling speed, im milliseconds. 207 */ 208 209void LiquidCrystal_PCF8574::scrollDisplayLeft(int charsToScroll, int scrollSpeed) { 210 for (int i=0 ; i < charsToScroll ; i++) 211 { 212 _command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT); 213 delay(scrollSpeed); 214 } 215} 216 217/** These commands scroll the display without changing the RAM 218 * charsToScroll - how many chars to scroll right 219 * scrollSpeed - define scrolling speed, im milliseconds. 220 */ 221 222void LiquidCrystal_PCF8574::scrollDisplayRight(int charsToScroll, int scrollSpeed) { 223 for (int i=0 ; i < charsToScroll ; i++) 224 { 225 _command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT); 226 delay(scrollSpeed); 227 } 228} 229 230// This is for text that flows Left to Right 231void LiquidCrystal_PCF8574::leftToRight(void) { 232 _displaymode |= LCD_ENTRYLEFT; 233 _command(LCD_ENTRYMODESET | _displaymode); 234} 235 236// This is for text that flows Right to Left 237void LiquidCrystal_PCF8574::rightToLeft(void) { 238 _displaymode &= ~LCD_ENTRYLEFT; 239 _command(LCD_ENTRYMODESET | _displaymode); 240} 241 242// This will 'right justify' text from the cursor 243void LiquidCrystal_PCF8574::autoscroll(void) { 244 _displaymode |= LCD_ENTRYSHIFTINCREMENT; 245 _command(LCD_ENTRYMODESET | _displaymode); 246} 247 248// This will 'left justify' text from the cursor 249void LiquidCrystal_PCF8574::noAutoscroll(void) { 250 _displaymode &= ~LCD_ENTRYSHIFTINCREMENT; 251 _command(LCD_ENTRYMODESET | _displaymode); 252} 253 254 255/// Setting the brightness of the background display light. 256/// The backlight can be switched on and off. 257/// The current brightness is stored in the private _backlight variable to have it available for further data transfers. 258void LiquidCrystal_PCF8574::setBacklight(uint8_t brightness) { 259 _backlight = brightness; 260 // send no data but set the background-pin right; 261 _write2Wire(0x00, RSMODE_DATA, false); 262} // setBacklight 263 264 265// Allows us to fill the first 8 CGRAM locations 266// with custom characters 267void LiquidCrystal_PCF8574::createChar(uint8_t location, uint8_t charmap[]) { 268 location &= 0x7; // we only have 8 locations 0-7 269 _command(LCD_SETCGRAMADDR | (location << 3)); 270 for (int i=0; i<8; i++) { 271 write(charmap[i]); 272 } 273} 274 275/* The write function is needed for derivation from the Print class. */ 276inline size_t LiquidCrystal_PCF8574::write(uint8_t value) { 277 _send(value, RSMODE_DATA); 278 return 1; // assume sucess 279} 280 281/* ----- low level functions ----- */ 282 283inline void LiquidCrystal_PCF8574::_command(uint8_t value) { 284 _send(value, RSMODE_CMD); 285} // _command() 286 287 288// write either command or data 289void LiquidCrystal_PCF8574::_send(uint8_t value, uint8_t mode) { 290 // separate the 4 value-nibbles 291 uint8_t valueLo = value & 0x0F; 292 uint8_t valueHi = value>>4 & 0x0F; 293 294 _sendNibble(valueHi, mode); 295 _sendNibble(valueLo, mode); 296} // _send() 297 298 299// write a nibble / halfByte with handshake 300void LiquidCrystal_PCF8574::_sendNibble(uint8_t halfByte, uint8_t mode) { 301 _write2Wire(halfByte, mode, true); 302 delayMicroseconds(1); // enable pulse must be >450ns 303 _write2Wire(halfByte, mode, false); 304 delayMicroseconds(37); // commands need > 37us to settle 305} // _sendNibble 306 307 308// private function to change the PCF8674 pins to the given value 309void LiquidCrystal_PCF8574::_write2Wire(uint8_t halfByte, uint8_t mode, uint8_t enable) { 310 // map the given values to the hardware of the I2C schema 311 uint8_t i2cData = halfByte << 4; 312 if (mode > 0) i2cData |= PCF_RS; 313 // PCF_RW is never used. 314 if (enable > 0) i2cData |= PCF_EN; 315 if (_backlight > 0) i2cData |= PCF_BACKLIGHT; 316 317 Wire.beginTransmission(_Addr); 318 Wire.write(i2cData); 319 Wire.endTransmission(); 320} // write2Wire 321 322bool LiquidCrystal_PCF8574::checkI2CConnection() 323{ 324 int error; 325 // See http://playground.arduino.cc/Main/I2cScanner 326 Wire.begin(); 327 Wire.beginTransmission(_Addr); 328 error = Wire.endTransmission(); 329 330 if (error) 331 { 332 Serial.println("LCD not found."); 333 } 334 return error; 335 336} 337 338// The End. 339
Doggie Water Bowl Refill Indicator/Monitor Project File
arduino
1#include "Arduino.h" 2#include "LiquidCrystal_PCF8574.h" 3#define LCD_ADDRESS 0x27 4#define LCD_ROWS 2 5#define LCD_COLUMNS 16 6#define SCROLL_DELAY 150 7#define BACKLIGHT 255 8int LED1 = 2; 9int LED2 = 3; 10int BUZZ = 4; 11int RST = RST; 12int switchPinCounter = 0; 13int switchPinState = 0; 14int lastSwitchPinState = 0; 15 16LiquidCrystal_PCF8574 LCDi2C; 17 18const byte switchPin = 8; 19 20void setup () 21{ 22 Serial.begin (115200); 23 pinMode (switchPin, INPUT); 24 pinMode (RST, INPUT_PULLUP); 25 pinMode (LED1, OUTPUT); 26 pinMode (LED2, OUTPUT); 27 pinMode (BUZZ, OUTPUT); 28 LCDi2C.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, BACKLIGHT); 29} 30 31void loop () { 32 33 switchPinState = digitalRead(switchPin); 34 LCDi2C.setCursor(0, 0); 35 LCDi2C.print("Refill Count: "); 36 LCDi2C.print(switchPinCounter); 37 38 if (switchPinState != lastSwitchPinState) { 39 if (digitalRead (switchPin) == LOW) { 40 41 switchPinCounter++; 42 digitalWrite (LED1, HIGH); 43 digitalWrite (LED2, LOW); 44 LCDi2C.selectLine(2); 45 LCDi2C.print("Water Lvl = SAFE"); 46 noTone (BUZZ); 47 } 48 lastSwitchPinState = switchPinState; 49 50 if (digitalRead (switchPin) == HIGH) 51 { 52 53 digitalWrite (LED2, HIGH); 54 digitalWrite (LED1, LOW); 55 LCDi2C.selectLine(2); 56 LCDi2C.print("Time To REFILL!!"); 57 tone (BUZZ, 1000); 58 } 59 } 60} 61
Downloadable files
Water Bowl Refill Schematic.
Just match the dots and names/labels and I'm sure you'd understand how it's connected.
Water Bowl Refill Schematic.
Water Bowl Refill Schematic.
Just match the dots and names/labels and I'm sure you'd understand how it's connected.
Water Bowl Refill Schematic.
Documentation
Used TinkerCad For 3D Mock-up
Used TinkerCad For 3D Mock-up
This is the layout of the PCB.
Without the grayed out parts and the connections to ground of the SWITCH and LCD.
This is the layout of the PCB.
Used TinkerCad For 3D Mock-up
Used TinkerCad For 3D Mock-up
This is the layout of the PCB.
Without the grayed out parts and the connections to ground of the SWITCH and LCD.
This is the layout of the PCB.
Comments
Only logged in users can leave comments
Heathen_Hacks-v2
0 Followers
•0 Projects
Table of contents
Intro
2
0