At work we have AMQ height adjustable desks. They use a controller some corporate type probably thought was really cool. It is that one on the left and it screws into the underside of the desk. The problem with it is the capacitive touch buttons. They are unreliable when you want them to work and they often react when you just get near them with your chair causing most people in the office here to set their desks to one position and then unplug them. They get away with this because they appear to work in a demo and when they sell them to businesses and they are cheaper than the competition that probably makes a better controller. The rest of the desk is fine so I decided to make my own controller.
To start off I need to figure out how the controller works. To do this I used a Analog Discovery USB scope. It was easily the best tool I’ve bought for my own electronics hobbies and is worth double what they charge for it. The software is awesome and works on mac, linux, and windows. There is even an API so you can use it with your own code. Using a breadboard and a couple Ethernet jack breakouts I made a way to sniff the lines driven by the controller. With this I drew this diagram:
If you are smarter than me you will see a problem with this diagram that I discover later. However you can see that it is relatively simple. Each of the buttons pull one or two of the lines to ground when then are pressed. Also, I figured out how the number display works. It is just a UART line. Here are my notes on how the UART works:
When the numbers are displayed there are short bursts of 4 8-bit values sent over the UART line. When height number is displayed it sends two 1’s and then the height value as a integer. This then translates to a fractional value by dividing by 10. Secondly, when you press the memory button to set memory it sends 1, 6, a bit that corresponds to the memory setting, and then 0. Lastly there is an error state that displays A,S,and most of a F on the screen. This happens when the encoder has lost it’s place and you have to run the thing all the way to the bottom for it to zero again. Here is an image from the software for the logic analyzer showing a burst on the serial line:
One thing I really like about the Waveforms software is how easy the cursors are. Expensive rack mounted test equipment usually doesn’t have this useful of cursors. My next step was selecting the components I was going to use to build my controller. Here is what I chose (some of these were used because they were parts I had on hand from previous projects):
To build this here are the tools I used:
First I drilled out and test fitted my face plate on my enclosure. Here is a few pictures of that process:
I then cutout the space for the display by drilling the corners and then cutting the plastic with a razor blade. If I were to do this again I’d use a smaller drill bit for the corners and cut using a dremmel. Doing it this way took a long time.For the buttons I soldered stranded wire onto the leads and crimped female 0.1 headers onto the other side. Here are some pictures of that process:
One of my buttons was too close to the pcb mounting point to screw on the nut. I used an appropriate sized drill bit to cut it away:
With all that done the next step was to prototype the circuit and program the microcontroler. To do this I used a breadboard and prototyping wires. Here is where I learned I missed a few things before. For one the power connection. Before I was a bit confused about pin 3 and 4 which both seemed to be connected to power. By using the scope I discovered that pin 4 was only high when the other controller was plugged it however it was at a slightly smaller voltage than pin 3 which was always high. This lead me to believe that the controller was pulling it high to let to motor controller know it was plugged in. I tied it to the high line using a resistor and all seemed to work on the power front.
Next I discovered that if I wired up the buttons as I had drawn in my first diagram current would flow back through the lines I’d connected together and buttons that pulled only one line low (up and down) no longer worked after I connected those lines together on one side of some of the memory set buttons. To fix this I used electronic one way valves, aka diodes with a circuit like this:
This worked great and I was on to programming the microcontroler. This proved to be a bit challenging because the trinket I had chosen was so limited in pins and codespace. Because it did not have a hardware UART I had to use the SoftwareSerial library. For controlling the LED display I used the I2C connection and Adafruit’s library. However, because of the limited code-space to get my binary to fit I had to comment out parts of Adafruit’s library that was for the matrix displays. Here is the code I wrote for the trinket:
Here is the final circuits and a picture of my prototyping setup:
Once I proved that it all worked I soldered it all together on a prototyping board and assembled the box. To mount the pcb I used hot glue to secure some standoffs. I also used hot glue to secure the display in it’s spot.
Lastly I cutout the spot for the ethernet jack with a dremel and screwed the whole thing together. I now use it on my desk at work and it is awesome.