Saturday, May 21, 2016

Controller Extension Tutorial - Part I

Overview


The Nusbio's Controller Extension allows to turn on and off programmatically using any .NET language up to 3 devices.


In this part I, I will use the simple version of the extension which automatically provide current to power the devices and therefore each device must be 5 volts.
The limit of current per device is 200 milli-amp (mA) because this is the limit of the 2N3904 transistor used by the extension.
Also the total consumption must be less than 500 milli-amp, because this is the USB limit and the devices are really powered by the USB of the computer.

The rule of thumb is that an LED use 20 mA and this lamp has 3 so 60 mA. Simple motor found in printer will use 100 mA. To learn how to measure current consumption, see links at the end of this post.


Where to start?

Pick a 5 volts device like this lamp, even if the device is powered with battery like 3 AA battery (3 x 1.5 ~= 4.5 ~= 5 Volts ) and attach or solder a black wire to the negative and a red wire to the positive. Just follow the current black and red wire currently hooked from the batteries to the device.



a


Now, we have 3 items
  1. The Nusbio board
  2. The Controller Extension
  3. The 5 volts lamp



Plug the extension into Nusbio and
  • The black wire from the device must be plugged into the G0 pin (Ground 0)
  • The red wire from the device must be plugged into the V0 pin (VCC 0, in short VCC mean +)
  • Turning on or off Nusbio GPIO 0 programmatically will power or not the device



Programming

The shortest code would look like this and will turn on the device for 500 ms and turn it off for another 500 ms. The Nusbio .NET library is written in C# compiled as .NET 4.0 and therefore compatible with VB.NET, F#, PowerShell and IronPython.

var serialNumber = Nusbio.Detect();
if (serialNumber == null) // Detect the first Nusbio available
{
    Console.WriteLine("Nusbio not detected"); return;
}
using (var nusbio = new Nusbio(serialNumber)
{
    while(true) {
        nusbio.GPIOS[NusbioGpio.Gpio0].DigitalWrite(true);
        Thread.Sleep(500);
        nusbio.GPIOS[NusbioGpio.Gpio0].DigitalWrite(false);
        Thread.Sleep(500);
    }
}
 

To learn more

  Transistor Crash Course For Software Developer - PART I - Transistor As Switch  
  Measuring Current with a Digital Multimeter
  YouTube is your friend, if you want to learn electricity

No comments:

Post a Comment