RFID chicken name detector - working well!
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/
Detect my chickens by "name" when they visit the nest boxes
Build a web page that reports which lay the most (and least!) eggs
I purchased 2-off 125KHz RFID detector boards for about £20 including postage directly from Seeedstudio
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
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
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 -
ln -s /bin/busybox stty
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
Then when a tag is detected by the coil you see something like
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
tty raw ispeed 9600 ospeed 9600 -F /dev/ttyS0
cat < /dev/ttyS0 > /www/ramdisk/RFID_raw.txt &
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 -
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
(for research - remove this later)
It saves lines of html code for Canvas to create a time plot of the laying in
Having built the html lines it runs
which stitches together a graphic web page
(Read_RFID.bas and the notes below were updated on 13/1/2013)
ON ERROR GOTO ErrorNote
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
If not then append historical data to /var/www/RFID/RFID_text_store.txt
make_page.bas - this is run from within the above program
'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"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<div id="jg_docCanvas" style="position:relative;height:490px;width:800px;"></div>
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.
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!
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.
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