Remarks

x74595
Status
Source code GitHub
NuGet package Not Published

Shift registers offer the ability to increase the number of outputs on a microcontroller by using I2C or SPI interfaces. In the case of the 74xx595 series of shift registers, the SPI interface is used to output a series of bits that are then latched to the output pins of the chip.

This class allows Meadow to control the output pins on a 74HCT595 shift register using the SPI interface.

Note that when using this chip, care should be taken to ensure that the total output load of the chip does not exceed the current and thermal dissipation properties for the specific shift register being used.

Code Example

public class MeadowApp : App<F7Micro, MeadowApp>
{
    x74595 shiftRegister;

    public MeadowApp()
    {
        shiftRegister =new x74595(Device, Device.CreateSpiBus(), Device.Pins.D03, 8);

        shiftRegister.Clear(true);

        Console.WriteLine("Set Pin 3 to high");
        shiftRegister.WriteToPin(shiftRegister.Pins.GP3, true);

        TestX74595();
    }

    void TestX74595()
    {
        while (true)
        {
            shiftRegister.Clear();
            foreach (var pin in shiftRegister.Pins.AllPins)
            {
                shiftRegister.WriteToPin(pin, true);
                Thread.Sleep(50);
            }
        }
    }
}

Sample projects available on GitHub

Wiring Example

To wire a 74HCT595 to your Meadow board, connect the following:

Characteristic Locus
Inheritance System.Object > x74595
Namespace Meadow.Foundation.ICs.IOExpanders
Assembly x74595.dll

Syntax

public class x74595 : IIODevice

Constructors

View Source

x74595(IIODevice, ISpiBus, IPin, Int32)

Constructor a ShiftRegister 74595 object.

Declaration
public x74595(IIODevice device, ISpiBus spiBus, IPin pinChipSelect, int pins = 8)

Parameters

Type Name Description
IIODevice device
ISpiBus spiBus

SpiBus object

IPin pinChipSelect
System.Int32 pins

Number of pins in the shift register (should be a multiple of 8 pins).

Properties

View Source

Capabilities

Declaration
public DeviceCapabilities Capabilities { get; }

Property Value

Type Description
DeviceCapabilities
View Source

Pins

Declaration
public x74595.PinDefinitions Pins { get; }

Property Value

Type Description
x74595.PinDefinitions

Methods

View Source

Clear(Boolean)

Declaration
public void Clear(bool update = true)

Parameters

Type Name Description
System.Boolean update
View Source

CreateAnalogInputPort(IPin, Single)

Declaration
public IAnalogInputPort CreateAnalogInputPort(IPin pin, float voltageReference = 3.3F)

Parameters

Type Name Description
IPin pin
System.Single voltageReference

Returns

Type Description
IAnalogInputPort
View Source

CreateBiDirectionalPort(IPin, Boolean, Boolean, InterruptMode, ResistorMode, PortDirectionType)

Declaration
public IBiDirectionalPort CreateBiDirectionalPort(IPin pin, bool initialState = false, bool glitchFilter = false, InterruptMode interruptMode = null, ResistorMode resistorMode = null, PortDirectionType initialDirection = null)

Parameters

Type Name Description
IPin pin
System.Boolean initialState
System.Boolean glitchFilter
InterruptMode interruptMode
ResistorMode resistorMode
PortDirectionType initialDirection

Returns

Type Description
IBiDirectionalPort
View Source

CreateDigitalInputPort(IPin, InterruptMode, ResistorMode, Int32, Int32)

Declaration
public IDigitalInputPort CreateDigitalInputPort(IPin pin, InterruptMode interruptMode = null, ResistorMode resistorMode = null, int debounceDuration = 0, int glitchFilterCycleCount = 0)

Parameters

Type Name Description
IPin pin
InterruptMode interruptMode
ResistorMode resistorMode
System.Int32 debounceDuration
System.Int32 glitchFilterCycleCount

Returns

Type Description
IDigitalInputPort
View Source

CreateDigitalOutputPort(IPin, Boolean)

Creates a new DigitalOutputPort using the specified pin and initial state.

Declaration
public IDigitalOutputPort CreateDigitalOutputPort(IPin pin, bool initialState)

Parameters

Type Name Description
IPin pin

The pin number to create the port on.

System.Boolean initialState

Whether the pin is initially high or low.

Returns

Type Description
IDigitalOutputPort
View Source

CreateI2cBus(IPin, IPin, UInt16)

Declaration
public II2cBus CreateI2cBus(IPin clock, IPin data, ushort speed = 100)

Parameters

Type Name Description
IPin clock
IPin data
System.UInt16 speed

Returns

Type Description
II2cBus
View Source

CreateI2cBus(IPin[], UInt16)

Declaration
public II2cBus CreateI2cBus(IPin[] pins, ushort speed = 100)

Parameters

Type Name Description
IPin[] pins
System.UInt16 speed

Returns

Type Description
II2cBus
View Source

CreatePwmPort(IPin, Single, Single, Boolean)

Declaration
public IPwmPort CreatePwmPort(IPin pin, float frequency = 100F, float dutyCycle = 0.5F, bool invert = false)

Parameters

Type Name Description
IPin pin
System.Single frequency
System.Single dutyCycle
System.Boolean invert

Returns

Type Description
IPwmPort
View Source

CreateSerialPort(SerialPortName, Int32, Int32, Parity, StopBits, Int32)

Declaration
public ISerialPort CreateSerialPort(SerialPortName portName, int baudRate, int dataBits = 8, Parity parity = null, StopBits stopBits = null, int readBufferSize = 4096)

Parameters

Type Name Description
SerialPortName portName
System.Int32 baudRate
System.Int32 dataBits
Parity parity
StopBits stopBits
System.Int32 readBufferSize

Returns

Type Description
ISerialPort
View Source

CreateSpiBus(IPin, IPin, IPin, Int64)

Declaration
public ISpiBus CreateSpiBus(IPin clock, IPin mosi, IPin miso, long speed)

Parameters

Type Name Description
IPin clock
IPin mosi
IPin miso
System.Int64 speed

Returns

Type Description
ISpiBus
View Source

CreateSpiBus(IPin[], Int64)

Declaration
public ISpiBus CreateSpiBus(IPin[] pins, long speed)

Parameters

Type Name Description
IPin[] pins
System.Int64 speed

Returns

Type Description
ISpiBus
View Source

IsValidPin(IPin)

Checks whether or not the pin passed in exists on the chip.

Declaration
protected bool IsValidPin(IPin pin)

Parameters

Type Name Description
IPin pin

Returns

Type Description
System.Boolean
View Source

WriteToPin(IPin, Boolean)

Sets a particular pin's value.

Declaration
public void WriteToPin(IPin pin, bool value)

Parameters

Type Name Description
IPin pin

The pin to write to.

System.Boolean value

The value to write. True for high, false for low.