2018.10.17.01

Added FEATURE_MIDAS_I2C_DISPLAY
This commit is contained in:
Anthony Good 2018-10-17 23:24:50 -04:00
parent 050aa62ab9
commit ff16cf365a
18 changed files with 1437 additions and 17 deletions

View File

@ -378,6 +378,9 @@
Added FEATURE_AZ_POSITION_MECHASOLUTION_QMC5883 - QMC5883 digital compass support using Mechasolution library at https://github.com/keepworking/Mecha_QMC5883L
Modified MechaQMC5883.cpp to get rid of compiler warning about ::read
2018.10.17.01
Added FEATURE_MIDAS_I2C_DISPLAY
All library files should be placed in directories likes \sketchbook\libraries\library1\ , \sketchbook\libraries\library2\ , etc.
Anything rotator_*.* should be in the ino directory!
@ -388,7 +391,7 @@
*/
#define CODE_VERSION "2018.05.16.01"
#define CODE_VERSION "2018.10.17.01"
#include <avr/pgmspace.h>
#include <EEPROM.h>
@ -433,6 +436,11 @@
#include <LCD.h> // required for YourDuino.com I2C LCD display
#endif
#if defined(FEATURE_MIDAS_I2C_DISPLAY)
#include <LCD_C0220BiZ.h>
#include <ST7036.h>
#endif
#ifdef FEATURE_LCD_DISPLAY
#include "rotator_k3ngdisplay.h"
#endif

View File

@ -64,11 +64,11 @@
#define FEATURE_ONE_DECIMAL_PLACE_HEADINGS
#endif
#if defined(FEATURE_4_BIT_LCD_DISPLAY) || defined(FEATURE_I2C_LCD) || defined(FEATURE_ADAFRUIT_I2C_LCD) || defined(FEATURE_YOURDUINO_I2C_LCD) || defined(FEATURE_RFROBOT_I2C_DISPLAY) || defined(FEATURE_YWROBOT_I2C_DISPLAY) || defined(FEATURE_SAINSMART_I2C_LCD)
#if defined(FEATURE_4_BIT_LCD_DISPLAY) || defined(FEATURE_I2C_LCD) || defined(FEATURE_ADAFRUIT_I2C_LCD) || defined(FEATURE_YOURDUINO_I2C_LCD) || defined(FEATURE_RFROBOT_I2C_DISPLAY) || defined(FEATURE_YWROBOT_I2C_DISPLAY) || defined(FEATURE_SAINSMART_I2C_LCD) || defined(FEATURE_MIDAS_I2C_DISPLAY)
#define FEATURE_LCD_DISPLAY
#endif
#if defined(FEATURE_ADAFRUIT_I2C_LCD) || defined(FEATURE_YOURDUINO_I2C_LCD) || defined(FEATURE_RFROBOT_I2C_DISPLAY) || defined(FEATURE_YWROBOT_I2C_DISPLAY) || defined(FEATURE_SAINSMART_I2C_LCD)
#if defined(FEATURE_ADAFRUIT_I2C_LCD) || defined(FEATURE_YOURDUINO_I2C_LCD) || defined(FEATURE_RFROBOT_I2C_DISPLAY) || defined(FEATURE_YWROBOT_I2C_DISPLAY) || defined(FEATURE_SAINSMART_I2C_LCD) || defined(FEATURE_MIDAS_I2C_DISPLAY)
#define FEATURE_I2C_LCD
#endif

View File

@ -68,7 +68,7 @@
// #define FEATURE_EL_POSITION_MEMSIC_2125
// #define FEATURE_EL_POSITION_A2_ABSOLUTE_ENCODER
// If you are using an Adafruit, Yourduino, RFRobot, YWRobot, or SainSmart display, you must also change the feature setting in rotator_k3ngdisplay.h!!!!
// And if you are using any display other than a 4 bit LCD, you must also change the feature setting in rotator_k3ngdisplay.h!!!!
// #define FEATURE_4_BIT_LCD_DISPLAY // Uncomment for classic 4 bit LCD display (most common)
// #define FEATURE_ADAFRUIT_I2C_LCD
// #define FEATURE_ADAFRUIT_BUTTONS // Uncomment this to use Adafruit I2C LCD buttons for manual AZ/EL instead of normal buttons (also set this feature in rotator_k3ngdisplay.h)
@ -76,6 +76,7 @@
// #define FEATURE_RFROBOT_I2C_DISPLAY
// #define FEATURE_YWROBOT_I2C_DISPLAY
// #define FEATURE_SAINSMART_I2C_LCD
// #define FEATURE_MIDAS_I2C_DISPLAY
// #define FEATURE_ANALOG_OUTPUT_PINS

View File

@ -66,7 +66,7 @@
//#define FEATURE_EL_POSITION_INCREMENTAL_ENCODER
//#define FEATURE_EL_POSITION_MEMSIC_2125
// If you are using an Adafruit, Yourduino, RFRobot, YWRobot, or SainSmart display, you must also change the feature setting in rotator_k3ngdisplay.h!!!!
// And if you are using any display other than a 4 bit LCD, you must also change the feature setting in rotator_k3ngdisplay.h!!!!
// #define FEATURE_4_BIT_LCD_DISPLAY // Uncomment for classic 4 bit LCD display (most common)
// #define FEATURE_ADAFRUIT_I2C_LCD
// #define FEATURE_ADAFRUIT_BUTTONS // Uncomment this to use Adafruit I2C LCD buttons for manual AZ/EL instead of normal buttons (also set this feature in rotator_k3ngdisplay.h)
@ -74,6 +74,7 @@
// #define FEATURE_RFROBOT_I2C_DISPLAY
// #define FEATURE_YWROBOT_I2C_DISPLAY
// #define FEATURE_SAINSMART_I2C_LCD
// #define FEATURE_MIDAS_I2C_DISPLAY
//#define FEATURE_SUN_PUSHBUTTON_AZ_EL_CALIBRATION
//#define FEATURE_MOON_PUSHBUTTON_AZ_EL_CALIBRATION

View File

@ -73,7 +73,7 @@
// #define FEATURE_EL_POSITION_MEMSIC_2125
// #define FEATURE_EL_POSITION_A2_ABSOLUTE_ENCODER
// And if you are using an Adafruit, Yourduino, RFRobot, YWRobot, or SainSmart display, you must also change the feature setting in rotator_k3ngdisplay.h!!!!
// And if you are using any display other than a 4 bit LCD, you must also change the feature setting in rotator_k3ngdisplay.h!!!!
#define FEATURE_4_BIT_LCD_DISPLAY // Uncomment for classic 4 bit LCD display (most common)
// #define FEATURE_ADAFRUIT_I2C_LCD
// #define FEATURE_ADAFRUIT_BUTTONS // Uncomment this to use Adafruit I2C LCD buttons for manual AZ/EL instead of normal buttons (also set this feature in rotator_k3ngdisplay.h)
@ -81,6 +81,7 @@
// #define FEATURE_RFROBOT_I2C_DISPLAY
// #define FEATURE_YWROBOT_I2C_DISPLAY
// #define FEATURE_SAINSMART_I2C_LCD
// #define FEATURE_MIDAS_I2C_DISPLAY
// #define FEATURE_ANALOG_OUTPUT_PINS

View File

@ -67,7 +67,7 @@
#define FEATURE_EL_POSITION_INCREMENTAL_ENCODER
//#define FEATURE_EL_POSITION_MEMSIC_2125
// If you are using an Adafruit, Yourduino, RFRobot, YWRobot, or SainSmart display, you must also change the feature setting in rotator_k3ngdisplay.h!!!!
// And if you are using any display other than a 4 bit LCD, you must also change the feature setting in rotator_k3ngdisplay.h!!!!
// #define FEATURE_4_BIT_LCD_DISPLAY // Uncomment for classic 4 bit LCD display (most common)
// #define FEATURE_ADAFRUIT_I2C_LCD
// #define FEATURE_ADAFRUIT_BUTTONS // Uncomment this to use Adafruit I2C LCD buttons for manual AZ/EL instead of normal buttons (also set this feature in rotator_k3ngdisplay.h)
@ -75,6 +75,7 @@
// #define FEATURE_RFROBOT_I2C_DISPLAY
// #define FEATURE_YWROBOT_I2C_DISPLAY
// #define FEATURE_SAINSMART_I2C_LCD
// #define FEATURE_MIDAS_I2C_DISPLAY
//#define FEATURE_ANALOG_OUTPUT_PINS

View File

@ -1,7 +1,7 @@
#ifndef K3NG_DISPLAY_H
#define K3NG_DISPLAY_H
// K3NG_DISPLAY_LIBRARY_VERSION "2018.03.08.01"
// K3NG_DISPLAY_LIBRARY_VERSION "2018.10.17.01"
#if defined(ARDUINO) && ARDUINO >= 100
@ -34,7 +34,11 @@
#if defined(FEATURE_YOURDUINO_I2C_LCD)
#include <LCD.h>
#endif
#if defined(FEATURE_MIDAS_I2C_DISPLAY)
//#include <lcd.h>
#include <LCD_C0220BiZ.h>
#include <ST7036.h>
#endif
#if defined(FEATURE_YOURDUINO_I2C_LCD)
@ -71,6 +75,9 @@
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin, BACKLIGHT_PIN, POSITIVE);
#endif //FEATURE_SAINSMART_I2C_LCD
#if defined(FEATURE_MIDAS_I2C_DISPLAY)
ST7036 lcd = ST7036 ( 2, 16, 120 );
#endif
int display_columns = 0;
uint8_t display_rows = 0;
@ -110,10 +117,15 @@ K3NGdisplay::K3NGdisplay(int _display_columns, int _display_rows, int _update_ti
void K3NGdisplay::initialize(){
#if !defined(FEATURE_MIDAS_I2C_DISPLAY)
lcd.begin(display_columns, display_rows); // if you are getting an error on this line and do not have
// any of the LCD display features enabled, remove
// k3ngdisplay.h and k3ngdisplay.cpp from your ino directory
#endif
#if defined(FEATURE_MIDAS_I2C_DISPLAY)
lcd.init();
#endif
#ifdef FEATURE_YOURDUINO_I2C_LCD
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);

View File

@ -23,6 +23,7 @@
// #define FEATURE_YWROBOT_I2C_DISPLAY
// #define FEATURE_SAINSMART_I2C_LCD
// #define FEATURE_ADAFRUIT_BUTTONS
// #define FEATURE_MIDAS_I2C_DISPLAY
// #define OPTION_RFROBOT_I2C_DISPLAY_BACKLIGHT_OFF
@ -64,7 +65,7 @@
#include "rotator.h"
#endif
#define K3NG_DISPLAY_LIBRARY_VERSION "2018.03.08.01"
#define K3NG_DISPLAY_LIBRARY_VERSION "2018.10.17.01"
#define MAX_SCREEN_BUFFER_COLUMNS 20
#define MAX_SCREEN_BUFFER_ROWS 4

View File

@ -18,8 +18,8 @@
#define rotate_cw_ccw_pwm 0 // optional - PWM on CW and CCW output - set to 0 to disable (must be PWM capable pin)
#define rotate_cw_freq 0 // optional - CW variable frequency output
#define rotate_ccw_freq 0 // optional - CCW variable frequency output
#define button_cw 0 // normally open button to ground for manual CW rotation (schematic pin: A1)
#define button_ccw 0 // normally open button to ground for manual CCW rotation (schematic pin: A2)
#define button_cw 0 // normally open button to ground for manual CW rotation (schematic pin: A2)
#define button_ccw 0 // normally open button to ground for manual CCW rotation (schematic pin: A3)
#define serial_led 0 // LED blinks when command is received on serial port (set to 0 to disable)
#define rotator_analog_az A0 // reads analog azimuth voltage from rotator - pin 4 on Yaesu connector
#define azimuth_speed_voltage 0 // optional - PWM output for speed control voltage feed into rotator (on continually unlike rotate_cw_pwm and rotate_ccw_pwm)

View File

@ -9,8 +9,8 @@
#define rotate_cw 6 // goes high to activate rotator R (CW) rotation - pin 1 on Yaesu connector
#define rotate_ccw 7 // goes high to activate rotator L (CCW) rotation - pin 2 on Yaesu connector
#define button_cw A2 // normally open button to ground for manual CW rotation (schematic pin: A1)
#define button_ccw A3 // normally open button to ground for manual CCW rotation (schematic pin: A2)
#define button_cw A2 // normally open button to ground for manual CW rotation (schematic pin: A2)
#define button_ccw A3 // normally open button to ground for manual CCW rotation (schematic pin: A3)
#define serial_led 0 // LED blinks when command is received on serial port (set to 0 to disable)
#define rotator_analog_az A0 // reads analog azimuth voltage from rotator - pin 4 on Yaesu connector
#define brake_az 0 // goes high to disengage azimuth brake (set to 0 to disable)

View File

@ -0,0 +1,62 @@
// ---------------------------------------------------------------------------
// Created by Francisco Malpartida on 20/08/11.
// Copyright 2011 - 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: No
//
// @file LCD_C0220BiZ.cpp
// Display class implementation of the LCD API 1.0
//
// @brief Based on the LCD API 1.0 by dale@wentztech.com
// This library implements the driver to drive the Newhaven Display
// NHDC0220BiZFSWFBW3V3M. The display is build around the ST7036
// i2c LCD controller. This is a 3.3V display.
// I2C displays based on the ST7032i should also be compatible.
//
// Other compatible displays:
// - NHDC0220BiZFSWFBW3V3M
// - NHD-C0220BiZ-FS(RGB)-FBW-3VM
// Non tested but should be compatible with no or little changes
// - NHD-C0216CiZ-FSW-FBW-3V3
// - NHDC0216CiZFNFBW3V
//
//
// @author F. Malpartida - fmalpartida@gmail.com
// ---------------------------------------------------------------------------
#include "LCD_C0220BiZ.h"
// Class private constants and definition
// ----------------------------------------------------------------------------
const int NUM_LINES = 2; // Number of lines in the display
const int NUM_COLUMNS = 20; // Number of columns in the display
const int I2C_ADDRS = 0x78; // I2C address of the display
// Static member variable definitions
// ----------------------------------------------------------------------------
// Static file scope variable definitions
// ----------------------------------------------------------------------------
// Private support functions
// ----------------------------------------------------------------------------
// CLASS METHODS
// ----------------------------------------------------------------------------
// Constructors:
// ---------------------------------------------------------------------------
LCD_C0220BIZ::LCD_C0220BIZ( ):ST7036 ( NUM_LINES, NUM_COLUMNS, I2C_ADDRS )
{
}
LCD_C0220BIZ::LCD_C0220BIZ(int8_t backlightPin ) :
ST7036 ( NUM_LINES, NUM_COLUMNS, I2C_ADDRS, backlightPin )
{
}

View File

@ -0,0 +1,70 @@
// ---------------------------------------------------------------------------
// Created by Francisco Malpartida on 20/08/11.
// Copyright 2011 - 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: No
//
// @file LCD_C0220BiZ.h
// NHD C0220BiZ display class definition.
//
// @brief Based on the LCD API 1.0 by dale@wentztech.com
// This library implements the driver to drive the Newhaven Display
// NHD-C0220BiZ-FSW-FBW-3V3M. The display is build around the ST7036
// i2c LCD controller. This is a 3.3V display.
// I2C displays based on the ST7632 should also be compatible.
//
// Other compatible displays:
// - NHD-C0220BiZ-FSW-FBW-3V3M
// - NHD-C0220BiZ-FS(RGB)-FBW-3VM
// Non tested but should be compatible with no or little changes
// - NHD-C0216CiZ-FSW-FBW-3V3
// - NHD-C0216CiZ-FN-FBW-3V
//
// @author F. Malpartida - fmalpartida@gmail.com
// ---------------------------------------------------------------------------
#ifndef LCD_C0220BIZ_h
#define LCD_C0220BIZ_h
#define _LCDEXPANDED // If defined turn on advanced functions
#include <Arduino.h>
#include "ST7036.h"
#define _LCD_C0220BIZ_VERSION "1.2.0"
#define _LCD_API_VERSION "1.0"
class LCD_C0220BIZ : public ST7036
{
public:
/**
Constructor for the display class
@return None
LCD_C0220BIZ( );
*/
LCD_C0220BIZ( );
/**
Constructor for the display class with backlight allowcation pin.
@param backlightPin initiales the backlight pin.
@return None
LCD_C0220BIZ(int8_t backlightPin );
*/
LCD_C0220BIZ( int8_t backlightPin );
};
#endif

View File

@ -0,0 +1,339 @@
// ---------------------------------------------------------------------------
// Created by Francisco Malpartida on 20/08/11.
// Copyright 2011 - 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: No
//
// @file LCD_C0220BiZ.cpp
// Display class implementation of the LCD API 1.0
//
// @brief Based on the LCD API 1.0 by dale@wentztech.com
// This library implements the driver to any I2C display with the ST7036
// LCD controller.
// I2C displays based on the ST7032i should also be compatible.
//
// Other compatible displays:
// - NHDC0220BiZFSWFBW3V3M
// - NHD-C0220BiZ-FS(RGB)-FBW-3VM
// Non tested but should be compatible with no or little changes
// - NHD-C0216CiZ-FSW-FBW-3V3
// - NHDC0216CiZFNFBW3V
//
//
// @author F. Malpartida - fmalpartida@gmail.com
// ---------------------------------------------------------------------------
#include <Arduino.h> //all things wiring / arduino
#include <Wire.h>
#include <string.h> //needed for strlen()
#include <inttypes.h>
#include "LCD.h"
#include "ST7036.h"
// Class private constants and definition
// ----------------------------------------------------------------------------
const int CMD_DELAY = 1; // Command delay in miliseconds
const int CHAR_DELAY = 0; // Delay between characters in miliseconds
const int PIXEL_ROWS_PER_CHAR = 8; // Number of pixel rows in the LCD character
const int MAX_USER_CHARS = 16; // Maximun number of user defined characters
// LCD Command set
const uint8_t DISP_CMD = 0x0; // Command for the display
const uint8_t RAM_WRITE_CMD = 0x40; // Write to display RAM
const uint8_t CLEAR_DISP_CMD = 0x01; // Clear display command
const uint8_t HOME_CMD = 0x02; // Set cursos at home (0,0)
const uint8_t DISP_ON_CMD = 0x0C; // Display on command
const uint8_t DISP_OFF_CMD = 0x08; // Display off Command
const uint8_t SET_DDRAM_CMD = 0x80; // Set DDRAM address command
const uint8_t CONTRAST_CMD = 0x70; // Set contrast LCD command
const uint8_t FUNC_SET_TBL0 = 0x38; // Function set - 8 bit, 2 line display 5x8, inst table 0
const uint8_t FUNC_SET_TBL1 = 0x39; // Function set - 8 bit, 2 line display 5x8, inst table 1
// LCD bitmap definition
const uint8_t CURSOR_ON_BIT = ( 1 << 1 );// Cursor selection bit in Display on cmd.
const uint8_t BLINK_ON_BIT = ( 1 << 0 );// Blink selection bit on Display on cmd.
// Driver DDRAM addressing
const uint8_t dram_dispAddr [][3] =
{
{ 0x00, 0x00, 0x00 }, // One line display address
{ 0x00, 0x40, 0x00 }, // Two line display address
{ 0x00, 0x10, 0x20 } // Three line display address
};
// Static member variable definitions
// ----------------------------------------------------------------------------
// Static file scope variable definitions
// ----------------------------------------------------------------------------
// Private support functions
// ----------------------------------------------------------------------------
// CLASS METHODS
// ----------------------------------------------------------------------------
// Constructors:
// ---------------------------------------------------------------------------
ST7036::ST7036(uint8_t num_lines, uint8_t num_col,
uint8_t i2cAddr )
{
_num_lines = num_lines;
_num_col = num_col;
_i2cAddress = ( i2cAddr >> 1 );
_cmdDelay = CMD_DELAY;
_charDelay = CHAR_DELAY;
_initialised = false;
_backlightPin = -1;
}
ST7036::ST7036(uint8_t num_lines, uint8_t num_col,
uint8_t i2cAddr, int8_t backlightPin )
{
_num_lines = num_lines;
_num_col = num_col;
_i2cAddress = ( i2cAddr >> 1 );
_cmdDelay = CMD_DELAY;
_charDelay = CHAR_DELAY;
_initialised = false;
_backlightPin = backlightPin;
// If there is a pin assigned to the BL, set it as an output
// ---------------------------------------------------------
if ( _backlightPin != 0 )
{
pinMode ( _backlightPin, OUTPUT );
}
}
// Functions: modifiers (set), selectors (get) and class methods
// ---------------------------------------------------------------------------
void ST7036::init ()
{
size_t retVal;
// Initialise the Wire library.
Wire.begin();
Wire.beginTransmission ( _i2cAddress );
Wire.write ( (byte)0x0 ); // Send command to the display
Wire.write ( FUNC_SET_TBL0 );
delay (10);
Wire.write ( FUNC_SET_TBL1 );
delay (10);
Wire.write ( 0x14 ); // Set BIAS - 1/5
Wire.write ( 0x73 ); // Set contrast low byte
Wire.write ( 0x5E ); // ICON disp on, Booster on, Contrast high byte
Wire.write ( 0x6D ); // Follower circuit (internal), amp ratio (6)
Wire.write ( 0x0C ); // Display on
Wire.write ( 0x01 ); // Clear display
Wire.write ( 0x06 ); // Entry mode set - increment
_status = Wire.endTransmission ();
if ( _status == 0 )
{
_initialised = true;
}
}
void ST7036::setDelay (int cmdDelay,int charDelay)
{
_cmdDelay = cmdDelay;
_charDelay = charDelay;
}
void ST7036::command(uint8_t value)
{
// If the LCD has been initialised correctly, write to it
if ( _initialised )
{
Wire.beginTransmission ( _i2cAddress );
Wire.write ( DISP_CMD );
Wire.write ( value );
_status = Wire.endTransmission ();
delay(_cmdDelay);
}
}
size_t ST7036::write(uint8_t value)
{
// If the LCD has been initialised correctly write to it
// -----------------------------------------------------
if ( _initialised )
{
// If it is a new line, set the cursor to the next line (1,0)
// ----------------------------------------------------------
if ( value == '\n' )
{
setCursor (1,0);
}
else
{
Wire.beginTransmission ( _i2cAddress );
Wire.write ( RAM_WRITE_CMD );
Wire.write ( value );
_status = Wire.endTransmission ();
delay(_charDelay);
}
}
}
size_t ST7036::write(const uint8_t *buffer, size_t size)
{
// If the LCD has been initialised correctly, write to it
// ------------------------------------------------------
if ( _initialised )
{
Wire.beginTransmission ( _i2cAddress );
Wire.write ( RAM_WRITE_CMD );
Wire.write ( (uint8_t *)buffer, size );
_status = Wire.endTransmission ();
delay(_charDelay);
}
}
void ST7036::clear()
{
command (CLEAR_DISP_CMD);
}
void ST7036::home()
{
command ( HOME_CMD );
}
void ST7036::on()
{
command ( DISP_ON_CMD );
}
void ST7036::off()
{
command ( DISP_OFF_CMD );
}
void ST7036::cursor_on()
{
command ( DISP_ON_CMD | CURSOR_ON_BIT );
}
void ST7036::cursor_off()
{
command ( DISP_ON_CMD & ~(CURSOR_ON_BIT) );
}
void ST7036::blink_on()
{
command ( DISP_ON_CMD | BLINK_ON_BIT );
}
void ST7036::blink_off()
{
command ( DISP_ON_CMD & ~(BLINK_ON_BIT) );
}
void ST7036::setCursor(uint8_t line_num, uint8_t x)
{
uint8_t base = 0x00;
// If the LCD has been initialised correctly, write to it
// ------------------------------------------------------
if ( _initialised )
{
// set the baseline address with respect to the number of lines of
// the display
base = dram_dispAddr[_num_lines-1][line_num];
base = SET_DDRAM_CMD + base + x;
command ( base );
}
}
#ifdef _LCDEXPANDED
uint8_t ST7036::status(){
return _status;
}
uint8_t ST7036::keypad ()
{
// NOT SUPPORTED
return 0;
}
void ST7036::load_custom_character (uint8_t char_num, uint8_t *rows)
{
// If the LCD has been initialised correctly start writing to it
// --------------------------------------------------------------------------
if ( _initialised )
{
// If it is a valid place holder for the character, write it into the
// display's CGRAM
// --------------------------------------------------------------------------
if ( char_num < MAX_USER_CHARS )
{
// Set up the display to write into CGRAM - configure LCD to use func table 0
Wire.beginTransmission ( _i2cAddress );
Wire.write ( DISP_CMD );
Wire.write ( FUNC_SET_TBL0 ); // Function set: 8 bit, 2 line display 5x8, funct tab 0
delay ( _cmdDelay );
// Set CGRAM position to write
Wire.write ( RAM_WRITE_CMD + (PIXEL_ROWS_PER_CHAR * char_num) );
_status = Wire.endTransmission ();
// If we have changed the function table and configured the CGRAM position
// write the new character to the LCD's CGRAM
// -----------------------------------------------------------------------
if ( _status == 0 )
{
write ( rows, PIXEL_ROWS_PER_CHAR ); // write the character to CGRAM
// Leave the LCD as it was - function table 1 DDRAM and set the cursor
// position to (0, 0) to start writing.
command ( FUNC_SET_TBL1 );
setCursor ( 0,0 );
}
}
}
}
void ST7036::setBacklight(uint8_t new_val)
{
// Set analog write to the pin, the routine already checks if it can
// set a PWM or not.
// -----------------------------------------------------------------
if ( _backlightPin != -1 )
{
analogWrite ( _backlightPin, new_val );
}
}
void ST7036::setContrast(uint8_t new_val)
{
// Only allow 15 levels of contrast
new_val = map ( new_val, 0, 255, 0, 15 );
command(CONTRAST_CMD + new_val);
}
#endif // _LCDEXPANDED

302
libraries/LCD_C0220BIZ/ST7036.h Executable file
View File

@ -0,0 +1,302 @@
// ---------------------------------------------------------------------------
// Created by Francisco Malpartida on 20/08/11.
// Copyright 2011 - 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: No
//
// @file ST7036.h
// NHD C0220BiZ display class definition.
//
// @brief Based on the LCD API 1.0 by dale@wentztech.com
// This library implements the driver to any I2C display with the ST7036
// LCD controller.
// I2C displays based on the ST7632 should also be compatible.
//
// Other compatible displays:
// - NHD-C0220BiZ-FSW-FBW-3V3M
// - NHD-C0220ST7036BiZ-FS(RGB)-FBW-3VM
// Non tested but should be compatible with no or little changes
// - NHD-C0216CiZ-FSW-FBW-3V3
// - NHD-C0216CiZ-FN-FBW-3V
//
// @author F. Malpartida - fmalpartida@gmail.com
// ---------------------------------------------------------------------------
#ifndef ST7036_h
#define ST7036_h
#define _LCDEXPANDED // If defined turn on advanced functions
#include <Arduino.h>
#include <inttypes.h>
#include <Wire.h>
#include "Print.h"
#include "LCD.h"
#define _ST7036_VERSION "1.2.0"
#define _LCD_API_VERSION "1.0"
class ST7036 : public Print
{
public:
/**
Constructor for the display class
@param num_lines[in] Number of lines in the display
@param num_col[in] Number of columns in the display
@param i2cAddr[in] i2c address of the display
@return None
ST7036(uint8_t num_lines, uint8_t num_col, uint8_t i2cAddr );
*/
ST7036(uint8_t num_lines, uint8_t num_col, uint8_t i2cAddr );
/**
Constructor for the display class with backlight allowcation pin.
@param num_lines[in] Number of lines in the display
@param num_col[in] Number of columns in the display
@param i2cAddr[in] i2c address of the display
@param backlightPin initiales the backlight pin.
@return None
ST7036(uint8_t num_lines, uint8_t num_col, uint8_t i2cAddr );
*/
ST7036(uint8_t num_lines, uint8_t num_col, uint8_t i2cAddr,
int8_t backlightPin );
/**
Send a command to the display
@param value[in] Command to be sent to the display
@return None
void command(uint8_t value);
*/
void command(uint8_t value);
/**
Initialise the display. Once created the object, this is the next operation
that has to be called to initialise the display into a known state. It
assumes that the I2C bus is not initialised and hence initialise the Wire
interface.
Clear the display
Set contrast levels
Set the cursor at origens (0,0)
Turn on the entire display
void init();
*/
void init();
/**
Set a different delay to that in the library. It may be needed to delay
sending commands or characters one after the other.
@param cmdDelay[in] Delay after issuing a command
@param charDelay[in] Delay after issuing a character to the LCD
@return None
void setDelay(int,int);
*/
void setDelay(int,int);
/**
This is the write method used by the Print library. It allows printing
characters to the display and new lines: print, println. It will write the
value to the display and increase the cursor.
@param value[in] character to write to the current LCD write position
@return None
virtual void write(uint8_t);
*/
virtual size_t write(uint8_t);
/**
This is the write method used by the Print library. It allows printing
characters to the display and new lines: print, println. It will write the
value to the display and increase the cursor.
@param buffer[in] buffer to write to the current LCD write position
@param size[in] size of the buffer
@return None
virtual void write(uint8_t, size_t);
*/
virtual size_t write(const uint8_t *buffer, size_t size);
/**
Clear the display and set the cursor to 0,0
void clear();
*/
void clear();
/**
Set the cursor to 0,0
void home();
*/
void home();
/**
Switch the display on. This is the default state when the display is
initialised. See. init() method
void on();
*/
void on();
/**
Switch the display off.
void off();
*/
virtual void off();
/**
Turn on the cursor "_".
void cursor_on();
*/
void cursor_on();
/**
Turn off the cursor. This is the default state when the display is
initialised.
void cursor_off();
*/
void cursor_off();
/**
Activate cursor blink.
void blink_on();
*/
void blink_on();
/**
Deactivate cursor blinking. This is the default state when the display is
initialised.
void blink_off ();
*/
void blink_off();
/**
Set the cursor at the following coordinates (Line, Col). Initial value after
initialization is (0,0).
@param Line[in] Line where to put the cursor, range (0, max display lines-1)
This display only take (0, 1)
@param Col[in] Colum where to put the cursor, range (0, max width+1)
@return None
void setCursor(uint8_t Line, uint8_t Col );
*/
void setCursor(uint8_t Line, uint8_t Col );
//
// EXPANDED FUNCTIONALITY METHODS
// --------------------------------------------------------------------------
#ifdef _LCDEXPANDED
/**
Provides the state of the LCD. This value is updated every command is sent
to the LCD or a character or a buffer is writen to the display.
@return 0 OK, 1 if data was too big to be transmitted, 2 NACK on address
transmission, 3 NACK on data transmission, 4 other error.
uint8_t status();
*/
uint8_t status();
/**
Load a custom character on the display. After adding a new character to
the character set, the coordinates are set to (0, 0). This method should
be called during initialization.
@param char_num[in] Character to load onto the display, this display supports
upto 16 user defined characters.
@param rows[in] Bitmap defining the character, the display assumes an array
of 8 bytes per character.
@return None.
uint8_t load_custom_character(uint8_t char_num, uint8_t *rows);
*/
void load_custom_character(uint8_t char_num, uint8_t *rows);
/**
NOT SUPPORTED
uint8_t keypad();
*/
uint8_t keypad();
void printstr(const char[]);
/**
Sets the backlight level. If the backlight level is connected to a PWM pin,
new_val will set a light level range between 0 and 255. If it is connected
to a normal GPIO, from 0 to 127 it will be off and from 128 to 255 the
backlight will be on. Backlight pin allocation on constructor.
@param new_val[in] Backlight level of the display. Full range will only be
available on pins with PWM support.
@return None.
uint8_t setBacklight();
*/
void setBacklight(uint8_t new_val);
/**
Sets the LCD contrast level.
@param new_val[in] The contrast range (0 to 255) has been mapped to 16
contrast levels on the display.
@return None.
uint8_t setContrast();
*/
void setContrast(uint8_t new_val);
#endif
private:
uint8_t _num_lines;
uint8_t _num_col;
uint8_t _i2cAddress;
int _cmdDelay;
int _charDelay;
bool _initialised;
uint8_t _status;
int8_t _backlightPin;
};
#endif

View File

@ -0,0 +1,143 @@
#include <Arduino.h>
#include <Wire.h>
#include "ST7036.h"
#include "LCD_C0220BiZ.h"
// ???:fmalpartida:20110821
/*!
@defined CHAR_WIDTH
@abstract Character witdth of the display, expressed in pixeles per character.
*/
#define CHAR_WIDTH 5
/*!
@defined LDR_PIN
@abstract Light Detection Resistor Analog pin.
@discussion Define the Analog channel that will be used to read a LDR.
*/
#define LDR_PIN 7
extern unsigned int __bss_end;
extern unsigned int __heap_start;
extern void *__brkval;
//LCD_C0220BIZ lcd = LCD_C0220BIZ ( );
ST7036 lcd = ST7036 ( 2, 20, 0x78 );
/*!
@const charBitmap
@abstract Define Character bitmap for the bargraph.
@discussion Defines a character bitmap to represent a bargraph on a text
display. The bitmap goes from a blank character to full black.
*/
const uint8_t charBitmap[][8] = {
{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
{ 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0 },
{ 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x0 },
{ 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x0 },
{ 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x0 },
{ 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0 }
};
/*!
@function
@abstract Return available RAM memory
@discussion This routine returns the ammount of RAM memory available after
initialising the C runtime.
@param
@result Free RAM available.
*/
static int freeMemory()
{
int free_memory;
if((int)__brkval == 0)
free_memory = ((int)&free_memory) - ((int)&__bss_end);
else
free_memory = ((int)&free_memory) - ((int)__brkval);
return free_memory;
}
/*!
@function
@abstract Braws a bargraph onto the display representing the value passed.
@discussion Draws a bargraph on the specified row using barLength characters.
@param value[in] Value to represent in the bargraph
@param row[in] Row of the LCD where to display the bargraph. Range (0, 1)
for this display.
@param barlength[in] Length of the bar, expressed in display characters.
@param start[in] Start bar character
@param end [in] End bar character
@result None
*/
static void drawBars ( int value, uint8_t row, uint8_t barLength, char start,
char end )
{
int numBars;
// Set initial titles on the display
lcd.setCursor (row, 0);
lcd.print (start);
// Calculate the size of the bar
value = map ( value, 0, 1024, 0, ( barLength - 1) * CHAR_WIDTH );
numBars = value / CHAR_WIDTH;
lcd.setCursor ( row,2 );
// Draw the bars
while ( numBars-- )
{
lcd.print ( char( (sizeof(charBitmap ) / sizeof(charBitmap[0])) - 1 ) );
}
// Draw the fractions
numBars = value % CHAR_WIDTH;
lcd.print ( char(numBars) );
lcd.setCursor (row, barLength + 1);
lcd.print ( " " );
lcd.print (end);
}
void setup ()
{
int i;
int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));
Serial.begin ( 57600 );
analogReference ( DEFAULT );
pinMode ( LDR_PIN, INPUT );
lcd.init ();
lcd.setContrast(10);
// Load custom character set into CGRAM
for ( i = 0; i < charBitmapSize; i++ )
{
lcd.load_custom_character ( i, (uint8_t *)charBitmap[i] );
}
Serial.println ( freeMemory () );
}
void loop ()
{
int lightLevel;
lcd.clear ();
lcd.print ("Light Level:");
lightLevel = analogRead (LDR_PIN);
lcd.setCursor ( 1, 16 );
lcd.print ( lightLevel );
lcd.setCursor (1,0);
drawBars ( lightLevel, 1, 12, '-', '+' );
delay (100);
}

View File

@ -0,0 +1,191 @@
#include <Arduino.h>
#include "ST7036.h"
#include "LCD_C0220BiZ.h"
#include <Wire.h>
// ???:fmalpartida:20110821
/*!
@defined CHAR_WIDTH
@abstract Character witdth of the display, expressed in pixeles per character.
*/
#define CHAR_WIDTH 5
/*!
@defined LDR_PIN
@abstract Light Detection Resistor Analog pin.
@discussion Define the Analog channel that will be used to read a LDR.
*/
#define LDR_PIN 7
/*!
@defined TEMP_CAL_OFFSET
@abstract Temperature calibration offset.
@discussion This is the offset value that has to be modified to get a
correct temperature reading from the internal temperature sensor
of your AVR.
*/
#define TEMP_CAL_OFFSET 335
/*!
@defined FILTER_ALP
@abstract Low pass filter alpha value
@discussion This value defines how much does the current reading, influences
the over all value. The smaller, the less influence the current
reading has over the overall result.
*/
#define FILTER_ALP 0.1
extern unsigned int __bss_end;
extern unsigned int __heap_start;
extern void *__brkval;
//LCD_C0220BIZ lcd = LCD_C0220BIZ ( );
ST7036 lcd = ST7036 ( 2, 20, 0x78 );
static double tempFilter;
/*!
@const charBitmap
@abstract Define Character bitmap for the bargraph.
@discussion Defines a character bitmap to represent a bargraph on a text
display. The bitmap goes from a blank character to full black.
*/
const uint8_t charBitmap[][8] = {
{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
{ 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0 },
{ 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x0 },
{ 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x0 },
{ 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x0 },
{ 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0 }
};
/*!
@function
@abstract Return available RAM memory
@discussion This routine returns the ammount of RAM memory available after
initialising the C runtime.
@param
@result Free RAM available.
*/
static int freeMemory()
{
int free_memory;
if((int)__brkval == 0)
free_memory = ((int)&free_memory) - ((int)&__bss_end);
else
free_memory = ((int)&free_memory) - ((int)__brkval);
return free_memory;
}
/*!
@function
@abstract Returns AVR328p internal temperature
@discussion Configures the ADC MUX for the temperature ADC channel and
waits for conversion and returns the value of the ADC module
@result The internal temperature reading - in degrees C
*/
static int readTemperature()
{
ADMUX = 0xC8; // activate interal temperature sensor,
// using 1.1V ref. voltage
ADCSRA |= _BV(ADSC); // start the conversion
while (bit_is_set(ADCSRA, ADSC)); // ADSC is cleared when the conversion
// finishes
// combine bytes & correct for temperature offset (approximate)
return ( (ADCL | (ADCH << 8)) - TEMP_CAL_OFFSET);
}
/*!
@function
@abstract Braws a bargraph onto the display representing the value passed.
@discussion Draws a bargraph on the specified row using barLength characters.
@param value[in] Value to represent in the bargraph
@param row[in] Row of the LCD where to display the bargraph. Range (0, 1)
for this display.
@param barlength[in] Length of the bar, expressed in display characters.
@param start[in] Start bar character
@param end [in] End bar character
@result None
*/
static void drawBars ( int value, uint8_t row, uint8_t barLength, char start,
char end )
{
int numBars;
// Set initial titles on the display
lcd.setCursor (row, 0);
lcd.print (start);
// Calculate the size of the bar
value = map ( value, -20, 50, 0, ( barLength - 1) * CHAR_WIDTH );
numBars = value / CHAR_WIDTH;
// Limit the size of the bargraph to barLength
if ( numBars > barLength )
{
numBars = barLength;
}
lcd.setCursor ( row,2 );
// Draw the bars
while ( numBars-- )
{
lcd.print ( char( (sizeof(charBitmap ) / sizeof(charBitmap[0])) - 1 ) );
}
// Draw the fractions
numBars = value % CHAR_WIDTH;
lcd.print ( char(numBars) );
lcd.setCursor (row, barLength + 1);
lcd.print ( " " );
lcd.print (end);
}
void setup ()
{
int i;
int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));
Serial.begin ( 57600 );
analogReference ( INTERNAL );
pinMode ( LDR_PIN, INPUT );
lcd.init ();
lcd.setContrast(10);
// Load custom character set into CGRAM
for ( i = 0; i < charBitmapSize; i++ )
{
lcd.load_custom_character ( i, (uint8_t *)charBitmap[i] );
}
Serial.println ( freeMemory () );
tempFilter = readTemperature(); // Initialise the temperature Filter
}
void loop ()
{
int temp;
temp = readTemperature();
tempFilter = ( FILTER_ALP * temp) + (( 1.0 - FILTER_ALP ) * tempFilter);
lcd.clear ();
lcd.setCursor ( 0, 0 );
lcd.print ("Temperature:");
lcd.setCursor ( 1, 15 );
lcd.print ( tempFilter, 1 );
lcd.setCursor (1,0);
drawBars ( tempFilter, 1, 11, '-', '+' );
delay (100);
}

View File

@ -0,0 +1,35 @@
#######################################
# Syntax Coloring Map For Ultrasound
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
LCD_C0220BIZ KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
init KEYWORD2
setDelay KEYWORD2
command KEYWORD2
write KEYWORD2
clear KEYWORD2
home KEYWORD2
on KEYWORD2
off KEYWORD2
cursor_on KEYWORD2
cursor_off KEYWORD2
blink_on KEYWORD2
blink_off KEYWORD2
setCursor KEYWORD2
status KEYWORD2
load_custom_character KEYWORD2
keypad KEYWORD2
setBacklight KEYWORD2
setContrast KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################

253
libraries/LCD_C0220BIZ/lcd.h Executable file
View File

@ -0,0 +1,253 @@
// ---------------------------------------------------------------------------
// Created by Francisco Malpartida on 20/08/11.
// Copyright 2011 - 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: No
//
// @file lcd.h
// LCD API 1.0 interface declaration class.
//
// @brief Based on the LCD API 1.0 by dale@wentztech.com
// This class implements the LCD API abstract library class from
// which all LCDs inherite.
//
// @author F. Malpartida - fmalpartida@gmail.com
// ---------------------------------------------------------------------------
#ifndef LCD_h
#define LCD_h
#include "Arduino.h"
#include "Print.h"
#define _LCDEXPANDED // If defined turn on advanced functions
#define _LCD_API_VERSION "1.0"
class LCD : public Print
{
public:
/**
Send a command to the display
@param value[in] Command to be sent to the display
@return None
void command(uint8_t value);
*/
virtual void command(uint8_t value) = 0;
/**
Initialise the display. Once created the object, this is the next operation
that has to be called to initialise the display into a known state. It
assumes that the I2C bus is not initialised and hence initialise the Wire
interface.
Clear the display
Set contrast levels
Set the cursor at origens (0,0)
Turn on the entire display
void init();
*/
virtual void init() = 0;
/**
Set a different delay to that in the library. It may be needed to delay
sending commands or characters one after the other.
@param cmdDelay[in] Delay after issuing a command
@param charDelay[in] Delay after issuing a character to the LCD
@return None
void setDelay(int,int);
*/
virtual void setDelay(int,int) = 0;
/**
This is the write method used by the Print library. It allows printing
characters to the display and new lines: print, println. It will write the
value to the display and increase the cursor.
@param value[in] character to write to the current LCD write position
@return None
virtual void write(uint8_t);
*/
virtual size_t write(uint8_t) = 0;
/**
This is the write method used by the Print library. It allows printing
characters to the display and new lines: print, println. It will write the
value to the display and increase the cursor.
@param buffer[in] buffer to write to the current LCD write position
@param size[in] size of the buffer
@return None
virtual void write(uint8_t, size_t);
*/
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
/**
Clear the display and set the cursor to 0,0
void clear();
*/
virtual void clear() = 0;
/**
Set the cursor to 0,0
void home();
*/
virtual void home() = 0;
/**
Switch the display on. This is the default state when the display is
initialised. See. init() method
void on();
*/
virtual void on() = 0;
/**
Switch the display off.
void off();
*/
virtual void off() = 0;
/**
Turn on the cursor "_".
void cursor_on();
*/
virtual void cursor_on() = 0;
/**
Turn off the cursor. This is the default state when the display is
initialised.
void cursor_off();
*/
virtual void cursor_off() = 0;
/**
Activate cursor blink.
void blink_on();
*/
virtual void blink_on() = 0;
/**
Deactivate cursor blinking. This is the default state when the display is
initialised.
void blink_off ();
*/
virtual void blink_off() = 0;
/**
Set the cursor at the following coordinates (Line, Col). Initial value after
initialization is (0,0).
@param Line[in] Line where to put the cursor, range (0, max display lines-1)
This display only take (0, 1)
@param Col[in] Colum where to put the cursor, range (0, max width+1)
@return None
void setCursor(uint8_t Line, uint8_t Col );
*/
virtual void setCursor(uint8_t Line, uint8_t Col ) = 0;
//
// EXPANDED FUNCTIONALITY METHODS
// --------------------------------------------------------------------------
#ifdef _LCDEXPANDED
/**
Provides the state of the LCD. This value is updated every command is sent
to the LCD or a character or a buffer is writen to the display.
@return 0 OK, 1 if data was too big to be transmitted, 2 NACK on address
transmission, 3 NACK on data transmission, 4 other error.
uint8_t status();
*/
virtual uint8_t status() = 0;
/**
Load a custom character on the display. After adding a new character to
the character set, the coordinates are set to (0, 0). This method should
be called during initialization.
@param char_num[in] Character to load onto the display, this display supports
upto 16 user defined characters.
@param rows[in] Bitmap defining the character, the display assumes an array
of 8 bytes per character.
@return None.
uint8_t load_custom_character(uint8_t char_num, uint8_t *rows);
*/
virtual void load_custom_character(uint8_t char_num, uint8_t *rows) = 0;
/**
NOT SUPPORTED
uint8_t keypad();
*/
virtual uint8_t keypad() = 0;
void printstr(const char[]);
/**
Sets the backlight level. If the backlight level is connected to a PWM pin,
new_val will set a light level range between 0 and 255. If it is connected
to a normal GPIO, from 0 to 127 it will be off and from 128 to 255 the
backlight will be on. Backlight pin allocation on constructor.
@param new_val[in] Backlight level of the display. Full range will only be
available on pins with PWM support.
@return None.
uint8_t setBacklight();
*/
virtual void setBacklight(uint8_t new_val) = 0;
/**
Sets the LCD contrast level.
@param new_val[in] The contrast range (0 to 255) has been mapped to 16
contrast levels on the display.
@return None.
uint8_t setContrast();
*/
virtual void setContrast(uint8_t new_val) = 0;
#endif
private:
};
#endif