more notes for backup and a bad memory - - -
Chicken detector using thermal infrared PIR
We have some chickens that have learned to eat eggs - but which ones?
We have a webcam display of the nest boxes in the house.
The egg eaters do not enter the nest boxes fully so the RFID ankle fobs may not be detected.
Objective
Use cheap PIR detectors to give a warning in the house and also (later) record a picture of the culprit
First test - first record - Is that cockerel hiding from a rival - or is he the thief?
The HC-SR501 PIR detectors are these from eBay (about £1 from China) :-
An NSLU2 (Slug) runs the RFID system and an HD webcam that views the nest boxes.
The Slug now also runs the (Lesson 1) Python code below to listen to the PIR detectors.
At minimum time delay setting a PIR detector's output goes high for a few seconds when it senses a moving hot body.
The PIR signals connect to a hex inverter chip CD4069 .
The PIR gives 3.3 volts high - plenty to trigger 5 volt CMOS logic.
A PCF8574 eBay module sits on the Slug's i2c bus (this bus is lifted to 5 volts for other devices by a level converter board).
Note that this version of a
PCF8574 eBay module has 1Kohm resistors on the I/O pins. A similar board does not seem to include them.
(It is easy to have the PCF8574 output trying to drive a low CMOS output high if the code is in error)
The 3 PIR detectors drive the PCF8574 board pins 3 4 5 as inputs (via the CD4069).
LEDs are connected to pins 0 1 2 and the PCF8574 drives these pins as outputs,
The software uses these to confirm the detections and the leds can be seen on the webcam - proving that the system is running correctly.
(sorry - you must add the Python tabs).
'i2c_PCF8574_addr_read is a C program to get input like "BYTE = 239"
#!/usr/bin/python import os print "*** Hit CTRL+C to stop ***" address = sys.argv[1] # get the address argument print "address = ", address while True: print "Current date & time " + time.strftime("%c") # get the byte from the received text string (like BYTE = 239) # set the confirmation led s to the same pattern as received # nothing detected time.sleep(2) # lowest 3 bits are the confirmation leds # 255 1111 1111 248 1111 1000 none on |
The Joggler in the kitchen runs the Blassic bassic program Read_RFID.bas in a loop.
It uses wget to pull data from the Slug ramdisk and put it into the Joggler ramdisk.
This code is added to the existing RFID program to grab the PIR data :-
'5b===================================================START PIR 'Grab the PIR data from the Slug and put it in the local ramdisk ' print the PIR detection for testing IF PIRdecimal > 0 THEN GOSUB TalkPIR etc etc then :- SHELL "aplay /home/graham/sounds/online.wav" 'beep sound precedes the announcement IF PIRdecimal = 1 THEN Box$ = " 1" : talk$ = "flite -t " + "' " + Box$ + "'":SHELL talk$ SHELL "amixer -c 0 -- sset Master playback 99% > /dev/null 2>&1" ' restore the volume RETURN |
The C code is similar to these :-
/* 1) set the i2c address of the PCF8574 #include <stdio.h> int i2c; int main(int argc, char** argv) { printf("Error. usage: %s i2c_chip_address\n", argv[0]); } address = atoi(argv[1]); /* address is the first number after the program name */ i2c = open("/dev/i2c/0",O_RDWR); /* open the i2c-bus number 0 */ ioctl(i2c,I2C_SLAVE, address); /* set the address of the chip we will talk to */ buf[0] = 255; read(i2c,buf,1); /* now buf(0) contains the byte of data on the 8 port lines*/ byte = buf[0]; printf("BYTE = %d \n", byte); i2c = close(i2c); |
/* usage :- type with spaces but without the < > */ #include <stdio.h> int i2c; int main(int argc, char** argv) { printf("Error. usage: %s i2c_chip_address byte_to_send_out\n", argv[0]); } /* address is the first number after the program name */ address = atoi(argv[1]); /* the byte to send out to the PC8574 is the second number */ /* place it into the first element of the buf array */ buf[0] = atoi(argv[2]); i2c = open("/dev/i2c/0",O_RDWR); /* open the device on i2c-bus number 0*/ ioctl(i2c,I2C_SLAVE, address); /* set the i2c chip address */ write(i2c,buf,1); /* send the byte */ i2c = close(i2c); } |
- more to come . . . .
Please email me if you want to swap notes