Introducing Tweet-a-Veyor: An MDR Conveyor Driven by Twitter

Written By: Ric Halvorson

You could say one goal of our marketing department is to use social media to push conveyors. For this blog post, as a nerdy engineer may be inclined, I took that a little too literally. Allow me to introduce the Tweet-a-Veyor – an MDR (Motorized Drive Roller) conveyor driven by tweets:

There are several hurdles you might run into when developing an application like this – having never even sent a tweet before – I’m pretty sure I ran into them all. But if you’re like me and want to learn how to use Twitter to drive a nifty embedded gadget of your own, this might help get you started.

Reading Tweets

Conveyor Driven by TwitterThe first step to any project like this is to register your application with Twitter. It’s a fairly simple process, and can be started here: https://dev.twitter.com/. You sign in with your regular Twitter account and give some information about your application. When you’re registered, you’ll be given two of the four OAuth (Open Authorization) security keys needed to use many of the API’s functions. The remaining two keys will come from the user as he or she authenticates with your application. For simplicity’s sake, I limited myself to one user – me – so I went ahead and generated my user tokens as well. (More information for this method can be found here: Single-user OAuth with Examples)

I wrote a simple program in C# to send the tweet-driven signals to my microcontroller (MCU), an ATmega328P. Obviously, neither C# nor that particular MCU are required to get a device like this up and running; I’m just comfortable with C# and had some spare ATmega328P MCUs. There are also a number of handy .NET libraries available that provide an easier interface between C# and Twitter, such as Twitterizer, which a friend of mine suggested. To start using Twitterizer in your C# application, follow the instructions on the “How Do I?” section of the Twitterizer documentation page. Just be sure you’re using the .NET Framework 4 as your Target Framework as opposed to the .NET Framework 4 Client Profile, and you’ll be good to go.

Twitterizer’s documentation didn’t include a “Here’s How to Drive Conveyors with Tweets” entry (I was surprised, too), so getting useful information from my posts proved to be the biggest challenge in this project. Fortunately, the library’s classes are intuitively organized, so I was able to dig down into a TwitterTimeline object while debugging and find what I needed. The line of code below will give you the text of the most recent tweet in your timeline, assuming you’ve set up your OAuth tokens object properly:

latestTweet = TwitterTimeline.UserTimeline(tokens).ResponseObject[0].Text.ToString();

My code in particular searches the most recent tweet for the word “forward”, “reverse”, or “stop” and sends a serial command to my MCU accordingly. I poll my Twitter timeline for the latest tweet a little more than once every second, which is probably not the most elegant solution, but I haven’t discovered a way to have a new Tweet be automatically recognized. (I’d welcome that in the comments section if any reader knows how.)

Connecting to the Hardware

The details of setting up the interface between the microcontroller and your PC could fill another article, but simply put, you need to open a port in your application corresponding to the device, send serial signals to it, and program your MCU to perform based on those commands. If you’re using a .NET language, the SerialPort class in the System.IO.Ports namespace will get you the basic functionality you need.

Serial Signal Data

The ATmega328P’s Serial Communication Pins

Many microcontrollers contain a peripheral for handling serial data, and the ATmega328 is no different. Some excellent tutorials can be found here regarding how to setup the USART on an AVR microcontroller. It’s up to you how to set up the port parameters and individual commands; you just have to be consistent in your microcontroller firmware and PC application software.

You’ll also likely want a USB-to-Serial converter to make your life easier when connecting to the MCU. The one I used was actually a converter to RS-485, which is a standard for communicating a single signal as a difference in voltage across two wires. Translating that into the logic levels the microcontroller could read necessitated an additional chip.

Sparkfun USB Converter

Using Sparkfun’s USB-to-RS-485 Converter

There are similar products that convert USB directly to a serial signal the microcontroller can automatically read, such as this FT232RL USB to Serial breakout board. That may be the more sensible route, but it keeps you from learning about RS-485, differential pairs, and a clever way to mitigate electrical noise. I might also suggest it doesn’t bestow the same level of nerd cred. There’s always a trade-off.

In either case, with your PC pulling information from Twitter and a successful connection to a microcontroller, you should have your own gadget running in no time! If you have more detailed questions than this post could answer, or if you want to share your own project, please feel free to do so in the comments section.

Special thanks to Jarrod Stormo, software engineer at Interactive Intelligence, for pointing me to Twitterizer and clarifying OAuth.

About The Author

Ric Halvorson wrote one article on this blog.

I'm a mechanical engineer who joined the R&D team here in 2012. I'm consistently presented with opportunities to learn new things, and I've thoroughly enjoyed the challenge.

Tags: , , ,

8 Responses to “Introducing Tweet-a-Veyor: An MDR Conveyor Driven by Twitter”

  1. Brett says:

    Wow, that’s some impressive ingenuity! Good hire, Bastian!

  2. Tony says:

    I like it. Lots of application potential.
    I’ll keep my eye on these Bastian Solution blogs from now on.

  3. Geek says:

    Hey There. I discovered your weblog the use of msn. This is a very neatly written article. I will be sure to bookmark it and come back to read extra of your helpful information. Thank you for the post. I will certainly comeback.

  4. טיסה רומנטית טיסות כיף says:

    Thank you for another informative web site. Where else may just I am getting that kind of info written in such a perfect manner? I have a undertaking that I’m just now running on, and I have been on the look out for such info.

  5. Jennifer says:

    Great, an article that prdeoivs Aussies with excuses to sleep with animal, but enough about dogs and strange sleeping habits I’m not wanting to slow down PROGRESS, I’m wanting to speed it up. What we’ve been having is Technical Advancement, not Progress. They’re very similar, and I can understand how people confuse the two. The cotton gin was Technological Advancement. Progress didn’t start until education wrought change and provided the people displaced by the gin with new, and in almost every single case, better jobs. The first Industrial Revolution brought riches to many, and drudgery and debtor’s prisons for the rest. I’m concerning myself about the rest. I don’t accept that money is King, and economic imperatives only mean things to those who value money over people. I repeat, all we’ve done is ship off our manufacturing jobs to China and India. Bob’s dream of buildings with resources going in one side, and finished products coming out the other is coming true. Too bad all the buildings will be in China and India.Meanwhile, we’ll have an increasing amount of people living on the dole, or rooting like hogs to survive. Neither paints a pretty picture of the future. Those rooting will resent those who do not, and those paying for the dole will resent those who collect. What has progressed?Is the future all Star Trekky, with it’s replicators and apparently free energy? I sure hope so. My fear is that it will look more like Bladerunner, since no-one is biting on my Brave New World and Nineteen Eighty-Four references. And I can’t help but recall that they rarely showed life on Earth, other than from a Starfleet POV. A future where everyone must join a military organization isn’t very progressive! BGrigg

  6. Now we know who the sensible one is here. Great post!

  7. kiranvarma - npeducations says:

    Helpful info. Privileged me I found your website accidentally, with this particular astonished why that accident did not happened earlier! My spouse and i book-marked this.

Add a Comment