Previous posts for this project:
- [CaTS] ForgetMeNot - Index
- [CaTS] ForgetMeNot - Week 0: Project Description
- [CaTS] ForgetMeNot - Week 1: EnOceanPi and Sensors
- [CaTS] ForgetMeNot - Week 2: Elro CoCo and Pi Cam with OpenHAB
- [CaTS] ForgetMeNot - Week 3: Data persistence and charts with OpenHAB
- [CaTS] ForgetMeNot - Week 4: Arduino-OpenHAB communication
- [CaTS] ForgetMeNot - Week 5: Getting familiar with EAGLE
- [CaTS] ForgetMeNot - Week 6: Getting to know the TBS1052B-EDU oscilloscope
- [CaTS] ForgetMeNot - Week 7: First tests with RPiSoC
- [CaTS] ForgetMeNot - Week 7 (2): More testing with RPiSoC
- [CaTS] ForgetMeNot - Week 8: Water dispenser and temperature
- [CaTS] ForgetMeNot - 3D Printing: EnOcean sensor bracket
- [CaTS] ForgetMeNot - 3D Printing: EnOcean rocker switch and magnet holder
- [CaTS] ForgetMeNot - 3D Printing: Food dispenser prototype
- [CaTS] ForgetMeNot - 3D Printing: Weighing scale
- [CaTS] ForgetMeNot - Security: Some basic tips
- [CaTS] ForgetMeNot - Minion: Dave, the gassy minion
Introduction
This week I've been working on detecting which cat eats or drinks and when. This can then be correlated with "how much".
To do this, I've used two SPI RFID readers which would read an RFID tag attached to the cat's collar. This post is about validating the idea by setting up the "cat detection" system and ensuring the data is available for correlation.
RFID
As stated in the introduction, I've decided to go with RFID tags attached to the cat's collar and an RFID reader placed in front of each bowl. The idea is that when the cat stands in front of a bowl to eat or drink, the tag is close enough to the reader in order to detect the cat's presence and identity.
I've used two simple RFID readers that work via SPI.
There are Arduino libraries available, which should make the development process easier
Arduino
For this proof of concept, I've used an Arduino to test the idea of connecting two RFID readers and be able to detect two different cats at the same time.
I've used the library from Miguel Balboa and tested with a single RFID reader first, just to make sure the library works and it is capable of doing what I need.
Using the example sketch, detection and reading the tags UID worked out of the box.
I then proceeded with a modified version of the example sketch to support two RFID readers, sharing all pins except the SS and RST pins.
I connected the second RFID reader, uploaded the new sketch and tried again.
Success! Both RFID readers can report the detected tag and work simultaneously.
As I had done the exercise of passing serial data from Arduino to the Pi (and openHAB) earlier, I already had some knowledge on how to parse this data.
This is why I formatted the data of both RFID readers in a single string, with clear delimiters. This will make it easy to parse the string from openHAB.
In the example below, I tested different scenarios of presence, which seem to work properly:
Sketch
Below you'll find the sketch loaded on the Arduino. It checks for the presence of an RFID tag on both readers and returns the UID if present or "00000000" if not.
openHAB
Having tested the setup with the Arduino, I connected it to the Raspberry Pi via USB. Using minicom, I first verified the Arduino was correctly sending the data the to Pi.
With the data being received by the Pi, I configured openHAB to take in this data. To do this, I defined an item called "Arduino" which makes use of the serial binding.
I also created two additional items in order to display which cat is detected by which RFID reader.
String Arduino "Arduino [%s]" (arduino) {serial="/dev/ttyACM0"} String Arduino_RFID1 "Currently eating [MAP(rfid.map):%s]" String Arduino_RFID2 "Currently drinking [MAP(rfid.map):%s]"
A rule is used to parse the data received via the serial binding. As I put clear delimiters in the string, it was easy to parse the interesting bits of data. The parsed UIDs are then assigned to the proper items defined earlier.
rule "Arduino" when Item Arduino received update then var String ArduinoUpdate = Arduino.state.toString.trim var int rfid1StartsOn = ArduinoUpdate.indexOf("-B1-RFID1:") + "-B1-RFID1:".length var String reading1 = ArduinoUpdate.mid(rfid1StartsOn, ArduinoUpdate.indexOf('-E1-')-rfid1StartsOn) var int rfid2StartsOn = ArduinoUpdate.indexOf("-B2-RFID2:") + "-B2-RFID2:".length var String reading2 = ArduinoUpdate.mid(rfid2StartsOn, ArduinoUpdate.indexOf('-E2-')-rfid2StartsOn) Arduino_RFID1.postUpdate(reading1) Arduino_RFID2.postUpdate(reading2) end
I could convert the UIDs to meaningful names within the rule using "if" statements. I have however opted for the creation of a mapping file which will translate the UIDs to my cats' names. This approach is more simple, requires less code, and works just as well (I hope). Internally, the system will use the UIDs, but when exposing data, the names are used.
00000000=- E3468DF4=Spot 737193F4=Tijger
Collars
I attached the marked RFID tags to the cats' collars and watched how they reacted to this.
One of the cats' first reaction was to try to eat the tag ... after some failed attempts at eating it, the cat seemed OK with the tag hanging there. The other cat was less impressed, but accepted the tag as well.
So now you have finally seen my two test subjects: the striped cat, "Tijger", and the black cat, "Spot". At the end of this challenge, they will be the (lucky ?) owners of a fully automated [CaTS] prototype
Cover
I needed a way to attach the RFID readers properly, so I've made covers to be able to mount and protect them. It has an opening to connect the wires and four mounting holes.
Demo
To demonstrate the functionality, I could have waved the RFID tags manually in front of the readers and show the result in openHAB. As the final solution is meant to work with cats, I set up a small rig and lured one of the cats with some cold milk.
Cats are not actors, they have a will of their own and can't be told what to do. I have however managed to catch one of them on film, demonstrating the system.
This is the footage:
The video demonstrates the mechanism works. It does however require some fine tuning with regards to the positioning of the RFID reader, but I'm satisfied with the result!
I'll be travelling to Rome this week, to attend Maker Faire (is anyone else going ?). This means my next post might be slightly delayed ...
Top Comments