Transitioning from Duemilanove to Mega1280 for 8x8x8 LED Cube

Hey all,

I built the 8x8x8 cube featured at http://www.instructables.com/id/Led-Cube-8x8x8/ using a Duemilanove, and all was peachy. I have since decided to upgrade it with an LCD screen and keypad, which necessitated a switch to an Arduino Mega with the ATmega1280. However, the cube now behaves very erratically. I’m just about ready to pull out my hair trying to get this thing to work, and I’d really appreciate any help.

Here’s the Duemilanove code for the setup() and interrupt:

#include <avr/interrupt.h>
#include <string.h>
#define AXIS_X 1
#define AXIS_Y 2
#define AXIS_Z 3

volatile unsigned char cube[8][8];
volatile int current_layer = 0;

void setup()
{
  int i;
  
  for(i=0; i<14; i++)
    pinMode(i, OUTPUT);
  
  // pinMode(A0, OUTPUT) as specified in the arduino reference didn't work. So I accessed the registers directly.
  DDRC = 0xff;
  PORTC = 0x00;
  
  // Reset any PWM configuration that the arduino may have set up automagically!
  TCCR2A = 0x00;
  TCCR2B = 0x00;

  TCCR2A |= (0x01 << WGM21); // CTC mode. clear counter on TCNT2 == OCR2A, causes OCF2A = 1
  OCR2A = 10; // Interrupt every 25600th cpu cycle (256*100)
  TCNT2 = 0x00; // start counting at 0
  TCCR2B |= (0x01 << CS22) | (0x01 << CS21); // Start the clock with a 256 prescaler
  
  TIMSK2 |= (0x01 << OCIE2A);
}

ISR (TIMER2_COMPA_vect)
{
  int i;
  
  // all layer selects off
  PORTC = 0x00;
  PORTB &= 0x0f;
  
  PORTB |= 0x08; // output enable off.
  
  for (i=0; i<8; i++)
  {
    PORTD = cube[current_layer][i];
    PORTB = (PORTB & 0xF8) | (0x07 & (i+1));
  }
  
  PORTB &= 0b00110111; // Output enable on.
  
  if (current_layer < 6)
  {
    PORTC = (0x01 << current_layer);
  } else if (current_layer == 6)
  {
    digitalWrite(12, HIGH);
  } else
  {
    digitalWrite(13, HIGH);
  }
  
  current_layer++;
  
  if (current_layer == 8)
    current_layer = 0;
}

Here is a table of the changes I have made to convert to the Mega:

I basically just changed Port B on the Duemil. to Port A on the Mega, and Port D → Port L, and kept Port C the same. The exception is the Output Enable pin, for which I originally thought I needed to preserve OC2A for the interrupt (I don’t think it mattered).

I’d be happy to answer any questions you may have. Thanks in advance!

Hello

could anybody help me with led cube 8x8x8 controlled by arduino

can you explain idea,how leds are controlled and how it take signal from ICs and microcontroller?

thank you

See the instructables link for details. I did end up fixing this, and it works great! I had the data bus screwed up in my wiring (MSB/LSB)