Skip to content

A simple (Software) package LIKE of Fimata for RPI Pico W running Arduino

License

Notifications You must be signed in to change notification settings

djaus2/Soft-ata

Repository files navigation

Soft-ata Version 11.400

Updates

  • V11.400 In Console app, implemented Generic Display methods option ConsoleTestType.Displays_Generic: which calls methods common to all displays, even if not implemented. Should just ignore those.
    • getpins, getMiscCmds, clear, backlight, setCursor, writestrngCMD, cursor writestringCMD, homeCMD
      • Tested on LCD thus far (backlight is null for that).
  • V11.300 As per 11.100 and 11.200 Individual misc commnds for LCD in Console app
    • Also fixed misc switch case miscode for LCD!
  • V 11.200 As per 11.100 Individual misc commnds for GBargraph in Console app
    • ConsoleTestType.Displays_Suite_of_Tests
    • viz ConsoleTestType.Displays_Suite_of_Tests
    • Also added GBargraph misc commands in SoftataLib so can be directly used elsewehere.
  • V 11.100 Extended Console App fuctionality
    • Can run fixed suite of tests for a display, as previous.
    • Or run indiviaul misc commands, as selected. Only implemented for Pixel display thus far and GBargraph (Grove LED Bar).
  • V 11.000 Added sensor DHTXX that uses the DHTNew lib package available from lib in Arduino IDE. Can be used for DHT11,22 etc.
    • Includes auto adjusted min time btw reads.
      • Gets increased til no error. (Starts at 1000mS and incr by 250mS. Seems that 2000mS works)
      • If read is earlier than min time after last read, uses data from previous read.
      • Bonus: DHTXX.txt in BlocklyBonusExamplestoUpload folder: Upload in Blockly Is DHTXX sensor with 10 reads.
  • V 10.900
  • V10.199/200
    • Added Grove.Bargraph/Linksprite.bargraph as per linksprite.bargraph.rpipico
      • Added extra Misc commands now: flow,flow2,setLed,clrLed,toggleLed,setLevel,exercise
    • Console app: Can save settings (RPi Pico Server IPAddress and Port). Console app now has extra Misc coammnds as above and Grove.Bargraph option.
    • Renaming of tests in Console and Blazor apps
    • Renaming in Arduino Softata as well such as: Shift595ParaOut class to SIPO_74Hc595.
    • Console app now loops. When test finishes get menu again.
  • V10.111 Actuator:Grove Relay added
    • Connect to Pin 16(default)/18 or 20 (Socket 3/4 or 5 on bottom)
    • Can set,clear or toggle
    • Note that bit parameter is ignored but required (use 0).
  • V10.110: Simplified C2D message protocol
    • Can send C2D messages to Pause and Continue Telemetry
    • Eg "P1" or "Pause 1"
    • First char in string P ause or C ontinue determines command. Case insensitive
    • Last char is index (Nb: Typically 1 not 0).
    • T oggle, A (Set), R eset Actuator D2C messages coming.

Index this page:

1. In brief 8. Soft-ata Projects
2. About 9. RPi Pico W Arduino
3. History 10. "Some" of the required Arduino Libraries
4. API Documentation 11. Settings
5. Local Docs 12. Use
6. Background 13. Blockly
7. Firmata 14. Azure IoT Hub

In Brief

An Arduino sketch LIKE Firmata for a Rapberry Pi Pico W running Arduino. Includes a .NET package so that you can write your own remote client in C# to remotely control Pico devices. Console, Blazor and WebAPI app examples included with MAUI possible later.

A key objective was to also provide a Blockly style low code device programming using this infrastructure.

Soft-ata rather than firm-ata!

Branch 10.001 Is latest. Major resture of repository. All code under /code with a readme each. Under developement. Will merge back here when complete.


  • Documentation: Related blog posts

  • The Arduino Shield code is now downloadable as a Zip file when running the SoftataWebAPI

About

The Pico W app runs as a TCPIP Service taking commands, running them and returning the result to the client. For peripheral setups, displays and actuators, the expected result is simply an acknowledgement "OK:" string. For sensor reads, a data string is returned with an "OK:" prefix. The SoftaLib checks and consumes the acknowledgment data before it is forwarded to the client app.

The RPi Pico W has two processing cores. Whilst most interactions occur via the first core, some functionality is built into the second core. Firstly, the inbuilt LED flashes under control by the second core. When the Pico sketch first boots and both cores are ready, it blinks at a slow rate. (4s on/4s off). Once a connection is made, it blinks at 4x this rate.

  • The client app should not try connecting until then.
  • The device can run in a "headless" mode with status being indicated by "Coded flashes on the inbuilt LED" on this page. Communication between the two cores is generally from core one to core two and is done in a synchronized manner.

The second core is also used for autonomous streaming of Sensor Telemetry data over Bluetooth and to an Azure IoT Hub. Once started, it runs with periodic transmissions without further interaction until a Pause or Stop command is sent. When paused, the transmission continues after reception of a Continue command. For every transmission, there is also a quick double flash by the inbuilt LED.

Whereas Firmata is implemented from the ground up, implemented in terms of protocols with devices being added in terms of those implementations Softata is implemented in terms of existing specific Arduino device libraries. To add a device you include its Arduino library and then slot it into the Softata app infrastructure. That code is, in the main, polymorphic. To add for example, a sensor you copy you copy the template sensor.cpp file and implement the methods in it according to the devices library samples. You also create header code for it largely by copying an existing sensor's header. Within the Softata app and SoftataLib code there ar then some specific hooks to add for the device. This process is documented here. This needs some updating.

History

The plan was to implement an Arduino app to run on a RPi Pico W placed in a Grove Shield for Pi Pico. The Pico W has onboard Arduino implemented using the earlephilhowe BSP implementation. The Grove infrastructure being used because of it's simple standardised connectivity between devices and the shield at both ends. Rather than implement a general purpose interface for devices in One Wire, I2C or SPI, etc, use is made of existing Arduino libraries for Grove devices.

The intention was also to implement a class for each device type (sensor display, actuator etc) such that the class can be extended for each actual device of that type by implementing the base methods. That way, the functionality of the app for a device type needs no modification for any additions. Additional non Grove devices can be added by connecting to a Grove cable.

Ultimately the intention was to stream Telemetry from sensors to an Azure IoT Hub
Communication with a host app using a client service model with the service running on the Arduino app connected to by clients running on a host. This is all now functional.

A .NET library was built that communicates to the service as a mirror of the Arduino functionality. A Console app was built to fully test and demonstrate this functionality. A Blazor app to do same is under development. Similarly a .NET MAUI app is envisaged. Finally, a port of the .NET library to the Wilderness Labs Project Lab V3 device is also envisaged.***

API Documentation

The full API documentation is here (Extended/updated)

Local Docs

Background

I wanted to use a RPI Pico W with Arduino installed controlled by .NET apps. Drilling deeper, I wanted to make the Pico coding available with a Blockly style UI as per CodeCraft. There is also BlocklyDuino.

After some consideration Firmata was considered. But this lacks a simple .NET (not UWP) interface.

Firmata

Firmata is a protocol for communicating with microcontrollers from software on a host computer. The protocol can be implemented in firmware on any microcontroller architecture as well as software on any host computer software package. From

So if there a Firmata app running on a device, a host computer can interact directly with the device's hardware through a standard protocol over Serial, Ethernet (Wired or WiFi) or Bluetooth. The Firmata protocol can be viewed in the first link below. There are various implementations of it for various devices: ... There is more discussion of Firmata in the Blog post. ...

I could get the ConfigurableFirmata running on a RPi Pico W over WiFi. The.NET client libraries were quite old and used a Serial connection. Using a .NET TCPIP Client, I found that the functionality I could get working with interactively was limited. So I decided to build my own "Firmata", hence Soft-ata.

Soft-ata Projects

RPi Pico W Arduino

The Pico needs the following BSP installed:

Its API documentation is here

This BSP is as per previous repositories here as well as in some blog posts:


The required Arduino Libraries

Update 29 Oct 2024

(Been reinstalling PC so checking these libraries)

  • BMx280BMI <-- Updated 29 Oct /24
    • Direct library install from Arduino. Search for BMx280BMI
  • BME280 by Tyler Glenn (finitespace)
    • Direct library install from Arduino. Search for BME280
  • Grove_Ultrasonic_Ranger
    • Zip file install from here
  • u8g2 For Grove OLED096 Display
    • Direct library install from Arduino. Search for u8g2 <-- Correction 29 Oct /24 8 not B
  • Grove_LCD_RGB_Backlight For Grove-LCD RGB V4.00
    • Zip file install from here
  • Adafruit NeoPixel
    • Direct library install from Arduino, Search for Adafruit NeoPixel
  • PubSubClient
    • Direct library install from Arduino. Search for PubSubClient
  • Azure SDK for C - Arduino
  • Servo by Michael Margolis
    • Direct library install from Arduino. Search for Servo
  • PS: If you get static_assert(ENABLE_CLASSIC build error:
    • Tools->Bluetooth Stack set to Bluetooth and IPV4
    • Also need Flash Size 1M and 1M (last option)
  • Re: DHTNew (Watch this space)
    • DHTNew_Temperature_And_Humidity_Sensor
      • Direct library install from Arduino. Search for DHTNew
    • Setup for the DHT11 (Maybe use DHTNew lib)?? Resolving this: Will migrate to this library for DHTXX as this lib can sense wheich DHTXX and is in Arduino lib)

Settings

The Softata sketch requires at least, a WiFi SSID and Password. If sending telemetry to an Azure IoT Hub then connectivity settings for that are also required. There are a number of ways these settings can be ascribe such as fixed in a header file, input or read from flash. See Arduino Startup Options. The flash method can be set and survive download of a new sketch.

Use

See the Console app. The IpAddress as determined when the Pico W runs must match that in the library. The ports must also match. The Console test app has multiple options:

1.      Digital Button and LED
2.      Analog Potentiometer and LED
3.      PWM
4.      Servo
5.      Sensors
6.      Displays
7.      Loopback
8.      Analog Potentiometer Light and Sound
9.      USonicRange
A.      Potentiometer and Actuator
B.      GPS Serial
C.      Test OTA Or WDT
D.      Analog Device Raw

The Blazor app has similar functionality.

Blockly

SoftataWebAPI is an ASP.NET Core API sketch that presents a Blockly and a Swagger interface to all of the SoftataLib (.NET) API commands. This makes use of ignatandrei/NETCoreBlockly. SoftataWebAPI can also be used without installation as it is hosted on Azure at softatawebapii.azurewebsites.net. Note though that some tunnelling is required to connect SoftataWebAPI and the Softata service running locally on a Pico W. See Running Blockly on local Pico from Azure Softata API. Eg:

netcoreblockly

This Blockly app connects to the device at 192.168.0.9 (Begin), gets the version number of Softata (currently 10.001), gets a list of devices that can be used, and completes (which reboots the device).


Azure IoT Hub

  • Telemetry can be sent from a sensor connected to the Pico to an Azure IoT Hub. See Softata-Console_app_-_SensorsSome CD messages can be sent to stop, pause and start such telemetry. Control of an actuator via CD Messages is a work in progress.

Enjoy! :)