RFID chicken name detector - working well - NB! see notes at bottom of page!
These are my backup project notes - please email me if interested
or you may like to debate the Chicken RFID issues here ->http://612237.xobor.com/
Objective
Detect my chickens by "name" when they visit the nest boxes.
Build a web page that reports which lay the most (and least!) eggs.
Store a webcam photo of the detected laying bird.
Later - detect all visits to the feeder to ensure that any bird that does not seem
to have visited a nest box does indeed have a working RFID tag.
Method
I purchased 2-off 125KHz RFID detector boards for about £20 including postage directly from Seeedstudio
http://www.seeedstudio.com/wiki/Electronic_brick_-_125Khz_RFID_Card_Reader
Google for ELB149C5M to find many sites that stock this board.
This feeds data to an nslu2 (Slug) running Linux image nslu2_51_110124_image.bin on internal memory alone - normally used for HD webcams as here
(NB there is no need to have an Arduino - just the module above and a device to read the RS232)
I would like to find some 125KHz RFID chicken leg rings (they are sold wholesale - please email me if you find a retail source)
At present I am using the common (and cheap) ready programmed key fob tags from eBay (picture above) fastened with a nylon tie (see below).
In the UK 10 of these can be bought for £1.75 total including postage from China - how do they do that ?!
When a chicken is in the nest box I get 14 or more detections of its code an the RFID card per minute - even if they seem to sit still.
And a bird will often sit for 30 to 60 minutes.
RFID Module RS232
The RFID card RS232 is TTL level (the output terminal is normally held at 5V - data pulses the line to zero volts)
Combine RS232 from several modules
At present I have 3 nest boxes and 3 detector modules but may build more.
I am planning to have a sensor on the feeder and perhaps one at the exit to the outdoor compound to prove that the chickens that do not lay still have a working RFID leg-fob.
From chips in my stock I built a (crude) 6 input logic combiner.
All inputs are normally high and so is the output. A negative pulse on any input will appear at the output.
The CMOS runs at 3.3 volts obtained from the Slug. The CMOS can handle the 5 volt input pulses from the RFID cards directly.
(Note - since a laying chicken gives many detector outputs it might have been possible to multiplex several detector coils to one detector)
TTL-RS232 combiner circuit - NB! viewed from the solder side!
The detector coil
The small coil that comes with the kit is not big enough for this job.
I wound a coil on a circular plywood former of 6 inches diameter sandwiched between two square plywood boards as large as the nest box base
I tuned it on a 'scope and found it needed about 41 turns of wire.
I used standard plastic covered solid core connecting wire since there is plenty of room and I had a big reel in stock from an electronics sale.
The scope saw 42 volts peak to peak on the coil - more than the 38 volts from the small coil.
I think the Q was so high that I could have tuned it to give more but I believe that may have caused the signal to be more than the chip could handle.
At up to 5 cm distance the coil detects a horizontal key fob tag at the centre and a vertical tag over the windings.
Just the job for the random orientations of the chicken's leg while laying!
Code Overview - if you are new to all this please start at my home page
The nslu2 (Slug) detects the TTL level RS232 on it's serial port.
A bash script saves the raw data strings to a folder that is in RAM (to save the FLASH memory).
A Joggler on the home LAN runs a Blassic basic program to process the data.
It includes a bash code segment that uses wget to fetch the data from the ramdisk in the Slug website.
Canvas (OK in Firefox) displays the time graph on a web page
Slug code
Silence the terminal chatter
The Slug serial port normally outputs data from the Linux kernel.
To remove this "terminal chatter" after the boot messages modify /etc/inittab to -
::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K stop
# tts/0::askfirst:/bin/ash --login
# ttyS0::askfirst:/bin/ash --login
# tty1::askfirst:/bin/ash --login
Raw mode
It is necessary to change the baud rate to 9600 and to place the port in "raw" mode
(it then accepts characters one by one - no need to press RETURN at the end of a line)
To do this you need to have stty (part of busybox) loaded - this has to be done when the kernel is compiled
- I recompiled to add stty then simply replaced busybox on my slug to avoid setting it up all over again
- but then you need to let the slug know how to find stty -
cd /bin
ln -s /bin/busybox stty
Then do
stty raw ispeed 9600 ospeed 9600 -F /dev/ttyS0
see if it worked with
stty speed -F /dev/ttyS0
Then connect the RFID module to the Slug serial port as above
and in a terminal a
session type
cat /dev/ttyS0
Then when a tag is detected by the coil you see something like
00003CFBBA7D
Some early code
- see the bottom of the page for the latest updated set of files
I save the raw data to ramdisk (mounted as a folder under /www) on a Slug.
I wget that data using a Joggler also on the home LAN.
The bash script on the Slug
#!/bin/sh # /www/RFID/save_ID_to_ramdisk.shs tty raw ispeed 9600 ospeed 9600 -F /dev/ttyS0 cat < /dev/ttyS0 > /www/ramdisk/RFID_raw.txt & catPid=$! RFID_raw=`cat /www/ramdisk/RFID_raw.txt` echo $RFID_raw |
The above script ran on one Slug but not on two others with identical firmware.
I could send data to a ZTerm terminal on the iMac but not receive data on the Slug.
I loaded minicom onto the Slug and that would send data both ways.
After minicom was removed (kill -9 `pidof minicom`)the code above worked on all three Slugs.
So how to start then stop minicom from a bash script before running save_ID_to_ramdisk.sh ?
This works -
#!/bin/sh kill -9 `pidof minicom` |
null 2>&1 sends the output screen from minicom to a dump and & allows the script to proceed to the next line (thank you Google!)
(There must be better ways to do this (?) but it runs)
The Blassic basic on the Joggler to work on the data
UNDER CONSTRUCTION !!!!!!!
I see many null characters and then the detected code at the end.
Blassic basic to the rescue
blassic /var/www/RFID/Read_RFID.bas grabs the raw data using
wget -O /var/www/ramdisk/RFID_raw.txt 192.168.0.53:8053/ramdisk/RFID_raw.txt
it saves all detections to
/var/www/ramdisk/Pixel_Records.txt
(for research - remove this later)
It saves lines of html code for Canvas to create a time plot of the laying in
/var/www/RFID/RFID_text_store.txt
Having built the html lines it runs
/var/www/RFID/Build_RFID_webpage/make_page.bas
which stitches together a graphic web page
(Read_RFID.bas and the notes below were updated on 13/1/2013)
#! /usr/sbin/blassic ' /var/www/RFID/Read_RFID.bas '1 '2 '3 '4 PAUSE 2000 '5 '6 '7 '8 '9 '10 LABEL SkipPrint '11 ON ERROR GOTO ErrorNote PAUSE 1000 '12
LABEL GetChickenPixelLine 'modify this list as needed 'make the dots for the Canvas graphic
' build files of bird laying histories ' Zero the data for a new day |
Read_RFID.bas program notes - see numbers inset above Slug attached to the RFID detectors at 192.168.0.53 ----------------------------------------------------------------------- Read_RFID.bas program flow 3 4 5 7 8 9 10 If not then append historical data to /var/www/RFID/RFID_text_store.txt 11 12 |
make_page.bas - this is run from within the above program
#!/usr/sbin/blassic '/var/www/RFID/Build_RFID_webpage/make_page.bas 'the creation process is slow so save to a temp file then copy fast 'DATE$ is mm-dd-yyyy 'create the real file name for today PRINT "file_name_for_today$ ", file_name_for_today$ ' remove the previous save and dump error message 'top of page 'build the middle of the page from stored RFID readings - add the presence bars 'above bottom of page 'now finish the html SHELL "cp /var/www/RFID/Build_RFID_webpage/temp_RFID_plot.html /var/www/RFID/Build_RFID_webpage/"+file_name_for_today$ SHELL "cp /var/www/RFID/Build_RFID_webpage/temp_RFID_plot.html /var/www/RFID/Build_RFID_webpage/today_RFID_plot.html" SYSTEM |
webpage_top.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <head> <div id="jg_docCanvas" style="position:relative;height:490px;width:800px;"></div> <script type="text/javascript"> jg_doc.setStroke(2); jg_doc.setStroke(4); |
webpage_above_bottom.html
} |
webpage_bottom.html
</body> </html> |
The 19/1/2013 Results - Kitchen Joggler display |
I noticed from the HD nest-box web cam (connected to the nslu2 that also reads the RFID boards) that if a bird just visits the nest box but does not sit there may or may not be a detection. However, once they start to settle to lay the detections come every five seconds or so - and can do so for 30 minutes. |
13/1/2013
NB this failed - see lower down page for update
I have experimented with a new way of attaching the (cheap eBay) RFID key fobs to the chickens
The tags have indents at each side and 2 holes are drilled in each - I do not think that this lets water into the coil void.
A 9mm wide nylon tie is wired to the fob via the holes. The wires are tinned copper and are soldered on the side away from the chicken's leg.
(If the tie had been simply inserted into the hole in the end of the fob the point of the fob might have pressed on the leg.)
I was a bit concerned that the copper wire formed a shorted loop - but it is at a right angle to the detector loop and seems to have no bad effect.
The ties are tightened to a very loose fit round the chicken's ankle before the excess band is clipped off (The foot is much wider than the ankle).
The fobs are hollow and very light and birds show no sign of any discomfort. They happily layed eggs as usual on the day after the fitting!
A coloured band is attached to the other leg (I purchased some made from 10 different colours of plastic)
Below - Webcam view of the key-fob RFID tags in use, these are either of yellow or blue plastic - beware of some on eBay that are larger and thinner.
I lifted the birds from their perches in the dark with the aid of a small torch wrapped in card so as to make a very small spot of light.
If a cloth is draped round the bird's head and upper body they lie still on a bench while the tags are fitted.
Comments? email me
"But this is where I always lay!" |
"For goodness sake! - push girl, push!! or - Play fair! I booked the 12:15 slot! |
Tips! 1) Now I keep about 5 inches of deep litter on the concrete floor. It never smells and can be used as compost when the oak leaves fall again. 2)
|
|
NB!
|
Three in one box - White has just layed on top of Brown |
White leaves - and then the egg falls and breaks |
I have seen four birds in one box (and two boxes empty) and two more waiting to go in - bird brains?
The most recent set of files used in my Joggler are here - place them in the server web site root - eg in /var/www/RFID/
update 29/5/2013 - BEWARE some of the copper wire links to the RFID fobs are being pecked off - I will try small nylon ties next
13 March 2014
I fitted the birds with Chinese RFID tags like these :-
- but found that they had to be very much closer to the detection coils.
I now use a 7.5 mm nylon tie round the birds ankle.
A smaller nylon tie (as wide as the hole in the key fob) joins the key fob (as above) to the larger tie.
The fob is a bit exposed but they are very cheap and easy to replace.
The ties are loose and the birds seem to not notice them - I will be surprised if they can destroy the nylon.
It all seems to work now !