Introduction: Intel Edison IoT - Control Servo Using Accelerometer
Hello everyone, I'm among the lucky guys who received an Intel Edison Board and the Grove IoT Kit. I've spent a lot of time to learn about this new Edison Board, and awesome Arduino coding style. They are really great and compatible with other arduino example library, so you can jump start any project without rewrite the library.
This is a basic example about how to control servo use Freescale 3-axis accelerometer MMA8452Q and put the data to serial in real-time. Let's get started!
Step 1: Collecting the Parts
There are a few stuff you will need in this project:
- Intel Edison
- Edison Arduino Expansion Board
- Grove Base Shield
- Grove Kits Micro Servo
- A 12V power supply or 9V battery to supply enough power to drive the servo
- Freescale MMA8452Q 3-Axis Accelerometer Breakout Board, you can get one in Sparkfun
- 2 * 330R or 1k resistors to support I2C connection
- A BreadBoard, some bus wire and header for wiring stuff
Step 2: Connect Them Together
There are some notes you should know before starting:
- The accelerometer works with 3V3, NOT 5V in Arduino Expansion Board.
- There are two options: Adjust the Expansion Board to 3v3 logic level or Insert the resistors between I2C connection.
- The second option works like this:
MMA8452 <--------> Edison (5V logic level)
VCC ------------------- 3V3 Power Supply
GND ------------------- GND
SCL ------330R------- SCL
SDA ------330R------- SDA
- The MMA8452 use I2C protocol, and it have 2 ID address based on SA0 pin:
1 ---> 0x1D
If you leave SA0 no connect, it will have logic 1, mean 0x1D ID-Address
- The servo motor consumes lots of current, so the USB cable won't supply enough energy to make it run. Therefore, you will need 9V battery or Adapter to supply more power through to J1 DC Jack.
***Ok, that is all you need to know! Let's connect them***
Servo ----> D3 port (Grove Base Shield)
MMA8452 I2C pins (SCL and SDA) ----->330R or 1k resistors ----> SCL and SDA -Digital Ports in expansion board.
MMA8452 VCC ----->3V3 port of the Power Ports.
Step 3: It's Coding Time!
First, make sure that you are already installed all drivers and software, flash the newest Yocto Linus image to Edison, and do a blink example with Arduino Edison Compiler. If not, you must check out the specific getting started guide on intel maker site or the Intel IoT in Instructable, they are very useful for you to get familiar with Edison and Arduino.
Second, go to Sparkfun site and download MMA8452Q driver library. Sparkfun has already built a clear and specific library as well as hook up guide for the accel, so we don't need to build it again.
Here are some links:
MMA8452 overview: https://www.sparkfun.com/products/12756
Hookup Guide: https://learn.sparkfun.com/tutorials/mma8452q-acce...
Next, open the Arduino Edison Compiler and import the library. Go to Sketch/Import Library/Add Library...
Choose the downloaded firmware folder of driver library, and everything is imported. Now go to File/Example/MMA8452Q Basic Example and open it.
Now, try to verify it use a tick symbol on the upper left of the compiler. If nothing go wrong, then we are almost finished. Next, open the ino file attached, copy the code and paste to the basic example windows.
My current code only uses the z-axis value, so when you tilt the accelerometer on the right axis, the servo will rotate accordingly.
For more real-time data viewing, open the arduino Serial Monitor, it's located on the upper right of the compiler. Seem like it's smart enough that you don't have to adjust the baud rate, all you need to open and watch the output data.
Finally, everything is really, now you can compile the code and enjoy the result. It's actually really fun when you see the servo rotate follow to accelerometer movement.
Ok, good luck everyone! If you have trouble, just comment and I will help you asap.
Thanks Intel and Instructable for such a wonderful gift! Thanks audreyObscura for choosing me as a winner. The experience with Edison is really fresh and awesome!
Hi, I have just updated the demo video, enjoy!