Grove NFC-Tag module

I just wrote a bit of python code to talk to the Grove NFC tag module, which I guess might be of use to other people (and might want to go in the grovepi library somewhere?).

I only handled reading and writing the data, none of the other commands. It is slightly less efficient than it could be, in that it does everything as byte writes, rather than 4 bytes at a time, because of the limitations of the python smbus module, which doesn’t let you write full transactions (even getting it working this way is a bit of a hack using the smbus write_word message).

Anyway, the code is below, do with it what you want, it’s in the public domain as far as I’m concerned. Should be self explanatory:

import smbus
import time

NFC_ADDR = 0x53

bus=smbus.SMBus(1)
    
def readNFCData(addr,length):
  bus.write_byte_data(NFC_ADDR,addr>>8,addr&0xff)
  result=[]
  for c in range(length):
    result.append(bus.read_byte(NFC_ADDR))
  return result

def writeNFCData(addr,data):
    for byte in data:
      bus.write_word_data(NFC_ADDR,addr>>8,(addr&0xff | (byte<<8)))
      time.sleep(0.01)
      addr+=1

Hi joemarshall,
Thanks a lot for posting the NFC code. It would be even better if you sent a pull request to the Github Repository here: https://github.com/DexterInd/GrovePi.

We’ll be more than merge it with the existing examples. It would be even better if you document the code a bit so that people can easily use and update the code.

Thanks,
Karan