Someone please stop me from killing myself. I’ve spent about 5 hours today trying to make this silly LCD work, and it is still defeating me. I know the screen itself works, when i short the test jumpers it displays the test message just fine, however whenever I try to send it any messages, nothing happens (And yes, the i2c jumper is shorted).
Please have a look at my code and try to work out how it is different from the BASIC code presented in the AXE033 datasheet. Btw, my SCL and SDA are soldered properly, as I am able to access the DS1307 which is on that same board and bus just fine.
Here is what it should be, in BASIC code:
init: pause 500 // wait for display to initialise
i2cslave $C6,i2cslow,i2cbyte // set up i2cslave for LCD
main: writei2c 0,(254,128,255) // move to start of first line
pause 10 // wait for LCD to process data
writei2c 0,("Hello!123",255) // output text
end
Here is my attempt to achieve this in C# :
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.IO;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.IO;
namespace AXE033_API
{
public class AXE033_LCD
{
private static I2CDevice.Configuration AXE033_Config;
private static I2CDevice AXE033;
public AXE033_LCD(byte Address, int ClockRateKHz)
{
AXE033_Config = new I2CDevice.Configuration(Address, ClockRateKHz);
AXE033 = new I2CDevice(AXE033_Config);
}
public bool MoveCursor(int Line, int Position)
{
int MemoryPosition;
byte[] Command;
if (Line == 1) {
MemoryPosition = 128;
} else if (Line == 2) {
MemoryPosition = 192;
} else {
return false;
}
MemoryPosition += Position;
Command = new byte[4] {0,254,(byte)MemoryPosition, 255};
var xActions = new I2CDevice.I2CTransaction[2];
byte[] reg = new byte[1] { 0 };
xActions[0] = I2CDevice.CreateWriteTransaction(reg);
xActions[1] = I2CDevice.CreateWriteTransaction(Command);
AXE033.Execute(xActions, 1000);
Thread.Sleep(100);
Debug.Print("Cursor Moved");
return true;
}
public bool DisplayMessage(string Message)
{
int MessageLength = Message.Length;
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(Message+"0");
buffer[MessageLength] = 255;
var xActions = new I2CDevice.I2CTransaction[2];
byte[] reg = new byte[1] { 0 };
xActions[0] = I2CDevice.CreateWriteTransaction(reg);
xActions[1] = I2CDevice.CreateWriteTransaction(buffer);
AXE033.Execute(xActions, 1000);
Thread.Sleep(100);
Debug.Print("Message Displayed");
return true;
}
}
public class Program
{
public static void Main()
{
Thread.Sleep(2500);
AXE033_LCD AXE033 = new AXE033_LCD(0x63, 100);
AXE033.MoveCursor(1, 1);
AXE033.DisplayMessage("Hello");
}
}
}
Can anyone spot what I’m doing wrong? Its probably something simple to do with me misunderstanding the way i2c works, and I have really tried for a long time to make this work, but it isn’t happening.