The Eject-A-Bed: Part 1
June 25, 2013 2 Comments
Some people are born to greatness. Some people have greatness thrust upon them. Some people find greatness on Craig’s List. A couple of months ago, I was killing some time searching for mechanical devices on Craig’s List when I ran into this:
So of course I picked it up and put it into the garage. An interesting side note is that the seller got it at the UNC surplus warehouse. Apparently, you can get really good deals on used medical and university equipment there. I need to add it to my Christmas shopping rotation.
My daughter, Sonoma, and I first wanted to understand how the controller works. We first thought that the controller used PWM so we hooked up our Oscilloscope to the two metal wires that travel from the controller to the bed’s motor. We moved the controller up and down but no signal was being recorded. Sonoma then noticed that the “wire” was a hollow tube. Taking a wild guess, we blew down the pipe. Sure enough, that made the bed move
So now we had to figure out how the controller moved air up and down the pipe. We opened the controller and there is a small bellow that attaches to the pipe. Press the controller on 1 side and air is forced down the pipe, press the controller on the other side and air is sucked up the pipe.
So we batted around ideas about how to push air up and down the pipe – ideas included using a small electric air compressor, some kind of mechanical pressure plate, etc… We then decided to try and gluing a servo to the switch and controlling the movement that way. However, we couldn’t figure how to attach the servo to the existing plastic switch. So we decided to build our own switch – we used my son’s erector set to create the harness for the bellows
and we are now into the coding piece of it.
Step one was to confirm that I hooked up my scope to the Netduino correctly. I modified the Blinky code (Netduino equiv to ‘Hello World’ to add a pulse on one of the output ports:
Sure enough, I am seeing the pulse.
I then wired PWM class to see if the output was what I expected:
and sure enough I am getting a pulse every 20 milliseconds with a length of 1 millisecond.
A word to the wise, do NOT use the Cpu.PWMChannel enum as it does not fire – use PWMChannels enum
So now it is a question of hooking this up to my servo. It is a standard RC plan servo. I have no idea about the period, pulse and/or duty cycle of this specific servo but it seems that there is a standard in the RC community that periods are 20 MS (as confirmed when I worked on the RC lawnmower) and the pulses are:
- 1 MS = 180 to one direction
- 1.5 MS = Top Dead Center
- 2.0 MS 180 to the other direction
The problem is that the period is an uint – so I can’t set it to 1.5 MS. I then learned about Duty Cycles where I can pass in a double and have the period adjust. Basically:
- 1 MS = Duty Cycle of 5%
- 1.5 MS = Duty Cycle of 7.5%
- 2.0 MS = Duty Cycle of 10%
- So to test this, I set up the PWM to have a 20 MS period, a 1 MS duration, and a Duty Cycle of 1.0.
The problem is that this does not work. If you use the period/duration constructor for the PWM class, you cannot set the DutyCycle property and get the desired effect. What you have to do with that constructor is to use the duration property. So to get the non-integral units, I needed to change the PWM.ScaleFactor to Microseconds and start thinking of things in terms of thousands. Once I did that, I spent some time figuring out the TDC and the max left and right:
I then hooked up the servo to the bellow controller:
and set up a program to activate the bellows for 2 seconds: