Go Down

Topic: Full-colour RGB 4x4 button pad (monome-esque) (Read 7 times) previous topic - next topic


Mar 02, 2008, 08:45 am Last Edit: Mar 02, 2008, 08:47 am by big93 Reason: 1
ok, i have an idea, and i'm sure it'll work.

if you can... tell me what pins on the arduino, are connected to the other side, becuase the picture confuses me, especially the connection the the digital pots.

so if you could tell me where every used pin on the arduino goes to (ex pin 12 arduino to pin 5 digital pot )
i'm sure my project could work, becuase i am certain that the wrong pins are in the wrong place, and that has to be the problem!

thanks in advance, and if u need any links, just tell me...


here is the link to the digital pot page where it shows the pins, so you can identify it easier...


big93, all of the connections are defined in the code, in the defines and variables at the top. It may be different in different examples I have posted, so look at the code you're using and either use those pins, or change the defines to meet your needs. I long ago disassembled my version of the project, so this code is all I have to go on myself.

Here are the relevant lines from the "color fading" example, and an explanation of what they're saying. The first three must not be changed, since they're hardware features of the SPI, and make sure you're using Arduino pin 10 as an OUTPUT only, otherwise it will mess up the hardware SPI, too. Other than that, they can all be changed.

The data connections for the digital pot (can't be changed):
Code: [Select]
#define DATAOUT 11//MOSI (pin 7 of AD5206)
#define DATAIN 12//MISO - not used, but part of builtin SPI
#define SPICLOCK  13//sck (pin 8 of AD5206)

The LED "row" select, and the two slave select lines for the digital pot. Also, the defined function "slavesel" chooses which digital pot to send the data based on the pot register numbers.
Code: [Select]
#define slavesel(x) ((x<6) ? 0 : 1)
const byte rowpin[ROWS] = {
const byte slaveselect[2] = {
 10, 18};

The pins for writing to and reading from the buttons.
Code: [Select]
const byte buttonRead[4] = {
 5, 2, 3, 4}; //Pins for the Vin of the buttons
const byte buttonWrite[4] = {
 6, 7, 8, 9}; //Pins for reading the state of the buttons

All of the above refer to Arduino pins. Pins 14, 15, 16, and 17 are analog pins 0, 1, 2, and 3, respectively.

The following code does not refer to Arduino pins, it refers to which digital pot registers to which the various color lines are connected. The "slavesel" function below is used to choose which chip the number refers to (the first chip if the number is 0-5, and the second if it is 6-11), and a modulo function (% sign) is used to shift the numbers higher than 5 down to make sense when talking to the chip.

Code: [Select]
// The pot register numbers for each of the red, green, and blue channels
const byte red[4] = {
 8, 7, 2, 5};
const byte green[4] = {
 10, 6, 0 , 3};
const byte blue[4] = {
 11, 9, 4, 1};

I can't emphasize this enough, those are not Arduino pins. If you happened to use them that way, then that could definitely be the source of your problems!


ok that makes more sense now... So I just need to know that all pins can be rearanged except for arduino pin 10. but the code will definitly help, now I can get the pins in the right place.

But to be honest, you have soon much code, you should just go a little extra way, and make a library out of it with the simple ability to bring up any button and give 3 colors to blend ( r g b ). But since you discontinued this, I guess it won't matter...

Thanks for the help, and I'll message back as soon as I have results( hopefully good results)

P.S I bought those same transistors to replicate your project as close as I can to hopefully make it work.


ok, so as far as i see, it seems that everything is hooked up fine.
now i tried messing with the wiring, and after simply connecting one led gnd to the middle transistor pin, it changes colors sometimes, but not smothly. its verry sudden, be aware, that buttons are not hooked up yet becuase i just wanted to see if the lights pwm like they are sapposed to... obviously they arent... wires are all correct, and i even tried a "debug" led thats connected right from the digital pot resistor to gnd, and its not changing smoothley.... very sudden, i can't put my finger on whats wrong, as of now, everything seems to be hooked up perfectly.

i might just scrap the way it's put together, and try to put it together on my own, becuase maybe itll make more sense...

but before i do that, i have to understand how you tell the second digital pot chip what to do...

i'm confused how you communicate between the second digital pot, and how you "switch between them"

so heres what i think you do, and please correct me if i'm wrong, so i don't mess up the chips...

i think you turn the master slave chip for one on, and the other off by either setting it to high ( on ) or low ( off ). And then you just comunicate like your talking to one chip becuase the clock and data pins are connected. is this correct?
And as for the transistors... are they REALLY REALLY neccasery, i think theyre just dead weight, unless they really help becuase i think a resistor might just slow enough current, before it entars the arduino, and the transistors just confuse me becuase i think they might be the source of my failure... if they savge the arduino, ill keep them ,but if theyre a "just in case" i might have to leave em out...


ok that makes more sense now... So I just need to know that all pins can be rearanged except for arduino pin 10.

No, you can't rearrange pins 11, 12, or 13, either.

You are correct about how to communicate between the two pots.

I think you can probably get away without using the transistors; I used them just to be safe (and also, to make sure I knew what I was doing with the transistors!). Even if you've got all of the LEDs on at their full capability (20mA/color channel), that's still only 240mA at any one time, which I believe the Arduino can handle. To be extra safe, make sure that all twelve of the lines from the digital pot have a reasonably sized resistor on them to limit the current from each (the definition of "reasonable" is left as an exercise); it'll make the output dimmer, but you can always swap them out later for something with lower resistance.So, yes, I think you can get rid of them. Just don't expect me to buy you a new Arduino if it doesn't work!  ;) Also, you'll need to change the code a little bit: every time you see a digitalWrite to rowpin[r], change LOW to HIGH, and HIGH to LOW. I believe there will be three changes total.

Good luck!


Mar 05, 2008, 01:27 am Last Edit: Mar 05, 2008, 05:09 am by big93 Reason: 1
ive tried everything... it just doesent want to work! I started making my own code to test it and see if it workks, and i'm getting some results. I've succesfully made 4 colors on one row that can light up every button the same color by delaying them very fast. And also for some reason, the second digital pot won't work, even though i change slave select to 10... Does anything else need to be changed, or can everything stay the same except for slave select?
thanks again....


ok, so i tinkered around some more, and now i have half the buttons light up diffrent colors. Ill post a pic or maybe a vid on the tube.
I also half figured out why i couldent get the second digital pot working....:
i unhooked all the color wires from the second pot when i was re checking everything...
i only found it out when one wire accidentally touched a resistor, and the whole row 3rd row turned blue.

and 1 more thing...
in the first version you complained of the very very lack of bright intense colors, but ever since i removed the transistors AND the resistors connecting to the arduino pins, the arduino dident break, and the colors are so bright i can bring them into fairly bright rooms and still see them well....

hopefully when i hook up the other 2 rows, the current doesent add up and murder my arduino...
if you know this will happen, please warn me

and i have a youtube video up, showin it, also read the description because i purposely slow down the refresh rate...:


ok ok, only 1 more edit...

so i keep trying to make the second digital pot work, but it seems not to be working...
i hooked up the rest of the rgb led's the same way i hooked up the first digital pot, and i changed the slave select on my arduino code and the same thing thats been happening on the first side, is not happening on the other. I'll post the code further down... So i'm guessing that exactly the same thing should happen on the other side, but it doesent seem to do anything similarly... It doesent even have a refresh rate like the first pot, cuz when i slow it down with the pot, it doesent stop.


can you see my code and tell me if you see anything faulty please?


Code: [Select]
#define DATAOUT 11//MOSI
#define DATAIN 12//MISO - not used, but part of builtin SPI
#define SPICLOCK  13//sck
#define SLAVESELECT 10//ss*** it is either 10, or 18
byte potpin = 0;
byte r1=0;
byte g2=1;
byte g1=2;
byte b2=3;
byte b1=4;
byte r2=5;
byte res1=255;
byte res2=255;
byte res3=255;
byte res4=255;
byte res5=255;
byte res6=255;
char spi_transfer(volatile char data)
 SPDR = data;                    // Start the transmission
 while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
 return SPDR;                    // return the received byte

void setup()
 byte i;
 byte clr;
 pinMode(DATAIN, INPUT);
 pinMode(7, OUTPUT);
 pinMode(6, OUTPUT);
 pinMode(5, OUTPUT);
 pinMode(4, OUTPUT);
 digitalWrite(SLAVESELECT,HIGH); //disable device
 // SPCR = 01010000
 //interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
 //sample on leading edge of clk,system clock/4 (fastest)
 SPCR = (1<<SPE)|(1<<MSTR);
 for (i=0;i<6;i++)

byte write_pot(int address, int value)
 //2 byte opcode
 digitalWrite(SLAVESELECT,HIGH); //release chip, signal end transfer

void loop()
potpin = analogRead(0)/5+1;
digitalWrite(7, LOW);
write_pot(r2, 0);
write_pot(g1, 0);
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
write_pot(g1, 255);
write_pot(r1, 0);
write_pot(r2, 255);
write_pot(b2, 0);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
 write_pot(r1, 255);
 write_pot(b2, 255);
 write_pot(g1, 0);
 write_pot(b2, 0);
 write_pot(r2, 0);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
write_pot(b1, 0);
write_pot(g2, 0);
write_pot(g1, 0);
write_pot(b2, 255);
write_pot(r2, 255);
digitalWrite(4, HIGH);
write_pot(g2, 255);
write_pot(b1, 255);
write_pot(g1, 255);

looks ok to me.. and it works on the first digital pot....


did someone test it by making 8x8 buttons/Leds Matrix ?
I mean, by adding 3 other 4x4 buttons Leds matrix to the initial project ? ?

my project : http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1209311743
I'll have to drive a matrix of at least 8x5 RGB Leds and i'm a little bit stuck in this:


Yes, I have an 8x8 working:


Real life has gotten in the way of working on this project for a while, but one day, hopefully soon, I will be able to write up proper documentation and post the source code.


sadly, i never got the 4 by 4 working, it still is lying right infront of me, right here on my desk, i wish it worked, but that relay splitting pin 10 idea never worked out well

but maybe the dualcore arduino can fix that...


Yes, I have an 8x8 working:


Real life has gotten in the way of working on this project for a while, but one day, hopefully soon, I will be able to write up proper documentation and post the source code.

looking forward to it.


After that, I need to start thinking of ways to use the color on a button-by-button basis

Since i came across your project I had a couple of thoughts about ways that the monome sequencer/sampler patch 'mlr' could be modified to make use of the RGB leds.

I guess you already know, but just in case; mlr evenly 'splits' up audio files into rows of buttons (each button representing a diff offset from the start of the sample).

Using a max object link bonk~ it would be possible to analyze the slices and send colour information accordingly.

For instance it would be possible to check whether there was a significant transient close to the beginning of the slice or not. So in the case of drum beats it would be possible to colour the buttons representing main rhythmic accents differently from the others.

It may be feasable to figure-in an analysis of the frequency content of the transients too, so you could see which button represents a kick or a snare for instance.

Another, simpler, modification of mlr could be to colour entire rows based on a special prefix/suffix detected in the sample name. This way the user would be free to create a categorisation system for himself, and name different types of samples accordingly. Sample files ending with '_p', for percussive loops, could be configured to use red light. Bass-heavy samples '_b' might be blue, etc.

I'm watching your blog with interest :)


Yes, I have an 8x8 working:


Real life has gotten in the way of working on this project for a while, but one day, hopefully soon, I will be able to write up proper documentation and post the source code.

looking forward to it.

As do i.


About posting source code on blogger; This service is handy for transforming code into bloggerfriendly html: http://formatmysourcecode.blogspot.com/


my modest contribution to the arduino based monome clone RGB 8x8: the [bon]ome



hi guys.
i'm thinking to build a similar project but there's a problem.
the link doesn't work!!!
please someone can link me the istructions?
thank you a lot!

and sorry for my english :)

Go Up