-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow specification of SPI interface instead of default on ESP32
- Loading branch information
1 parent
51dec69
commit 7f6c491
Showing
5 changed files
with
151 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
examples/CustomSPI/CheckCardAuthorisationESP32/CheckCardAuthorisationESP32.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Example of the Trivial RFID authorisation library | ||
* | ||
* https://github.com/ncmreynolds/TrivialRFIDauthorisation | ||
* | ||
* This example will authorise the card for a single ID when presented to the reader | ||
* | ||
* Here you can see how to change the pins used for connecting the reader to the default SPI interface (VSPI) on an ESP32 | ||
* | ||
* Unlike many other microcontrollers ESP32s can be flexibly configured use _most_ of their GPIO pins for hardware SPI | ||
* | ||
* This example was tested with an ESP32S3 but should work with most ESP32s if you set appropriate pins | ||
* | ||
*/ | ||
#include <TrivialRFIDauthorisation.h> | ||
|
||
#if defined(ESP32) | ||
const int rfidCsPin = 47; //Set the CS pin | ||
const int rfidClkPin = 48; //Set the CLK pin | ||
const int rfidCopiPin = 45; //Set the COPI pin | ||
const int rfidCipoPin = 38; //Set the CIPO pin | ||
TrivialRFIDauthorisation rfid(rfidClkPin, rfidCipoPin, rfidCopiPin, rfidCsPin); | ||
#else | ||
#error This sketch will only work on an ESP32 | ||
#endif | ||
|
||
uint8_t idToAuthorise = 28; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
//rfid.debug(Serial); //Enables debugging. Doing this before 'begin' means you can see the reader initialisation information! | ||
if(rfid.begin()) { //Start the RFID reader | ||
Serial.println(F("*******************************")); | ||
Serial.println(F("Checking authorisation of cards")); | ||
Serial.println(F("*******************************")); | ||
} | ||
else | ||
{ | ||
Serial.println(F("*******************************")); | ||
Serial.println(F("RFID reader self test failed")); | ||
Serial.println(F("*******************************")); | ||
delay(0); | ||
} | ||
} | ||
|
||
void loop() { | ||
rfid.pollForCard(); //Must run regularly to read and process the card | ||
if(rfid.cardPresent() == true && rfid.cardChanged() == true) | ||
{ | ||
bool result = rfid.checkCardAuthorisation(idToAuthorise); | ||
Serial.println(F("********************************")); | ||
Serial.print(F("Checking card for authorisation against ID:")); | ||
Serial.print(idToAuthorise); | ||
Serial.print(F(" - ")); | ||
if(result == true) | ||
{ | ||
Serial.println(F("authorised")); | ||
} | ||
else | ||
{ | ||
Serial.println(F("not authorised")); | ||
} | ||
Serial.println(F("********************************")); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
examples/CustomSPI/CheckCardAuthorisationESP32HSPI/CheckCardAuthorisationESP32HSPI.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Example of the Trivial RFID authorisation library | ||
* | ||
* https://github.com/ncmreynolds/TrivialRFIDauthorisation | ||
* | ||
* This example will authorise the card for a single ID when presented to the reader | ||
* | ||
* Here you can see how to change the pins used for connecting the reader to the second SPI interface (HSPI) on an ESP32 | ||
* | ||
* Unlike many other microcontrollers ESP32s can be flexibly configured use _most_ of their GPIO pins for hardware SPI and have multiple SPI interfaces | ||
* | ||
* This example was tested with an ESP32S3 but should work with most ESP32s if you set appropriate pins | ||
* | ||
*/ | ||
#include <TrivialRFIDauthorisation.h> | ||
|
||
#if defined(ESP32) | ||
const int rfidCsPin = 47; //Set the CS pin | ||
const int rfidClkPin = 48; //Set the CLK pin | ||
const int rfidCopiPin = 45; //Set the COPI pin | ||
const int rfidCipoPin = 38; //Set the CIPO pin | ||
SPIClass hspi = SPIClass(HSPI); //Create an instance of an SPI driver specifically for the RFID reader | ||
TrivialRFIDauthorisation rfid(hspi, rfidClkPin, rfidCipoPin, rfidCopiPin, rfidCsPin); | ||
#else | ||
#error This sketch will only work on an ESP32 | ||
#endif | ||
|
||
uint8_t idToAuthorise = 28; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
//rfid.debug(Serial); //Enables debugging. Doing this before 'begin' means you can see the reader initialisation information! | ||
if(rfid.begin()) { //Start the RFID reader | ||
Serial.println(F("*******************************")); | ||
Serial.println(F("Checking authorisation of cards")); | ||
Serial.println(F("*******************************")); | ||
} | ||
else | ||
{ | ||
Serial.println(F("*******************************")); | ||
Serial.println(F("RFID reader self test failed")); | ||
Serial.println(F("*******************************")); | ||
delay(0); | ||
} | ||
} | ||
|
||
void loop() { | ||
rfid.pollForCard(); //Must run regularly to read and process the card | ||
if(rfid.cardPresent() == true && rfid.cardChanged() == true) | ||
{ | ||
bool result = rfid.checkCardAuthorisation(idToAuthorise); | ||
Serial.println(F("********************************")); | ||
Serial.print(F("Checking card for authorisation against ID:")); | ||
Serial.print(idToAuthorise); | ||
Serial.print(F(" - ")); | ||
if(result == true) | ||
{ | ||
Serial.println(F("authorised")); | ||
} | ||
else | ||
{ | ||
Serial.println(F("not authorised")); | ||
} | ||
Serial.println(F("********************************")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters