Retransmitting Alarm System State Changes with Raspberry Pi and Arduino
I spotted a post by Lior Hass on Hackaday a little while back where he described his Alarmino project where his alarm system now connects with an Arduino and a custom board to simulate the phone line and interpret Contact-ID protocol. He could then get the system to SMS him in the case of an alarm. In his case, he did this in lieu of using a central monitoring service and it only reported events that would have been sent to the central monitoring service. But suppose someone was using a central monitoring service and just wanted to augment the system with additional potentially detailed and configurable notifications.
System designers often choose to transmit system state through serial protocols. For instance, one such system is described here. Systems like this use a common bus between keypads and the central system with power, ground, and clock and data lines. It would be nice to make use of such system state information on computers like the Raspberry Pi. But one has to be careful not to damage the Pi’s digital inputs as the voltages may be quite a bit higher (e.g. 12V) than the Raspberry Pi can handle. Opto-isolators can be useful in protecting the Raspberry Pi or micro-controllers like the Arduino. Depending on the speeds of the serial signals you’re seeking to monitor, reading them reliably on the Raspberry Pi can be a challenge. For the signals I was seeking to read, while the Raspberry Pi was capable of reading them, reliability was poor even when I gave the process priority because of the possibility of it being pre-empted. And if the serial signal being transmitted has no checksums or other mechanism built in to detect errors, one really can’t afford to miss any parts of the transmission. This is a perfect example of where the Raspberry Pi can work cooperatively with a micro-controller like the Arduino. If the Arduino could do the monitoring and report state changes to the Raspberry Pi over its serial connection, the Pi could handle the more sophisticated signal interpretation and notifications.
In the configuration shown below, the Raspberry Pi both powers and receives serial information from an Arduino Uno and custom shield by USB. The Raspberry Pi is shown with WiFi dongle, case, and low-profile microSD card adapter from Adafruit.
I used an Adafruit Proto Shield to mount the terminal blocks and opto-isolator for the Arduino. I happened to have some TLP-624-4 chips on hand so I used one but I only needed two of the four channels that chip provides (to handle clock and data). In my case, I needed 1K resistors on the input side and actually 180 Ohm pull-ups on the output side to read the signal reliably. In the case of the Arduino, the output pull-ups are to 5v and earlier when I was reading the outputs using the Gpio lines on the Raspberry Pi, they were pulled up to the 3.3v line. The terminal blocks on the left of the photo are to the monitored system.
I added the optional terminal blocks on the right if I wanted to pass the signals through to another device on the bus. The higher voltage red power wire is only there for the purpose of the pass through to other devices. Any two digital lines on the Arduino would suffice for reading the signal — I chose 6 & 7 (actually originally I chose 7 & 8 but realized that I might want to try the shield with the Electric Imp Shield for wireless transmission which uses 8 & 9 by default). I’ve included a Fritzing-generated breadboard and schematic diagram later in the article to make the circuit more clear.
The logic trace below shows an example of data being received from the bus. The SPI protocol analyzer on the Saleae Logic Analyzer does a good job of interpreting the bytes being transmitted (Caution: make sure you know the voltage levels you are testing are within the allowable range for your analyzer). In this case, I took data to be valid on the trailing edge of the clock pulse.