Remarks
x74595 | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
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
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
Capabilities
Declaration
public DeviceCapabilities Capabilities { get; }
Property Value
Type | Description |
---|---|
DeviceCapabilities |
Pins
Declaration
public x74595.PinDefinitions Pins { get; }
Property Value
Type | Description |
---|---|
x74595.PinDefinitions |
Methods
Clear(Boolean)
Declaration
public void Clear(bool update = true)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | update |
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 |
CreateBiDirectionalPort(IPin, Boolean, InterruptMode, ResistorMode, PortDirectionType, Double, Double, OutputType)
Declaration
public IBiDirectionalPort CreateBiDirectionalPort(IPin pin, bool initialState = false, InterruptMode interruptMode = null, ResistorMode resistorMode = null, PortDirectionType initialDirection = null, double debounceDuration = 0, double glitchDuration = 0, OutputType outputType = null)
Parameters
Type | Name | Description |
---|---|---|
IPin | pin | |
System.Boolean | initialState | |
InterruptMode | interruptMode | |
ResistorMode | resistorMode | |
PortDirectionType | initialDirection | |
System.Double | debounceDuration | |
System.Double | glitchDuration | |
OutputType | outputType |
Returns
Type | Description |
---|---|
IBiDirectionalPort |
CreateDigitalInputPort(IPin, InterruptMode, ResistorMode, Double, Double)
Declaration
public IDigitalInputPort CreateDigitalInputPort(IPin pin, InterruptMode interruptMode = null, ResistorMode resistorMode = null, double debounceDuration = 0, double glitchFilterCycleCount = 0)
Parameters
Type | Name | Description |
---|---|---|
IPin | pin | |
InterruptMode | interruptMode | |
ResistorMode | resistorMode | |
System.Double | debounceDuration | |
System.Double | glitchFilterCycleCount |
Returns
Type | Description |
---|---|
IDigitalInputPort |
CreateDigitalOutputPort(IPin, Boolean, OutputType)
Creates a new DigitalOutputPort using the specified pin and initial state.
Declaration
public IDigitalOutputPort CreateDigitalOutputPort(IPin pin, bool initialState, OutputType outputType)
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. |
OutputType | outputType |
Returns
Type | Description |
---|---|
IDigitalOutputPort |
CreateI2cBus(IPin, IPin, Int32)
Declaration
public II2cBus CreateI2cBus(IPin clock, IPin data, int frequencyHz = 100000)
Parameters
Type | Name | Description |
---|---|---|
IPin | clock | |
IPin | data | |
System.Int32 | frequencyHz |
Returns
Type | Description |
---|---|
II2cBus |
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 |
CreateI2cBus(IPin[], Int32)
Declaration
public II2cBus CreateI2cBus(IPin[] pins, int frequencyHz = 100000)
Parameters
Type | Name | Description |
---|---|---|
IPin[] | pins | |
System.Int32 | frequencyHz |
Returns
Type | Description |
---|---|
II2cBus |
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 |
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 |
CreateSerialMessagePort(SerialPortName, Byte[], Boolean, Int32, Int32, Parity, StopBits, Int32)
Declaration
public ISerialMessagePort CreateSerialMessagePort(SerialPortName portName, byte[] suffixDelimiter, bool preserveDelimiter, int baudRate = 9600, int dataBits = 8, Parity parity = null, StopBits stopBits = null, int readBufferSize = 512)
Parameters
Type | Name | Description |
---|---|---|
SerialPortName | portName | |
System.Byte[] | suffixDelimiter | |
System.Boolean | preserveDelimiter | |
System.Int32 | baudRate | |
System.Int32 | dataBits | |
Parity | parity | |
StopBits | stopBits | |
System.Int32 | readBufferSize |
Returns
Type | Description |
---|---|
ISerialMessagePort |
CreateSerialMessagePort(SerialPortName, Byte[], Boolean, Int32, Int32, Int32, Parity, StopBits, Int32)
Declaration
public ISerialMessagePort CreateSerialMessagePort(SerialPortName portName, byte[] prefixDelimiter, bool preserveDelimiter, int messageLength, int baudRate = 9600, int dataBits = 8, Parity parity = null, StopBits stopBits = null, int readBufferSize = 512)
Parameters
Type | Name | Description |
---|---|---|
SerialPortName | portName | |
System.Byte[] | prefixDelimiter | |
System.Boolean | preserveDelimiter | |
System.Int32 | messageLength | |
System.Int32 | baudRate | |
System.Int32 | dataBits | |
Parity | parity | |
StopBits | stopBits | |
System.Int32 | readBufferSize |
Returns
Type | Description |
---|---|
ISerialMessagePort |
CreateSerialPort(SerialPortName, Int32, Int32, Parity, StopBits, Int32)
Declaration
public ISerialPort CreateSerialPort(SerialPortName portName, int baudRate = 9600, 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 |
CreateSpiBus(IPin, IPin, IPin, SpiClockConfiguration)
Declaration
public ISpiBus CreateSpiBus(IPin clock, IPin mosi, IPin miso, SpiClockConfiguration config)
Parameters
Type | Name | Description |
---|---|---|
IPin | clock | |
IPin | mosi | |
IPin | miso | |
SpiClockConfiguration | config |
Returns
Type | Description |
---|---|
ISpiBus |
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 |
CreateSpiBus(IPin[], Int64)
Declaration
public ISpiBus CreateSpiBus(IPin[] pins, long speed)
Parameters
Type | Name | Description |
---|---|---|
IPin[] | pins | |
System.Int64 | speed |
Returns
Type | Description |
---|---|
ISpiBus |
GetPin(String)
Declaration
public IPin GetPin(string pinName)
Parameters
Type | Name | Description |
---|---|---|
System.String | pinName |
Returns
Type | Description |
---|---|
IPin |
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 |
SetClock(DateTime)
Declaration
public void SetClock(DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime |
SetSynchronizationContext(SynchronizationContext)
Declaration
public void SetSynchronizationContext(SynchronizationContext context)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.SynchronizationContext | context |
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. |