Pages: 1 [2]   Go Down
Author Topic: Schematic and Arduino sketch that work  (Read 3025 times)
0 Members and 1 Guest are viewing this topic.
Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sigh... still having no luck, but then I checked my circuit and I have a schematic for PNP transistors being contolled by pins 10, 11 and 12 but the 2N2222 transistors I am using are NPN type. Also I have schematic for the NPN transistors being controlled by pins 4, 5 and 6 but the 2N2907 transistors I am using are PNP type. Help I am even more confused that I was before (might just buy a cheap set of christmas tree lights and be done with it ...)

If I put this code;
_____________________________________________________________

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

    delay(1000);

    }


with all connection between LED matrix and Arduino LED's 1 ,5 and 7 flash. The same as when I had ;

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);
  }
___________________________________________________________________

Is the fact that I have used the wrong type of transistors making my hair greyer than it was this morning,
thanks Pedro.
Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27089
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You're quite welcome. Good luck.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 47
Posts: 2892
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There are several errors in the drawing as shown... The NPN are shown as emitter ffollowers and there are 2 issues there, 1. the emitter cant ever go higher than the base, in this case for a functioning transistor the emitter MUST be .7 V lower than the collector (5V source) so we now have a max supply that is ~ 15% lower than it should be and 2. while the emitter current is the SUM of the collector and base currents the available voltage for series led's is lower making a good power supply a must. For optimal results switch the NPN's and PNP's respecting polarity... THe emitter of a PNP is the most positive element of the transistor and to turn it on you must "Pull" current from the base to ground so remember to include a 1K resistor in the base circuit and good design practice would have a 10K pull-up from base to Vcc as this prevents uncertain (read Floating) base connections from turning on the PNP transistor and use the NPN's to Sink current and use a 470R resistor for the base current limiting resistor again good practice would have a 10K resistor from base to ground. When connected in this manner both the PNP's and the NPN's are operating as true switches and the only losses will be ohmic (wire/connection) resistance and the Vce sat of the transistors. Were it me, for light loads (under 150 Ma/device) I would choose a 2SC945 for the NPN and a 2N3906 for the PNP for 2 reasons 1. the '945 has a typ dc gain of ~ 100 @ 150 mA Ic and the '3906 although a lower gain device still has the base current flowing in the emitter lead of the device thus extra base current will be dissipated in the LED rather than to ground as your drawing clearly shows and the smaller the value of base resistor the more wasted current. Never assume that the port of a microcontroller is responsible for insuring that the state of any connection to it. Use Pull-ups (5 10K) and pull downs of the same value. Pull UP PNP's and Pull DOWN NPN's... finally P & N channel mosfets would be my preferred devices for power control of that type... 5A P Ch mosfets can be had for 25 -50 cents a piece... pretty much the same for N channel devices in the same current range. OR one could use TPIB595's and ULN2803's for higher currents and simplified wiring.

Doc
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27089
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"Is the fact that I have used the wrong type of transistors making my hair greyer than it was this morning"

Yes.

Your sketch

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

    delay(1000);

    }
would work with the schematic you drew, now you just need to wire up the correct parts.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks again Crossroads,
I had a good long hard look at what I have done and with your help I finally got it to work as I set out to. Do you think that I should construct a new circuit, matching what I had in the original schematic with Pins 10,11,12  controlling PNP transistors and Pins 4, 5, 6 controlling NPN transistors rather than how they currently are, or doesn,t it matter?  Something tells me that as my physical circuit currently is, it is incorrect to have current sinking transistors to pins 10, 11 ,12 and current sourcing transistors to pins 4, 5, 6. It's all very confusing to the uninitiated I can tell you.
Also (I realise that I might be pushing my luck here) now that I have a 3 x 3 matrix working using six Arduino pins what is the next step to controlling a 3 x 3 x 3 cube. From what I have read it involves using shift registers? Would it be possible for you to point me in the right direction, keeping in mind that I am a rank novice to all this. Thanks again for your help Pedro.
Logged


Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Docedison, 
as you may be able to tell I am a complete novice here and I will have to spend some time digesting what you are telling me about the circuit I am using. I have just "cobbled  it together", (albeit not technically correct) from things I saw online and only managed to get it to work because of help from people like Crossroads. From my initial thought on what you are telling me I am in for a lot of reading. Thanks for your time and I can assure you once I understand what you are suggesting I will take it on board so to speak,
Pedro.
Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27089
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Pedro,
I'd go back to Reply #4 & wire it up that way.
You can use 9 Arduino outputs driving 9 PNP transistors for the anodes (or just drive the anode directly), and 3 Arduino outputs driving 3 NPN transistors for the layers.
Your code will drive the 9 anodes for layer 1, and drive layer 1 cathode briefly (1-2mS)
Then drive the 9 anodes for layer 2, and drive layer 2 cathode briefly.
Then drive the 9 anodes for layer 3, and drive layer 3 cathode briefly.

I did the same for a 12 anode x 8 cathode matrix recently, 500uS per cathode.
The LEDs were layed out in a long line, but could have been built up as 8 layers of 3x4 just as easily.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Crossroads,
after I make up a new cube I'll give it the old college try. If I thought that I was confused with one 3 x 3 this will test me,
Pedro.
Logged


Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have just constructed a 3 x 3 x 3 cube with some much appreciated help from Crossroads. The three levels are controlled by three digital outputs and the nine columns by another nine digital outputs of an Arduino Uno R2. Now that I have begun to write the code for it I realise how time consuming and prone to error it is and was wondering if there are any tips anyone could share with me. I have seen that there are LED libraries available and am wondering how these work especially since not all cubes of this configuration will be wired up to the Arduino  the same way. Thank Pedro.
Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27089
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I would write a time check in loop and every 2mS or so read an array holding your 9 bits per layer and update the outputs.
The rest of the time, your code could be reading buttons, pots, receiving serial data, and updating the array.
When then next 2mS hit, read the next layer and send it out.
That way the cube display is sort of automated, and your code is available to do other things.

Something like this. Need to fill in the byte definitions, create the arrays for pins used, etc.
arrayPin
  • is the 9 LED anodes, say 2-3-4-5-6-7-8-9-10, so:
byte arrayPin[] = {2,3,4,5,6,7,8,9,10};
cathodePin[layer] is the 3 cathode control pins, say 11-12-13, so:
byte cathodePin[] = {11,12,13};
byte arrayDisplay[layer, x] is the data:
[0,0], [0,1], [0,2], [0,3], [0,4], [0,5], [0,6], [0,7], [0,8]
[1,0], [1,1], [1,2], [1,3], [1,4], [1,5], [1,6], [1,7], [1,8]
[2,0], [2,1], [2,2], [2,3], [2,4], [2,5], [2,6], [2,7], [2,8]
probably write a for:next loop within a loop to initialize these:
for (byte layer = 0; layer<3; layer =layer+1){
  for (byte ledbit =0; letbit<9; ledbit = ledbit+1){
  arrayDisplay[layer, ledbit] = 0;
  } //next ledbit
} // next layer

same with the pins:
for (byte pins = 2; pins <14; pins=pins+1){
pinMode (pins, OUTPUT);
digitalWrite (pins, LOW); // don't think this is needed, can't hurt
}

arrayDisplay [0,0] =0;  // example to clear the data for the LED at location layer 0, LED 0
arrayDisplay [2,5] =1;// example to set the data for the LED at location layer 2, LED 5

I'm just making this up as I go, will need some work, I think it gets the idea across.

Code:
void loop(){
timecheck = millis(); // all time variables are unsigned long type
if ((timecheck - previoustime)>=duration){ // see if time to update
previoustime = previoustime + duration;  // yes, setup for next time
digitalWrite (cathodePin[layer], LOW);  // turn off current cathode
layer=layer+1; // get ready for next layer
  if (layer == 3){layer = 0;} //wrap around to beginning
    for (x=0; x<9; x=x+1){ // update the 8 anode pins to the LEDs
    digitalWrite (arrayPin[x],arrayDisplay[layer, x]); // read the array, write the bit
    } // end LED 0-8 update
  digitalWrite (cathodePin[layer], LOW); // turn on the layer
  } // end layer update
// now update arrayDisplay[x,y], x = layer 0-2, y = LED 0-8, as needed based on whatever. That's the fun part!
} // end of loop

will look better when autoformatted (CTRL-T) also.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Crossroads,

I am going to have to learn what all those commands etc mean. And I thought that building and getting the cube to flash a few lights was challenging. Oh well, this is supposed to be a learning experience so off I go. Thanks again for taking an interest in helping me with this (and many others on this forum) and I will now go off and learn about byte arrayPin, arrayDisplay and "time check in loop" etc.

Signing off Pedro.   smiley-cool
Logged


Pages: 1 [2]   Go Up
Jump to: