Professional Documents
Culture Documents
Interfaccia: IC
Alimentazione: da 3V a 5V
Ora passiamo al tutorial vero e proprio andando a vedere come utilizzare questo modulo con un
Arduino Uno.
Lista del materiale:
Modulo GY-521
SCHEMA
BREADBOARD
GY521
Arduino Uno
VCC
3.3V
GNS
GND
SCL
A5
SDA
A4
N.B. : Lo schema ed i collegamenti sono indirizzati solo per Arduino Uno, ma il tutorial valido
anche per tutte le altre board di Arduino. Lunica cosa che cambia nei collegamenti sono i 2 pin
I2C, ovvero SDA e SCL (Es. su Arduino Uno il pin SCL si trovare sul pin A5 mentre su Arduino Mega
si trova sul pin 20). Basta consultare il datasheet o fare delle ricerche su google per trovare gli
ingressi I2C della propria board.
Ora passiamo allo sketch di verifica, in questo modo verificheremo se il nostro modulo GY-521
collegato correttamente ad Arduino.
1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
2
1
2
2
2
3
2
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
-------------------------------------i2c_scanner
Version 1
This program (or code that looks like it)
can be found in many places.
For example on the Arduino.cc forum.
The original author is not know.
Version 2, Juni 2012, Using Arduino 1.0.1
Adapted to be as simple as possible by Arduino.cc user Krodal
Version 3, Feb 26 2013
V3 by louarnold
Version 4, March 3, 2013, Using Arduino 1.0.3
by Arduino.cc user Krodal.
Changes by louarnold removed.
Scanning addresses changed from 0...127 to 1...119,
according to the i2c scanner by Nick Gammon
http://www.gammon.com.au/forum/?id=10896
Version 5, March 28, 2013
As version 4, but address scans now to 127.
A sensor seems to use address 120.
This sketch tests the standard 7-bit addresses
Devices with higher bit address might not be seen properly.
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
Serial.println("\nI2C Scanner");
}
4
2
5
2 void loop()
6 {
2 byte error, address;
7 int nDevices;
2
8 Serial.println("Scanning...");
2
9 nDevices = 0;
3 for(address = 1; address < 127; address++ )
0 {
3
// The i2c_scanner uses the return value of
1
// the Write.endTransmisstion to see if
3
// a device did acknowledge to the address.
2
Wire.beginTransmission(address);
3
error = Wire.endTransmission();
3
3
if (error == 0)
4
{
3
Serial.print("I2C device found at address 0x");
5
if (address<16)
3
Serial.print("0");
6
Serial.print(address,HEX);
3
Serial.println(" !");
7
3
nDevices++;
8
}
3
else if (error==4)
9
{
4
Serial.print("Unknow error at address 0x");
0
if (address<16)
4
Serial.print("0");
1
Serial.println(address,HEX);
4
}
2
4 }
3 if (nDevices == 0)
Serial.println("No I2C devices found\n");
4
4 else
Serial.println("done\n");
4
5
4 delay(5000);
// wait 5 seconds for next scan
6 }
4
7
4
8
4
9
5
0
5
1
5
2
5
3
5
4
5
5
5
6
5
7
5
8
5
9
6
0
6
1
6
2
6
3
6
4
6
5
6
6
6
7
6
8
6
9
7
0
7
1
7
2
7
3
7
4
7
5
7
6
7
7
7
8
7
9
8
0
Bene! Se avete fatto la verifica ed andato tutto bene non ci resta che proseguire il tutorial e
provare le funzionalit del sensore MPU-6050, ovvero la lettura dei 3 assi (X,Y,Z) del giroscopio,
dellaccelerometro e per finire anche la misurazione della temperatura in gradi celsius (C).
Prima di tutto dovete caricate questo sketch sulla board arduino:
1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
2
1
2
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
3
0
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
Dopodich aprendo il Monitor Seriale si dovrebbero vedere i valori degli assi X,Y,Z
dellaccelerometro,giroscopio e della temperatura in C come nellimmagine seguente: