SD on SEEED Studio ethernet fails when not powered via USB

Hello everyone,

I've been working with Arduino R3 for a long time, but I'm running into some issues with the new R4 Wifi.
My software works just fine when powered via USB-C (from my phone leader USB-C).
My solution uses the SD from a SEEED Studio Ethernet shield (v2) to read data.
However, when I power my R4 Wifi via the barrel jack (6 , 9 and 12 volt), the SD will not work.
If I use an Arduino R3 in combination with regular SD.H there is no issue at all.

I've already had issues getting the SD to work on R4.
Normal SD.H does not work, so I use and also have set pin 10 High ?:

#include <SPI.h>
#include "SdFat.h" 

const int8_t DISABLE_CS_PIN = 10;
const uint8_t SD_CS_PIN = 4;
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(8))
SdFs sd;
File myFile;

in setup :

digitalWrite(DISABLE_CS_PIN, HIGH);
 if (!sd.begin(SD_CONFIG)) {
    sd.initErrorHalt(&Serial);
  }

Does anyone know what causes this? Is it just a faulty R4?

Regards,

you have to set the CS of the W5500 HIGH so it doesn't interfere on the SPI bus. that is normal

Hi, thx for the reply.
Although i find it weird that I do not have to explicitly set pin 10 high when using the <sd.h> sample on an R3 ?
using sd. sample on the R4 i must add :

 pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }

But it does not explain why the initialization fails when i power the R4 via the barrel jack ?

maybe your AC/DC adapter can't supply enough current or is slow to supply it. try to delay the shield initialization

Hi
I tested with 12V 3.34 A , 9V 1.3A and there is a delay ( its testing leds ) of 6 seconds before the sd.begin is started?

  pinMode(A0,INPUT);  // Signal in
  pinMode(ledPinTEMP,OUTPUT);  // ERR
  pinMode(ledPinLAN,OUTPUT);  // OK
  pinMode(InPin,OUTPUT);  // OK
  for (int x = 0; x < 4; x++) { 
    digitalWrite(ledPinLAN,HIGH);
    digitalWrite(ledPinTEMP,HIGH);
    digitalWrite(InPin,HIGH); 
    delay(1000);
    digitalWrite(ledPinLAN,LOW);
    digitalWrite(ledPinTEMP,LOW);
    digitalWrite(InPin,LOW);
    delay(1000);
  }



 if (DISABLE_CS_PIN >= 0) {
     pinMode(DISABLE_CS_PIN, OUTPUT);
    digitalWrite(DISABLE_CS_PIN, HIGH);
  }
  // Initialize the SD card.
  digitalWrite(ledPinTEMP,HIGH);
  if (!sd.begin(SD_CONFIG)) {
     
    sd.initErrorHalt(&Serial);
  }
digitalWrite(ledPinTEMP,LOW);

Hi,
Just an update, today ran the same on a brand new R4 Wifi.
Issue is the same :frowning:
Only when powered by USB-C the SD initialization works and data is read. But when powered via the Barrel Jack (DC) it fails..
Anyone ?

Do you have
"while (!Serial) // wait for serial port to connect " in your sketch?

@Dozie while (!Serial) is not a problem on Uno R4 WiFi. Serial goes to the esp32s2 and the esp32s2 is the USB adapter.

@Juraj, my bad, forgot it is the Wifi version.

Hi

No, 'while Serial' is not the cause ( its not in the code )..

Arduino Ethernet Shield 2 (which is similar to your SEEED Studio Ethernet shield (v2)) work fine with UNO R3 and UNO R4 Minima without any changes to the IDE's SD library examples. But for UNO R4 Wifi, you need to add sufficient delay, say "delay(2000) after Serial.begin() " for the examples to work. So for your issue (as long as your sketch does not depend on the serial monitor being open to run when the powered is powered by DC jack, you need to use appropriate dalay in the right place in your sketch for it to work).
You can test with the SD examples in the IDE with your board to check if they work as suggested.

Hi

It seems the issue was the SdFat.h that somehow requires serial ??
I altered the code to SD.h and used below in setup:
(CS Pin 10 Must be set high or else it will not work on this board and extra delay does not seem to have any impact)

  pinMode(DISABLE_CS_PIN, OUTPUT);
  digitalWrite(DISABLE_CS_PIN, HIGH);
   // Initialize the SD card.
  if (!SD.begin(4)) {
    while(1);
  }

so thx for the feedback, seems to work now :slight_smile:

1 Like