LED Cube Programming

Need Help!!! Ive built my 8x8x8 led cube but i cant for the life of me figure out the programming for it.
I have code for the uno but Im using a mega2560. Could someone please give me some guidance as to how to make it work? I feel like im trying to learn this programming thing backwards… Thanks!!

attached is the code i have. It was written By CHR on instructables i guess.

Im using these pin’s on the Mega2560

30-37 for the Data Bus for latches
50 for output enable
51-52 for address bus for latches
42-49 for layer select

arduinocube.ino (12.8 KB)

Important code bit. the rest are just the animations for the cube

#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
 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;
}

if (current_layer == 8)

Never come across a cool smilie as a quantity to compare to.

This is why we have rules about posting code. We also have rules which suggest how to ask a question and what information you need to give. Please read them:- How to use this forum

Not merely a cool smilie, but an italic cool smilie.

better? literally first post ive made here.

Thefleshman: better?

Yes thanks. BUT the software means nothing without knowing the hardware it is supposed to be driving. Did you miss that when you read those rules?

ok ill try again to explain what im trying to do. I am building an 8x8x8 led cube. I am using an instructable written by chr. http://www.instructables.com/id/Led-Cube-8x8x8/

|500x297|500x360

I am using these schematics for my circuit.

everything is identical to his except the avr board.

I am using an arduino Mega2560 instead of the UNO and the code given is not compatible because the ports on the microcontrollers are different. Im trying to figure out how to wire my mega board and modify the UNO code to work with each other. I do know that i am trying to write an interrupt routine and use a timer to do it.

I have zero experience with any code written outside of the arduino platform and his code uses the registers directly. Tell me exactly what other information you need and i will gladly give it. Im just afraid that if i go too much further ill just confuse you. I dont speak programming. I have just scratched the surface.

Ok so this is the code ive got so far.

#include <avr/interrupt.h>
#include <string.h>
#include <math.h>
#define AXIS_X 1
#define AXIS_Y 2
#define AXIS_Z 3
int CUBE_SIZE = 8;

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

void setup()
{
int i;

for(i=0; i<54; i++)
pinMode(i, OUTPUT);

// pinMode(A0, OUTPUT) as specified in the arduino reference didn't work. So I accessed the registers directly.
DDRL = 0xff;
PORTL = 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
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
PORTL = 0x00;
PORTB &= 0x0f;

PORTB |= 0x08; // output enable off.

for (i=0; i<8; i++)
{
PORTC = cube[current_layer][i];
PORTB = (PORTB & 0xF8) | (0x07 & (i+1));
}

PORTB &= 0b00110111; // Output enable on.

current_layer++;

if (current_layer == 8)
current_layer = 0;
}

Nothing was working and i started grounding my cube and Holy crap its working…sortve. My transistors are not grounding like they are supposed to do. Is that a code thing or hardware thing?

Im going to do some more troubleshooting and see if my transistors are firing.

again any real help would be awesome. Im pulling my hair out

ok ive checked my transistors and im not getting signal to my bases. Which means the arduino is not doing what its supposed to. Any ideas?

Any ideas?

Get an oscilloscope onto the output pins.

Unfortunately I don't own a oscilloscope. What I meant though is the pins are not putting out any voltage. I think it has something to do with the code.

So, simplify the code until you do get some output.

ok i think i found it. I cut out a bit of code that i needed. Gonna try it when i go to lunch.

I will post the final code when im done with all this. Hopefully it will help someone out.

K I finally figured it out. Attached is the final code.

If you want to use it here are the corresponding pins for the arduino mega2560.

Address bus
51-53

Layer select
42-49

Data bus
30-37

Output enable
50

Final_cube_code.ino (13.6 KB)