A new specific actuator device class has been added to Softata: The Grove Relay.

This relay was previously used with the Softata Console app but was coded purely as a digital on/off device. This abstracts it leading to its use in the Blockly code and with remote activation via Azure IoT Hub using a Cloud to Device message.

About

The Grove Relay plugs into the Grove RPi Pico Shield in one of the three sockets at the bottom (sockets 3 to 5, group 2 below). The third socket is the default which connects to Pico using pin 16.

The other 2 sockets use pins 18 and 20.

Blockly Setup

You can use the default setup which uses pin 16/the third socket:

Or you can use the general setup, say, using the fourth socket/pin 18:

Note in both cases, the returned actuatorListIndex value from the instantiation. This is then used in the Relay Actions.

SoftataLib Actuator.Relay Setup c# Code

In the updated Console app:

    byte relayPin = 16;
    byte actuatorIndex = 0;
    switch (potRelaySelection)
    {
        case 1:
            //Previous digital mode
            SoftataLib.Digital.SetPinMode(RELAY, SoftataLib.PinMode.DigitalOutput);
            break;
        case 2:
            actuatorIndex = SoftataLib.Actuator.SetupDefault(SoftataLib.Actuator.ActuatorDevice.Relay);
            break;
        case 3:
            relayPin = 18;
            actuatorIndex = SoftataLib.Actuator.Setup(SoftataLib.Actuator.ActuatorDevice.Relay, relayPin);
            break;
        case 4:
            relayPin = 20;
            actuatorIndex = SoftataLib.Actuator.Setup(SoftataLib.Actuator.ActuatorDevice.Relay, relayPin);
            break;
    }
  • Case 2 uses the default Actuator.Relay setup (pin 16).
  • Cases 3 and 4 explicitly set the pin 18/20 using the non-default Actuator.Relay setup.

Blockly Relay Actions

You can set, reset and toggle the state of the relay once instantiated:

Note: The bit parameter is dummy but required; zero here. It has no bearing on the functionality.

SoftataLib Actuator.Relay Actions C# Code

Note: The actuatorIndex returned from the relay class instantiation when added to the Actuators linked list.
And also not the “dummy” bit number of 0.

    SoftataLib.Actuator.SetBit(actuatorIndex,0);

Setting the relay

    SoftataLib.Actuator.ClearBit(actuatorIndex, 0);

Clearing/resetting the relay

    SoftataLib.Actuator.ToggleBit(actuatorIndex, 0);

Toggling the relay

Cloud to Device Relay Messages

As per previous post :Softata - Cloud 2 Device Messages 2

Can send C2D messages using amongst other tools: Azure IoT Explorer

The C2D message is a string. Properties etc are ignored.

  • The first character determines the command, and is case insensitive alpha.
  • The last character (if numeric) is interpreted as the device linked list index.
  • The second last character (if numeric), is a dummy parameter, but is required. Iis ignored.

  • Actuator01: Set the relay of index 1
  • Reset01: Reset the relay of index 1
  • Toggle01: Toggle the relay of index 1

eg: A00 Set the relay with index 0.

Conclusion

Whilst the discussion here has been about orchestrating a Grove Relay, the connected actuator could also be an LED, Buzzer, simple DC motor etc. Anything that gets turned on or off and manifests as a single bit.


 TopicSubtopic
  Next: > App Settings for a .NET Console App
   
 This Category Links 
Category:Softata Index:Softata
  Next: > Softata
<  Prev:   Softata