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

More blinking leds


  • Please log in to reply
15 replies to this topic

#1 Szymon

Szymon

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts
  • LocationPoland, Krakow

Posted 22 August 2010 - 09:41 AM

Hi, I have published article on my blog that shows how to use shift registers to extend number of digital output pins on Netduino. In particular I demonstrate how to use it to control a 7-segment display or any other LED components. In two examples I show how to display values from potentiometer and SHT15 temperatuer & humidity sensor. Here is the blog post: http://geekswithblog...nking_leds.aspx I also made a short video to show how this works: You can download the source code here: http://cid-4c7ec0c21...s^_20100822.zip Please let me know if you like it or not, and if you would like to see more projects like this from me.

#2 segu

segu

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationLima - Peru

Posted 22 August 2010 - 02:07 PM

Szymon Downloaded, saw the video and will try. That is a very useful info to me, thank you :) Regards PostData: Is another thread, but waiting your 1 wire info :) :)

#3 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 22 August 2010 - 02:09 PM

Please let me know if you like it or not, and if you would like to see more projects like this from me.


Oh, absolutely. That's a very well-done project, and a very well-written article. I'm going to need to go build one now :)

What potentiometer are you using?

Chris

#4 Szymon

Szymon

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts
  • LocationPoland, Krakow

Posted 22 August 2010 - 02:10 PM


What potentiometer are you using?


10K

#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 22 August 2010 - 02:11 PM

10K


Do you know the part/model # or where I could buy one? It's nice!

#6 Szymon

Szymon

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts
  • LocationPoland, Krakow

Posted 22 August 2010 - 02:30 PM

Do you know the part/model # or where I could buy one? It's nice!


It's just regular potentiomater that I got from a local hobby electronics store in my town.
Looks exactly like this one: http://www.oreind.co...products_id=859

I only put a platics knob on it :-)

#7 Snipehunter

Snipehunter

    New Member

  • Members
  • Pip
  • 6 posts

Posted 22 August 2010 - 04:56 PM

Man, I love this place. The answers to my questions come before I even get to the point where I'm writing up the question post! Great blog post there Szymon; it taught me a lot!

#8 RedHermit

RedHermit

    Member

  • Members
  • PipPip
  • 14 posts
  • LocationColorado

Posted 23 August 2010 - 07:07 PM

I was just learning about shift registers the other day, making them work with my Arduino to learn the basics, the whole time thinking about how to do the same on Netduino - this information is golden! Wonderful article/tutorial, thank you very much for taking the time to do this Szymon!

#9 Websteria

Websteria

    Member

  • Members
  • PipPip
  • 25 posts

Posted 25 August 2010 - 04:05 PM

Hi,
I have published article on my blog that shows how to use shift registers to extend number of digital output pins on Netduino. In particular I demonstrate how to use it to control a 7-segment display or any other LED components. In two examples I show how to display values from potentiometer and SHT15 temperatuer & humidity sensor.

Here is the blog post: http://geekswithblog...nking_leds.aspx

I also made a short video to show how this works:

You can download the source code here: http://cid-4c7ec0c21...s^_20100822.zip

Please let me know if you like it or not, and if you would like to see more projects like this from me.



Syzmon, your post inspired me to get a shift register, even though I've NEVER had success with IC's before in electronics.

I started out trying to just read the values off of Q0 and Q1 on the Netduino ports, but they always showed as on, even if they should have been sent as off, is this because the 5V sent to the IC is being output to the other ports?

I'm using Dig Pin5 for DS, Dig Pin6 as Data, Pin7 as latch and reading values from Q0 on Pin0 and Q1 on Pin1.

Thanks!


My code looks like this:
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace ShiftRegister
{
    public class Program
    {
        public static void Main()
        {
            // write your code here
            OutputPort DS = new OutputPort(Cpu.Pin.GPIO_Pin5, false);
            OutputPort StoreData = new OutputPort(Cpu.Pin.GPIO_Pin6, false);
            OutputPort Latch = new OutputPort(Cpu.Pin.GPIO_Pin7, true);

            InputPort Read1 = new InputPort(Cpu.Pin.GPIO_Pin0, false, Port.ResistorMode.Disabled);
            InputPort Read2 = new InputPort(Cpu.Pin.GPIO_Pin1, false, Port.ResistorMode.Disabled);

            //Write 1,0 then send it...

            // set the latch low...
            Latch.Write(false);

            //Write the 1..
            DS.Write(true);

            StoreData.Write(true);
            Thread.Sleep(100);
            StoreData.Write(false);

            //Write the 0..
            DS.Write(false);

            StoreData.Write(true);
            Thread.Sleep(100);
            StoreData.Write(false);

            // let er rip..
            Latch.Write(true);
            Thread.Sleep(100);
            Latch.Write(false);

            Debug.Print("Value @ pin Q0: " + Read1.Read().ToString());
            Debug.Print("Value @ pin Q1: " + Read2.Read().ToString());


        }

    }
}





#10 Szymon

Szymon

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts
  • LocationPoland, Krakow

Posted 26 August 2010 - 11:05 AM

I'm using Dig Pin5 for DS, Dig Pin6 as Data, Pin7 as latch and reading values from Q0 on Pin0 and Q1 on Pin1.


You should be using the SecretLabs.NETMF.Hardware.Netduino.Pins enumeration instead of Cpu.Pin. This will ensure correct mapping from hardware specific pin numbers to internal numbers. For example Netduino.Pins.GPIO_PIN_D5 true value is 51. So in your case you should change these lines:

            OutputPort DS = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D5, false); 
            OutputPort StoreData = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D6, false); 
            OutputPort Latch = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D7, true); 
 
            InputPort Read1 = new InputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D0, false, Port.ResistorMode.Disabled); 
            InputPort Read2 = new InputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D1, false, Port.ResistorMode.Disabled); 

I hope this helps.

#11 Szymon

Szymon

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts
  • LocationPoland, Krakow

Posted 26 August 2010 - 11:29 AM

Here is a simple Shifter test class extracted from my project:

using System;
using System.Threading;
using Microsoft.SPOT.Hardware;

namespace ShiftRegisterTest
{
    public class Program
    {
        private static Cpu.Pin latchPin     = SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D7;
        private static Cpu.Pin clockPin     = SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D6;
        private static Cpu.Pin dataPin      = SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D5;

        public static void Main()
        {
            var shifter = new Shifter(latchPin, clockPin, dataPin);

            byte value = 0;
            while (true)
            {
/*
                // blink all LEDs
                shifter.Write(255);
                Thread.Sleep(200);
                shifter.Write(0);
                Thread.Sleep(200);
*/
                // blink single LED
                shifter.Write(value);
                value = (byte)(value << 1);
                if (value == 0) value = 1;
                Thread.Sleep(200);
            }
        }
    }

    public class Shifter : IDisposable
    {
        private readonly OutputPort _latchPort;
        private readonly OutputPort _clockPort;
        private readonly OutputPort _dataPort;

        public Shifter(Cpu.Pin latchPin, Cpu.Pin clockPin, Cpu.Pin dataPin)
        {
            _latchPort = new OutputPort(latchPin, false);
            _clockPort = new OutputPort(clockPin, false);
            _dataPort = new OutputPort(dataPin, false);
        }

        public void Dispose()
        {
            _latchPort.Dispose();
            _clockPort.Dispose();
            _dataPort.Dispose();
        }

        public void Write(params byte[] buffer)
        {
            // Ground latchPin and hold low for as long as you are transmitting
            _latchPort.Write(false);

            for (int i = 0; i < buffer.Length; i++)
            {
                ShiftOut(buffer[i]);
            }

            // Return the latch pin high to signal chip that it 
            // no longer needs to listen for information
            _latchPort.Write(true);
            _latchPort.Write(false);
        }

        private void ShiftOut(byte value)
        {
            _clockPort.Write(false);

            for (int i = 0; i < 8; i++)
            {
                byte mask = (byte)(1 << i);
                _dataPort.Write((value & mask) != 0);

                // Raise Clock
                _clockPort.Write(true);

                // Raise Data to prevent IO conflict 
                _dataPort.Write(true);

                // Lower Clock
                _clockPort.Write(false);
            }
        }
    }
}



#12 Websteria

Websteria

    Member

  • Members
  • PipPip
  • 25 posts

Posted 26 August 2010 - 03:10 PM

You should be using the SecretLabs.NETMF.Hardware.Netduino.Pins enumeration instead of Cpu.Pin. This will ensure correct mapping from hardware specific pin numbers to internal numbers. For example Netduino.Pins.GPIO_PIN_D5 true value is 51. So in your case you should change these lines:

            OutputPort DS = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D5, false); 
            OutputPort StoreData = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D6, false); 
            OutputPort Latch = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D7, true); 
 
            InputPort Read1 = new InputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D0, false, Port.ResistorMode.Disabled); 
            InputPort Read2 = new InputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D1, false, Port.ResistorMode.Disabled); 

I hope this helps.



Ok, think this should be stickied, the problem is that VS2010 will AUTOMATICALLY put the microsoft default PINS in there, which do not map up to the Netduino pins. That was my problem. Thank you so much!!!!

#13 Szymon

Szymon

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts
  • LocationPoland, Krakow

Posted 27 August 2010 - 11:23 AM

Ok, think this should be stickied, the problem is that VS2010 will AUTOMATICALLY put the microsoft default PINS in there, which do not map up to the Netduino pins. That was my problem. Thank you so much!!!!


I think you are right. The classes from SecretLabs.NETMF.Hardware.Netduino namespace should be actually declared as internal classes on Netduino class. Then it would be clear that you have to write for example Netduino.Pins.GPIO_PIN_D3. Currently this code is invalid. If I remmember ut is done this way in GHI and DeviceSolutions SDKs.

#14 GB30

GB30

    Member

  • Members
  • PipPip
  • 10 posts

Posted 13 September 2010 - 07:39 AM

I think you are right. The classes from SecretLabs.NETMF.Hardware.Netduino namespace should be actually declared as internal classes on Netduino class. Then it would be clear that you have to write for example Netduino.Pins.GPIO_PIN_D3. Currently this code is invalid. If I remmember ut is done this way in GHI and DeviceSolutions SDKs.



Hi. I'm tryng to use Netduino. First Examples run correctly on board, but I controll pin numbers in Netduino dll:

public static class Pins
{
public const Cpu.Pin GPIO_NONE = -1;
public const Cpu.Pin GPIO_PIN_A0 = 59;
public const Cpu.Pin GPIO_PIN_A1 = 60;
public const Cpu.Pin GPIO_PIN_A2 = 61;
public const Cpu.Pin GPIO_PIN_A3 = 62;
public const Cpu.Pin GPIO_PIN_A4 = 10;
public const Cpu.Pin GPIO_PIN_A5 = 11;
public const Cpu.Pin GPIO_PIN_D0 = 27;
public const Cpu.Pin GPIO_PIN_D1 = 28;
public const Cpu.Pin GPIO_PIN_D10 = 54;
public const Cpu.Pin GPIO_PIN_D11 = 17;
public const Cpu.Pin GPIO_PIN_D12 = 16;
public const Cpu.Pin GPIO_PIN_D13 = 18;
public const Cpu.Pin GPIO_PIN_D2 = 0;
public const Cpu.Pin GPIO_PIN_D3 = 1;
public const Cpu.Pin GPIO_PIN_D4 = 12;
public const Cpu.Pin GPIO_PIN_D5 = 51;
public const Cpu.Pin GPIO_PIN_D6 = 52;
public const Cpu.Pin GPIO_PIN_D7 = 3;
public const Cpu.Pin GPIO_PIN_D8 = 4;
public const Cpu.Pin GPIO_PIN_D9 = 53;
public const Cpu.Pin ONBOARD_LED = 55;
public const Cpu.Pin ONBOARD_SW1 = 29;
}
}


They don't match with numbers on schematic : why?
For example onboard_SW1 = 29, but pin on schematic is 75!!!

Thnak you!

#15 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 13 September 2010 - 07:44 AM

They don't match with numbers on schematic : why?
For example onboard_SW1 = 29, but pin on schematic is 75!!!


Hi GB30,

The numbers next to the pins on the schematic are the actual physical lead #s on the microcontroller -- not the "GPIO pin #s" used by the Atmel MCU. The #'s on the schematic are for locating the physical connections.

To calculate the pin # for use in your code, PA0-30 are 0-30 and PB0-30 are 32-62.

But it's best to just use the Pins.GPIO* enumeration provided by the Netduino's HardwareProvider. If you include the SecretLabs.NETMF.Hardware.Netduino.dll file into your solution and the respective using namespace statements up top, typing "Pins." should bring up the proper enumeration.

Does that help explain things?

Chris

#16 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 13 September 2010 - 07:46 AM

For example onboard_SW1 = 29, but pin on schematic is 75!!!

There is a difference between numbering the pins (peripheral I/O lines) and package leads: the onboard switch (SW1) is pin #29 (PA29), accessible via package lead #75. Hope this helps.




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.