Mails Here!
Updates and Status
<section begin=updates />*After testing and trying many different things I'm afraid that the range on the normal Xbee modules just isn't strong enough for my application. I will probably be getting some Xbee pro modules soon to try and compensate for this. The device's operation is just hit and miss with the current setup. Ive tried implementing several solutions to compensate for this but all of which were unacceptable. Im putting this project on hold until my next Mouser purchase when I can get the better modules. --Paul 15:13, 6 September 2007 (EDT)<section end=updates /> <section begin=oldnews />
- I have been working on this project for three days straight and have been making good progress. I finally have something im willing to test in the field and will be doing so for the next week. --Paul 17:42, 30 August 2007 (EDT)
- Exciting week! My Mails Here! board arrived on sat and my new Aoyue 2702 soldering station arrived Monday. If im happy with the outcome of this new board ill upload the layout to the Mails Here! page. I have some work ahead of me now! --Paul 14:12, 14 August 2007 (EDT)
- My newly designed boards have finally arrived. I was working on porting the code over to the old PIC to the new one (18f8722 to a 18f2550) when I came across a lot of ways I could do things more efficiently so its ending up like a total rewrite than a port, which is fine. Will post some of the good stuff once I`m happy with it. --Paul 22:37, 6 July 2007 (EDT)
- I ordered the revision 3 of the PCB. This version includes a Dallas/Maxim DS1305 RTC with super capacitor backup. I wanted to include it sense day one but the whole project being such a large step for me I decided against it until now. Now I will be able to implement a RTC easer as well as a full calender. I cant wait for the boards to arrive so I can get back into it. --Paul 18:11, 1 August 2007 (EDT)
<section end=oldnews />
Abstract
Mails Here! is a mail notification system consisting of two parts. The first is a device that is placed in a mail box with a photo sensor, button, and RF transmitter/receiver. When light is detected in the box, the MCU makes a decision at to whether it's mail being delivered or retrieved based on the following actions and transmits the corresponding signal to the base station. The base station is the second part of the system which consists of an LCD, 4 button navigation panel and an RF transmitter/receiver. When a signal is received from the mailbox device, the MCU inside the base station records the activity and updates the display. The MCU also keeps a log of the previous 7 days which can be displayed on the LCD using the navigation buttons.
Functions
Mail box device
After the user powers up the device by installing a 9V battery, a 30 second timer will activate allowing them to place the device in the mailbox. After 30 seconds, the device will go into power saving mode and stay there until light is detected. If the amount of light detected is above the threshold that is set by the potentiometer, the device will wake up and begin a 30 second timer. If the button on the device is pressed within this 30 second time frame, the device will assume its someone retrieving the mail and transmit a "Mail Retrieved" code to the base station. The device then provides a 20 second grade period for the user to close the mail box so the device can reset and await another delivery. If no button is pressed within the 30 second time frame, the device will assume its the mail being delivered and will transmit a "Mail Delivered" code to the base station.
Parts
Circuits
Code
Mail box device
I wrote code for the mail box device in assembly. Intended to run on a PIC16F88. [1]
The main code:
;**********************************************************************
; *
; Filename: main.asm *
; Date: 04/28/07 *
; File Version: 1.0 *
; *
; Author: Paul Mac *
; *
; *
; *
;**********************************************************************
; *
; Files required: P16F88.INC *
; *
; *
; *
;**********************************************************************
; *
; Operation: After setup the PIC is put into sleep. A change *
; in the comparator will bring the PIC out of sleep.Light hits the *
; photocell the comparator will wakeup the PIC and it will start a 30 *
; second timer. If the button is pressed within the time limit a *
; "mail picked up" routine will be executed. If not after the timer *
; is up a "mail delivered" routine will be executed. After both *
; routines the PIC will reset and return to sleep *
; *
;**********************************************************************
list p=16f88, r=HEX ; list directive to define processor
#include <p16F88.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_OFF & _WDT_OFF & _INTRC_CLKOUT
__CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
;***** VARIABLE DEFINITIONS ********************************************
cblock 0x20
d1,d2,d3,d4
txbyte,rxbyte
buttonloopdelay, ticker, repeat
endc
w_temp EQU 0x71 ; variable used for context saving
status_temp EQU 0x72 ; variable used for context saving
pclath_temp EQU 0x73 ; variable used for context saving
;**********************************************************************
ORG 0x000 ; processor reset vector
goto Initialize ; go to beginning of program
; *** isr ************************************************************
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move STATUS register into W register
movwf status_temp ; save off contents of STATUS register
movf PCLATH,W ; move PCLATH register into W register
movwf pclath_temp ; save off contents of PCLATH register
; ISR here
movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
;**********************************************************************
Initialize
BANKSEL OSCCON
movlw b'01110000' ;select 8-MHz INTOSC clock
movwf OSCCON
Stable
BANKSEL OSCCON
btfss OSCCON,IOFS ;INTOSC frequency stable?
goto Stable ;no, loop
ADcon
movlw b'00000110' ;PORTA 1 and 2 are analog inputs
BANKSEL ANSEL
movwf ANSEL
Comparator
movlw b'00000101' ;Setup Comparator, C1 disabled, C2 enabled Vin- is RA1 Vin+ is RA2 output is RA4
BANKSEL CMCON
movwf CMCON
Ports
movlw b'00000110' ;PORTA RA1 and RA2 are comparator inputs, RA0 is LED output
BANKSEL TRISA
movwf TRISA
movlw b'010000101' ;PORTB RB7:NA RB6:CTS, Input RB5:UartTX, output RB4:RTS, output RB3:Xbee Reset, output RB2:UartRX, Input RB1:Xbee Sleep, Output RB0:Button, Input
BANKSEL TRISB
movwf TRISB
Uartsetup
movlw d'51' ;set UART to 9.6k baud
BANKSEL SPBRG
movwf SPBRG
movlw b'00100100' ;setup UARTtx for 8bit-Asynchronous high baud
BANKSEL TXSTA
movwf TXSTA
movlw b'10010000' ;setup UARTrx for enable serial port and continuous receive 8bit
BANKSEL RCSTA
movwf RCSTA
Interrupts
movlw b'01000000' ;Enable PIE and intrupt
BANKSEL INTCON
movwf INTCON
movlw b'0010000' ;Enable RCIE Ausart receive interrupt
BANKSEL PIE1
movwf PIE1
movlw b'01000000' ;Enable Comparator Interrupt
BANKSEL PIE2
movwf PIE2
GetReady
BANKSEL PORTA
BSF PORTB,3 ;Make sure the xbee reset pin is high
; clrf PORTA
; clrf PORTB
call Delay_20s ;20 second delay till device is active UNCOMMENT WHEN DONE TESTING
movlw '0'
call Uart_out
; Program entry *******************************************************
Main
BANKSEL PORTA
bcf PORTA,0 ;turn the button loop light off if its on
bsf PORTB,1 ;Put the Xbee to sleep
SLEEP ;gooo to sleeppppp
nop ;Prefetched before sleep
BANKSEL CMCON
btfss CMCON,C2OUT
goto Runlight
BANKSEL PIR1
btfsc PIR1,TXIF
goto RxInt
goto Main
Runlight
movlw D'6' ;default value is 255 for with a 6 ticker for ~30 second delay
BANKSEL ticker
movwf ticker
movlw D'255' ;default value is 255 for with a 6 ticker for ~30 second delay
BANKSEL buttonloopdelay
movwf buttonloopdelay
Buttonloop
BANKSEL PORTA
movlw b'00000001' ;toggle RA0, AHH YUP, GOOD TO GO
xorwf PORTA,f
btfss PORTB,0 ;Test to see if button has been pressed.
goto Pickup ; If so branch
call Buttonloopdelay ;delay 20ms then poll again.
BANKSEL buttonloopdelay
decfsz buttonloopdelay,f ;decrement a 255 count delay
goto Buttonloop
decfsz ticker,f
goto Buttonloop
movlw 'M' ;Tx the MAILS HERE code
BANKSEL txbyte
movwf txbyte
call Uart_out
goto Main
Pickup
movlw 'R' ;Tx the MAILS RETRIEVED code
movwf txbyte
call Uart_out
;20s delay to let the user gtfo without rerunning the thing
;40000000 cycles
movlw 0x6D
movwf d1
movlw 0x32
movwf d2
movlw 0x58
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0
goto Main
Uart_out
BANKSEL PORTB
bcf PORTB,1 ; wake the xbee up
CTS
btfsc PORTB,6 ; make sure shes up and ready
goto CTS ; If she isent, loop till she is.
BANKSEL PIR1
WaitTX
btfss PIR1,TXIF ;test to see if the Tx buffer is full
goto WaitTX
BANKSEL txbyte
movf txbyte ;moves the byte to be transmitted to the W reg
BANKSEL TXREG
movwf TXREG ;Tx the sucker
WaitTX_2
call Buttonloopdelay ; delay before doing it again
btfss PIR1,TXIF
goto WaitTX_2
BANKSEL txbyte
movf txbyte
BANKSEL TXREG
movwf TXREG
return
RxInt
movf RCREG,w
movwf rxbyte ;put the recived byte in the rxbyte register
goto Main
Clr_Int ;Clr the intruppt flags
clrf PIR1
clrf PIR2
return
Delay_20s
;39999993 cycles
movlw 0x6C
movwf d1
movlw 0x32
movwf d2
movlw 0x58
movwf d3
Delay_20s_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_20s_0
;3 cycles
goto $+1
nop
;4 cycles (including call)
return
Buttonloopdelay ; 20ms delay with 8Mhz clock
;39993 cycles
movlw 0x3E
movwf d1
movlw 0x20
movwf d2
Buttonloop_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Buttonloop_0
;3 cycles
goto $+1
nop
;4 cycles (including call)
return
; initialize eeprom locations
ORG 0x2100
DE 0x00, 0x01, 0x02, 0x03
END
Base station
I'm currently rewriting my code for the base station as I port it over to a 18F2550. Will post it when I'm satisfied with it.
PCB layout
PCB layout of the mailbox device:
PCB layout of the base station: I have made some changes to the PCB and am waiting for my prototype to arrive to test it before posting it.
Pictures
-
The mailbox system tucked away in its weather proof case.
-
Overview of the mailbox board with its case.
-
Closeup of the mailbox board with its case.