Pages: 1 2 [3] 4   Go Down
Author Topic: Multiplex IR LED's?  (Read 6995 times)
0 Members and 1 Guest are viewing this topic.
Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34724
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The code is nearly right but you only do one column per refresh not all of them.
You are only sourcing one LED's current per shift register pin so that is fine but check on the data sheet that the total package current is OK, it depends on what type of shift register you get, that is given by the letters before the 595 bit, you might have to use LS or HS type. The darlingtons are good for 500mA per pin.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I also forgot to ask, how would I generate a 38khz wave for the IR Emitters so the detectors can sense the IR signals?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34724
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You love springing surprises don't you. You said at the start that the IR carried no data, now you are saying they are modulated!!!
Well modulation is data, what sort of sensor do you have, part number? This changes again how you should do things.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code is nearly right but you only do one column per refresh not all of them.
You are only sourcing one LED's current per shift register pin so that is fine but check on the data sheet that the total package current is OK, it depends on what type of shift register you get, that is given by the letters before the 595 bit, you might have to use LS or HS type. The darlingtons are good for 500mA per pin.
OOOOOOOohhhh omg I understand now smiley-grin

Firstly, the datasheet for the 595s Im getting say the max continuous output current is 35mA I think, http://www.jaycar.com.au/products_uploaded/ZC4895.pdf But I dont know if thats per pin or not?

Ok now to the good part smiley-razz, I think I have got it, and I wrote up the code, not psuedocode:
This works if the ULN2803 inverts I have read that it does but im still not sure, on your site It says they do or is that for the FET's?

Code:
const int latchPin = 4;
const int clockPin = 3;
const int dataPin = 2;

byte displayData [ ] = {
B11111111,
B10000001,
B10111101,
B10100101,
B10100101,
B10111101,
B10000001,
B11111111,
B11011011,
B11111111,
B11111111,
B11111111};
int rowCount = 0;

long int refreshDue;
long int refreshTime = 10;

void setup() {
  pinMode(dataPin, OUTPUT); //Data
  pinMode(clockPin, OUTPUT); //Clock
  pinMode(latchPin, OUTPUT); //Latch
}
void loop() {
  if(millis() >= refreshDue){
    refreshDue = millis() + refreshTime;
    refreshDisplay();
  }
}

void refreshDisplay(){

  if (rowCount>=12)rowCount=0;
 
  byte rowData;
  byte col1Data;
  byte col2Data;
 
  rowData = displayData[rowCount];
 
  if (rowCount<=7){
    col2Data=B00000000;
    col1Data=byte(rowCount+1);
  }else if (rowCount>=8{
    col2Data=byte((rowCount-8)+1);
    col1Data=B00000000;
  }
 
  digitalWrite(latchPin, LOW);
  shiftout(dataPin, clockPin, MSBFIRST, col2Data);
  shiftout(dataPin, clockPin, MSBFIRST, col1Data);
  shiftout(dataPin, clockPin, MSBFIRST, rowData);
  digitalWrite(latchPin, HIGH);

  rowCount ++;
 
}
(I also used alot of your code, thanks bro smiley-razz)

There is one minor flaw in this code...
instead of refreshing left to right, or right to left (which is what I wanted)
it refreshes or the bit walks like this (_ means that its not used shift register pin)
00000001 0000 _ _ _ _
00000010 0000 _ _ _ _
00000100 0000 _ _ _ _
00001000 0000 _ _ _ _
00010000 0000 _ _ _ _
00100000 0000 _ _ _ _
01000000 0000 _ _ _ _
10000000 0000 _ _ _ _
00000000 0001 _ _ _ _
00000000 0010 _ _ _ _
00000000 0100 _ _ _ _
00000000 1000 _ _ _ _

Also I believe you mean HC, I cant find any HS595's anywere smiley-razz

P.S: I saw your post whilst I was posting a reply to the other one smiley-razz, I dont mean to spring the surprise, I was using just a photodiode and hoping it would work, when I realised the part that I ordered from sparkfun wasnt a photodiode but rather a reciever Lol, fail, so then I just thought since the instructable I was following before was a load of crap and I might as well actually use the reciever it could give me a better result smiley
This is the part:  TSOP38, can be found here: http://www.sparkfun.com/products/10266
But I might have to order from somewhere else as they only take credit card and use something like this: http://www.jaycar.com.au/productView.asp?ID=ZD1952&form=CAT2&SUBCATID=976#1
which is way too overpriced for me smiley-sad
I would prefer to use this: http://www.electus.co.nz/productView.asp?ID=6149&CATID=33&keywords=&SPECIAL=&form=CAT&SUBCATID=140 but I dont know how to use it with the emitter, all examples use reciever breakouts and stuff smiley-sad

Thanks Mike smiley-grin
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34724
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

With your code, have the walking 1 variable as a global like the rowCount. Change it each time by a:-
Code:
walk1 = walk1 << 1;
Reset it to 1 when you reset the rowCount. Then there is no need to calculate the col2Data or col1Data simply output the walk1 value:-
Code:
  shiftout(dataPin, clockPin, MSBFIRST, walk1 >> 8);
  shiftout(dataPin, clockPin, MSBFIRST, walk1);
  shiftout(dataPin, clockPin, MSBFIRST, rowData);

You better say what your application is because I suspect that the sensor you have is not suitable. Look at the data sheet and you will see that you can't carry on giving it pulses and expect the output to say at one level. If you want to just detect when a beam is broken you need the TSOP4038 sensor.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

With your code, have the walking 1 variable as a global like the rowCount. Change it each time by a:-
Code:
walk1 = walk1 << 1;
Reset it to 1 when you reset the rowCount. Then there is no need to calculate the col2Data or col1Data simply output the walk1 value:-
Code:
  shiftout(dataPin, clockPin, MSBFIRST, walk1 >> 8);
  shiftout(dataPin, clockPin, MSBFIRST, walk1);
  shiftout(dataPin, clockPin, MSBFIRST, rowData);
Ahh thats what the >> and << operators do, I see, yes that narrows down the code alot, thanks smiley

You better say what your application is because I suspect that the sensor you have is not suitable. Look at the data sheet and you will see that you can't carry on giving it pulses and expect the output to say at one level. If you want to just detect when a beam is broken you need the TSOP4038 sensor.
I just want to detect a broken beam yea smiley
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34724
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok so you need to change your sensor.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok so you need to change your sensor.
Damn, so I get a TSOP4038, I found this one on an Australian site which I might be able to buy it off: http://www.x-on.com.au/details-new.asp?i=549879&t=7&p=

My only problem is, everywhere people mention that the IR Emitters need to be pulsing at 38khz for the IR Detectors to pick it up... So how do I do that?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34724
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You setup one of the timers to change the PWM frequency to 38KHz and drive the LEDs from that pin.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You setup one of the timers to change the PWM frequency to 38KHz and drive the LEDs from that pin.

But how can one output drive 6 or more Ir emitters? With a transitor or something?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34724
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes one output through a resistor into the base of a transistor. Emitter to ground, then collector to a resistor, other end to an LED and then on to the +ve supply. You can parallel up the resistor / LED series circuit many times, providing the transistor can take the collector emitter current.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes one output through a resistor into the base of a transistor. Emitter to ground, then collector to a resistor, other end to an LED and then on to the +ve supply. You can parallel up the resistor / LED series circuit many times, providing the transistor can take the collector emitter current.
Sorry I have not replied for days, I have been preoccupied with schoolwork, mainly tests and stuff, I will reply again soon but right now Im just posting this not to be rude smiley

Thankyou Mike smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Phew... Its been along time Mikey ;P, sorry I haven't replied.

I managed to get some of it working and others not so much... all my parts have come and I finally have started putting it together. The IR Recievers work well smiley, I found some neat code for them, the only problem I have is the Multiplexed LED's, I made a few modifications to the code:

(Not including IR parts)
Code:
const int latchPin = 4;
const int clockPin = 3;
const int dataPin = 2;

byte displayData [ ] = {
B10101101,
B10000001,
B10101001,
B10100101,
B10100101,
B10010101,
B10000001,
B10010101,
B10010011,
B10101010,
B10100101,
B11111111};
int rowCount = 0;
unsigned int walk1 = 1;

long int refreshDue;
long int refreshTime = 5000;

void setup() {
  pinMode(dataPin, OUTPUT); //Data
  pinMode(clockPin, OUTPUT); //Clock
  pinMode(latchPin, OUTPUT); //Latch
  Serial.begin(9600);
 
  //Clear Registers
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, B00000000);
  shiftOut(dataPin, clockPin, MSBFIRST, B00000000);
  shiftOut(dataPin, clockPin, MSBFIRST, B00000000);
  digitalWrite(latchPin, HIGH);
}
void loop() {
  if(millis() >= refreshDue){
    refreshDue = millis() + refreshTime;
    refreshDisplay();
  }
}

void refreshDisplay(){

  if (rowCount>=12){
    rowCount=0;
    walk1 = 1;
  }
 
  byte rowData=0;

  rowData = displayData[rowCount];
  byte walk2=highByte(walk1);
 
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, walk2);
  Serial.println("C2: ");
  Serial.println(walk2,BIN);
  shiftOut(dataPin, clockPin, MSBFIRST, lowByte(walk1));
  Serial.println("C1: ");
  Serial.println(lowByte(walk1),BIN);
  shiftOut(dataPin, clockPin, MSBFIRST, rowData);
  Serial.println("Row: ");
  Serial.println(rowData,BIN);
  digitalWrite(latchPin, HIGH);

  walk1 = walk1 << 1;
  rowCount ++;
 
}

Now what happens is peculiar,using this layout:

The LED's light up in random? I have tried changing the row data array to make them all light up, none light up and only 1 light up etc... whenever at least one 1 bit is in the rowdata, the led's light up randomly. I have not connected all the columns/rows to the Darlington and shift registers yet, but I dont see if this should make much of a difference yet I guess im wrong. only row 1 & 2 are connected and column 1 & 2, yet I cant get the LED's to light up how I define them in the rowdata matrix. I hope you understand what im saying if not tell me I  shall clarify.

Im not sure but could it be the shift registers are not cleared properley? if so, how can I do that, I tried in the setup function yet it doesnt look like it did anything

Thanks for your help again in  advance, Ill take pics of the project soon smiley
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34724
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Two points:-
1) do not use pins 0 & 1 as these are used for serial operations and will interfere with uploading code.
2) Add some decoupling capacitors on each chip. http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Right sorry I forgot to change the pin order, ye its not on 0,1,2 its on 2,3,4

I am going to decouple it ASAP, ill post back when I do smiley Thanks Mike
Logged

Pages: 1 2 [3] 4   Go Up
Jump to: