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

时间:2013-03-14 02:06:56

标签: c++ arduino microcontroller ethernet lcd

问题

使用LiquidCrystal库(当然还有盾牌)时,我无法让我的Arduino Uno的LCD screen库打印到我的Ethernet

代码

#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 code anomalies - LCD fails with multiple 'if' statements

我不相信我的问题是内存不足。我正在使用最新的以太网库,它修复了以前版本的memory leak bug

1 个答案:

答案 0 :(得分:3)

我在这里找到答案: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屏幕引脚。