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

Shift-Register Problem - Turn led's on


  • Please log in to reply
4 replies to this topic

#1 gfcwfzkm

gfcwfzkm

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts
  • LocationBrig-Glis, Switzerland

Posted 30 October 2012 - 09:36 AM

Hi,

i try to split two numbers (93 to 9 and 3) and convert it to binary.
That works fine (Thx to NooM). On a 3 i become FalseFalseTrueTrue (When i test the code on a Console)
But it dont do the same with the led's, who are connected two 74HC595 Shift Register's.

To use the shift register's, i use the Toolbox.Netmf.Hardware.dll

Here a piece of my Code :S
[expander]
Dim state As String = "13:93"
        ' write your code here
        ' We got 4 74HC595's in a chain
        Dim IcChain As Ic74hc595 = New Ic74hc595(SPI_Devices.SPI1, Pins.GPIO_PIN_D9, 1)
        Dim IcChain2 As Ic74hc595 = New Ic74hc595(SPI_Devices.SPI1, Pins.GPIO_PIN_D8, 1)
        For Counter = 0 To IcChain.Pins.Length - 1
            Thread.Sleep(50)
            IcChain.Pins(Counter).Write(False)
        Next
        ' Led loop back and forward
        Dim o As String() = state.Split(":")
        Dim s As String = o(0)
        Dim t As String = o(1)
        Dim z1 As String = s(0)
        Dim z2 As String = s(1)
        Dim z3 As String = t(0)
        Dim z4 As String = t(1)
        Dim y As Integer
        Dim z1b As [Byte] = z1
        z1b = z1b Or 0 << 0
        z1b = z1b Or 0 << 1
        z1b = z1b Or 0 << 2
        z1b = z1b Or 0 << 3
        Dim z2b As [Byte] = z2
        z2b = z2b Or 0 << 0
        z2b = z2b Or 0 << 1
        z2b = z2b Or 0 << 2
        z2b = z2b Or 0 << 3
        'IcChain: 00010000  Problem: 10000000
        'IcChain2:00011000  Problem: 00010000
        IcChain.Pins(3).Write(True)
        IcChain2.Pins(1).Write((z1b And (1 << 3)) > 0)
        IcChain2.Pins(2).Write((z1b And (1 << 2)) > 0)
        IcChain2.Pins(3).Write((z1b And (1 << 1)) > 0)
        IcChain2.Pins(4).Write((z1b And (1 << 0)) > 0)
        Thread.Sleep(5000)
        'IcChain: 00000000  Problem: 10000000 - It dont turn off -.-
        'IcChain2:00000000  
        IcChain.Pins(3).Write(False)
        IcChain2.Pins(1).Write(False)
        IcChain2.Pins(2).Write(False)
        IcChain2.Pins(3).Write(False)
        IcChain2.Pins(4).Write(False)
        Thread.Sleep(5000)
        'IcChain: 00010000  Problem: 11000000
        'IcChain2:01001000  Problem: 00011000
        IcChain.Pins(3).Write(True)
        IcChain2.Pins(1).Write((z2b And (1 << 3)) > 0)
        IcChain2.Pins(2).Write((z2b And (1 << 2)) > 0)
        IcChain2.Pins(3).Write((z2b And (1 << 1)) > 0)
        IcChain2.Pins(4).Write((z2b And (1 << 0)) > 0)
        Thread.Sleep(5000)
        'IcChain: 00000000  Problem: 10000000 It dont turn off again :(
        'IcChain2:00000000
        IcChain.Pins(3).Write(False)
        IcChain2.Pins(1).Write(False)
        IcChain2.Pins(2).Write(False)
        IcChain2.Pins(3).Write(False)
        IcChain2.Pins(4).Write(False)
        Thread.Sleep(60000)
[/expander]
I cant see the fail in the code, when i try the demo code from the netmf.toolbox site, it works fine :S

mfg

gfc

Attached Files



#2 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 30 October 2012 - 04:05 PM

Hi,

I have not looked at your code as I don't do VB.

Two things about your circuit:

1/ You should be using a resistor on each LED to limit the current. Assuming 2V@20mA for each LED, you want to be using about 150 ohms.
R = V / I = (5V - 2V) / 0.02A = 150 ohms

2/ The LEDs are all the wrong way round. At least they did not get burnt out.

Hope this helps - Paul

#3 supra

supra

    Advanced Member

  • Members
  • PipPipPip
  • 210 posts
  • LocationOntario, Canada

Posted 31 October 2012 - 02:52 AM

I'm using NGo. There is no need to add resistors. The TTls can handle up to 20mA. There is something wrong with code.. I can only do short code in order to reduce file size.

#4 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 31 October 2012 - 07:09 AM

Yes, one nice thing about 74 series TTL was that you could drive LEDs directly from it because the output high voltage was close to the forward voltage of the LEDs. The circuit in the thumb nail shows 74HC which is CMOS not TTL. I thought that would give an output level near to 5V - hence a resistor would be sensible. Perhaps I am missing something about gfc's circuit. Paul

#5 gfcwfzkm

gfcwfzkm

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts
  • LocationBrig-Glis, Switzerland

Posted 31 October 2012 - 07:54 AM

The Picture with the led's is not 100% true, sry.
I use a Experimental board, and it has led's for 5V included. (has 24led's :D)

i think, there must be a error in the code, because when i try easy stuff like this...
IcChain.Pins(0).Write(True)
IcChain2.Pins(7).Write(True)
Thread.Sleep(1000)
'...

...then it works :S

mfg

EDIT:// I attached the Console-Code, where i tested a part of the code
I saw on the toolbox site, that there is a "CreateParallelOut" too. I want to test it, but how i use it? here

Attached Files






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.