So I'm using an ESP32 with a TTGO display (see image below for pinout) and I want to use the RC522 RFID module, however, I'm getting a communication error and the firmware version is unknown. I'm using the Arduino IDE, SPI library and MFRC522 library.
I've spent the whole day scouring the internet, I've read numerous posts on forums and tried the solutions that were provided (such as: solder the pins, check the wiring again ...). I've also read and watched countless tutorials, all to no avail. When I tried to use the RFID module on the Arduino UNO, everything worked great, but I have to use the ESP32. I feel like I've tried everything so I'm just hoping that someone has had the same issue and found a solution.
Below is my code, it's the DumpInfo example of the MFRC522 library, modified a tiny bit because - as I said- i've tried a bunch of 'solutions'. The RC522 has 8 pins: 3.3V, GND, RST, RQ, MOSI, MISO, SCK and SDA. The 3.3V is connected to the 3.3V of the ESP32, GND to GND of the ESP32. RST is the reset pin which is connected to GPIO22 (defined as RST_PIN). SDA is the slave select pin which is connected to GPIO21 (defined as SS_PIN). Then there's the SCK, MOSI and MISO pins which are connected respectively to GPIO25, GPIO26 and GPIO27 (defined as SCK_PIN, MOSI_PIN and MISO_PIN). The RQ pin is used for interrupts which we don't need, so it's not connected to anything.
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 22 //GPIO22
#define SS_PIN 21 //GPIO21
#define MISO_PIN 27 //GPIO27
#define MOSI_PIN 26 //GPIO26
#define SCK_PIN 25 //GIPO25
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
SPIClass spi(HSPI);
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
spi.begin(SCK_PIN, MISO_PIN, MOSI_PIN);
spi.setDataMode(SPI_MODE3);
mfrc522.PCD_Init(); // Init MFRC522
delay(5000); // Optional delay. Some board do need more time after init to be ready, see Readme
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
void loop() {
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
This results in a few random symbols and then the following in the serial monitor:
Firmware Version: 0x0 = (unknown)
WARNING: Communication failure, is the MFRC522 properly connected?
Scan PICC to see UID, SAK, type, and data blocks...
As I mentioned, this is sort of a last resort. I'm hoping someone has been in the same situation and could provide some useful info that I hopfully haven't already read somewhere.
I was at exactly the same situation as you were: my MFRC-522 was working fine on the Uno, but it did not work on the ESP32. I came here for help, and your question led me in the correct direction. In my code, the arguments for the SPI.begin() call were missing: SCK_PIN, MISO_PIN and MOSI_PIN. Without those arguments, my ESP32 could not read the data. I have tested and confirmed that the pinMode(SS_PIN, OUTPUT) and spi.setDataMode(SPI_MODE3) calls are not necessary for it to work, but passing the arguments as you did on SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN) is mandatory.
I'm using different pin numbers, it's the only difference between my working code and yours. Here's my defines:
#define RST_PIN 22
#define SS_PIN 21
#define MISO_PIN 19
#define MOSI_PIN 23
#define SCK_PIN 18
I realize you must not be reading this, but I hope I can help someone as you have helped me. Thanks!
Bruno
Related
I am new to arduino and recently encountered this problem. I got a starter kit and in that had an RFID module. I tried using it with the arduino they provided me, but it didn't seem to work.
Here is the code if you want to see it.
/*
* --------------------------------------------------------------------------------------------------------------------
* Example sketch/program showing how to read data from a PICC to serial.
* --------------------------------------------------------------------------------------------------------------------
* This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
*
* Example sketch/program showing how to read data from a PICC (that is: a RFID Tag or Card) using a MFRC522 based RFID
* Reader on the Arduino SPI interface.
*
* When the Arduino and the MFRC522 module are connected (see the pin layout below), load this sketch into Arduino IDE
* then verify/compile and upload it. To see the output: use Tools, Serial Monitor of the IDE (hit Ctrl+Shft+M). When
* you present a PICC (that is: a RFID Tag or Card) at reading distance of the MFRC522 Reader/PCD, the serial output
* will show the ID/UID, type and any data blocks it can read. Note: you may see "Timeout in communication" messages
* when removing the PICC from reading distance too early.
*
* If your reader supports it, this sketch/program will read all the PICCs presented (that is: multiple tag reading).
* So if you stack two or more PICCs on top of each other and present them to the reader, it will first output all
* details of the first and then the next PICC. Note that this may take some time as all data blocks are dumped, so
* keep the PICCs at reading distance until complete.
*
* #license Released into the public domain.
*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
* SPI SS SDA(SS) 10 53 D10 10 10
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*/
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
void loop() {
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
I tried using it with my arduino mega, but when I went to open up the serial monitor, here is what it said:
Firmware Version: 0x0 = (unknown)
WARNING: Communication failure, is the MFRC522 properly connected?
Scan PICC to see UID, SAK, type, and data blocks...
But when I use my arduino uno it says the following:
Firmware Version: 0x92 = v2.0
Scan PICC to see UID, SAK, type, and data blocks...
And it works just fine! Is there something wrong with the arduino mega, or is there an obvious solution.
Thanks
The code you're using is taylored to UNO; for MEGA you need to change the defines for the pins:
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout
For MEGA, change those values, RST to 52 and SS to 53.
You also need to change your wiring accordingly.
I am trying to get my SIM800C to talk with my Arduino. There is no communication happening, though.
#include <SoftwareSerial.h>
SoftwareSerial at(2, 3);
void setup() {
Serial.begin(9600);
at.begin(9600);
}
void loop() {
// try every 2 seconds
delay(2000);
Serial.println("sending AT ... ");
at.println("AT");
while (at.available() > 0) {
Serial.write(at.read());
}
}
I am not able to get an OK back. SIM800C is supposed to detect the baud rate by itself.
I am sure there has to be a simple stupid mistake. I just don't know what to do at this point. I obviously already checked for cable break. Out of desperation I already tried to switch RX and TX. I also tried different baud rates (whatever is within the usual limitations of SoftwareSerial) but it should automatically detect it once a couple of AT commands got in anyway.
Weird enough, the pin PWX on the SIM800C needs to be hooked up to a GND to work. It started blinking every second now and is responding to AT commands.
Also it turned out that this specific module does not ship with autobauding enabled, as stated by the SIM800C documentation. The correct baud rate is 115200.
There are some problems you need to consider:
Use below sample code which transfers data between PC and SIM. Sometimes SIM module would go into power down state and won't respond on any AT command but would print some results in the serial monitor.
As already mentioned in comments it seems that your wiring is wrong and as you declared Software Serial as SoftwareSerial at(2, 3); which means pin 2 is Rx on Arduino and should connect to Tx pin of SIM and pin 3 is Tx on Arduino and should connect to Rx pin of SIM. Please don't mess with the pins and connect the pins like below correctly.
Arduino SIM
Rx 2 ----> Tx
Tx 3 ----> Rx
I'm not sure if you can power on SIM800 with a 500mA USB connector, make sure that use an external 1/2 A power supply for VCC of SIM module.
Look at the blink speed of SIM module if it connected and powered on it would blinky with 3 seconds delay and if it blinks fast, it means that it is being restarted. Also if SIM powered on correctly it would print some info like SIM READY, CALL READY, etc.
Try other baud rates like 115200 and see if you get anything on power on.
I put some macro definition to make pin mappings more clear.
#include <SoftwareSerial.h>
//SIM800 TX is connected to Arduino D2
#define SIM800_TX_PIN 2
//SIM800 RX is connected to Arduino D3
#define SIM800_RX_PIN 3
//Create software serial object to communicate with SIM800
SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);
void setup() {
//Begin serial comunication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
while(!Serial);
//Being serial communication witj Arduino and SIM800
serialSIM800.begin(9600);
delay(1000);
Serial.println("Setup Complete!");
}
void loop() {
//Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor
if(serialSIM800.available()){
Serial.write(serialSIM800.read());
}
//Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
if(Serial.available()){
serialSIM800.write(Serial.read());
}
}
Yes this module will not work in this configuration. There is a pin of V_TTL With 5V pin.. This pin enables the TTL logic converter of your GSM.. You have to connect this pin to 5V in case of arduino and to 3V in case of ESP8266.See the pin configuration here
I want to send data from my ESP8266 device to an Arduino Uno board via UART.
The ESP8266 has been flashed with NodeMCU firmware (the build has the following timestamp: nodemcu-master-8-modules-2017-05-30-19-21-49-integer). The firmware has been built using only the following modules: file, gpio, net, node, tmr, uart, websocket, wifi. The ESP8266 board itself is an Adafruit Huzzah board.
The ESP board is powered via a Serial Cable from my laptop USB. The cable I am using is this one, which provides me 5V for powering my board and I know the USB on my Mac can supply the 500mA needed.
The Arduino is also powered via the other USB port on my computer.
The ESP board and the Arduino are connected as follows:
ESP8266
TX RX GND
| | |
| | |
10 11 |
RX TX GND
Arduino
The Adafruit Huzzah board claims that:
The TX pin is the output from the module and is 3.3V logic. The RX pin
is the input into the module and is 5V compliant (there is a level
shifter on this pin)
So there shouldn't be a need for a level converted between these two.
The code I am running on the ESP8266 board, as init.lua is:
uart.setup(0,115200,8,0,1)
tmr.alarm(0, 5000, 0, function()
uart.write(0, "A", 19)
end)
The code I am running on the Arduino is:
#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
MeetAndroid meetAndroid;
SoftwareSerial sSerial(rxPin, txPin);
uint8_t lastByte;
uint8_t serialBuffer[64];
int count = 0;
int onboardLed = 13;
void setup() {
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(115200);
sSerial.begin(115200);
pinMode(onboardLed, OUTPUT);
digitalWrite(onboardLed, HIGH);
}
void loop() {
while (sSerial.available() > 0) {
serialBuffer[count] = sSerial.read();
count++;
}
for (int i = 0; i < count; i++) {
Serial.println(serialBuffer[i]);
}
}
What I see on the Serial Monitor in Arduino once I reset my ESP board is garbage:
⸮⸮⸮⸮⸮⸮Z,⸮}⸮߿⸮ߏ⸮\⸮⸮LYLYLYLYL⸮L⸮L⸮L⸮L⸮L (((((⸮$⸮$⸮$⸮$⸮$⸮$⸮4⸮0⸮#⸮#⸮#⸮#⸮#⸮#⸮#⸮#⸮#⸮#⸮#⸮# ((((⸮$:⸮&i(⸮⸮
After a short delay it starts printing out line upon line of garbage after this initial line. It's clear to me that, somewhere, there is a mismatch.
I've looked for previous questions on this matter, but the only one I could find that was the closest to my use stated simply that one ought to read the docs, which was not very helpful.
Does anyone know what is amiss here?
You have to set a proper baud-rate. You can set the baud-rate on the bottom right corner of the serial monitor.
I prefer to use the standard debug baud rate of 9600.
I believe those are two different problems.
The first line of garbage after booting up actually belongs to esp8266's firmware, it's default baud rate is 74880 and if you open a serial monitor on that baud rate, you can see something like this:
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
The second problem is with the softwareSerial library.
Based on this (and my own experience), maximum reliable baud rate seems to be around 28800 and you've set it up to high.
I recommend decreasing the baud rate or switching to other libraries such as AltSoftSerial.
I am doing a simple tcp communication from an arduino to raspberry-pi wirelessly with an ESP8266 wifi module on arduino uno.The tcp server is running on the raspberry-pi.I am able to do TCP communication with the following AT commands in arduino serial monitor at a baudrate of 9600.
AT+CIPMUX=1
AT+CIPSTART=4,"TCP","192.168.43.150",7777
AT+CIPSEND=4,5
>hai
How to do this programatically in an arduino sketch.I used the following code on my arduino uno,but still without any success.The baudrate is 9600 only since it is working directly in serial monitor.
#include <SoftwareSerial.h>
SoftwareSerial esp8266(2,3);
void setup()
{
Serial.begin(9600);
esp8266.begin(9600); // your esp's baud rate might be different
}
void loop()
{
esp8266.println("AT");
if(esp8266.available()) // check if the esp is sending a message
{
while(esp8266.available())
{
// The esp has data so display its output to the serial window
char c = esp8266.read(); // read the next character.
Serial.write(c);
}
}
}
The connections are as follows
ESP8266 Arduino Uno
Vcc 3.3V
CH_PD 3.3V
RX RX(PIN 2)
TX TX(PIN 3)
GND GND
This might be a bit late, but I got stuck with a similar problem fairly recently. If it's sorted then feel free to ignore this.
Depending on firmware version of your ESP8266 module the baud rate of 9600 may not work, try out 115200 instead - it may prove to be more reliable?
I think the main reason your code above isn't working is because of the face that the ESP needs both newline and carriage returns at the end of the AT command. The serial monitor adds these on for you. Rather than sending AT try sending AT\r\n. This should encourage the ESP to reply with OK, or if the echo is turned on AT\r\nOK.
Serial.available() also checks that there is content in a receive buffer - this takes time unfortunately so I had to put a delay(10) in there to get it to register a character in the buffer.
#include <SoftwareSerial.h>
//i find that putting them here makes it easier to
//edit it when trying out new things
#define RX_PIN 2
#define TX_PIN 3
#define ESP_BRATE 115200
SoftwareSerial esp8266(RX_PIN, TX_PIN);
void setup()
{
Serial.begin(9600);
esp8266.begin(ESP_BRATE); // I changed this
}
void loop()
{
esp8266.println("AT\r\n"); //the newline and CR added
delay(10); //arbitrary value
if(esp8266.available()) // check if the esp is sending a message
{
while(esp8266.available())
{
// The esp has data so display its output to the serial window
char c = esp8266.read(); // read the next character.
Serial.write(c);
}
}
}
My next problem is that the0 replies for my ESP are unreliable - sometimes they are read as OK but sometime they are garbage values. I suspect it's a matter of not enough power to the module.
I have come across the same problem and yet not have found a solution.
But your connections are a bit of, you have to connect the TX pin of your ESP8266 module to the RX pin of your arduino and the RX pin of your ESP8266 module to the TX pin.
Hope this helps you on your way
I'm working in project involving Arduino, Bluetooth and Android. My Arduino hardware will collect data from sensors and send them to an Android tablet via Bluetooth. My application on Android seems to work well when I tested it with BlueChat; it successfully receives data from BlueChat. Following is my code for my Arduino hardware. I'm quite sure I initiate HC-05 correctly. Can anyone look at my code and suggest whether it works if my idea is to collect reading from a temperature sensor at Analog pin 0, then transmit them to Digital pin 11, which is the Tx pin on Arduino connecting to Rx pin of Hc-05?
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);
int tempPin=0;
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
}
void loop()
{
float reading = analogRead(tempPin); // reading on tempPin
float voltage = reading*5.0/1024.0; // the resolution of a pin is 10 bit,
float tempC = voltage/0.01; // 10mV = 1 Celcius
mySerial.write(tempC);
delay(3000);
}
I should mention that I power my Arduino Uno externally by an 9V battery.
Steps to try in this case:
- Send anything via HC-05 (hello world) -> this will exclude connection problems (might be a good idea to put HC-05 on the "real" serial and the debug messages on the 'soft' serial)
Test analog read part of the code via Serial Monitor: you can see if you get reasonable data
Test the combination of sensor reading and sending via HC-05
I don't think SoftwareSerial has a write( float ) method. I suggest you report back the raw data and let your app do the conversion. Don't forget delimiters, so you know when one number ends and the next starts:
void loop()
{
int reading = analogRead(tempPin); // reading on tempPin
mySerial.println( tempC, DEC );
delay(3000);
}