Skip to content

Libraries

steigeia edited this page May 9, 2017 · 3 revisions

Standard Arduino Libraries

My project uses 3 of the Standard Libraries from Arduino which can be found here. These libraries include the SPI, SD, and Wire libraries. The SPI library is used to allow the UNO to talk to other device using the SPI communication protocol. The Wire library is used to allow the UNO to talk to other device using the I2C communication protocol. You can learn more about the SPI and I2C communication protocol on the Communication Protocols page here. You can learn more about Arduino's SPI library here and Arduino's Wire library here. The SD library allows for the Arduino UNO to read from and write to SD cards utilizing SD slot like on the data logging shield. I mainly utilized the code from the Datalogger example which can be found here.

RTClib-master

The RTClib-master library can be found in the documentation for Adafruit data logger shield here or in my code repository here. This library communicates with a Real Time Clock through the I2C communications protocol by using the Wire library. In order to use the Real Time Clock, you need to set it to the correct time this can be done using the ds1307 example which can be found here. I also found this code to be a good over view of how to retrieve the current time from the Real Time Clock.

AddicoreRFID

The addicoreRfid library can be found with the documentation for the RC522 Module here or in my code repository here. This library lets the Arduino UNO communicate with RC522 Module through SPI communications. It can be a bit hard to understand how to do certain things using the library but the example in the library shows how to rea the UNIDs of RFID cards which is what is needed for this project. This example is the Addicore_RFID_Example and can be found here. There is one issue with the example code which can be seen below.

pinMode(chipSelectPin,OUTPUT);              // Set digital pin 10 as OUTPUT to connect it to the RFID /ENABLE pin 
digitalWrite(chipSelectPin, LOW);           // Activate the RFID reader
pinMode(NRSTPD,OUTPUT);                     // Set digital pin 5, Not Reset and Power-down
digitalWrite(NRSTPD, HIGH);

The above code implies that in order to change which pins are used for SS and Reset can be changed just by setting their pin mode and value. The init function is what is supposed to do this and the library has a setup function for setting the SS and Reset pins. The correct way to use the library would be to use the setup function followed up by the init function which can be seen below.

//set the value for the Slave Select and the Reset pin then initialize
myRFID.Advanced_Setup_AddicoreRFID(chipSelectRFID, resetRFID);
myRFID.AddicoreRFID_Init();

Another 2 functions that is used are for selecting and reading the UNID of a RFID card. These function can be seen below.

stat = myRFID.AddicoreRFID_Request(PICC_REQIDL , str);//search area for cards
stat = myRFID.AddicoreRFID_Anticoll(str);//read selected card with anticollision detection

The PICC_REQUIDL searchs the antenna area and selects a card. In AddicoreRFID_Request(PICC_REQIDL , str), str is a unsigned char* that contains information about the type of RFID chip is in the card but this is not used in this project. In AddicoreRFID_Anticoll(str), str is an unsigned char* that contains the 4 byte UNID and a 1 byte checksum which should be the exclusive or of all 4 of the UNID bytes. both functions return a status btye which can be one of the following values.

//AddicoreRFID error codes
#define MI_OK                   0
#define MI_NO_TAG_ERR           1
#define MI_ERR                  2

The final function that is used is AddicoreRFID_Halt() which puts the selected card into hibernation to avoid filling up chip's buffer.

Clone this wiki locally