This tutorial was featured on the official Arduino blog on 3/9/2011
Update (6/7/2012) – I’ve had to disable comments on this post, because it is being targeted by spam bots for some reason. Please use the contact page if you have a question about this topic.
In this week’s arduino tutorial, we’ll be taking a look at SPI device control using the arduino. Specifically, we’re going to be using the Analog Devices 5204 Digital Potentiometer to control the brightness of several LEDs. For an example of another device that uses SPI control, checkout these Sparkfun RGB LED matrices that I’m using in my ReacXion Audio/Visual Theremin. Enjoy the video!
You can download the files associated with this episode here:
Distributed under the GNU General Public (Open-Source) License. Please Attribute and Share-Alike.













Pingback: Tweets that mention JeremyBlum.com » Arduino Tutorial 8: SPI Interfaces -- Topsy.com
February 25, 2011 at 9:03 pm
hi Jeremy
thank you for the outstanding quality tutorials.
i’m following all of your tutorials, it’s all very helpful for beginners like me.
The last tutorial (8) on SPI was gave me little start on my SD card project.
but I’m having hard time on finding a good example. I’m using Arduino UNO and SD card and some resistors for voltage divider. can you please make one tutorial on this it will be very helpful.
thank you
February 26, 2011 at 1:27 pm
What are the components you are using? Which SD card reader. I can’t make a tutorial about every specific topic, but I can try to help you.
March 1, 2011 at 11:05 pm
Thanks for your reply.
I’m using micro SD card reader that i found on sparkfun http://www.sparkfun.com/products/544
which has the following pins
CD,DO,GND,SCK,VCC,DI,CS
and i’m using 4 photo resistors same ones you used for the youtube tutorial (03). i need to store all 4 light values (Serial.prints) on the SD card real-time text document (.txt).
Pingback: Arduino Blog » Blog Archive » Must-See Beginner Tutorials For Arduino
April 11, 2011 at 3:03 am
Warning: Dumb question incoming. :)
In the schematic you have B1, 2 and 3 each going to their own 10K resistor, and then tied together at ground.
What would be the practical implications/problems of tying all three together first, and then going through a single resister to ground?
April 11, 2011 at 11:25 am
Not a dumb question at all! The 10k pull down resistors are creating a voltage divider with each of the internal 10k potentiometers. If we just used one resistor for all of them, then all the 10k potentiometers would be connected in parallel, effectively changing the values we would expect to see.
April 12, 2011 at 2:04 am
Thanks Jeremy :)
May 11, 2011 at 10:17 pm
Thanks for the great video, clear and simple!
I was wondering, how do you control speaker volume with this? Any example?
thanks.
May 14, 2011 at 6:37 pm
You couldI explain it in this video: http://jeremyblum.com/2010/08/27/reacxion-build-progress/
You basically just adjust a resistance in series with the speaker.
May 23, 2011 at 10:58 pm
Awesome tutorial Jeremy.
Just a small correction: eagle is not open source.
Thanks dude, I’m anxious for you new tutorials …
8-)
June 26, 2011 at 4:41 pm
It’s not a “washer”, it’s W for “Wiper”. Also, I was really hopefully you would cover multi-device using one cs pin…
June 27, 2011 at 8:32 pm
I know, you’re not the first to mention that. Minor mis-statement on my part.
October 12, 2011 at 1:24 am
Hi Jeremy,
very great tutorial(s). Awesome.
I was wondering if maybe you as a pro could help me with this one:
I am using a TLC 5490 on a Mega board. The TLC requires following SPI PINs:
Mega pin 51 (MOSI) -> SIN (Tlc pin 26)
Mega pin 52 (SCK) -> SCLK (Tlc pin 25)
Mega pin 11 (OC1A) -> XLAT (Tlc pin 24)
Mega pin 12 (OC1B) -> BLANK (Tlc pin 23)
Mega pin 9 (OC2B) -> GSCLK (Tlc pin 18)
However it is not using a CS.
Now I would like to add the Ethernet ENC28J60 Breakout Shield which also uses SPI:
NT Digital 2
SO Digital 12
SCK Digital 13
RESET RESET
GND GND
SI Digital 11
CS Digital 10
VCC 3,3V
I know that the MEGA uses different PINs for SDI than the smaller brothers, thats not the prob.
The problem I see is that the TLC doesnt use SC which (I think) means that the TLC will always be called and I cannot call the ENC.
Anyways, I am not a pro at all, I got most of my knowledge out of forums and tutorials.
SO thats why Id like to ask you whethter you can help me on this one with a few ideas to solve the double SPI usage for these specific devices on a MEGA board.
One more thing:
the ENC requires 3.3v with (as I heard and read) about 250mA. Do you think I can try the 3.3v output of the MEGA anyways (though only gives up to 40 mA)? Instead, can I use the 5v Output without a voltage converter? As I read the ENC board is 5v tolerant. Some use 2x 1N4007 diodes between 5vOut and 3.3vIn but I am not quite sure if this is necessary or not. Others talk about a LM317 (which has a too big Drop Out) or rather a LM 3940 but I am still not sure if this is necessary at all.
Hope you can hellp me, especially on the SPI usage.
Would be great
Best//
Thorsten
October 28, 2011 at 2:38 pm
For the TLC 5490, how about you hook the 5V supply up through a transitor to a digital logic pin, and physically switch of power to the device when you are talking to Ethernet shield? As for the ENC, you should use an external supply regulated to 3.3V to power it. Don’t use 5V directly, and don’t bother trying to use the built-in 3.3V regulator. It won’t provide enough current.
October 29, 2011 at 10:35 am
Well, might be an idea to think about. Just wondering – when turning off power of the tlc, even for 1-5secs, while communicating with the encshield – what will happen to my LEDs connected to the TLC? will they stay as they are? (e.g. at 50% PWM = 2048)?
Anyways – if this would work – can you be more specific why I would need a transistor? COuldnt I just use the PIN as voltage instead of 5v and not using a transitor?
Anyways – Would Pin21/Vcc (http://www.pjrc.com/teensy/td_libs_Tlc5940.html) be the one you mean?
Would this transistor work (since I still have these in my electronic supply box): BC 337-40 Transistor NPN TO-92 45V 0,5A 0,625W
For the Encboard I bought myself a LM1117 Low Dropout Voltage Regulator 3.3V, that should work since it provides up to 800mA. Will use two 22 µF 6V Tantalum Capacitors – on each side one. You think 6v will work for this, even on the 5v Vin? (hope so cause i have these available)
Thx a lot for helping me out on this
October 29, 2011 at 9:54 pm
No, the LEDs would turn off, because you removing power to the board. Presumably, this is not what you want…. If programmed effectively, it might be so fast that you don’t notice them turn on then off again.
I suggested a transistor, because using the current provided by a logic pin will not be enough to light the LEDs. You can use that current to switch a transistor, that will then provide power to the LED board. You wouldn’t use the Vcc pin, you’d use a logic pin that you should switch in software.
The TO-92 will work fine for this purpose.
I’m confused by your 6V question. What in your system is 6V? Is there a 6V battery? Feed anything beteween 4.75 and 10V into the LM1117, and you’ll get the 3.3V output that you need.
January 8, 2012 at 12:24 pm
Could you have programmed the maximum voltage to the LEDs to ~3V and gotten rid of the resistors going into them?
January 9, 2012 at 11:30 pm
Yes, but its hard to get that exactly right, and using a current limiting resistor is always good practice.
January 12, 2012 at 5:35 pm
Hi Jeremy, Excellent tutorial, i have been looking for something like this for a while.
I am a complete noob and was planning on adapting this method to use on a 8 channel dac chip. Im trying to send analogue signals to 6 servo amplifiers. The desired values for the signals will be calculated from a flight sim software. For the SPI registers and levels Is it possible to use real time values from another program instead of just using predetermined values? Thanks
January 14, 2012 at 5:50 pm
Yes, you should be able to use a serial connection to get those values, and feed them as variables into the SPI commands.
June 4, 2012 at 11:31 am
Hi Jeremy,
I am an absolute beginner and I just have to say I am really enjoying this series, I have learned so much!
I am having trouble deciding which components are suitable or better then others for certain circuits. For my first major project I want control multiple leds (30+), more then the arduino would allow. Would a digital pot like this be suitable or is this more of a shift register thing? Can I still use PWM on either method?
Any help would be greatly appreciated.
FYI. I have looked into multiplexing but I dont understand how it works.
Pingback: Tutorials for Arduino Getting Acquainted with Arduino - Arduino for ProjectsArduino for Projects