Illegal byte sequence

No sé por qué me sale este error, estoy intentando pasar mi programa de matlab a octave y esoty intentando ver como adptar mi fichero arduino.m a octave pero me está dando problemas

l3>cd>⢂慰>> motorcon
Elegir:  1.- Identificaci�n del modelo del motor  2.- Control del motor:  1
Tipo de referencia:  1.- Sinusoidal.  2.- Escal�n: 2
0.- Motor 1.-Simulaci�n0
error: serial: Error opening the interface: Illegal byte sequence
>> ar=arduino()
ar =
  arduino object with fields of:
            port = \\.\COM4
           board = uno
       libraries = {
              i2c
              spi
              servo
              shiftregister
        }
        availablepins = {
              d0 - d13
              a0 - a5
        }
>> serialport('COM4')
error: Invalid call to serialport.  Correct usage is:

 -- Loadable Function: SERIAL = serialport ([PATH], [BAUDRATE])
 -- Loadable Function: SERIAL = serialport ([PATH], [PROPNAME,
          PROPVALUE])

Additional help for built-in functions and operators is
available in the online version of the manual.  Use the command
'doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at https://www.octave.org and via the help@octave.org
mailing list.
>> serialportlist
ans =
{
  [1,1] = COM4
}

>> serialport('COM4', '115200')
error: Invalid call to serialport.  Correct usage is:

 -- Loadable Function: SERIAL = serialport ([PATH], [BAUDRATE])
 -- Loadable Function: SERIAL = serialport ([PATH], [PROPNAME,
          PROPVALUE])

Additional help for built-in functions and operators is
available in the online version of the manual.  Use the command
'doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at https://www.octave.org and via the help@octave.org
mailing list.
>> serialport([COM4], [115200])
error: 'COM4' undefined near line 1, column 13
>> s1=serialport('COM4')
error: serialport: Error opening the interface: Acceso denegado.

Not sure exactly what you are tryinh to do but it looks like you are connecting to the arduino using the arduino function call and then trying to open the serial port that is already open using the serialport function?

Thats not going to work as the serialport is already open via the arduino call

Assuming motorcon is your code, what calls is it making?

now I get this:

Ĭerror: subsref: unknown method or property: pinMode
error: called from
    inicializa at line 6 column 1
    motorcon at line 132 column 1
>>

My initcaliza.m file looks like this

global SIMULACION;
global posicion;

if SIMULACION == 0
%Asignaci�n de pines
a.pinMode(4,'OUTPUT');
a.pinMode(10,'OUTPUT');

%Puesta a cero de la salida 4 y 10
a.digitalWrite(4,0);
a.analogWrite(10,0);

%Reseteo contador de encoder
a.reset_contador;

%Conversi�n pulsos/�ngulo
posicion=[a.e*.18*(2*pi/360)];
else
    posicion=[0];
end

tic

global timer_data
timer_data.period_s = 4;
timer_data.n_calls = 3;
timer_data.callback_fcn = @callback_calculo;
timer_data.end_fcn = @callback_resultados;
timer_data.tic_id = [];
timer_data.call_num = 0;

function timer_callback ()
  global timer_data
  if (timer_data.call_num == 0 && isempty (timer_data.tic_id))
    timer_data.tic_id = tic ();
    return;
  endif

  if (toc (timer_data.tic_id) > timer_data.period_s)
    if (timer_data.call_num < timer_data.n_calls)
      timer_data.callback_fcn ()
      timer_data.call_num += 1;
      timer_data.tic_id = tic ();
    else
      timer_data.end_fcn ();
      remove_input_event_hook (timer_data.hook_id);
    endif
  endif
endfunction

timer_data.hook_id = add_input_event_hook (@timer_callback);

Assuyming ‘a’ in an arduino object, I dont see documentation saying pinMode is a function in the matlab arduino ackage. And it is not in the Octave package [1].

You are wanting to use configurePin perhaps ?

Down lower, writeDigitalPin, writeAnalogPin.

It looks like you are trying to use ‘arduino’ functions mixed with the matlab functions? See the reference link below for functions

[1] List of Functions for the 'arduino' package

This appears to be (c) Mathworks code so should not be posted here.

The GNU octave arduino toolkit has been written to conform with the published functions that Matlab has.

What the Matlab version, or derivatives of the Matlab code internals does it probably out of scope of what can be answered here.

As previously mentioned, the GNU Octave arduino classes support the functions as as publically described but not internals.

SO really the only questions we can probably answer will be when functions of the toolkit do not work as expected.

The GNU Octave Arduino manual is here [1]

[1] Top (Arduino Toolkit - a somewhat Matlab compatible arduino toolkit for GNU octave.)

Hi, I am slowly working out the bugs. I changed matlab functions like pinMode and digitalWrite to octave configurePin and writeDigitalPin. Now I get a weird error that I can’t figure out which file the retval and configurePin line belongs to in order to know how to fix the error (the motorcon and initializa file I do have).
Best regards.

image

Im guessing you are writing something like

x = configurePin(ar, somepin, somemode)

But when calling configurePin to set a mode it does not return a value

The documentation:

currmode = configurePin (ar, pin)

configurePin (ar, pin, mode) 

For setting the pin:

configurePin(ar, somepin, somemode)

for getting the mode:

mode = configurePin(ar, somepin)

Understood. Now I get this error xd
image

without any of your code - who knows what the issue is - at a guess the arduino is already open and you are trying to open it again ?

Also, if you can please paste text rather than images of a section of text

Hi, I have managed to solve that, the problem is that I am getting errors to functions that I have implemented in my matlab project that I have to convert to octave. I think the main problem is that I do not know if there is any way to pass my matlab file arduino.m to octave, that file looks a lot like this, with some tweaking to implement a servo.

What specific error are you getting?

Here, in my initialize file. I have solved the pinMode and analogWrite errors by adapting to octave functions but now I have a problem with one created by me,reset_contador, which is written in my modified arduino.m script.


What I don’t know is if I would have to go modifying the entire arduino.m script and adapt it to octave or if something could be done that is less complex.
Best regards.
What the function does is this:

[First part.txt|attachment](upload://zLsxiLW5hnwL3kejU9fcEttKygV.txt) (320 Bytes)

Scond part.txt (957 Bytes)

you need to change your code to call all arduino toollkit functions - it is also better if you dont call it arduino.m since that is a toolkit function name

From the code, it look like you have a motor controller attached to a serial port on the arduino ? so you will need to open the arduinos serial port (not the serial port on the computer, AND not the comport on the arduino used for communication to the computer)

And then use the arduino serial port functions to write to the port.

Please read the documentation [1] [2] for the functions to use.

[1] Function Reference: @device/device
[2] Function Reference: @device/write

If not hooked to the serial port, then you need to then modify your code to use whatever device type it is hooked to

ie: stepper motor hooked directly to the arduio - use the simplestepper class

if its a servo, use the servo class

if its aDC motor, use PWM

if its hooked up to a adafruit motor sheild v2, use that addon - all these are documented within the manual of the toolkit.

I keep getting the same error: “error: serial: Error opening the interface: Illegal byte sequence” even though I have added the serial() function, I have adapted the part I added in my arduino.m file in matlab and I still get the same errors.
Best regards.
inicializa.m (2.2 KB)

You are opening a serialport on the PC with

a.aser=serial(“COM4”, 115200);

This also the port thats already opened in the arduino object, so you can not open it again.

Do you want to open a serial port of the PC or one on the arduino?

The error “error: serial: Error opening the interface: Illegal byte sequence” I got before adding the line a.aser=serial(“COM4”, 115200); when I opened the serial port with the arduino object

So if you do not include any call to serial, you still get that error ?