Focusing upon sensors, an outline of how to add an additional device to the Softata mix.

The Softata Repository

GitHub:djaus2/Soft-ata

Context

  • Have Softata deployed and working on a RPi Pico W.
  • Have the Pico inserted into a Grove RPi Pico Shield plus cables.
  • The Softata Console works with the Pico.
  • New device is a Grove device with fully connectivity = Alternatively, the device can be connected to a Grove cable.
  • Have a working Arduino example of the device on the Pico, whether the library for the device is:
    • Available for direct installation from the Arduino library, or …
    • Downloadable from a vendor or third party as an installable Zip file

1. Prelims

  • Select a name for the new device
    • Eg Grove_MyDevice
      • Typically use the Arduino library device name .
  • Identify the connection type, and connection pins
    • One Wire
      • D16,18,20 = GPU Pins 16,18,20
      • 17,19,21 are also available
    • Serial
      • Serial1, Serial2 = GPU pins 0,4
      • This is Tx, Rx = Tx+1
    • I2C
      • I2C0, IC21 = GPU Pins 8,6
      • This is SDA, SCL = SDA+1
    • SPI
    • Analog
      • A0,A1,A2 = GPU Pins 26,27,28

Pins are for if using the Grove RPi Pico Shield. More options if not.

2. Duplicate the relevant Softata header and source files

eg. From <Repository directory>\Softata\Softata\src

  • Duplicate grovesensor.h as grove_mydevice.h
    • Change GROVE_SENSORH at the top to GROVE_MYDEVICEH. Change on lines 1 nd 2.
    • Change the class name to MyDevice eg:
      • class Grove_SensorTemplate: public Grove_Sensor becomes:
      • class Grove_MyDevice: public Grove_Sensor
    • Enter the following as a third line
      #include "grove_sensor.h"
    • If the device is a sensor ,set the number of properties in the line:
      #define NUM_PROPERTIES 0
  • Duplicate grove_sensor_template.cpp.txt as grove_mydevice.cpp
    • Change all entries of Grove_SensorTemplate in that file to: Grove_MyDevice
      • eg Grove_SensorTemplate:: become
        Grove_MyDevice::
      • And …#include "grove_template.h" should now refer the device’s header file.
    • Change #include <????.h> to reference the Arduino library as per the sample app.
    • Implement the methods as per the sample app.
      • Use dht11.cpp and bme280.cpp as guides

3. Softata.h

  • Add the sensor device to #define G_SENSORS C(DHT11)C(BME280)C(URANGE)
    • eg #define G_SENSORS C(DHT11)C(BME280)C(URANGE)C(MYDEVICE)
    • Other device type entries are listed in lines nearby
  • Below line 81 add an entry for sensor’s properties
  • Below line 85 add an entry for the sensor’s number of properties
  • Below line 89 add any further information required by Setup
    • This will typically be default values.
  • Below line 91 add sensor connections for the device

Softata.ino

  • About line 500 look for case s_getpinsCMD:
    • Add an entry below the last branch of the case statement switch ((GroveSensor)other), just before default: to get the device pin connections eg:
      case MYDEVICE:
      {
          client.print(Grove_MyDevice::GetPins());
      }
      break;
      
  • Similarly add an entry under
    case s_getPropertiesCMD: just before default: add code to get the device properties such as:
      case MYDEVICE:
      {
          client.print(Grove_MyDevice:GetListofProperties());
      }
    
  • And under
    case s_setupdefaultCMD/s_setupCMD: in the switch ((GroveSensor)other sequence just before default: add an entry to instantiate the device such as:
      case MYDEVICE:
      {
          grove_Sensor  = new Grove_MyDevice();
          //
          _done = true;
      }
      break;
    
    • You might have to provide any parameters required in the class constructor such as a pin.
  • Below if(_done)/if(param==s_setupdefaultCMD) enter any non-default setup code in the else branch.

The rest of the sensor code is sensor generic (polymorphism).

C# Softatalib & Console app

When Sensors are chosen (option 5), the Console app should list the new Sensor device and be able to be chosen, get its properties and pins, and exercise it without any modifications to this code. Similarly any new Display device should be listed for that menu. Nb Implementation of a display device is similar to a sensor implementation but can be more complex if Misc commands are used.

Call to arms:

When you get your device working please fork the repository, add your entry and submit it back, thx.


 TopicSubtopic
   
 This Category Links 
Category:Softata Index:Softata
  Next: > Softata
<  Prev:   Softata