public static void InitializeDisplay() { var spi = SpiController.FromName(SC20100.SpiBus.Spi4); var gpio = GpioController.GetDefault(); DisplayController = new ST7735Controller( spi.GetDevice(ST7735Controller.GetConnectionSettings(SpiChipSelectType.Gpio, gpio.OpenPin(SC20100.GpioPin.PD10))), // ChipSelect gpio.OpenPin(SC20100.GpioPin.PC4), // Pin RS gpio.OpenPin(SC20100.GpioPin.PE15) // Pin RESET ); var bl = gpio.OpenPin(SC20100.GpioPin.PA15); // back light bl.Write(GpioPinValue.High); bl.SetDriveMode(GpioPinDriveMode.Output); DisplayController.SetDataAccessControl(true, true, false, false); //Rotate the screen. DisplayController.SetDrawWindow(0, 0, Width, Height); DisplayController.Enable(); // Create flush event Graphics.OnFlushEvent += Graphics_OnFlushEvent; }
static void InitDisplay() { // Display Get Ready //////////////////////////////////// var spi = SpiController.FromName(FEZBit.SpiBus.Display); var gpio = GpioController.GetDefault(); st7735 = new ST7735Controller( spi.GetDevice(ST7735Controller.GetConnectionSettings (SpiChipSelectType.Gpio, GpioController.GetDefault().OpenPin(FEZBit.GpioPin.DisplayCs))), //CS pin. gpio.OpenPin(FEZBit.GpioPin.DisplayRs), //RS pin. gpio.OpenPin(FEZBit.GpioPin.DisplayReset) //RESET pin. ); var backlight = gpio.OpenPin(FEZBit.GpioPin.Backlight); backlight.SetDriveMode(GpioPinDriveMode.Output); backlight.Write(GpioPinValue.High); st7735.SetDataAccessControl(true, true, false, false); //Rotate the screen. st7735.SetDrawWindow(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); st7735.Enable(); // Create flush event Graphics.OnFlushEvent += Graphics_OnFlushEvent;; // Create bitmap buffer screen = Graphics.FromImage(new Bitmap(SCREEN_WIDTH, SCREEN_HEIGHT)); font12 = Resource.GetFont(Resource.FontResources.droid_reg12); screen.Clear(); screen.DrawRectangle(new Pen(new SolidBrush(Color.White)), 10, 10, SCREEN_WIDTH - 20, SCREEN_HEIGHT - 20); screen.DrawString("FEZ Bit", font12, new SolidBrush(Color.Red), 55, 30); screen.DrawString("SITCore", font12, new SolidBrush(Color.Green), 50, 50); screen.DrawString("GHI Electronics", font12, new SolidBrush(Color.Blue), 25, 70); screen.Flush(); }
static void InitializeSPIDisplay() { var spi = SpiController.FromName(SC20100.SpiBus.Spi3); var gpio = GpioController.GetDefault(); var csPin = gpio.OpenPin(SC20100.GpioPin.PD10); st7735 = new ST7735Controller( spi.GetDevice(ST7735Controller.GetConnectionSettings(SpiChipSelectType.Gpio, csPin)), // CS PD10 gpio.OpenPin(SC20100.GpioPin.PC4), // PE10 RS gpio.OpenPin(SC20100.GpioPin.PE15) // PE10 RESET ); st7735.SetDataAccessControl(true, true, true, false); var bl = gpio.OpenPin(SC20100.GpioPin.PE5); // Backligth PC7 bl.SetDriveMode(GpioPinDriveMode.Output); bl.Write(GpioPinValue.High); Graphics.OnFlushEvent += Graphics_OnFlushEvent; graphic = Graphics.FromImage(new Bitmap(160, 128)); }
static void TestWithGraph(MicClick mic) { const int SCREEN_WIDTH = 160; const int SCREEN_HEIGHT = 128; int graph; var spi = SpiController.FromName(SC20100.SpiBus.Spi3); var gpio = GpioController.GetDefault(); //Display Setup var st7735 = new ST7735Controller( spi.GetDevice(ST7735Controller.GetConnectionSettings (SpiChipSelectType.Gpio, SC20100.GpioPin.PD10)), //CS pin. gpio.OpenPin(SC20100.GpioPin.PC4), //RS pin. gpio.OpenPin(SC20100.GpioPin.PE15) //RESET pin. ); var backlight = gpio.OpenPin(SC20100.GpioPin.PE5); backlight.SetDriveMode(GpioPinDriveMode.Output); backlight.Write(GpioPinValue.High); var displayController = DisplayController.FromProvider(st7735); st7735.SetDataAccessControl(true, true, false, false); //Rotate the screen. displayController.SetConfiguration(new SpiDisplayControllerSettings { Width = SCREEN_WIDTH, Height = SCREEN_HEIGHT, DataFormat = DisplayDataFormat.Rgb565 }); displayController.Enable(); // Create flush event Graphics.OnFlushEvent += Graphics_OnFlushEvent; var screen = Graphics.FromImage(new Bitmap (displayController.ActiveConfiguration.Width, displayController.ActiveConfiguration.Height)); while (true) { graph = (int)(mic.Read() * 100) + 20; if (x++ > SCREEN_WIDTH) { x = 0; screen.Clear(Color.Black); } screen.DrawLine(new Pen(Color.Green), x, SCREEN_HEIGHT, x, graph); screen.Flush(); } void Graphics_OnFlushEvent(IntPtr hdc, byte[] data) { st7735.DrawBuffer(data); } }
public static void Main() { var spi = SpiController.FromName(G80.SpiBus.Spi2); var gpio = GpioController.GetDefault(); var st7735 = new ST7735Controller(spi.GetDevice(ST7735Controller.GetConnectionSettings(SpiChipSelectType.Gpio, G80.GpioPin.PD10)), gpio.OpenPin(G80.GpioPin.PE10), gpio.OpenPin(G80.GpioPin.PE12)); st7735.SetDataAccessControl(true, true, false, false); st7735.Enable(); var disp = DisplayController.FromProvider(st7735); disp.SetConfiguration(new SpiDisplayControllerSettings { Width = 160, Height = 128 }); var bl = gpio.OpenPin(G80.GpioPin.PC7); bl.Write(GpioPinValue.High); bl.SetDriveMode(GpioPinDriveMode.Output); var hdc = GraphicsManager.RegisterDrawTarget(new DrawTarget(disp)); var screen = Graphics.FromHdc(hdc); var rnd = new Random(); var x = rnd.Next(160); var y = rnd.Next(128); var vx = rnd.Next(20) - 10; var vy = rnd.Next(20) - 10; var color = new Pen(Color.Green); var teal = new SolidBrush(Color.Teal); // This is a special built-in font for simple SPI displays var font = new Font("GHIMono8x5", 8); while (true) { x += vx; y += vy; if (x >= 160 || x < 0) { vx *= -1; } if (y >= 128 || y < 0) { vy *= -1; } screen.Clear(Color.Black); screen.DrawString("Hello World!", font, teal, 40, 10); screen.DrawEllipse(color, x, y, 10, 10); screen.Flush(); Thread.Sleep(10); } }
/// <summary> /// Constructor of TftDisplayShield /// </summary> /// <param name="i2CBus">Id of I2C bus</param> /// <param name="spiBus">Id of Spi bus</param> /// <param name="pinChipSelect">Id of ChipSelect pin (D10)</param> /// <param name="pinDataCommand">Id of control pin (D8)</param> /// <param name="bgrPanel">if true display is BGR panel, else it is RGB panel</param> public TftDisplayShield(string i2CBus, string spiBus, int pinChipSelect, int pinDataCommand, bool bgrPanel = false) : base(i2CBus, Address) { _bgrPanel = bgrPanel; PinMode(ResetPin, GpioPinDriveMode.Output); PinModeBulk(Button.All, GpioPinDriveMode.InputPullUp); SetBackLight(BackLightOff); ResetTft(); var dc = GpioController.GetDefault().OpenPin(pinDataCommand); dc.SetDriveMode(GpioPinDriveMode.Output); _st7735Controller = new ST7735Controller(SpiController.FromName(spiBus).GetDevice(ST7735Controller.GetConnectionSettings(SpiChipSelectType.Gpio, pinChipSelect)), dc); SetOrientation(Orientation.Landscape); _oldState = ReadButtons() ^ Button.All; }
/// <summary> /// Constructor of TftDisplayShield /// </summary> /// <param name="i2CBus">Id of I2C bus</param> /// <param name="spiBus">Id of Spi bus</param> /// <param name="pinChipSelect">Id of ChipSelect pin (D10)</param> /// <param name="pinDataCommand">Id of control pin (D8)</param> /// <param name="bgrPanel">if true display is BGR panel, else it is RGB panel</param> public TftDisplayShield(string i2CBus, string spiBus, GpioPin pinChipSelect, GpioPin pinDataCommand, bool bgrPanel = false) : base(i2CBus, Address) { _bgrPanel = bgrPanel; PinMode(ResetPin, GpioPinDriveMode.Output); PinModeBulk(Button.All, GpioPinDriveMode.InputPullUp); SetBackLight(BackLightOff); ResetTft(); var spi = SpiController.FromName(spiBus); var spiConnectionString = ST7735Controller.GetConnectionSettings(SpiChipSelectType.Gpio, pinChipSelect); _st7735Controller = new ST7735Controller(spi.GetDevice(spiConnectionString), pinDataCommand); _st7735Controller.Enable(); Graphics.OnFlushEvent += Graphics_OnFlushEvent; _oldState = ReadButtons() ^ Button.All; }
public static void Main() { var spi1Controller = SpiController.FromName(FEZ.SpiBus.Spi1); var gpioController = GpioController.GetDefault(); var st7735 = new ST7735Controller(spi1Controller.GetDevice(ST7735Controller.GetConnectionSettings(SpiChipSelectType.Gpio, FEZ.GpioPin.D10)), gpioController.OpenPin(FEZ.GpioPin.D8)); st7735.SetDataAccessControl(false, false, false, false); st7735.SetDrawWindow(0, 40); var display = DisplayController.FromProvider(st7735); display.SetConfiguration(new SpiDisplayControllerSettings { Width = 128, Height = 80, DataFormat = DisplayDataFormat.Rgb444 }); display.Enable(); var hdc = GraphicsManager.RegisterDrawTarget(new DrawTarget(display)); var screen = Graphics.FromHdc(hdc); var cnt = 0; var font = new Font("GHIMono8x5", 8); while (true) { screen.Clear(Color.Black); screen.DrawString(cnt++.ToString(), font, new SolidBrush(Color.Purple), 0, 40); screen.DrawEllipse(new Pen(Color.Blue), 0, 0, 10, 10); screen.DrawRectangle(new Pen(Color.Red), 10, 0, 10, 10); screen.DrawLine(new Pen(Color.Green, 1), 25, 0, 22, 24); screen.DrawString("The quick brown fox jumped over the lazy dogs.", font, new SolidBrush(Color.Teal), new RectangleF(40, 0, 60, 40)); var idx = 0; screen.DrawLine(new Pen(Color.Black, 1), 60 + idx, 40, 60 + idx, 70); idx += 4; screen.DrawLine(new Pen(Color.White, 1), 60 + idx, 40, 60 + idx, 70); idx += 4; screen.DrawLine(new Pen(Color.Gray, 1), 60 + idx, 40, 60 + idx, 70); idx += 4; screen.DrawLine(new Pen(Color.Red, 1), 60 + idx, 40, 60 + idx, 70); idx += 4; screen.DrawLine(new Pen(Color.Green, 1), 60 + idx, 40, 60 + idx, 70); idx += 4; screen.DrawLine(new Pen(Color.Blue, 1), 60 + idx, 40, 60 + idx, 70); idx += 4; screen.DrawLine(new Pen(Color.Yellow, 1), 60 + idx, 40, 60 + idx, 70); idx += 4; screen.DrawLine(new Pen(Color.Purple, 1), 60 + idx, 40, 60 + idx, 70); idx += 4; screen.DrawLine(new Pen(Color.Teal, 1), 60 + idx, 40, 60 + idx, 70); idx += 4; screen.Flush(); } }
public WaveShare18Display(GpioPin reset, GpioPin rs, GpioPin cs, SpiController spi, GpioPin backlight) { // Display Get Ready //////////////////////////////////// var gpio = GpioController.GetDefault(); this.backlight = backlight; this.st7735 = new ST7735Controller( spi.GetDevice(ST7735Controller.GetConnectionSettings (SpiChipSelectType.Gpio, cs)), //CS pin. rs, //RS pin. reset //RESET pin. ); backlight.SetDriveMode(GpioPinDriveMode.Output); backlight.Write(GpioPinValue.High); this.st7735.SetDataAccessControl(true, true, false, false); //Rotate the screen. this.st7735.SetDrawWindow(0, 0, 160, 128); this.st7735.Enable(); // Create flush event Graphics.OnFlushEvent += this.Graphics_OnFlushEvent; }
public static void Main() { // Get the display ready var spi = SpiController.FromName(G80.SpiBus.Spi2); var gpio = GpioController.GetDefault(); var st7735 = new ST7735Controller(spi.GetDevice(ST7735Controller.GetConnectionSettings(SpiChipSelectType.Gpio, G80.GpioPin.PD10)), gpio.OpenPin(G80.GpioPin.PE10), gpio.OpenPin(G80.GpioPin.PE12)); st7735.SetDataAccessControl(true, true, false, false); st7735.Enable(); var disp = DisplayController.FromProvider(st7735); disp.SetConfiguration(new SpiDisplayControllerSettings { Width = 160, Height = 128 }); var bl = gpio.OpenPin(G80.GpioPin.PC7); bl.Write(GpioPinValue.High); bl.SetDriveMode(GpioPinDriveMode.Output); var hdc = GraphicsManager.RegisterDrawTarget(new DrawTarget(disp)); screen = Graphics.FromHdc(hdc); screen.Clear(Color.Black); var btn1 = gpio.OpenPin(G80.GpioPin.PE0); btn1.SetDriveMode(GpioPinDriveMode.InputPullUp); btn1.ValueChanged += Btn1_ValueChanged; // Serial port serial = UartController.FromName(G80.UartPort.Usart1); serial.SetActiveSettings(9600, 8, UartParity.None, UartStopBitCount.One, UartHandshake.None); serial.Enable(); serial.DataReceived += Serial_DataReceived; Thread.Sleep(Timeout.Infinite); }