/// <summary> /// This sets up a 16x2 character LCD, directly connected to a set of GPIO pins, with a hardwired or no backlight and 4 Bit commands /// </summary> private static void UsingGpioPins() { using (Lcd1602 lcd = new Lcd1602(registerSelectPin: 22, enablePin: 17, dataPins: new int[] { 25, 24, 23, 18 })) { lcd.Clear(); lcd.Write("Hello World"); } }
/// <summary> /// This program will print `Hello World` /// </summary> /// <param name="args">Should be empty</param> static void Main(string[] args) { // Sets up a 16x2 character LCD with a hardwired or no backlight. using (Lcd1602 lcd = new Lcd1602(registerSelect: 1, enable: 2, data: new int[] { 3, 4, 5, 6 })) { lcd.Clear(); lcd.Write("Hello World"); } }
/// <summary> /// This program will print `Hello World` /// </summary> /// <param name="args">Should be empty</param> static void Main(string[] args) { // Sets up a 16x2 character LCD with a hardwired or no backlight. using (Lcd1602 lcd = new Lcd1602(registerSelectPin: 22, enablePin: 17, dataPins: new int[] { 25, 24, 23, 18 })) { lcd.Clear(); lcd.Write("Hello World"); } }
private static (ITextDisplayDevice, IDisposable) Create(GpioController gpioController) { var lcdInterface = LcdInterface.CreateGpio(ToChipPin(29), ToChipPin(32), new[] { ToChipPin(31), ToChipPin(33), ToChipPin(35), ToChipPin(37) }, controller: gpioController, shouldDispose: false); var hd44780 = new Lcd1602(lcdInterface); return(new Sundew.TextView.Iot.Devices.Drivers.LcdTextDisplayDevice(hd44780, "A00"), hd44780); }
static void Main(string[] args) { Lcd1602 lcd = new Lcd1602(I2cDevice.Create(new I2cConnectionSettings(1, DefaultLcdAddress))) { DisplayOn = true, BacklightOn = true, BlinkingCursorVisible = true, Increment = true, }; lcd.Write("Hello, World!"); }
public void TestMethod1() { using (Lcd1602 lcd = new Lcd1602(new I2CMock("/dev/i2c-1", 0x27))) //0x27 address of LCD { Console.WriteLine("Init"); lcd.Init(); Console.WriteLine("Clear"); lcd.Clear(); Console.WriteLine("Hello"); lcd.Write(0, 0, "Hello"); Console.WriteLine("World!"); lcd.Write(0, 1, "World!"); } }
public static void TemperatureCharacters(Lcd1602 lcd) { byte[] temperatureCharacters = new byte[8]; temperatureCharacters[0] = 0b_11000; temperatureCharacters[1] = 0b_11000; temperatureCharacters[2] = 0b_00011; temperatureCharacters[3] = 0b_00100; temperatureCharacters[4] = 0b_00100; temperatureCharacters[5] = 0b_00100; temperatureCharacters[6] = 0b_00011; temperatureCharacters[7] = 0b_00000; lcd.CreateCustomCharacter(TemperatureCharactersNumber, temperatureCharacters); }
public CharacterDisplay(ArduinoBoard board) { _controller = board.CreateGpioController(); _display = new Lcd1602(8, 9, new int[] { 4, 5, 6, 7 }, -1, 1.0f, -1, _controller); _display.BlinkingCursorVisible = false; _display.UnderlineCursorVisible = false; _display.Clear(); _textController = new LcdConsole(_display, "SplC780", false); _textController.Clear(); LcdCharacterEncodingFactory f = new LcdCharacterEncodingFactory(); var cultureEncoding = f.Create(CultureInfo.CurrentCulture, "SplC780", '?', _display.NumberOfCustomCharactersSupported); _textController.LoadEncoding(cultureEncoding); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { using I2cDevice i2c = I2cDevice.Create(new I2cConnectionSettings(1, 0x27)); using Pcf8574 driver = new Pcf8574(i2c); lcd = new Lcd1602(registerSelectPin: 0, enablePin: 2, dataPins: new int[] { 4, 5, 6, 7 }, backlightPin: 3, backlightBrightness: 1f, readWritePin: 1, controller: new GpioController(PinNumberingScheme.Logical, driver)); while (!stoppingToken.IsCancellationRequested) { TemperatureDto interiorTemp = await _temperatureReadingService.GetLatestInteriorReadingAsync(); lcd.Clear(); string output = string.Empty; DisplayLcdText( interiorTemp != null ? $"In: {interiorTemp.Fahrenheit.ToString()}F {interiorTemp.Celsius.ToString()}C" : "No Data", DateTime.Now.ToString("ddd MM/dd HH:mm") ); await Task.Delay(TimeSpan.FromSeconds(DelaySeconds), stoppingToken); TemperatureDto minInteriorTemp = await _temperatureReadingService.GetMinInteriorReadingAsync(); TemperatureDto maxInteriorTemp = await _temperatureReadingService.GetMaxInteriorReadingAsync(); output = string.Empty; DisplayLcdText( minInteriorTemp != null ? $"Min: {minInteriorTemp.Fahrenheit.ToString()}F {minInteriorTemp.Celsius.ToString()}C" : string.Empty, maxInteriorTemp != null ? $"Max: {maxInteriorTemp.Fahrenheit.ToString()}F {maxInteriorTemp.Celsius.ToString()}C" : string.Empty ); await Task.Delay(TimeSpan.FromSeconds(DelaySeconds), stoppingToken); } }
static void Test1602() { using (Lcd1602 lcd = new Lcd1602(new I2C("/dev/i2c-1", 0x27))) //0x27 address of LCD { lcd.Init(); lcd.Clear(); var screenWidth = 16; var message = "Hello Krysia, how are you today?"; var text = message.PadLeft(message.Length + screenWidth).PadRight(message.Length + 2 * screenWidth); for (var i = 0; i < text.Length - screenWidth + 1; i++) { lcd.Write(0, 0, text.Substring(i, screenWidth)); Thread.Sleep(250); } } }
/// <summary> /// This method will use an mcp gpio extender to connect to the LCM display. /// This has been tested on the CrowPi lcd display. /// </summary> static void UsingMcp() { UnixI2cDevice i2CDevice = new UnixI2cDevice(new I2cConnectionSettings(1, 0x21)); Mcp23008 mcpDevice = new Mcp23008(i2CDevice); int[] dataPins = { 3, 4, 5, 6 }; int registerSelectPin = 1; int enablePin = 2; int backlight = 7; using (mcpDevice) using (Lcd1602 lcd = new Lcd1602(registerSelectPin, enablePin, dataPins, backlight, controller: mcpDevice)) { lcd.Clear(); lcd.Write("Hello World"); lcd.SetCursorPosition(0, 1); lcd.Write(".NET Core"); } }
/// <summary> /// This method will use an mcp gpio extender to connect to the LCM display. /// This has been tested on the CrowPi lcd display. /// </summary> private static void UsingMcp() { I2cDevice i2CDevice = I2cDevice.Create(new I2cConnectionSettings(1, 0x21)); Mcp23008 driver = new Mcp23008(i2CDevice); int[] dataPins = { 3, 4, 5, 6 }; int registerSelectPin = 1; int enablePin = 2; int backlight = 7; using (driver) using (Lcd1602 lcd = new Lcd1602(registerSelectPin, enablePin, dataPins, backlight, controller: new GpioController(PinNumberingScheme.Logical, driver))) { lcd.Clear(); lcd.Write("Hello World"); lcd.SetCursorPosition(0, 1); lcd.Write(".NET Core"); } }
public static void SampleEntryPoint() { Console.WriteLine("Starting..."); // for PCF8574T i2c addresses can be between 0x27 and 0x20 depending on bridged solder jumpers // for PCF8574AT i2c addresses can be between 0x3f and 0x38 depending on bridged solder jumpers var i2cDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x27)); var driver = new Pcf8574(i2cDevice); var lcd = new Lcd1602(registerSelectPin: 0, enablePin: 2, dataPins: new int[] { 4, 5, 6, 7 }, backlightPin: 3, readWritePin: 1, controller: new GpioController(PinNumberingScheme.Logical, driver)); using (lcd) { Console.WriteLine("Initialized"); Console.ReadLine(); TestPrompt("SetCursor", lcd, SetCursorTest); TestPrompt("Underline", lcd, l => l.UnderlineCursorVisible = true); lcd.UnderlineCursorVisible = false; TestPrompt("Walker", lcd, WalkerTest); CreateTensCharacters(lcd); TestPrompt("CharacterSet", lcd, CharacterSet); // Shifting TestPrompt("Autoshift", lcd, AutoShift); TestPrompt("DisplayLeft", lcd, l => ShiftDisplayTest(l, a => a.ShiftDisplayLeft())); TestPrompt("DisplayRight", lcd, l => ShiftDisplayTest(l, a => a.ShiftDisplayRight())); TestPrompt("CursorLeft", lcd, l => ShiftCursorTest(l, a => a.ShiftCursorLeft())); TestPrompt("CursorRight", lcd, l => ShiftCursorTest(l, a => a.ShiftCursorRight())); // Long string TestPrompt("Twenty", lcd, l => l.Write(Twenty)); TestPrompt("Fourty", lcd, l => l.Write(Fourty)); TestPrompt("Eighty", lcd, l => l.Write(Eighty)); TestPrompt("Twenty-", lcd, l => WriteFromEnd(l, Twenty)); TestPrompt("Fourty-", lcd, l => WriteFromEnd(l, Fourty)); TestPrompt("Eighty-", lcd, l => WriteFromEnd(l, Eighty)); TestPrompt("Wrap", lcd, l => l.Write(new string('*', 80) + ">>>>>")); TestPrompt("Perf", lcd, PerfTests); // Shift display right lcd.Write("Hello .NET!"); try { int state = 0; Timer timer = new Timer(1000); timer.Elapsed += (o, e) => { lcd.SetCursorPosition(0, 1); lcd.Write(DateTime.Now.ToLongTimeString() + " "); if (state == 0) { state = 1; } else { lcd.ShiftDisplayRight(); state = 0; } }; timer.AutoReset = true; timer.Enabled = true; Console.ReadLine(); } finally { lcd.DisplayOn = false; lcd.BacklightOn = false; Console.WriteLine("Done..."); } } }
public static void Test() { Console.WriteLine("Starting..."); #if USEI2C var i2cDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x21)); var controller = new Mcp23008(i2cDevice); var lcd = new Lcd1602(registerSelectPin: 1, enablePin: 2, dataPins: new int[] { 3, 4, 5, 6 }, backlightPin: 7, controller: controller); #elif USERGB var i2cLcdDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x3E)); var i2cRgbDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x62)); var lcd = new LcdRgb1602(i2cLcdDevice, i2cRgbDevice); #else Hd44780 lcd = new Hd44780(new Size(20, 4), LcdInterface.CreateGpio(12, 26, new int[] { 16, 17, 18, 19, 20, 21, 22, 23 }, readWritePin: 13)); #endif using (lcd) { Console.WriteLine("Initialized"); Console.ReadLine(); TestPrompt("SetCursor", lcd, SetCursorTest); TestPrompt("Underline", lcd, l => l.UnderlineCursorVisible = true); lcd.UnderlineCursorVisible = false; TestPrompt("Walker", lcd, WalkerTest); CreateTensCharacters(lcd); TestPrompt("CharacterSet", lcd, CharacterSet); // Shifting TestPrompt("Autoshift", lcd, AutoShift); TestPrompt("DisplayLeft", lcd, l => ShiftDisplayTest(l, a => a.ShiftDisplayLeft())); TestPrompt("DisplayRight", lcd, l => ShiftDisplayTest(l, a => a.ShiftDisplayRight())); TestPrompt("CursorLeft", lcd, l => ShiftCursorTest(l, a => a.ShiftCursorLeft())); TestPrompt("CursorRight", lcd, l => ShiftCursorTest(l, a => a.ShiftCursorRight())); // Long string TestPrompt("Twenty", lcd, l => l.Write(Twenty)); TestPrompt("Fourty", lcd, l => l.Write(Fourty)); TestPrompt("Eighty", lcd, l => l.Write(Eighty)); TestPrompt("Twenty-", lcd, l => WriteFromEnd(l, Twenty)); TestPrompt("Fourty-", lcd, l => WriteFromEnd(l, Fourty)); TestPrompt("Eighty-", lcd, l => WriteFromEnd(l, Eighty)); TestPrompt("Wrap", lcd, l => l.Write(new string('*', 80) + ">>>>>")); TestPrompt("Perf", lcd, PerfTests); #if USERGB TestPrompt("Colors", lcd, SetBacklightColorTest); #endif // Shift display right lcd.Write("Hello .NET!"); try { int state = 0; Timer timer = new Timer(1000); timer.Elapsed += (o, e) => { lcd.SetCursorPosition(0, 1); lcd.Write(DateTime.Now.ToLongTimeString() + " "); if (state == 0) { state = 1; } else { lcd.ShiftDisplayRight(); state = 0; } }; timer.AutoReset = true; timer.Enabled = true; Console.ReadLine(); } finally { lcd.DisplayOn = false; lcd.BacklightOn = false; Console.WriteLine("Done..."); } } }
public static void FishCharacters(Lcd1602 lcd) { byte[] Fish1 = new byte[8]; Fish1[0] = 0b_00000; Fish1[1] = 0b_00000; Fish1[2] = 0b_00000; Fish1[3] = 0b_00000; Fish1[4] = 0b_00000; Fish1[5] = 0b_10110; Fish1[6] = 0b_11001; Fish1[7] = 0b_10110; byte[] Fish2 = new byte[8]; Fish2[0] = 0b_00000; Fish2[1] = 0b_00000; Fish2[2] = 0b_00000; Fish2[3] = 0b_00000; Fish2[4] = 0b_10110; Fish2[5] = 0b_11001; Fish2[6] = 0b_00110; Fish2[7] = 0b_00000; byte[] Fish3 = new byte[8]; Fish3[0] = 0b_00000; Fish3[1] = 0b_00000; Fish3[2] = 0b_00000; Fish3[3] = 0b_00110; Fish3[4] = 0b_11001; Fish3[5] = 0b_10110; Fish3[6] = 0b_00000; Fish3[7] = 0b_00000; byte[] Fish4 = new byte[8]; Fish4[0] = 0b_00000; Fish4[1] = 0b_00000; Fish4[2] = 0b_10110; Fish4[3] = 0b_11001; Fish4[4] = 0b_10110; Fish4[5] = 0b_00000; Fish4[6] = 0b_00000; Fish4[7] = 0b_00000; byte[] Fish5 = new byte[8]; Fish5[0] = 0b_00000; Fish5[1] = 0b_00110; Fish5[2] = 0b_11001; Fish5[3] = 0b_10110; Fish5[4] = 0b_00000; Fish5[5] = 0b_00000; Fish5[6] = 0b_00000; Fish5[7] = 0b_00000; byte[] Fish6 = new byte[8]; Fish6[0] = 0b_10110; Fish6[1] = 0b_11001; Fish6[2] = 0b_00110; Fish6[3] = 0b_00000; Fish6[4] = 0b_00000; Fish6[5] = 0b_00000; Fish6[6] = 0b_00000; Fish6[7] = 0b_00000; lcd.CreateCustomCharacter(0, Fish1); lcd.CreateCustomCharacter(1, Fish2); lcd.CreateCustomCharacter(2, Fish3); lcd.CreateCustomCharacter(3, Fish4); lcd.CreateCustomCharacter(4, Fish5); lcd.CreateCustomCharacter(5, Fish6); }
static void Main(string[] args) { Heater heater = null; ConsoleEx.WriteLineWithDate("AquariumController is running"); ConsoleEx.WriteLineWithDate("Setting up I2C..."); I2cConnectionSettings settings = new I2cConnectionSettings(BUSID, I2CADDRESS); I2cDevice device = I2cDevice.Create(settings); ConsoleEx.WriteLineWithDate("Setting up UFire EC Probe..."); Iot.Device.UFire.UFire_pH uFire_pH = new Iot.Device.UFire.UFire_pH(device); uFire_pH.UseTemperatureCompensation(true); ConsoleEx.WriteLineWithDate("Setting up MySql db...."); MySqlConnection conn = new MySqlConnection(ConfigurationManager.AppSettings.Get("ConnectionString")); conn.Open(); ConsoleEx.WriteLineWithDate("Setting up Heater...."); heater = new Heater(conn); Timer saveTemperturTimer = Settings.SetupSaveInterval(conn, "TemperatureSaveInterval", Tempertur.SaveTempertur); Timer savePhTimer = Settings.SetupSaveInterval(conn, "PHSaveInterval", Ph.SavePh); //read setting every 5 minute. AutoResetEvent saveTemperturAutoResetEvent = new AutoResetEvent(false); Timer readSetupTimer = new Timer(Settings.ReadSetup, saveTemperturAutoResetEvent, 0, 5 * 60 * 1000); ConsoleEx.WriteLineWithDate("Setting up GpioController...."); _Controller = new GpioController(); _Controller.OpenPin(AIRPUMPPIN, PinMode.Output); ConsoleEx.WriteLineWithDate("Setting up Lcd1602...."); using (Lcd1602 lcd = new Lcd1602(registerSelectPin: LCDRSPIN, enablePin: LCDENABLEPIN, dataPins: LCDDATA, shouldDispose: true)) { LcdConsole console = new LcdConsole(lcd, "A00", false) { LineFeedMode = LineWrapMode.Wrap, ScrollUpDelay = new TimeSpan(0, 0, 1) }; SetCharacters.FishCharacters(lcd); SetCharacters.TemperatureCharacters(lcd); lcd.SetCursorPosition(0, 0); int _fishCount = 0; bool _revers = false; int _positionCount = 0; while (!Console.KeyAvailable) { try { Tempertur.TemperturValue = Convert.ToDouble(uFire_pH.MeasureTemp()) + Tempertur.TemperturCalibrateOffSet; Ph.PH = Math.Round(uFire_pH.MeasurepH(), 1); string tempterturText = Math.Round(Tempertur.TemperturValue, 1, MidpointRounding.AwayFromZero).ToString() + (char)SetCharacters.TemperatureCharactersNumber; string pHText = Ph.PH + "pH"; console.ReplaceLine(0, tempterturText + " " + pHText); Animation.ShowFishOnLine2(console, ref _fishCount, ref _revers, ref _positionCount); Heater.SetHeaterControlOnOff(conn, Tempertur.TemperturValue); heater.HeaterOnOff(conn); //Blink display if tempertur is over max tempertur if (Tempertur.TemperturValue > Tempertur.TemperatureMax) { console.BlinkDisplay(1); } AirPump.AirPumpOnOff(conn, _Controller, AIRPUMPPIN); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { ConsoleEx.WriteLineWithDate("Got an error: " + ex.Message + "StackTrace: " + ex.StackTrace); if (ex.InnerException != null) { ConsoleEx.WriteLineWithDate("Error InnerException: " + ex.InnerException.Message); } } finally { Thread.Sleep(1000); } #pragma warning restore CA1031 // Do not catch general exception types } console.Dispose(); } saveTemperturTimer.Dispose(); savePhTimer.Dispose(); readSetupTimer.Dispose(); conn.Close(); conn.Dispose(); _Controller.Dispose(); }
public LcdDisplay(I2cDevice i2c) { _i2c = i2c; _ioExpander = new Pcf8574(_i2c); _lcd = new Lcd1602(registerSelectPin: 0, enablePin: 2, dataPins: new int[] { 4, 5, 6, 7 }, backlightPin: 3, readWritePin: 1, controller: _ioExpander); }