Hallo Leute,
Ich versuche für ein Messtechnikprojekt zwei Winkel zu messen und anschließend die Werte alle 10ms auf einer SD-Karte zu speichern.
Das Problem: Die Datei wird nicht auf der SD-Karte erstellt.
Verwende ich ein Beispielprogramm funktioniert das Speichern und auch das beschreiben der erstellten Datei. Gehe ich allerdings dann in meinem Programm nach dem gleichen Prinzip vor, wird nichtmal die gewünschte Datei erstellt. Bin Anfänger und verstehe leider das Problem nicht.
Für jeden Rat bin ich dankbar.
Codes füg ich ein.
//MEINCODE
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#define MPU6050_ADRESS1 0x68
#define MPU6050_ADRESS2 0x69
const int ACCEL_OFFSET = 200;
long timer=0;
long timeout=10;
int accValue1[3], accAngle1[3], accValue2[3],accAngle2[3] ,accCorr2, accCorr1;
File data;
void setup()
{
pinMode(3,INPUT);
pinMode(10,OUTPUT);
SD.begin();
if(!SD.begin(10))
{
Serial.print("Fehler SD-Karte");
return;
}
data=SD.open("Messdaten.txt", FILE_WRITE);
data.print("Linker SKI: ");
data.print("rechter SKI: ");
data.close();
Wire.begin();
Wire.beginTransmission(MPU6050_ADRESS1); // Begins a transmission to the I2C slave
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Wire.beginTransmission(MPU6050_ADRESS2); // Begins a transmission to the I2C slave
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
Serial.flush();
}
void loop()
{
if(millis()> timer+timeout)
{
timer=millis();
if(digitalRead(3)==1)
{
Wire.beginTransmission(MPU6050_ADRESS1);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) [MPU-6000 and MPU-6050 Register Map and Descriptions Revision 4.2, p.40]
Wire.endTransmission(false); // the parameter indicates that the Arduino will send a restart. As a result, the connection is kept active.
Wire.requestFrom(MPU6050_ADRESS1, 3*2, true); // request a total of 7*2=14 registers
// "Wire.read()<<8 | Wire.read();" means two registers are read and stored in the same variable
for(byte i=0; i<3; i++) {
accValue1[i] = Wire.read()<<8 | Wire.read(); // reading registers: ACCEL_XOUT, ACCEL_YOUT, ACCEL_ZOUT
}
Serial.print("Linker Ski: ");
for(byte i=0;i<3;i++)
{
accCorr1 = accValue1[0]- ACCEL_OFFSET;
accCorr1 = map(accCorr1, -16800, 16800, -90, 90);
accAngle1[0] = constrain(accCorr1, -90, 90);
// Serial.print(accAngle1[i]);
// Serial.print("\t");
}
Serial.print(accAngle1[0]);
Wire.beginTransmission(MPU6050_ADRESS2);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) [MPU-6000 and MPU-6050 Register Map and Descriptions Revision 4.2, p.40]
Wire.endTransmission(false); // the parameter indicates that the Arduino will send a restart. As a result, the connection is kept active.
Wire.requestFrom(MPU6050_ADRESS2, 3*2, true); // request a total of 3*2=14 registers
// "Wire.read()<<8 | Wire.read();" means two registers are read and stored in the same variable
for(byte i=0; i<3; i++) {
accValue2[i] = Wire.read()<<8 | Wire.read(); // reading registers: ACCEL_XOUT, ACCEL_YOUT, ACCEL_ZOUT
}
Serial.print("| Rechter Ski: \t");
for(byte i=0;i<3;i++)
{
accCorr2=accValue2[0]- ACCEL_OFFSET;
accCorr2= map(accCorr2,-16800,16800,-90,90);
accAngle2[0] = constrain(accCorr2,-90,90);
//Serial.print(accAngle2[i]);
// Serial.print("\t");
}
Serial.print(accAngle2[0]);
Serial.println(" ");
}
}
else
{
//data1.close();
Serial.print("Messung beendet");
}
}
//Beispielcode funktioniert
#include <SPI.h>
#include <SD.h>
File Datei;
void setup() {
pinMode(10,OUTPUT);
Serial.begin(9600);
SD.begin();
while(!Serial)
{
;
}
if(!SD.begin(10))
{
Serial.println("Verbindung zur SD Karte fehlgeschlagen");
return;
}
Datei = SD.open("daten.txt", FILE_WRITE);
Datei.print("SERVUS");
Datei.print("ARDUINO");
Datei.close();
Serial.println("Fertig");
}
void loop() {
// put your main code here, to run repeatedly:
}