SD CARD and RFID not working together
hey.
i have project want play soundfile when specifc rfid tag have been read.
i use micro sd card adapter, arduino uno , rfid-rc522.
i try use spi, setting slave pins of components high or low either "turn device off" or "turn device on". components share same miso, mosi , clock pin, , each have own individual slave pin, rfid having rst pin.
i have triple checked connections , components work individually.
i think problem spi.transfer iam not sure.
i upload code below , hope can me.
i have project want play soundfile when specifc rfid tag have been read.
i use micro sd card adapter, arduino uno , rfid-rc522.
i try use spi, setting slave pins of components high or low either "turn device off" or "turn device on". components share same miso, mosi , clock pin, , each have own individual slave pin, rfid having rst pin.
i have triple checked connections , components work individually.
i think problem spi.transfer iam not sure.
i upload code below , hope can me.
code: [select]
#include <require_cpp11.h>
#include <mfrc522hack.h>
#include <mfrc522extended.h>
#include <mfrc522debug.h>
#include <deprecated.h>
#include <sd.h>
#include <tmrpcm.h>
#include <spi.h>
#include <mfrc522.h>
#define sdslave 4 //cs pin fra sd card
#define rstpin 7 //reset pin rfid
#define rfidslavepin 6 // slavepin rfid
int pullldowndelay = 50;
tmrpcm tmrpcm; // create object use in sketch til lyden
mfrc522 mfrc522(rfidslavepin, rstpin); // create mfrc522 instance til rfid scanner
void setup() {
serial.begin(9600);
while (!serial); // nothing if no serial port opened (added arduinos based on atmega32u4)
spi.begin(); // init spi bus
pinmode(rfidslavepin, output);
pinmode(sdslave, output);
digitalwrite(rfidslavepin, low);
digitalwrite(sdslave, high);
delay(pullldowndelay);
mfrc522.pcd_init(); // init mfrc522
mfrc522.pcd_dumpversiontoserial(); // show details of pcd - mfrc522 card reader details
serial.println(f("scan picc see uid, sak, type, , data blocks..."));
tmrpcm.speakerpin = 9;
digitalwrite(rfidslavepin, high);
digitalwrite(sdslave, low);
delay(pullldowndelay);
if (!sd.begin(sdslave)) { // see if card present , can initialized:
return; // don't more if not
}
}
void loop() {
sdcard();
}
void sound() {
digitalwrite(rfidslavepin, high);
digitalwrite(sdslave, low);
delay(pullldowndelay);
serial.print("sound function called");
tmrpcm.play("lol.wav");
delay(8000); // delay after sound played let song finish
delay(pullldowndelay);
digitalwrite(sdslave, high);
digitalwrite(rfidslavepin, low);
}
void sdcard() {
// new cards https://www.youtube.com/watch?v=3uwz7xmr55c
digitalwrite(sdslave, high);
digitalwrite(rfidslavepin, low);
delay(pullldowndelay);
if (!mfrc522.picc_isnewcardpresent()) {
serial.print("no new cards found");
serial.println();
return;
}
// select 1 of cards
if (!mfrc522.picc_readcardserial()) {
serial.print("problems reading cards");
serial.println();
return;
}
// dump debug info card; picc_halta() automatically called
mfrc522.picc_dumptoserial(&(mfrc522.uid));
//show uid on serial monitor
serial.print("uid tag :");
string content = "";
byte letter;
for (byte = 0; < mfrc522.uid.size; i++)
{
serial.print(mfrc522.uid.uidbyte[i] < 0x10 ? " 0" : " ");
serial.print(mfrc522.uid.uidbyte[i], hex);
content.concat(string(mfrc522.uid.uidbyte[i] < 0x10 ? " 0" : " "));
content.concat(string(mfrc522.uid.uidbyte[i], hex));
}
serial.println();
serial.print("message : ");
content.touppercase();
if (content.substring(1) == "3a 14 a1 e8") //change here uid of card/cards want give access
{
serial.println("authorized access");
serial.println();
delay(3000);
sound();
}
}
yout not same guy fb finger print scanner ya?
what sd module using
what sd module using
Arduino Forum > Using Arduino > Programming Questions > SD CARD and RFID not working together
arduino
Comments
Post a Comment