Commits

F Malpartida  committed 0cccc65

Added LCD ByVac - supported but not maintained since it is not an open source LCD.

  • Participants
  • Parent commits fc7ac42

Comments (0)

Files changed (4)

 // PUBLIC METHODS
 // ---------------------------------------------------------------------------
 // When the display powers up, it is configured as follows:
-//
+// 0. LCD starts in 8 bit mode
 // 1. Display clear
 // 2. Function set: 
 //    DL = 1; 8-bit interface data 
 //    S = 0; No shift 
 //
 // Note, however, that resetting the Arduino doesn't reset the LCD, so we
-// can't assume that its in that state when a sketch starts (and the
+// can't assume that its in that state when a application starts (and the
 // LiquidCrystal constructor is called).
 // A call to begin() will reinitialize the LCD.
 //
       // figure 24, pg 46
       
       // we start in 8bit mode, try to set 4 bit mode
+      // Special case of "Function Set"
       send(0x03, FOUR_BITS);
       delayMicroseconds(4500); // wait min 4.1ms
       
       // second try
       send ( 0x03, FOUR_BITS );
-      delayMicroseconds(4500); // wait min 4.1ms
+      delayMicroseconds(150); // wait min 100us
       
       // third go!
       send( 0x03, FOUR_BITS );
-      delayMicroseconds(150);
+      delayMicroseconds(150); // wait min of 100us
       
       // finally, set to 4-bit interface
-      send ( 0x02, FOUR_BITS ); 
+      send ( 0x02, FOUR_BITS );
+      delayMicroseconds(150); // wait min of 100us
+
    } 
    else 
    {
       
       // third go
       command(LCD_FUNCTIONSET | _displayfunction);
+      delayMicroseconds(150);
+
    }
    
    // finally, set # lines, font size, etc.
-   command(LCD_FUNCTIONSET | _displayfunction);  
+   command(LCD_FUNCTIONSET | _displayfunction);
+   delayMicroseconds ( 60 );  // wait more
    
    // turn the display on with no cursor or blinking default
    _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;  

File LiquidCrystal_I2C_ByVac.cpp

+// ---------------------------------------------------------------------------
+// Created by GHPS on 5/06/2012.
+// Copyright 2012 - Under creative commons license 3.0:
+//        Attribution-ShareAlike CC BY-SA
+//
+// This software is furnished "as is", without technical support, and with no 
+// warranty, express or implied, as to its usefulness for any purpose.
+//
+// Thread Safe: No
+// Extendable: Yes
+//
+// @file LiquidCrystal_I2C_ByVac.c
+// This file implements a basic liquid crystal library that comes as standard
+// in the Arduino SDK but using the extension board BV4218/BV4208 from ByVac.
+// 
+// @brief 
+// This is a basic implementation of the LiquidCrystal library of the
+// Arduino SDK. The original library has been reworked in such a way that 
+// this class implements the all methods to command an LCD based
+// on the Hitachi HD44780 and compatible chipsets using I2C extension
+// backpack BV4218 from ByVac.
+//
+// The functionality provided by this class and its base class is identical
+// to the original functionality of the Arduino LiquidCrystal library.
+//
+// @author GHPS - ghps@users.sourceforge.net
+// ---------------------------------------------------------------------------
+#if (ARDUINO <  100)
+#include <WProgram.h>
+#else
+#include <Arduino.h>
+#endif
+#include <inttypes.h>
+#include "Wire.h"
+#include "LiquidCrystal_I2C_ByVac.h"
+
+// CONSTRUCTORS
+// ---------------------------------------------------------------------------
+LiquidCrystal_I2C_ByVac::LiquidCrystal_I2C_ByVac( uint8_t lcd_Addr )
+{
+   _Addr = lcd_Addr;
+   _polarity == NEGATIVE;
+}
+
+// PUBLIC METHODS
+// ---------------------------------------------------------------------------
+
+//
+// begin
+void LiquidCrystal_I2C_ByVac::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) 
+{
+   Wire.begin();
+   LCD::begin ( cols, lines, dotsize );   
+}
+
+// User commands - users can expand this section
+//----------------------------------------------------------------------------
+// Turn the integrated backlight off/on
+
+// setBacklight
+void LiquidCrystal_I2C_ByVac::setBacklight( uint8_t value ) 
+{
+  Wire.beginTransmission(_Addr);
+  Wire.write(0x03); 					//  ByVac command code 0x03 for backlight
+  if (value==0) Wire.write(1); else Wire.write((byte)0); 	// 1 for off since polarity is NEGATIVE
+  Wire.endTransmission();
+}
+
+// Turn the contrast off/on
+
+// setContrast
+void LiquidCrystal_I2C_ByVac::setContrast( uint8_t value ) 
+{
+  Wire.beginTransmission(_Addr);
+  Wire.write(0x05); 					//  ByVac command code 0x05 for contrast
+  if (value==0) Wire.write((byte)0); else Wire.write(1); 
+  Wire.endTransmission();
+}
+
+// PRIVATE METHODS
+// ---------------------------------------------------------------------------
+
+//
+// init
+int LiquidCrystal_I2C_ByVac::init()
+{
+   int status = 0;
+   
+   // ByVac backpack initialized by onboard firmware
+   // ------------------------------------------------------------------------
+   status=1;
+   return ( status );
+}
+
+// low level data pushing commands
+//----------------------------------------------------------------------------
+
+//
+// send - write either command or data
+void LiquidCrystal_I2C_ByVac::send(uint8_t value, uint8_t mode) 
+{
+  Wire.beginTransmission(_Addr);
+  Wire.write(mode+1); // map COMMAND (0) -> ByVac command code 0x01/ DATA  (1) ->  ByVac command code 0x02
+  Wire.write(value);
+  Wire.endTransmission();
+}

File LiquidCrystal_I2C_ByVac.h

+// ---------------------------------------------------------------------------
+// Created by GHPS on 5/06/2012.
+// Copyright 2012 - Under creative commons license 3.0:
+//        Attribution-ShareAlike CC BY-SA
+//
+// This software is furnished "as is", without technical support, and with no 
+// warranty, express or implied, as to its usefulness for any purpose.
+//
+// Thread Safe: No
+// Extendable: Yes
+//
+// @file LiquidCrystal_I2C_ByVac.c
+// This file implements a basic liquid crystal library that comes as standard
+// in the Arduino SDK but using the extension board BV4218/BV4208 from ByVac.
+// 
+// @brief 
+// This is a basic implementation of the LiquidCrystal library of the
+// Arduino SDK. The original library has been reworked in such a way that 
+// this class implements the all methods to command an LCD based
+// on the Hitachi HD44780 and compatible chipsets using I2C extension
+// backpack BV4218 from ByVac.
+//
+// The functionality provided by this class and its base class is identical
+// to the original functionality of the Arduino LiquidCrystal library.
+//
+// @author GHPS - ghps-et-users-sourceforge-net
+// ---------------------------------------------------------------------------
+#ifndef LiquidCrystal_I2C_ByVac_h
+#define LiquidCrystal_I2C_ByVac_h
+#include <inttypes.h>
+#include <Print.h>
+
+#include "Wire.h"
+#include "LCD.h"
+
+
+class LiquidCrystal_I2C_ByVac : public LCD 
+{
+public:
+   
+   /*!
+    @method     
+    @abstract   Class constructor. 
+    @discussion Initializes class variables and defines the I2C address of the
+    LCD. The constructor does not initialize the LCD.
+    
+    @param      lcd_Addr[in] I2C address of the IO expansion module. For BV4218,
+    the address can be configured using the address commands (to be implemented).
+    */
+   LiquidCrystal_I2C_ByVac (uint8_t lcd_Addr);
+
+   /*!
+    @function
+    @abstract   LCD initialization and associated HW.
+    @discussion Initializes the LCD to a given size (col, row). This methods
+    initializes the LCD, therefore, it MUST be called prior to using any other
+    method from this class or parent class.
+    
+    The begin method can be overloaded if necessary to initialize any HW that 
+    is implemented by a library and can't be done during construction, here
+    we use the Wire class.
+    
+    @param      cols[in] the number of columns that the display has
+    @param      rows[in] the number of rows that the display has
+    @param      charsize[in] size of the characters of the LCD: LCD_5x8DOTS or
+    LCD_5x10DOTS.
+    */
+   virtual void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
+   
+   /*!
+    @function
+    @abstract   Send a particular value to the LCD.
+    @discussion Sends a particular value to the LCD for writing to the LCD or
+    as an LCD command.
+    
+    Users should never call this method.
+    
+    @param      value[in] Value to send to the LCD.
+    @param      mode[in] DATA - write to the LCD CGRAM, COMMAND - write a 
+    command to the LCD.
+    */
+   virtual void send(uint8_t value, uint8_t mode);
+   
+   
+   /*!
+    @function
+    @abstract   Switch-on/off the LCD backlight.
+    @discussion Switch-on/off the LCD backlight.
+    
+    @param      value: backlight mode (HIGH|LOW)
+    */
+   void setBacklight ( uint8_t value );
+ 
+   /*!
+    @function
+    @abstract   Switch-on/off the LCD contrast.
+    @discussion Switch-on/off the LCD contrast.
+
+    
+    @param      value: contrast mode (HIGH|LOW)
+    */
+   void setContrast ( uint8_t value );
+ 
+private:
+   
+   /*!
+    @method     
+    @abstract   Initializes the LCD class
+    @discussion Initializes the LCD class and IO expansion module.
+    */
+   int  init();
+   
+   /*!
+    @function
+    @abstract   Initialises class private variables
+    @discussion This is the class single point for initialising private variables.
+    
+    @param      lcd_Addr[in] I2C address of the IO expansion module. For BV4218,
+    the address can be configured using the address commands.
+    */
+    
+   uint8_t _Addr;             // I2C Address of the IO expander
+   
+};
+
+#endif

File examples/HelloWorld_byVac/HelloWorld_byVac.ino

+//#include <LiquidCrystal.h>
+//LiquidCrystal lcd(4, 7, 8, 9, 10, 11, 12);
+
+#include <Wire.h> 
+//#include <LiquidCrystal_I2C_ByVac.h>
+//LiquidCrystal_I2C_ByVac lcd(0x21); 
+
+//#include <LiquidCrystal_I2C.h>
+//LiquidCrystal_I2C lcd_1(0x27,2,1,0,4,5,6,7,backlight_pin,POSITIVE); // DF Robots
+
+//#include <LiquidCrystal_SR.h>
+//LiquidCrystal_SR lcd(14,15,4);
+
+#include <LiquidCrystal.h>
+//LiquidCrystal lcd(4, 7, 8, 9, 10, 11, 12);
+LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // LCD Shield
+
+uint8_t bell[8]  = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4};
+uint8_t note[8]  = {0x2,0x3,0x2,0xe,0x1e,0xc,0x0};
+uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};
+uint8_t heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0};
+uint8_t duck[8]  = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0};
+uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
+uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0};
+uint8_t retarrow[8] = {	0x1,0x1,0x5,0x9,0x1f,0x8,0x4};
+
+
+const byte backLightpin = 5; 
+//const byte backLightpin = 10; 
+const byte contrast_pin = 6;
+
+void setup () {
+   //lcd.begin(16,2);   
+   lcd.begin(20,4);
+   lcd.clear();
+  // lcd.backlight();
+  //   lcd.setBacklightPin(3);
+   //  lcd.setBacklight(1);
+   pinMode(backLightpin, OUTPUT);
+   analogWrite(backLightpin, 210);
+   pinMode(contrast_pin, OUTPUT);
+   analogWrite(contrast_pin, 40);
+   lcd.createChar(0, bell);
+   lcd.createChar(1, note);
+   lcd.createChar(2, clock);
+   lcd.createChar(3, heart);
+   lcd.createChar(4, duck);
+   lcd.createChar(5, check);
+   lcd.createChar(6, cross);
+   lcd.createChar(7, retarrow);
+  }
+
+// display all keycodes
+void displayKeyCodes(void) {
+  uint8_t i = 0;
+  while (1) {
+    lcd.clear();
+    lcd.print("Codes 0x"); lcd.print(i, HEX);
+    lcd.print("-0x"); lcd.print(i+16, HEX);
+    lcd.setCursor(0, 1);
+    for (int j=0; j<16; j++) {
+      lcd.write(i+j);
+    }
+    i+=16;
+    
+    delay(10000);
+  }}    
+    
+
+void loop () {
+  displayKeyCodes();
+}