Is Your LED in Backwards?

Since the Arduino I/O pins can sink and source current, it is possible to use one pin as the ground and the other the supply for an LED.  One of my very first projects, actually used bi-colored LEDs and you could change the color by reversing the pins.

I've been doing beginner soldering kits, and putting an LED in backward is a common mistake. It occurred to me I could use this trick so that a reversed LED could still be used without having to remove and reverse it. Better yet, could it be detected and accounted for automatically?

Since the LED only allows current to flow one direction (unless it is bi-colored), and we have the ability to read the pins as well as output to them, we should be able to figure this out. If we apply voltage (via the internal pull up resistor) to one leg of the LED, if it goes high, near the source voltage, we can assume we are dealing with the cathode, or negative side since no current is flowing. Conversely, if the voltage drops, we can assume we have the anode, or positive side since current is flow.

Enough theory. Time for proof. With the LED correctly installed, an analogRead() on the pulled up port reads ~350, or 1.7 volts.  With it in backwards, it reads nearly 5 volts.  Since the voltage drop is more than half, the digitalRead() can be used and the resulting true/false value assigned to correct or incorrect orientation.

Seems like a silly thing, but then again, silly things can be useful at times.

Here is my code if you want to try it for yourself:

int ledPinNeg = A0;  // assume negative lead
int ledPinPos = A1;  // assume positive lead


void setup() {
  Serial.begin(9600);

  // test: with a weak pullup, the pin will read HIGH if LED in backward (no path for current)
  pinMode(ledPinPos, INPUT);
  pinMode(ledPinNeg, OUTPUT);
  digitalWrite(ledPinPos, HIGH); // turn on pull up
  digitalWrite(ledPinNeg, LOW);  // sink current
  int testVal = digitalRead(ledPinPos);  // reads < 400 if orientation is correct
  
  Serial.print("Pin ");
  Serial.print(ledPinPos);
  Serial.print(" = ");
  Serial.println(analogRead(ledPinPos));
  
  // set both pins to OUTPUT and LOW
  digitalWrite(ledPinPos, LOW); // turn off pullup
  pinMode(ledPinPos, OUTPUT);

  if (testVal){// LED is backward, just swap pins
    int temp = ledPinPos;
    ledPinPos = ledPinNeg;
    ledPinNeg = temp;
    Serial.println("LED IS BACKWARDS OR MISSING");
  }
  else {
    Serial.println("LED APPEARS CORRECT");
  }
}


void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(ledPinPos, HIGH);
  delay(1000);
  digitalWrite(ledPinPos, LOW);
  delay(1000);
}

How to Price a Kit


 
- VS -
I've seen a couple of post recently on Hack-a-day and Twitter about my Geek Spinner (and US based kits in general) being priced too high.  As both a maker and consumer of kits, let me first say that I am sensitive to this issue. When I price a kit, the first question is always, "would I pay this much for it?"  Consider the following:

  • I publish my BOM and PCB files along with instructions and firmware, so you don't need to buy anything from me.
  • I sell kits to cover the cost of my developing them.  I usually build at least three versions before I'm willing to put it out there for others to try.
  • I price the kits to cover the cost of materials and my time for packaging the kits.
  • I enjoy designing and making kits and helping others make them.  I do not enjoy kitting or selling them. It is a lot of work.
  • I'm selling at very low volumes, usually in multiples of ten, where the scale of economy has barely begun.
I think, in general, what we fail to recognize when we look at the price of kit, are the intangibles:
  • Well documented, well supported.
  • Quality components from known sources.
  • Design files and schematics so we can understand or modify the design to our own purpose.
  • Tutorials and examples files.
I've sold enough kits to know that I'm at least in the ball park.  I'm making enough so my wife doesn't need to see the credit card bill for the weekly Digi-Key delivery, or to sweat making a medium-run OSH Park PCB order when I'm ready to face the public.  I'm also sure, that if I total it all up, I'm  making below minimum wages.  But then again, I'm doing something I enjoy.  For the most part.

So, vote with your dollar.  But also ask yourself, "is the seller adding any value?"

Building Your Own Multimeter

An experienced hobbyist should be able to build a well designed project from the BOM (bill of materials) and the markings on the PCB.  The rest of us need some help. I recently put together an $11 multimeter that had very little documentation, and I figured I might add some tidbits to the interwebs that might help others get through this.  Like a Jedi and their lightsaber, what could be better than building your own instruments!

This is a DT-830T "Digital Multimeter Electronic Training Kit from Banggood.com.  If by "training", they mean figuring things out on your own, this is a winner.  My first plan of attack was to sort the resistors and mark the PCB diagram with values (why don't they do that to start with?)  Ironically, since I can't identify anything other than 330, 1K and 10K by sight, I used a multimeter to test and label the resistors.  Kind of a chick-and-egg thing. There are more 220K resistors than any other, so getting them out of the way significantly lowers the others than need sorting.
The only thing that tripped me us was the fact that resistors R17 and R38 have switch position between the diagram and the PCB silk screen.

With resistors out of the way, I turned my attention to capacitors. Again, I'm not good with reading values, but another recent project, a GM328 Transistor Tester, got put to go use.

Here are the values and markings:

  • C1 - 100 pF - "101"
  • C7 - 220 pF - "221"
  • C2, 4, ,5 ,6 - 100 nF - "104"
  • C3 - 220 nF - "224"
  • C8 - 1 uF - "105"

The final unidentified component was marked "4B DMZ".  This is a re-settable thermal fuse, and by this point there are only a couple of empty spots on the PCB it could go (R32).

There are some springs and ball bearings that were not obvious (to me) where they went. I found a Youtube video of someone assembling this as a clue.

With everything assemble, it worked, and I tested it against known voltage and resistance, and it was pretty close. There is an a potentiometer (VR1), which I assume is for adjustment, so I tweaked it to match the known voltage.

My main use for a multimeter is as a continuity checker with the buzzer.  That is where this meter shines.  Instead of having to rotate the selector switch to the resistance setting on the Fluke and then press a button to get the speaker, I can leave the rotary on the DT-830T on continuity and just turn it on and off with the push button.  Not many meters work that way. That alone makes it a keeper.  Plus, I can say "I made this myself".

And, if it helps you, here is my scratchpad:



How Fast is Your Fidget Spinner?

You never know what people will do with your ideas, and it is always fun to see someone do something I would have never thought of with them.  I got a video from someone who built my Programmable Fidget Spinner, and used a leaf blower to see how fast they could get it to go.  Fortunately, they were wearing safety glasses, and no, it didn't come flying apart.  It did, however, start displaying erratically at about 3600 RPM (the fastest I can get it by hand is just under 2000 RPM).

So, what is going on?  TLDR: I figured it out and fixed it, and here is proof.

One of the reasons I love Arduino is because it is so easy to write and understand it's code.  All the hard parts that scare beginners away have been abstracted out.  Case in point, to turn on a single LED, all I have to do is call the function digitalWrite(LED, HIGH).  The only thing I need to know is what pin number the LED is attached to and that "HIGH" means "ON" (and "LOW" means "OFF").  To display on the eight LEDs on the fidget spinner, I can use
    for (int led=0;  led<8;  led++) {
      digitalWrite(LEDS[led], state[led]);
    }
Which means to iterate over the eight pins the LEDs are attached to, one at a time, and turn them on or off based on the value held in the state array.  Easy-peazy, and all is well, unless you are doing something that becomes time limiting like turning those LEDs on and off in an ever decreasing amount of time as the figet spinner speeds up.  At some point (about 3600 RPM), there just isn't enough time, and the CPU moves on to something else, leaving the LED output garbled.

Now intuitively, I know the Arduino is more than fast enough to do what I want, the problem is that the digitalWrite() function hides a lot of dirty work under the hood, and calling it in a loop only multiplies the problem by eight!  When you realize that each of the eight pins is actually an 8-bit port, and that you can set all eight at once using a PORT command, you can increase your speed by almost an order of magnitude.

Of course, there is a lot more detail (and math) to this than I feel qualified to try and explain, but I did try a few timing experiments a while back that probably helped me figure my current conundrum out. Perhaps the most instructive thing to do here is demonstrated how to do the venerable "blink" sketch using ports.

First step in leaving the comfort of Arduino abstaction is figuring out from a Pin-Out chart  that Digital Pin 13 (the built-in Arduino LED) is actually bit 5 of Port B on the Atmega328 chip, a.k.a "PB5".

Instead of pinMode(13, OUTPUT); we set the data direction bit of DDRB for bit 7 to 1 using the command DDRB = B00100000; 
Now to turn the LED on, we set bit 5 of port B high using PORTB = B00100000, and off using PORTB = B00000000

Realize, off course, that we are controlling all the bits of the port the same time, and that there are clever ways to hit just the bits we want, but I'll save that for a later post.

The most instructive part of this experiment is seeing the difference in the sizes of the regular blink sketch (1030 bytes), and the port manipulation equivalent (634 bytes) is almost 400 bytes!  That doesn't seem like much if you are thinking about 32K of memory, but realize that each byte represents an instruction, and you can see we are not just wasting program space, but also using a lot instructions to do the same thing.

I think the bottom line here is to realize that Arduino is great, and abstraction makes life easy, but at some point, you will have to get your hands dirty if you want to go fast!



500 Tindie Orders, 1200 Kits Sold!

When I started selling kits on Tindie, I made 50 Yet Another Programming Shield Kits, and hoped to sell half of them to break even.  The one thing I realized quickly was that I would need more than one kit offering if I hoped to make any money.

Three and a half years later, I've filled 500 orders consisting of more than 1200 kits of eleven different types.  This doesn't count kits I've sold for workshops and conferences, which would be at least another 500.  I'm making just enough money to keep developing new kits and buying PCBs from OSH Park without putting them on a credit card my wife can see.

I've been amazed at how many overseas sales I've had since the shipping costs seem prohibitive. I've sold to every continent except Antarctica (contact me and I'll make you a deal):


I've also sold something to every US state except Montana, North and South Dakota, Alaska, and Maine (contact me and I'll make you a deal).

I've got some great kits in the works, including an awesome low-cost robot and a Raspberry Pi Camera setup.  I can't wait to see where the next 500 kits go!



Girl Scout Girls Are Awesome

I got invited to do an electronics workshop at a Fall Girl Scout daycamp. I had been on a Maker hiatus since HP let me go back in February, and I was really missing the fun and joy of teaching. The camp was on the east side of the Oregon Coast Range, and although it was cool and a bit wet, the lodge was warm and dry and overlooked a serene pond.

The sessions were an hour and half which was more than enough time to assemble my simple LED kit and give the girls time to incorporate it into a craft project. Before starting, I talked about Ann Makosinski, a young lady who invented a LED flashlight powered by body heat, as an example of why you would want to learn to solder. I also gave the girls a "nanosecond" of wire and told briefly of the contribution of Grace Hopper to computer science.

The girls were positive and awesome and picked up the skills quickly. It always gives me warm fuzzies when I overhead comments like "this is fun" and see the girls helping each other! It is fun to learn, fun to do, and fun to teach others!

The final group was more advanced, and had purchased Adafruit LED goggle kits.  I pre-programmed the microcontrollers, and the session was just enough time to assemble and test them. Since the theme of the camp was Steam Punk, they fit right in with the costumes the girls had prepared.

I am always grateful that my girls are growing up in an age when they can be independent and do anything their heart desires. I am also grateful for opportunities to help others find their passion.

ChickTech Robotics 2015

I've spent a lot of the past year designing and testing a low-cost robot that could be assembled and programmed in a workshop. It has been, in one form or another, demonstrated at three Maker Faires this year. I finally got a chance to put the project to a full test for ChickTech's Portland High School workshop. 
The event was held at Portland State University. There were more than one hundred students that got to chose between eight different workshops. We had fourteen girls for robotics. We spent the first day building the robot and learning how to program an Arduino microcontroller.
The second day we finished the robot and learned how to program it. In my workshops I always emphasize that makers have to patient and persistent, and the girls, most of whom had no prior programming or electronics experience, did a great job in picking up those skills.
At the end of the event, the girls got a chance to show off what they had learned to family and friends. This is always the pay off for me as I hear them proudly explain things I was teaching them just hours earlier. It always makes all the time planing, preparing, and teaching well worth it.