element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs Pi Passport: Step 2: Setting up NFC
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: charlotte_godley
  • Date Created: 10 Aug 2014 6:19 PM Date Created
  • Views 1461 views
  • Likes 2 likes
  • Comments 12 comments
  • raspberry-pi-b+
  • b+
  • raspberry-pi-bplus
  • pipassport
  • explore-nfc
  • raspberry-pi
  • raspberrypi
  • nfc
  • charlotte_godley
Related
Recommended

Pi Passport: Step 2: Setting up NFC

charlotte_godley
charlotte_godley
10 Aug 2014

See the first post: project introduction

 

Here I'm going to go through really simple set up with NFC, which I promise is dead quick, using Python as it's simplest. This assumes you know how to set your pi up, and have it all ready for putting code onto it using the internet, and communicating with it in some way in order to program. You will need:

  1. A Raspberry pi of any model and power supply
  2. An SD card or MicroSD card with raspbian installed
  3. Add-on board - Explore NFC from Farnell element14
  4. Internet connection

Stage 1: Set up Start by removing power from your pi, if it's turned on (make sure you do a sudo halt first!), and plugging in your NFC board onto the GPIO connector.

Complicated hardware set up out of the way, turn your pi back on. Run an update and upgrade:image

sudo apt-get update

sudo apt-get upgrade

and turn SPI on in raspi config (sudo raspi-config, advanced options>spi>yes).

For the interfacing with NXP, I'm using a library called NXPPY – this is an incredibly simple python wrapper which calls the code made by Farnell for the explorer board: as such the only function in python is reading the serial ID. Please note the following code is deprecated! This tutorial was written using version 1 of the above library, which you will need to download using the releases page. If you've downloaded and installed using pip instead, please refer to the realm on the github page of the repo: https://github.com/svvitale/nxppy

The code essentially boils down to this:

import nxppy 
uid = nxppy.read_mifare()

Which is fairly simple to understand. In order to make it so it'll keep waiting for an ID:


Make this file by entering:

sudo nano read.py

entering the code, then CTRL+X followed by y, then press enter to save the file.

In the console now enter:

sudo python read.py

As shown in the screenshot:

image

The program should hang, waiting for a scanned NFC (If you'd like to close the python file, you can also press CTRL+C) - if you put the card that came with the scanner on the scanner whilst this program is running as shown in this photo:

image

Your python file should print out the card's ID:

image


Something to note: you can scan your mobile phone using this, but the NFC serial ID will be different every time, so we can't use a phone for the purpose of this project.

I'll cover my next step, of how to build a class around this in the next blog.

  • Sign in to reply
  • Former Member
    Former Member over 9 years ago

    Hello Charlotte. I have Raspberry and Element14 NFC device(PN512). Maybe you can help me to fing any examples how to work with it from java code?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • charlotte_godley
    charlotte_godley over 10 years ago in reply to Former Member

    Read the note in bold above where I put the code in.

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 10 years ago

    Hello Charlotte

    I followed several times your installation instructions as described.

    I always get the following error when you run the read.py

     

    pi@raspberrypi ~ $ sudo python read.py

    Traceback (most recent call last):

      File "read.py", line 3, in <module>

        uid=nxppy.read_mifare()

    AttributeError: 'module' object has no attribute 'read_mifare'

    pi@raspberrypi ~ $

     

     

     

    hast du mir da einen type?

    Dank dir aus der Schweiz

     

     

    fswema

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • charlotte_godley
    charlotte_godley over 10 years ago in reply to Former Member

    Aaaaah ok this is because element14's code highlighter has messed up my indenting. I'll go and switch that section to a gist because it's easier to use, but basically for all the lines after "while True" excluding "print uid" indent them using 8 spaces and python should let it pass image Python's very particular about indenting because it uses them to control program flow/scope

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 10 years ago

    I get the following error after running the script:

     

    File "read.py", line 5

    uid=nxppy.read_mifare()

    IdentationEror:expected as indented block

     

    Any suggestions for how to get this working? I've been trying for days to get the shield up and running, so any help is more than welcomed. And thank you for this tutorial! image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube