Forum: Mikrocontroller und Digitale Elektronik Gy-521 mit MSP430G3 (version 1.5) Launchpad


von Martin (Gast)


Lesenswert?

Hallo zusammen,
ich versuche vergeblich einen MPU6050 auf einem GY-521 breakout board 
mit einem MSP430G2 via I2C auszulesen. Ich habe die pins wie folgt 
belegt:

MSP    -> GY-521
GND    -> GND
VCC    -> VCC
Pin1.7 -> SDA
Pin1.8 -> SCL
(optional zusätzlich auch GND -> AD0 um die Adresse auf 0x69 
festzusetzen)

Der code, den ich in Energia verwende ist:


#include<Wire.h>
const int MPU_addr=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Serial.begin(9600);
}
void loop(){
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 
registers
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C 
(ACCEL_XOUT_L)
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E 
(ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 
(ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 
(TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 
(GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 
(GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 
(GYRO_ZOUT_L)
  Serial.print("AcX = "); Serial.print(AcX);
  Serial.print(" | AcY = "); Serial.print(AcY);
  Serial.print(" | AcZ = "); Serial.print(AcZ);
  Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation 
for temperature in degrees C from datasheet
  Serial.print(" | GyX = "); Serial.print(GyX);
  Serial.print(" | GyY = "); Serial.print(GyY);
  Serial.print(" | GyZ = "); Serial.println(GyZ);
  delay(333);
}

Die MPU-address sollte stimmen und ansonsten sehe ich nicht, wo der 
fehler liegen könnte. Den code habe ich von einem arduino-Beispiel 
benutzt. Die wire-library sollte ja identisch sein. Da das MSP430 nur 
3.3V ausgibt, habe ich auch schon extern 5V als power supply verwendet 
und kein anderes Ergebnis bekommen. Das GY-521 hat auch bereits pull-up 
Widerstände on-board. Hat jemand einen Tipp, was ich übersehe bzw. 
welchen Fehler ich mache?

Vielen Dank und viele Grüße,
Martin

von help (Gast)


Lesenswert?

Hallo Martin,

auf der Seite vom Beispiel
http://playground.arduino.cc/Main/MPU-6050#info
Steht die Adresse Vergabe anders herum: ad0 low -> 68 und High -> 69.

Der 6050 soll 3,3V kompatibel sein.

Kannst du die Leitungen mit Scope Abtasten?

von Martin (Gast)


Lesenswert?

Hallo,
danke für die Antwort, ich habe es mit 5V und 3.3V versucht und den ad0 
sowohl auf GND als auch auf 3.3V ausprobiert (dann jeweils addresse 0x68 
bzw. 0x69) verwendet. Andersherum habe ich's auch schon versucht. Leider 
ohne Erfolg

von Clemens L. (c_l)


Lesenswert?

Du hast den Fehler nicht beschrieben.

Kannst du die Leitungen mit Scope Abtasten?

Den MSP430 mit 5V zu braten ist keine gute Idee.

von Martin (Gast)


Lesenswert?

Hallo,
danke für die Antwort. Ich habe ein Multimeter zur Hand, mit dem ich die 
Leitungen abtasten kann. Wenn du das mit Scope meinst. Die 5V habe ich 
von einem arduino aus direkt an das GY-521 angeschlossen, als ich es mit 
einer 5V-Spannungsversorgung versucht habe.

von Martin (Gast)


Lesenswert?

Der Fehler besteht darin, dass ich im Serial Monitor keine Änderungen 
der Beschleunigungs und Positionswerte sehe, wenn ich den Sensor bewege.

von Clemens L. (c_l)


Lesenswert?

Was heißt das konkret? Dass keine neuen Werte kommen, oder immer die 
selben Werte? Und welche?

von Martin (Gast)


Lesenswert?

Es kommen immer die selben Messwerte, AcX = Acy = AcZ = GyX = GyY = GyZ 
= 0; Tmp = 36.

von Wolfgang (Gast)


Lesenswert?

Martin schrieb:
> Tmp = 36.

Du meinst 36.53?

Daraus folgt, das aus dem MPU6050 alle Register als 0 gelesen werden.

von Clemens L. (c_l)


Lesenswert?

Pin 1.8 gibt es nicht.

von Martin (Gast)


Lesenswert?

@ Clemens: Sorry, ich meinte auch
Pin1.7 -> SDA
Pin1.6 -> SCL
war schon spät, als ich den post geschrieben habe, habe mich einfach 
vertippt.
@Wolfgang: Genau, 36.53, was kann ich darauf ableiten, dass alle 
Register als 0 gelesen werden? Der MPU6050 wird also einfach nicht 
ausgelesen. Wo könnte ich ansetzen das Problem zu finden?

von Rufus Τ. F. (rufus) Benutzerseite


Lesenswert?

Funktioniert die I2C-Kommunikation mit irgendwas anderem, kannst Du 
mit Deinen Routinen beispielsweise ein I2C-EEPROM à la 24C02 auslesen?

von Wolfgang (Gast)


Lesenswert?

Martin schrieb:
> Der MPU6050 wird also einfach nicht ausgelesen. Wo könnte ich
> ansetzen das Problem zu finden?

Du solltest erstmal prüfen, ob er über haupt reagiert, also ob der 
MPU6050 überhaupt auf dem Bus mit Ack reagiert. Das setzt allerdings 
mehr als ein Multimeter voraus.

In deinem Code ignorierst du sämtliche Rückgabewerte von wire.write() 
und liest in blindem Vertrauen vom Bus, ohne vorher mit Wire.available() 
zu prüfen, ob Wire.requestFrom() überhaupt angekommen ist. Da ist die 
Diagnosemöglichkeit natürlich eingeschränkt.

Ein simpler I2C-Scanner könnte dir verraten, ob der Sensor sich 
überhaupt meldet und ob die Adresse stimmt.

von Rufus Τ. F. (rufus) Benutzerseite


Lesenswert?

Da Energia sich sehr am Arduino-Framework orientiert, könnte 
http://playground.arduino.cc/Main/I2cScanner eine Grundlage für 
derartige Tests sein.

von Clemens L. (c_l)


Lesenswert?

Der Code ist von http://playground.arduino.cc/Main/MPU-6050, also liegt 
das Problem wahrscheinlich in der Schaltung. Ein Schaltplan oder Foto 
wäre hilfreich.

von Martin (Gast)


Angehängte Dateien:

Lesenswert?

Den code habe ich, wie Clemens schon gesagt hat von 
http://playground.arduino.cc/Main/MPU-6050
übernommen. Das MSP430G2553 habe ich wie im angehängten Bild mit dem 
GY-521 verbunden. Der Pin unten rechts auf dem MSP ist ebenfalls ein GND 
pin (habe ich nachgemessen: VCC->GND unten rechts entspricht 3.3V). Den 
Jumper J51 habe ich rausgenommen, gemäß der Anleitung unter
http://energia.nu/pin-maps/guide_msp430g2launchpad/

von Clemens L. (c_l)


Lesenswert?

Du solltest mindestens den Rückgabewert von endTransmission() 
überprüfen.

von Martin (Gast)


Lesenswert?

Die Ausgabe ist 0 also success.

von Martin (Gast)


Lesenswert?

Auch wenn ich anstatt der Addresse des MPU6050 0x69 eingebe und nicht 
0x68 bekomme ich auch für
Serial.print(Wire.endTransmission());
den Wert 0. Das sollte ja eigentlich nicht gehen oder liege ich da 
falsch?

von help (Gast)


Lesenswert?

Den Hinweis zu der Adresse gab es schon:
Beitrag "Re: Gy-521 mit MSP430G3 (version 1.5) Launchpad"

von Clemens L. (c_l)


Lesenswert?

Welchen endTransmission()-Aufruf hast du geändert? Oder hast du einen 
hinzugefügt?

Bitte überprüfe auch den Rückgabewert von requestFrom().

von Wolfgang (Gast)


Lesenswert?

Martin schrieb:
> Das sollte ja eigentlich nicht gehen oder liege ich da falsch?

Jetzt lade doch einen I2C-Adress Scanner auf den µC hoch und guck. Das 
geht schneller als diese Rumprobiererei.
http://playground.arduino.cc/Main/I2cScanner

von Martin (Gast)


Lesenswert?

Die Ausgabe vom I2C scanner spuckt das aus:

Scanning...
I2C device found at address 0x01  !
I2C device found at address 0x02  !
I2C device found at address 0x03  !
I2C device found at address 0x04  !
I2C device found at address 0x05  !
I2C device found at address 0x06  !
I2C device found at address 0x07  !
I2C device found at address 0x08  !
I2C device found at address 0x09  !
I2C device found at address 0x0A  !
I2C device found at address 0x0B  !
I2C device found at address 0x0C  !
I2C device found at address 0x0D  !
I2C device found at address 0x0E  !
I2C device found at address 0x0F  !
I2C device found at address 0x10  !
I2C device found at address 0x11  !
I2C device found at address 0x12  !
I2C device found at address 0x13  !
I2C device found at address 0x14  !
I2C device found at address 0x15  !
I2C device found at address 0x16  !
I2C device found at address 0x17  !
I2C device found at address 0x18  !
I2C device found at address 0x19  !
I2C device found at address 0x1A  !
I2C device found at address 0x1B  !
I2C device found at address 0x1C  !
I2C device found at address 0x1D  !
I2C device found at address 0x1E  !
I2C device found at address 0x1F  !
I2C device found at address 0x20  !
I2C device found at address 0x21  !
I2C device found at address 0x22  !
I2C device found at address 0x23  !
I2C device found at address 0x24  !
I2C device found at address 0x25  !
I2C device found at address 0x26  !
I2C device found at address 0x27  !
I2C device found at address 0x28  !
I2C device found at address 0x29  !
I2C device found at address 0x2A  !
I2C device found at address 0x2B  !
I2C device found at address 0x2C  !
I2C device found at address 0x2D  !
I2C device found at address 0x2E  !
I2C device found at address 0x2F  !
I2C device found at address 0x30  !
I2C device found at address 0x31  !
I2C device found at address 0x32  !
I2C device found at address 0x33  !
I2C device found at address 0x34  !
I2C device found at address 0x35  !
I2C device found at address 0x36  !
I2C device found at address 0x37  !
I2C device found at address 0x38  !
I2C device found at address 0x39  !
I2C device found at address 0x3A  !
I2C device found at address 0x3B  !
I2C device found at address 0x3C  !
I2C device found at address 0x3D  !
I2C device found at address 0x3E  !
I2C device found at address 0x3F  !
I2C device found at address 0x40  !
I2C device found at address 0x41  !
I2C device found at address 0x42  !
I2C device found at address 0x43  !
I2C device found at address 0x44  !
I2C device found at address 0x45  !
I2C device found at address 0x46  !
I2C device found at address 0x47  !
I2C device found at address 0x48  !
I2C device found at address 0x49  !
I2C device found at address 0x4A  !
I2C device found at address 0x4B  !
I2C device found at address 0x4C  !
I2C device found at address 0x4D  !
I2C device found at address 0x4E  !
I2C device found at address 0x4F  !
I2C device found at address 0x50  !
I2C device found at address 0x51  !
I2C device found at address 0x52  !
I2C device found at address 0x53  !
I2C device found at address 0x54  !
I2C device found at address 0x55  !
I2C device found at address 0x56  !
I2C device found at address 0x57  !
I2C device found at address 0x58  !
I2C device found at address 0x59  !
I2C device found at address 0x5A  !
I2C device found at address 0x5B  !
I2C device found at address 0x5C  !
I2C device found at address 0x5D  !
I2C device found at address 0x5E  !
I2C device found at address 0x5F  !
I2C device found at address 0x60  !
I2C device found at address 0x61  !
I2C device found at address 0x62  !
I2C device found at address 0x63  !
I2C device found at address 0x64  !
I2C device found at address 0x65  !
I2C device found at address 0x66  !
I2C device found at address 0x67  !
I2C device found at address 0x68  !
I2C device found at address 0x69  !
I2C device found at address 0x6A  !
I2C device found at address 0x6B  !
I2C device found at address 0x6C  !
I2C device found at address 0x6D  !
I2C device found at address 0x6E  !
I2C device found at address 0x6F  !
I2C device found at address 0x70  !
I2C device found at address 0x71  !
I2C device found at address 0x72  !
I2C device found at address 0x73  !
I2C device found at address 0x74  !
I2C device found at address 0x75  !
I2C device found at address 0x76  !
I2C device found at address 0x77  !
I2C device found at address 0x78  !
I2C device found at address 0x79  !
I2C device found at address 0x7A  !
I2C device found at address 0x7B  !
I2C device found at address 0x7C  !
I2C device found at address 0x7D  !
I2C device found at address 0x7E  !
done

von Martin (Gast)


Lesenswert?

@ Clemens: wenn ich
Serial.print(Wire.requestFrom()) eingebe, wird der code nicht 
kompiliert, da requestForm() drei integers als inout benötigt. Welche 
soll ich dort eingeben?
Für die Überprüfung von endTransmission() habe ich lediglich die Zeile
Serial.print(Wire.endTransmission())
eingefügt

von Wolfgang (Gast)


Lesenswert?

Martin schrieb:
> Die Ausgabe vom I2C scanner spuckt das aus:
>
> Scanning...
> I2C device found at address 0x01  !
> I2C device found at address 0x02  !
> ...
> I2C device found at address 0x7D  !
> I2C device found at address 0x7E  !
> done

Und du bist ganz sicher, dass deine I2C Bibliothek und dein µC incl. 
Beschaltung ok sind?

Das sieht weder nach einem Adress-0x68/0x69- noch nach einem 
MPU6050-Problem aus.

von Martin (Gast)


Lesenswert?

Hallo Wolfgang,
bei der Schaltung bin ich mir zu 100% sicher! Den code für den I2C 
scanner habe ich wie gesagt von
http://playground.arduino.cc/Main/I2cScanner
übernommen. Was du mit den I2C Bibliotheken meinst, weiß ich nicht. Ich 
habe den selben µC nun mit dem gleichn code an zwei unterschiedlichen 
Rechnern ausprobiert und bekomme immer das gleiche Ergebnis beim I2C 
scan. Wo liegt der Fehler? Hat jemand eine Idee?

von Wolfgang (Gast)


Lesenswert?

Martin schrieb:
> Was du mit den I2C Bibliotheken meinst, weiß ich nicht

Wire.c

von Martin (Gast)


Lesenswert?

Die ist im header mit drin. Was kann ich sonst noch probieren?

von Wolfgang (Gast)


Lesenswert?

p.s.
... oder wire.cpp oder wire.ino oder wie auch immer.

von Wolfgang (Gast)


Lesenswert?

Martin schrieb:
> Die ist im header mit drin.

Nein, wire.h ist nur das Interface zu der Bibliothek.

von Martin (Gast)


Lesenswert?

Dann werde ich wohl das Arduino reaktivieren müssen, wenn ich das 
Datenkabel irgendwo finde :/

von Wolfgang (Gast)


Lesenswert?

Martin schrieb:
> Hat jemand eine Idee?

Martin schrieb:
> Das GY-521 hat auch bereits pull-up Widerstände on-board.

Hast du das nachgemessen? Welche Spannung misst du an SDA/SCL gegen Gnd?

von Martin (Gast)


Lesenswert?

Beide 3.3V

von Martin (Gast)


Lesenswert?

Mit dem Arduino Uno funktioniert der Sensor bzw ich kann ihn über den 
Serial Monitor auslesen. Das Skript ist identisch zur Anleitung unter:
http://playground.arduino.cc/Main/MPU-6050
und der I2c-scanner wirft
I2C Scanner
Scanning...
I2C device found at address 0x68  !
done
aus. Mir ist aufgefallen, dass das MSP430 auch die selbe lange Liste an 
I2C devices ausspuckt, wenn das MPU6050 gar nicht angeschlossen ist. Ich 
mache anscheinend irgendwas falsch mit dem MSP.

Beitrag #4971017 wurde von einem Moderator gelöscht.
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.