JeremyBlum.com

v3.1

Tutorial 8 for Arduino: SPI Interfaces

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:

GNU GPL License Distributed under the GNU General Public (Open-Source) License. Please Attribute and Share-Alike.

23 Comments

  1. Pingback: Tweets that mention JeremyBlum.com » Arduino Tutorial 8: SPI Interfaces -- Topsy.com

  2. 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

  3. 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).

  4. Pingback: Arduino Blog » Blog Archive » Must-See Beginner Tutorials For Arduino

  5. 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?

    • 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.

  6. Thanks for the great video, clear and simple!

    I was wondering, how do you control speaker volume with this? Any example?

    thanks.

  7. Awesome tutorial Jeremy.
    Just a small correction: eagle is not open source.
    Thanks dude, I’m anxious for you new tutorials …
    8-)

  8. It’s not a “washer”, it’s W for “Wiper”. Also, I was really hopefully you would cover multi-device using one cs pin…

  9. 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

    • 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.

  10. 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

    • 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.

  11. Could you have programmed the maximum voltage to the LEDs to ~3V and gotten rid of the resistors going into them?

  12. 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

  13. 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.

  14. Pingback: Tutorials for Arduino Getting Acquainted with Arduino - Arduino for ProjectsArduino for Projects