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:

#include "LibraryBase.h"

#define MYADDON1_INIT  0x00
#define MYADDON1_FUNC1 0x01

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


classdef MyAddon1 < arduinoio.LibraryBase
  properties(Access = private, Constant = true)
    INIT_COMMAND = hex2dec('00');
    FUNC1_COMMAND = hex2dec('01');
  properties(Access = protected, Constant = true)
    LibraryName = 'MyAddons/MyAddon1';
    CppHeaderFile = fullfile(arduinoio.FilePath(mfilename('fullpath')), 'MyAddon1.h');
    CppClassName = 'MyAddon1';
    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, []);
    function retval = func1(obj)
       cmdID = obj.FUNC1_COMMAND;
       retval = sendCommand(obj.Parent, obj.LibraryName, cmdID, []);

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

I had given up on the problem for the time being. But I came back to it after noticing arduino package updates. I tried it again and got further: the addon MyAddon1 from the minimal example is recognized now. But the build in the arduino IDE fails with the message:

addons.h:3:10: error: expected initializer before 'addon1'
 MyAddon1 addon1(octavearduino);
exit status 1
expected initializer before 'addon1'

This is in an automatically generated “addons.h” file by the Octave arduino package, so there seems to be a bug there(?).

Another thing I found in the minimum example from the website given in my first post: the function names are not consistent: MYADDON1_INIT vs MYADDON_INIT and MYADDON1_FUNC1 vs MYADDON_FUNC1. I would hope for a more consistent and working example on the website.

Using the code you pasted above for MyAddon1.h, I see a couple of issues, which are incorrect in the docs as well.

The case statements show MYADDON_INIT and MYADDON_FUNC1 but should be MYADDON1_INIT and MYADDON1_FUNC1

Secondly, the class needs a ‘;’ after the ‘}’ in the class definition

Ill update the docs

Thank you! I got it to work with these corrections. One more thing I had to do: force Octave to close after calling ar = arduino([],[], 'libraries', 'MyAddons/MyAddon1', 'forcebuild', true); because it prevented writing access to the arduino from the IDE. This was different when calling the standard arduinosetup where the compiling and code transfer was possible and Octave simply waited for the process to finish. Do you have an idea why this is or how to prevent this?

When calling like that, it should disconnect from the arduino serial port, run the IDE, wait for you to close the IDE (assuming programming it) and then reconnect to the port.

Can you edit arduino.m in the installed package and after the line:

printf("starting reprogram process ....\n")

Add a line of:


Restart octave (to make sure it uses the changed file), and retry your arduino call and we will hopefully be able to see where it is failing.

Actually, should be able to run without the edit as:

ar = arduino([],[], 'libraries', 'MyAddons/MyAddon1', 'forcebuild', true, 'debug', true);

Also, note that the forcerebuild option only will force a rebuild if the library has not been installed on the arduino previously. If it has previously been installed (even if it was a older version) it will not be reprogrammed.

Matlab has a forcebuildon option that the octave arduino package currently does not have, that would force the rebuild regardless.

Thank for the additional input. I found a reason/workaround for Octave blocking the upload of the addon library. In the arduino package function __freeArduino__ the check if(obj.connected) never returns a true. If I simply replace the code with obj.delete without any if-condition, the interaction between Octave and the IDE works as expected. As for the forcebuild option only working on the first installation of the library, I now simply use arduinosetup('libraries', 'MyAddons/MyAddon1'). This works every time.

Ok - in freeArduino, the line could change from



if isobject (obj.connected)