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):
- RX to Digital I/O pin 3 (which is COM2 TX - netduino Plus Pins Chart)
- GND to GND
- VDD to 5V
Thanks to everyone for the help and hope this saves someone else some time
Cheers,
Donovan