PN522 reader as keyboard using Cjmcu Beetle (ATMEGA32U4)
thingiverse
Human: I'm using a PN522 reader that sends data as keyboard input to my PC via an Arduino CJMCU Beetle (ATMEGA32U4). The Beetle is programmed like a Leonardo using the Arduino IDE 1.8.5, and the PN522 is set up for I2C communication using a dip switch on the module (1=on, 2=off). When ready, a yellow LED with resistor lights up; an active buzzer beeps when the card is good, and double beeps when the card is wrong (with the LED blinking). I can read a maximum of 16 characters from the card in block 5. To make it work with my Italian keyboard, I had to add < and > characters, which are very hard to send. The keyboard.h library is for English keyboard scancode only. Libraries used: Adafruit_PN532.h and Keyboard.h for Leonardo. Code (missing hashtag character): #include <Keyboard.h> // Keyboard.h #include <Wire.h> // Wire.h #include <Adafruit_PN532.h> // Adafruit_PN532.h #define PN532_IRQ A0 #define PN532_RESET 15 #define PIN_TONE 11 #define PIN_LED 10 #define PLAY_ERROR tone(11, 100,500) #define PLAY_OKAY1 tone(11, 600, 200) #define PLAY_OKAY2 tone(11, 700, 200) uint8_t success; // Flag to check if there was an error with the PN532 uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type) uint8_t currentblock; // Counter to keep track of which block we're on bool authenticated = false; // Flag to indicate if the sector is authenticated uint8_t data[16]; // Array to store block data during reads uint8_t keyuniversal[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; // Keyb on NDEF and Mifare Classic should be the same Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET); void setup(void) { delay(1000); pinMode(PIN_LED, OUTPUT); nfc.begin(); uint32_t versiondata = nfc.getFirmwareVersion(); if (!versiondata) { PLAY_ERROR; PLAY_ERROR; while (1) { digitalWrite(PIN_LED, HIGH); delay(300); digitalWrite(PIN_LED, LOW); }; // halt } nfc.SAMConfig(); // configure board to read RFID tags digitalWrite(PIN_LED, HIGH); Keyboard.begin(); } void loop(void) { // Wait a bit before trying again digitalWrite(PIN_LED, LOW); delay(2000); digitalWrite(PIN_LED, HIGH); success = nfc.readPassiveTargetID(PN532_IRQ, uid, uidLength); if (!success) { PLAY_ERROR; return; } authenticated = true; // Authenticated ... we should be able to read the block now success = nfc.mifareclassic_ReadDataBlock(currentblock, data); if (!success) { PLAY_ERROR; return; } // Read successful for(int i=0;data[i]>0;i++) { if(data[i]=='<') { Keyboard.write(236); // < } else if(data[i]=='>') { Keyboard.press(KEY_LEFT_SHIFT); Keyboard.write(236); // > Keyboard.release(KEY_LEFT_SHIFT); } else { Keyboard.print((char)data[i]); } } PLAY_OKAY1; delay(100); PLAY_OKAY2; PCB Wires: Yellow to led Blue GND for led and buzzer Green to buzzer PN522: Black GND Red VCC White to SDA Gray to SCL Purple to IRQ Pink to RTS0
With this file you will be able to print PN522 reader as keyboard using Cjmcu Beetle (ATMEGA32U4) with your 3D printer. Click on the button and save the file on your computer to work, edit or customize your design. You can also find more 3D designs for printers on PN522 reader as keyboard using Cjmcu Beetle (ATMEGA32U4).