Skip to main content

Arduino Mega 2560 and the SD Card Reader

 

Arduino Mega 2560 and the SD Card Reader

The next board to test with the SD Card Readers is the Arduino MEGA 2560.  This is a more complex microprocessor, with 54 digital I/O pins, 16 analog inputs and a larger space for your sketch.

 
Arduino Mega2560

Microcontroller ATmega2560
Operating Voltage 5V
Input Voltage (recommended) 7-12V
Input Voltage (limit) 6-20V
Digital I/O Pins 54 (of which 15 provide PWM output)
Analog Input Pins 16
DC Current per I/O Pin 20 mA
DC Current for 3.3V Pin 50 mA
Flash Memory 256 KB of which 8 KB used by bootloader
SRAM 8 KB
EEPROM 4 KB
Clock Speed 16 MHz
LED_BUILTIN 13
Length 101.52 mm
Width 53.3 mm
Weight 37 g

The SPI serial communication on this device uses pins 50, 51, 52 and 53.

Arduino / Genuino Board MOSI MISO SCK SS (slave) SS (master) Level
Uno or Duemilanove 11 or ICSP-4 12 or ICSP-1 13 or ICSP-3 10 5V
Mega1280 or Mega2560 51 or ICSP-4 50 or ICSP-1 52 or ICSP-3 53 5V

It still uses 5v logic levels, so nothing new there…

I set up the Mega2560 under the tools menu:

 
Mega2560 Setup

Then I ran a quick compile on the CardInfo program.  It worked first time…

 
Compile Message

Sketch uses 10958 bytes (4%) of program storage space. Maximum is 253952 bytes.
Global variables is 1434 bytes (17%) of dynamic memory, leaving 6758 bytes for local variables. Maximum is 8192 bytes.

For CardInfo and DumpFile programs, I only changed one line in the program to make it compatible with the Mega2560 board.

I changed the chipSelect variable to match the hardware CS pin.



The output of the CardInfo program looks good…

 
CardInfo Output

Take my word that the DumpFile program works, as well.

For Files, listfiles and ReadWrite programs, I also changed just one line to make it work with the Mega2560. I changed the pin number for the CS pin to 53 to match the hardware.

 
Change for Mega2560

Similarly, just 1 line to change in the datalogger_kill program…

 
datalogger_kill CS select for Mega2560

 

 
datalogger_kill output 2560

Of course, the program runs much faster on this chip, and is not restricted by hardware as to how fast it loops through the data logging.  It is restricted by the wait time saved in one of the variables.  The Uno seemed a little slower, even with the same wait time, so is probably a little constrained by the hardware.

I was even able to comment out the delay altogether with this board, and the program still ran reliably.  Nice to have some horsepower!

 
No Delay…

So there appears to be no real tricks to get the SD Card Reader to work with the Mega2560.  Just hook the reader up to the specified pins, and change one line of code to specify the Chip Select pin to match the hardware.

Next!…

Comments

Popular posts from this blog

APRS I-Gate

Yaesu G-450XL Rotator Repair

ERC-4 Interface & My HyGain Ham-IV Rotator Controller – Part 3