Arduino Nano SPI Problem

Hallo Leute,

ich arbeite gerade an einem kleinen Arduino Projekt und wollte einmal den SparkFun Level Shifting microSD Breakout (SparkFun Level Shifting microSD Breakout - DEV-13743 - SparkFun Electronics) ausprobieren.

Um ihn zu testen habe ich das SD Modul zunächst an meinen Arduino UNO angeschlossen und konnte ihn problemlos zum laufen kriegen, als ich jedoch das selbe an meinem Arduino NANO probiert habe lief nichts mehr.

Die Anschlüsse waren wie folgt:

UNO

MOSI -> 11
MISO -> 12
SCK -> 13
CS -> 8
VCC -> 3.3 V

NANO

MOSI -> 11
MISO -> 12
SCK -> 13
CS -> 8
VCC -> 3.3 V

Den CD (CardDetect) habe ich beide male nicht angeschlossen.

ich habe es auch über den ICSP versucht ging aber auch nicht.
Das Script kommt nach dem Text.

Ich hoffe es kann mit jemand helfen :smiley:

// include the SD library:
#include <SPI.h>
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 8;

void setup() {
 // Open serial communications and wait for port to open:
 Serial.begin(9600);
 while (!Serial) {
   ; // wait for serial port to connect. Needed for native USB port only
 }


 Serial.print("\nInitializing SD card...");

 // we'll use the initialization code from the utility libraries
 // since we're just testing if the card is working!
 if (!card.init(SPI_HALF_SPEED, chipSelect)) {
   Serial.println("initialization failed. Things to check:");
   Serial.println("* is a card inserted?");
   Serial.println("* is your wiring correct?");
   Serial.println("* did you change the chipSelect pin to match your shield or module?");
   return;
 } else {
   Serial.println("Wiring is correct and a card is present.");
 }

 // print the type of card
 Serial.print("\nCard type: ");
 switch (card.type()) {
   case SD_CARD_TYPE_SD1:
     Serial.println("SD1");
     break;
   case SD_CARD_TYPE_SD2:
     Serial.println("SD2");
     break;
   case SD_CARD_TYPE_SDHC:
     Serial.println("SDHC");
     break;
   default:
     Serial.println("Unknown");
 }

 // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
 if (!volume.init(card)) {
   Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
   return;
 }


 // print the type and size of the first FAT-type volume
 uint32_t volumesize;
 Serial.print("\nVolume type is FAT");
 Serial.println(volume.fatType(), DEC);
 Serial.println();

 volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
 volumesize *= volume.clusterCount();       // we'll have a lot of clusters
 volumesize *= 512;                            // SD card blocks are always 512 bytes
 Serial.print("Volume size (bytes): ");
 Serial.println(volumesize);
 Serial.print("Volume size (Kbytes): ");
 volumesize /= 1024;
 Serial.println(volumesize);
 Serial.print("Volume size (Mbytes): ");
 volumesize /= 1024;
 Serial.println(volumesize);


 Serial.println("\nFiles found on the card (name, date and size in bytes): ");
 root.openRoot(volume);

 // list all files in the card with date and size
 root.ls(LS_R | LS_DATE | LS_SIZE);
}


void loop(void) {

}

Was genau heißt "lief nichts mehr" ?
Gab es eine Fehlermeldung ?
Oder irgend ein Info die auf da Problem hinweist ?

pinMode(SS,OUTPUT);
oder aller wenigstens
pinMode(SS,INPUT_PULLUP);
in setup() vergessen.

Was bedeutet "lief nix mehr"?
gabs irgend ne Fehlermeldung?
leuchteten irgendwelche leds aufm Nano?
mit skc an pin 13 müsste wahrend dem kommunikationsversuch mit der sd auch die "L" led leuchten/flackern.

Ein bisschen genauer solltest du bitte das lief nix mehr schon ausführen, damit wir helfen können.

LG Stefan

Hi,

erstmal danke für die schnellen Antworten :wink:
Entschuldigt bitte meine unausführliche Beschreibung, ist das erste mal, dass ich etwas in einem Forum frage.

Aber nun zurück zum Problem, wie bereits erwähnt läuft die SD Karte auf dem UNO, der Serielle Monitor gibt bei dem oben aufgeführten Script folgendes aus

Initializing SD card...Wiring is correct and a card is present.

Card type: SDHC

Volume type is FAT32

Volume size (bytes): 1027604480
Volume size (Kbytes): 1003520
Volume size (Mbytes): 980

Files found on the card (name, date and size in bytes):
SYSTEM~1/ 2019-07-06 16:23:14
WPSETT~1.DAT 2019-07-06 16:23:14 12

Wenn ich das ganze jedoch mit den oben genannten Anschlüsse auf dem NANO probiere, kriege ich folgende Ausgabe

Initializing SD card...initialization failed. Things to check:

  • is a card inserted?
  • is your wiring correct?
  • did you change the chipSelect pin to match your shield or module?

// Nur bevor es jemand fragt ich bin natürlich alle Verbindungen nochmal durch gegangen und habe natürlich auch den CS angepasst, sowie auch eine SD Karte (FAT 32 formatiert) eingeschoben

Die "L" LED leuchtet dabei nach dem hochladen für ca. 2 Sekunden und geht danach aus. Das macht ja soweit auch Sinn weil das Script ja nicht dauerhaft versucht das Modul anzusprechen sondern nur ein mal.

Wenn noch weitere Informationen benötigt werden, dann schreibt einfach nochmal.
Vielen Dank schon mal an jeden der sich die Mühe macht mir zu helfen :wink:

Hast du auch mal versucht, die Karte an 5 Volt zu betreiben ?
Ich vermute, der 3,3V Pin des Nano liefert nicht genug Strom.

Ja ich habe es auch schon mit 5 Volt ausprobiert, ich habe das Gefühl, dass ich irgendetwas falsch mache mit den SPI Pins. Ich weiß nicht aber muss man die bei dem Nano anders behandeln im Script (also manuell die Pins auf low stellen etc.)?

Heisenbuerger:
Ja ich habe es auch schon mit 5 Volt ausprobiert, ich habe das Gefühl, dass ich irgendetwas falsch mache mit den SPI Pins. Ich weiß nicht aber muss man die bei dem Nano anders behandeln im Script (also manuell die Pins auf low stellen etc.)?

Nein....der Nano hat auch den Atmega328, wie der Uno.

dass ich irgendetwas falsch mache mit den SPI Pins.

Mittlerweile den SS Pin hoch gezogen, oder auf Ausgang gestellt?

Ja habe auch den Pinmode vom SS Pin auf "OUTPUT" gestellt und den auf "HIGH" geschaltet, leider immer noch das selbe Ergebnis wie zuvor.

Hi,

ich habe gerade nochmal einen MPU6050 (Gyro) an meinem Arduino UNO ausprobiert.

SCL -> 19

SDA -> 18

VCC -> 5V

GND -> GND

Mit folgendem Script:

// (c) Michael Schoeffler 2017, http://www.mschoeffler.de
#include "Wire.h" // This library allows you to communicate with I2C devices.
const int MPU_ADDR = 0x68; // I2C address of the MPU-6050. If AD0 pin is set to HIGH, the I2C address will be 0x69.
int16_t accelerometer_x, accelerometer_y, accelerometer_z; // variables for accelerometer raw data
int16_t gyro_x, gyro_y, gyro_z; // variables for gyro raw data
int16_t temperature; // variables for temperature data
char tmp_str[7]; // temporary variable used in convert function
char* convert_int16_to_str(int16_t i) { // converts int16 to string. Moreover, resulting strings will have the same length in the debug monitor.
sprintf(tmp_str, "%6d", i);
return tmp_str;
}
void setup() {
Serial.begin(9600);
Wire.begin();
Wire.beginTransmission(MPU_ADDR); // Begins a transmission to the I2C slave (GY-521 board)
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
}
void loop() {
Wire.beginTransmission(MPU_ADDR);
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(MPU_ADDR, 72, true); // request a total of 72=14 registers

// "Wire.read()<<8 | Wire.read();" means two registers are read and stored in the same variable
accelerometer_x = Wire.read()<<8 | Wire.read(); // reading registers: 0x3B (ACCEL_XOUT_H) and 0x3C (ACCEL_XOUT_L)
accelerometer_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x3D (ACCEL_YOUT_H) and 0x3E (ACCEL_YOUT_L)
accelerometer_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x3F (ACCEL_ZOUT_H) and 0x40 (ACCEL_ZOUT_L)
temperature = Wire.read()<<8 | Wire.read(); // reading registers: 0x41 (TEMP_OUT_H) and 0x42 (TEMP_OUT_L)
gyro_x = Wire.read()<<8 | Wire.read(); // reading registers: 0x43 (GYRO_XOUT_H) and 0x44 (GYRO_XOUT_L)
gyro_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x45 (GYRO_YOUT_H) and 0x46 (GYRO_YOUT_L)
gyro_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x47 (GYRO_ZOUT_H) and 0x48 (GYRO_ZOUT_L)

// print out data
Serial.print("aX = "); Serial.print(convert_int16_to_str(accelerometer_x));
Serial.print(" | aY = "); Serial.print(convert_int16_to_str(accelerometer_y));
Serial.print(" | aZ = "); Serial.print(convert_int16_to_str(accelerometer_z));
// the following equation was taken from the documentation [MPU-6000/MPU-6050 Register Map and Description, p.30]
Serial.print(" | tmp = "); Serial.print(temperature/340.00+36.53);
Serial.print(" | gX = "); Serial.print(convert_int16_to_str(gyro_x));
Serial.print(" | gY = "); Serial.print(convert_int16_to_str(gyro_y));
Serial.print(" | gZ = "); Serial.print(convert_int16_to_str(gyro_z));
Serial.println();

// delay
delay(1000);
}

Dieser gibt mir dann im Seriellen Monitor die gewünschten Werte des Sensors aus.

aX = 608 | aY = -92 | aZ = 15820 | tmp = 24.48 | gX = -282 | gY = 116 | gZ = 108
aX = 672 | aY = -48 | aZ = 16016 | tmp = 24.53 | gX = -316 | gY = 159 | gZ = 91
aX = 676 | aY = -128 | aZ = 16032 | tmp = 24.62 | gX = -302 | gY = 79 | gZ = 100
aX = 648 | aY = -196 | aZ = 15824 | tmp = 24.58 | gX = -312 | gY = 119 | gZ = 109
aX = 700 | aY = -72 | aZ = 16100 | tmp = 24.67 | gX = -319 | gY = 88 | gZ = 87
aX = 688 | aY = -20 | aZ = 15856 | tmp = 24.58 | gX = -329 | gY = 109 | gZ = 106
aX = 592 | aY = -64 | aZ = 15972 | tmp = 24.58 | gX = -309 | gY = 126 | gZ = 106
aX = 704 | aY = -204 | aZ = 15956 | tmp = 24.77 | gX = -331 | gY = 97 | gZ = 104
aX = 588 | aY = -120 | aZ = 15828 | tmp = 24.67 | gX = -301 | gY = 116 | gZ = 99

Wenn ich das ganze dann aber auf dem NANO probiere

SCL -> 5

SDA -> 4

VCC -> 5V

GND -> GND

Dann leuchtet nach dem Uploaden die "TX" LED in regelmäßigen Abständen auf, nach jedem aufleuchten gibt es auch eine Werterückgabe im Seriellen Monitor jedoch sieht die so aus.

aX = -1 | aY = -1 | aZ = -1 | tmp = 36.53 | gX = -1 | gY = -1 | gZ = -1
aX = -1 | aY = -1 | aZ = -1 | tmp = 36.53 | gX = -1 | gY = -1 | gZ = -1
aX = -1 | aY = -1 | aZ = -1 | tmp = 36.53 | gX = -1 | gY = -1 | gZ = -1
aX = -1 | aY = -1 | aZ = -1 | tmp = 36.53 | gX = -1 | gY = -1 | gZ = -1
aX = -1 | aY = -1 | aZ = -1 | tmp = 36.53 | gX = -1 | gY = -1 | gZ = -1
aX = -1 | aY = -1 | aZ = -1 | tmp = 36.53 | gX = -1 | gY = -1 | gZ = -1

Und nach dem 6ten mal gibt es keine Ausgabe mehr und die "TX" LED hört auch auf zu blinken.
Mir ist dabei aufgefallen, dass die Power LED vom MPU6050 beim anschließen an den NANO nicht leuchtet.

Ich hoffe jemand hat ne Idee :smiley:

Der NANO ist übrigens der hier:

https://www.ebay.de/itm/Nano-V3-0-ATmega-328-Board-CH340-USB-Chip-Arduino-Kompatibel/252742123829?hash=item3ad89ac135:g:xCEAAOSwPGtb33e0#rwid

Hi

In #0 konntest Du schon Mal mit Code-Tags umgehen, wohl wieder verlernt.
Schade eigentlich.

MfG

Und welche Pins verwendest du nun genau ?
Das ist ein wenig irritierend, was du schreibst.

Hi,

wegen der Pins nochmal. Ich habe jetzt einmal zwei Fritzing Dateien gemacht worauf man alles erkennen sollte.

die nicht leuchtende LED deutet auf ein Spannungsversorgungsproblem hin. Hast Du ein Voltmessgerät (Multimeter)? Wenn ja, miss mal die Spannung am 5V Ausgang gegen GND am Nano, erstmal ohne den Sensor, und wenn die Spannung da ist (ein bisschen weniger als 5V ist noch ok) , dann schliesse den Sensor wieder an und miss nochmals. ISt die Spannung immer noch da, miss auch am Eingang des Sensors, ob da die Spannung auch ankommt.

LG Stefan

Heisenbuerger:
wegen der Pins nochmal. Ich habe jetzt einmal zwei Fritzing Dateien gemacht worauf man alles erkennen sollte.

Warum bleibst du nicht bei dem SD-Modul aus deinem Eingangspost ?
Warum misst du nicht die Spannung, die an den Pins anstehen soll ?
Warum verwendest du nicht die üblichen Pinbezeichnungen (SDA oder A4, SCL oder A5) bei denen jeder versteht, worum es geht ?

Nur immer irgend etwas probieren, ohne zu wissen, was da abgeht, hilft dir und uns nicht weiter.

Im übrigen hat "SDA oder A4, SCL oder A5" nichts, sogar überhaupt nichts mit SPI zu tun.

Also warum diese Irreführung ?

Und auch von mir gerne der Hinweis:
Setze deinen Sketch in Code-Tags.
Schaltfläche "</>" oben links im Editor verwenden.
Das kannst du auch nachträglich noch machen.
Dazu den Sketch markieren und die Schaltfläche klicken.

Damit wird dieser für alle besser lesbar.