首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Arduino的LiquidCrystal库会干扰Wi-Fi库吗?

Arduino的LiquidCrystal库会干扰Wi-Fi库吗?
EN

Stack Overflow用户
提问于 2013-03-15 04:06:10
回答 1查看 1.4K关注 0票数 0

有一天,我在玩我的Arduino时,有了一个很酷的想法。也许我可以在没有串行监视器的情况下进行无线连接!我可以用液晶显示器来代替!所以,我去上班了。我把所有串行的东西都换成了LCD的东西。

最后,我的代码中没有错误(根据Arduino客户端)。

下面是我的代码:

代码语言:javascript
复制
#include <LiquidCrystal.h>
#include <WiFi.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

char ssid[] = "Fake Network";                    // Your network SSID (name)
char key[] = "1";       // your network key
int keyIndex = 0;                                // Your network key Index number
int status = WL_IDLE_STATUS;                     // The Wi-Fi radio's status

void setup() {

    lcd.begin(16, 2);

    // Check for the presence of the shield:
    if (WiFi.status() == WL_NO_SHIELD) {
        lcd.println("WiFi shield not present");
        // Don't continue:
        while(true);
    }

    // Attempt to connect to Wi-Fi network:
    while ( status != WL_CONNECTED) {
        lcd.print("Attempting to connect to WEP network, SSID: ");
        lcd.println(ssid);
        status = WiFi.begin(ssid, keyIndex, key);

        // Wait 10 seconds for connection:
        delay(10000);
    }

    // Once you are connected:
    lcd.print("You're connected to the network");
    printCurrentNet();
    printWifiData();
}

void loop() {
    // Check the network connection once every 10 seconds:
    delay(10000);
    printCurrentNet();
}

void printWifiData() {
  // Print your Wi-Fi shield's IP address:
  IPAddress IPaddr = WiFi.localIP();
  lcd.print("IP Address: ");
  lcd.println(IPaddr);
  lcd.println(IPaddr);

  // Print your MAC address:
  byte MACaddr[6];
  WiFi.macAddress(MACaddr);
  lcd.print("MAC address: ");
  lcd.print(MACaddr[5],HEX);
  lcd.print(":");
  lcd.print(MACaddr[4],HEX);
  lcd.print(":");
  lcd.print(MACaddr[3],HEX);
  lcd.print(":");
  lcd.print(MACaddr[2],HEX);
  lcd.print(":");
  lcd.print(MACaddr[1],HEX);
  lcd.print(":");
  lcd.println(MACaddr[0],HEX);
}

void printCurrentNet() {
    // Print the SSID of the network you're attached to:
    lcd.print("SSID: ");
    lcd.println(WiFi.SSID());

    // Print the MAC address of the router you're attached to:
    byte bssid[6];
    WiFi.BSSID(bssid);
    lcd.print("BSSID: ");
    lcd.print(bssid[5],HEX);
    lcd.print(":");
    lcd.print(bssid[4],HEX);
    lcd.print(":");
    lcd.print(bssid[3],HEX);
    lcd.print(":");
    lcd.print(bssid[2],HEX);
    lcd.print(":");
    lcd.print(bssid[1],HEX);
    lcd.print(":");
    lcd.println(bssid[0],HEX);

    // Print the received signal strength:
    long rssi = WiFi.RSSI();
    lcd.print("signal strength (RSSI):");
    lcd.println(rssi);

    // Print the encryption type:
    byte encryption = WiFi.encryptionType();
    lcd.print("Encryption Type:");
    lcd.println(encryption,HEX);
    lcd.println();
}

结果是......没什么。未显示任何内容。

然后我去做我的调试版本。请注意,我从代码的底部开始。

代码语言:javascript
复制
lcd.print("bug");

我把它放在代码的每一行下面。最后,我到达了顶端,在这条线下:

代码语言:javascript
复制
lcd.begin(16, 2);

猜猜发生了什么!任何行中都没有显示!我到处都找过了,还检查了显示插针。

终于,我找到了问题所在!

这是一个我无法摆脱的可怕的bug!使用WiFi.h库时,显示不会显示!我不知道为什么,但如果我甚至在我的程序中使用#include <WiFi.h> (或任何带有LiquidCrystal库的程序...事情就是这样的!

这个问题的原因是什么?我如何解决它?我还没走运呢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-15 04:10:51

根据documentation的说法

Arduino使用SPI总线(通过ICSP报头)与无线屏蔽的处理器和SD卡进行通信。这是在Uno上的数字引脚11、12和13上,在Mega上的引脚50、51和52上。在Uno上,11MOSI12MISO

根据您的代码

代码语言:javascript
复制
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

您正在为液晶屏使用引脚1112。现在,如果液晶屏使用SPI,则液晶屏可以与Wi-Fi屏蔽板共享引脚1112,因为用于SS (Slave Select)功能的同一组引脚将告诉外设其中哪一个应该在监听。但是,LiquidCrystal库将其前两个参数引脚分别用于RSEnable,这使得它与SPI不兼容。解决方案:将LCD移到不同的针脚上。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15419152

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档