4x4 LED Matrix not working

I've built a 4x4 LED matrix like this, but the LEDs are arranged in a linear way instead (like a LED strip). Btw the logic and the connections are the same, so i've tried running the code in that page, but no LED turned on.

Then i've tried connecting each column individally to the Arduino GND directly and this time 4 LEDs turned on correctly (except the 1st of each row which seems to blink).

It is likely i made some mistake since i am new to this kind of LEDs wiring...

Ahh dear.

Show us the photograph, perfectly focused and no wider than the web page.

Ok, here it is: pic1 pic2

From the left to the right on the breadboard you can see: - the LED anodes connected into rows; - the LED cathodes connected into columns; - an unconnected IC (which i'm going to use later)

The controller board is a Tamino Uno, which is an Arduino clone

The problem is that is never going to work without the meatballs and bolognese sauce!

Ok, in this case pictures are not going to help much. Can you post a schematic? Hand drawn and scanned/photographed is perfectly ok.

Paul

the schematic is exactly the same in the page i previously linked. The only difference is how the LEDs are arranged.

well, if everything is wired like that, it should work :p.

It's near impossible to help you here. What you're trying should work, if it doesn't, start going step by step to see where it's going wrong. You're already doing some good analysis by only trying 1 group of 4 leds, start experimenting with what works and what doesn't work, and when you've got more to tell us, come back :).

Maybe there was something wrong in the code in that page, i've written this function to turn on a single LED in the matrix and it works!

void turnOnLed( int x, int y )
{
/*
     Serial.print("debug turning on pins:");
     Serial.println(x, DEC);
     Serial.print(y, DEC);
 */

     pinMode(x, OUTPUT);
     digitalWrite(x, HIGH);
     pinMode(y, OUTPUT);
     digitalWrite(y, LOW);
    
    delay(1000);
   
    pinMode(x, INPUT);
    digitalWrite(x, LOW);
    pinMode(y, INPUT);
    digitalWrite(y, LOW);
}

What values of x and y light a led, for example?

Give us your complete sketch and we can compare the two sketches.

In the end i’ve rewritten the whole thing since i do not want to draw figures with the matrix, but address single LEDs individually:

byte anodes[4] = {5, 6, 7, 8};
byte cathodes[4] = {9, 10, 11, 12};

void clearAllPins()//make all pins 'floating' - so they do nothing
{
 for(byte i=0;i<4;i++)//code inside is executed 4 times with value 'i' increased every time
 {
  pinMode(anodes[i], INPUT);
  digitalWrite(anodes[i], LOW);
  pinMode(cathodes[i], INPUT);
  digitalWrite(cathodes[i], LOW);
 }
}


void turnOnLed( byte n )
{
  byte x = anodes[n>>2]; // compute the row  (n/4)
  byte y = cathodes[i&3];  // compute the col  (n%4)
  
  /*
  Serial.print("debug turning on pins:");
  Serial.println(x, DEC);
  Serial.print(y, DEC);
  */
  
     pinMode(x, OUTPUT);
     digitalWrite(x, HIGH);
     pinMode(y, OUTPUT);
     digitalWrite(y, LOW);
     
    delay(1);
    
    pinMode(x, INPUT);
    digitalWrite(x, LOW);
    pinMode(y, INPUT);
    digitalWrite(y, LOW);
}

void setup()
{
    Serial.begin(9600);
    clearAllPins();

}

void loop()
{
   /*
   byte n = Serial.parseInt();
   if(n>15) n=15;
   if(n<0) y=0;
  */
  
   for(int n=0; n<=15; n++)
     turnOnLed(n);
     
   return;
  
}

Now i think i will pass a custom delay time to turnOnLed, because i want to use it to display MIDI notes…

Well done for getting it working. Did you figure out why that other code did not work for you?

Try to avoid using delay() for long periods (I.e. more than a few milliseconds) because it might cause you problems later. Better to use millis() to time when to switch leds on or off.

I still have to figure out, maybe something has got altered in the copy-paste process... btw now i am just happy it is working!

I've also found an alternative wiring method called "charlieplexing" which could save some Arduino pins, but reportedly it is a bit less safe than this matrix method, do you agree?

eadmaster: I've also found an alternative wiring method called "charlieplexing" which could save some Arduino pins, but reportedly it is a bit less safe than this matrix method, do you agree?

No, there's nothing "unsafe" about it and a charlieplexed matrix is just a kind of matrix. For 16 leds, you would need 5 arduino pins (up to 20 leds in fact). With 8 pins you can charlieplex 56 leds. As long as you only light one led at a time, you don't need any other components (other than series resistors of course).

I will need to turn on up to 4 LEDs at a time, so i guess i will have to set a check to avoiding powering more than 2 LED from the same pin.

side question: For longer LEDs lifespan, is it better to have them blinking or constantly on?

For longer LEDs lifespan, is it better to have them blinking or constantly on?

Irrelevant question as your wiring scheme requires "blinking" in order to achieve multiplexing. Longer LED lifespan is achieved by not allow the LEDs to overheat.

eadmaster: I will need to turn on up to 4 LEDs at a time

Multiplex them, and have all 16 on at once if you want, using 4 ordinary npn transistors, like I did here.