Cannot wakeup MIFARE 1k card - arduino

What we need to do
We need to detect both the presence and absence of an RFID chip. We intend to do this by continually checking for a card. If one is there, we read it and confirm which it is. If there isn't one there after there previously was, then that is noted. It doesn't have to be super fast.
What we're using
Arduino UNO + RC522 FRID reader, with MIFARE 1k cards. Using the library at: https://github.com/miguelbalboa/rfid
The problems
Cannot read multiple cards
Contrary to what seems to be stated in example code found elsewhere, I am never able to read more than one card without resetting the RC522. As soon as it reads a card, and it's HALTed, no more cards can be read until the processor is reset. Other examples suggest this shouldn't be the case and a new card should immediately be readable on the next loop. Using:
void loop() {
// Look for new cards
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_DumpDetailsToSerial(&(mfrc522.uid));
mfrc522.PICC_HaltA();
}
Successfully gives:
Card UID: B6 35 9F 46
Card SAK: 08
PICC type: MIFARE 1KB
But I cannot read any more cards until I reset the RF522 (either using software or just restarting the device).
Cannot authenticate card
void loop() {
// Look for new cards
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));
}
Gives the following output
Card UID: B6 35 9F 46
Card SAK: 08
PICC type: MIFARE 1KB
Sector Block 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 AccessBits
15 63 PCD_Authenticate() failed: Timeout in communication.
14 59 PCD_Authenticate() failed: Timeout in communication.
13 55 PCD_Authenticate() failed: Timeout in communication.
...
Cannot read card when starting
I cannot read a card if it's present when starting the RC522, the communication times out. It does, however, take longer when a card is present. Using the following code:
// this is triggered by a serial command input
void resetAndRead() {
Serial.println("Init and check for any card");
mfrc522[0].PCD_Reset();
Serial.print("Reset complete (antenna off): ");
Serial.println(millis() - time_last_action);
delay(2000);
time_last_action = millis();
initialise();
Serial.print("Init complete: ");
Serial.println(millis() - time_last_action);
delay(10);
time_last_action = millis();
PICC_IsAnyCardPresent();
Serial.print("Check for card complete: ");
Serial.println(millis() - time_last_action);
}
void initialise() {
mfrc522[0].PCD_Init(ssPins[0], RST_PIN); // Init each MFRC522 card
mfrc522[0].PCD_DumpVersionToSerial();
}
bool PICC_IsAnyCardPresent() {
byte bufferATQA[2];
byte bufferSize = sizeof(bufferATQA);
MFRC522::StatusCode result = mfrc522[0].PICC_WakeupA(bufferATQA, &bufferSize);
Serial.print("Status Code: ");
Serial.print(mfrc522[0].GetStatusCodeName(result));
Serial.println();
return (result == MFRC522::STATUS_OK || result == MFRC522::STATUS_COLLISION);
}
I get the following output with no card present
Init and check for any card
Reset complete (antenna off): 50
Firmware Version: 0x92 = v2.0
Init complete: 51
Status Code: Timeout in communication.
Check for card complete: 41
And with a card present
Init and check for any card
Reset complete (antenna off): 52
Firmware Version: 0x92 = v2.0
Init complete: 53
Status Code: Timeout in communication.
Check for card complete: 294
The Questions
Particularly given the first issue - does this sound like a hardware issue? No one else seems to have problems reading multiple cards without requiring a reset.
Should it be possible to solve the third issue? i.e. should an RFID reader be able to communicate with an RFID chip when the antenna is first switched on.

You forgot exit an authentificated PICC. Try to use the MFRC522::PCD_StopCrypto1() function.
Used to exit the PCD from its authenticated state. Remember to call
this function after communicating with an authenticated PICC -
otherwise no new communications can start.
You can use the method after dumping the information:
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
or directly before checking a new card (multiple calls are no problem):
mfrc522.PICC_IsNewCardPresent()

Bit late,
but perhaps someone will find these usefull..
https://github.com/miguelbalboa/rfid/issues/269#issuecomment-292783655
https://github.com/miguelbalboa/rfid/issues/269#issuecomment-472342583
// Function requires an integer assigned to specific reader
// If not multi-reader, just drop the [...]
void mfrc522_fast_Reset(int reader) {
digitalWrite(RST_PIN, HIGH);
mfrc522[reader].PCD_Reset();
mfrc522[reader].PCD_WriteRegister(mfrc522[reader].TModeReg, 0x80); // TAuto=1;
// Timer starts automatically at the end of the transmission
// in all communication modes at all speeds
mfrc522[reader].PCD_WriteRegister(mfrc522[reader].TPrescalerReg, 0x43); // 10μs.
// mfrc522.PCD_WriteRegister(mfrc522.TPrescalerReg, 0x20); // test
mfrc522[reader].PCD_WriteRegister(mfrc522[reader].TReloadRegH, 0x00);
// Reload timer with 0x064 = 30, ie 0.3ms before timeout.
mfrc522[reader].PCD_WriteRegister(mfrc522[reader].TReloadRegL, 0x1E);
//mfrc522.PCD_WriteRegister(mfrc522.TReloadRegL, 0x1E);
mfrc522[reader].PCD_WriteRegister(mfrc522[reader].TxASKReg, 0x40);
// Default 0x00. Force a 100 % ASK modulation independent
//of the ModGsPReg register setting
mfrc522[reader].PCD_WriteRegister(mfrc522[reader].ModeReg, 0x3D);
// Default 0x3F. Set the preset value for the CRC coprocessor
// for the CalcCRC command to 0x6363 (ISO 14443-3 part 6.2.4)
mfrc522[reader].PCD_AntennaOn(); // Enable the antenna driver pins TX1 and TX2
// (they were disabled by the reset)
}

Related

Why do sketches take up so much space and memory in arduino?

When I compile my program i get this message
Sketch uses 7,074 bytes (21%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,033 bytes (50%) of dynamic memory, leaving 1,015 bytes for local variables. Maximum is 2,048 bytes.
What do this message states?
this is my code
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println("Scan PICC to see UID and type...");
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;//go to start of loop if there is no card present
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;//if ReadCardSerial returns 1, the "uid" struct (see MFRC522.h lines 238-45)) contains the ID of the read card.
}
// Dump debug info about the card. PICC_HaltA() is automatically called.
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
and I'm getting this message on blinking led long pin 13 too
If you look at this question you'll see that without care, constant strings like "Scan PICC to see UID and type..." will use SRAM (dynamic memory) and not flash (program storage space).
It is a message that informs you on the state of arduino's memory.

Arduino 101 - BLE Queries: Characteristics and Advertisement

I have the following queries regarding BLE peripheral on Arduino 101 :
Is is possible to advertise any characteristic value(dynamic data) rather than the UUID in the advertising packet. If so what are the APIs for that? My goal is to get any temperature data in the adv packet instead of connecting to the peripheral.
Current Observation: I was only able to advertise service uuids and local name using the APIs setAdvertisedServiceUuid and setLocalName.
2.In the following code I was able to start and capture the advertisement in the first instance but in the letter instance the begin had a false return value. Am I doing anything wrong? The idea is to start and stop the advertisement and may be even change the advertisement data.
#include <CurieBle.h>
void setup() {
// set LED pin to output mode
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
//BLE Peripheral
BLEPeripheral * blePeripheral = new BLEPeripheral;
//Set the Local Name
blePeripheral->setLocalName("MyDevice");
//Start Advertising
blePeripheral->begin();
//Run the advertisement for 20 seconds
delay(20000);
//Stop the advertisement
blePeripheral->end();
//Delete the BLE Peripheral
delete blePeripheral;
//Wait 5 seconds before starting the next adv
delay(5000);
}
Any help will be appreciated.
Thanks.
Swaroop
BLEPeripheral blePeripheral; // BLE Peripheral Device (the board you're programming)
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service
// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEUnsignedCharCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
https://www.arduino.cc/en/Reference/BLEPeripheralConstructor

Sending AT commands to a GSM/GPRS and displaying the reply on a Serial Monitor

I am quite rusty when it comes to Serial ports. I want to send an AT command to a GSM/ GPRS shield connected to my Arduino UNO. The AT command I want to pass in particular is the command to get a networks signal strength.
I am using the SIM900 and SoftwareSerial library to send the command as the GSM library does not compile correctly for me. Meaning I have to use the SoftwareSerial library.
I have this example code from the SIM900 library working that relies on reading inputs from the serial monitor to carry out commands but I need it to be automated and the command to be passed in hardcoded. In this example code, the place of interest is the simplehwread() method.
#include "SIM900.h"
#include <SoftwareSerial.h>
int numdata;
char inSerial[40];
int i=0;
void setup()
{
//Serial connection.
Serial.begin(9600);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(9600))
Serial.println("\nstatus=READY");
else Serial.println("\nstatus=IDLE");
};
void loop()
{
//Read for new byte on serial hardware,
//and write them on NewSoftSerial.
serialhwread();
//Read for new byte on NewSoftSerial.
serialswread();
};
void serialhwread()
{
i=0;
if (Serial.available() > 0) {
while (Serial.available() > 0) {
inSerial[i]=(Serial.read());
delay(10);
i++;
}
inSerial[i]='\0';
if(!strcmp(inSerial,"/END")) {
Serial.println("_");
inSerial[0]=0x1a;
inSerial[1]='\0';
gsm.SimpleWriteln(inSerial);
}
//Send a saved AT command using serial port.
if(!strcmp(inSerial,"TEST")) {
Serial.println("SIGNAL QUALITY");
gsm.SimpleWriteln("AT+CSQ");
} else {
Serial.println(inSerial);
gsm.SimpleWriteln(inSerial);
}
inSerial[0]='\0';
}
}
void serialswread()
{
gsm.SimpleRead();
}
No matter how I modify this code, the command does not get passed in and response displayed while the method here does it but not the way I want it to be done. i.e Direct input. Could anyone assist here?
i have dealt with exactly this scenario at a company with a cellular radio on board. there are many status signals that come over and if not dealt with appropriately these status flags from the cell modem will be lost
you need to look at the data sheets associated with your cell modem and its protocol so you know what flags to watch for at the various steps taken along the way from configuration, to eventual connection to cellular service.
multi-threaded coding techniques must be followed as well.
keep in mind that the comm channel is not ideal and there WILL be failures. provided your coding techniques are sound and you follow protocol requirements, then it should work.
Ron
Boise, ID

sending sms to stop a pump using atmega32 and sim300

I'm working on a project that has to turn a pump off upon sending an sms to the microcontroller. This code below has to be able to read and download the message so it can turn the pump off but it is not working. Can someone please check the code and let me know the problem. The microcontroller used is atmega32 and the software to program it is atmel studio 6.1.
while(1)
{
//check_sensor();
/*uint8_t x=0;
while(GSMWaitForMsg(&id)!=GSM_OK)
{
if(x)
{
LCDWriteStringXY(10,3,"%3"); //LOVE SYMBOL TILL MSG COMES CHECK MYUTILS.H
x=0;
}
else
{
LCDWriteStringXY(10,3,"%4"); //ARROW TO SHOW MESSAGE DOWNLOAD
x=1;
}
}
LCDWriteStringXY(10,3,"%2");
_delay_ms(1000);
//function to read message
char msg[300];
int8_t r=GSMReadMsg(id,msg); //ID=NUMBER MSg=MESSAGE OA=THE REPLY
if(r==GSM_OK)
{
if(strcasecmp(msg,"STOP")==0) // checking if message read is stop
{
PORTC|=(1<<PC7);
LCDClear();
LCDWriteStringXY(0,1,"PUMP TURNED OFF"); // displaying on the lcd screen
RelayOff(); // turning the relay off
_delay_ms(2000);
goto comehomeboy; // going back to home
}
}
}
The message received for GSM module (on UART of controller) are merely ASCII characters.Mostly there is no NULL(\0) appended to the data.
For strcasecmp() function you need NULL terminated strings as Input.
Please make sure 'msg' array is terminated with NULL.

unable to send call from Arduino to a specific number

I Am using Arduino UNO and SIM900A module for GSM + ARDUINO based communication.I used following code to call a specific number but nothing happens,
void setup()
{
Serial.begin(9600);
delay(10000);
}
void loop()
{
Serial.println("ATDTxxxxxxxxxx;"); //where xxxxxxxxxx is a 10 digit mobile number
delay(30000); // wait 20 seconds.
Serial.println("ATH"); // end call
do // remove this loop at your peril
{
delay(1);
}
while (1>0);
}
whereas when i used ATDTxxxxxxxxxx; in minicom while communicating with SIM900A module, i was able to call(AS ATDxxxxxxxxxx was giving No carrier error, so i used " ; ").Similr is the case with Sending message. I am getting "+CMS ERROR: 302" while i am using
AT+ CMGF=1
AT+CMGS="Mobno." //after this i get the error.
I am not able to send the message through minicom + SIM900A GSM module and i want to test it with Arduino.I think i am having some problem with settings of SIM or either module.I even tried to reset the settings of SIM , but nothing worked out.
First of all: never, never ever use delay instead of proper waiting by parsing the actual response given by the modem. And you must read back the responses given by the modem and wait for the final result code before proceeding to the next command. See this answer and this answer for more details (especially regarding proper AT+CMGS handling).
A list of all the CMS ERRORs are defined in 27.005 in the section 3.2.5 Message Service Failure Result Code +CMS ERROR. Does your subscription allow sending SMS (most likely, but just to be sure check this. Test sending an sms using this sim inserted into another mobile phone)? What message storage are you using? Are you sure the gsm module supports text mode?
I solve the problem just use this code:
void setup()
{
Serial.begin(9600);
delay(10000);
}
void loop()
{
Serial.println("ATD+60148266823;"); //where xxxxxxxxxx is a 10 digit mobile number
delay(30000); // wait 20 seconds.
Serial.println("ATH"); // end call
do // remove this loop at your peril
{
delay(1);
} while (1>0);
}
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.println("AT");
delay(500);
Serial.print("ATD");
Serial.println("99XXXXXXX8;");
delay(20000);
Serial.println("ATH");
}

Resources