All devices now also have a native SPI display provider that is used just like the existing parallel displays. On a DisplayController created for the SPI native API, call ApplySettings with an instance of SpiDisplayControllerSettings. Then just create an instance of Graphics like previously. Some displays, like the N18, require certain configuration before flushing data, so make sure to do that yourself before calling Flush. It’s also expected that you initialize the display itself as well.
Is there any example code available using this controller for the N18? I am experimenting with the G80 Development Board.
Reworking TinyCLR 0.9 code for G400 Development Board:
using System;
using System.Collections;
using System.Text;
using System.Threading;
using GHIElectronics.TinyCLR.Devices.Display;
using System.Drawing;
using GHIElectronics.TinyCLR.Pins;
namespace TinyCLRG80_SPIDisplay
{
class Program
{
static void Main()
{
DisplayController displayController = DisplayController.GetDefault();
// Enter the proper display configurations
displayController.ApplySettings(new SpiDisplayControllerSettings
{
Width = 128,
Height = 160,
SpiSelector = G80.SpiBus.Spi2
});
Font font = Resource1.GetFont(Resource1.FontResources.small);
// Some needed objects
Graphics screen = Graphics.FromHdc(displayController.Hdc);
Pen GreenPen = new Pen(Color.Green);
// Start Drawing (to memroy)
screen.Clear(Color.Black);
screen.DrawEllipse(GreenPen, 40, 30, 20, 40);
// Flush the memory to the display. This is a very fast operation.
screen.DrawString("Text", font, new SolidBrush(Color.White), 50, 50);
// screen.FillRectangle(new SolidBrush(Color.Red), 10, 136, 460, 100);
// screen.DrawString("Overlay", font, new SolidBrush(Color.Black), 50, 150);
screen.Flush();
displayController.WriteString("Test");
}
}
}
The following exception is thrown at runtime:
An unhandled exception of type ‘System.ArgumentException’ occurred in mscorlib.dll occurred
Also, what string is required for the “SpiSelector” setting?
Thanks.
I think you need to know the SPI port attached to the display. You are using SPI2 port. Anyway the driver doesn’t initialize the spi display. You need to send via direct SPI connection all the init commands BEFORE using the spi display driver itself.
I can’t help you about N18, but I think you can find info on the internet (arduino, netmf and so on…).
Updated firmware to 0.10.0 and updated libraries to 0.10.0 - compiles and deploys ok - display is all white.
Rolling back to 0.9 and it all works again.
The Release Notes indicated a number of display fixes. It appears the update has changed something that invalidates this display code. Can others confirm?
Thanks.
@John_Brochue, thank you. That was it.
Moving GpioController.GetDefault did the trick - all working in 0.10.0.
@Bauland’s code: moved _controlPin = GpioController.GetDefault().OpenPin(controlPin);
and also had to split into two for the Controller and Pin to resolve.