How to use PCb labels (D1,D2...) instead of "PIN number.

I am trying to use a Nano 33 IoT Data Logging SD and RTC shield. Several examples use different PINs for SPI and I2C connections. They all have failed. The connections to the 30 pin header were "buzzed out" and confirm signals run to the following PINs labeled as: CS-D12, MISO-D11, SCLK-D13, MOSI-D10, SDA-D18, and SCL-D19. The last two are for I2C.

How do I use this information to run this example Sketch?

/*
  SD card read/write
 
 This example shows how to read and write data to and from an SD card file 	
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
 
 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 
 This example code is in the public domain.
 	 
 */
 
#include <SPI.h>
#include <SD.h>

File myFile;

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


  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
   pinMode(1, OUTPUT);
   
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
  
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
	// close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
  
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
    
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    	Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
  	// if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{
	// nothing happens after setup
}

Of course, the Monitor always posts: "Initialization Failed"

I am using Arduino the Nano 33 IoT and I do not understand how to convert from D1... to PIN number.
Thanks for the help.

Wagsalot:
I am trying to use a Nano 33 IoT Data Logging SD and RTC shield.

Please post a link to where you bought the shield.

Wagsalot:
if (!SD.begin(4)) {

Do you have the CS pin of the SD card holder connected to the pin marked "D4" on your Nano 33 IoT?

Wagsalot:
I am using Arduino the Nano 33 IoT and I do not understand how to convert from D1... to PIN number.

It's not clear what you're asking. Please provide more details. What to you mean by "PIN number"?

If you're asking for how to convert the Dn pin labels on the Nano 33 IoT's silkscreen to Arduino pin numbers, the Arduino pin number is n. So the pin marked D1 on the Nano 33 IoT's silkscreen is Arduino pin 1.

digitalWrite(1, HIGH)

With the An pins, Arduino has created special definitions for these pin names, so you can just use the An as an Arduino pin number in your sketch. For example:

analogRead(A2)

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Is the code you are using ported to use the Nano 33 IOT?

Thanks.. Tom.. :slight_smile:

Wagsalot:
NANO 33 IoT SPI:
CS-D12 by default, but you can use any pin
MISO-D11
SCLK-D13
MOSI-D10
NANO 33 IoT I2C:
SDA-D18
SCL-D19

How do I use this information to run this example Sketch?
NANO SPI:
MOSI - pin 11
MISO - pin 12
CLK - pin 13
CS - pin 10 by default, but you can use any pin

Are you SURE you have those NANO 33 IoT pins right? They don't seem to match the documentation. The official pinout diagram shows:

  • SPI MOSI - pin 11
  • SPI MISO - pin 12
  • SPI SCK - pin 13
  • I2C SDA - pin 18/A4
  • I2C SCL - pin 19/A5

It looks like they took care to keep the SPI and I2C/TWI/Wire pins in the same place as the NANO. You should be able to plug your NANO shield onto a NANO 33 IoT and expect the examples for it to probably work.