Arduino:LiquidCrystal 无法使用以太网库打印
Arduino: LiquidCrystal Won't Print With Ethernet Library
问题
使用以太网库(当然还有屏蔽(时,我无法将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屏幕引脚。
- 如何循环打印顶点结构
- 为什么在popback()操作之后,它仍然打印完整的矢量
- 如何在c++中打印目录
- 有一个打印语句的函数是一种糟糕的编程实践吗
- 在线编译器中的分段C++没有打印消息
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 如何将结构插入到集合中并打印集合的成员
- 在循环C++中指定字符串之后,不会打印该字符串
- 以螺旋方式打印矩阵的程序.(工作不好)
- 从控制台中删除最后打印的元素
- 如何使用Crypto++并为RSA返回可打印的字节/字符数组
- 如何仅使用对象名称打印特定于对象的成员
- 回溯C++不打印函数,因此文件
- 在一定长度后从数组中打印时缺少整数
- 为什么这个 c++ 代码打印出长度 5,当我打印出字符串时,程序会自动终止?
- 在gem5中打印文件中的所有cache_blocks
- 打印数字图案
- Log4cpp:以UTC/GMT时区打印日期
- Arduino:LiquidCrystal 无法使用以太网库打印