The Eject-A-Bed: Part 1

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:

image

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

image

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.

image

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

WP_20130616_003

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:

  1. OutputPort port = new OutputPort(Pins.GPIO_PIN_D5,false);
  2. OutputPort led = new OutputPort(Pins.ONBOARD_LED,false);
  3. while (true)
  4. {
  5.     port.Write(true);
  6.     led.Write(true);
  7.     Thread.Sleep(250);
  8.     port.Write(false);
  9.     led.Write(false);
  10.     Thread.Sleep(250);
  11. }

 

Sure enough, I am seeing the pulse.

WP_20130619_001

I then wired PWM class to see if the output was what I expected:

  1. private static void ActivateServo()
  2. {
  3.     uint period = 20;
  4.     uint duration = 1;
  5.  
  6.     PWM servo = new PWM(PWMChannels.PWM_PIN_D5, period, duration, PWM.ScaleFactor.Milliseconds, false);
  7.     servo.Start();
  8.  
  9.     Thread.Sleep(Timeout.Infinite);
  10.  
  11. }

 

and sure enough I am getting a pulse every 20 milliseconds with a length of 1 millisecond.

WP_20130619_003

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. 
    1. uint period = 20;
    2. uint duration = 1;
    3.  
    4. PWM servo = new PWM(PWMChannels.PWM_PIN_D5, period, duration, PWM.ScaleFactor.Milliseconds, false);
    5. servo.Start();
    6.  
    7. while (true)
    8. {
    9.     servo.DutyCycle = 1;
    10. }

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:

  1.  
  2. private static void TestServoFullRange()
  3. {
  4.     uint period = 20000;
  5.     uint duration = 1500;
  6.  
  7.     PWM servo = new PWM(PWMChannels.PWM_PIN_D5, period, duration, PWM.ScaleFactor.Microseconds, false);
  8.     servo.Start();
  9.     
  10.     Thread.Sleep(2000);
  11.     servo.Duration = 2500;
  12.     Thread.Sleep(3000);
  13.     servo.Duration = 500;
  14.     Thread.Sleep(3000);
  15.     servo.Duration = 1500;
  16. }

 

I then hooked up the servo to the bellow controller:

 

WP_20130619_004

 

and set up a program to activate the bellows for 2 seconds:

  1. private static void ActivateServoForBellows()
  2. {
  3.     uint period = 20000;
  4.     uint duration = 1500;
  5.  
  6.     PWM servo = new PWM(PWMChannels.PWM_PIN_D5, period, duration, PWM.ScaleFactor.Microseconds, false);
  7.     servo.Start();
  8.     Thread.Sleep(2000);
  9.     
  10.     InputPort button = new InputPort(Pins.ONBOARD_BTN, false, Port.ResistorMode.Disabled);
  11.  
  12.     Int32 numberOfPresses = 0;
  13.  
  14.     while (true)
  15.     {
  16.         if (button.Read())
  17.         {
  18.             if (numberOfPresses < 10)
  19.             {
  20.                 servo.Duration = 1250;
  21.                 Thread.Sleep(2000);
  22.                 servo.Duration = 1500;
  23.                 numberOfPresses++;
  24.             }
  25.         }
  26.     }
  27. }

and success.

Advertisements

2 Responses to The Eject-A-Bed: Part 1

  1. Pingback: Eject-a-Bed Aborts Sweet Dreams

  2. Hello Jamie,

    My name is David Aspinall and I am a reporter for Caters News, an international press agency based in the UK (www.catersnews.com)

    I have seen your eject-a-bed on Neatarama and I was hoping to do a story on it for the national press over here.

    If you’re interested in working with me can you get in touch on davidaspinall@catersnews.com.

    I look forward to hearing from you.

    Kind regards,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: