wip rfid
This commit is contained in:
parent
1258a23dc4
commit
eb0d631ea2
32
README.md
32
README.md
|
|
@ -9,23 +9,31 @@ This library only works on multi-core ESP32 chips like the ESP32-S3. It does not
|
||||||
|
|
||||||
## Pins
|
## Pins
|
||||||
|
|
||||||
|
### Amplifier
|
||||||
```
|
```
|
||||||
Amplifier:
|
26 -> DIN
|
||||||
25 -> DIN
|
27 -> BCLK
|
||||||
D8 -> BCLK
|
25 -> LRC
|
||||||
D4 -> LRC
|
|
||||||
5V -> Vin
|
5V -> Vin
|
||||||
GND -> GND
|
GND -> GND
|
||||||
|
|
||||||
DAC Channel ESP32 = PIN 25
|
|
||||||
|
|
||||||
SD Card:
|
|
||||||
CS -> D1
|
|
||||||
MOSI -> D7
|
|
||||||
CLK -> D5
|
|
||||||
MISO -> D6
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### SD Card
|
||||||
|
|
||||||
|
```
|
||||||
|
CS -> 22 (D1)
|
||||||
|
MOSI -> 23 (D7)
|
||||||
|
CLK -> 18 (D5)
|
||||||
|
MISO -> 19 (D6)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Buttons
|
||||||
|
|
||||||
|
```
|
||||||
|
Start / Stop -> 17 and GND
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## TODOs
|
## TODOs
|
||||||
* Card Reader with SPI. Configure hspi, second SPI channel? Or does SD Card + RFID run at the same channel?
|
* Card Reader with SPI. Configure hspi, second SPI channel? Or does SD Card + RFID run at the same channel?
|
||||||
|
|
||||||
|
|
|
||||||
106
src/main.cpp
106
src/main.cpp
|
|
@ -19,6 +19,7 @@
|
||||||
// define pins for RFID
|
// define pins for RFID
|
||||||
#define CS_RFID 32
|
#define CS_RFID 32
|
||||||
#define RST_RFID 33
|
#define RST_RFID 33
|
||||||
|
#define IRQ_RFID 34
|
||||||
|
|
||||||
// Audio DAC
|
// Audio DAC
|
||||||
#define I2S_DOUT 26 // connect to DAC pin DIN
|
#define I2S_DOUT 26 // connect to DAC pin DIN
|
||||||
|
|
@ -27,6 +28,8 @@
|
||||||
|
|
||||||
#define BTN_START_STOP 17 // Button on D3 and GND
|
#define BTN_START_STOP 17 // Button on D3 and GND
|
||||||
|
|
||||||
|
#define CS_SDCARD 22
|
||||||
|
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "WebContent.h"
|
#include "WebContent.h"
|
||||||
|
|
@ -50,10 +53,28 @@ DirectoryNode *currentNode = NULL;
|
||||||
|
|
||||||
boolean blockState = false;
|
boolean blockState = false;
|
||||||
|
|
||||||
|
volatile bool newRfidInt = false;
|
||||||
|
|
||||||
|
|
||||||
|
MFRC522 rfid(CS_RFID, RST_RFID); // instatiate a MFRC522 reader object.
|
||||||
|
|
||||||
|
|
||||||
|
void activateSD() {
|
||||||
|
digitalWrite(CS_SDCARD, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void deactivateSD() {
|
||||||
|
digitalWrite(CS_SDCARD, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
void activateRFID() {
|
||||||
|
digitalWrite(CS_RFID, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void deactivateRFID() {
|
||||||
|
digitalWrite(CS_RFID, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
void playNextMp3()
|
void playNextMp3()
|
||||||
{
|
{
|
||||||
blockState = true;
|
blockState = true;
|
||||||
|
|
@ -168,6 +189,22 @@ void audio_eof_mp3(const char *info) {
|
||||||
playNextMp3();
|
playNextMp3();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void readRFID() {
|
||||||
|
rfid.PICC_ReadCardSerial();
|
||||||
|
Serial.print("Tag UID: ");
|
||||||
|
String uidString = String(rfid.uid.uidByte[0]) + " " + String(rfid.uid.uidByte[1]) + " " +
|
||||||
|
String(rfid.uid.uidByte[2]) + " " + String(rfid.uid.uidByte[3]);
|
||||||
|
Serial.println(uidString);
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearInt(MFRC522 mfrc522) {
|
||||||
|
mfrc522.PCD_WriteRegister(mfrc522.ComIrqReg, 0x7F);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IRAM_ATTR rfid_interrupt() {
|
||||||
|
newRfidInt = true;
|
||||||
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
|
|
@ -175,11 +212,50 @@ void setup()
|
||||||
|
|
||||||
pinMode(BTN_START_STOP, INPUT_PULLUP);
|
pinMode(BTN_START_STOP, INPUT_PULLUP);
|
||||||
|
|
||||||
|
/* setup the IRQ pin*/
|
||||||
|
pinMode(IRQ_RFID, INPUT_PULLUP);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Init MFRC522
|
||||||
|
// Init SPI bus
|
||||||
|
SPI.begin();
|
||||||
|
rfid.PCD_Init();
|
||||||
|
/*
|
||||||
|
* Allow the ... irq to be propagated to the IRQ pin
|
||||||
|
* For test purposes propagate the IdleIrq and loAlert
|
||||||
|
*/
|
||||||
|
rfid.PCD_WriteRegister(rfid.ComIEnReg, 0xA0);
|
||||||
|
|
||||||
|
newRfidInt = false; //interrupt flag
|
||||||
|
|
||||||
|
attachInterrupt(IRQ_RFID, rfid_interrupt, FALLING);
|
||||||
|
|
||||||
|
do { //clear a spourious interrupt at start
|
||||||
|
;
|
||||||
|
} while (!newRfidInt);
|
||||||
|
newRfidInt = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//switch off RFID Reader:
|
||||||
|
//pinMode(RST_RFID, OUTPUT);
|
||||||
|
//digitalWrite(RST_RFID, LOW);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// first parameter is name of access point, second is the password
|
// first parameter is name of access point, second is the password
|
||||||
AsyncWiFiManager wifiManager(&server, &dns);
|
AsyncWiFiManager wifiManager(&server, &dns);
|
||||||
|
|
||||||
wifiManager.autoConnect("HannaBox");
|
wifiManager.autoConnect("HannaBox");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
deactivateRFID();
|
||||||
|
|
||||||
Serial.print("Initializing SD card...");
|
Serial.print("Initializing SD card...");
|
||||||
|
|
||||||
if (!SD.begin(D1))
|
if (!SD.begin(D1))
|
||||||
|
|
@ -192,6 +268,16 @@ void setup()
|
||||||
|
|
||||||
rootNode.buildDirectoryTree("/");
|
rootNode.buildDirectoryTree("/");
|
||||||
rootNode.printDirectoryTree();
|
rootNode.printDirectoryTree();
|
||||||
|
|
||||||
|
Serial.println("RFID");
|
||||||
|
|
||||||
|
// clear RFID Reset
|
||||||
|
//digitalWrite(RST_RFID, HIGH);
|
||||||
|
|
||||||
|
activateRFID();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// printDirectoryTree(&rootNode, 0);
|
// printDirectoryTree(&rootNode, 0);
|
||||||
|
|
||||||
// printDirectory(root, 0);
|
// printDirectory(root, 0);
|
||||||
|
|
@ -227,9 +313,28 @@ void setup()
|
||||||
server.begin();
|
server.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (newRfidInt) {
|
||||||
|
|
||||||
|
deactivateSD();
|
||||||
|
activateRFID();
|
||||||
|
|
||||||
|
if(rfid.PICC_IsNewCardPresent()) {
|
||||||
|
readRFID();
|
||||||
|
}
|
||||||
|
|
||||||
|
deactivateRFID();
|
||||||
|
activateSD();
|
||||||
|
|
||||||
|
clearInt(rfid);
|
||||||
|
newRfidInt = false;
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
audio.loop();
|
audio.loop();
|
||||||
|
|
||||||
if (buttonPressed(BTN_START_STOP)) {
|
if (buttonPressed(BTN_START_STOP)) {
|
||||||
|
|
@ -240,6 +345,7 @@ void loop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean buttonPressed(const uint8_t pin) {
|
boolean buttonPressed(const uint8_t pin) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue