# LED matrix with mixed pin order

I'm going to make LED matrix which is driven by Arduino nano and two '959 shift registers. The problem is pins of my LED matrix doesn't match with row's and columns, I mean they aren't in any specific order. There are pins of rows and columns on both 8-pin connections.

I want to be able to copy codes and patterns created by online matrix generators but of course they won't work on my sketch.

What is the best way to convert online generated hex or binary variable that contains information for the matrix to variable that works on my matrix?

My matrix is 1088BS.

The problem is pins of my LED matrix doesn't match with row's and columns

the easiest way is to fix that..

The matrix came with my Arduino uno kit and I want to get it working. I know it would be much easier with a matrix with pins connected to logical order but maybe I'll learn something new if I get this to work.

I just need to know how I could convert the variables to match the order of my martix's pins. How can I read for example variables 4. binary digit? This is how I could convert the variables to match with my matrix binary by binary.

what about having wires? easy then to have them cross over to be in the right order...

can you show some code you plan to use? you need to look at the bits being sent and re-order those bits to match the real layout of your matrix

J-M-L:
what about having wires? easy then to have them cross over to be in the right order...

I'm going to solder this project on PCB. I have PCB's with straight copper traces, so I'm going to connect '595's straight to the matrix and figure out the problem with pin order on the sketch.

J-M-L:
can you show some code you plan to use? you need to look at the bits being sent and re-order those bits to match the real layout of your matrix

I don't have any code yet. I made a PCB earlier with a shift register and 7-segment display. This would be pretty similar. I just counted the binary values for all the digits from 0 to 9 and sent them to shift register.

I found a thread what could help me with getting binaries out of variables and re-order them. There are few ways to do it. Here's the thread: Converting int into char array. - Programming Questions - Arduino Forum

And thanks for those tutorials, I'll get to them!

well don't make it overly complicated

if `b1` is your byte you want to send, it has 8 bits `76543210` and you know you want to reorder them as `67345210` into a new variable `b2`

you can do the brute force, hardcoded way

``````byte b1, b2;
b1 = B01101100; // whatever you need

b2 = 0;
if (bitRead(b1,0)) bitSet(b2, 0); // 0 --> 0
if (bitRead(b1,1)) bitSet(b2, 1); // 1 --> 1
if (bitRead(b1,2)) bitSet(b2, 2); // 2 --> 2
if (bitRead(b1,3)) bitSet(b2, 5); // 3 --> 5
if (bitRead(b1,4)) bitSet(b2, 4); // 4 --> 4
if (bitRead(b1,5)) bitSet(b2, 3); // 5 --> 3
if (bitRead(b1,6)) bitSet(b2, 7); // 6 --> 7
if (bitRead(b1,7)) bitSet(b2, 6); // 7 --> 6
// here b2 has the right order
``````

or a more flexible way, you define a mapping array and use a loop

``````const byte pinMap[] = {0,1,2,5,4,3,7,6}; // what 0,1,2,3,4,5,6,7 maps onto

byte b1, b2;
b1 = B01101100; // whatever you need

b2 = 0;
for (byte i = 0; i<8; i++)
if (bitRead(b1,i)) bitSet(b2, pinMap[i]);
// here b2 has the right order
``````

hope this helps

That's exactly what I was looking for. Thanks a lot! I'm still waiting for my shift registers to arrive. Meanwhile I can try to finish my coding.

The LED matrix pins are laid out in a very specific (but still a bit mixed up) order:

If the image hosting disappears, here's the same thing in text:

``````  (16) C8 C7 R2 C1 R4 C6 C4 R1 (9)
-----------------------
(R1C1)(R1C2)(R1C3) ...       (R1C8)
(R2C1)
(R3C1)
...

(R8C1)
-----------------------
v
(1) R5 R7 C2 C3 R8 C5 R6 R3 (8)
``````

The use of bit operations for reordering bits in the values that get shifted out to shift registers requires microcontroller processing power at runtime. On the other hand, optimizing the wiring on the PCB requires more effort during PCB design and production, but does not add any overhead at runtime.

If you wanted to increase the screen refresh rate, or needed to save some clock cycles for other, more important, tasks performed by the microcontroller (assuming it does not just drive the LED matrix), you may still find it better to optimize in hardware than in software.