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

Serial LCD and Netduino Plus 2


  • Please log in to reply
4 replies to this topic

#1 don664

don664

    Advanced Member

  • Members
  • PipPipPip
  • 77 posts
  • LocationHillcrest, KZN, South Africa

Posted 20 November 2012 - 08:02 AM

Hi there,

After struggling with this for a day I finally got it working and thought I'd share.

The problem seemed to be with the declaration syntax (sorry if I'm using the wrong terminology here) between .Net Micro Framework 4.1 and 4.2.

For example the class I was trying to use declared the serial port like this:
_lcd = new SerialPort(com, 9600, Parity.None, 8, StopBits.One);

Yet it needs to be like this:
_lcd = new System.IO.Ports.SerialPort(com, 9600, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);

Once I sorted that out it all seems to be working just fine now. This syntax was corrected by right clicking on the red underlined text, such as SerialPort, and selecting "Resolve"... IntelliSense does the rest for you ;)

Here's the LCD class (LCD.cs):

using System;
using Microsoft.SPOT;

namespace slcdHelloWorld
{
    class LCD
    {
        private System.IO.Ports.SerialPort _lcd;
        private byte[] clear = { 0xFE, 0x01 };
        private byte[] blinkboxon = { 0xFE, 0x0D };
        private byte[] blinkboxoff = { 0xFE, 0x0C };
        
        public LCD(string com)
        { 
            _lcd = new System.IO.Ports.SerialPort(com, 9600, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
            _lcd.Open();
            this.Clear();
            this.MoveCur(0);
            this.Write(blinkboxoff);
        }

        public void Clear()
        {
            this.Write(clear);
            this.MoveCur(0);
            this.Write(blinkboxoff);
        }

        public void Write(byte[] B)
        {
            _lcd.Write(b, 0, b.Length);
        }

        public void MoveCur(int i)
        {
            this.Write(blinkboxon);

            if (i > 15) i += 48;
            byte locByte = (byte)(128 + i);
            byte[] moveto = { 0xFE, locByte };
            Debug.Print("MoveTo - " + moveto[0].ToString() + " - " + moveto[1].ToString() + " - locByte " + locByte.ToString());
            this.Write(moveto);
        }
    }
}


And here's the Program.cs:

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.Netduino;

namespace slcdHelloWorld
{
    public class Program
    {
        // initialise the LCD display
        static LCD mylcd = new LCD("COM2");

        public static void Main()
        {
            // write your code here
            while (true)            {
                
                mylcd.Clear();
                byte[] bytes = System.Text.Encoding.UTF8.GetBytes("Hello World");
                mylcd.Write(bytes);
                Thread.Sleep(5000);
                mylcd.Clear();
                mylcd.MoveCur(30); 
            }
        }

    }
}


In terms of connecting up the Serial LCD (https://www.sparkfun.com/products/9395) simply run wires like this (LCD to Netduino):


Posted Image

Thanks to everyone for the help and hope this saves someone else some time :D

Cheers,
Donovan

#2 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 20 November 2012 - 11:52 AM

You can also do: using System.IO.Ports; Then you don't need to preface everything with System.IO.Ports

#3 don664

don664

    Advanced Member

  • Members
  • PipPipPip
  • 77 posts
  • LocationHillcrest, KZN, South Africa

Posted 20 November 2012 - 12:21 PM

Ah ha! Thanks Dave :D

#4 Chuckles

Chuckles

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 17 June 2013 - 01:45 AM

Hi Donovan. Both that part and then one at https://www.sparkfun.com/products/9568 seem to require 5V. How did you deal with that?

Thanks.

#5 don664

don664

    Advanced Member

  • Members
  • PipPipPip
  • 77 posts
  • LocationHillcrest, KZN, South Africa

Posted 18 June 2013 - 10:12 AM

Hi Chuckles,

 

The supplier I use offers a 3.3V Serial LCD: http://www.netram.co...tml?keyword=lcd

 

Cheers,

Donovan






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.