|
Post by calimero921 on Mar 5, 2014 5:06:46 GMT -8
First my project, A Weather Station with GUI and logs.
Here is my configuration : Arduino mega 2560, Grove Mega Shield for sensors (I2C & digital) and Gameduino2. First, I've done the modification for SPI pin change on Mega. The gameduino works well with the demo applications.
I made an interface to display my sensors informations in real time. Works well too. Now, i'd like to use the SD card to log informations from my sensors.
Here is my question : When I'd like to send command from GD2 libray (begin) the Gameduino then display FTDI logo and it hang. While GD2 library don't offer the command I expected, I used Arduino SD library, same effect. It only work when the SD.begin is send first (before GD.begin), but, after begin all other SD commands end FTDI Logo, even if file writing is done.
Note that I put SS pin (53 on mega) to output and declare pin 9 as CS pin on SD.begin as said in SD api docs.
Do someone have an idea ?
|
|
|
Post by jamesbowman on Mar 5, 2014 6:00:38 GMT -8
Aha, OK, so I think you are asking about using both the GD and the SD library in the same sketch.
This is a bit tricky because all the libraries need to share the SPI bus. GD, in particular, leaves the SPI bus open between API calls, so you must explicitly shut it down while talking to another SPI device.
So, for initialization, I recommend starting the GD library without SD card support, like this:
GD.begin(~GD_STORAGE); Then every time you call an SD library function, you must disable GD around the call with "GD.__end()" and "GD.resume()", like this:
GD.__end(); SD.<something> GD.resume();
|
|
|
Post by calimero921 on Mar 5, 2014 9:22:02 GMT -8
It works very well thank you.
|
|
|
Post by madivad on Mar 7, 2014 12:46:27 GMT -8
Since the GD2 uses the SD card for it's own storage (well, retrieval), is it possible to use the GD2 library for this purpose as well? Duplicating code by incorporating a separate SD library is only going to serve to bloat the sketch.
|
|
|
Post by madivad on Mar 19, 2014 3:54:59 GMT -8
Asked a different way: is there any functionality in the GD2 library for FILE access to the SD card in order to write and read random files?
|
|
|
Post by jamesbowman on Mar 19, 2014 6:49:40 GMT -8
The GD2 library's SD card support is strictly read-only.
|
|
|
Post by rayman on Jul 30, 2014 13:14:59 GMT -8
It works very well thank you. hi, can you post an example ? my test does not work ;( when i use the cardinfo example, my result is Initializing SD card...Wiring is correct and a card is present. Card type: SDHC Could not find FAT16/FAT32 partition. Make sure you've formatted the card the card works fine in all my other logger (openlog, ...) and i load my font.gd2 from the same card ;( #include <EEPROM.h> #include <Wire.h> #include <SPI.h> #include <GD2.h> #include <DS1307RTC.h> #include <Time.h> #include <I2Cdev.h> #include <ADXL345.h> #include <L3G4200D.h> #include <HMC5883L.h> #include <BMP085.h> #include <SD.h>
[...]
void setup() { pinMode(9, OUTPUT); // for sd-lib ???
Serial.begin(115200);
if (!SD.begin(sdSelect)) { Serial.println(F("sd-card failed")); } else { Serial.println(F("sd-card init ok")); }
[...]
GD.begin(~GD_STORAGE);
[...] }
void loop() { GD.__end(); // ... access to sd-card GD.resume();
[...] }
|
|
|
Post by aminnie on Jan 31, 2015 22:17:28 GMT -8
Thank you for the explanation and solution. It worked for me too.
|
|
|
Post by powersoft on Jul 25, 2015 5:44:53 GMT -8
Hello,
Have tried this approach, but this is not working for de GD2 and DUE.
Is there another solution to attach the SD card?
Thanks, Jan
|
|
BrewBot
Junior Member
busy
Posts: 21
|
Post by BrewBot on Nov 16, 2015 10:36:37 GMT -8
Hello Everyone As a few of you have, I would also like to use the SD card in the display for program data storage. turns out 4k of EEPROM on a Mega is just not enough for datalogging. I have seen a few people reference an SD library, but I am unable to find it (and its documentation for learning how to use it) any suggestions would be great thx Jason Edit: The reference library for this was the Arduino SD card library www.arduino.cc/en/Reference/SDas mentioned in this post gameduino2.proboards.com/thread/267/sd-card-library
|
|
BrewBot
Junior Member
busy
Posts: 21
|
Post by BrewBot on Mar 11, 2016 21:10:36 GMT -8
Aha, OK, so I think you are asking about using both the GD and the SD library in the same sketch. This is a bit tricky because all the libraries need to share the SPI bus. GD, in particular, leaves the SPI bus open between API calls, so you must explicitly shut it down while talking to another SPI device. So, for initialization, I recommend starting the GD library without SD card support, like this: GD.begin(~GD_STORAGE); Then every time you call an SD library function, you must disable GD around the call with "GD.__end()" and "GD.resume()", like this: GD.__end(); SD.<something> GD.resume(); Hey everyone, I am using this above code, and I am able to pull information off of the SD card during the first loop through. I however cannot seem to communicate with the SD card again after this loop as the SD.begin function returns false. Any tips? I want to be able to loop through a program while displaying on the gameduino LCD, but also record information onto the SD card in these loops My code is below and for now just spits out the content of the SD card root directory: GD.__end(); if (!SD.begin(chipSelect)) { Serial.println("SD could not load"); } else { root = SD.open("/"); printDirectory(root, 0); } GD.resume();
|
|
|
Post by jamesbowman on Mar 17, 2016 13:38:27 GMT -8
This is a small example that puts a directory listing on the screen.
It uses a macro SHARE() around every operation on the SD card.
#include <EEPROM.h> #include <SPI.h> #include <GD2.h> #include <SD.h> // Wrap all SD operations in this macro. // It makes the GD library release the SPI, does an operation, // then reaquires the SPI bus. #define SHARE(X) do {GD.__end(); (X); GD.resume();} while (0) #define FONT 28 void fail(char *s) { for (;;) { GD.Clear(); GD.cmd_text(480 / 2, 272 / 2, 31, OPT_CENTER, s); GD.swap(); } } void setup() { int success; GD.begin(~GD_STORAGE); SHARE(success = SD.begin(9)); if (!success) fail("No SD card detected"); } void loop() { File dir, entry; GD.Clear(); SHARE(dir = SD.open("/")); for (int y = 0; y < 272; y += 30) { SHARE(entry = dir.openNextFile()); if (!entry) break; GD.cmd_text(0, y, FONT, 0, entry.name()); if (entry.isDirectory()) GD.cmd_text(300, y, FONT, OPT_RIGHTX, "<dir>"); else GD.cmd_number(300, y, FONT, OPT_RIGHTX, entry.size()); SHARE(entry.close()); } SHARE(dir.close()); GD.swap(); }
|
|
|
Post by Tango on Jun 20, 2016 19:33:41 GMT -8
Hi, im trying to load an jpg image from the sd card, and works fine, but my question is about, it is possible to load an image from a determined file folder, for example: d:// <---- SD rooth d:/imagefolder/ <---- determined file folder
I thinkit could be very helpful to do so, i wish you can inlight me.
Thanks!
|
|
|
Post by selcuk06 on Jun 10, 2017 21:49:37 GMT -8
Hi, im trying to load an jpg image from the sd card, and works fine, but my question is about, it is possible to load an image from a determined file folder, for example: d:// <---- SD rooth d:/imagefolder/ <---- determined file folder I thinkit could be very helpful to do so, i wish you can inlight me. Thanks! Hi, I was looking for an answer for the same question . Is there anyway to call images from a certain directory? "001.png" works fine in root directory but calling it from "folder1\001.png" does not work. Thank you
|
|