【问题标题】:Characters in row 3 & 4 are moved to the right in 16x4 LCD - Raspberry Pi 4第 3 行和第 4 行中的字符在 16x4 LCD 中向右移动 - Raspberry Pi 4
【发布时间】:2021-03-04 12:04:21
【问题描述】:

我正在尝试制作一个简单的 c++ 代码来显示 4 个文本内容,每个内容分为 4 个单独的行。我正在使用最新版本的 Raspberry Pi OS (Debian Buster)、WiringPi 2.52 和 16x4 LCD 显示器(5v - 1604A LCD 屏幕)。

这是我的代码。

#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <cstdlib>
#include <wiringPi.h>
#include <lcd.h>
#include <string.h>

using namespace std;

#define LCD_RS 30 //reset pin
#define LCD_E 10  //enable pin 
#define LCD_D4 23 //data pin 4
#define LCD_D5 22 //data pin 5
#define LCD_D6 21 //data pin 6
#define LCD_D7 14 //data pin 7

int lcd;

int main()
{
    wiringPiSetup();
    lcd = lcdInit(4, 20, 4, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, 0, 0, 0, 0);
    lcdPosition(lcd, 0, 0);
    lcdPuts(lcd, "Test Row 1");
    lcdPosition(lcd, 0, 1);
    lcdPuts(lcd, "Test Row 2");
    lcdPosition(lcd, 1, 2);
    lcdPuts(lcd, "Test Row 3");
    lcdPosition(lcd, 1, 3);
    lcdPuts(lcd, "Test Row 4");
    cout << "LCD Displays" << endl;
    sleep(30);
    lcdClear(lcd);
    cout << "LCD Clear" << endl;
    return 0;
}

但是当我运行这段代码时,除了第 3 行和第 4 行之外,它在 LCD 显示器的第 1 行和第 2 行中完美地显示了结果。

我把结果放在下面以获得一个想法。

从上图中,前两行打印完美,但在第 3 行和第 4 行中,当我尝试在第 2 列中打印它们时,它会在第 6 列中打印 (lcdPosition(lcd, 5, 2))。我无法弄清楚这个问题的确切原因。有人可以帮我解决这个问题吗?谢谢。

【问题讨论】:

    标签: c++ raspberry-pi4 wiringpi


    【解决方案1】:

    这只是一个猜测,但您的显示器是 16x4,但您的 lcdInit 调用指定了 20 列。

     lcd = lcdInit(4, 20, 4, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, 0, 0, 0, 0);
    

    尝试将其更改为 16

     lcd = lcdInit(4, 16, 4, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, 0, 0, 0, 0);
    

    挖掘代码这似乎是来自 WiringPi 的 lcd.c 中的一个错误。我在另一个库上找到了 discussing similar issues 的人,并查看了 lcd.c:84 中的代码,它具有相同的偏移量,并且似乎无法处理 16 与 20 列。

    由于 WiringPi 是 deprecated,因此我将如何最好地解决这个问题留给个人开发人员。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 2015-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多