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

Newbie problems with 74HC595 chips


  • Please log in to reply
15 replies to this topic

#1 Fuginator

Fuginator

    New Member

  • Members
  • Pip
  • 7 posts

Posted 06 February 2011 - 09:27 AM

Ahhhhhh..... Can someone lend me a hand before I go nuts?

I am trying to setup two 74HC595 chips to control 16 LED's - and am using the wiring here:
http://arduino.cc/en/Tutorial/ShiftOut
(I hooked up the reset pin 10 to ground it out for clearing, as seen in code)

I am trying to run this using my code, posted below.

Here are two video's of my results, almost on.



(LED1 to the left, then up towards right)

Any kind words / advise on how to fix this up?

Thanks,

Andrew

public class Program
    {
        static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
        static OutputPort led0 = new OutputPort(Pins.GPIO_PIN_D0, false);
        static OutputPort SRreset = new OutputPort(Pins.GPIO_PIN_D1, false);

        static Cpu.Pin Data = Pins.GPIO_PIN_D11;
        static Cpu.Pin Clock = Pins.GPIO_PIN_D12;
        static Cpu.Pin Latch = Pins.GPIO_PIN_D8;

        public static void Main()
        {
            // Reset registars (pin 10 on 595)
            SRreset.Write(false);
            SRreset.Write(true);

            display(new bool[] { true, true, true, true, true, true, false, false, true, true, true, true, true, true, false, false });
            Thread.Sleep(1000);
            display(new bool[] { false, false, true, true, true, true, true, true, false, false, true, true, true, true, true, true });
            Thread.Sleep(1000);
            display(new bool[] { false, false, true, true, false, false, true, true, false, false, true, true, false, false, true, true });


            for (int i = 0; i < 16; i++) {
                bool[] tmp = new bool[] { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false };
                tmp[i] = true;
                display(tmp);
                Thread.Sleep(1000);
            }



            Thread.Sleep(1000); //keep debug window up for a sec.
        }

        private static void display(bool[] vars) {
            // ouput data from array of bool values
            // Outputs
            OutputPort LatchO = new OutputPort(Latch, false);
            OutputPort ClockO = new OutputPort(Clock, false);
            OutputPort DataO = new OutputPort(Data, false);

            for (int i = 0; i < vars.Length; i++)
            {
                // pulse / data
                Debug.Print("Working with: " + i + " set to: " + vars[i]);
                DataO.Write(vars[i]);
                ClockO.Write(true);
                ClockO.Write(false);
                DataO.Write(false);
                //Pz();
                /*if (i % 8 == 0) {
                    // Send the data pulsed to output?
                    Debug.Print("Latch");
                    LatchO.Write(true);
                    LatchO.Write(false);
                    //next chip from here?
                }*/
            }
            LatchO.Write(true);
            LatchO.Write(false);

            LatchO.Dispose();
            ClockO.Dispose();
            DataO.Dispose();
        }

        private static void Pz(){
            // pause w\ some hardware feedback that things are happening
            led.Write(true);
            Thread.Sleep(1);
            led.Write(false);
        }
    }


#2 Fuginator

Fuginator

    New Member

  • Members
  • Pip
  • 7 posts

Posted 06 February 2011 - 11:35 AM

The problem can be seen with just these lines, in the above code (can replace the for loop)...

It should light up the 'true' LED's, but skips 8 and goes to 9, that is on the other IC.

Something wrong with my display function? (also below)

            Thread.Sleep(1000);
            display(new bool[] { false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false });
            Thread.Sleep(1000);
            display(new bool[] { false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false });
            Thread.Sleep(1000);
            display(new bool[] { false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false });

Display function
        private static void display(bool[] vars) {
            // ouput data from array of bool values
            // Outputs
            OutputPort LatchO = new OutputPort(Latch, false);
            OutputPort ClockO = new OutputPort(Clock, false);
            OutputPort DataO = new OutputPort(Data, false);

            // Reset registars (pin 10 on 595)
            SRreset.Write(false);
            SRreset.Write(true);

            for (int i = 0; i < vars.Length; i++)
            {
                // pulse / data
                Debug.Print("Working with: " + i + " set to: " + vars[i]);
                DataO.Write(vars[i]);
                ClockO.Write(true);
                
                DataO.Write(false);
                ClockO.Write(false);
                Pz();
            }
            //latch data
            LatchO.Write(true);
            LatchO.Write(false);

            LatchO.Dispose();
            ClockO.Dispose();
            DataO.Dispose();
        }


#3 Fuginator

Fuginator

    New Member

  • Members
  • Pip
  • 7 posts

Posted 08 February 2011 - 03:04 AM

Okay, I have a good feeling that someone else has used two or more 74HC595 chips w\ their netduino - would they like to share code or wiring? Please? :mellow:

#4 AlfredBr

AlfredBr

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationConnecticut, USA

Posted 08 February 2011 - 04:14 PM

I've done this (i.e. several '595's) with both the ezExpander and 'from scratch' on a breadboard. Are you more interested in the code or the circuit? I can post the code tonight, but it may take a few days to transcribe the circuit to something that is postable... In the meantime, have you read this? http://forums.netdui...ch__1#entry6593

#5 Fuginator

Fuginator

    New Member

  • Members
  • Pip
  • 7 posts

Posted 09 February 2011 - 12:22 AM

I think code is my issue here - I used code from the post you linked, still a no-go, so I'm going to re-wire now. And by no-go, here were the results:

#6 Fuginator

Fuginator

    New Member

  • Members
  • Pip
  • 7 posts

Posted 09 February 2011 - 12:40 AM

and just the first 595 wireup - should be all off / on cycle.... I would like to see the code you used, may save my sanity. Thanks, Andrew Edit, Added video

#7 Fuginator

Fuginator

    New Member

  • Members
  • Pip
  • 7 posts

Posted 09 February 2011 - 12:51 AM

Wow - I'll check my wiring 4 times before posting, seeing that 3 times was one time too little for things to work. Now works w\ code from other thread, thanks! I would still be interested in your code however. Andrew.

#8 AlfredBr

AlfredBr

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationConnecticut, USA

Posted 09 February 2011 - 05:16 PM

Glad you got it working. I'll post my code tonight. Getting these to work in series is mostly in the circuit. The code does not change when using two '595's, I just pass a 16-bit value.

#9 Nk54.fr

Nk54.fr

    New Member

  • Members
  • Pip
  • 6 posts

Posted 16 April 2011 - 05:08 PM

Your code is so nice ! It works perfecty with 8 leds. I'm waiting for my 4 shift register OUT (shit ! i've bought some but for input not output lol (i'll make a keyboard so ... ^^) I'll take a picture of mine for you :) (i've made something very beautifull with the wires hahaha) Now i need to make it work with SPI. It didn't perfecty until now ... Have you already try ? Thank a lot by the way

#10 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 17 April 2011 - 05:56 AM

Now i need to make it work with SPI. It didn't perfecty until now ... Have you already try ?

Thank a lot by the way

Funny, never seen this thread, but I made a library (including schematics) with those IC's over SPI.
See http://forums.netdui...h-the-netduino/ for more details.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#11 Nk54.fr

Nk54.fr

    New Member

  • Members
  • Pip
  • 6 posts

Posted 02 May 2011 - 07:30 PM

*can't delete message :/*

#12 Nk54.fr

Nk54.fr

    New Member

  • Members
  • Pip
  • 6 posts

Posted 02 May 2011 - 07:45 PM

Haha :) i've already download your code. I've a question, should i use the same pin on my netduino in order to use spi ? I'm using pin 1, 2 ,3 static Cpu.Pin Data = Pins.GPIO_PIN_D2; static Cpu.Pin Clock = Pins.GPIO_PIN_D3; static Cpu.Pin Latch = Pins.GPIO_PIN_D1; your code is very good. But i've not understand everything. Outputportshift Multispi ic...595 ic...595chain I'm not getting everything. I'll try tomorow or in 2 days to make it work with it. That's not so much complex but i'm a noob with netduino stuff. Thanks

#13 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 02 May 2011 - 07:48 PM

Nope. Managed SPI on Netduino is only possible on pins 11 to 13. See also http://sandbox.netduino.com/SPI.ashx
It's the only managed SPI bus the Netduino has. You could connect the IC's like this schematic:

Posted Image
You could discard the left part if it's only for 595's
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#14 Nk54.fr

Nk54.fr

    New Member

  • Members
  • Pip
  • 6 posts

Posted 02 May 2011 - 09:47 PM

THank you so much for your fast answer ! I was using pin 1 2 3. That could be a reason why it doesn't work ... ^^ I'm going to have a deeper look to your code right now. I'll give you feedback. Good night Stefan and thank for helping ! Netduino got a little community. But a very nice one :)

#15 Nk54.fr

Nk54.fr

    New Member

  • Members
  • Pip
  • 6 posts

Posted 02 May 2011 - 10:05 PM

After a first reading, i find that your link is very helpfull ! To understand spi and your code too :)

#16 Nk54.fr

Nk54.fr

    New Member

  • Members
  • Pip
  • 6 posts

Posted 03 May 2011 - 11:46 AM

It's working well ! I'm looking to start from scratch to understand and know how it works. I get an idea. But still a bit complicated for me :)




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.