使用 C# 将 Waveshare LCD1602 RGB 连接到树莓派

Connecting Waveshare LCD1602 RGB to Raspberry using C#

我正在尝试使用 C# 将 LCD1602 RBG Waveshare 连接到 Raspberry。我将它连接到 Raspberry 并设置了权限,现在尝试传递一些数据。下面的代码 运行 所有行,但 LCD 没有反应。 如果有人能告诉我。

using System;
using System.Device.Gpio;
using System.Threading.Tasks;
using System.Device.I2c;
using Iot.Device.CharacterLcd;
using Iot.Device.Pcx857x;
using System.Threading;

namespace pi_project
{
    public class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Test1");

            using I2cDevice i2c = I2cDevice.Create(new I2cConnectionSettings(1, 0x3e));
            //BCM2835
            using var driver = new Pcf8574(i2c);
            using var lcd = new Lcd1602(registerSelectPin: 0,
                                    enablePin: 2,
                                    dataPins: new int[] { 4, 5, 6, 7 },
                                    backlightPin: 3,
                                    backlightBrightness: 0.3f,
                                    readWritePin: 1,
                                    controller: new GpioController(PinNumberingScheme.Logical, driver));
            int counter = 0;

            while (counter <= 4)
            {
                lcd.Clear();

                lcd.SetCursorPosition(0, 0);
                lcd.Write("TestText1");

                lcd.SetCursorPosition(0, 1);
                lcd.Write("TestText2");

                Thread.Sleep(2000);
                counter++;
            }
        }
    }
}
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- 3e --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: 60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: 70 -- -- -- -- -- -- --

这些显示器的控制器通常是 HD44780 或兼容的。如果 python 示例工作正常,那么应该这样做:

var i2cLcdDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x3E));
var i2cRgbDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x60));
using LcdRgb lcd = new LcdRgb(new Size(16, 2), i2cLcdDevice, i2cRgbDevice);
{
    lcd.Write("Hello World!");
    lcd.SetBacklightColor(Color.Azure);
}

(出于我以外的原因,python 示例将地址定义为 0x7c >> 10xc0 >> 1,即 0x3E 和 0x60,与您的设备扫描一致)