Creating a dynamic NFC Tag with Arduino and the TI

Creating a dynamic NFC tag, e.g. a NFC Tag that looks like a static tag to an Android/Windows Smartphone but whose content (e.g. URL) can be changed dynamically, is a bit complicated if you’re not using the Android APIs and accept the “form factor” of a smartphone. There are commercial solutions available, like the DTAG100 but you pay an extra $100 for not knowing how to update an NFC chip. So figuring out how to program a dynamic NFC Tag has been a long time goal of mine. Finally, I’ve something to share.

IMG_20130902_090543

What you see above is the RF430CL330H from Texas Instruments (TI). Actually, you see the target board that includes the chip in the middle. The target board adds some electrical components such as a few resistors and capacitors here and there that are required to make the chip work correctly. Also, the target board adds a built-in NFC antenna and makes it really easy to connect wires to it. The wires shown are connected to an Arduino.

To understand how to program the NFC chip, you have to dive into a few protocols and standards. The NFC target board communiates with the Arduino via I2C, a pretty well-known communication protocol that only consumes 2 wires on an Arduino and is therefore very popular. It is all byte-based, so you read and write from registers to communicate with the NFC chip. We’ll not go into detail here, but the above link to the NFC chip would give you the register info for the NFC chip.

Next up is NDEF – NDEF is the NFC Data Exchange Format – a standard by the NFC Forum. It defines, which byte-array exactly makes up a valid NFC message – for a URL for example. It’s again bytes, lot’s of bytes. Around 40 for a smaller 10 character URL. The hard part here is the composition of the bytes. “http://” in a typical URL is for example replaced with a single byte, as it saves space and NFC tags typically cannot hold a lot of data.

Together with Ten Wong, whom I met via the TI Forums and we later communicated along on Google+, I was able to put it all together. He also wrote a library which abstracts the NFC chip. There is one pretty bad issue with the Arduino Wire library, which does the I2C Communication: it will send a stop-bit after 20 or so characters. The problem is that the NDEF message is > 40 bytes. That was causing the messages to be broken. Which files to change exactly can be seen here.

My final addition to this mix was to make the Arduino communicate via a serial connection to a PC or Mac and update the NFC chip with the URL received via Serial. The format is this:

^www.hybris.com^

I am omitting the http:// at this point and only support http:// URLs. Changing that is not very hard though.

Finally, here is the code that is required to make this all work. It is processing code, Arduino Uno and Mega compatible. It will assume the TI NFC Target board is connected as shown in the pic above to I2C and the +3.3V and GND.

The loop() method is waiting for the first ^ and will then call the updateURL method, which will read all data from Serial till another ^ is received. This method is also calculating the dynamic NdEF byte array and then finally hands it over to Ten’s library for storage on the NFD chip.

The cost of the setup is around $15 for the dynamic nfc chip on the target board, plus an Arduino. If you buy a clone, you can get one for around $10 which brings the total solution to a price point of around $25 plus shipping. Of course, this is prototyping and mass producing this probably costs a few dollars only.

Play, Collect, Redeem

This post is a follow up post to the physical endeavors we’re currently undertaking. We’re not only looking into “physical” because making is a huge trend, we also believe there are many interesting applications when it comes to in-store usage. Prototyping with electronics and other physical components gives us the required knowledge to build up prototypes around in-store ecommerce. One example is couponing. How would you use in-store couponing to drive sales to your online or offline store? How can a social profile be merged with coupons and used to gain insights or create viral coupon campaigns? What are the elements of coupons, the characteristics and how do users collect and redeem these coupons?

Our prototype explores exactly this.

The big picture – Play, Collect, Redeem

IMG_20130603_141449

The somewhat ¬†ūüôā technical architecture below shows the key components and how the are linked together for form a couponing system. Customers can play physical games, then collect coupons that they can later redeem for products (or get discounts, etc.). Let’s take a look at each component, seperated via the swimlanes in the below graphic. For the better understanding, we begin with the physical gaming frontends.

hybris Coupons (1)

Physical Frontend

The physical frontends are easy-to-play games that customers will love to interact with and try out. These games are crossover projects between gaming, art and technology. The games include a physical keyboard (via PVC foil and capacitive sensors), a push-button game and a foosball table (kicker) which we put light barriers inside to get the scores.

We designed the system in a way, that only “authenticated” frontends can be used to obtain coupons from the backend. This authentication is done via a simple shared secret (more complex scenarios possible), but the shared secret is not in the web app or otherwise saved in resources that can be accessed from the web. The shared secret is part of the Arduino hardware and trasmitted via a set of keystrokes to the web frontend. That means, only if you are in the posession of the physcial game and the Arduino prototyping board, you can obtain the access token to the coupon backend.

IMG_20130704_111802

Web Frontend

The web frontend is used to receive the game inputs from the physical games, receives the authentication key from time to time and is used to display the coupons. At a later stage, we will also use it to show the game rules to the users of the game (right now these frontends are very basic, ready to be skinned by an CSS guru!).

Via the web, or mobile web, users can also “sign-in” to a physical game frontend. The users can scan a QR code or scan a NFC tag to be redirected to a facebook login page. Once they’ve authorized our coupon application, their profiles and names appear on the web UI. Later on, these profiles will also be used to share the coupon activity to Facebook and to personalize the received coupon itself. We have all the stuff in place to help coupons generated go viral.
Coupon Backend

The coupon backend is the heart of the system and shared among all three frontends. With the required authentication token from the physcial game frontends, the web apps are able to create new coupons via AJAX calls after the users have played a game. Based on the score, a different coupon is created. Each coupon is unique and protected via a signed URL. This allows the coupon backend to trust incoming requests, as the secret for generating the URL signature is known to the backend only. If you get a coupon, tamper with the URL and try to view or redeem it, it won’t work.

The three main RESTful/JSON APIs that the coupon backend exposes are the APIs required to create coupons, view coupons and later redeem coupons. The viewing part has different representations – one is pure JSON, meant to be used for mobile clients or other systems accessing the coupon. The second is a web representation, e.g. a responsive web page which holds the coupon as a QR code. The third is an image-only representation, ready to be embedded into a HTML img tag. These three representation make it very easy to integrate coupons into any application.

As an example, we’ve already upgraded our hybris Wishlist Android application with the feature to collect coupons. As it is a native Android application, the QR code or NFC tag is scanned, which transmits the signed coupon URL to the app. The app then resolves the Coupon via the REST api and chooses the JSON representation to obtain access to all coupon data.
Mobile Frontend 

There are actually two mobile frontends: there are the shopping assistants, who scan the coupons and redeem the coupons for the users. They use a simple QR code scanner on any OS to view the coupon. They are the only ones who can mark ¬†a coupon “used” – that means the coupon’s “use count” is increased by one. Once a coupon hits the max use count figure it is no longer valid.

The other frontend, used by normal users, is either a web representation of the coupon or a mobile app, such as our Android-based coupon app. The benefit of the app is that you can collect multiple coupons, store them, revisit them and later redeem them.

 

So far so good, what’s next…

We got a lot of essential systems in place, but there would be a lot of opportunity for further research. Think about data analysis, different coupon/product combinations, geofencing wishlist items and coupons or just coupon variations (one-off coupons, product segment coupons, single product coupons, shareable/viral coupons, etc.).

We’ll also go on a roadshow to present all this. First stop will be Derry in the UK for a technology and art festival. Next up might be a swiss conference which is not yet finally approved. All these conferences and presentations will help us to interact a lot with real users, potential customers of hybris systems and also end-users. It’s a great, playful and uncomplicated way to get real and honest feedback. It all begins with a game…

IMG_20130724_130656

Physical Computing

If you’ve read Chris Anderson’s “The new industrial revolution” you’ll likely be infected with the virus of¬†making. So are we. Chris writes about electronics, laser cutting, 3D printing and how this could lead to a new industrial revolution. It’s about connecting the physcal world to the internet. Expanding your reach to the physical world, which – as you know – is damn big! Among our hybris colleages, we discovered many that also “play” with robots, flying drones or automatic gardening systems. What previously looked like pure play got a serious touch as many of these things can be relevant even in an commerce setting. To explore physical frontends other than “just screens” in combination with ecommerce, we’re currently working on not just one, but already a few protoypes. This blog post will be the first one of (very likely) quite a few others that explore physical computing and “making”. If all works out, we’ll be presenting and talking about our experiences at the CultureTech Conference. Till then, a lot of making and learning has to happen!

Custom PCP board

Before we delve into our first prototype in more details, let me tell you one thing that we’ve learned already: ¬†connecting physical things to the internet, to your computer or to other systems requires a bit of learning, but it has been an extremely rewarding process. Learning how to make a box yourself via a lasercut service is simply awesome and a great skill to learn. Armed with some basic knowledge of electronics, like the Arduino board you quickly realize that pretty much everything is possible. Connecting arcade buttons to a in-store display? Easy. Create a physical keyboard as a frontend for a coupon-generating backend in the cloud? Done. Flying into space? Well…

(very) first prototype

The very first prototype we were working on is a physcial keyboard. The idea is that users have to successfully complete a music challenge to be rewarded with a digital coupon via QR code or NFC. The idea was born at hybris’ customer and partner event 2013. We disdovered how much fun we all had interacting with technology in a physical world (in this case, it was hand gestures via Kinect). We used a simple poster printing service to print a keyboard on a large piece of PVC foil. Next, we had to think how we get the keypresses as input into a computer. Arduino, the low-cost board which can be easily programmed was a natural choice. The communication to the computer was prototyped with a Node.js server running on a Mac that opens a serial connection to the arduino. At the same time, that Node.js server is creating ¬†local websocket to be connected to a local web application (served by Node, too). This allows us to keep the UI in the browser, the logic of the game in JavaScript and use lightning fast connections via a 115200 baud fast serial connection. It took a while to connect the dots, but it does work.

malte malte_sven

Figuring out how to create the sensors was a challenge in itself. I initially prototyped a keyboard with a few pressure-sensistive resistors before Malte¬†had the idea to use simple and cheap copper foil for capacitive sensors¬†(we ordered copper foil from eBay and finance was *not* impressed). He created our own, custom PCB board, send it to a PCB manufacturing service and finally programmed an ATMega chip you control a special capacitive sensing chip. We had to solder all these SMD (=SUPER SMALL) components onto the board, later connect the cables and fine-tune the sensing. The original goal to use the keyboard with your foot was dismissed due to too much jitter in the signals, we’ll now hang the keyboard at a wall and you’ll have to use your hands to operate it.

arduino_cables

A physical frontend, like our physical keyboard is not created overnight. It requires all kind of disciplines to be combined. A diverse set of skills hase to come together to make this happen. I went to a local stitcher and paid her for stitching the PVC foil so the sensors cannot move freely between the top and bottom layer.  Malte and me soldered and I cannot tell you how many times I sat at home and tried out circuits and early prototypes connected via breadboard to the Arduino. For the software, I had to get into Node.js programming which I did via 2 hands-on books on my Kindle. I am still a total beginner when it comes to electronics but the basic knowledge is there and all the rest can be read on the internet. The diverse combination of disciplines is awesome, as it sparks creativity (diversity is a key principle of innovation).

In the end, we figured out that there is most likely and easier way to connect the keyboard to the web application ūüôā We’ve ordered two more keyboard foils and I am pretty confident that we’ll simplify the whole system.

stitcher

 

Now that we have¬†gained all this knowledge, we’re ready for a few more physical frontends. Likely, we’ll be creating gamification ideas using LED buttons, lasers and all kind of sensors. Stay tuned and go ask us questions. The hybris technology group on g+ is a great place to get in contact with us and discuss.

Exploring the physical world and connecting it to the internet was an awesome ride so far and the good news is that we just tapped into it!