Problem realizing minimal example of an arduino addon

Problem description

I’ve been trying to implement the minimal example of a custom arduino addon by following the package doc: Addons Overview (Arduino Toolkit - a somewhat Matlab compatible arduino toolkit for GNU octave.)
I created the addon directory: I (separately) tried creating a custom addon-directory both within the arduino package’s +arduinoioaddons folder and in a separate +arduinoioaddons directory which I added to the Octave load path. However, listArduinoLibraries never returns the addon as a valid addon, even though I haven’t changed the example from the website at all yet. The problem seems to be that the undocumented call to meta.class.fromName(classname) within addons returns nothing for this addon and I cannot see why.

I would appreciate any helpful comments.

As for the content of the two required files:
MyAddon1.h:

#include "LibraryBase.h"

#define MYADDON1_INIT  0x00
#define MYADDON1_FUNC1 0x01

class MyAddon1 : public LibraryBase
{
  uint8_t cnt;
public:
  MyAddon1(OctaveArduinoClass& a)
  {
    libName = "MyAddons/MyAddon1";
    a.registerLibrary(this);
  }
  void commandHandler(uint8_t cmdID, uint8_t* data, uint8_t datasz)
  {
    switch (cmdID)
      {
      case MYADDON_INIT:
        {
          cnt = 0;
          sendResponseMsg(cmdID, 0,0);
          break;
        }
      case MYADDON_FUNC1:
        {
          // func 1 is just returning a uint8 count of number of times called
          cnt ++;
          sendResponseMsg(cmdID, &cnt, 1);
          break;
        }
      default:
        {
          // notify of invalid cmd
          sendUnknownCmdIDMsg();
        }
      }
  }
}

MyAddon1.m:

classdef MyAddon1 < arduinoio.LibraryBase
  properties(Access = private, Constant = true)
    INIT_COMMAND = hex2dec('00');
    FUNC1_COMMAND = hex2dec('01');
  endproperties
  properties(Access = protected, Constant = true)
    LibraryName = 'MyAddons/MyAddon1';
    CppHeaderFile = fullfile(arduinoio.FilePath(mfilename('fullpath')), 'MyAddon1.h');
    CppClassName = 'MyAddon1';
  endproperties
  methods
    function obj = MyAddon1(parentObj, varargin)
      obj.Parent = parentObj;
      # no pins being used
      obj.Pins = [];
      # send any command to the arduino during setup ?
      sendCommand(obj.Parent, obj.LibraryName, obj.INIT_COMMAND, []);
    endfunction
    function retval = func1(obj)
       cmdID = obj.FUNC1_COMMAND;
       retval = sendCommand(obj.Parent, obj.LibraryName, cmdID, []);
    endfunction
  endmethods
endclassdef

My system

  • OS: Windows 10 (version 20H2) (also reproduced this on Ubuntu)
  • Octave version: Version 6.3.0
  • Installation method: Downloaded and installed “octave-6.3.0-w64-installer.exe” from Download

@lostbard Any ideas what goes wrong here?

A little late to the question, but ensure that the +arduinioaddons directrory is in the octave path, the library name and class match

A couple of questions:

  1. is the +arduinioaddons directory in the octavce path ?
  2. whats the full path to your MyAddon1.m ?

In linux, if I have the .m fie in my home directory in path: ~/+arduinoioaddons/+MyAddons/MyAddon1.m

My octave path command (unmodified) has ‘.’ in the path list, so if I am in my home directory and run listArduinoLibriaies, it is listed.

If I am not in my home direcory but addpath my home directory, I see it listed.

1 Like