Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

LCD HD77480 and a PCF8574


  • Please log in to reply
5 replies to this topic

#1 Trey Aughenbaugh

Trey Aughenbaugh

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 20 March 2011 - 07:27 AM

After I completed my First Project I decided to tackle working with an LCD display.
The examples I found did not work with C# or were for the 74HC595.

I found the μLiquidCrystal library but it did not have a class for my chip. After looking at the MCP23008 Expander class, it looked like I could just re-assign the pins to mine.
So I create two new classes based on the MCP23008 and gave it a try.

Which did end up working. If you want to build this, you need to download the μLiquidCrystal library and save the two class files into the same folder as the MCP2003Exander.cs file.
You also need to add a Reference to the MicroLiquidCrystal project.

Here is a quick way to test it (Hopefully it is quick.).
-Download the uLiquidCrystal Library.
-Open the MicroLiquidCrystal.sln file. Ignore some errors about the 'Example' project path.
-From within Visual Studio, Right Click on the 'Solution MicroLiquidCrystal (X Project)' from the Solution Explorer window and select 'Add New Project.'
-Open the new Program.cs file and paste this code in.
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;

using FusionWare.SPOT.Hardware;
using MicroLiquidCrystal;
using System.Text;
using Microsoft.SPOT.Net.NetworkInformation;

namespace PCF8574ClockTest
{
    public class Program
    {

        private static Lcd _lcd;
        private static I2CBus _bus;
        private static Timer _lcdTimer;

        public static void Main()
        {

           _bus = new I2CBus();
      
            // initialize provider (multiple devices can be attached to same bus)
            var lcdProvider = new PCF8574LcdTransferProvider (_bus);

            // create the LCD interface
            _lcd = new Lcd(lcdProvider);
            _lcd.Backlight = true;
            // set up the LCD's number of columns and rows: 
            _lcd.Begin(16, 2);  // this again to reset.
            // Print a message to the LCD.
            _lcd.Write("Netduino clock");
            _lcdTimer = new Timer(UpdateDisplay, null, 500, 500);

         Thread.Sleep(Timeout.Infinite);
        }

        static readonly byte[] _lineBuffer = new byte[16];

        private static byte[] FillLine(string text)
        {
            // fill empty space
            for (int i = 0; i < _lineBuffer.Length; i++)
                _lineBuffer[i] = (byte)' ';

            // write new text
            var bytes = Encoding.UTF8.GetBytes(text);
            bytes.CopyTo(_lineBuffer, 0);

            return _lineBuffer;
        }

        private static void UpdateDisplay(object state)
        {
            var dt = DateTime.Now;

            // write time 
            _lcd.Home();
            _lcd.Write(FillLine(dt.ToString("hh:mm:ss")), 0, 16);

            // write date
            _lcd.SetCursorPosition(0, 1);
            _lcd.Write(FillLine(dt.ToString("MM/dd/yyyy")), 0,16);

        }

    }
}

-Right click on 'Add Reference' for your project and select the Projects tab, then 'MicroLiquidCrystal'.

You should now be able to run it.

Also, my PCF8574 may have a different address than yours, you can change the address in the 'PCF8574Expander.cs' class.

Hopefully I did not mess a step an this helps someone!

HELP!!!
One odditity I did notice, after leaving the clock run for a while, intermittently my display with show garbage.
I added a little routine to my onboard switch that sends a _lcd.Begin(16, 2); command to restart it all.
I have no clue why this does this and I wish I knew how to prevent it.
When I created my LED test with the PCF8574, I left the LEDs plugged in when attaching to the LCD.
It does show me that even though the display is showing garbage, the LEDs are lighting on/off just like they do when it is displaying correctly.
Maybe the LEDs are causing some interference after a while. I plan on making a board and will have a better test outside of a breadboard setup.

Good luck!
Trey Aughenbaugh

Attached Files



#2 Hinnie

Hinnie

    New Member

  • Members
  • Pip
  • 9 posts

Posted 20 March 2011 - 02:31 PM

Hi Trey, For driving a LCD with HD44870 protocol via a PCF8574 portexpander I successfully use the driver "Bansky". See my post on TinyCLR http://www.tinyclr.com/forum/2/2643/ Ultrasonic distance sensors are also read (SRF05) and servos controlled.

#3 Trey Aughenbaugh

Trey Aughenbaugh

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 21 March 2011 - 01:02 AM

Hi Trey,

For driving a LCD with HD44870 protocol via a PCF8574 portexpander I successfully use the driver "Bansky".
See my post on TinyCLR http://www.tinyclr.com/forum/2/2643/
Ultrasonic distance sensors are also read (SRF05) and servos controlled.


I would love to try the "Bansky" driver, but between C# conversion problems and errors such as:
'Microsoft.SPOT.Hardware.I2CDevice.CreateWriteTransaction(byte[])' cannot be accessed with an instance reference; qualify it with a type name instead \LCDBlankeyTest\PCF8574P.cs	36	21	LCDBlankeyTest
I am unable to get it to work as quickly as I could with the MicroCrystal library.
I wanted to test it hoping that it would eliminate my LCD garbage that randomly shows up.

I downloaded this project http://bansky.net/bl...CD_library.zip.

I'll play some more and see if I can get it to work correctly.
Thanks for the reference though, there are some good examples on Pavel Bánský's web site.

-Trey

#4 Hinnie

Hinnie

    New Member

  • Members
  • Pip
  • 9 posts

Posted 21 March 2011 - 12:45 PM

I had the same problem in the send byte functions.
After a few tries I got the following solution

       public void SendByte(byte data)
        {
            if (!_bigEndian)
                data = ReverseBits(data);

            lock (_i2cbus)
            {
                _i2cbus.Config = _config;
                I2CDevice.I2CTransaction[] xact = new I2CDevice.I2CTransaction[]
                {
         //        _i2cbus.CreateWriteTransaction(new byte[] { data })
                   I2CDevice.CreateWriteTransaction(new byte[] { data })
                };

                _i2cbus.Execute(xact, 3000);
            }
        }

The faulty line is a comment line with under my working line.
Perhaps this will lead to a solution for you too.

#5 Trey Aughenbaugh

Trey Aughenbaugh

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 21 March 2011 - 08:56 PM

I had the same problem in the send byte functions.
After a few tries I got the following solution

       public void SendByte(byte data)
        {
            if (!_bigEndian)
                data = ReverseBits(data);

            lock (_i2cbus)
            {
                _i2cbus.Config = _config;
                I2CDevice.I2CTransaction[] xact = new I2CDevice.I2CTransaction[]
                {
         //        _i2cbus.CreateWriteTransaction(new byte[] { data })
                   I2CDevice.CreateWriteTransaction(new byte[] { data })
                };

                _i2cbus.Execute(xact, 3000);
            }
        }

The faulty line is a comment line with under my working line.
Perhaps this will lead to a solution for you too.



Thanks Hinnie, that fixed my compile problem.
Now I just need to rewire my PCF8574 pins to match the pins relating to this code.
The MicroCrystal library is much nicer when it comes to changing the pins, you just edit the Transferprovider file.
Based on looking at the code, It will be easier for a wire change rather than a code change.

I'll let you know if this library fixes my garbage problem.

Thanks,
Trey

#6 alesbedac

alesbedac

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts

Posted 15 October 2013 - 07:01 PM

Hi all.

 

i have 20x4 HD44780  i tested Your code but its not working, can You please help me where i did a bug ?

 

Lot of thanks for Your help

 

2013-10-17 :

 

I saw higher the image where is PCF ecpander connected to Analog ports on netduino..thats correct i am connecting it with SC and SD pins ?

thanks for answers.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.