Arduino:LiquidCrystal 无法使用以太网库打印

Arduino: LiquidCrystal Won't Print With Ethernet Library

本文关键字:以太网 打印 LiquidCrystal Arduino      更新时间:2023-10-16

问题

使用以太网库(当然还有屏蔽(时,我无法将Arduino Uno的LiquidCrystal库打印到LCD屏幕上。

代码

#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
EthernetClient client;
String text = "Original Text";
void setup() {
  // Set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Setup Text");
  // We have serial, but no milk!
  Serial.begin(9600);
}
void loop() {
  text = "Altered Text";
  if (Ethernet.begin(mac) != 0) {
      Serial.println("Some Ethernet work...");
  }
  lcd.setCursor(0, 1);
  lcd.print(text);
}

预期结果

表示一个空白字符

屏幕应打印:
Setup▓Text▓▓▓▓▓▓
Altered▓Text▓▓▓▓

Some Ethernet work...打印到Serial时。

实际结果

屏幕打印:
Setup▓Text▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

Some Ethernet work...打印到Serial时。

备注

如果我注释掉循环中的以太网代码,我会得到预期结果

我的问题与这个问题相似,但不完全相同:
Arduino代码异常-LCD出现多个"if"语句故障

我不认为我的问题是记忆力不足。我使用的是最新的以太网库,它修复了以前版本的内存泄漏错误。

我在这里找到了答案:https://electronics.stackexchange.com/questions/29240/arduino-uno-ethernet-shield-16x2-lcd-not-initializing

@ben as per the page here, the comment by user "njohnson" states that the shield uses all the digital pins except 1,2 and 8. based on this i tried hooking up the lcd to the 6 analog pins (as outputs) and its working fine now. Now the question is where/how can i study the shield schematic to be sure what all pins can i use. On a side now, it seems an unusual design decision since using the shield means sacrificing 13 of the digital pins ! – Ankit Apr 3 '12 at 21:14

解决方案

我将LCD引脚移到模拟引脚(14-19(。

代码修改

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);更改为LiquidCrystal lcd(19, 18, 17, 16, 15, 14);,并相应地移动LCD屏幕引脚。