VCR Remote Control via SMS
Imagine it, it’s 3:15 on a weekday afternoon and you’ve just realised you’ve forgotten to set the video to tape ‘Pet Rescue’. Usually you would be condemned to an afternoon of misery and disappointment, knowing you had no heartwarming cute animal stories to come home to. But not any more. Below I describe a simple interface between a T28 mobile phone (ME) and Matsui VX770 VCR to allow remote recording of programmes.
Block Diagram
The heart of the interface, the only active component, is a PIC16x84 microcontroller.
It has 1024 bytes of program/data memory, 36 bytes of static RAM and 64 bytes of non-volatile RAM. In this application it runs at 6 MHz, giving an instruction cycle of 0.67us (1.5 MIPS), plenty to handle the low data rates of the two interfaces. Read all about the awsome power of the 16×84 here.
Two interfaces are required, one to the ME to send and receive SMS messages and one to the VCR to control channel selection and recording. These are described below.
VCR interface
This is a simple interface as we can exploit the existing infra-red (IR) remote control interface which will provide all the necessary functions via a single wire link. The VCR’s IR sensor output was disconnected and replaced with a link to one of the pins of the PIC.
Then the required IR codes were captured by connecting a photosensor to the microphone input of a PC soundcard and recording the appropriate transmissions from the remote control.
An example of the captured output is shown below. You can hear the output by downloading matsui_ir_code-stop.wav.
The high/low transitions are clearly visible and easily interpreted. There is an initial long high level followed by a low. This is to allow the IR receiver’s automatic gain control to adjust to the signal level. There then follows 32 bits of data forming 4 bytes. A binary ‘0’ is coded as a high->low pulse of equal mark-space ratio while a ‘1’ is coded with a mark-space ratio of about 3.5. The waveform above is the ‘STOP’ command and represents the bitstream:
1 |
00000001 11011110 11101000 00010111 |
i.e. the bytes:
1 2 |
10000000 01111011 00010111 11101000 0x80 0x7B 0x17 0xE8 |
Studying other codes showed that the first two bytes, 0x80 and 0x7B, are constant and are probably manufacturer/model specific. The next byte is the command code and the final byte is its complement, probably for error checking.
The timing of the stream was easily measured from the captured waveform and code to emulate the stream developed. In addition to the control line, a power sense line was connected to the VCR’s power LED so the PIC knows if it has to turn the VCR on before recording can commence. The bitstreams of the other functions are given in matsui_codes.txt.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
;*********************** ; IR control codes ; (6MHz CLOCK = 0.6us instruction cycle) ; IR_CODE_PWR EQU B'00010011' IR_CODE_STOP EQU B'00010111' IR_CODE_REC EQU B'00010101' ; the channel codes are simply ; the desired channel number (0-9) ; define some macros for controlling the IR line ; handy because some systems use inverted levels (as in this case) IR_ON MACRO BCF PORTA,IR_DATA ENDM IR_OFF MACRO BSF PORTA,IR_DATA ENDM WAIT MACRO DELAY MOVLW DELAY CALL WWAIT ENDM ; SEND A BYTE (IN W) OVER IR IR_BYTE MOVWF TX_BYTE ; for each bit MOVLW 8 MOVWF LOOP IRB1 IR_ON ; THE ON TIME IS THE SAME FOR 1'S AND 0'S WAIT 10 IR_OFF MOVLW 13 ;'zero' delay BTFSC TX_BYTE,0 ; test LSB of TX byte MOVLW 35 ; 'one' delay CALL WWAIT RRF TX_BYTE,F ; get next bit DECFSZ LOOP,F GOTO IRB1 RETURN ; *************************** IR_TX ; transmit the byte in W in Matsui IR format MOVWF CD_BYTE MOVWF CP_BYTE ; prepare the complement of the required code COMF CP_BYTE,F ; time critical - stop interrupts MOVLW B'00000000' MOVWF INTCON ; IR intro - sets up IR receiver's agc IR_ON WAIT 248 WAIT 248 WAIT 248 WAIT 248 IR_OFF WAIT 248 WAIT 248 ; now send the (manufacturers?) 2-byte code MOVLW B'10000000' CALL IR_BYTE MOVLW B'01111011' CALL IR_BYTE ; now send the required code MOVF CD_BYTE,W CALL IR_BYTE ; and its complement MOVF CP_BYTE,W CALL IR_BYTE ; all done - just one last pulse IR_ON WAIT 10 IR_OFF ; bring back interrupts MOVLW B'10100000' MOVWF INTCON RETURN ; *************************** |
ME interface
A standard data connector was used to connect the PIC to the ME.
The link is 9600 bps, 8 data bits, 1 stop bit, no parity. This is implemented in the PIC by simple toggling of the data lines in a similar way to the IR emulator. An example of the byte 0x30 (00110000) which represents the character ‘0’ is given below.
The use of a TTL-RS232 level converter is not required as both the PIC and the ME use TTL levels. The Ericsson T28 supports most of the AT command set as described in GSM specification 07.05 (freely available from
www.etsi.org) which allows the reception and transmission of SMS messages from external equipment (TE). This page explains the message formats very nicely.
A typical exchange between ME and TE is given below. The ‘<‘ and ‘>’ characters show direction of data (> = from TE to ME, < = ME to TE), # denotes a comment.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# AT commands from ETSI TS 100 585 V7.0.1 (1999-07) # GSM 07.05 version 7.0.1 # This session with an Ericsson T28 World # Software version 010314 0130 prgCXC125206 #Setup: >AT # ping the ME <OK >AT+CNMI=3,1,2,0 # setup message format/incoming SMS notification <OK >AT+CPMS="ME","ME","ME" # store all messages on ME <+CPMS: 10,15,10,15,10,15 # messages/max messages in each location specified above < <OK #Incoming SMS: #Message: 'REC4': <+CMTI: "ME",11 # message stored on ME at index 11 >AT+CMGR=11 # request read from index 11 <+CMGR: 0,,23 <0791448720003023040C9144773081631500002060521115954004D2E29006 <OK #Delete message from ME: >AT+CMGD=11 # request delete from index 11 <OK |
The format of the received SMS message string is as follows:
1 2 |
SMSC address Originating number TP-PID/TP-DCS Date Time Message length 7-bit encoded message 'REC4' 07914 48720003023 040C91 447730816315 0000 206052 11159540 04 D2E29006 |
You can see that it is a simple matter to check the originating number corresponds to your phone so no one else can seize control of your VCR! In my implementation it also provides a convienient point to synchronise to when looking for the start of the message. The parser on the PIC is quite unintelligent so any deviation from the format described above will result in failure.
Code was developed in the PIC to configure the ME and listen for incoming messages. Two SMS commands were implemented, record and stop. The command formats are as follows:
1 RECn - start recording on channel 'n'
1 STOP - stop recording
In addition, the PIC echoes the message back to the sender to confirm reception using the send message (+CMGS) command. The ME uses a Vodafone Pay As You Talk SIM which has the advantage of no line rental. Even if it runs out of calling credit it can still receive messages okay, but will no longer be able to acknowledge received commands. If you have an old mobile phone lying around then this system will just cost you the price of a PIC (about £2.50). Once these interfaces are implemented, some simple logic holds it all together to control channel selection and recording functions. The PIC ASM code can be downloaded here.
Results:
Aww!