Connecting the Dash to an SD Card Reader


#1

Can someone help me connect to an SD Card and write a file. I can get it to work on an Arduino using the SD Card library, but I’m having problems trying to accomplish the same task on the Dash.

#include <SPI.h>
#include <SD.h>
//Add SD Card Lib (SPI)
// MOSI -> DI: D26 (MOSI) - Data In from SD CARD
// SCK -> SCK: D08 (SCK) - System Clock
// MISO -> DO: D27 (MISO) - Data Out from SD CARD
// CS -> CS0: D29 (CS0) - Chip Select
#define SPI_CS D29

File sentGPSData;
File pendingGPSData;

void setup() {

  if (!SD.begin(SPI_CS)) {
    Serial.println("Card init. failed!");
  }

  sentGPSData = SD.open("GPS_DATA_LOG.TXT", FILE_WRITE);
  pendingGPSData = SD.open("GPS_DATA_PENDING.TXT", FILE_WRITE);
}

void loop() {
  String logMsg = "Hello World";
  sentGPSData.println(logMsg);
  sentGPSData.flush();
  
  pendingGPSData.println(logMsg);
  pendingGPSData.flush();

  delay(2000);

}

Saving data to the Dash (EEPROM)
#2

Any help would be appreciated, I’m stuck on how to get this working. I’ve looked at SD from Adafruit, SD from Arduino, SDFatlib. I can’t seem to make any progress.

PLEASE HELP!


#3

Here is the error I receive

/Users/ss/Documents/Arduino/libraries/SD/utility/Sd2PinMap.h:27:24: error: 'SS' was not declared in this scope
 uint8_t const SS_PIN = SS;

                        ^
/Users/ss/Documents/Arduino/libraries/SD/utility/Sd2PinMap.h:28:26: error: 'MOSI' was not declared in this scope
 uint8_t const MOSI_PIN = MOSI;

                          ^
/Users/ss/Documents/Arduino/libraries/SD/utility/Sd2PinMap.h:29:26: error: 'MISO' was not declared in this scope
 uint8_t const MISO_PIN = MISO;

                          ^
/Users/ss/Documents/Arduino/libraries/SD/utility/Sd2PinMap.h:30:25: error: 'SCK' was not declared in this scope
 uint8_t const SCK_PIN = SCK;

#4

Try using D12 and D14 for your MOSI/MISO. D26/27 are a second SPI config, using AltSPI name instead of SPI. I’ll update our documentation to make this clear. The SD lib is probably expecting the SPI name.

Not all Arduino libraries are compatible with the Dash. If you can post a link to the library source I’ll check and see if it is compatible. If it’s using vanilla SPI calls though it should be fine.


#5

This is the library I’m trying to use, If you could provide a very simple sketch with the AltSPI I would be forever grateful. And It doesn’t have to be this library, I just need to read/write to an SD Card so whatever you would suggest.

Thanks,


#6

There’s not an easy way to use that lib or a similar one I found from Sparkfun because the pins are hard-coded in the library. I’ll see if I can come up with a workaround.


#7

Oh if you could that would be amazing, I am moments away from having my project finished, and this is the last piece. If you have a patreon I would gladly donate for your help! I’m so close to being finished can taste it :grin:


#8

Hey @Erik, I was checking to see if you had figured out a workaround to make one of the SD Card libraries work?

Thanks for all of your help.


#9

I have a quick-hack version of the SD library that builds with the Dash. Extract this zip file in the Arduino libraries directory (delete the existing one first).
SD.zip (60.3 KB)

I made definitions for the missing symbols in Sd2PinMap.h. I’ll add these symbols to our Dash definitions as they should be there for compatibility - but they aren’t actually used because it uses the SPI object by default. I specified AltSPI there, with the symbol SDCARD_SPI that is used in the library. I’m not sure where the right place to define that so it will be scoped correctly by the library, but that seems to work for now.

As the library is written, the SS pin isn’t used if the SPI object is used. It only uses the default SS pin. On the Dash and the Due, you can specify SS in beginTransaction(). I made a quick-fix for that in Sd2Card.cpp, but it should really be in the stock library.

Unfortunately I don’t have an SD card shield, so I can’t test this out. So it may not work at all. Let me know if it works. I was able to the example sketches. Make sure you set the SS pin in the card.init() call.


#10

Trying the SD Library now


#11

I tried a few different options (D29, SS, 33) for the CS and unfortunately, I’m getting “initialization failed.” Although on the plus side it compiled correctly and uploaded onto the dash.


#12

I’ve also tried changing the Sd2PinMap.h to the First set of SPI pins to no avail. They look like they mirror the arduino pinout using CS2.

SS 10
MISO 11
MOSI 12
SCK 13

Any other thoughts on how to workaround the problem?


#13

I did the CardInfo example, changing only 1 line:
const int chipSelect = D29;
I don’t have a card reader to connect, but I did connect my logic analyzer to the ALT SPI pins and the CS.

In the first picture you can see the 10 byte 0xFF write along with the clock (at 250kHz) and CS lines.

In the second picture you can see the first command sent, which is 0 | 0x40, 4 data bytes of 0, and the 2-byte CRC.

So I think the modified library is working. Double-check your connections and if you have an analyzer or oscilloscope use that to see if your IO are toggling.


#14

Ok I will try it again and see, I don’t have a logic analyzer or an oscilloscope, but I did have it wired up to an Arduino Uno before and was able to get it to read/write so I know the module is good.


#15

Unfortunately, I am still getting card init errors. Here are some pictures of my setup. Maybe you can tell me if I’m missing something


#16

I think you just have it wired wrong.

SCK (green) should be connected to L05 on the other side of the board.
CS looks good.
You may need to switch MISO/MOSI (blue/yellow) because I’m not sure if the breakout is labeled relative to the SD card or the Dash. Probably the SD card so I’m going to guess you need to swap them. Try it both ways.
What voltage does the SD card need to run at? If it’s 5V then you have VCC correct.
GND is good.


#17

IT WORKS!!! WOOHOO!! Thank you so much for your help :slight_smile:

I ran the cardInfo sketch and it didn’t give me anything, which made me assume that it at least found it. So I ran the datalogger sketch and sure enough, data started logging on the serial monitor and it correctly created the file and wrote to it!


#18

That’s great! We’d love to hear about your project once you get it working. Good luck.


#19

Here was part of my confusion. I know the 1.0 module is no longer being made, but for those that still have the module a couple of the spots may need to be corrected on the pinout sheet.


#20

Understandable. Yes, that diagram contains a number of mistakes. The Dash 1.1 is pin compatible with the 1.0, so you can use the current documentation https://hologram.io/docs/reference/dash/datasheet/ for either. The updated pinout diagram is near the end of the page. Sorry for the confusion. That one’s on us.