Close

SPI for Arduino Mega with Uno shield

A project log for NTSC/PAL Video Display Shield

An Arduino NTSC/PAL video display shield with integrated framebuffer and composite video output.

magicwolfiMagicWolfi 02/12/2018 at 01:074 Comments

The issue: The Arduino Mega has its SPI port mapped on pins 50 to 53, which is on the dual row header at the end of the board. Those pins are not accessible through are regular Uno shield.
To use my Video Display shield (and any other shield that wants to talk SPI), this is what I did:

Connect the SPI communication signals through jumper wires to the shield.

The slave select pin 53 does not need to be wired, as it is mapped as a normal GPIO in a normal Uno sketch. The picture for the pin numbers 50-51 on the Mega connector is misleading due to the parallax. 

(The RCA connector is not in a ideal location for the wire jumpers. Here is a reason for another spin).

Make pins 11 to 13 on the Mega inputs or tri-stated outputs.

Add the define somewhere in the header file for the shield or at the beginning of the sketch

#define MEGA 

Add the code to disable the pins that are used by Uno for SPI in the setup() function

#ifdef MEGA 
pinMode(11, INPUT); 
pinMode(12, INPUT); 
pinMode(13, INPUT); 
#endif

 This was all I needed to do and the MEGA was happily configuring the Video Display shield and outputting the test patterns.

And the compile log told me, there is lots of memory available compared to the Uno:

Sketch uses 7498 bytes (2%) of program storage space. Maximum is 253952 bytes.
Global variables use 424 bytes (5%) of dynamic memory, leaving 7768 bytes for local variables. Maximum is 8192 bytes.

That was easy. (Edit: Well, to easy to not mess it up, pin numbers are now correct, see comments)

Discussions

Michael Shiloh wrote 08/10/2023 at 06:29 point

I teach, and being able to show my students how it's done in real life is so useful. Well written logs during project development (like yours) are a wonderful resource! Glad I could help in some small way.

  Are you sure? yes | no

MagicWolfi wrote 08/11/2023 at 17:41 point

Thanks for building the next generation of smart kids. Not an easy job. Feel free to use anything from my projects for your teaching material.

  Are you sure? yes | no

Michael Shiloh wrote 08/09/2023 at 06:14 point

Thanks for posting this information, it is so useful to see someone's process. I note a discrepancy in the SPI pin numbers for the Uno: You say MOSI: Mega pin 51   -> Uno shield pin 12 and MISO: Mega pin 50  -> Uno shield pin 11 but I believe that the Uno pins are reversed.  Can you verify? I use this as a reference: https://content.arduino.cc/assets/A000066-full-pinout.pdf

  Are you sure? yes | no

MagicWolfi wrote 08/10/2023 at 02:30 point

Hello Michael, I am glad my stuff is useful for somebody. And you are absolutely correct, the connections are reversed, I am going to fix the log. It is even visible in the picture that the blue wire is going from Mega pin 51 to Uno pin 11. Thanks for finding and reporting this one.

  Are you sure? yes | no