more G-Labs products

Author Topic: HD44780 LCD I2C  (Read 3963 times)

December 15, 2014, 08:18:56 PM
Read 3963 times

StatX

  • **
  • Information
  • Jr. Member
  • Posts: 30
Hello,

how about adding supprot for HD44780 LCD controlled by PCF8574 (I2C interface) to show customizable info for example:

I want ot check the some temperatures form DS18B20 sensors and not turn the computer on, so the LCD is showing me the temperatures all the time.

Can it be done ? its easy with arduino but i am starting my adventure with RasPi and dunno how to do It. The electronic side is easy but programing it ... thats a different story :P

i like those displays because they are very readable from a distance.

December 15, 2014, 08:30:17 PM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer

December 15, 2014, 08:37:32 PM
Reply #2

StatX

  • **
  • Information
  • Jr. Member
  • Posts: 30
ok so i need to import this program to HG ? or it is already in because i cannot find it ?

December 15, 2014, 10:25:50 PM
Reply #3

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
create a new program, set the type to "C# Program" and use this code:
Code: [Select]
var driver = GpioConnectionSettings.DefaultDriver;

var registerSelectPin = driver.Out(ConnectorPin.P1Pin22.ToProcessor());
var clockPin = driver.Out(ConnectorPin.P1Pin18.ToProcessor());
var data8 = driver.Out(ConnectorPin.P1Pin16.ToProcessor());
var data7 = driver.Out(ConnectorPin.P1Pin15.ToProcessor());
var data6 = driver.Out(ConnectorPin.P1Pin13.ToProcessor());
var data5 = driver.Out(ConnectorPin.P1Pin11.ToProcessor());

var dataPins = new Raspberry.IO.IOutputBinaryPin[]{
  data8,
  data7,
  data6,
  data5
};

var settings = new Hd44780LcdConnectionSettings
{
  ScreenWidth = 20,
  ScreenHeight = 2,
};

var pins = new Hd44780Pins(registerSelectPin, clockPin, dataPins);

using (var connection = new Hd44780LcdConnection(settings, pins))
{
  connection.SetCustomCharacter(1, new byte[] {0x0, 0x0, 0x04, 0xe, 0x1f, 0x0, 0x0});
  connection.SetCustomCharacter(2, new byte[] {0x0, 0x0, 0x1f, 0xe, 0x04, 0x0, 0x0});
  connection.Clear();
  connection.WriteLine("R# IP Config");
  connection.WriteLine(Environment.OSVersion);
}

to find out other things you can do with the Hd44780LcdConnection object (named connection in the code above) see this:

https://github.com/raspberry-sharp/raspberry-sharp-io/blob/master/Raspberry.IO.Components/Displays/Hd44780/Hd44780Pins.cs

After compiling, use Run from Actions menu to execute the code.

let me know if this works.

Cheers,
g.

December 15, 2014, 10:56:46 PM
Reply #4

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Off course the code above is for stand-alone Hd44780 directly connected to RPi GPIOs.
Interfacing through PCF8574 is also possible but you need to know the protocol implemented for controlling the display.
Do you have such specification or code?

g.

December 15, 2014, 11:02:01 PM
Reply #5

StatX

  • **
  • Information
  • Jr. Member
  • Posts: 30
ok i compiled the program but i will connect the LCD tomorrow after work

December 22, 2014, 10:01:26 AM
Reply #6

StatX

  • **
  • Information
  • Jr. Member
  • Posts: 30
Hi there,

sorry for being off for so long holiday preparation etc.

I've connected the LCD as shown in adafruit tutorial i changed the GPIO pins to:

RS - Pin 29
Clock - Pin 40
Data 5 - Pin 31
Data 6 - Pin 33
Data 7 - Pin 35
Data 8 - Pin 37

also the Read Write Pin is connected to GND

The power supply ( 5V ) i am taking form the outside Power Supply and the GND of it and GND of Rpi is connected together.

I used Your program ( with changed pins and LCD dimesnions - i have 16x2 )
The program has yellow light on it and nothing happens when i'm starting it only yellow light  in HG comes on and the information that program is running but on LCD i see only black boxes in top row.

any sugestions ?

December 22, 2014, 05:31:57 PM
Reply #7

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer

December 23, 2014, 08:35:26 AM
Reply #8

StatX

  • **
  • Information
  • Jr. Member
  • Posts: 30
hmm i tried the github config - the program and the setup and now i get error when compiling the program

error code:
access violation on patch /sys/class/gpio/export

December 23, 2014, 10:35:16 AM
Reply #9

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
If you're using homegenie sd card the P1-11 (GPIO17) is already in use by LIRC module and the P1-7 (GPIO4) is already in use by 1-Wire module.
So disable those modules first and reboot.

g.

December 23, 2014, 10:56:04 AM
Reply #10

StatX

  • **
  • Information
  • Jr. Member
  • Posts: 30
But the program isn't using Pin 7 ( GPIO 4 ) witch is 1-wire.
The program is using pins  11, 13, 15, 16, 18, 22
I will try with LIRC in just a second

Same situation, nothing changed, and by the way LIRC was disabled because i had on that pin DHT-11 now i moved it to pin 12 .

I've also disabled DHT-11 and 1-wire notching changes.

maybe i am missing ( its part of the code You send me earlier ):

var driver = GpioConnectionSettings.DefaultDriver;
« Last Edit: December 23, 2014, 11:07:18 AM by StatX »

December 23, 2014, 11:17:14 AM
Reply #11

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
So don't know what it could be the problem. Try sending a message to the author of RaspberrySharp library.

Cheers,
g.

December 23, 2014, 11:47:56 AM
Reply #12

StatX

  • **
  • Information
  • Jr. Member
  • Posts: 30
Ok thank You for help i will try to contact the autor, if i will manage sto get it going i will share everything :)

January 19, 2015, 09:51:03 AM
Reply #13

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi StatX,

I just caught into this note of the raspberry-sharp author:

https://github.com/raspberry-sharp/raspberry-sharp-io/issues/13

so using the display through PCF8574 I2C is possible by changing the code so that will be using the I2CConnection.
See example here about using either MCP23017 or PCF8574:

https://github.com/raspberry-sharp/raspberry-sharp-io/blob/master/Tests/Test.Gpio.HD44780/ConfigurationLoader.cs#L88

Cheers,
g.

March 12, 2015, 03:03:06 PM
Reply #14

NickP

  • *
  • Information
  • Newbie
  • Posts: 24
Try this, I'm working it up into a module:
Code: [Select]
// change as needed for your setup
//Pi pins conencting to MCP23017 - unlikely to change if yiu areusing hardware i2c
    const ConnectorPin sdaPin = ConnectorPin.P1Pin03;
    const ConnectorPin sclPin = ConnectorPin.P1Pin05;

// MCP23017 to LCD pins, change these to match your actual connection
    const Mcp23017Pin registerSelectPin = Mcp23017Pin.B7;
    const Mcp23017Pin clockPin = Mcp23017Pin.B5;
    const Mcp23017Pin backlightPin = Mcp23017Pin.B0;   // note this is assumed to be connected to the LCD led+
    const Mcp23017Pin readWritePin = Mcp23017Pin.B6;
    var dataPins = new[]
    {
        Mcp23017Pin.B4,
        Mcp23017Pin.B3,
        Mcp23017Pin.B2,
        Mcp23017Pin.B1
    };

   // i2C address of the MCP23017
    const int address = 0x20;

// LCD setting characters wide and lines deep
    var settings = new Hd44780LcdConnectionSettings
    {
        ScreenWidth = 16,
        ScreenHeight = 2,
    };

   // connect the system
    var driver = new I2cDriver(sdaPin.ToProcessor(), sclPin.ToProcessor()) { ClockDivider = 512 };
    var i2cconnection = new Mcp23017I2cConnection(driver.Connect(address));
   
    var    Pins = new Hd44780Pins(
            i2cconnection.Out(registerSelectPin),
            i2cconnection.Out(clockPin),
            dataPins.Select(pin => (IOutputBinaryPin)i2cconnection.Out(pin)))
            {
                Backlight = i2cconnection.Out( backlightPin ),
                ReadWrite = i2cconnection.Out( readWritePin )
            };

    var connection = new Hd44780LcdConnection(settings, Pins);

    connection.Clear();
    connection.BacklightEnabled = true;

    connection.WriteLine("OS Version");
    connection.WriteLine(Environment.OSVersion);



When.ProgramStopping(()=>{
  ((IDisposable)connection).Dispose();
  ((IDisposable)driver).Dispose();
  return true;
});


while (Program.IsEnabled)
{
   // do whatever