Manual Control of a Servo on the Arduino for the Zipwhip TextSpresso Machine


Control a servo without using the Arduino servo library.

The Arduino has a great servo library, but we found while making our TextSpresso machine that the servo library wouldn’t play nice with our stepper motors. We happily connected our stepper motors up to pins 2 through 9 because we were using a stepper motor shield. Then we connected the servos to much higher pin numbers like 26 and 27. To our dismay whenever we sent commands to the steppers, it would cause massive gyrations on the servos.

This had us investigate what was going on and to do that we had to dig under the covers of the servo library. Not many newbies know about the timer capabilities of the Arduino. The servo library hides us from the gory details. Well, it turns out that the servo library relies on a timer callback to get the precision control of the servos. This callback means the Arduino can’t be processing any other code at the exact moment the callback occurs. If the Arduino is busy, then all hell breaks lose on the exact timing of pulses being sent to the servo.

Servos expect a 20 millisecond (ms) pulse. To set the servo at 0 degrees, you send it a high voltage for the 1st ms of the 20 ms pulse. To set the servo at 180 degrees, you send it a high voltage for the 1st 2 ms of the 20 ms pulse. Pretty easy actually. Anywhere in between 1.0 ms and and 2.0 ms gives you different degrees between 0 and 180.

We wrote the sample code below to help you manually control your servo. It just takes a millisecond value and sends it to the servo and then pauses for the remainder of the pulse. I’m actually not sure why the Arduino IDE doesn’t give a manual example like this because it’s so easy to do. We couldn’t find any sample code on the Internet either for “manual servo control on the Arduino”. We hope you find this helpful.

// Manual servo control 
// Copyright 2012 by Zipwhip. 
// You are free to use and modify this code in your own software.

#define SERVO_PIN         39  // Any pin on the Arduino or Mega will work.

void setup()
{
  pinMode(SERVO_PIN, OUTPUT);

}

int lenMicroSecondsOfPeriod = 20 * 1000; // 20 milliseconds (ms)
int lenMicroSecondsOfPulse = 1.8 * 1000; // 1.0 ms is 0 degrees

void loop()
{

 // Servos work by sending a 20 ms pulse.  
 // 1.0 ms at the start of the pulse will turn the servo to the 0 degree position
 // 1.5 ms at the start of the pulse will turn the servo to the 90 degree position 
 // 2.0 ms at the start of the pulse will turn the servo to the 180 degree position 
 // Turn voltage high to start the period and pulse
 digitalWrite(SERVO_PIN, HIGH);

 // Delay for the length of the pulse
 delayMicroseconds(lenMicroSecondsOfPulse);

 // Turn the voltage low for the remainder of the pulse
 digitalWrite(SERVO_PIN, LOW);

 // Delay this loop for the remainder of the period so we don't
 // send the next signal too soon or too late
 delayMicroseconds(lenMicroSecondsOfPeriod - lenMicroSecondsOfPulse); 

}

Manually Sweeping the Servo from 0 to 180 Degrees

Taking the example above further and trying to mimic the Arduino sample sweep code for a servo we produced the test code below. This let us fully test our manual control of the servo. We found that for our HiTec HS-422 servo that the 0 degree position was at about a 0.5 ms pulse and that the full 180 degrees was around a 2.2 ms pulse. You may find something different for your servo but you can adjust the control variables in the code below until you’re happy.

We also found that a pulse length of about 25 ms worked better for our servo. The standard is 20 ms so I’m not surprised we found something a bit longer than the expected pulse worked better. When we went shorter on the pulse like 18 ms we found the servo acted really weird. That’s probably because the voltage was getting applied prior to the servo finishing it’s measurements and that would throw off pulse lengths overall.

// Manually Sweeping the Servo from 0 to 180 Degrees
// Copyright 2012 by Zipwhip.
// You are free to use and modify this code in your own software.

#define SERVO_PIN         39  // 26 or 39. Any pin on the Arduino or Mega will work.

int lenMicroSecondsOfPeriod = 25 * 1000;       // 25 milliseconds (ms). found much better smoothness at 25, not 20 ms.
int lenMicroSecondsOfPulse = 0;                // used in the while loop below
int lenMicroSecondsOfPulseStart = 0.5 * 1000;  // 0 degrees
int lenMicroSecondsOfPulseEnd = 2.2 * 1000;    // 180 degrees
int lenMicroSecondsOfPulseStep = 0.01 * 1000;   // .1 millisecond. That's 200 increments b/w 1.0 and 2.0

void setup()
{
  pinMode(SERVO_PIN, OUTPUT);

  // Setup our start point for our main loop
  lenMicroSecondsOfPulse = lenMicroSecondsOfPulseStart + lenMicroSecondsOfPulseStep;

}

void loop()
{

 // Servos work by sending a 20 ms pulse.
 // 1.0 ms at the start of the pulse will turn the servo to the 0 degree position
 // 1.5 ms at the start of the pulse will turn the servo to the 90 degree position
 // 2.0 ms at the start of the pulse will turn the servo to the 180 degree position

 // Do a while loop starting at our start pulse and incrementing each time thru the loop
 // Stop when we reach our final end point
 while (lenMicroSecondsOfPulse = lenMicroSecondsOfPulseStart)
 {
   // Turn voltage high to start the period and pulse
   digitalWrite(SERVO_PIN, HIGH);

   // Delay for the length of the pulse
   delayMicroseconds(lenMicroSecondsOfPulse);

   // Turn the voltage low for the remainder of the pulse
   digitalWrite(SERVO_PIN, LOW);

   // Delay this loop for the remainder of the period so we don't
   // send the next signal too soon or too late
   delayMicroseconds(lenMicroSecondsOfPeriod - lenMicroSecondsOfPulse); 

   // Increment our pulse
   lenMicroSecondsOfPulse += lenMicroSecondsOfPulseStep;

 }

 // Now reverse the step so we go in the opposite direction
 lenMicroSecondsOfPulseStep = lenMicroSecondsOfPulseStep * -1;
 lenMicroSecondsOfPulse += lenMicroSecondsOfPulseStep;

 // delay for a few seconds and do it all again
 delay(2 * 1000);

}

U.S. Cellular Launches Web To Text Powered By Zipwhip

 

 

We’re very excited to announce our new partnership with U.S. Cellular. This partnership allows all U.S. Cellular customers access to a co-branded version of Zipwhip’s web texting portal. The portal is accessible from the U.S. Cellular website or by going directly to uscellular.com/webtotext. Customers can now send text messages to friends and family on all major U.S. mobile networks.  More of the benefits and details are available in a press release that went out yesterday.

As you watch this video you’ll notice how incredibly fast and easy it is to send a text from you computer–that’s the beauty of U.S. Cellular Web To Text. Cristy Burgan, our VP of Sales, introduces the video. She played a big role in bringing this partnership to life, so it was very fitting to include her in this blog. Congrats to her and the rest of the Zipwhip and U.S. Cellular team members. This is another way that cloud texting is making communication better.

Zipwhip Commercial

 

 

This is our official direct to consumer video. It was created with the help of WINTR. Our goal was to produce a video that was both informative and fun. We hope it also shows that we don’t take ourselves too seriously. At Zipwhip we successfully mix hard work with play. Sometimes that’s not as easy as you might think. Come join us as we bring cloud texting everywhere.

Zipwhip Registration Process

 

 

We thought it was important to demonstrate the Zipwhip registration process. This video covers it all. We know that nobody likes wasting their time with lengthy sign-ups. That’s why ours is so simple. Like the rest of our services we hope you find it easy and uncomplicated.

After watching this video you should be whipping out text messages in no time. It’s cloud texting, pure and simple.

 

Zipwhip Desktop App Installation (PC)

 

 

For today’s blog we take you through the installation process for our desktop application (PC). Towards the end of the video you’ll get to see cloud texting in action. Software developer Greg Mace is the movie star for the day, while social media manager Kelsey Klevenberg took care of the filming and voice work. If you have any questions about our service please send us an email to info@zipwhip.com. We are also active on facebook (facebook.com/zipwhip), and twitter (@zipwhipinc). Thanks for watching and we hope to hear from you soon.

Zipwhip Boss Man Comes Home

 

 

Last Friday we finally got to pick up Boss Man from Metrix: Create Space. He turned out absolutely perfect and we couldn’t be happier with the finished product. Boss Man and two other characters (Androgyny Woman and Library Girl) were created by WINTR for our consumer launch video this past December. We got such a kick out of the characters that we decided to bring them to life. Boss Man is our favorite character, thanks in large part to his gruff demeanor and rad haircut. His mustache is nothing to scoff at either. In order to stay in his good graces we decided that he should be the first one up. Right now he’s mean mugging the entire office and signing pink slips. We hope to have the rest of the characters alongside him soon.

To really attach these characters to the Zipwhip brand we did something unique. Instead of using something boring and standard, we implemented these characters as our stock avatar. Thanks for being a part of this creative process. Let us know what you think of the finished product. We think it’s been well worth the wait.

Boss Man says to get back to work. Turns out he needs you to come in this Saturday, too.

Zipwhip Attends GeekWire Summit

 

 

On Wednesday we joined tech industry luminary Ray Ozzie, Hulu CTO Richard Tom and 500 other industry taste-makers at the GeekWire Summit in downtown Seattle to talk tech and celebrate GeekWire’s 1st birthday. The event featured fireside chats and panels that covered everything from the new iPad, to the future of television. The summit portion of the day went from 1:00-5:00, and was followed by a birthday party that featured a “dev-licious” signature cocktail, killer food (more sliders please) and plenty of lively conversation. Things went from business to pleasure in 60 seconds after the last panel of the day. That’s when Presidents of the United States of America member Dave Dederer decided to serenade the GeekWire team with a spruced up version of Happy Birthday, following a few sips of wine.

The event was a great opportunity to celebrate the success of a fellow startup. More than relying on GeekWire to stay informed on the latest trends and breaking news from our industry, companies like ours benefit a great deal from the exposure the site offers. A story featured on GeekWire provides reach beyond that of many company blogs and generates interest in technology among the greater public. It was pleasure to take part in the celebration. So to John Cook, Todd Bishop, Johnathan Sposato and the rest of the team, Happy Birthday. May there be many more to come.

That Zipwhip Magic Moment

 

 

There’s one thing about Zipwhip that gets our CMO John Larson particularly excited. It’s what he’s been calling “that magic moment.” Actually, he’s been singing about it too. Since we’re all getting tired of him butchering The Drifters hit song “This Magic Moment” we decided to get him on film explaining what he’s talking about. As John recaps in this video, we’ve got a stellar web app and a great tablet app. What really gets him going though, is our desktop app. It will completely change the way you think about text messaging.

That “magic moment” when the text bubble pops right onto your screen will make you wonder why you didn’t download the app sooner. Responding to your incoming texts is as easy as clicking on the text bubble and typing out your response. Whether it’s at work, or when you’re checking out your facebook timeline in the evening, this app allows you to easily unchain text messaging from your mobile device.

Face it, you’ll never be able to fire out text messages on your qwerty or touch screen as fast as Ha Mok-min, the former text messaging world champion. But with the help of Zipwhip’s desktop app and a keyboard, you’ll be whipping out responses in seconds flat. Get your texts in real time and respond in a flash with Zipwhip.

Zipwhip Desktop App (Mac)

 

 

For all of you Mac users that also use an Android phone, this post is for you. Zipwhip developer Jed Hoffman takes you through the installation of our desktop app. The installation time for the app in this video took about a minute, so you should be ready to text across your devices in no time.

Follow

Get every new post delivered to your Inbox.