Pages: [1]   Go Down
Author Topic: Arduino Nano with Lego Accelerometer  (Read 649 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know how many people have actually done this, but my day was spent getting this to work.
So to start with, you need to cut a lego cable
Soldering/tinning the ends works best smiley-wink

Then, with a breadboard most likely, connect the pins 1 and 4 to 5v, 2 and 3 to ground, 5 and 6 to I2C clock and data respectively.
Then the code:
Code:
#include "Wire.h"
void setup()
{
  Wire.begin();
  Serial.begin(19200);           // start serial for output
}

void loop()
{
  Wire.beginTransmission(1); // transmit to device #1(lego accelerometer
  Wire.send(0x42);           // sends Read first 8 bits of accelerometer
  Wire.endTransmission();
  delay(700);
  Wire.requestFrom(1, 8);
  while(Wire.available())
  {
    char c = Wire.receive();
    Serial.println(c,HEX);    //output the data
  }
  Serial.print("Done \n");
  delay(500);
}
Fairly simple, but I had trouble googling it, so I did it myself
The rest of the request bytes can be found on the hitechnic site

Always glad to help
~Nai
Logged

Dallas, TX
Offline Offline
Full Member
***
Karma: 0
Posts: 170
Check out my blog on your smartphone!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You might have to take a look at the datasheet on the accelerometer, for the I2C connection. Are you receiving any type of data back? If so, will you post it.
« Last Edit: June 08, 2010, 03:12:32 pm by caseygross » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nope, got it working. One of the wires was broken inside the connector.
Also, for anyone else doing this here's the code:
Code:
#include "Wire.h"
void setup()
{
  Wire.begin();
  Serial.begin(19200);
}

void loop()
{
  Wire.beginTransmission(1);
  Wire.send(0x42);
  Wire.endTransmission();
  delay(20);
  Wire.requestFrom(1, 1);
  char b;
  while(Wire.available())
  {
    b = Wire.receive();
  }
  delay(50);
  Wire.send(0x45);  
  Wire.endTransmission();
  delay(20);
  Wire.requestFrom(1, 1);
  while(Wire.available())
  {
    char c = Wire.receive();
    int i = (c & 3) + (b << 2);
    Serial.println(i,DEC);
  }
  delay(500);
}
Logged

Pages: [1]   Go Up
Jump to: