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

Help with Serial LCD displaying gobbly-de-gop!


  • Please log in to reply
10 replies to this topic

#1 waxie

waxie

    Member

  • Members
  • PipPip
  • 13 posts

Posted 01 September 2011 - 06:08 AM

Hi there,

I was wondering if someone could help me with my Serial LCD display. I am a newbie using the Netduino and I have brought this Serial LCD display and have followed the instructions here but for some reason when I run my sample application i just get rubbish sent to the display.

I have wired the display into the 5V and ground pins and for the data port I have wired it to digital Input 0.
I have not touched the sample code provided but here it is for full clarity.

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 Bansky.SPOT.LCD;

namespace NetduinoPlusApplicationLCDDisplay
{
    public class Program
    {
        public static void Main()
        {
            // Create instance of shift register
            HC4094 shifter = new HC4094(Pins.GPIO_PIN_D0, 	// Data pin
                                          Pins.GPIO_PIN_A5, 	// Clock pin
                                          Pins.GPIO_PIN_A4,	// Strobe pin
                                          true);               // Little Endian

            // Create new LCD instance and use shift register as a transport layer
            LCD4Bit lcd = new LCD4Bit(shifter);

            // Creating custom characters (Smiley face and gimp)
            byte[] buffer = new byte[] {    0x07, 0x08, 0x10, 0x10, 0x13, 0x13, 0x10, 0x10,
                                            0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04,
                                            0x1C, 0x02, 0x01, 0x01, 0x19, 0x19, 0x01, 0x01,
                                            0x10, 0x10, 0x12, 0x11, 0x10, 0x10, 0x08, 0x07,
                                            0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x1F,
                                            0x01, 0x01, 0x09, 0x11, 0x01, 0x01, 0x02, 0x1C,

                                            0x15, 0x15, 0x0E, 0x04, 0x04, 0x0A, 0x11, 0x11,
                                            0x04, 0x04, 0x0E, 0x15, 0x04, 0x0A, 0x11, 0x11
                                       };

            // Load custom characters to display CGRAM
            lcd.WriteToCGRAM(0x00, buffer);

            // Turn displat on, turn back light on, hide small cursor, show big blinking cursor
            lcd.Display(true, true, false, true);

            lcd.Clear();
            lcd.Write("Start me up!");
            Thread.Sleep(3000);

            lcd.Clear();
            lcd.Display(true, true, false, false);

            // Print the special characters with the face
            lcd.Write(new byte[] { 0x00, 0x01, 0x02 }, 0, 3);
            lcd.Write(" .NET Micro");

            // Move to second line
            lcd.SetPosition(40);

            // Print the special characters with the face
            lcd.Write(new byte[] { 0x03, 0x04, 0x05 }, 0, 3);
            lcd.Write("  Framework");
            Thread.Sleep(2000);

            // Blink with back light
            for (int i = 0; i < 4; i++)
            {
                lcd.Display(true, ((i % 2) != 0), false, false);
                Thread.Sleep(400);
            }

            lcd.Clear();
            string message = "* Hello World! *";
            // Let gimp write the message
            for (int i = 0; i < message.Length; i++)
            {
                lcd.SetPosition(i + 40);
                lcd.WriteByte((byte)(((i % 2) == 0) ? 0x06 : 0x07));

                lcd.SetPosition(i);
                lcd.Write(message[i].ToString());

                Thread.Sleep(200);

                lcd.SetPosition(i + 40);
                lcd.Write(" ");
            }
            Thread.Sleep(1500);

            lcd.Clear();
            lcd.SetPosition(16);

            lcd.Write("http://bansky.net/blog");
            // Scroll the page url
            while (true)
            {
                lcd.ShiftDisplay(false);
                Thread.Sleep(400);
            }


        }

    }
}



#2 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 01 September 2011 - 07:01 AM

You totally messed up the hardware, the tutorial and the software. Sorry, waxie!
Your module is "smarter" than the depicted one in the tutorial. It embeds a tiny microcontroller acting as interface serial UART --> parallel LCD.
The tutorial assumes you're having a normal parallel LCD, and instructs how to interface it directly to the Nteduino using a shift-register and the SPI.

Your case is dramatically simpler.
According with the module specs, you should connect only three wires: ground, +5V and "signal". This "signal" can be connected to the Netduino's I/O #3, which is the UART transmit line (TXD).
That's all about the hardware.

For the software side, you should only configure the serial UART as the specs say: 9600,N,8,1 as default.
Try this:

public static void Main()
{
       SerialPort sPort = new SerialPort(SerialPorts.COM1, 9600, Parity.None, 8, StopBits.One);
       sPort.Open();

       byte[] buffer = //set-up the byte stream to be sent (see module specs)
       sPort.Write(buffer, 0, buffer.Length);
       Thread.Sleep(Timeout.Infinite);
}
Cheers.
Biggest fault of Netduino? It runs by electricity.

#3 waxie

waxie

    Member

  • Members
  • PipPip
  • 13 posts

Posted 01 September 2011 - 09:17 AM

You totally messed up the hardware, the tutorial and the software. Sorry, waxie!
Your module is "smarter" than the depicted one in the tutorial. It embeds a tiny microcontroller acting as interface serial UART --> parallel LCD.
The tutorial assumes you're having a normal parallel LCD, and instructs how to interface it directly to the Nteduino using a shift-register and the SPI.

Your case is dramatically simpler.
According with the module specs, you should connect only three wires: ground, +5V and "signal". This "signal" can be connected to the Netduino's I/O #3, which is the UART transmit line (TXD).
That's all about the hardware.

For the software side, you should only configure the serial UART as the specs say: 9600,N,8,1 as default.
Try this:

public static void Main()
{
       SerialPort sPort = new SerialPort(SerialPorts.COM1, 9600, Parity.None, 8, StopBits.One);
       sPort.Open();

       byte[] buffer = //set-up the byte stream to be sent (see module specs)
       sPort.Write(buffer, 0, buffer.Length);
       Thread.Sleep(Timeout.Infinite);
}
Cheers.


Oh fiddlesticks!! Ive spent ages rubbing my noggin on this and your code looks ever so simple! Thank you for pointing me in the right direction. Like I say I am new to all of this and so its all one big learning curve. I will have to check this out when I get home tonight.

While I have got your ear can I ask you a question about the digital ports. I thought that these ports could only be used to send/recieve a 1 or a 0. (true/false) but in this example you are able to use Digital Input port 0 and write characters to it. Is this because you are using the SerialPort class instead of the OutputPort/InputPort classes?

#4 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 01 September 2011 - 10:15 AM

The term/suffix "port" is abstract: it would mean "a point where the data flows". With that term the designers of software uses to describe a variety of different forms to exchange data. Now, even a "data" is an abstract term. An InputPort is a "port" that allows input (only) of data of type "Boolean", thus false or true. Similarly, the OutputPort is the symmetric form for the same kind of data (Boolean). A SerialPort is a "port" which allows the exchange of "stream" of byte, or -if you like- byte array. When you design a class/component which gives the user a "door" to something else (typically hardware), it is a best practice to add the suffix "Port". At a first glance anyone may understand what's the basic purpose of that class/component. To tell the truth, I would have named the SPI class differently, just because it is another kind of port. Why not "SpiPort"? Cheers
Biggest fault of Netduino? It runs by electricity.

#5 waxie

waxie

    Member

  • Members
  • PipPip
  • 13 posts

Posted 01 September 2011 - 10:38 AM

The term/suffix "port" is abstract: it would mean "a point where the data flows".
With that term the designers of software uses to describe a variety of different forms to exchange data. Now, even a "data" is an abstract term.
An InputPort is a "port" that allows input (only) of data of type "Boolean", thus false or true.
Similarly, the OutputPort is the symmetric form for the same kind of data (Boolean).
A SerialPort is a "port" which allows the exchange of "stream" of byte, or -if you like- byte array.

When you design a class/component which gives the user a "door" to something else (typically hardware), it is a best practice to add the suffix "Port". At a first glance anyone may understand what's the basic purpose of that class/component.
To tell the truth, I would have named the SPI class differently, just because it is another kind of port. Why not "SpiPort"?

Cheers


Thanks for this info Mario and thanks for helping me with my problem.

#6 waxie

waxie

    Member

  • Members
  • PipPip
  • 13 posts

Posted 02 September 2011 - 06:17 AM

Just for completness here is my code now which fully works! Thanks again.

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 System.IO.Ports;
using System.Text;

namespace NetduinoPlusApplicationLCDTest4
{
    public class Program
    {
        public static void Main()
        {
            // write your code here
            SerialPort sPort = new SerialPort(SerialPorts.COM1, 9600, Parity.None, 8, StopBits.One);
            sPort.Open();

            byte[] buffer = null;

            string text = "Starting Up!";
            buffer = Encoding.UTF8.GetBytes(text);
            sPort.Write(buffer, 0, buffer.Length); // Write to LCD

            Thread.Sleep(3000);

            // Now lets clear display!
            sPort.Write(new byte[] { 0x00FE, 0x01 }, 0, 2); // Write to LCD

            while (true)
            {
                text = "hello ";
                buffer = Encoding.UTF8.GetBytes(text);
                sPort.Write(buffer, 0, buffer.Length); // Write to LCD

                Thread.Sleep(500);

                text = "Netduino";
                buffer = Encoding.UTF8.GetBytes(text);
                sPort.Write(buffer, 0, buffer.Length); // Write to LCD

                Thread.Sleep(500);

                // Now lets clear display!
                sPort.Write(new byte[] { 0x00FE, 0x01 }, 0, 2); // Write to LCD

                Thread.Sleep(500);

            }

            Thread.Sleep(Timeout.Infinite);


        }

    }
}


#7 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 02 September 2011 - 06:40 AM

Hello waxie! I am happy that you resolved your problem.
Just for curiosity and completeness, what do you see if you try to write a text containing "special" characters, like the extended alphabet, for instance?
You may try to write the following string:

àèìòù€äöüñ

Cheers
Biggest fault of Netduino? It runs by electricity.

#8 waxie

waxie

    Member

  • Members
  • PipPip
  • 13 posts

Posted 02 September 2011 - 09:20 AM

Hello waxie! I am happy that you resolved your problem.
Just for curiosity and completeness, what do you see if you try to write a text containing "special" characters, like the extended alphabet, for instance?
You may try to write the following string:

Cheers


Hi Mario.

I am at work at the moment but when I get back home tonight I will test your sample chracters and see what is displayed on the LCD and report back.

#9 waxie

waxie

    Member

  • Members
  • PipPip
  • 13 posts

Posted 04 September 2011 - 06:45 AM

Hi there.

Okay so I tried your special characters using this code:

string text = "àèìòù€äöüñ"; // "Starting Up!";
buffer = Encoding.UTF8.GetBytes(text);
sPort.Write(buffer, 0, buffer.Length); // Write to LCD

and it produces klingon!!!! :) It doesnt like those special characters.

Here is a screenshot

#10 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 04 September 2011 - 07:57 AM

and it produces klingon!!!! :) It doesnt like those special characters.

It's Japanese - you'd need to get the LCD controller's datasheet to see what character table it has. Usually, the controller has character generator RAM, which can be programmed with custom glyphs, so it is possible to display different special characters; you may also need to use appropriate code table (encoding), i.e. other than UTF8.

#11 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 04 September 2011 - 08:52 AM

It's Japanese - you'd need to get the LCD controller's datasheet to see what character table it has. Usually, the controller has character generator RAM, which can be programmed with custom glyphs, so it is possible to display different special characters; you may also need to use appropriate code table (encoding), i.e. other than UTF8.

That's exactly the reason I asked him to try with extra-ASCII chars.

@waxie: at this point you may even avoid the UTF8 encoding, because it has no sense. BTW, it may produce false results. The LCD assumes always 1 char = 1 byte, while UTF may carry out two bytes for a single char.
I'd map the text as follows:
string text = "àèìòù€äöüñ"; // "Starting Up!";
buffer = Encoding.ASCII.GetBytes(text);
sPort.Write(buffer, 0, buffer.Length); // Write to LCD
Cheers
Biggest fault of Netduino? It runs by electricity.




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.