Adding an accelerometer to SmartQ V7

Oct 12, 2010   #accelerometer  #kxps5  #mod  #smartq  #v7 

* Originally written as a guide at SmartQ MID Unofficial Wiki, hence the DIY-type text. *

One of the features the SmartQ Q/V series lack is an accelerometer. This project will be about adding one to the SmartQ V7. I’m sure this mod can be adapted to the others models/series as well, but unfortunately, I own just the V7.

Preparation

For this project, we gonna need to build a board containing the accelerometer itself and some passive components. This means some skill with soldering, PCB making and a place to buy the needed material.

If you don’t want to build the board (for every word “board” on this guide, I’m refering to the accelerometer board), you can use a pre-built breakout board for various accelerometer models. Just check if it has a digital, I²C serial interface. If you go this way, however, I can’t provide detailed instructions, but you can use the guide as a reference.

Please remember: as with every hardware mod, be VERY CAREFUL with your device. I can’t stress on how many ways to toast your device exist. If you do not feel confident about doing this, leave it alone.

Theory

This board is based around a Kionix KXPS5-3157, Tri-axis, 3g, with digital (I²C or SPI) and Analog Outputs, LGA14 package accelerometer. It provides mechanical and electrical base to the IC, supplying power, signal and configuration. It also exposes an interface of the signal pins to the SmartQ V7. In this case, the I²C bus will be used.

The I²C pins will be connected to SmartQ’s I²C bus, where the audio codec (WM8987) is also connected for receiving commands. Since the I²C bus is multi-device capable, we can add new devices to it until the limit of 112 devices or the maximum bus capacitance of 400 pF.

The accelerometer board

The first step will be building the accelerometer board. Since the accelerometer is a SMD part (LGA-14), I’ve done all the board with SMD parts. You can use non-SMD parts if you want, but you’ve got to hook small and thin wires to KXPS5’s pads. Also, by using SMD parts you can fit it nicely inside SmartQ.

You’ll need the following parts:

  • 1 x Kionix KXPS5-3157 Accelerometer
  • 1 x 1 μF 0805 Ceramic Capacitor
  • 3 x 0.01 μF 0805 Ceramic Capacitor
  • 1 x 0.1 μF 0805 Ceramic Capacitor
  • 1 x 10 kΩ 0805 Resistor

It’s a pretty default setup for operating the KXPS5, taken from its datasheet. Freefall/Motion interrupt has been disabled and the address pin is held low, making the device’s address as “0x18″.

Get here the eagle board and schematics. I’ve used the LIS302DL library from here. Since it’s also a LGA-14 part, it would be compatible with KXPS5. The pinout are not the same though, so don’t pay attention to the pins name in the schematics! They’re wrong! Also, since I wouldn’t print the silk layer, it isn’t beautifully placed, but it is there just as a reference to locating the parts on the board.

You can solder it with a soldering iron or by “reflowing”. I suggest doing the reflow process, as you get a nicer result. Google it for details.

Once your board is done, move on.

Installing the hardware

First step here is to tear your SmartQ V7 apart.

Once your device is open, we need to locate 4 special points in the mainboard: +3.3V, GND, SDA and SCL. The +3.3V and GND are your power supply, while SDA and SCL are the I²C bus. We know that the audio codec WM8987 is controlled by SmartQ’s I²C bus, so, by looking at the chip’s datasheet we discover the pins. They are connected to the resistors marked with “103” (10k), as shown in the picture. Solder accordingly with your KXPS5 board I²C pads.

For power, they can be easily found in the mainboard, as their name is printed on it. Check the picture for the points: GND is the one near the speaker and 3.3V near the charger connector. As you noticed, the 3.3V point is the farthest point. An alternative point would be the AT88SC0104C power pin. Refer to the picture.

Do not worry about that black wire near the LCD flat cable: it’s my serial port wiring.

Installing the software

After installing the hardware, we need to test the board and its communication with your SmartQ. First of all, we need to install the package i2c-tools to play around. Open your terminal and type:

1
sudo apt-get install i2c-tools

Now we have tools to detect devices on the bus, dump its content, read and write its registers. Let’s start by probing the bus:

1
sudo i2cdetect -y i2c-gpio4

You should see the chars “UU” at address 0x41 (the audio codec chip) and the number 18 at address 0x18. If there is no device at address 0x18, the accelerometer board couldn’t be found. Recheck your wiring and board.

Now we can peek/poke data! For details on which registers to mess around, refer to KXPS5 datasheet. As a quick test, let’s read its acceleration value, let’s say, for X axis:

1
sudo i2cget -y i2c-gpio4 0x18 0x00 w

The command is pretty straightforward:

  • i2c-gpio4 – the bus we want to use
  • 0x18 – our KXPS5 address
  • 0x00 – the register we want to read. In this case, the word (2 bytes) starting at 0x00 is our X axis data.
  • w – read a word.

You can also try:

1
sudo watch -n1 "i2cget -y i2c-gpio4 0x18 0x00 w"

You’ll get a new reading every second. Turn you SmartQ V7 around and see the KXPS5 track your movement!

The kernel module for exposing the accelerometer data is being developed. I’ll update this article whenever something new happens.

Here a demonstration: