I've done a lot of projects over the holidays. This is a quick collection of notes to remind myself later.
I used an RC522 RFID scanner (originally part of a Tonuino project) and wired it to a Particle Photon. Whenever an RFID tag was held to it, it would publish an event containing the ID of the card to the Particle Cloud. When the card was removed, it would publish a blank event. This is the code from the Photon:
// Photon RFID-RC522
// A2 SDA
// A3 SCK
// A4 MISO
// A5 MOSI
// D2 RST
// GND GND
// 3V3 3.3V
#include
#include
#define LED_PIN D7
constexpr uint8_t RST_PIN = D2; // Configurable, see typical pin layout above
constexpr uint8_t SS_PIN = A2; // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
uint32_t lastMillis = 0;
bool wasPresent = false;
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
if(wasPresent) {
if(! mfrc522.PICC_IsNewCardPresent()) {
Serial.println("No card");
Particle.publish("rfid_scan", "", 60, PRIVATE);
wasPresent = false;
}
} else {
}
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
char cardID[32] = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
char hex[4];
snprintf(hex, sizeof(hex), "%02x", mfrc522.uid.uidByte[i]);
strncat(cardID, hex, sizeof(cardID));
}
if (millis() - lastMillis < 1000) {
return;
}
lastMillis = millis();
if(!wasPresent) {
wasPresent = true;
Particle.publish("rfid_scan", cardID, 60, PRIVATE);
Serial.printlnf("Card: %s", cardID);
// Turn on the LED
digitalWrite(LED_PIN, HIGH);
// Leave it on for one second
delay(1s);
// Turn it off
digitalWrite(LED_PIN, LOW);
// Wait one more second
delay(1s);
}
// Dump debug info about the card; PICC_HaltA() is automatically called
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
I then used IFTTT to read these events and write them to a Google Spreadsheet. This is the IFTTT Excel code:
{{CreatedAt}} |||{{EventContents}}||| =IF(ISODD(ROW()), "Started", "Stopped") ||| =IF(ISEVEN(ROW()),ROUND(((DATEVALUE(REGEXEXTRACT(INDIRECT(ADDRESS(ROW(),COLUMN()-3,4)), "w+ d{2}, d{4}")) + TIMEVALUE(REGEXEXTRACT(INDIRECT(ADDRESS(ROW(),COLUMN()-3,4)), "d{2}:d{2}[A|P]M$"))) - ( DATEVALUE(REGEXEXTRACT(INDIRECT(ADDRESS(ROW()-1,COLUMN()-3,4)), "w+ d{2}, d{4}")) + TIMEVALUE(REGEXEXTRACT(INDIRECT(ADDRESS(ROW()-1,COLUMN()-3,4)), "d{2}:d{2}[A|P]M$")))) * 24, 2),"")|||
=IFERROR(VLOOKUP(INDIRECT(ADDRESS(ROW(), COLUMN()-3),4), I$3:J$10, 2, FALSE), "")
We now have a physical time tracker that can be used to log time spent on individual projects. Super-handy for Jenni's freelance work.