X-10 Ninja Pan/Tilt Camera Mount Mods

02/27/15 Updates

12/05/09 Updates

Introduction

I have added several cameras to my home control system and plan to add more in the future.  I also added an ASELPRO Video Switcher from National Control Devices.  This is a 16X2 switcher so it gives me plenty of room for expansion.  While the cameras are nice, what I really wanted was the ability to pan and tilt selected cameras to change the view if necessary.  I did quite a bit of searching and most of the pan and tilt mounts were more than I was willing to pay.  I also considered building my own but, while doable, was more packaging than I wanted to mess with.  I finally settled on the Ninja Pan and Tilt Camera Mounts from X-10.  These are relatively inexpensive - I got my last one on eBay for $30 - and appear to be reasonably well built.

The negative to these mounts, at least for me, is that they are controlled by an RF remote and the knock on them is that they have a pretty limited range.  My cameras tend to be spread out and I wanted to control them from my home control system located in the basement so that didn't seem to be a very attractive option.  There are quite a few sites around the internet devoted to hacking these devices but most of them seem to be aimed at increasing the range of the remotes.  There's even a few where someone has replaced the processor in the Ninja with their own processor and custom code.  Since my cameras are all hard-wired, I decided to go with a hard-wired approach for the Ninja as well and convert them to operate an an RS-485 network.  That's what this page is all about.

Ninja Description

As I mentioned previously, there is quite a bit of information available on the web and the most important piece of information I needed was the protocol currently used by the Ninja.  I found the best descriptions on Ed Cheungs comprehensive home automation site (although the data was actually provided by Dennis Hawkins) and Dave Houston's excellent web site.  I also found all of the details of how the Ninja hardware worked on this site.  This last modification consisted of replacing the micrcontroller with an SX controller and changed the Ninja to be controlled over a serial link to a PC.  It also involved a new protocol and several new capabilities.  While I liked this approach, I wanted to control several Ninjas and the distance would just be too great for an RS-232 connection.  So let's get started.

Here are a couple of shots of an unmodified Ninja disassembled to see the guts:

Ninja
Ninja

In the shot on the left you can see the PCB, main processor, the 5 volt regulator under the mess of wiring, and the ribbon cables which supply the power signals to the servos located under the PCB.  In the shot on the right you can see the RF receiver board which is responsible for receiving the RF signal and transmitting it to the main processor.  This board has 3 wires connecting it to the main board - the white and black wires which are +5V and Ground as well as the yellow wire which is the signal to the main processor.  Since we are not using RF, we will remove this board and then design our new interface to fit in the same location using the same wires.  If we do this correctly, the processor will never know the difference.

Before removing the board completely, I cut the wire to get a better look at the signal going to the Ninja processor.  In order to see this, I used my Logic Analyzer from Saleae LLC.  This is a great product at a great price and, if you've never used one before, it's a great tool for understanding whats going on with your circuits and programming.  So when I hooked up the analyzer to the yellow signal wires, here's what I got:

RF Signal

If you look at the detailed protocol documents, you'll see that this matches the described protocol extremely closely.  Now I knew what I had to produce.

Implementation


My choice was to replace the RF board with my own board using an Atmel ATTiny2313 AVR controller.  I've been using Atmel processors for a while now and am very pleased with their performance and, while I can program them in assembler, I usually choose Bascom-AVR.  This is a very nice Basic compiler and produces excellent and fast code.  In order to make sure that I could replicate the Ninja protocol,  I installed a Tiny2313 on my breadboard with an 8.000 mhz resonator, wrote a quick program to generate the requisite signal, and hooked up my logic analyzer.  So here's the result:

AVR Signal


After comparing signals, it was apparent that I would have no trouble generating the correct signals.  To make absolutely sure,  I connected the signal from the AVR to the yellow wire going to the Ninja processor and was very pleased to see the Ninja move as commanded.  Now I was ready for the next step.

The next step was to verify my idea of controlling the Ninja over an RS-485 connection.  I chose a National LTC485 RS485 Interface Transceiver.  This would attach to the UART on the Tiny 2313 and provide RS485 level signals.  I also purchased an inexpensive RS-232 to RS-485 converter to attach to my PC.  When I set this up on my breadboard, after understanding that the TTL level signals on the Tiny2313 are inverted, this also worked great.  I was ready to design my final circuit and printed circuit board.

The circuit ended up being very simple and here's what I ended up with:

schematic

The circuit is composed of the ATTiny2313 processor, the LTC485 Transceiver, a couple of bypass capacitors, an 8.000 mhz resonator, and a 120 ohm resistor.  The 120 ohm resistor is used as a terminating resistor which is required at either end of an RS-485 network and there is a set of solder pads which can be connected, or not, to put the resistor into the circuit.  I chose to add the resonator instead of the internal RC clock source since some of these circuits would be exposed to the weather and the internal resonator can vary enough, especially with temperature, to affect the accuracy of RS-232 transmission.   The circuit was designed using TinyCAD.

Next was the printed circuit board.  I used FreePCB and started with a board outline that  would exactly replace the existing RF board.  So here's the design and the final board:

PCB
PCB

The board fit perfectly and here's the Ninja with the new board installed:

Ninja
Ninja

The only problem I had was that there was no room left on the board for a programming header which I try to put on all of my AVR boards.  Since this was also my first surface mount AVR, I couldn't use a piggy-back type board in a socket to do my programming like I have done in the past.  The solution was a Pomona SOIC Clip.  I had a little problem getting this to work in the beginning but only because excess flux from the my soldering was causing contact problems.  Here's what the clip look like in actual use:

PomonaClip


So now I had my hardware modifications made.  Before I go on to the software, a few more explanations are in order.  The Ninja is powered by a 12 volt, 200 ma, X-10 controlled plug-in supply.  Although rated at 12 volts, the supplies are poorly regulated and the ones I checked actually measured around 22 volts.   The power supply has 3 wires going to the Ninja.  Two wires provide the operating voltage and are active all of the time.  The third wire carries power only when the X-10 address of the power supply is on.  This tells the Ninja that it is being addressed and to respond to move commands.  As far as I can tell, although there are separate commands for each home address (A, B, C,...), the Ninja will respond to any of them if its signal lead is powered.

Software


I decided to make use of the previous fact regarding Ninja commands in order to simplify things so, when I modified the Ninja, I jumpered the power wire to the third wire signal.  In this way, each Ninja would think that it was always on.  Then, in the Tiny 2313,  I save an address for each unit in the onboard EEPROM.  So one unit would be address "1", another address "2", and so on.  Now I could control each unit independently by sending a simple 2 character command sequence.  For example, "1u" to move camera #1 up and "2l" to move camera #2 left.  At the current time, I have implemented left, right, up, down, and center.  The program is written in Bascom-AVR and is very simple.

The main loop looks like this:
Do

'wait for address
Do
Do
Ch = Ischarwaiting()
Loop Until Ch = 1
Get #1 , K
K = K - 48 'convert from ASCII "0"-"9" to 0-9
Loop Until K = Myaddr

'now wait for command
Do
Ch = Ischarwaiting()
Loop Until Ch = 1
Get #1 , K
Cmd = Chr(k)

'this must be for us so see if it matches one of the possible commands
'and set up values for A and B for that command before calling subroutine
'to send command
A = &H0000
Select Case Cmd
Case "l" : A = &H9560 'left
Case "r" : A = &H9661 'right
Case "c" : A = &HA16C 'center
Case "u" : A = &H9762 'up
Case "d" : A = &H9863 'down
Case Else
End Select

B = &H0006 'always

If A <> 0 Then 'we have a valid command
For K = 1 To Rpt
Gosub Sendcmd
Waitms 10
Next Rpt
End If

Loop

and the Sendcmd subroutine looks like this:
'**********Ninja command protocol**********
'The start sequence is a 2.4ms pulse followed by a 1.6ms space. A 1-bit is a
'0.6ms pulse followed by a 1.6ms space and a 0-bit is a 0.6 ms pulse followed
'by a 0.6ms space. Only 20 bits of data are sent. A 0-bit marks the end of
'the frame. Repeats follow with no gap.
'See: http://davehouston.net/cr14a-rf.htm
Sendcmd:
Reset Signal
Waitus 2400
Set Signal
Waitus 2400
Reset Signal
Waitus 1600

For I = 15 To 0 Step -1
Set Signal
Waitus 600
Reset Signal
If A.i = 1 Then
Waitus 1600
Else
Waitus 600
End If
Next I

For I = 3 To 0 Step -1
Set Signal
Waitus 600
Reset Signal
If B.i = 1 Then
Waitus 1600
Else
Waitus 600
End If
Next I

Set Signal
Waitus 600
Reset Signal
Return

End


Last, but not least, I use a stripped down, heavily modified version of a Web Server that I found on Planet Source Code.  The webserver runs on a PC from my basement and, using dynamic DNS, allows me to view and interact with my cameras from virtually anywhere that I have access to a web browser.

What's Next


I already have a second Ninja and am in the process of modifying it as well.  When I finish it, I plan to add additional commands to the processor.  First, the Ninja has the capability of remembering and returning to 4 pre-defined positions.  I will add this to the command processor.  Finally, the Ninja has the capability to continuously scan through all 4 previously defined positions, so I will add this as well.

Here's what the Ninja looks like mounted on the side of my house and working:

Mounted

I'm not sure if anyone's interested but here's a zip file containing the schematic in TinyCAD format, the PCB layout in FreePCB format, and the Bascom-AVR source code.  You could also purchase a circuit board for this project directly from BatchPCB which is part of Spark Fun ElectronicsHere's the direct link to the board.

If you're interested in another approach to camera switching and Ninja hacking that doesn't require RS485 and may even be simpler to implement, take a look at this page.

Thanks for reading and be sure to email me if you have any questions or comments

DOWNLOAD FILES


link_blue16 (1K)

12/05/09 Updates


Well I had to modify a second Ninja to make sure my networking scheme would work as I had planned.  I finished the second unit and installed and wired it and it worked just fine.  At the same time, I upgraded the program to provide the capability to program 4 pre-defined positions and then go to any of those positions as well as to continuously scan all 4 positions.  This seems to work great and I'm happy with it.  You can see the cameras and pan and tilt the Ninjas at my web cam page.  Currently only cameras 1 and 3 have a Ninja mount.  On this public page, I only provide the capability to pan, tilt, and center.  I have another page (not public) with the other programming and scanning capability.  I didn't want to publish that page since I didn't want someone to start a scan and then leave the cameras scanning without my knowledge.  I also updated the zip file above with the latest version of the Ninja firmware.

02/27/15 Updates


After 5 or 6 years one of my Ninja devices stopped working the other day and I thought I should document in somewhere.  The symptom was that the device panned all the way to the hard stop and then wouldn't move from there.  Because the unit was all the way at the end, the screws to disassemble it were not lined up with the access holes so I had to take a dremel to it and carve a few new access holes.  After disassembling and troubleshooting, it appeared that the photo refelective sensor for the pan action failed.  The device senses a refelective strip that's approximately half way around the perimeter and indicates where the device is currently located.  Here's a picture of the sensor on an unmodified unit:

sensor

I had to search around since the unit had no actual part numbers on it but I eventually settled on a LTH209-01 manufactured by LiteOn which was an identical replacement and only cost less then a dollar.  Here's a datasheet for the device.  Once I unsoldered the existing device and soldered in the new one, the Ninja was back to working correctly.

These devices have certainly been very reliable especially considering that one of them has been mounted outside this whole time.


Contact

Home