How-to: poor-man's accelerometers

I got a bunch of Memsic MXC6202xJ accelerometers from Farnell.com for about 5 euros each and managed to read them out using an Arduino Mini. I’ll try to explain how I got them working.

First a few notes:

  • I soldered wires directly onto the chip and glued everything tightly onto a piece of metal. The chip is quite small (5x5x1mm) so beware! Of course you can buy adapter boards or make a PCB yourself. Here is an image of the bare chip.
  • According to the datasheet the chip needs 2.7 V to 3.6 V for Vdd. Therefore, I let my Arduino Mini also run on around 3V. (The I2C bus voltage has to be equal or less than Vdd.)

Preparing the sensor:
I don’t have a third hand or soldering aid, so I glued the chip with 5-seconds-glue to a piece of paper which I taped to my desk. 6 pins need to be soldered out of the 8. I blacked out the pins that I did not need to solder with a thick permanent felt marker (check the datasheet), so the risk of accidentally touching them would be a bit smaller.
The GND (3) and COM (2) pins are next to each other, so I chose to solder them together since they both have to be connected to ground. In my case, Vdd and Vdd2 both go to +3V, but since the pins (resp. 8 & 5) are not next to each other, I chose to give them separate wires. I went for a 5 wire ribbon cable (4 would suffice if you manage to connect the Vdd and Vdd2 with one wire).
I had cut the each string of the wire in advance so it would be a bit easier to hold them in place and less tension would be the end result. Here is a picture after I had soldered the first wire to GND and COM.
After all wires are in place, I cut the chip loose from the paper and glued it onto a small piece of clean metal (a piece of a beer cap). Then I soldered a capacitor of 0.1uF between Vdd and GND. I also connected to the piece of metal to GND using the leg of the capacitor (as recommended in the datasheet).
Here is a picture of the fully wired chip on a piece of metal with the capacitor soldered onto it.
Finally, I put a big, hot blob of glue from my glue gun to seal the whole package. Here is a picture of the result. And another one :wink:

Wiring to the Arduino Mini
The sensor communicates with Arduino using the I2C protocol. A library named Wire is included in the Arduino IDE to support this. The wire going to the SDA pin (7) on the sensor should be connected to the Analog 4 pin on the Arduino Mini. The SCL pin (6) on the sensor goes to Analog pin 5 on the Arduino Mini. Vdd and Vdd2 both go to the 3V power supply and the GND/COM wire to ground.
The SCL and SDA lines need pull-up resistors. On my test breadboard, I used one 10K resistor between the SCL and Vdd (+3V) and another one between SDA and Vdd. Worked OK for me.

Sketching
Here is an example of a program that reads out the sensor with 100msec intervals and prints it to the serial port in decimal numbers:

#include <Wire.h>

char memsicAddress = 0x10; // (7 first bits of 0x20)
int lastX = 0;
int lastY = 0;

void setup() {
  Wire.begin(); // join i2c bus (address optional for master)
  Serial.begin(115200);
  wakeAcc();
};

void loop() {
  readAcc();
  Serial.print(lastX, DEC);
  Serial.print(" ");
  Serial.print(lastY, DEC);
  Serial.println("");
  delay(100);
};

void readAcc() {
  byte n = 0;
  Wire.beginTransmission(memsicAddress);
  
  // Start at register address 0x01:
  Wire.send(0x01);
  
  // Read 4 bytes:
  Wire.requestFrom(memsicAddress, 4);
  while(Wire.available()) {
    switch (n) {
      case 0:
        // MSB X-axis
        lastX = Wire.receive() << 8; // Shift most significant byte
        break;
      case 1:
        // LSB X-axis
        lastX += Wire.receive();
        break;
      case 2:
        // MSB Y-axis
        lastY = Wire.receive() << 8; // Shift most significant byte
        break;
      case 3:
        // LSB Y-axis
        lastY += Wire.receive();
        break;
    };
    n++;
  };
  Wire.endTransmission();
};

void wakeAcc() {
  Serial.println("trying to wake up the accelerometer...");
  Wire.beginTransmission(memsicAddress);
  Wire.send(0x00);
  Wire.send(0x00);
  delay(50);
  Wire.endTransmission();
  delay(100);
};

Good luck!

Hello Martijn,

I'm using the exact same setup, the Memsic accelerometer & arduino mini. I've tried to use your code but I cant figure out the correct address for the accelerometer. In the datasheet it says '20H' since the printed number on the IC is MXC62020JV. Could you tell me how you figured out the address of your memsic accelerometer?

Kind Regards,

Brian

Hi Brian,

The address is 0x20H as stated in the datasheet (like you said). But you have to make it 7-bit form, Wire expects that. It becomes 0x10H in 7-bit form. So basically I bitshifted the address 1 bit to the right. (You can do this with Mac’s Calculator app. Set it to Hex and “Programmer mode”, type in 20 and then use the “>>” button to bitshift one bit to the right…)

Drd noted that Wire expects 7-bit addresses, you can read more here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1170973485/38#38

Are you using a voltage of 3.3V?
Did you place the pull-up resistors correctly?
Can you post a picture somewhere?

Good luck!

Hi Martijn,

I've tried using 0x10 address but no difference. I've added a picture of the breadboard setup. How come you use 115200 while the datasheet states 400Khz i2c protocol?

I've put in two pull-up resistors 10K. It should be running at 3,2 V which should be oke (2.7~3.6)

Do you have any clue why it's not working?

Regards,

Brian

did u try to interface Wii's Nunchuck controller? it's great one. just more $ but got 3-axis accelerometer and X-Y joystick with two button that's pretty cheap than buy component from shop! http://www.windmeadow.com/node/42

Hi Brain,

I think you have to supply not only the sensor with 3.3V, but also the Arduino. Otherwise you're trying to connect a 3.3V device to a 5V I2C bus. When I tried it, I powered the sensor AND the Arduino using a 3.3V power supply (the one from Spark Fun). That worked for me.

The Mini USB only has a +5V output (although the FTDI chip offers a 3.3V out, it's not used on the Mini USB, unfortunately).

Good luck!