So day two at Notting Hill Gate, happy with having a play around with the microbits I moved my attention to something a little further up the food chain, the still usable, but potentially more involved, Arduino platform. I bought an Uno board ages ago and played around for a few minutes here and there, but never actually got around to connecting anything to it, even only simple things, so once again this was a good time to just hook up some simple stuff, and see what is and isn’t doable…
Adding basic devices to Arduino
Aim
Testbed for use of Arduino IDE, hook up of simple devices to facilitate rapid development of more focused and useful applications – knowledge formative exercise adding each device one at a time, establish method for mode of operation for each device, and understand code with view to merging code and devices at once, to build full scale applications using the array of I/O of an Uno board.
BOM
Arduino Uno, HD44780 Compliant LCD, RC522 NFC Card reader
Setup
Stage 1 – LCD device, attach the LCD to the Uno development board as follows:
LCD RS to Digital 12
LCD Enable to Digital 11
LCD D4 to Digital 5
LCD D5 to Digital 4
LCD D6 to Digital 3
LCD D7 to Digital 2
LCD R/W to GND
LCD Pin 3 to GND (Contrast)
Copy test code into Arduino device:
// Bring in the required library for driving LCD displays #include <LiquidCrystal.h> // LCD pin setup, see LCD example documentation for further details LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { // Sets X Y configuration of LCD connected lcd.begin(16, 2); // Display something on the LCD. lcd.print("hello, world!"); } void loop() { // Running code for main loop here... }
Use
Demonstrates how simple the LCD is to set up, and puts basic characters onto the screen, useful for serial debug etc. Remove wiring and LCD for stage 2.
Setup
Stage 2 – Reading with an RC522 NFC reader and dumping the output to the IDE serial monitor. Attach the RC522 in the following fashion:
RST to Digital 9
SDA to Digital 10
MOSI to Digital 11
MISO to Digital 12
SCK to Digital 13
3.3V to 3.3V
GND to GND
Copy test code into Arduino device:
// Bring in necessary libraries for the reader and interfaces #include <SPI.h> #include <MFRC522.h> // Start an instance of the reader MFRC522 mfrc522(10, 9); void setup() { Serial.begin(9600); while (!Serial); SPI.begin(); mfrc522.PCD_Init(); mfrc522.PCD_DumpVersionToSerial(); Serial.println(F("Scan card to see all available details...")); } void loop() { if ( ! mfrc522.PICC_IsNewCardPresent()) { return; } if ( ! mfrc522.PICC_ReadCardSerial()) { return; } mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); }
Use
Present card to RC522, contents of device are presented on the IDE serial monitor screen as a verbose dump. Most useful value arguably card serial, ideal for use as identity device as serial is read only block. Demonstrates simple extraction of data from NFC.
Further Development
Combining both sets of code to give output on LCD display, or message customized to the card.
Another good day of tinkering with simple stuff, but good stuff that can be combined to make BETTER stuff… Day three, is the first day of our group project.