Go Down

Topic: Schematic and Arduino sketch that work (Read 3362 times) previous topic - next topic

Pedro147

Help please  =( , I have been spending hours looking at supposed "tutorials" on the internet showing how to construct a 3 by 3 LED cube. While the description of the construction seems quite well done and easy to follow, when it comes to providing a readable schematic and a sketch that will even upload without coming back with a multitude of errors, it is a different story. I realise that nobody owes me any of their valuable time in showing how to learn about these things but why waste peoples time showing them something that clearly will not ever work. I am no expert (rank , enthusiastic amatuer comes to mind) but if someone on this forum would be kind enough to point me in any legitimate direction I would be gratefull. Have a good day or night as the case may be, Pedro
http://www.pedroduino.com

P18F4550

Hello Pedro,

The Arduino project is all about tinkering, experimenting and learning, personally i find it hard to follow other peoples code, if something doesn't work as you expected investigate and find out why

My advise would be to first construct a 3x3x1 matrix and when you master that add another layer to make 3x3x2 then another 3x3x3, if you need to know how to multiplex i will try and help but i work and don't get much time

Pedro147

Hello P18F4550
and thanks for your reply. Yes I suppose that approaching it from simplifying a cube to a series of matrices makes sense.Thanks again.
http://www.pedroduino.com

copiertalk

If you could post the code you are trying to use and the schematic you are trying to use the members would probably bend over backwards to assist you in finding the faults in both.

Saying it does not work without something to go on is kind of vague at best.

CrossRoads

One approach - drive 3 layers of LEDs with anodes connected in columns. Arduino drives LED anodes, ULN2003/2803, or discrete transistors, sink the up to180mA of current from up to 9 LEDs. Or 20mA if just 1 is on.

Each layer's cathodes are connected together.
Drive the anodes, drive cathodes for layer 1.
Drive the anodes, drive cathodes for layer 2.
Drive the anodes, drive cathodes for layer 3.
Repeat every 5mS.
The rest of the time, read switches, button, serial port, etc to make decision about how the display will change.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Pedro147

Hello Crossroads. Cool name there,,, I love the blues too. Look I am a rank amatuer here and to be frank I do not understand your suggestion , although I'm sure it's a very good one. P18F4550 suggested that I start with a 3 x 3 matrix and expand on that which is what I am now trying.  First I have built a simple circuit to power one led via transistors switching the anode and cathode on and off via digital signals from the Arduino uno R2. I also wrote a sketch to operate the circuit and so far it seems to be all ok and working but although it works maybe I am kidding myself as to how it works if that makes sense?
If someone could cast an eye over my circuit and Arduino sketch I would be gratefull for any feedback (verbal, not electronic ? )
Thanks Pedro.
http://www.pedroduino.com

CrossRoads

Hi Pedro,
You're on the right track, the operation of the transistors is just flipped over with respect to the comments:

(Oh - put a resistor between arduino and the NPN base also)

Code: [Select]
  void setup ()                                 // run once, when the sketch starts
 {
  pinMode (12 , OUTPUT);             // sets the digital pin 12 as output - drives Base of PNP transistor
                                                // Low here turns PNP on
  pinMode (13 , OUTPUT);             // sets the digital pin 13 as output - drive Base of NPN transistor
                                                // High here turns NPN on
 }
  void loop ()                                   // run over and over again
 {
  digitalWrite (12 , HIGH);               // sets the +ve side of led on via transistor >> PNP off
  digitalWrite (13 , LOW);               // sets the -ve side of led on via transistor >> NPN off
                                                  // so LED is actually Off here
  delay(1000);                                 // waits for one second
  digitalWrite (12 , LOW);               // sets the +ve side of led off via transistor >> PNP on
  digitalWrite (13 , HIGH);              // sets the -ve side of led off via transistor >> NPN on
                                                 // LED is actually On here
  delay(1000);                                // waits for one second
 }


You could start with a 1x9 matrix (which I drew up) physically layed out in a 3x3 grid.
Then put 2 more on top of that (the three rows I drew).
The Anodes of the LEDs in each column get connected together, the cathodes in each layer get connected.

Thus you drive the anodes, and only drive 1 cathode on at a time to light up 1 row at a time.
Repeat that quickly in software, turning some or all of the LEDs in each row for say 10mS at a time, and to the eye it will seem that all are being driven all the time.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Pedro147

Hello Crossroads,
thanks for your help and I am glad that I'm basically thinking along the right lines.. I put a 4.7k resistor between the arduino and NPN base and the LED seems not quite as bright. Presumably these resistor values should be calculated depending on the specs of the LED's and transistors? I just picked resistor values that I have seen in similair circuits online without knowing the maths behind their values.
Thanks again and have a great day Pedro.
http://www.pedroduino.com

CrossRoads

I'd put 20ma in to make sure the transistor turns on hard.
Vbe of many transistors is 0.7.
So there'd be 4.3V across a base resistor.
4.3/.02 = 215 ohm, use a 220 ohm resistor.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Pedro147

Thanks Crossroads,I'll try that once I stop burning out LED's by connecting power to the wrong place on the breadboard (opps...)
http://www.pedroduino.com

Pedro147

I have been constructing a simple 3 x 3 LED matrix which I want to control with an Arduino R2. I want to be able to control the LED's individually to create sequences,  initially in this matrix and ultimately in a 3 x 3 x 3 cube. I realise that you can buy chips to do these sort of things but I am doing it to learn about electronics and the Arduino interface. I have attached a circuit diagram of the matrix connected to the Arduino.
When I connect the matrix, (including the transistors and resistors)  without the Arduino, to 5v and earth for the approprite LED, they all work as expected. 

Then I connected the  LED matrix  to Arduino pins 10, 11 and 12 to provide power  and pins 4, 5 and 6 for grounds. I think this is where it is becoming confusing for me, the concept of digital signals and the subsequent coding. I assumed that if I set pin 12 HIGH and pin 6 LOW then LED 1 would light which it does as long as it is the only LED actually connected to the Arduino via D 12 and D 6 . If I connect up more than one "pair" of wires (power and ground for relevant LED) I get more than one LED flashing even if I use basic code such as ;
___________________________________________________________________

void setup ()                         
  {
   
   pinMode (4 , OUTPUT);               
   pinMode (5 , OUTPUT);
   pinMode (6 , OUTPUT); 
   pinMode (10 , OUTPUT); 
   pinMode (11 , OUTPUT); 
   pinMode (12 , OUTPUT); 
   
  }
   void loop ()                     
  {
    digitalWrite( 12 , HIGH);
    digitalWrite ( 6 , LOW);     
    delay(1000);                           
    digitalWrite( 12 , LOW);
    digitalWrite ( 6 , HIGH);
   
   
    delay(1000);
  }
___________________________________________________________________

I get LED's 1, 4 and 7 flashing with all connections made between matrix and Arduino. But with all connections and the following code where I have not set digital pins 4 and 5 as OUTPUTS, I get LED's 1, 2 and 3 flashing alternately. But obviously this is not allowing me to access LED's 4 through 9.
___________________________________________________________________


   pinMode (6 , OUTPUT); 
   pinMode (10 , OUTPUT); 
   pinMode (11 , OUTPUT); 
   pinMode (12 , OUTPUT); 
   
  }
   void loop ()                     
  {
    digitalWrite( 12 , HIGH);    // sets led 1 on
    digitalWrite ( 6 , LOW);         
    delay(1000);                           
    digitalWrite( 12 , LOW);     // sets led 1 off
    digitalWrite ( 6 , HIGH);
    delay(1000);
    digitalWrite( 11 , HIGH);     // sets led 2 on
    digitalWrite ( 6 , LOW);     
    delay(1000);                           
    digitalWrite( 11 , LOW);     // sets led 2 off
    digitalWrite ( 6 , HIGH);
    delay(1000);
    digitalWrite( 10 , HIGH);     // sets led 3 on
    digitalWrite ( 6 , LOW);     
    delay(1000);                           
    digitalWrite( 10 , LOW);     // sets led 3 off
    digitalWrite ( 6 , HIGH);
    delay(1000);
  }


As I have previously stated I am a beginner at all this and I am suspecting that this problem has something to do with the last state of some of the pins as my circuit tests o.k. with straight analog input. It is all very confusing I must say and would appreciate it if someone could point me in the right direction.
Thanking you Pedro.
http://www.pedroduino.com

Pedro147

In relation to my last post I don,t think that this attached Pedro.
http://www.pedroduino.com

Pedro147

Sorry I,m making a botch of this post.... The .png file that I attached is a bit hard to scroll on so here is a .jpg file that you can zoom in on . Pedro (again)
http://www.pedroduino.com

CrossRoads

Pins 10,11,12 you have controlling PNP transistors - PNPs are On when the Base is Low, and Off when the base is high.
You need to adjust your logic to reflect that.
10,11,12 Low AND 4,5,6 High will turn on LEDs.

Either 10,11,12 High OR 4,5,6 Low will turn off LEDs.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Pedro147

Hello Crossroads. I'll modify my thinking to get my head around that and see how I go. Thanks so much for all your help you are a generous man with your time on this forum, Pedro.
http://www.pedroduino.com

Go Up