Tuesday, December 13, 2011

OOP – Resistor Storage

I finally did it.  I threw in the towel.  I finally reached the point where my loss of productivity forced me to stop and do something I’ve been threatening to do for a while.  I decided to get organized.  I’ve spent a lot of time out in the wood shop this year getting it organized (more posts coming!). However, the electronics lab is a different monster that I’ve been thinking about for years about how to best handle but could just never come up with that perfect unique idea.  Operation: Organize my Parts (OOP) has begun.

So, I decided to think smaller.  I’ve been spending a lot of time working on several different electronics projects in recent months and by far the most time consuming activity has been searching through my pile of resistors.
 
PileOfResistorBags

In truth, I started this little project over two years ago when I bought a lot of fourty Plano 3449 mini tackle boxes off eBay (for about $1 each) for this purpose.  However, I took a couple years off from doing anything serious with electronics and so the boxes have just sat in a bigger box in my office.  When I bought the boxes, my idea was basically to put every different value in a separate compartment.  However, the more I thought about it that was a terribly ineffective use of space since a vast majority of the resistor values I have come from assortment bags and I only have 5 to 10 units of each value.

2011-12-12 22.36.26So, I started to think about how to better utilize the space within the compartments of the Plano boxes to help reduce the number of boxes required to store the complete resistor collection and to allow me to be able to quickly and easily find & store resistors when needed.  To make it easy to find resistors, I knew I needed them labeled with their numeric value and sorted.  To make it easy to store resistors, I knew I would need their color codes easily viewable.

2011-12-12 22.37.09
The solution I finally arrived up was an envelope system that had a closing flap that contained the resistor value and the color codes such as the one on the left.  The colored flap secures the envelope and also prevents accidental spilling should the box get dumped.  To make the envelopes, I decided to create an Excel spreadsheet to help with the color coding.  This turned out to be a much bigger challenge than I initially expected.  Consider this my Christmas present to you should you decide to use it (I’ll expect a Christmas card in return! ;)

ExcelLayoutAfter printing out pages of all the envelope templates that I needed, it was then just a matter of sitting in front of the TV with some scissors cutting out all the squares, folding them and taping the ends.  I then sorted through and identified all the resistors and placed them in their appropriate envelopes.

The rule of thumb that I've been using and which has worked very well regarding resistor inventory is to start out with a couple 1000 resistor assortments from eBay.  Then as I run out of a particular value, I order 200 to replace it.  20 resistors is about all that will comfortable fit in the tiny envelopes.  So, for more than that for a single value they get their own dedicated compartment within the box.  I place the envelope over the divider so that it's value & color code are easily visible.

2011-12-12 22.35.26I'm now able to fit all of my resistors into three of the Plano boxes and can locate the needed one within seconds instead of minutes.  It's especially nice that the boxes are clear and I'm able to view the labels through the box lid without opening it to locate the correct box.  It took several nights to get it all setup and sorted but now it's very easy to maintain and I consider it well worth the effort.

A couple of issues to mention concerning the Excel spreadsheet.  First, I was focused on the majority of my resistors that are 1/4W and failed to provide a way to note this on the envelope.  Since I'm not willing to recreate the envelopes just to add a "1/4W" label on them, the approach I'm taking is that as I add resistors of a different Watt rating then I hand write "1/4W" below the resistor value in the empty white space and print the new envelope for the new value with the Watt value on it.  If you decide to use my spreadsheet, you should add the W label on there before printing.  Secondly, the data formatting abilities in Excel seems to have a limitation where it is not possible to have it hide the decimal if the format contains the ability to have decimal places.  For example, if the format is "0.##" and the number is 10 then it will display the number as "10." (including the period).  So, for this reason you will see a lot of extra periods on the envelopes.  If you know a way to eliminate the period, please leave a comment with the solution and I'll update the spreadsheet.

2011-12-12 22.33.19I hope this post has helped someone else escape "resistor hell".  Now onto capacitors...

Tuesday, November 8, 2011

FEZ Hydra Announced!

Today, GHI Electronics announced their much anticipated FEZ Hydra Gadgeteer mainboard.  This is GHI's first Open Hardware/Software Gadgeteer board.  The Hydra represents a significant upgrade in power vs. the FEZ Spider Gadgeteer mainboard released earlier this year and is being offered at a lower price.  I'll briefly compare these two Gadgeteer boards here and will be presenting a more exhaustive look at the Hydra in a few days when my board arrives and I can do an unboxing post.

See GHI's official announcement.

FEZ Hydra

FEZ Spider
Processor 240MHz 32-bit ARM9
(running at 200MHz)
72MHz 32-bit ARM7
RAM 16MB SDRAM 16MB SDRAM
Gadgeteer Sockets 14 14
Type A 2 2
Type B 1 1
Type C 0 1
Type D 1 1
Type E 0 1
Type F 1 1
Type G 1 1
Type H 0 1
Type I 2 4
Type K 1 1
Type P 1 2
Type R 1 1
Type S 2 2
Type T 1 1
Type U 4 4
Type X 2 2
Type Y 10 7
Type Z 1 1
FLASH 4 MB 4.5 MB
Open Source Hardware Yes No
Open Source Software Yes No
Graphics Support Yes Yes
TFT Display Interface Yes Yes
FAT Support 16/32 16/32
TCP/IP Stack SSL, HTTP, TCP, UDP, DHCP SSL, HTTP, TCP, UDP, DHCP
USB Device USB 2.0 (12 Mbps *) USB 2.0 (12 Mbps)
USB Host No Yes
SD Card Support 4-bit w/ no size limit 4-bit w/ no size limit
Dimensions W 3.42" x L 2.44" x H 0.5" W 2.25" x L 2.05" x H 0.5"
Active Power Consumption 130 mA 160 mA
Idle Power Consumption TBD 120 mA
Hibernate Power Consumption TBD 40 mA
Operating Temp -20 to 70C -20 to 70C
RoHS Compliant Yes Yes
Lead-free Compliant Yes Yes
Configurable LED 1 1
Price $79.95 $119.95

*USB Device was previously reported to have 480Mbps speed. Prior to shipping this was changed.

Saturday, October 15, 2011

NETMF Extension Methods

If you come from desktop development with the full .NET Framework then you're probably familiar with extension methods.  Extension methods allow us to write functions that extend existing classes for which we may not have the source.

For example, suppose for our project we know we will commonly need to convert strings to an array of their ASCII character codes.  We could write a function that accepts a string parameter and returns an integer array but a cleaner alternative would be an extension method.

var someString = "ABC";

// Using a function it would look like this...
var asciiCodes = ConvertStringToAsciiCodesArray(someString);

// Using an extension method it would look like this...
var asciiCodes = someString.ToAsciiCodesArray();

However, if you have created extension methods before and you just dive in and try to create them in NETMF as you normally would then you'll either quickly assume they just aren't available in NETMF or you'll end up here.  Creating extension methods in NETMF as you normally would will result in the following error when you try to use the this keyword.
Cannot define a new extension method because the compiler required type 'System.Runtime.CompilerServices.ExtensionAttribute' cannot be found. Are you missing a reference to System.Core.dll?
Then you'll probably look for System.Core to reference and won't be able to find it...  You won't.  Don't need it.  This is a mostly useless error.  But what you do need to do is demonstrated in the following code sample.  Pay special attention to the first block of code that is used to enable extension methods in NETMF.

using Microsoft.SPOT;

// Required for NETMF to recognized extension methods
namespace System.Runtime.CompilerServices
{
    [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
    public sealed class ExtensionAttribute : Attribute { }
}

// Extension methods for string - note that it must be static
// You'll probably want to put this in it's own file.
public static class StringExtensions
{
    // Method to convert a string into an array of it's ascii character codes.  Note that it must also be static.
    public static int[] ToAsciiCodesArray(this string me)
    {
        // Make sure a null isn't passed in.
        if (me == null) return null;

        var chars = me.ToCharArray();
        var asciiCodes = new int[me.Length];
        for(var ndx = 0; ndx < me.Length; ndx++)
        {
            asciiCodes[ndx] = chars[ndx];
        }
        return asciiCodes;
    }
}

namespace ExtensionMethodsTutorial
{
    public class Program
    {
        public static void Main()
        {
            // Let's test out our new ToAsciiArray() extension method;
            var someString = "ABC";
            foreach (var asciiCode in someString.ToAsciiCodesArray())
            {
                Debug.Print(asciiCode.ToString());
            }
            return;
        }
    }
}

I hope this gets you going creating extension methods in NETMF. Feel free to contact me if you have any other problems with extension methods or NETMF in general.

CREDIT:  I first found the solution to this problem here but thought it deserved a more public write-up.

Saturday, September 17, 2011

Using a Joystick With NETMF and the NETMFx Joystick Library

JoystickOnPandaII
As I’m working on the Omnimote, I decided the next article in the NETMF for Electronics Noobs series should be about how to interface a joystick with a NETMF device.
For this example, I’m using a Parallax joystick from Adafruit.com.  Sparkfun has a similar joystick which should work using the same directions although the labels for the pinouts are slightly different.  I prefer the one from Adafruit because it has a nice rubber feel to it and it’s pin headers fit in a breadboard.  The one from SparkFun is a slippery hard plastic and requires you to buy a separate PCB in order to make it breadboard friendly.  It does have the advantage of an additional push button selector built-in that the one from Adafruit does not.  They both have convex tops.  I would have much rather had concave tops such as you get with an XBox 360 controller but these were not carried.

A joystick controller is simply a stick connected to two small potentiometers – one for the left-right (X) motion and one for the up-down (Y) motion.  To connect the joystick to the board, we will need two analog pins plus +5V and ground connections.  The following table will show the labels and pins for these two joysticks.
Adafruit Joystick Sparkfun Joystick Arduino Compatible Pin
L/R+ VCC +5V
L/R HOR Analog*
U/D+ VCC +5V
U/D VER Analog*
GND GND GND
Any two analog pins can be used for L/R and U/D.  For this tutorial, I am using Analog0 for L/R and Analog1 for U/D.


image
This post also serves as an announcement of a new open source NETMF library I’ve created called NETMFx.  This will serve as a place for me (and anyone else who wants to contribute) to put custom drivers and anything NETMF related.  My goal is to make anything in it compatible with both GHI and netduino so that the greater NETMF community can make use of it.  I’ve done this by using conditional compile symbols when necessary.  Be sure and check out the progress made so far in NETMFx.Joystick and NETMFx.Math projects in the NETMFx source code download.

There is also a “Samples” project in the NETMFx solution where I’ve posted a sample project called “Joystick Tutorial” that is specific to this post.  I’ve done a fairly complete job of documenting the project from the code so I will not bother going into detail in this post.  Feel free to contact me if you need further clarification of how to run the code once you have everything wired up.

Thursday, September 8, 2011

Sawdust - Entertainment Center

I just realized that Software & Sawdust is really all software and no sawdust at the moment...  So, to break things up a little I'm digging up a project I finished last year - a custom built entertainment center.  I keep my woodworking project details on the LumberJocks.com site.  Read more about this project and a few of my other projects.  As the weather is cooling down, I'll be getting out in the new workshop more in the next few months.  We built a new house this year and are in need of a lot of bookshelves and my home office has a lot of needs.  Where to begin...?

Tuesday, August 30, 2011

Controlling a Brushless Motor with NETMF

2011-08-30 22.10.59
Continuing with the NETMF for Electronics Noobs Tutorials.  Today, I’ll demonstrate wiring up a brushless motor to your NETMF device.
 
If you’re building any type of R/C planes, copters, cars, boats or robots with your NETMF device then you’ll likely encounter the need to control a brushless motor.  Controlling a brushless motor is very different than controlling a regular brushed DC motor.  What makes it different is the addition of the Electronic Speed Controller (ESC).

The main reason this article exists is because the hobby parts distributors have done a terrible job of documenting these most basic of parts.  You should be able to go to the manufacturer website for the ESC you purchase and get most of this info.  However, my experience is that you can’t and they assume you know what you’re doing if you buy these parts.  Obviously, not the case or you wouldn’t be here.

If you click on the main photo, and look closely at the ESC (the blue part in the lower left corner) you will see that on one side it has three black wires.  These colors may vary from model to model.  On the other side it will have two thick red & black wires.  It will also have a bundle of two or three thinner wires depending on your model.

2011-08-30 22.12.09First connect the three black wires from the ESC to the three wires coming from your motor.  Right now you’re thinking “which wires on the motor go to which wires on the ESC?”.  Trust me, it doesn’t matter.  To understand why, study how brushless motors work and you’ll understand.  For now, just take a leap of faith.  If you find later that your motor is turning in the wrong direction, then swap any two of these wires and the direction will change.  It’s magic…
2011-08-30 22.24.17
The small bundle of three wires on my ESC are colored brown, red, and orange.  After quite a bit of digging, I finally found that the two outer wires are the important ones.  The brown wire is ground and the orange wire is the control.  The red wire in the center provides 5V power and can be used to power the microcontroller.  Most people do not recommend this due to the fact that when the motor is accelerated quickly it is possible that power could be momentarily lost.  This is an especially bad situation if you’re controlling a flying vehicle.  It’s not so bad if you’re controlling a car or plane.  If your bundle only has two wires, then you do not have the power wire.

You should wire the brown wire of the ESC bundle to any ground on your NETMF device.  For this example, I’m using a GHI Panda-II.  The orange wire should be connected to any PWM pin.  I’m using PWM1 (I/O 10).

2011-08-30 22.12.31Next, all you need to do is connect the red & black wires from the ESC to the respective wires on your battery.  If all is well, you will probably hear a series of tones from your ESC indicating that it is now armed.

NEVER TEST YOUR MOTOR WITH A PROPELLOR ATTACHED!!!

Until you have fully tested out your controls and have everything mounted securely and have a safe place to work, it is a really bad idea to attach the propellers.  If you have never worked with a brushless motor with a propeller on it, you will probably be amazed at how much power they have the first time your power it up.  Propellers are very sharp and will cut you.

Now that everything is wired up, it’s a simple thing to get the software going.  Start by downloading Chris’ Brushless Motor ESC driver class and add it to a new NETMF project.  Assuming you also used pin 10 to control your ESC, the following code should test your motor by powering it up to 20% power for about half a second and then powering it off.  Push the reset button to make it go again.

public static void Main()
{
    var m1 = new BrushlessMotor((PWM.Pin) FEZ_Pin.PWM.Di10);
    m1.Scale = 100;
    m1.SetPower(20);
    Thread.Sleep(500);
    m1.Stop();
}
If that works then you’re off and running.  Just figure out what power your project needs and when then apply where necessary.  If you need additional motors, then rinse & repeat but use a different PWM pin.

If you’re using a netduino or other NETMF device, do not be dissuaded.  It’s very easy to port Chris’ driver class to your device and to make the appropriate change to the test app.  Feel free to drop me a line if you need help.

Choulant asked for it and here they are - the parts used in this tutorial:



Have fun!

Congrats to my new Eagle Scout!

This post isn’t about software or sawdust but about something more important.  My son was awarded the highest rank in Boy Scouts this weekend – Eagle Scout.  Only about 2 out of 100 boys that start the Scouting program achieve this and I’m very proud of him.  He’s worked very hard (with a lot of encouragement ;).  I’m sure this is going to be the first of many great accomplishments we see from him.
imageThe Boy Scouts is unquestionably the best youth program that exists.  If you would like to learn more or find a local troop to join, go to the BSA website.  I’ve been a Scout leader for many years and will be glad to also assist with any questions you may have.