0
내 NodeMCU v3에서 SPI 인터페이스를 사용하여 RF522를 사용하려고합니다. 필자는 RF522를 Pi Zero에 연결하여 휴대 전화의 NFC뿐 아니라 칩을 스캔하여 하드웨어가 양호하다는 것을 확신 할 수있었습니다. 내 아두 이노 스케치 을 업로드 할 수 없습니다 (espcomm_upload_mem 실패) 내가 스크립트를 실행할 수 없습니다, 내가 모든 것을를 연결하면NodeMCU V3 with RF522를 사용할 때의 이상한 행동
- : 여기 는 지금까지 (연결 코드 아래에 설명되어 있습니다) 발견했습니다 무엇 노드 카드는 입니다.
- RF522의 3v 전원을 분리하면 스크립트를 업로드하고 실행할 수 있습니다. 나는 3V 전원 차단을두면
- 이 프로그램은 자체 테스트 실패 : 나는 NodeMCU 부팅 후에 있지만 자체 테스트 전에 3V 전원 선을 연결하면 mfrc522.PCD_PerformSelfTest()를
- , 그것은 자체 테스트를 통과하고 실행!
- 카드를 찾지 못했습니다 (영원히 "새 카드 없음 ..."반복). 기존 칩과 전화를 사용해 보았지만 아무 것도 발견되지 않았습니다.
왜 전원이 들어오지 않으면 시작부터 모든 것을 유지할 수 있을지 모르겠지만 셀프 테스트가 통과되면 카드를 읽을 수없는 이유가 무엇인지 잘 모릅니다! 다른 누구도 RF522와 NodeMCU를 함께 사용하는 경험이 있습니까?
코드 :
#include <ESP8266WiFi.h> //ESP8266 Core WiFi Library (you most likely already have this in your sketch)
#include <DNSServer.h> //Local DNS Server used for redirecting all requests to the configuration portal
#include <ESP8266WebServer.h> //Local WebServer used to serve the configuration portal
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
#include <PubSubClient.h>
#include <SPI.h>
#include <MFRC522.h>
/*
*RST GPIO15 -- D8
*SDA(SS) GPIO2 -- D4
*MOSI GPIO13 -- D7
*MISO GPIO12 -- D6
*SCK GPIO14 -- D5
*GND GND
*3,3V 3,3V
*/
#define SS_PIN 2 // D4 -- SDA-PIN for RC522
#define RST_PIN 15 // D8 -- RST-PIN for RC522
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
WiFiClient espClient;
PubSubClient mqtt(espClient);
const char* MQTT_user = "rfid.local";
const char* MQTT_server = "mqtt.local";
const char* topic_base = "home/rfid/";
void setup() {
Serial.begin(115200);
Serial.println("Lets get started!!");
WiFiManager wifiManager;
wifiManager.setTimeout(180);
if(!wifiManager.autoConnect("RFID", "RFID")) {
Serial.println("Failed to connect and hit timeout");
delay(3000);
ESP.reset();
delay(5000);
}
Serial.println("Connected...yippie!");
mqtt.setServer(MQTT_server, 1883);
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
if (mfrc522.PCD_PerformSelfTest())
Serial.println("RF522 Passed self test!");
else {
Serial.println("RF522 Failed self test!");
delay(3000);
ESP.reset();
delay(5000);
}
Serial.println("Waiting for someone to scan...");
}
void reconnectMQTT() {
// Loop until we're reconnected
while (!mqtt.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (mqtt.connect(MQTT_user, MQTT_user, MQTT_user)) {
Serial.println("connected");
} else {
Serial.print("failed, rc=");
Serial.print(mqtt.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void loop() {
// Make sure we are still connected!
if (!mqtt.connected()) {
reconnectMQTT();
}
mqtt.loop();
// Look for new cards
if (! mfrc522.PICC_IsNewCardPresent()) {
Serial.println("No new card...");
delay(1000);
return;
}
// Select one of the cards
if (! mfrc522.PICC_ReadCardSerial()) {
Serial.println("Can't read card...");
delay(1000);
return;
}
// Dump debug info about the card. PICC_HaltA() is automatically called.
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
//mqtt.publish(topic_base...);
}
RST 라인을 제거하면 장치가 부팅되어 Vcc가 켜진 상태에서 자체 테스트를 통과 할 수 있습니다. 마지막 코멘트는 여기를 참조하십시오 : https://forum.mysensors.org/topic/4299/nodemcu-and-nrf-spi-init-problem/4 – Jaron
여기가 내가 Pi와 함께 작동하도록했던 것입니다 (드라이버 1.44 만 사용).) : http://bsd.ee/~hadara/blog/?p=1017 정상적인 python 구현 중 하나를 사용할 수 없습니다. 내가 나쁜 독자를 가졌는지 궁금하게 생각하니? – Jaron