How to write Shield Base Digital I/O - Netduino Go - Netduino Forums
   
Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

How to write Shield Base Digital I/O


  • Please log in to reply
14 replies to this topic

#1 supra

supra

    Advanced Member

  • Members
  • PipPipPip
  • 210 posts
  • LocationOntario, Canada

Posted 02 October 2012 - 03:05 PM

Since I got Shield base 1 mnth ago, but haven't play around yet. On breadboard, I have common cathode connected to Power GND and 330 ohms with anode's led connected to digital i/o pin 4 of shield base.
My question, how do i write code to shield base digital i/o pin 4?

Output leds = new output(pins_gpio_pin_5,false)
<== I'm not sure if this write to shield base

Shield Base connected to sck5 of NGo..

Thank.

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 02 October 2012 - 03:14 PM

Hi supra,

To blink an LED attached to pin D4 on the Shield Base:
// NOTE: be sure to add Microsoft.SPOT.Hardware.dll and NetduinoGo.ShieldBase.dll as references to your project.

// use the Shield Base on socket 5 (nothing else plugged into sockets 6-8 for the moment)
NetduinoGo.ShieldBase shieldBase = new NetduinoGo.ShieldBase(GoSockets.Socket5);

Microsoft.SPOT.Hardware.OutputPort ledPort = new Microsoft.SPOT.Hardware.OutputPort(shieldBase.Pins.GPIO_PIN_D4, false);

while (true)
{
    ledPort.Write(!ledPort.Read());
    System.Threading.Thread.Sleep(250);
}
Chris

#3 supra

supra

    Advanced Member

  • Members
  • PipPipPip
  • 210 posts
  • LocationOntario, Canada

Posted 02 October 2012 - 03:18 PM

Hi supra,

To blink an LED attached to pin D4 on the Shield Base:

// NOTE: be sure to add Microsoft.SPOT.Hardware.dll and NetduinoGo.ShieldBase.dll as references to your project.

// use the Shield Base on socket 5 (nothing else plugged into sockets 6-8 for the moment)
NetduinoGo.ShieldBase shieldBase = new NetduinoGo.ShieldBase(GoSockets.Socket5);

Microsoft.SPOT.Hardware.OutputPort ledPort = new Microsoft.SPOT.Hardware.OutputPort(shieldBase.Pins.GPIO_PIN_D4, false);

while (true)
{
    ledPort.Write(!ledPort.Read());
    System.Threading.Thread.Sleep(250);
}
Chris


Thank. I try today after gym.

#4 supra

supra

    Advanced Member

  • Members
  • PipPipPip
  • 210 posts
  • LocationOntario, Canada

Posted 03 October 2012 - 02:55 PM

How do i turn led1 on and led2 off and turn led1 off and turn led2 on?

NetduinoGo.ShieldBase sb = new NetduinoGo.ShieldBase(GoSockets.Socket5);
            Microsoft.SPOT.Hardware.OutputPort ledPort = new Microsoft.SPOT.Hardware.OutputPort(sb.Pins.GPIO_PIN_D6, false);
            Microsoft.SPOT.Hardware.OutputPort ledprt5 = new Microsoft.SPOT.Hardware.OutputPort(sb.Pins.GPIO_PIN_D5, false);
            while (true)
            {
           // ledPort.Write(!ledPort.Read());
            //ledprt5.Write(!ledprt5.Read());
                ledPort.Write(ledPort.Read());
                Thread.Sleep(1000);
                ledprt5.Write(!ledPort.Read());
                Thread.Sleep(1000);
                ledPort.Write(!ledPort.Read());
                Thread.Sleep(1000);
                ledprt5.Write(!ledPort.Read());
                Thread.Sleep(1000);
            }


#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 03 October 2012 - 02:58 PM

Hi supra,

I think that what you're trying to do is invert the state of ledprt5. To do that, you'll need to read the value of ledprt5.

Instead of this...
ledprt5.Write(!ledPort.Read());
Do this...
ledprt5.Write(!ledprt5.Read());
Chris

#6 neslekkim

neslekkim

    Advanced Member

  • Members
  • PipPipPip
  • 350 posts
  • LocationOslo, Norway

Posted 03 October 2012 - 03:24 PM

Seems that he only want to toggle those two leds, so:

bool x = false;
while (true) {
  ledPort.Write(!x);
  ledprt5.Write(x);
  x=!x;
  Thread.Sleep(1000);
}

I guess there is no need to do an read, since it is an output port?

--
Asbjørn


#7 supra

supra

    Advanced Member

  • Members
  • PipPipPip
  • 210 posts
  • LocationOntario, Canada

Posted 03 October 2012 - 03:48 PM

Hi supra,

I think that what you're trying to do is invert the state of ledprt5. To do that, you'll need to read the value of ledprt5.

Instead of this...

ledprt5.Write(!ledPort.Read());
Do this...
ledprt5.Write(!ledprt5.Read());
Chris



Sorry. It was my mistaken. I just copy and paste it. But i didn't realize in parameter.

Finally, I got knight rider working. I been struggled for 1 hrs.

Here is code:
public static void Main()
        {
            // write your code here
            NetduinoGo.ShieldBase sb = new NetduinoGo.ShieldBase(GoSockets.Socket5);
            Microsoft.SPOT.Hardware.OutputPort ledPort = new Microsoft.SPOT.Hardware.OutputPort(sb.Pins.GPIO_PIN_D6, true);
            Microsoft.SPOT.Hardware.OutputPort ledprt5 = new Microsoft.SPOT.Hardware.OutputPort(sb.Pins.GPIO_PIN_D5, true);
            while (true)
            {
                ledprt5.Write(!ledprt5.Read());
                Thread.Sleep(1000);
                ledPort.Write(!ledPort.Read());
            }


#8 supra

supra

    Advanced Member

  • Members
  • PipPipPip
  • 210 posts
  • LocationOntario, Canada

Posted 03 October 2012 - 03:56 PM

@Gutwork:

Thank you very much. I appreciated ur helping.

Here is code:
Sub Main()
        ' write your code here
        Dim sb As NetduinoGo.ShieldBase = New NetduinoGo.ShieldBase(GoSockets.Socket5)
        Dim ledport As Microsoft.SPOT.Hardware.OutputPort = New Microsoft.SPOT.Hardware.OutputPort(sb.Pins.GPIO_PIN_D4, False)
        While True
            ledport.Write(True)
            Thread.Sleep(1000)
            ledport.Write(False)
            Thread.Sleep(5000)
        End While

    End Sub


Btw, I'm going to try knight rider. Also will be moving on to 8x8 dotmatrix(bicolor).

Thank for helping supra.

#9 supra

supra

    Advanced Member

  • Members
  • PipPipPip
  • 210 posts
  • LocationOntario, Canada

Posted 03 October 2012 - 04:10 PM

Seems that he only want to toggle those two leds, so:

bool x = false;
while (true) {
  ledPort.Write(!x);
  ledprt5.Write(x);
  x=!x;
  Thread.Sleep(1000);
}

I guess there is no need to do an read, since it is an output port?


U got 6 lines and i got 3 lines. So mine is betterPosted Image

while (true)
            {
                ledprt5.Write(!ledprt5.Read());
                Thread.Sleep(1000);
                ledPort.Write(!ledPort.Read());
            }



I will try ur code today.

#10 neslekkim

neslekkim

    Advanced Member

  • Members
  • PipPipPip
  • 350 posts
  • LocationOslo, Norway

Posted 03 October 2012 - 04:15 PM

short or not short, It depends on what read is doing, if it reads an internal variable it should be ok, if it goes out and smells the pin, one can wonder, since it still is an output port that you defined.. :)

--
Asbjørn


#11 supra

supra

    Advanced Member

  • Members
  • PipPipPip
  • 210 posts
  • LocationOntario, Canada

Posted 03 October 2012 - 04:15 PM

@Chris

What voltage we getting frm Shield Base? It is 3.3V or 5V?Posted Image

#12 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 03 October 2012 - 04:48 PM

What voltage we getting frm Shield Base? It is 3.3V or 5V?

The Shield Base outputs 3.3V digital outputs.

Chris

#13 neslekkim

neslekkim

    Advanced Member

  • Members
  • PipPipPip
  • 350 posts
  • LocationOslo, Norway

Posted 03 October 2012 - 05:35 PM

regarding questions like that, you have this spec page for the Go, but none for the shieldbase ? http://www.netduino....inogo/specs.htm

--
Asbjørn


#14 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 03 October 2012 - 05:59 PM

Hi neslekkim,

regarding questions like that, you have this spec page for the Go, but none for the shieldbase ?
http://www.netduino....inogo/specs.htm

That's a good idea.

Today we have an accessories page, and details on the Wiki pages. We should create specs pages for each module.

Chris

#15 supra

supra

    Advanced Member

  • Members
  • PipPipPip
  • 210 posts
  • LocationOntario, Canada

Posted 05 October 2012 - 09:05 AM

Hi neslekkim,


That's a good idea.

Today we have an accessories page, and details on the Wiki pages. We should create specs pages for each module.

Chris


Thank for NGO catalog. But still awaitng for gadgeteer adapterPosted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.