Go Down

Topic: Neopixel and SD card (Read 6086 times) previous topic - next topic

Grumpy_Mike

#30
May 01, 2017, 07:09 pm Last Edit: May 01, 2017, 07:12 pm by Grumpy_Mike
It looks like the limit on this is about 240 LEDs. You can probably get a bit more by taking out the print statements but it will not approach what you want so yes buy a Mega or a Zero.
Note if you go for a Zero then that uses 3V3 signals so you will have to build a buffer to drive the Neopixels.

Note we have knocked on the head your theory that you can't run an SD card and drive Neopixels.

mooop

Ok, I will buy a Mega then, the code is the exact same one right? 8K SRAM should be enough?

Thanks a lot for your help. One last question, when I modify the patterns file by adding 6 different colors:

29B299
B22929
000CFF
FBFF00
35AD4D
1EDADF
000000
000000
000000

The LED don't change colors, they're always in the blue spectrum. Why is that? I'm not mistake by saying that this:

29B299
B22929
000CFF
FBFF00
35AD4D
1EDADF

Is one frame of 6 pixels right? So my first pattern should display these pixels.

Grumpy_Mike

#32
May 01, 2017, 10:32 pm Last Edit: May 01, 2017, 10:33 pm by Grumpy_Mike
Quote
when I modify the patterns file by adding 6 different colors:
How are you changing this file?

Quote
they're always in the blue spectrum.
The blue numbers are much bigger than the other ones.

mooop

#33
May 03, 2017, 11:09 am Last Edit: May 03, 2017, 11:19 am by mooop
Ok so I went to the electronics store, they didn't have any Arduino Mega, only a "replica" which the guy said work great. Regardless of what he said  I didn't have time to buy one online, so I got this one, and my SD shield does not seem to work with this one. It keeps telling me that the SD initialization failed. One time it detected the card, but said not FAT partition was found. It works great with the Arduino.

The Arduino Mega 2560 replica characteristics are the exact same, what am I doing wrong?

 I am using the example sketch from the SD library:

I am guessing this is due to shitty hardware, could be wrong.

Code: [Select]

// 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
// MKRZero SD: SDCARD_SS_PIN
const int chipSelect = 4;

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) {

}


EDIT: CORRECTION. My Arduino is also returning an initialization error now. What the hell happened I didn't change anything? Is it possible that the Mega replica messed with the shield?

EDIT 2: CORRECTION. It is working on the Uno, I got the pins wrong. But it is definitely not working on the Mega replica.

Grumpy_Mike

The mega has different pins for the SPI bus than the Arduino. In fact these lines are not on the normal pins but on the header pins. Do a search for the exact details.

mooop

I get this once in a while:


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

Card type: SD1
Could not find FAT16/FAT32 partition.
Make sure you've formatted the card


But most of the time just could not initialized. How come?

Grumpy_Mike

Because the error messages assume you have an SD card connected to the SPI pins. You have not, they are floating pins so they can read back as anything. Hence the error messages make no sense.

mooop

I checked online, here is what I found:

MISO on pin 51
MOSI on pin 50
CLK on pin 52
CS on pin 53

I rewired this way, and it does not change anything. I still get card detected but no FAT partition once in 10 times or so.

Quote
Because the error messages assume you have an SD card connected to the SPI pins. You have not, they are floating pins so they can read back as anything.
Thanks for your help again. How do I fix this?

Grumpy_Mike

Have you changed the software so that the CS pin is pin 53?

mooop

I have changed the chipSelect variable.

I found this, but when I try these lines of code I get an error. I guess the library doesn't support that anymore.


Grumpy_Mike

#40
May 03, 2017, 01:15 pm Last Edit: May 03, 2017, 01:17 pm by Grumpy_Mike
Well the code as I posted works on my Mega by just changing the SD.begin(4) to SD.begin(53) and rewiring it:-

SPI Uno Mega
SS 10 53
MOSI 11 51
MISO 12 50
SCK 13 52

It also works when I set the number of pixels to 400.

mooop

Ok it is now working, however I dot understand why when I change your test.PAT to my hex colors it doesn't change anything.

Grumpy_Mike

As I said before, how are you changing it and how are you checking it?

mooop

I insert the micro SD into my computer slot through an adapter, I modify the contents of the file as follows, for instance:

29B299
B22929
000CFF
FBFF00
35AD4D
1EDADF

I save, I insert the micro sd into the arduino shield, and it doesn't change the led values. Just blue.


mooop

There is also this text file from instructables containing led matrix values, but I don't even understand what type of data that is.

-16777216
-16777216
-29922026
-29922026
-29922026
-29922026
-16777216
-16777216
-16777216
-16777216
-16777216
-16777216
-29922026
-29922026
-29922026
-29922026
-27884011
-26635696
-26635696
-27884011
-20063548
-20063548
-20063548
-20063548
-20063548
-20063548
-27884011
-26635696
-26635696
-27884011
-20063548
-16777216
-16777216
-29922026
-21769968
-16777216
-16777216
-21769968
-29922026
-29922026
-29922026
-29922026

Go Up