Posts tonen met het label RFID-12. Alle posts tonen
Posts tonen met het label RFID-12. Alle posts tonen

maandag 13 augustus 2012

The tweeting cat IV


The system is now finished. The full version displayed above, and the twitter stream is available at NephthysCat. Of course she's not wearing the harness all the time so don't expect constant updates. The battery life is longer than the calculated 7.1 hours, which was to be expected because I didn't expect the components to run at their maximum rating the whole time.

I solved the charging of the LiPoly battery by cutting a USB cable in half and using that power for the input of the charger circuit. On the Playstation 2 I have the cu command (cu -s 9600 -l /dev/ttyUSB0 dir >entry) run in a local terminal. This will cause all the incoming messages to appear in the file "entry":

4F0088E27B5E
4F00889B0F53
4F00890403C1
4F00890403C1
4F00889BD78B
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088EE88A1
4F0088EE88A1
4F0088EE88A1

A simple pike program keeps track of which line we are in this file, and continues from there. If an entry gets added beyond that, it will a message read from a file called "tweets". Here is the code:

/* NEPH.PIKE - Allow Nephthys to tweet */
/* 110812: Started programming */

#pike 7.0

#include

mapping(string:string) tweets = ([]);

int main() {
  string data = Stdio.read_file("tweets");
  string *lines = data/"\n";
  for(int i=0;i
    tweets["0"+lines[i]]=lines[i+1];
    tweets["1"+lines[i]]=lines[i+2];
  }
  string current = Stdio.read_file("current");
  int where = (int)current;
  write("Last index: " + where + "\n");
  int count = 0;
  while(1) {
    string entries = Stdio.read_file("entry");
    lines = entries/"\n";
    if((sizeof(lines)-1)>where) {
      tweet(lines[where++]);
      Stdio.write_file("current", "" + where);
      write("New index: " + where + "\n");
      count = 0;
    } else {
      if (count++ > 60) {
        //tweet("Purr!");
      }
    }
    write("Sleeping...\n");
    sleep(60);
  }
}

void tweet(string text) {
  text-="\r";
  text-="\n";
  string last = text[(sizeof(text)-2)..(sizeof(text)-1)];
  string code = "" + random(2) + last;
  string message = tweets[code];
  if (!message) {
    message = "Cat error " + code;
  }
  write("Tweeting: " + message + "\n");
  system("/usr/local/bin/ttyter -keyf=nephthys -status='" + message + "'");
}


The code doesn't filter out duplicates, but fortunately twitter does this for you. It uses the ttyter command line to send the tweets. The tweets file contains the last two digits of the tag, followed by two possible tweet lines which it can choose from at random. For example:

32
Nom, nom, nom!
Oops, I dropped a piece of food. No worries, Miuty will get it.
A1
This is smelly tasty food from the top shelf.
This food is better because it is higher.

The tags are placed at crucial positions in the house, for example near the cat toy.


There are obviously many improvements that can be added, and more tags that can be spread around the house.

maandag 6 augustus 2012

The tweeting cat II

I managed to get the XBee USB explorer hooked up to my playstation 2 linux system, and it only crashed twice so far. Playstation 2 linux runs 2.2.1 (a very old release). Since 2.2.1 doesn't have USB and the Playstation 2 uses USB for the keyboard and mouse, they ported the 2.2.18 USB modules, but the driver for the XBee USB explorer only exists in 2.2.19 and up, so I had to port that back too. It required me to manually edit usbserial.c (as this contains PS2 specific code) but the other files could just be copied from 2.2.20 and 2.2.19.

The next step was to build the circuit. I saw a good option on bildr blog which I decided to persue:
I also added a 330 Ohm resistor and a LED to the ID-12, to make sure you could see when a tag was successfully scanned. The positive lead of the LED goes to the pin, for those that are wondering. As a battery supply I used four rechargeable NiMH AAA batteries, which give a voltage between 5.6 and 4.9 volt, I initially used a diode to drop the voltage by 0.7V to ensure that I didn't send more than 5.4V to the ID-12 (the XBee is protected by the 3.3V converter).

Then I had to attach it to a cat harness, for which I used electrical tape and band aid tape (to not bother the skin of the cat with the electronics). This is what Nephthys looks like with the system on:


You can see the LED and the RFID-12 on this picture.


And on this picture you can see the battery pack with the XBee attached to the back.

The system worked once, but the cat decided not to go after any of the RFID tags I put around the house and the system stopped working after an hour. After a lot of debugging I discovered this was because the batteries had run out of power (oddly enough the RFID-12 and the XBee still work, and the LED still blinks, but the RFID-12 refuses to send any data to the XBee, which made for a lot of trouble debugging. So I'll try the system without a diode next, which would give the system a lot more battery life.

As you can imagine, I'll put tags on the food bowls, the water bowls, the favorite sitting spots of the cat, maybe the litter box, but also the other cat, Miuty:


Of course, I'll also have to set up a twitter account and create a way to translate the RFID numbers into tweets. But it will all happen.

woensdag 25 juli 2012

Cat tweeter, order placed

Hi - your order is ready to ship!

SparkFun Electronics Order

Date Packed: 07/25/2012

Shipping Method: UPS Ground

Items shipping in this package:

Breakout Board for XBee Module x1
Logic Level Converter x1
Voltage Regulator - 3.3V x1
2mm 10pin XBee Socket x4
RFID Tag - 125kHz (retail pack of 5) x2
RFID Reader ID-12 (125 kHz) x1
RFID Reader Breakout x1
XBee 1mW Chip Antenna - Series 1 (802.15.4) x2
XBee Explorer USB x1

This is for my new tweeting cat project. The plan is to hook up the RFID Reader ID-12 to the XBee Series 1, and send data to the other XBee Series one which is hooked up using the XBee Explorer USB to my playstation 2, which will send tweets based on where the cat is. I'll put the RFID tags on the various places that the cat goes (drinks, litter box, other cat, cat toy, sleeping place, doorway, food bowl, et cetera). Biggest concern are the batteries, but I'll figure out what to do with that. Most likely it will need a harness to avoid the cat being entangled in wires, and to avoid the RFID chip getting into the water bowl.