As promised here is your driver and test code for the Newhaven Display I2C serial displays. Enjoy and keep us posted on the progress.
using System; using System.Text; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; namespace NewhavenDisplay { // For use with newhaven I2C displays // I2C protocol: // To enter the I2C mode, place a jumper on R1. // SDA and SDK have pull?up resistors (10K Ohm) on R7 and R8. // The default I2C address is 80 (50 hex). The I2C address can be changed to any 8?bit value by command function, with // the exception that the LSB (least significant bit) must always be ‘0’. Once the I2C address has been changed, it will be // saved in the system memory, and it will revert back to the default address if either RS232 or SPI protocol is selected. // The I2C interface is capable of receiving data at up to 100KHz?clock rate. // See http://www.newhavendisplay.com/specs/NHD-0216K3Z-FL-GBW.pdf public class SerialLCD { private static I2CDevice.Configuration _config = new I2CDevice.Configuration(0x50 >> 1, 100); public SerialLCD() { } public void Write(I2CDevice device, string sText) { device.Config = _config; var xActions = new I2CDevice.I2CTransaction[1]; byte[] buf = Encoding.UTF8.GetBytes(sText); // Convert the string to array xActions[0] = I2CDevice.CreateWriteTransaction(buf); device.Execute(xActions, 1000); } public void DisplayOn(I2CDevice device) { device.Config = _config; var xActions = new I2CDevice.I2CTransaction[1]; xActions[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0xFE, 0x41 }); device.Execute(xActions, 1000); } public void DisplayOff(I2CDevice device) { device.Config = _config; var xActions = new I2CDevice.I2CTransaction[1]; xActions[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0xFE, 0x42 }); device.Execute(xActions, 1000); } public void SetCursor(I2CDevice device, byte Position) { // 0x00 = line 1 column 1 // 0x40 = line 2 column 1 device.Config = _config; var xActions = new I2CDevice.I2CTransaction[1]; xActions[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0xFE, 0x45, Position }); device.Execute(xActions, 1000); } public void Clear(I2CDevice device) { device.Config = _config; var xActions = new I2CDevice.I2CTransaction[1]; xActions[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0xFE, 0x51 }); device.Execute(xActions, 1000); } public void SetContrast(I2CDevice device, byte ContrastLevel) { // Value between 0 and 50, default is 40 device.Config = _config; var xActions = new I2CDevice.I2CTransaction[1]; xActions[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0xFE, 0x52, ContrastLevel }); device.Execute(xActions, 1000); } public void SetBrightness(I2CDevice device, byte BrightnessLevel) { // Value between 1 to 8 device.Config = _config; var xActions = new I2CDevice.I2CTransaction[1]; xActions[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0xFE, 0x53, BrightnessLevel }); device.Execute(xActions, 1000); } public void Firmware(I2CDevice device) { device.Config = _config; var xActions = new I2CDevice.I2CTransaction[1]; xActions[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0xFE, 0x70 }); device.Execute(xActions, 1000); } } }
using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using NewhavenDisplay; namespace Serial_Display_Test { public class Program { public static void Main() { // Create an I2C device with no device configuration I2CDevice i2cDevice = new I2CDevice(null); SerialLCD display = new SerialLCD(); display.DisplayOn(i2cDevice); // Write to display display.Clear(i2cDevice); display.SetCursor(i2cDevice, 0x00); display.Write(i2cDevice, "Hello"); // Wait indefinitely Thread.Sleep(Timeout.Infinite); } } }