Thursday, September 11, 2014

Arduino Yun to GY 521 (accelerometer)

Here is wiring diagram for Arduino to GY 521 accelerometer connection



VCC to  3.5 V
GND to GND
SCL to D3
SDA to D2


Arduino is based on Leonardo processor, thus
2 (SDA), 3 (SCL)



I started playing with Arduino Yun. I am running Arduino 1.5.7 on ISX 10.9.4. Believe me it was nightmare passing the code through usb, most of the time code was struck at "uploading". I read many posts, and figured out may be my driver was out of date, so update my drivers. Still no luck. Uploading the source was problematic to such an extend that I had to force quit Arduino IDE and force shut down my Mac several times. Eventually I arrived at reliable workaround.

Instead of passing code through USB, transfer it via Wifi. it is very easy, all you have to do is follow steps in https://www.temboo.com/arduino/yun/serial-to-console

Here is I2c_scanner code converted to Wifi

#include <Bridge.h>
#include <Wire.h>

void setup() {
    Bridge.begin();
    Console.begin();
    while(!Console);
}


void loop()
{
  byte error, address;
  int nDevices;

  Console.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ ) 
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Console.print("I2C device found at address 0x");
      if (address<16) 
        Console.print("0");
      Console.print(address,HEX);
      Console.println("  !");

      nDevices++;
    }
    else if (error==4) 
    {
      Console.print("Unknow error at address 0x");
      if (address<16) 
        Console.print("0");
      Console.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Console.println("No I2C devices found\n");
  else
    Console.println("done\n");

  delay(5000);           // wait 5 seconds for next scan

}

I hope I'll save someone's hours of frustration.