Monday, May 27, 2013

A welcome gift

My father stopped by last night bearing two oscilloscopes. Pretty sure they are old enough that they use vacuum tubes, but it'll be great fun to show the kids, visually, the signals that we've been talking about.

In other notes, I still haven't gotten the code working for the shift register circuit, but, admittedly, I didn't get to spend much time this weekend. Maybe tomorrow.

Thursday, May 23, 2013

Back to basics: Using 1 shift register

At it's core the 74HC595 shift register is simply a way to turn on 8 signals at one time. To do this only 5 wires need to be run from the Arduino board. So you save 3 pins, "so what, I have plenty of pins" you ask? While this is true, the magic really happens when you want to use 16 signals, or, even 64 or more. Guess what? The same 5 wires will control all of them, even over 500 if necessary. Now that's some power.

A couple of entries ago, I dove into an overly aggressive project, attempting to wire 4 shift registers to control both the anode and cathode wires of my, now infamous, 8x8 RGB LED matrix. You can't imagine how many times I typed "8x8 RGB LED" into Google over the last few weeks. This matrix has 8 rows on the anode (plus) side connecting to all 24 LED connections in that row. That makes this panel a "Common Anode" device. This matrix, then, has 24 columns on the cathode (minus) side, 8 for each color and column. This gives this board 36 total connections. Thus, the 4 shift registers. One would be dedicated to that 8 anode connections, 8 for the red, 8 for the blue, and 8 for the green cathodes.

I full-heartedly dove right in wiring this together, borrowing some code that I found on-line, I compiled my masterpiece, watched as the transmit/receive LEDs lit up on my Arduino board as the code was transferred and watched, in horror, as absolutely nothing happened.

[insert expletive here]

I felt I understood the wiring but, admittedly, didn't understand the code at all.

That's why I find myself here, now.

I ripped my project apart and decided to start at the beginning with using shift registers. I intend to spend as much time understanding the code as I do with the wiring. Since I have to start somewhere I'm going to start with the wiring.

If you've read some of my other postings, you'll remember that I had come across some replacement LEDs from some Christmas light sets, 4 in total. While this is an incredibly simple for the use of a shift register, it will be enough to gain the understanding that I need.




This is a clip from the manufacturers datasheet which can be downloaded by clicking the above link. The pins that I am going to first concern myself with are as follows:


Pin Label Meaning
1QBData Output 2
2QCData Output 3
3QDData Output 4
4QEData Output 5
5QFData Output 6
6QGData Output 7
7QHData Output 8
8GNDGround
10SCLRShift Register Clear Input. If this pin is driven low, it will clear the register. Since I don't have a need for that right now, I will just hold it high. The easiest way to do this is to connect it to the 5 volt pin on my Arduino board.
11SCKShift Register Clock. This will be wired to the Arduino and is used to control the movement of the bits in the register.
12RCKStorage Register Clock Input. This will be connected to the Arduino board. When this is low, data is expected to be flowing into the shift register. When this pin is high, the data is copied from the shift register to the storage register. This, in effect, turns on or off the pins that you told it to. This is just like turning on or off 8 light switches at the same time, in parallel, as it is known.
13GOutput Enable Input. When this is high, it turns off all output. Yes, you could use the SCLR, but this remembers the data. When the pin is, once again, low, the same pins that were on before will be turned on again. By toggling this, it is possible to dim the LEDs using PWM. For now, I just want to keep this low. This easiest way to do this is to wire it to ground.
14SISerial Data Input. This is our workhorse. On this pin, we will send the on and off signals telling this register which outputs will be on or off.
15QAData Output 1
16VccPositive Supply Voltage. This is, just like it sounds, positive voltage. I'll simply wire this to the 5v on the Arduino board.

Whew! Maybe a picture will make this overwhelming amount of information make sense. Here is a drawing of the circuit:
Clear now? Let's break it down. First, all of the black wires are ground (minus) and all of the red wires are 5V (plus). If you have the same kind of breakout board as shown here, you'll see 2 rows of pins at the top and 2 more at the bottom. One has a red line and the other black. These rows are connected across the entire board and are there to have a simple way to grab a positive or negative lead. Think of it as a power strip like you would use in your home to plug you tv, dvd, vcr (what that? :), and other components into instead of running them all to the wall outlet. Likewise, why run all of these extra wires back to the Arduino? So the first thing I did was run a lead from the 5v pin (wall outlet) to the red row at the top (power strip). Then, just for convenience, we plug in another "power strip" on the bottom of the board. 

Now, I added my other components. First, the shift register chip. Notice how it straddles the gap in the middle of the board. On breakout boards all of the pins are connected in columns, but they are not connected across the gap. With the chip in place, I get 4 rows of connectors for each pin on the top row of the chip and the same is true on the bottom of the chip. If not for the gap, you would be connecting the pins on the top of the chip to the pins on the bottom of the chip which, obviously, is not desirable. Also, notice the notch in the chip on the left side. If you look above at the picture with the pin descriptions, you'll see that picture, too, has a notch. This tells us that pin 1 is on the lower left as I plugged it into the board.

Next my 4 LEDs, taking care that the anode is on the left of each one. One pin in each column. Below them, are 220k OHM current limiting resisters. These are simply to protect the LEDs. If too much current passes through the LED, it will not produce noticeably more light, light a light bulb would. Instead, it will start to generate heat. Heat will damage the components inside the LED and wear them out quicker. I bought 400 resisters on ebay for less than $5 which is far cheaper than LEDs.

Now all of our components are installed and we have power readily available. In the pin description above, I said that there were 3 wires, besides 5v and ground, that were going to be connected to the Arduino. These are SCK (11), RCK (12), and SI (14). I'm connecting these to pins 10, 9, and 8 on the Arduino board with the yellow, purple, and blue wires. This is where our code will come in to do it's magic.

Now we wire the LEDs. Pin 15 (QA) on the shift register will go to the anode on LED 1. Pin 1 (QB), pin 2 (QC), and pin 3 (QD) are connected to the anodes on LED 2, 3, and 4. In the picture, I have each of these connections on a different row. This is not necessary, since all of the pins in that column on that side of the gap are connected. This was just done this way so the picture looked better.

I, in the pin description above, mentioned that the SCLR (pin 10) needs to be held high, so run a red wire to the positive power row at the top of the board. Likewise, G (pin 13) needs to be held low, so run a black led wire to the negative power row at the top.

That's all the logic that needs connecting. Now let's provide power and ground to everything that needs it. Each of the resisters that are coming from the cathodes of our LEDs need to go to ground so run a black wire to the negative power row at the bottom. The shift register needs a ground on pin 8, so run a black wire to the negative power row. Lastly, our shift register needs power on pin 16, so a red wire from the positive power row to pin 16 takes care of that.

I'll leave you with a schematic drawing of the circuit. In the schematic drawing, instead of the Arduino PCB (printed circuit board) being illustrated, the actual connections on the ATmega chip are shown. In essence, this is what is happening. The PCB also has connections to USB, power supply, etc. but, essentially, the chip is performing its work on the connections indicated.You should be able to find the wires that go to each connection on the schematic. See one of my previous blog entries for a description of the schematic symbols.
Next time, I'm going to figure out the code that goes with this....

I hope!

Wednesday, May 22, 2013

Shift registers-the basics

I've disassembled a portion of my #arduino project and am building a new circuit with 4 leds and one shift register to make sure that I understand the basics of using the shift register. Most of the circuit is wired, now I have to put some code together.

Tuesday, May 21, 2013

Too sure of myself

Brimming with confidence, thinking that I completely understood shift registers and without a single simple experiment to insure that I did, I dove into building this circuit. This circuit includes the RGB led matrix that I've spoken of and 4 shift registers. 1 for the 8 anode connections and the other three controlling the red, green, and blue connections of the diodes. One shift register is dedicated to each color. I used some code that was written for high speed led control. I compiled it and installed it on my Arduino board and watched, to my amazement, as absolutely nothing happened. Sigh. Since I have a ton of shift registers, but no bread boards, I am resigned to tearing this apart to do some experimenting that I, obviously, should have done in the first place. Oh well.

Saturday, May 18, 2013

Started working on a new circuit on the #Arduino

I'm rebuilding the new circuit for the Led matrix using 4 shift register chips on the breadboard. I had almost finished installing the current limiting resisters when I realized I was short 4 resisters. So much for pulling an all nighter. I hate the thought of running to Radio Shack and paying retail, but how much could it cost?

Friday, May 17, 2013

More with the 8x8 RGB LED matrix

I received my shift register ICs, but didn't get to play with them tonight because I'm still wrestling with the red LEDs. The 220k resisters are perfect for the blue and green, but the red doesn't seem to ever dim or it is too dim to see. I guess I have to break down and calculate the appropriate resister and then if I don't have the right one in my, rather large, stock of resisters, I'll have to buy the right one.

I did tweak the code a bit for the 4x4 section of the matrix that I'm playing with to get brighter colors but there is still a notable flicker.

Tomorrow being Friday, I can pull an all-nighter and accomplish something, I hope.

Thursday, May 16, 2013

They're here!

It looks like my shift registers are here:
I hope I have time to start using them tonight.

Wednesday, May 15, 2013

PWM on the cathode

This is the new circuit. You can see I've added current limiting resisters on the cathode side of the diodes. I used 220k resisters on the blue and green and I wanted 330 for the red but didn't have any that size. I think the next size I had above 220 was 470 which turned out to be either too big or possibly I wired it wrong because I never saw red in my loops. Now that I think about it, it could have just as easily been my code. Also, you may have noticed, I don't have 36 connections. This is because the Arduino Mega doesn't have the 24 PWM pins that I would need to drive the whole board, so I choose to use a 4x4 grid in the center of the board. It does appear to work although there is still a notable flicker.

Tomorrow, I'll debug my circuit and sketch. In the end, I'll still have to wait for the shift registers to arrive to fully test this.

More Research

I was looking into how to make this LED matrix work the way it should on my Arduino. I finally resigned myself to the fact that I would need to utilize shift register ICs. So I started researching how to use them. Logically, I kept thinking that I had to use the PWM pins on the anode side of the LEDs. I thought that to vary the signal, I had to vary the positive side. So I coded that way thinking that I had to set the PWM on the anode for one color, then ground it. Then I coded each other color, but got terrible flicker and found that there was absolutely no way to run the while matrix this way.

WRONG!

What was I thinking?

What is PWM, but a toggling between positive and negative. The higher the value on the pin, the longer the pulse stays positive. Because LEDs only allow current to move one direction, I can put the PWM on the cathode.

This next part I am just guessing, but because I will now be modifying the pulse on the cathode, lower PWM values will make shorter pulses, but in effect make the LEDs brighter because the cathodes will be negative longer making the LED stay on longer. Furthermore, it makes sense that common anode LED matrices would be preferred because they can be powered independently and not draw their power from the PWM pulse preventing too much strain on the Arduino's power supply.

It's after midnight now, so I can't try this out now. I can't wait to try this tomorrow.

One last thing I realized, I can't address the entire matrix with my Arduino. It only has 14 PWM pins and I need 18. But, I can definitely test this on a 4x4 section of the LED matrix, right. I've already ordered some shift register ICs from a US supplier that promises delivery by Friday.

Monday, May 13, 2013

Really trying to figure this out.

The kids, completely on their own, booted up the laptop, hooked up the circuit from Saturday, and wanted to tinker with their code. They were struggling a bit, wanting to do a bunch of fading in and out, so rather than continuing to do the overly complicated, nested, loops I helped them out with a "fade in" and "fade out" functions. They only accept 1 argument and that is the pin number. It assumes that the cathode is already set to LOW. Here's the functions:

void fadein(int ipin){
  for(int strength=1;strength<=255;strength++){
    analogWrite(ipin,strength);
    delay(10);
  }
}
void fadeout(int ipin){
  for(int strength=255;strength>=0;strength--){
    analogWrite(ipin,strength);
    delay(10);
  }
}      

After the kids went to bed, I rewired the LED Matrix. I think I figured out a few things. The first thing a figured out was why I couldn't lower the value of my LEDs with an analogWrite(). I didn't realize that only 14 of the 54 pins on my Arduino board can be used for PWM (Pulse Width Modulation). LEDs simply require a certain a minimum voltage and they light up. Less voltage does not make it light up less, just as more voltage will not make it brighter. The only way to make an LED brighter or dimmer is to flicker them off and on. That's what PWM does. I'll let the Arduino site give the technical explanation. My Arduino Mega  can only do PWM on pins 2-13, 45, and 46.

When I rewired my LED matrix, I made sure that the rows were attached to PWM pins. Now, when I set a red column to LOW. If I do analogWrite() with different values, I can make it different levels of brightness. Next, I want to try blending the colors. This is when I realized what was meant by the term "Common Anode," which is the type LED matrix I have. This term simply means that all of the colors in a given row are powered at the same time. By enabling the ground on the column of the desired color whatever PWM signal is sent through that row will apply to all grounded colors in that row. So how can I blend the colors?

The only thing that I can figure out is to:

  1. ground red "digitalWrite(LOW)" 
  2. power the row with the appropriate PWM pulse "analogWrite(pin,value). 
  3. Remove the ground from red "digitalWrite(HIGH)" 
  4. set the row back to ground "analogWrite(pin,0) 
Then do that for green and blue. Whew!

It kinda works for 1 LED, but it is not very bright. Adding a 1 millisecond delay between the colors helped brighten them. Here's the real problem, more than one LED makes it flicker, beyond belief. I think I'm going to have to figure out how shift registers work. I had assumed that the reason that all of the examples that I have found used shift register because the Unos didn't have enough pins. I didn't think it'd be necessary since the Arduino Mega has so many pins. Maybe it's my code. Who knows?

Saturday, May 11, 2013

The Kids Take Their Turn

Tonight was the kids turn to build their own circuit from scratch, then write their own sketch from scratch.

We started out with a review. I even made an Impres presentation (that's the Open Office version of Power Point.) We reviewed the basic symbols in a schematic that we would use in today's project. Next, we went over the LED, it's properties, and how to determine the anode (+) and cathode (-) side. And, finally, we reviewed the code they would need for the project. This included integer variables, the setup() and loop() functions, analogWrite, pinMode, and a very long discussion about for loops and nested for loops. This eventually, somehow, got into a long discussion about bits and bytes. Now they know how to count in binary. lol!

Next, the kids built their circuit, taking turns installing and wiring 3 LEDs on the mini breadboard and connecting them to the Arduino. They connected the anodes to pins 1, 3, and 5 and the cathodes to pins 2, 4, and 6.

Finally, they wrote the code. The 7 year old wrote the initial comments and the setup() function and the 11 year old wrote the loop(). Debugging was a hoot. They quickly found out that this is case sensitive since it didn't even like the "VOID" before the setup() function.

Their assignment was to turn on and turn off all 3 LEDs in any manor they chose.

They decided to light LED3, pause 1 second, light LED2, pause 1 second, light LED3, and pause 1 second. Then fade LED3 off, LED2 off, and LED1 off. I was impressed with a few things.

  1. My son (the 7 year old) really grasped the concept of variables, because when he wrote his loop in the setup, he chose to create a variable called "code" instead of "pin." This, to me, meant that he really understood that the variable was just a holding place with a name and whatever he chose to name it had no bearing on the program.
  2. My daughter chose to fade out the LEDs. This required her to create a nested loop, making this a much more complex first sketch. Good to know she wasn't afraid to put everything she learned into practice.
Here's what they came up with:

//LED1=+1   -2
//LED2=+3 -4
//LED3=+5  -6

void setup(){
  for(int code=1;code<7;code++){
    pinMode(code,OUTPUT);
  }
}

void loop(){
  for(int led =5;led>=1;led=led-2){
    analogWrite(led,255);
    delay(1000);
  }
  for(int led =5;led>=1;led=led-2){
    for(int code=255;code>=0;code--){
      analogWrite(led,code);
      delay(10);  
    }
  }
}

Tomorrow, we start experimenting with the servo.

Here is our first LED Sketch

First, I have to admit, I haven't figured out how to mix the colors. When I try to do an analogWrite(), I get nothing. So here's a pic of the display.
And, as promised, here is the code. Remember, this will only work on a Mega and Due. An Uno will not have enough have enough pins.

int colsr[]={9,10,11,12,13,14,15,16};
int colsg[]={28,27,26,25,24,23,22,21};
int colsb[]={1,2,3,4,5,6,7,8};
int rows[]={17,18,19,20,29,30,31,32};


void setup() {
  // put your setup code here, to run once:
   for(int pin=1;pin<=32;pin++){
     pinMode(pin,OUTPUT);
   }
   for(int idx=1;idx<=9;idx++){
     digitalWrite(colsr[idx-1],HIGH);
     digitalWrite(colsg[idx-1],HIGH);
     digitalWrite(colsb[idx-1],HIGH);
     digitalWrite(rows[idx-1],LOW);
   }
}

void loop() {
  // put your main code here, to run repeatedly: 
/*  for(int x=0;x<8;x++){
    digitalWrite(colsg[x],LOW);
//    digitalWrite(colsr[x],LOW);
    digitalWrite(rows[0],HIGH);
  }
*/  
  for(int st=0;st<8;st++){
    digitalWrite(colsg[st],LOW);
    digitalWrite(rows[st],HIGH);
//    delay(500);
    digitalWrite(colsg[st],HIGH);
    digitalWrite(rows[st],LOW);
//    delay(500);
    digitalWrite(colsb[7-st],LOW);
    digitalWrite(rows[st],HIGH);
//    delay(500);
    digitalWrite(colsb[7-st],HIGH);
    digitalWrite(rows[st],LOW);
  }
  for(int st=0;st<3;st++){
    digitalWrite(colsr[st+1],LOW);
    digitalWrite(colsr[st+4],LOW);
    digitalWrite(rows[0],HIGH);
    digitalWrite(rows[7],HIGH);
    digitalWrite(colsr[st+1],HIGH);
    digitalWrite(colsr[st+4],HIGH);
    digitalWrite(rows[0],LOW);
    digitalWrite(rows[7],LOW);
  }
  for(int st=0;st<4;st++){
    digitalWrite(colsr[st+2],LOW);
    digitalWrite(rows[1],HIGH);
    digitalWrite(rows[6],HIGH);
    digitalWrite(colsr[st+2],HIGH);
    digitalWrite(rows[1],LOW);
    digitalWrite(rows[6],LOW);

//    digitalWrite(colsb[st+2],LOW);
//    digitalWrite(rows[1],HIGH);
//    digitalWrite(colsb[st+2],HIGH);
//    digitalWrite(rows[1],LOW);
  }
  for(int st=3;st<5;st++){
    digitalWrite(colsr[st],LOW);
    digitalWrite(rows[2],HIGH);
    digitalWrite(rows[5],HIGH);
    digitalWrite(colsr[st],HIGH);
    digitalWrite(rows[2],LOW);
    digitalWrite(rows[5],LOW);
  }
  for(int st=1;st<4;st++){
    digitalWrite(colsr[0],LOW);
    digitalWrite(colsr[7],LOW);
    digitalWrite(rows[st],HIGH);
    digitalWrite(rows[7-st],HIGH);
    digitalWrite(colsr[0],HIGH);
    digitalWrite(colsr[7],HIGH);
    digitalWrite(rows[st],LOW);
    digitalWrite(rows[7-st],LOW);
  }
  for(int st=2;st<4;st++){
    digitalWrite(colsr[1],LOW);
    digitalWrite(colsr[6],LOW);
    digitalWrite(rows[st],HIGH);
    digitalWrite(rows[7-st],HIGH);
    digitalWrite(colsr[1],HIGH);
    digitalWrite(colsr[6],HIGH);
    digitalWrite(rows[st],LOW);
    digitalWrite(rows[7-st],LOW);
  }
  for(int st=3;st<5;st++){
    digitalWrite(colsr[2],LOW);
    digitalWrite(colsr[5],LOW);
    digitalWrite(rows[st],HIGH);
    digitalWrite(colsr[2],HIGH);
    digitalWrite(colsr[5],HIGH);
    digitalWrite(rows[st],LOW);
  }
}

Not the most elegant, but it works.

Eureka...and more

Tonight, I pulled all 36 pins from the Arduino and the breakout boards. I then connected 1 wire to what I thought was pin 17 and the other to what I thought was pin 1. I wrote a quick script to blink these pins with 500 ms delay between. A red LED started blinking. Turns out, what I thought was pin 1, wasn't. I moved the pins down the row, one at a time lighting column 2-8 red, then the green columns. Now that I know what is what, I quickly started rewiring. This time I noticed that that top row of pins on the right were not pins 22-23, but 5 volt leads and the next 2 pins are actually correct. Now I was able to write a script to make an "X" with one green line and one blue one. I'll post the code tomorrow. Now I have to see how to mix colors.

The "and more" part? The stepper motor has finally arrived!!! I can't wait to start playing with that.

Friday, May 10, 2013

Getting wired...

So I attached the LED board across 2 breadboards. You can see the first tiny breadboard peaking out from under the front of the array.  It had 17 rows and, yes, the matrix only needed 16. I verified where pin 1 was and ran leads from each pin to the matching pin on the Arduino board.
It's a thing of beauty, is it not? Now down to business, I have to match up the pins to the rows, columns, and colors for my first sketch. Carefully going through the schematic, I came up with:

int colsr[]={9,10,11,12,13,14,15,16}; //red
int colsg[]={28,27,26,25,24,23,22,21}; //green
int colsb[]={1,2,3,4,5,6,7,8}; //blue
int rows[]={17,18,19,20,29,30,31,32};

I'll have to come up with a little more eloquent method, but this will do to get some lights lit up. Again, referring to the schematic, I see that the LEDs are oriented so that the power is coming from the rows, so the colors/columns are specified by the ground pins. This seems backward to me since, at some point, I'm going to want to write different values to the pins to blend colors instead of just setting them to HIGH.

Next, I created my setup() routine. Here I need to initialize all of the pins for output and set their initial state.

void setup() {
  // put your setup code here, to run once:
   for(int pin=1;pin<=32;pin++){
     pinMode(pin,OUTPUT);
   }
   for(int idx=1;idx<=9;idx++){
     digitalWrite(colsr[idx-1],HIGH);
     digitalWrite(colsg[idx-1],HIGH);
     digitalWrite(colsb[idx-1],HIGH);
     digitalWrite(rows[idx-1],LOW);
   }
}
Since the columns are supposed to be grounds, I chose to set them to the opposite state, so I raised them to HIGH, and the rows, I set to LOW. Makes sense, right? My loop is pretty straight forward. I want to turn on pin 1, row 1, turn it off, then pin 2, row 2, etc. What I ended up with was a pattern, of 1 sometimes 2 LEDs lighting up in each column, but after running for a bit, other LEDs lit and stayed on. Now comes the fun part. Is it my code, or my wiring, or both. I'll keep you posted.

Wednesday, May 8, 2013

Entering the Matrix

No, Keanu Reeves isn't gonna ask you to pick the Red or Blue pill. This is the Matrix, Arduino style. Today, the new breadboard arrived. As I suspected, the LED matrix will not fit. But between the two breadboards, I should be able to make this work. I've already wired pins 17-32 on the mini breadboard and have the LED matrix mounted between both boards. To late to play any more tonight. I'll have to finish running the remaining wires tomorrow. I'll post a picture too.

Wish the servo would get here soon...

Tuesday, May 7, 2013

A few more LEDs

I found 3 more LEDs. 2 were white and the other blue. Like the original, these were destined to be replacement bulbs for a Christmas light set. I don't know their power requirements, etc. which make for a brave assembly on my new Arduino board. At minimum, I believe, from what I've read, that I should have current limiting resisters in my circuit. But, the risk, I hope, is to the LEDs and not my board. So I wired up my tiny breadboard with these 4 LEDs. First, I should point out, there is no flat side on these LEDs, but they do have one longer wire (anode). But, to be sure that it wasn't an anomaly from the assembly process, I read about a third method of determining the positive and negative leads.



Excuse my crude drawing. If you look inside the LED, the wires meet up to little plates inside. The larger side, on the right in this drawing, is the negative.




With that information in mind I wired up my circuit. I used a program from Fritzing to draw out my wiring diagram. Besides providing this tool, which is designed to work with Arduino, they can even custom build a circuit board to your specifications. So, if you ever design something great and even have ideas to sell it, this program will allow you to prototype the wiring diagram, automatically create a schematic, and design the etchings for a PCB that you can then send off to Fritzing Fab to have it made into reality. I can imagine, someday, when the kids and I have fabricated our robot using a breadboard or two to hold all of our wires, we just might want to have boards made, since they'll be smaller and more durable than components stuck in a breadboard.

So here is my drawing (click for larger version.) You'll even be able to see inside the LEDs, when you enlarge, to see what I was talking about above. Now, we get to play a little. My son came up with some scenarios, and we wrote a sketch to accomplish it.I'll go through that code next time.

BTW, I forgot to mention, there is a fourth way to tell the positive and negative side of an LED. Plug it in, power it up, if it doesn't light, turn it around.

Monday, May 6, 2013

Back to ebay






So a new breadboard was in order. I found this on ebay but I'm not convinced that it's any bigger than the other one where it counts. Yes, it has a ton more connections, but across, I don't think it does.



I just superimposed two pictures for this.I don't this this'll work either. I have already ordered this new board, so now I have a decision to make. Do I order some male to female cables? or bridge the LED panel over 2 boards?




So while on ebay, I bought a digital servo, of course the new breadboard, and a 16x2 character lcd display.

I also had a breakthrough on the issue of switching ground wires on the arduino. It was easier than I thought. Simply setting the pin to LOW makes is a ground. And, if I were interested in CharliePlexing, if I set the pinMode() to INPUT, it'll actually remove it from the circuit. Actually, it runs it through a high gain pull-up resister which is the equivalent of removing it from the circuit.

Saturday, May 4, 2013

More Parts Arrive...

Next, the connector wires and the breadboard arrived. The connector wires are cool. Each wire rather than being solid wire or dipped in solder, are attached to a pin connector, plus all 40 wires are molded together like a ribbon cable, yet easily pulled apart.

But the breadboard...
Oops! when the description said "mini," it wasn't kidding. Note to self, "measure first, then order." There is no possible way to do anything with the diode matrix.

In the meantime, some basics for the kids. We talked about current and how if flows from one end of the power source, in this case a battery, through the circuit and back to the battery. We talked about diodes, since this is the first thing we would be utilizing. We especially talked about the fact that they will only allow the current to pass through in one direction.
To drive the point home we did a little experimenting with the Snap Circuits kit that my son got for Christmas. This includes some basic parts like a motor, 3 ICs, an LED, speaker, 2 types of switches, etc. We assembled a basic circuit that had a push-button to turn on the LED. Next, we replaced the LED with a light bulb. To make a point we turned the light bulb around and it still lit when we pushed the button. Then we put the LED back correctly, proved that it worked, then turned it around too. No light emitted when the button was pushed.

The Snap Circuit parts are really clever. First, they do have a genuine snap, like a winter coat would use, on the connection points of each part. Second, they have the schematic representation of the part on it. Now that they saw this, we could talk, at length, about the, much more complex, schematic for the LED array.

But, we still really wanted to get building something, anything, using the Arduino board. I found some LED replacement bulbs that belonged to set of Christmas lights that we had bought. 3 white LEDs, that's it. I took one of the LEDs out of it's plastic housing and placed the long wire (anode or positive) in pin 13 and the other wire (cathode or negative) went into GND (ground) right next to it. We powered up the board and the new LED blinked in time with the on-board LED since our sketch from last time was still on there. Next, I thought we could move the LED to another pin, and modify the sketch to alternately blink the on-board LED then the one that we just moved to pin 10. Just as a quick test, I changed the sketch to just blink pin 10 instead of 13, by changing the led variable to 10. Now, for the record, the anode is in 10 and the cathode is in 9. Compiled, downloaded, nothing. No lights blinked anywhere.

Times up, I have to figure out what to do about the ground. Yeah, I can move the LED to my teeny, tiny, breadboard and have the anode go to pin 10 and the cathode go to ground and all would be right with the world and the sketch. But, there is something that I'm missing...

The Secret is Out

First, my shiny new tri-color LED panel arrived. It was exactly as advertised, but still a mystery. My understanding of multiplexing was vague, but I think I had it, but how am I going to switch grounds? I carefully re-wrapped the panel in its protective bubble wrap and placed it, reverently, on top of my PC.

When my Arduino arrived, I couldn't wait to do something, anything.  The kids were almost as excited as I was. But right away, they were ready to start building a robot. It will be tough to convince them of the need to learn a lot of theory before diving in.

First Sketch

I had read that the Arduino had a permanent LED mounted on the board, attached to pin 13. Since I have no other devices or LEDs to attached to the board, this would have to suffice. With that in mind, I planned to blink that LED, the Arduino equivalent of "Hello World," the first program that almost every programming language teaches as its first lesson. Loading the Arduino software had already been done. It merely has to be extracted from its zip file. I chose to put the development on a thumb drive so that whether I use my PC, laptop, or whatever, I would be able to carry the code with me.

The next step was to install the Windows drivers. The Arduino site provides simple instructions. Plug in the Arduino to an available USB port. When Windows gives up trying to find the appropriate drivers, you close the wizard, browse to the device manager, and open the new unknown device. Open that device, click update driver, and browse to the driver folder in the Arduino development directory. The only other thing necessary is to note the com port that it is assigned.

Opening the Arduino development application, I browsed the example library and opened one under the basic heading aptly called "blink." Scanning the code:
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}
First, I noticed that the pin assignment in this example was 13 for the on-board LED. Perfect. Next, I went into tools and selected com3, since this is what my driver was attached to. I confidently clicked the upload button and nothing happened.

[sigh]

Then I realized I hadn't selected the board. Quickly, I went to the tools->board menu and selected the "Arduino Mega 2560." Clicked upload, and this time breathed a sigh of relief as the little red LED blinked off and on. SUCCESS! Later, I showed the kids, line by line through the code, explaining variables, the two required functions, how the pinMode function prepares the pin for, in this case, output, how the digitalWrite function turns on or off the LED, and finally what the delay function does.

For fun, we played with the delay values and shortened them to see the results.

Now I have to figure out the next step...

Friday, May 3, 2013

Back to school...

So my research turned up some good information about multiplexing, shift registers, and, of all things Charlieplexing.

Multiplexing and Shift Registers

Instructables has a pretty good explanation on how to implement multiplexing using a 74HC595 chip here. It simply allows you to effectively increase the number of pins that your main board has. Basically, you turn on (power) one row of pins and ground the columns of the pins that you want to light. Then you cycle through each of the rows, grounding the appropriate columns. Thanks to persistence of vision, all of the desired LEDs appear to be lit at the same time. 
Persistence of Vision is like what you see when you go to a laser show. Most of the pictures are drawn with a single laser. The laser is not that much different than a laser pointer that you may have used, only a stronger beam. This beam is bounced off of mirrors that are attached to salvos that bounce the beam in the direction that it will draw the next segment. These mirror/galvo devices are so fast 15-30Hz that there appears to be solid lines. 


Most TVs and computer monitors only use 60Hz. That means the entire screen is repainted 60 times a second. My simple 8x8 Matrix will need to paint 8 rows and 24 columns roughly that fast or there will be a noticeable flicker. 

Charlieplexing

This method allows you to arrange an array of diodes in such a way that you can use even less connections. Again, Instructables has a great explanation here. The long and short of it is that by turning on, grounding, and removing pins electronically, and using the polarity (the fact that electricity will only pass through in one direction) of the LEDs, and lastly, the fact that current will always follow the path of least resistence, it is possible to control 20 LEDs with 5 connections, or 90 with a mere 10 connections.

In the end, my LED array is simply not wired that way. 

...now how to I turn ground on and off?

Thursday, May 2, 2013

Troubling discovery...

Now having made my first purchases, I took the time to examine what I had purchased. In buying the LED panel, I reasoned, that it would be necessary to start with the basics. We would need to learn how the board worked and how to start making our circuits. I thought what would be easier than turning on a light. I went back to the ebay listing for my purchase. It had included technical specifications and a schematic.
The first thing that I noticed was that it showed 8 rows with pin numbers 17, 18, 19, 20, 29, 30, 31, and 32. While odd that the pin numbers were grouped in 2 sets of 4, this didn't bother me as much as the fact that each column had 3 pin numbers. Pins 1-8 look to be connected to blue, pins 9-16 are connected to red, and pins 21-28 are connected to green. How could it be that each column had 3 pins? The diagrams didn't really show the pins, but there was a photo that showed the bottom of the panel. I carefully counted the pins, using my mouse to keep track, and found that there were 32 pins. 64 LEDs, but only 32 pins. Even more concerning, since each color of each led was treated as it it were a separate led, there is really 192 bulbs. I knew enough about electronics to know that each would require a positive and a negative so that brings us to a whopping 
384 connections with only 32 pins!
Now, I'm not a complete stranger to electronics and schematics. Most of my education came from Radio Shack and the electronic project kits that I loved so much as a child, too many years ago. I remembered, for example, that an led, which is a type of diode, will only let power pass in one direction which flows in the direction that the arrow. 
Looking at the schematic for the LED panel, I can see that each of the rows are tied together to the positive side of the diodes, and then there are 24 columns tied to each of the negative connections. Apparently, I have to be able to switch both positive and negative on and off to light these LEDs.
So much for starting out with the basics. This would require a lot more research. Still, I don't regret my Arduino purchase and can't wait for it to get here.

Note to Reader

This Blog was not started until after the first parts started to arrive. It is my intent to share the events that happened as accurately as possible, but it is necessary to compress the timeline to bring the entries current. At least this will save the reader the dreadful wait for products to arrive from China.

Wednesday, May 1, 2013

More purchases...

By the end of the day, I ordered an 8x8 color led panel $4.99+$1 Shipping, a set of jumper wires $2.75, and a mini prototype board $1.49 Now off to the Arduino web site to download the development environment.

In the beginning...

Like I said, I have always been a closet hardware junkie. I've been watching the emerging prototyping platform like Arduino and Raspberry Pi but never had a really good reason (ok, excuse) to spend some time and money on it. The pros and cons came down to one simple item...price. It looks the the Raspberry Pi is almost a stand alone PC, but it is much more expensive than the Arduino. Looking at the various options, and pricing them on ebay, I decided that the Arduino Mega was the best bang for the buck. ebay has tons of listings for under $20 and this has a bunch of extra pins that the Uno model doesn't have.

I bid on "Hiduino ATmega2560-16AU + ATMEGA16U2 + USB Cable For 2012 ARDUINO's MEGA 2560 R3" not really paying attention to the first word of the sentence.

...and won... for $16.50 and Free Shipping

Ok, so it's a knockoff. It's an open source platform anyway, right?

Shipping via China Post... Hmmm... This could be a while...

Oh well plenty of prep to do, right? I need a breakout board, servo motors, wires, etc.

Wait!!! Slow down. This is a project for you and the kids.

But wait, that full color 8x8 panel looks cool... Two clicks later, I'm the owner of an led panel for $4.99 and $1.00 shipping.

Mini Breadboard... click    click
Jumper Cables... click    click

Now, I think I've got enough to get started. Now time to wait for a slow boat from China.

The idea

I've been a software developer for all of my adult life, but I've always had a soft spot for hardware, building my own home computers instead of buying. When my 11 year old daughter and 7 year old son came to me asking if we could build a robot, I couldn't have been happier.