Submitted by fabio on Mon, 2012-07-09 10:59.
Yesterday night, me and Federico Vanzati (one of the guys working for Officine Arduino at Fablab Torino) had a good time hacking the NFC shield by Adafruit so that it could work with the new Arduino Leonardo.
The hacking started when we connected the Leonardo to the NFC and discovered that I2C, the default hardware communication bus used by the shield to communicate with the Arduino, was not working on the Leonardo. This shield, even if already designed for Arduino UNO R3 pinout, wasn't working with the Arduino Leonardo at all! This blog post is a small summary of what we did to address these issues.
We started investigating the problem..
the first strange thing worth noting is that this shield, even if it comes with the various Open Hardware logos on it, it doesn't actually have any shematics nor EDA CAD designs available The designs were actually available on Adafruit github but simply not linked from the product page, that's why we missed them. So, we had to kind of reverse engineering the shield in order to understand the problem.
So, the first problem we discovered is that the IRQ pin of the PN532, used to signal the microcontroller on a successful read, is connected to pin Digital 2 on the shield.. this is not good at all with the Leonardo since D2 is also I2C SDA making communication impossible. Fixing this was as simple as cutting out the trace going from the IRQ pin into the D2 pin on the shield.
We decided to use a two ways on-on switch (see picture below) connecting IRQ to D2 in one position and IRQ to D8 in the other position.. the idea was being able to switch between D8 and D2 when used with UNO or Leonardo respectively. On a second thought, it is probably better to move that to another pin usable on both the UNO and Leonardo.
The next problem we had to address was a pin conflict: this shield connects I2C SDA and SCL both on the new SDA and SCL pins on the new Arduino UNO R3 pinouts (top left near the various digital pins) as well on the legacy A4 and A5 pins used for I2C in legacy Arduino Duemilanove and previous boards. Fixing this was as simple as cutting out the traces connecting I2C to A4 and A5.
With a small modification to the reference code from the Adafruit NFC library (attached below), instructing the library to use D8 instead of D2 as IRQ connection, we finally had a perfectly functioning NFC shield with I2C on the Arduino Leonardo!
Suggestion for Adafruit: in case backward compatibility with legacy boards is needed, I'd use a 2 ways on-on switch (eg: JS202011SCQN) allowing the connection to A4 and A5 when needed on legacy boards. Solder jumpers will work too.