You are viewing an older revision! See the latest version

RFID Tweeter

Intro

This little demo will show you how to trigger a tweet from your mbed, using an RFID tag.

Components needed

Libraries involved

Hardware

Schematic

Here's the (oh-so-good-looking) schematic:

http://mbed.org/media/uploads/donatien/schematic.png

Wiring it up

First of all, plug your mbed into the breadboard. Connect the ground (GND) pin with the breadboard's ground line and the USB power pin ((VU) to the power line.

RFID Reader

  • Connect the 5V (pin 11) and /RST (pin 2) pins to the power line
  • Connect the GND (pin 1) and FS (pin 7) pins to the ground line
  • Finally connect the D0 (pin 9) pin to the p14 pin of the mbed (which is a serial input pin)

Ethernet Socket

Warning

The socket's pinout is valid for this part, if you are using a different one be sure to check if the pinout is not different.

  • Connect the socket's pin 3 to the mbed's RD- pin
  • Connect the socket's pin 1 to the mbed's RD+ pin
  • Connect the socket's pin 4 to the mbed's TD- pin
  • Connect the socket's pin 6 to the mbed's TD+ pin

Finally...

Plug a network cable into the socket, and connect your mbed to your computer.

Software

The full program is available here, and below for reference. http://mbed.org/users/donatien/programs/TweetRFID

Code

// RFID Tweeter

#include "mbed.h"
#include "ID12RFID.h"
#include "EthernetNetIf.h"
#include "HTTPClient.h"

#define TWITTER_USER "donatiengarnier"
#define TWITTER_PASSWORD "myverysecurepassword"

#define IDS_COUNT 3
const int ids_list[IDS_COUNT] = {89481809, 89481810, 89481811};
const char* names_list[IDS_COUNT] = {"Donatien", "Simon", "Dan"};

EthernetNetIf ethernet;
HTTPClient twitter;

ID12RFID rfid(p14);
DigitalOut tag_present(LED1);
DigitalOut tweet_ok(LED4);

int main() {
  ethernet.setup();
  twitter.basicAuth(TWITTER_USER, TWITTER_PASSWORD);

  while(true) {
    int id = rfid.read();
    tag_present = 1;
    for(int i = 0; i < IDS_COUNT; i++) {
      if (ids_list[i] == id) {
        HTTPMap msg;
        msg["status"] = names_list[i];
        msg["status"] += " just arrived home!";
        HTTPResult r = twitter.post("http://twitter.com/statuses/update.xml", msg, NULL);
        tweet_ok = !r;
      }
    }
    tag_present = 0;
  }
}

Editing the program

  • First of all, replace the TWITTER_USER and TWITTER_PASSWORD macros with your account's parameters
  • Change the registered tag ids and their owners in the ids_list and names_list tables (and update the IDS_COUNT define accordingly)
  • Finally you can personalize the message (msg["status"]) a bit...

Finally

Compile the program and download it to your mbed. Press the reset button, and you're done!


All wikipages