Make I2C address configurable for HD44780 LCD variations
Also add a basic README with some pointers on how to connect and configure the LCDs
This commit is contained in:
parent
ef0ebb4d49
commit
ce367f73cb
8
Conf.cpp
8
Conf.cpp
|
@ -130,6 +130,7 @@ m_tftSerialBrightness(50U),
|
|||
m_hd44780Rows(2U),
|
||||
m_hd44780Columns(16U),
|
||||
m_hd44780Pins(),
|
||||
m_hd44780i2cAddress,
|
||||
m_hd44780PWM(false),
|
||||
m_hd44780PWMPin(),
|
||||
m_hd44780PWMBright(),
|
||||
|
@ -438,6 +439,8 @@ bool CConf::read()
|
|||
m_hd44780Rows = (unsigned int)::atoi(value);
|
||||
else if (::strcmp(key, "Columns") == 0)
|
||||
m_hd44780Columns = (unsigned int)::atoi(value);
|
||||
else if (::strcmp(key, "I2CAddress") == 0)
|
||||
m_hd44780i2cAddress = value;
|
||||
else if (::strcmp(key, "PWM") == 0)
|
||||
m_hd44780PWM = ::atoi(value) == 1;
|
||||
else if (::strcmp(key, "PWMPin") == 0)
|
||||
|
@ -889,6 +892,11 @@ std::vector<unsigned int> CConf::getHD44780Pins() const
|
|||
return m_hd44780Pins;
|
||||
}
|
||||
|
||||
std::string CConf::getHD44780i2cAddress() const
|
||||
{
|
||||
return m_hd44780i2cAddress;
|
||||
}
|
||||
|
||||
bool CConf::getHD44780PWM() const
|
||||
{
|
||||
return m_hd44780PWM;
|
||||
|
|
2
Conf.h
2
Conf.h
|
@ -137,6 +137,7 @@ public:
|
|||
unsigned int getHD44780Rows() const;
|
||||
unsigned int getHD44780Columns() const;
|
||||
std::vector<unsigned int> getHD44780Pins() const;
|
||||
std::string getHD44780i2cAddress() const;
|
||||
bool getHD44780PWM() const;
|
||||
unsigned int getHD44780PWMPin() const;
|
||||
unsigned int getHD44780PWMBright() const;
|
||||
|
@ -252,6 +253,7 @@ private:
|
|||
unsigned int m_hd44780Rows;
|
||||
unsigned int m_hd44780Columns;
|
||||
std::vector<unsigned int> m_hd44780Pins;
|
||||
std::string m_hd44780i2cAddress;
|
||||
bool m_hd44780PWM;
|
||||
unsigned int m_hd44780PWMPin;
|
||||
unsigned int m_hd44780PWMBright;
|
||||
|
|
|
@ -36,7 +36,7 @@ char m_buffer2[128U];
|
|||
char m_buffer3[128U];
|
||||
char m_buffer4[128U];
|
||||
|
||||
CHD44780::CHD44780(unsigned int rows, unsigned int cols, const std::string& callsign, unsigned int dmrid, const std::vector<unsigned int>& pins, bool pwm, unsigned int pwmPin, unsigned int pwmBright, unsigned int pwmDim, bool displayClock, bool utc, bool duplex) :
|
||||
CHD44780::CHD44780(unsigned int rows, unsigned int cols, const std::string& callsign, unsigned int dmrid, const std::vector<unsigned int>& pins, const std::string& i2cAddress, bool pwm, unsigned int pwmPin, unsigned int pwmBright, unsigned int pwmDim, bool displayClock, bool utc, bool duplex) :
|
||||
CDisplay(),
|
||||
m_rows(rows),
|
||||
m_cols(cols),
|
||||
|
@ -48,6 +48,7 @@ m_d0(pins.at(2U)),
|
|||
m_d1(pins.at(3U)),
|
||||
m_d2(pins.at(4U)),
|
||||
m_d3(pins.at(5U)),
|
||||
m_i2cAddress(i2cAddress),
|
||||
m_pwm(pwm),
|
||||
m_pwmPin(pwmPin),
|
||||
m_pwmBright(pwmBright),
|
||||
|
@ -239,7 +240,7 @@ bool CHD44780::open()
|
|||
void CHD44780::adafruitLCDSetup()
|
||||
{
|
||||
// The other control pins are initialised with lcdInit()
|
||||
::mcp23017Setup(AF_BASE, MCP23017);
|
||||
::mcp23017Setup(AF_BASE, m_i2caddress);
|
||||
|
||||
// Backlight LEDs
|
||||
::pinMode(AF_RED, OUTPUT);
|
||||
|
@ -311,7 +312,7 @@ void CHD44780::adafruitLCDColour(ADAFRUIT_COLOUR colour)
|
|||
void CHD44780::pcf8574LCDSetup()
|
||||
{
|
||||
// Initalize PFC8574
|
||||
::pcf8574Setup(AF_BASE, PCF8574);
|
||||
::pcf8574Setup(AF_BASE, m_i2cAddress);
|
||||
|
||||
// Turn on backlight
|
||||
::pinMode (AF_BL, OUTPUT);
|
||||
|
|
|
@ -67,7 +67,7 @@ enum ADAFRUIT_COLOUR {
|
|||
#define AF_ON LOW
|
||||
#define AF_OFF HIGH
|
||||
|
||||
#define MCP23017 0x20
|
||||
// #define MCP23017 0x20
|
||||
#endif
|
||||
|
||||
// Define for HD44780 connected via a PCF8574 GPIO extender
|
||||
|
@ -83,13 +83,13 @@ enum ADAFRUIT_COLOUR {
|
|||
#define AF_D2 (AF_BASE + 6)
|
||||
#define AF_D3 (AF_BASE + 7)
|
||||
|
||||
#define PCF8574 0x27
|
||||
// #define PCF8574 0x27
|
||||
#endif
|
||||
|
||||
class CHD44780 : public CDisplay
|
||||
{
|
||||
public:
|
||||
CHD44780(unsigned int rows, unsigned int cols, const std::string& callsign, unsigned int dmrid, const std::vector<unsigned int>& pins, bool pwm, unsigned int pwmPin, unsigned int pwmBright, unsigned int pwmDim, bool displayClock, bool utc, bool duplex);
|
||||
CHD44780(unsigned int rows, unsigned int cols, const std::string& callsign, unsigned int dmrid, const std::vector<unsigned int>& pins, const std::string& i2cAddress, bool pwm, unsigned int pwmPin, unsigned int pwmBright, unsigned int pwmDim, bool displayClock, bool utc, bool duplex);
|
||||
virtual ~CHD44780();
|
||||
|
||||
virtual bool open();
|
||||
|
@ -123,6 +123,7 @@ private:
|
|||
unsigned int m_d1;
|
||||
unsigned int m_d2;
|
||||
unsigned int m_d3;
|
||||
std::string m_i2cAddress;
|
||||
bool m_pwm;
|
||||
unsigned int m_pwmPin;
|
||||
unsigned int m_pwmBright;
|
||||
|
|
|
@ -107,15 +107,20 @@ Brightness=50
|
|||
[HD44780]
|
||||
Rows=2
|
||||
Columns=16
|
||||
|
||||
# For basic HD44780 displays (4-bit connection)
|
||||
# rs, strb, d0, d1, d2, d3
|
||||
# For basic HD44780 displays
|
||||
Pins=11,10,0,1,2,3
|
||||
|
||||
# Device address for I2C
|
||||
I2CAddress=0x20
|
||||
|
||||
# PWM backlight
|
||||
PWM=0
|
||||
PWMPin=21
|
||||
PWMBright=100
|
||||
PWMDim=16
|
||||
|
||||
DisplayClock=1
|
||||
UTC=0
|
||||
|
||||
|
|
|
@ -875,6 +875,7 @@ void CMMDVMHost::createDisplay()
|
|||
unsigned int rows = m_conf.getHD44780Rows();
|
||||
unsigned int columns = m_conf.getHD44780Columns();
|
||||
std::vector<unsigned int> pins = m_conf.getHD44780Pins();
|
||||
std::string i2cAddress = m_conf.getHD44780i2cAddress();
|
||||
bool pwm = m_conf.getHD44780PWM();
|
||||
unsigned int pwmPin = m_conf.getHD44780PWMPin();
|
||||
unsigned int pwmBright = m_conf.getHD44780PWMBright();
|
||||
|
@ -898,7 +899,7 @@ void CMMDVMHost::createDisplay()
|
|||
if (displayClock)
|
||||
LogInfo(" Display UTC: %s", utc ? "yes" : "no");
|
||||
|
||||
m_display = new CHD44780(rows, columns, m_callsign, dmrid, pins, pwm, pwmPin, pwmBright, pwmDim, displayClock, utc, m_duplex);
|
||||
m_display = new CHD44780(rows, columns, m_callsign, dmrid, pins, i2cAddress, pwm, pwmPin, pwmBright, pwmDim, displayClock, utc, m_duplex);
|
||||
}
|
||||
#endif
|
||||
#if defined(OLED)
|
||||
|
|
46
README.HD44780
Normal file
46
README.HD44780
Normal file
|
@ -0,0 +1,46 @@
|
|||
- HD44780 LCD SUPPORT -
|
||||
|
||||
Support for the HD44780 LCD is via the wiringPi library available at
|
||||
http://wiringpi.com/download-and-install/ which must be installed in all cases.
|
||||
|
||||
The HD44780 in 4-bit mode is probably the most common connection method and
|
||||
wiring details can be found at http://wiringpi.com/dev-lib/lcd-library/
|
||||
|
||||
To compile MMDVMHost with support for the HD44780 use the following commands.
|
||||
|
||||
# cp Makefile.Pi.HD44780 Makefile
|
||||
# make clean
|
||||
# make
|
||||
|
||||
Other HD44780 variations exist that connect via I2C. Support is also via
|
||||
wiringPi, but to compile for each I2C device requires a different Makefile
|
||||
depending on the IC attached to the LCD.
|
||||
|
||||
- ADAFRUIT RGB LCD SHIELD -
|
||||
|
||||
The Adafruit RGB LCD Shield is available from https://www.adafruit.com/product/714
|
||||
I2C is via the MCP23017 IC and is enabled with Makefile.Pi.Adafruit. The
|
||||
I2C device address in MMDVM.ini should be set to 0x20.
|
||||
|
||||
- PCF8574 IC -
|
||||
|
||||
HD44780 LCDs connected via a PCF8574 Remote 8-Bit I/O Expander are available on
|
||||
eBay for very little money! This IC uses Makefile.Pi.PCF8574 and the I2C
|
||||
device address should be set to 0x27.
|
||||
|
||||
- BEWARE -
|
||||
|
||||
The I2C device address can be manually configured on some devices!
|
||||
|
||||
- CHECK YOUR ACTUAL DEVICE ADDRESS -
|
||||
|
||||
More information on configuring and using I2C on the RPi including how to probe
|
||||
the I2C bus for device addresses can be found at
|
||||
https://learn.sparkfun.com/tutorials/raspberry-pi-spi-and-i2c-tutorial#i2c-on-pi
|
||||
|
||||
- PWM BACKLIGHT CONTROL -
|
||||
|
||||
Whilst connected in 4-bit mode or via the PCF8574 IC, the LED backlight can be
|
||||
wired for control via PWM. Connect the backlight +ve pin to any spare GPIO pin
|
||||
and configure MMDVM.ini as appropriate. By default, wiringPi pin 21 is
|
||||
configured.
|
Loading…
Reference in a new issue