Jun 03

Using the GY80 10DOF module with Arduino

I recently purchased a 10 Degrees of Freedom (10DOF) sensor from eBay called a GY-80. It’s a compact module that includes a gyroscope, accelerometer, digital compass, and a barometric pressure / temperature sensor.

GY80 Top Labeled

All of the individual sensors are accessible over I2C so you only need 4 connections to access all those sensors. SDA, SCL, Ground and VCC (you can use 3.3v or 5v).

GY80 Bottom Labeled

Each component can be accessed individually. I was planning on doing a write-up on each one, but it looks like Bildr beat me to the punch as they already have a great tutorial for each component. Here are the links to the datasheets and tutorials for each component:

L3G4200D

3 axis gyroscope from ST
L3G4200D Datasheet
Bildr Tutorial: http://bildr.org/2011/06/l3g4200d-arduino/

ADXL345

3 axis accelerometer from Analog Devices
ADXL345 Datasheet
Bildr Tutorial: http://bildr.org/2011/03/adxl345-arduino/

HMC5883L

3 axis digital compass from Honeywell
HMC5883L Datasheet
Bildr Tutorial: http://bildr.org/2012/02/hmc5883l_arduino/

BMP085

Barometric Pressure and Temperature Sensor from Bosch
BMP085 Datasheet
Bildr Tutorial: http://bildr.org/2011/06/bmp085-arduino/

Next steps

This module can be used individually as the articles above show but they can also be monitored at the same time. MultiWii is an open source software project that is used as the brain of multi-copter projects. The code runs on Arduino and it is compatible with a large variety of sensors (the GY80 being one of them). It does require a little tinkering to get it working properly. I’ll document the process in a future article. Also since this module works over I2C it can also be accessed using a Raspberry Pi.

Jan 05

How to Build a BlinkM Clone

The original BlinkM was the first in a series of I2C controlled RGB LEDs from ThingM. It’s easy to integrate into projects and control with anything that supports I2C. At its base level it is an ATtiny45 and a Piranha RGB LED. For anyone who wants a simple, elegantly packaged component I would highly recommend that you buy one of these. I am more of a do it yourselfer so I decided to build my own out of parts I had laying around.

Build

Here are materials I used in my project:

  • ATtiny chip (I’ll be using the ATtiny85 but an ATtiny45 will work too)
  • RGB LED with a Common Cathode
  • 3 resistors
  • Jumper cables

This project is very tolerant to variation and you can really do it however you see fit. If you don’t have an RGB LED and want to use individual LEDs that will work. If you have a common anode LED instead of a common cathode LED you will need to use a different firmware package but it’ll work as well. The point is to have fun and learn.

Firmware upload

The firmware for the BlinkM is currently closed source. The reason for this is that the patent for controlling RGB LEDs over I2C is owned by Phillips/NXP. ThingM has licensed these patents to produce their line of BlinkM products. You’ll notice that the license for the BlinkM firmware states that it is for personal use only, not for internal business purposes or for commercial gain. Keep this in mind if you would like to produce a product using this technology.

Because this is closed source it led to the development of an open source alternative: CyzRgb. This firmware is fairly similar to the BlinkM firmware with some additions (like a logarithmic curve for more accurate colors) and some subtractions (it only has 1 script as opposed to the 18 BlinkM has). Some people have noted it’s buggier but if you want to make something that is physically different from the BlinkM (like using a common Anode LED) you will need to use it.

ThingM offers a simple way to upload the firmware through which is called the ReflashBlinkM. This program can be used with the ArduinoISP and can be used to load raw ATtiny chips with their firmware. To do this you’ll need to setup the Arduino ISP wiring as described in the Run Arduino Code on an ATtiny article. Once it’s all connected then start the ReflashBlinkM program:

  1. Select the BlinkM firmware to use (if you are using CyzRgb, select custom and pick the .HEX file from their binary zip file)
  2. Click ArduinoISP on Arduino
  3. Select the port your Arduino is currently on
  4. Click Reflash

ReflashBlinkM using ArduinoISP

It will show the progress in the text at the bottom. When it says “Reflashing Done!” you now are ready to use your ATTiny as a BlinkM.

NOTE: This worked for me when using my UNO but not with my Leonardo.

Wiring

Now that you have an ATtiny programed with the BlinkM (or CyzRgb) firmware it’s time to build the rest of the circuit around it. It’s important to make sure the correct colors are attached to each pin. This circuit can run on 5v or 3.3v.

ATTiny blinkm clone wiring

Use

Now that it’s all hooked up it’s time to test it out. When you first power up a newly flashed BlinkM it will run a default script which flashes through white, red, green, blue and off then starts again.

ThingM offers a package of example code which includes a handful of sketches for controlling it with Arduino. I found it easier to just extract the whole zip file to my Arduino Sketch folder. The all-in-one sketch for controlling everything the BlinkM does is BlinkMTester. With it you can use the serial monitor in ArduinoIDE to view a menu of options. If you are using ArduinoIDE 1.0.2 this will not work, it functions properly on version 1.0.3. If you are using a Leonardo you need to send “?” to get the menu to show up.

BlinkMTester Arduino Sketch Menu

Next Steps

This is an easy component to work with on its own or to integrate into existing products. I created mine as an exploration of the product but I foresee it having functionality in future projects where a diagnostic light is needed. In addition, since it works over I2C it’s compatible with a variety of development boards including the Raspberry Pi.

Sep 24

Arduino Controlled Garage Door – Part 3

In my last 2 articles I put together a prototype for a garage door control that I could power on and off through a website I developed. I plugged everything in and let it sit on my desk connected to the network for about a week. Every once in a while I’d load up the webpage and click the buttons to make sure I heard the relays switch on then off.  I wanted to give it a chance to “burn in” and ensure it would work over a long period of time. Once I felt comfortable it was working as expected it was time to do the physical installation.

My hope is that this will be the first project in a series that will automate several functions in my house. Because of this concept I decided to place the Arduino in a centralized location in my house and run a cable to the garage that I could use for 5v power and I2C communication.

Materials

  • Power Supply
  • 1 Low voltage wall box
  • 1 Blank Wall Plate
  • 2 Buttons
  • Any cable with 4 or more wires (I used Cat5)
  • Pull up resistors
  • Heat shrink tubing

Buttons

I wanted to keep the look of this project neat so instead of reusing the old buttons that controlled my garage doors I decided to build my own. I cut a hole in the wall and installed a low voltage wall box mounted sideways. I used 2 concave arcade style buttons from Sparkfun for the physical buttons. To tie it all together I got a blank plastic wall plate and drilled a hole for each button.

Garage Door Button Plate

I secured the module to the top of the buttons and secured it with zip ties. I wanted to make sure that even if the relay module or the Arduino were unusable that I would still be able to open the garage doors so I wired the buttons in as manual overrides. In this configuration either the buttons or the relay can complete the circuit. I used heat shrink tubing to cover all the exposed copper.

Garage Door Button Wiring

Once everything was wired up I put the whole module into the wall and screwed the cover on. You can’t see it in the picture but when the module is powered up you can see the green light from the LED shining through the white plate.

Finished Garage Button Plate

Last Minute Tweak

Once it was all finished I plugged the other end of the cable into my Arduino and loaded up the website and… nothing. I pressed both buttons, neither worked. I figured I must have mixed up the I2C wires for SDA and SCL so I swapped them and still nothing. I have worked pretty extensively with I2C and I remembered that many people recommend pull up resistors on the SDA and SCL lines but in my experience it was never needed because the Arduino has integrated pull up resistors for these pins. I decided to try it anyway and added a pair of 4.6k resistors to the Arduino side of the I2C circuit and tested the web buttons again. This time it worked. It seems that the pull up resistors in the Arduino are better suited for short runs.

Next Steps

The next step in this process is for the Arduino to detect or show the status of the garage doors. This also allows for future expansion of the system by adding other I2C devices. A temperature sensor would be an easy addition and may be a future project.

Aug 28

Arduino Controlled Garage Door – Part 2

In part 1 of this series I showed how I created an I2C relay module to open and close my garage doors. Now that I have the ability to do this, the next step is to make the user interface for this accessible from a laptop, smart phone, etc. To do this we will create a simple Arduino Ethernet based web page with a button for each door.

The libraries to run an Arduino Ethernet or Ethernet shield are included in the Arduino IDE. The sample sketches include the ability to tweet, telnet, and create a webpage. The example for a web server is fairly simple, however for projects that require more sophistication there is the Webduino library that adds the ability to use AJAX buttons, sliders, and login authentication on websites directly on an Arduino. Because this will eventually be a more complex system this is the method we’ll use in this project.

Materials

  • Arduino Ethernet or Ethernet shield (must be Wiznet-based)
  • relay control module
  • Webduino library

Installing Webduino

Before we can get started we need to install the Webduino library into the Arduino IDE.

  • Download the latest version from https://github.com/sirleech/Webduino/zipball/master
  • Create a “libraries” folder inside your Arduino Sketch folder
  • Extract the zip file to the libraries folder you just created.
  • Open Arduino program and paste the code below
  • Upload the below code to Arduino

The below code is a modified version of the buzzer sketch. It creates 2 buttons, one for each garage door. In this example the web interface can be reached at http://192.168.1.20/garage (this may need to be modified for your network).

// Garage Control Code
// Fork Robotics 2012
// Based on Webduino buzzer sketch

#include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"
#include

//randomly generated MAC http://sqa.fyicenter.com/Online_Test_Tools/Test_MAC_Address_Generator.php
static uint8_t mac[] = { 0x7C, 0xD5, 0x93, 0xAE, 0xB2, 0x76 };
static uint8_t ip[] = { 192, 168, 1, 20 };

#define PREFIX "/garage"
WebServer webserver(PREFIX, 80);

int garageToggle=0;
int ATtinyAddress=0x26;

void garageCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  if (type == WebServer::POST)
  {
    bool repeat;
    char name[16], value[16];
    do
    {
      repeat = server.readPOSTparam(name, 16, value, 16);
      if (strcmp(name, "garage") == 0)
      {
        garageToggle = strtoul(value, NULL, 10);
      }
    } while (repeat);
    server.httpSeeOther(PREFIX);
    return;
  }

  server.httpSuccess();
  if (type == WebServer::GET)
  {
    /* store the HTML in program memory using the P macro */
    P(message) =
      "Webduino Garage Example"
""
 "</pre>
<h1>Pick a Door</h1>
<pre>
"
 "</pre>
<form action="/garage" method="POST">"
 "
<button name="garage" value="1">Left Door</button>

"
 "
<button name="garage" value="2">Right Door</button>

"
 "</form>
<pre>
";
    server.printP(message);
  }
}

void setup()
{
  Wire.begin();
  Ethernet.begin(mac, ip);
  webserver.setDefaultCommand(&garageCmd);
  webserver.begin();
}

void loop()
{
  webserver.processConnection();
  if (garageToggle > 0){
    RelaySwitch(ATtinyAddress,garageToggle);
    garageToggle=0;
  }
}

void RelaySwitch(byte device,byte data) {
  Wire.beginTransmission(device);
  Wire.write(data);
  Wire.endTransmission();
}

The Result

The result of this code is a simple webpage with 2 buttons. When a button is clicked it will send the appropriate I2C command to the module created in part 1.

Next steps

While the Webduino library makes great strides towards making the Arduino Webserver more useable it is still limited in what it can do. I just recently got my hands on a Raspberry Pi; it has I2C, integrated Ethernet, a real time OS and Apache. Eventually the main control mechanism could be a switched over to this platform but for the moment the next step is to install this into my house.