Go Down

Topic: different errors that arose when making 3x3x3 white LED cube (Read 679 times) previous topic - next topic

nsivakumar

Jan 13, 2019, 03:45 am Last Edit: Jan 13, 2019, 03:09 pm by nsivakumar Reason: did not attach document
Hello,

I recently made a 3x3x3 LED cube using white LEDs using the instructions on
https://circuitdigest.com/microcontroller-projects/making-3X3X3-led-cube-with-arduino

I faced a couple of problems and now I have to do a workshop related to it so I need to know why those errors occurred.
I have attached the code to the post.

1) As you can see in the code, in order to power an led I have to do DigitalWrite(layer, HIGH) and then DigitalWrite(column, LOW)
My question is that normally we would have to do DigitalWrite(column, high). I figured out the code through trial and error. Is it because the anodes and cathodes got switched?  I tried to do according to the schematic on the website, columns have common anodes and layers have common cathodes.

2) when applying this code, if I want to light up the entire cube (the first line pattern in the code), the brightness of the led decreases. Is this because I didn't use a transistor? I powered it using the USB port in my laptop(5V). Or is this because we used only 3 resistors of 2220 ohms.

3) is it necessary to use a transistor in a 3x3x3 LED cube?

4) Should the resistors be connected to each layer or each of the columns?

5) I want to be able to switch only one LED in the entire cube. What would be the code to do that?

I added the code below because it wouldn't attach for some reason.


Code: [Select]
void setup() {
int d=100;
   pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
   pinMode(9, OUTPUT);
   pinMode(10, OUTPUT);
   pinMode(A0, OUTPUT);
   pinMode(A1, OUTPUT);
   pinMode(A2, OUTPUT);

    }  


void loop() {
   
digitalWrite(A2, HIGH);
digitalWrite(A1, HIGH);    // lights up entire cube
digitalWrite(A0, HIGH);
   
digitalWrite(2,LOW);
delay(d);
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
delay(d);                     // snake column wise
digitalWrite(3, HIGH);
digitalWrite(4,LOW);
delay(d);
digitalWrite(4,HIGH);
digitalWrite(7,LOW);
delay(d);
digitalWrite(7,HIGH);
digitalWrite(6,LOW);
delay(d);
digitalWrite(6,HIGH);
digitalWrite(5,LOW);
delay(d);
digitalWrite(5,HIGH);
digitalWrite(8,LOW);
delay(d);
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
delay(d);
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
delay(200);

digitalWrite(10,HIGH);
digitalWrite(9,LOW);
delay(d);                     // snake column wise rewind
digitalWrite(9, HIGH);
digitalWrite(8,LOW);
delay(d);
digitalWrite(8,HIGH);
digitalWrite(5,LOW);
delay(d);
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
delay(d);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
delay(d);
digitalWrite(7,HIGH);
digitalWrite(4,LOW);
delay(d);
digitalWrite(4,HIGH);
digitalWrite(3,LOW);
delay(d);
digitalWrite(3,HIGH);
digitalWrite(2,LOW);
delay(200);



digitalWrite(A0, LOW);
digitalWrite(A1, LOW);
digitalWrite(A2, LOW);

digitalWrite(A2, HIGH);
digitalWrite(2,LOW);
delay(d);
digitalWrite(2,HIGH);
digitalWrite(5,LOW);
delay(d);                     // snake pin wise top layer
digitalWrite(5, HIGH);
digitalWrite(8,LOW);
delay(d);
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
delay(d);
digitalWrite(9,HIGH);
digitalWrite(6,LOW);
delay(d);
digitalWrite(6,HIGH);
digitalWrite(3,LOW);
delay(d);
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
delay(d);
digitalWrite(4,HIGH);
digitalWrite(7,LOW);
delay(d);
digitalWrite(7,HIGH);
digitalWrite(10,LOW);
delay(d);
digitalWrite(10,HIGH);


digitalWrite(A0, LOW);
digitalWrite(A1, LOW);
digitalWrite(A2, LOW);

digitalWrite(A1, HIGH);
digitalWrite(10,LOW);
delay(d);
digitalWrite(10,HIGH);
digitalWrite(9,LOW);
delay(d);                     // snake pin wise middle layer
digitalWrite(9, HIGH);
digitalWrite(8,LOW);
delay(d);
digitalWrite(8,HIGH);
digitalWrite(5,LOW);
delay(d);
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
delay(d);
digitalWrite(6,HIGH);
digvitalWrite(7,LOW);
delay(d);
digitalWrite(7,HIGH);
digitalWrite(4,LOW);
delay(d);
digitalWrite(4,HIGH);
digitalWrite(3,LOW);
delay(d);
digitalWrite(3,HIGH);
digitalWrite(2,LOW);
delay(d);
digitalWrite(2,HIGH);


digitalWrite(A0, LOW);
digitalWrite(A1, LOW);
digitalWrite(A2, LOW);

digitalWrite(A0, HIGH);
digitalWrite(2,LOW);
delay(d);
digitalWrite(2,HIGH);
digitalWrite(5,LOW);
delay(d);                     // snake pin wise bottom layer
digitalWrite(5, HIGH);
digitalWrite(8,LOW);
delay(d);
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
delay(d);
digitalWrite(9,HIGH);
digitalWrite(6,LOW);
delay(d);
digitalWrite(6,HIGH);
digitalWrite(3,LOW);
delay(d);
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
delay(d);
digitalWrite(4,HIGH);
digitalWrite(7,LOW);
delay(d);
digitalWrite(7,HIGH);
digitalWrite(10,LOW);
delay(d);
digitalWrite(10,HIGH);

delay(200);





Paul__B

Well, I suppose you realise by now that design is dodgy (faulty).

For a start, the resistors are wrong - you should have nine resistors in the column wires not three in the rows (levels), and they should be at least 1k.  This will bring the LED current down to 3 mA each and 27 mA for the whole nine lit simultaneously with which the pin driver can cope - given that you are multiplexing one row at a time.  If you try to illuminate the whole lot at once - activating all rows together, then you will be sharing that 3 mA among three rows, but the effect will be (almost) the same as multiplexing one row after another.

If you really want to build a single colour 4 by 4 cube, you should use one of the readily available MAX7219 modules which is designed to multiplex 64 LEDs with good and uniform brightness.



Now, You need to go and read the forum instructions so that you can go back and modify your original post - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window.  Just highlight each section of code (or output) from the IDE and click the icon.  In fact, the IDE has a "copy for forum" link to put these markings on to a highlighted block for you so you then just paste it here in a posting window.

It is inappropriate to attach it as a ".ino" file.  People can usually see the mistakes directly and do not want to have to actually load it in their own IDE.  And that would also assume they are using a PC and have the IDE running on that PC.

But don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read.  If you do not post it as "code", it can be quite garbled and is always more difficult to read.

Blackfin

Yeah, the resistor positions are not ideal but for basic testing will tell you if you're on the right track.

You need to multiplex this sort of display. That means rapidly cycling through the layer "commons" and turning on the LEDs on each layer at the right time. This happens at a rate that meets the "persistence of vision" criteria; for this sort of thing, going through all 3 layers in ~20-30mS should give that effect.

By using muxing, addressing a single LED in the matrix is easy. If you don't mux, the cube's usefulness is severely compromised.

I modified your code to support multiplexing. I didn't feel like transcribing your patterns so I made a simple "walk an LED through the matrix" pattern. You can make anything you like.

It's somewhat more complex than your code and may not work out of the gate.

Code: [Select]
const unsigned long CUBE_DELAY_SHORT = 100;     //mS
const unsigned long CUBE_DELAY_LONG = 200;      //mS

//assumes each panel is wired like this (view from top)
// 2 3 4
// 5 6 7
// 8 9 A

#define NUM_PATTERNS    28      //27 LEDs plus all off

//local prototypes
void SetPlane( byte );
void DriveLEDMatrix( void );
void UpdatePlaneVars( void );

const int LAYER_0 = A0;
const int LAYER_1 = A1;
const int LAYER_2 = A2;

#define NUM_LEDS_PER_PLANE      9
#define COL_UPDT_RATE           10  //mS per layer
#define LAY_0                   0
#define LAY_1                   1
#define LAY_2                   2

#define LAYER_ON                HIGH
#define LAYER_OFF               LOW
#define LED_OFF                 HIGH    //with common anode
#define LED_ON                  LOW

struct patternStruct
{
    int Plane_2;
    int Plane_1;
    int Plane_0;
};

typedef struct patternStruct Patterns;

Patterns LEDPatterns[NUM_PATTERNS] =
    {
        {0x0000, 0x0000, 0x0001},
        {0x0000, 0x0000, 0x0002},
        {0x0000, 0x0000, 0x0004},
        {0x0000, 0x0000, 0x0008},
        {0x0000, 0x0000, 0x0010},
        {0x0000, 0x0000, 0x0020},
        {0x0000, 0x0000, 0x0040},
        {0x0000, 0x0000, 0x0080},
        {0x0000, 0x0000, 0x0100},
        {0x0000, 0x0001, 0x0000},
        {0x0000, 0x0002, 0x0000},
        {0x0000, 0x0004, 0x0000},
        {0x0000, 0x0008, 0x0000},
        {0x0000, 0x0010, 0x0000},
        {0x0000, 0x0020, 0x0000},
        {0x0000, 0x0040, 0x0000},
        {0x0000, 0x0080, 0x0000},
        {0x0000, 0x0100, 0x0000},
        {0x0001, 0x0000, 0x0000},
        {0x0002, 0x0000, 0x0000},
        {0x0004, 0x0000, 0x0000},
        {0x0008, 0x0000, 0x0000},
        {0x0010, 0x0000, 0x0000},
        {0x0020, 0x0000, 0x0000},
        {0x0040, 0x0000, 0x0000},
        {0x0080, 0x0000, 0x0000},
        {0x0100, 0x0000, 0x0000},
        {0x0000, 0x0000, 0x0000}    //all LEDs off
    };

byte
    stateMatrix;

int
    DispPlane_0,
    DispPlane_1,
    DispPlane_2;

int
    pinPlaneLED[NUM_LEDS_PER_PLANE] =
    {
        2, 3, 4, 5, 6, 7, 8, 9, 10
    };
   
void setup()
{
    for( int i=0; i<NUM_LEDS_PER_PLANE; i++ )
    {
        pinMode( 2+i, OUTPUT);
        digitalWrite( 2+i, LED_OFF );
       
    }//for
   
    pinMode(A0, OUTPUT);
    digitalWrite( A0, LAYER_OFF );
    pinMode(A1, OUTPUT);
    digitalWrite( A1, LAYER_OFF );
    pinMode(A2, OUTPUT);
    digitalWrite( A2, LAYER_OFF );
   
    stateMatrix = LAY_0;

}//setup

void DriveLEDMatrix( void )
{
    static unsigned long
        timeMatrix = 0;
    unsigned long
        timeNow;

    timeNow = millis();
    if( (timeNow - timeMatrix) < COL_UPDT_RATE )
        return;

    timeMatrix = timeNow;

    switch( stateMatrix )
    {
        case    LAY_0:
            digitalWrite(LAYER_0, LAYER_ON);
            digitalWrite(LAYER_1, LAYER_OFF);
            digitalWrite(LAYER_2, LAYER_OFF);
            stateMatrix = LAY_1;
           
        break;
        case    LAY_1:
            digitalWrite(LAYER_0, LAYER_OFF);
            digitalWrite(LAYER_1, LAYER_ON);
            digitalWrite(LAYER_2, LAYER_OFF);
            stateMatrix = LAY_2;
        break;
        case    LAY_2:
            digitalWrite(LAYER_0, LAYER_OFF);
            digitalWrite(LAYER_1, LAYER_OFF);
            digitalWrite(LAYER_2, LAYER_ON);
            stateMatrix = LAY_0;
        break;
           
    }//switch

    SetPlane( stateMatrix );
   
}//DriveLEDMatrix

//called from within the matrix drive code, this
//sets the LEDs for the current layer
void SetPlane( byte stateMatrix )
{
    int
        i,
        mask,
        Plane;
       
    switch( stateMatrix )
    {
        case    LAY_0:
            Plane = DispPlane_0;
        break;

        case    LAY_1:
            Plane = DispPlane_1;
        break;

        case    LAY_2:
            Plane = DispPlane_2;
        break;
    }//

    //Plane LEDs are expressed as bits within an int (2 bytes):
    //0bxxxxxxx000000000
    //         098765432
    //         1
    //the upper bits are not-care (x)
    //the logic below walks through the variable holding the pattern for
    //  the current panel and turns on/off the LEDs as required
    mask = 0x0001;
    for( i=0; i<NUM_LEDS_PER_PLANE; i++ )
    {
        digitalWrite( pinPlaneLED[i], (Plane & mask) ? LED_ON:LED_OFF );
        mask << 1;
                 
    }//for
   
}//SetPlane


void UpdatePlaneVars( void )
{
    static int
        planeIndex = 0;
    static unsigned long
        timeDelay = 0,
        timePlane = 0;
    unsigned long
        timeNow;

    timeNow = millis();
    if( ( timeNow - timePlane) < timeDelay )
        return;

    timePlane = timeNow;

    DispPlane_0 = LEDPatterns[planeIndex].Plane_0;
    DispPlane_1 = LEDPatterns[planeIndex].Plane_1;
    DispPlane_2 = LEDPatterns[planeIndex].Plane_2;
   
    planeIndex++;
    if( planeIndex == NUM_PATTERNS )
    {
        planeIndex = 0;
        timeDelay = CUBE_DELAY_LONG;
    }
    else
        timeDelay = CUBE_DELAY_SHORT;
       
}//UpdatePlaneVars

void loop()
{
    DriveLEDMatrix();
    UpdatePlaneVars();
   
}//loop

Grumpy_Mike

Do you think you are going to provide any sort of valuable educational experance presenting a workshop of a faulty design, with you knowing so little about it and with such very bad software?

It seems to me that the trouble with the maker movement at the moment is that anyone who can get an LED to blink thinks they are qualified to teach others.

Paul__B

I think you are saying what I was saying, but were you addressing it to the OP or "Blackfin"?

AWOL

Code: [Select]
void setup() {
int d=100;
Oops

(And also suggests the code is incomplete)

Paul__B

I didn't follow that - but in any case I am waiting for some response from the OP.

Blackfin

I think you are saying what I was saying, but were you addressing it to the OP or "Blackfin"?
?

AWOL

I didn't follow that - but in any case I am waiting for some response from the OP.
'd' isn't used in setup(), but is used in loop().
loop() has no definition for a variable called 'd'

nsivakumar

First of all, thank you everyone for reply.

Do you think you are going to provide any sort of valuable educational experance presenting a workshop of a faulty design, with you knowing so little about it and with such very bad software?

It seems to me that the trouble with the maker movement at the moment is that anyone who can get an LED to blink thinks they are qualified to teach others.
To answer your question, I will merely be assisting the workshop. A more qualified person will be the one  in charge. Andthought I should get my errors cleared. And no. Now I won't be using this design. But thank you for your valuable advice

PaulRB

Now I won't be using this design. But thank you for your valuable advice
+1 Karma

If you want to continue the project for your own education, we will be happy to help. Now we know you won't be spreading bad practices, I'm sure we will be more supportive.

nsivakumar

So does anybody have any recommendations like any website/book that has good coding information/guides so I can learn how to code an LED cube the right way?

PaulRB

I think it would be a mistake to focus only on the coding. Please post your schematic. A schematic you have made. Because with most Arduino projects, half the story is the circuit and half is the code.

Blackfin

So does anybody have any recommendations like any website/book that has good coding information/guides so I can learn how to code an LED cube the right way?
Did you have a look a the code I posted earlier?

nsivakumar

Did you have a look a the code I posted earlier?

Yes, I did and as you said, the code is too complex for me to understand.

I think it would be a mistake to focus only on the coding. Please post your schematic. A schematic you have made. Because with most Arduino projects, half the story is the circuit and half is the code.
I have attached a rough schematic, I apologize for the untidiness.


Go Up