Thursday, June 25, 2015

GDevice is now renamed Nusbio

On June 23 2015, I renamed the device from GDevice to Nusbio.

This will explain why on previous post the device referenced as GDevice.

How fast can I turn a Nusbio gpio on and off in C#

How fast can I turn a Nusbio gpio on and off in C#?

The oscilloscope says 1 Milli second to turn it on, 1 Milli second to turn it off.
 



How fast can I turn a extra gpio pin on and off in C#?

The extension Ex8G32kE, add an extra 8 gpio pins and a 32k EEPROM to Nusbio.

For the extra gpio pins, I used the MCP23008 gpio expander. The MCP23008 is an I2C device.



To turn on the extra gpio pin, the method DigitalWrite() in the C# class MCP23008, makes 2 I2C calls (GetGPIOMask() and SetGPIOMask()) to turn on the gpio.


public override void DigitalWrite(byte gpioIndex, MadeInTheUSB.GPIO.PinState d)
{
    var mcpIndex = gpioIndex - this.GpioStartIndex;

    // only 8 bits!
    if (mcpIndex > 7) return;

    // read the current GPIO output latches
    int gpio = GetGPIOMask();

    // set the pin and direction
    if (d == GPIO.PinState.High)
    {
        gpio |= (byte)(1 << mcpIndex);
    }
    else
    {
        gpio &= (byte)(~(1 << mcpIndex));
    }
    // write the new GPIO
    SetGPIOMask((byte)gpio);
}

internal int GetGPIOMask()
{
    // read the current status of the GPIO pins
    return this._i2c.Ready1Byte8BitsCommand(MCP230XX_GPIO); 
}

internal bool SetGPIOMask(byte gpio)
{
    return this._i2c.Send2BytesCommand(MCP230XX_GPIO, gpio);
} 
 
How fast can I turn a extra gpio pin on and off in C#?
The oscilloscope says 7.4 milli second to turn it on, 7.4 Milli second to turn it off. 
We can estimate the cost of one I2C call to 3.7 Milli second.



Source Code

Thursday, June 18, 2015

Nusbio 8 Button Panel


All I wanted to do was to create an 8 keys keyboard PCB, but I wanted to light up one LED if at least one key was pressed. This will be the GDevice extension kit, 8 Buttons Panel.


Just Buttons


First, the basic schematic for 2 buttons, with no LED.


This is generally how I handle buttons, using what is called a Pull Down resitor.
  1. The current start flowing from VCC (pin 9) and arrive as the input of the buttons (Switch) S0 and S1. 
  2. When the button S0 is pressed the current flow through the button and goes to ground via the resistor rp0 and also goto to the gpio 0 (pin 1). When the button S2 is pressed the following method gDevice.GPIOS[GDeviceGpio.Gpio0].DigitalRead(), returns High. When the button  is not pressed the method returns Low.
  3. Button S1 works the same and could be the same for another 6 buttons, for a total of 8 buttons.
    Since the GDevice offers 8 gpios.

 With a LED.


Now I want to add an LED that will light up if at least one button is pressed.


 This was my first thought, and luckily I tested this on a bread board, because there is an issue
  • When the button S0 is pressed the current flow 
    • To ground via the resistor rp0
    • To Gpio0
    • To the led LEDKBD and to ground via resistor RLEDKBD. The resistor light up.
So far so good.

When the button S0 is pressed the method,
gDevice.GPIOS[GDeviceGpio.Gpio0].DigitalRead() returns High, but the method
gDevice.GPIOS[GDeviceGpio.Gpio1].DigitalRead() also return High.

What?

Yes, now that the current flow into the LED LEDKBD from the button S0, it also flow using the other branch that lead to Gpio1, providing 5 volt to Gpio1.  And therefore that means S1 is pressed.
Well no, it means there is an issue with the circuit.

Diode


Since I want to prevent the current to flow back from button 0 to Gpio 1 when button 0 is pressed, or
from button 1 to Gpio 0 when button 1 is pressed, I thought diode (A diode allows the current to go to only one direction).



The good thing, it is working. but now for my 8 Buttons Panel kit, I have 8 buttons, 8 resistors and 8 diodes. This raise the following issues:
  • Difficulty of the kit increase
  • Price of the kit increase, PCB real state and diode have a cost.
Is there a simpler way?

That is why I go to the Artisans Asylum hacker space, on wednesday. So I can ask for help.
So here is the answer.

If one or more button are pressed the current flow from VCC to GND and therefore the LED will light up. The previous solution with the diodes may be considered a better one, because in this last solution the LED being first create a voltage drop, and the voltage that goes into the Gpios is 1.8 volt rather than 5 volt, this could not be considered as a true High. But with the GDevice it is working.

About the resistors. For a Pull Down resistor 10 k is the more conventional. But in this case this will also affect the brightness of the LED. So 1 or 2 k is probably what I will chose.


Final Schematic


Few months ago I discovered resistor array. For example the 652-4610X-1LF-1K, is 9 x 1k resistors.
and the advantage is that it offer 9 input, 9 1k resistors but only one output, that in my case will go to ground.

This is not for all solution, but if all the output of the resistors go to the same wire, this save n-1 wire and soldering and space in the PCB. You can find resistor array in different grouping : 4, 8 , 9, 13.
You can also find resistor array with  n input and n output.

But here my final schematic for the Nusbio 8 Buttons Panel PCB.


The LED LEDPWR, is just here to show that the extension is correctly connected to the GDevice.
I also added a jumper, so I can easy, plug a multi meter and measure the current.