RFID working with Arduino UNO but not with Arduino Mega 2560 - arduino

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.

Related

Two Arduino HC-05 over Software Serial communication not working

I am currently working with 1. Master Hc-05 on Arduino Mega and 2. Slave Hc-05 on Arduino Nano where the Nano is sending integer to the Mega.
I have already configured the AT command such that for the Master HC-05:
AT+ROLE=1
AT+CMODE=0
AT+ADDR= (was set to the address of the slave HC-05)
AT+UART=38400,0,0
The AT configuration for Slave HC-05:
AT+Role=0
AT+UART=38400,0,0
I am following the schematic here:
Except I have the pin connections as:
RX of mega to digital pin 3 (soft TX)
TX of mega to digital pin 2 (soft RX)
and
RX of nano to digital pin 3 (soft TX)
TX of nano to digital pin 2 (soft RX)
What I am trying to do is send an integer from Nano(slave) to Mega(master) that is parsed through the serial monitor connected to the Nano, and then print the same integer received on the end of Mega's serial monitor. (I have connected Nano to laptop 1 and Mega to another laptop2)
However, the integer parsed in thorugh laptop connected to Nano's serial monitor is printing but none is printing on the Mega side.
It seems like the two Hc-05 are paired and connected as the two are blinking twice every 2 seconds at the same rate, but they are not receiving any messages on Bluetooth serial?
The code for Nano (Slave / Transmitter):
#include<SoftwareSerial.h>
#define softrx 2
#define softtx3
SoftwareSerial BTSerial(softrx, softtx);
void setup(){
BTSerial.begin(38400);
Serial.begin(9600);
}
void loop(){
while(Serial.available()){
int data = Serial.parseInt(); //reads the data sent through serial monitor
BTSerial.write(data); //send the number to the Master Hc-05
Serial.println(); // print the number sent through the serial monitor
}
}
The code for Mega (Master / Receiver)
#include <SoftwareSerial.h>
#define softrx 2
#define softtx 3
SoftwareSerial BTSerial(softrx, softtx); // RX | TX
void setup() {
BTSerial.begin(38400);
Serial.begin(9600);
}
void loop() {
if (BTSerial.available()>0)
{
char data = BTSerial.read();
Serial.println(data);
}
}
These are just my setup and ultimately I want to connect flex sensors on Nano which sends integer based on sensor data to activate LED connected to mega.
But this simple thing is not even working and I want to know what I am doing wrong here.
Tried connecting tx of the microcontroller to tx of HC-05 but did not work either.

ESP32 RFID RC522 - Firmware version 0x0 + communication error

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

How can I connect two BLE modules to eachother?

Hi i would to connect two Arduino with a BLE module, but i don't know what module can i use and how to use it. I know that bluetooth connection is based on master slave relation, but when one is master how can i search the other BLE module to connect and then how can i connect the two modules?
I've worked with Bluetooth some to connect to an Android, but not BLE or between 2 Arduinos. However, I did find some articles that should provide some guidance that makes sense to me.
Your BLE modules should connect the same way as BT2 modules. I suspect BLE will become the norm before too long.
The AT codes are the same for both the HC-05 and the HM-10 and the latter should be a drop-in replacemnt for the former. In the light of this, the article by Philipe Cantin on Arduino<>ARduino connection should apply with BLE.
You need modules that are in master mode. While master modules are in slave mode by default, they can all be set up as master. I am not aware of any BLE module that is slave-only.
http://phillipecantin.blogspot.com.au/2014/08/hc-05-bluetooth-link-with-zero-code.html
Note that, if power is a concern, both modules need to be BLE.
https://forum.arduino.cc/index.php?topic=358570.0
In the Connecting 2 Arduinos by Bluetooth using a HC-05 and a HC-06: Pair, Bind, and Link post I explained how to connect a HC-05 to a HC-06 so that when powered they automatically made a connection. Here we look at using that connection to get Arduinos talking over Bluetooth.
http://www.martyncurrey.com/connecting-2-arduinos-by-bluetooth-using-a-hc-05-and-a-hc-06-pair-bind-and-link/
Most HC-05s and HC-06s have 3.3v TX and RX pins. 5V Arduinos will read 3.3v as HIGH so the BT modules TX pin can be connected directly to the Arduino RX pin. However, the Arduino TX pin needs to be converted to 3.3v before connecting to the BT modules RX pin. A simple way to do this is by using a voltage divider made from 2 resistors; I generally use 1 x 1K and 1 x 2K.
Arduino RX (pin 8) to BT module TX pin
Arduino TX (pin 9) to BT module RX pin via a voltage divider
Both Arduinos have the same connections to the BT modules.
* Sketch: Arduino2Arduino_MASTER_01
* By Martyn Currey
* 08.04.2016
* Written in Arduino IDE 1.6.3
*
* Send commands through a serial connection to turn a LED on and OFF on a remote Arduino
* There is no error checking and this sketch sends only
* Commands should be contained within the start and end markers < and >
*
* D8 - AltSoftSerial RX
* D9 - AltSoftSerial TX
*
*/
// AltSoftSerial uses D9 for TX and D8 for RX. While using AltSoftSerial D10 cannot be used for PWM.
// Remember to use a voltage divider on the Arduino TX pin / Bluetooth RX pin
// Download AltSoftSerial from https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
#include <AltSoftSerial.h>
AltSoftSerial BTserial;
// Change DEBUG to true to output debug information to the serial monitor
boolean DEBUG = true;
void setup()
{
if (DEBUG)
{
// open serial communication for debugging and show
// the sketch filename and the date compiled
Serial.begin(9600);
Serial.println(__FILE__);
Serial.println(__DATE__);
Serial.println(" ");
}
// open software serial connection to the Bluetooth module.
BTserial.begin(9600);
if (DEBUG) { Serial.println("BTserial started at 9600"); }
} // void setup()
void loop()
{
BTserial.println("<LEDON>");
if (DEBUG) {Serial.println("LEDON command sent");}
delay (1000);
BTserial.println("<LEDOFF>");
if (DEBUG) {Serial.println("LEDOFF command sent");}
delay (1000);
}
http://www.martyncurrey.com/arduino-to-arduino-by-bluetooth/

Arduino Nano no serial communication SIM800C

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

Send data via UART from ESP8266 (NodeMCU) to Arduino

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.

Resources