element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • Experts & Guidance
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • 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
Personal Blogs
  • Members
  • More
Personal Blogs
Legacy Personal Blogs The Light-up NFC Bracelet Project: Stage 2
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: charlotte_godley
  • Date Created: 12 Jun 2015 1:03 PM Date Created
  • Views 553 views
  • Likes 1 like
  • Comments 1 comment
  • nfcrfidch
  • neopixel
  • charlotte_godley
  • adafruit_gemma
  • circuits_with_charlotte
  • adafruit
Related
Recommended

The Light-up NFC Bracelet Project: Stage 2

charlotte_godley
charlotte_godley
12 Jun 2015

It's been a while since I last posted - I've had a lot of work to do with uni, but now I can continue writing this project up, and I hope you enjoy reading some more on it and hopefully learning.

 

Last time I wrote about soldering together the hardware to create an NFC based bracelet which will glow based on a phone pattern.

Today I'm going to write about creating the code on an android device which will change the bracelet's pattern. I'll be using Android Studio, which you can download and set up here: link.

 

Step 1

The first step is to design the user interface. Start by creating a new activity:

image

Create new: Creating a new activity

 

Activity settings: Input your activity settings

image

Then go to the your_activty_layout.xml which should be stored in res/layouts.

Flip to the designer tab and remove the text view. Add a new grid layout.

image

Here your results should vary from mine depending on how many LEDs you intend to connect. For me, I put in 6, so the top row includes 4 buttons, and the third row includes a further two.image

In the second and fourth rows respectively, I put text inputs. Buttons will allow us to input a colour, whilst text inputs will allow us to dictate how many seconds to turn the LED on for.

Finally, I added a button at the bottom which will pull all of the inputs together into an NFC string.

image

 

Step 2

Next up let's create a colour picker activity. This is a popup type that isn't included in Android as standard, so here is some code I borrowed from another tutorial off of Google (track down the link):

Code:

Code to put in your main activity:

Now let's connect the buttons to the colour picker. Go back to your layout's xml file, and on each button, change the onClick handler to be the getColor method.

image

Step 3

Finally, let's create the handler for the Generate button. Put in this handler:

this basically goes through each button and text input, pulls the colour hex code from the button and pairs it with the text input. It then puts it all together into a string, and temporarily logs it so we know what's happened.

 

Step 4

Finally we need to put in code to send the string of data to NFC, and fill in all the gaps from the handler method we created above. Here's another gist to fill that in. Put this inside your activity outside of any handler methods:

 

We also need to modify the OnCreate method so that it sets up some things. To properly handle the colour pickers we put in earlier, we should also change the activity to extend the colour picker listener interface:

 

To make sure our app has the permission to use a phone's NFC antenna, we also need to change AndroidManifest.xml. Replace it with the following code:

 

You can test all this has worked now by putting the bracelet's antenna against the back of your phone and generating the signal. Note that if there has not been an NFC component detected, it will show an error:

imageimageimage

 

Then go to the Play store and download the M24SR64 demo app, open it and put the tag against your phone again. It should pop up with the string of hex input and text inputs you sent to the tag!

Next time we'll pull all of this together with code on the bracelet itself. Here is the Github repo containing the full activity. If you have any suggestions to make it better, I'd love a pull request!

  • Sign in to reply
  • DAB
    DAB over 8 years ago

    Very good detailed post.

     

    DAB

    • 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 © 2023 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