a simple sample machine (as independent as possible) - any ideas ?

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
soerena
 
Posts: 57
Joined: Fri Nov 16, 2012 7:00 am

Re: a simple sample machine (as independent as possible) - any ideas ?

Post by soerena »

auch! so I really have to implement a 595 for just 1 I/O huh? ... bummer :/

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: a simple sample machine (as independent as possible) - any ideas ?

Post by adafruit_support_rick »

Implement a 595? No - it's all software. It's typically done with a pair of lookup tables. The table index is the LED number, the table entries list digital pin numbers. So, for 12 LEDs, you would have two arrays of 12. One array lists the pin to drive high, and the other pin lists the pin to drive low to light each LED

Assume that we're using D1, D2, D3, and D4 to drive the matrix of 12 LEDs

Code: Select all

//                    LED #   0  1  2  3  4  5  6  7  8  9  10 11
const byte DriveHigh[12] = {  2, 3, 4, 1, 3, 4, 1, 2, 4, 1, 2, 3};
const byte DriveLow[12]  = {  1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4};
So, you index through the table at a regular interval. If, say your current index is 5, and LED 5 is supposed to be on, you would call digitalWrite(DriveHigh[index], HIGH), and digitalWrite(DriveLow[index], LOW); If LED 5 is supposed to be off, then you would drive both pins LOW.

At the end of the interval, you turn the current LED off by driving both pins low, index to the next LED, and turn it on.

Add a third array to hold the current on/off state of each LED, and the whole thing becomes completely simple: a few array accesses using the same index, one if-then-else, and a few digitalWrite calls.

Code: Select all

byte LEDState[12]        = {  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

User avatar
soerena
 
Posts: 57
Joined: Fri Nov 16, 2012 7:00 am

Re: a simple sample machine (as independent as possible) - any ideas ?

Post by soerena »

Re: a simple sample machine (as independent as possible) - any ideas ?
by adafruit_support_rick » 22 Jun 2013 16:05

Implement a 595? No - it's all software. It's typically done with a pair of lookup tables. The table index is the LED number, the table entries list digital pin numbers. So, for 12 LEDs, you would have two arrays of 12. One array lists the pin to drive high, and the other pin lists the pin to drive low to light each LED

Assume that we're using D1, D2, D3, and D4 to drive the matrix of 12 LEDs
CODE: SELECT ALL
// LED # 0 1 2 3 4 5 6 7 8 9 10 11
const byte DriveHigh[12] = { 2, 3, 4, 1, 3, 4, 1, 2, 4, 1, 2, 3};
const byte DriveLow[12] = { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4};


So, you index through the table at a regular interval. If, say your current index is 5, and LED 5 is supposed to be on, you would call digitalWrite(DriveHigh[index], HIGH), and digitalWrite(DriveLow[index], LOW); If LED 5 is supposed to be off, then you would drive both pins LOW.

At the end of the interval, you turn the current LED off by driving both pins low, index to the next LED, and turn it on.

Add a third array to hold the current on/off state of each LED, and the whole thing becomes completely simple: a few array accesses using the same index, one if-then-else, and a few digitalWrite calls.
CODE: SELECT ALL
byte LEDState[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Ok, that sounds pretty useful but I'm note quite sure how to hook this up physically. You're talking about 4 I/O's controlling the state of 12 LED's (in my particular case it's 12 transistors switching 12 lamps on/off to external 12v), but how would that look like?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: a simple sample machine (as independent as possible) - any ideas ?

Post by adafruit_support_rick »

Have a look at some of the charlieplexing links I posted earlier. It's a 2D matrix. Since you're using transistors, you should be able to use regular diodes to get the correct polarities to the bases.

Here's a good place to start:
http://www.instructables.com/id/ED0NCY0UVWEP287ISO/

tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: a simple sample machine (as independent as possible) - any ideas ?

Post by tldr »

rick,

what you describe is not charlieplexing. charlieplexing requires selectively assigning pins as inputs with the advantage of getting a 1/n duty cycle on the outputs as opposed to 1/(n*(n-1)) with your method.

in a charlieplexed array you would set one pin up as an output and set it, (for instance), low, then the devices attached to the other pins can be either turned on, by making a pin an output and setting it high, or turned off, by making the pin an input. wiring such a beast can be a real biBANNED, but the results can be quite satisfying.

User avatar
soerena
 
Posts: 57
Joined: Fri Nov 16, 2012 7:00 am

Re: a simple sample machine (as independent as possible) - any ideas ?

Post by soerena »

OK, So I've tried for quite a long time now doing this with a 74HC595 - without luck.

I used this tutorial and the example code 1.2 (one by one): http://arduino.cc/en/Tutorial/ShiftOut

So I hooked 3 transistors (IRF520N) up to pin 1, 2 and 3 of the 595 and I hooked everything else up as explained in the above-mentioned tutorial (with a 0.1f cap) I also tried it without the 0.1f cap.

I also tried using the LED setup (as in the tutorial), and the LED's light up when I hook up the arduino, but as soon as I send anything to the serial, all the LEDs go off and I can't put any of them on. Something is wrong, and I'm really on bare bottom here.
Any suggestions what I might be doing wrong?

And by the way, does anyone know if the 0.1"f is a 0.1 uf cap ? this really confuses me

Søren

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: a simple sample machine (as independent as possible) - any ideas ?

Post by adafruit_support_rick »

@tldr - you are correct. It's been a long time since I've done it, and I was getting it confused with a slightly different technique I was using to multiplex 5 RGB LEDs.
But the overall description was correct - it's just that you have to set the unused pins to inputs. As for the 1/n vs. 1/(n*(n-1)), I didn't think it was worth getting into the extra complexity for only 12 LEDs.

Although if soerena used one of the many charlieplexing libraries out there, I guess that wouldn't be an issue.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: a simple sample machine (as independent as possible) - any ideas ?

Post by adafruit_support_rick »

@soerena - if you're going to add hardware, I'd go with an I2C expander instead of a 595.

User avatar
soerena
 
Posts: 57
Joined: Fri Nov 16, 2012 7:00 am

Re: a simple sample machine (as independent as possible) - any ideas ?

Post by soerena »

Re: a simple sample machine (as independent as possible) - any ideas ?
by adafruit_support_rick » 24 Jun 2013 16:07

@soerena - if you're going to add hardware, I'd go with an I2C expander instead of a 595.

Hi Rick,

I'm trying to set up an MCP23016, but it's giving me endless amounts of headache. I just can't get it working no matter what I do.

I'm on an Arduno Uno board R3

I've connected the hardware as follows:

from the MCP23016:

pin 15 (SDA) to analog pin 4
pin 14 (SCL) to analog pin 5

pin 9 (CLK):
* through a series of resistors with a total value of 3.87k (I didn't have a 3.9k resistor at hand) to 5V
* through 3 10pf caps in parallel to GND --- NOTE: this should give a total value of 30pf, and the instruction tells me to use a 33pf cap, but since I didn't have one, I did this instead. Could a difference of 3pf really make a difference?


pin 16, 17, 18 (addresses) and 19 (vss) to GND
pin 20 (vdd) to 5V
pin 21, 22 and 23 to each their own IRF520 transistor (gate pin). each transistor has its drain pin connected to one side of a 12V lamp and the source pin connected to 12V (external, power supply with 4,2 Amps)

Can anyone confirm if the physical side of this setup ought to work?

I'm using this simple library and the example that follows, trying to turn my lamps on/off:
https://sourceforge.net/projects/ioexpander/

I'm using an MCP23016 I/SP, but in the library it says to use an MCP23016 I/SP-ND. Is there any difference to this? I'm not sure what the "ND" means.

Søren

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: a simple sample machine (as independent as possible) - any ideas ?

Post by adafruit_support_rick »

I don't know much about using the 23016. The one we sell is the 23017, which is slightly different (for one thing, it doesn't require an external clock). We have a library for the 23017.
https://github.com/adafruit/Adafruit-MC ... no-Library

There is another thread here with someone trying to get a 23016 working.
http://forums.adafruit.com/viewtopic.php?f=8&t=37506

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”