gnu-octave / octave-arduino

Basic Octave implementation of the matlab arduino extension, allowing communication to a programmed arduino board to control its hardware.
https://gnu-octave.github.io/octave-arduino/
GNU General Public License v3.0
6 stars 1 forks source link

Can't make arduino object with a Mac #3

Closed EkpuzC closed 6 months ago

EkpuzC commented 7 months ago

I'm new to using a Mac (MacBook Pro, Sonoma 14.4) but have experience with Octave and Arduino in Windows. After pkg load arduino I can see this:

Package Name        | Version | Installation directory
--------------------+---------+-----------------------
           arduino *|  0.12.1 | .../cathy.zupke/.local/share/octave/api-v58/packages/arduino-0.12.1
instrument-control *|   0.9.2 | .../.local/share/octave/api-v58/packages/instrument-control-0.9.2
>>
The Octave version is:
>> version
ans = 8.4.0
>>

I can run arduinosetup and it will open the Arduino IDE and let me upload the code to an Arduino Uno board. That board can then work with Octave on a Windows machine, but when I try to make a connection on the MacBook I get this:

>> a=arduino('/dev/cu.usbmodem14201')
error: __initArduino__: failed get lib 1 err=1 - Undersized packet header
error: called from
    __initArduino__ at line 114 column 12
    arduino at line 133 column 16
>>

While more rare, I've also seen this:

>> a=arduino('/dev/cu.usbmodem14201')
error: set: H must be a graphics handle
>>

Unplugging the board and plugging it back in seems to restore it to the "Undersized packet header" state.

For what it is worth, when installing the instrument-control package, there were a lot of warnings but as far as I could tell, no errors.

lostbard commented 7 months ago

Undersized packet header can mean it didnt get any data in response or got some data.

what does running the command: serialportlist

in octave show

And:

a = serialport("/dev/cu.usbmodem14201")

And what does running the below show:

a=arduino('/dev/cu.usbmodem14201', '', 'Debug', 1)

Finally, running outside of octave, in a bash shell:

ls /dev/cu.*

and

ls -l /dev/cu.usbmodem14201

On Sat, Mar 9, 2024 at 9:17 PM Cathy Zupke @.***> wrote:

I'm new to using a Mac (MacBook Pro, Sonoma 14.4) but have experience with Octave and Arduino in Windows. After pkg load arduino I can see this:

pkg list Package Name | Version | Installation directory --------------------+---------+----------------------- arduino | 0.12.1 | .../cathy.zupke/.local/share/octave/api-v58/packages/arduino-0.12.1 instrument-control | 0.9.2 | .../.local/share/octave/api-v58/packages/instrument-control-0.9.2

The Octave version is:

version ans = 8.4.0

I can run arduinosetup and it will open the Arduino IDE and let me upload the code to an Arduino Uno board. That board can then work with Octave on a Windows machine, but when I try to make a connection on the MacBook I get this:

a=arduino('/dev/cu.usbmodem14201') error: initArduino: failed get lib 1 err=1 - Undersized packet header error: called from initArduino at line 114 column 12 arduino at line 133 column 16

While more rare, I've also seen this:

a=arduino('/dev/cu.usbmodem14201') error: set: H must be a graphics handle

Unplugging the board and plugging it back in seems to restore it to the "Undersized packet header" state.

For what it is worth, when installing the instrument-control package, there were a lot of warnings but as far as I could tell, no errors.

— Reply to this email directly, view it on GitHub https://github.com/gnu-octave/octave-arduino/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI3CYRLVYGLJC3XILA4U4LYXO7DBAVCNFSM6AAAAABEOSORIKVHI2DSMVQWIX3LMV43ASLTON2WKOZSGE3TONBYG44TOMI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

EkpuzC commented 7 months ago

Thanks for the prompt response. Here is the information asked for:

>> serialportlist
ans =
{
  [1,1] = /dev/tty.BLTH
  [2,1] = /dev/tty.Bluetooth-Incoming-Port
  [3,1] = /dev/tty.usbmodem14201
}

>> a = serialport("/dev/cu.usbmodem14201")
a =

  Serial Port Object Serial-/dev/cu.usbmodem14201
    Port:     /dev/cu.usbmodem14201
    BaudRate: 115200
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  -1
>>

ADM-L021269-MAC:~ c.z$ ls /dev/cu.*
/dev/cu.BLTH            /dev/cu.usbmodem14201
/dev/cu.Bluetooth-Incoming-Port
ADM-L021269-MAC:~ c.z$ 
lostbard commented 7 months ago

And for:

a=arduino('/dev/cu.usbmodem14201', '', 'Debug', 1)

lostbard commented 7 months ago

and in bash:

ls -l /dev/cu.usbmodem14201

lostbard commented 7 months ago

Also, can you verify that nothing else is also trying to use the serial port? In linux, I would just run the following in a bashshell before doing the arduino octave call:

sudo lsof | grep usbmodem14201

EkpuzC commented 7 months ago

without any objects in Octave:

ADM-L021269-MAC:~ c.z$ sudo lsof | grep usbmodem14201 Password: Sorry, try again. Password: ADM-L021269-MAC:~ c.z$

After making a serialport object:

ADM-L021269-MAC:~ c.z$ sudo lsof | grep usbmodem14201 octave-gu 16447 c.z 19u CHR 9,7 0t0 805 /dev/cu.usbmodem14201 ADM-L021269-MAC:~ c.z$

lostbard commented 7 months ago

without any objects in Octave:

ADM-L021269-MAC:~ c.z$ sudo lsof | grep usbmodem14201 Password: Sorry, try again. Password: ADM-L021269-MAC:~ c.z$

After making a serialport object:

ADM-L021269-MAC:~ c.z$ sudo lsof | grep usbmodem14201 octave-gu 16447 c.z 19u CHR 9,7 0t0 805 /dev/cu.usbmodem14201 ADM-L021269-MAC:~ c.z$

ok -that seems good for nothing else using it

Can you provide the data from the other checks?

EkpuzC commented 7 months ago

This is what I shared before. I see that I missed the 'debug' one. I'll try to get that soon.

serialportlist ans = { [1,1] = /dev/tty.BLTH [2,1] = /dev/tty.Bluetooth-Incoming-Port [3,1] = /dev/tty.usbmodem14201 }

a = serialport("/dev/cu.usbmodem14201") a =

Serial Port Object Serial-/dev/cu.usbmodem14201 Port: /dev/cu.usbmodem14201 BaudRate: 115200 Parity: None DataBits: 8 StopBits: 1 Timeout: -1

ADM-L021269-MAC:~ c.z$ ls /dev/cu.* /dev/cu.BLTH /dev/cu.usbmodem14201 /dev/cu.Bluetooth-Incoming-Port ADM-L021269-MAC:~ c.z$

lostbard commented 7 months ago

also ls -l /dev/cu.usbmodem14201 (note the - lower case L)

lostbard commented 7 months ago

also, not thatit should make any difference, is it a official arduino uno, or an off brand one ?

EkpuzC commented 7 months ago

The board I’ve been using is an ELEGOO UNO R3 clone. It looks like using a Sparkfun clone works more normally. My students are using the Sparkfun board but some are still having trouble. On the off chance that we’ll discover something helpful I’ll go through the different diagnostic steps for both boards.

First with the ELEGOO board…

>> serialportlist
ans =
{
  [1,1] = /dev/tty.BLTH
  [2,1] = /dev/tty.Bluetooth-Incoming-Port
  [3,1] = /dev/tty.usbmodem14201
}

>> a=arduino('/dev/cu.usbmodem14201', '', 'Debug', 1)
>> 165 0 1 0
<<
error: __initArduino__: failed valid response err=1 - Undersized packet header
error: called from
    __initArduino__ at line 49 column 8
    arduino at line 221 column 14
>> a = serialport("/dev/cu.usbmodem14201")
a =

  Serial Port Object Serial-/dev/cu.usbmodem14201
    Port:     /dev/cu.usbmodem14201
    BaudRate: 115200
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  -1

In the bash terminal…

ADM-L021269-MAC:~ c.z$ ls -l /dev/cu.usbmodem14201
crw-rw-rw-  1 root  wheel  0x9000005 Mar 11 20:07 /dev/cu.usbmodem14201
ADM-L021269-MAC:~ c.z$ 

ADM-L021269-MAC:~ c.z$ ls /dev/cu.*
/dev/cu.BLTH            /dev/cu.usbmodem14201
/dev/cu.Bluetooth-Incoming-Port
ADM-L021269-MAC:~ c.z$ ls -l /dev/cu.usbmodem14201
crw-rw-rw-  1 root  wheel  0x9000005 Mar 11 20:07 /dev/cu.usbmodem14201
ADM-L021269-MAC:~ c.z$ sudo lsof | grep usbmodem14201
Password:
ADM-L021269-MAC:~ c.z$ 

I think that was everything. Now I’ll repeat these steps (changing the port for the different board).

SparkFun Redboard:

 clear
>> serialportlist
ans =
{
  [1,1] = /dev/tty.BLTH
  [2,1] = /dev/tty.Bluetooth-Incoming-Port
  [3,1] = /dev/tty.usbserial-1420
}

>> s=serialport("/dev/cu.usbserial-1420")
s =

  Serial Port Object Serial-/dev/cu.usbserial-1420
    Port:     /dev/cu.usbserial-1420
    BaudRate: 115200
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  -1

>> a=arduino('/dev/cu.usbserial-1420', '', 'Debug', 1)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
a =

  arduino object with fields of:
            port = /dev/cu.usbserial-1420
           board = uno
       libraries = {
              i2c
              spi
              servo
              shiftregister
        }
        availablepins = {
              d0 - d13
              a0 - a5
        }
       config =
    board = uno
    baudrate = 9600
    mcu = atmega328p
    voltref = 5
    libs =
    {
      [1,1] =

        scalar structure containing the fields:

          id = 0
          name = core

      [1,2] =

        scalar structure containing the fields:

          id = 1
          name = i2c

      [1,3] =

        scalar structure containing the fields:

          id = 2
          name = spi

      [1,4] =

        scalar structure containing the fields:

          id = 3
          name = servo

      [1,5] =

        scalar structure containing the fields:

          id = 4
          name = shiftregister

    }

    port = /dev/cu.usbserial-1420
    description = Arduino Uno R3 Board
    pins =
    {
      [1,1] =

        scalar structure containing the fields:

          name = d0
          id = 0
          modes =
          {
            [1,1] = digital
            [1,2] = uart
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,2] =

        scalar structure containing the fields:

          name = d1
          id = 1
          modes =
          {
            [1,1] = digital
            [1,2] = uart
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,3] =

        scalar structure containing the fields:

          name = d2
          id = 2
          modes =
          {
            [1,1] = digital
            [1,2] = interrupt
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,4] =

        scalar structure containing the fields:

          name = d3
          id = 3
          modes =
          {
            [1,1] = digital
            [1,2] = pwm
            [1,3] = interrupt
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,5] =

        scalar structure containing the fields:

          name = d4
          id = 4
          modes =
          {
            [1,1] = digital
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,6] =

        scalar structure containing the fields:

          name = d5
          id = 5
          modes =
          {
            [1,1] = digital
            [1,2] = pwm
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,7] =

        scalar structure containing the fields:

          name = d6
          id = 6
          modes =
          {
            [1,1] = digital
            [1,2] = pwm
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,8] =

        scalar structure containing the fields:

          name = d7
          id = 7
          modes =
          {
            [1,1] = digital
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,9] =

        scalar structure containing the fields:

          name = d8
          id = 8
          modes =
          {
            [1,1] = digital
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,10] =

        scalar structure containing the fields:

          name = d9
          id = 9
          modes =
          {
            [1,1] = digital
            [1,2] = pwm
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,11] =

        scalar structure containing the fields:

          name = d10
          id = 10
          modes =
          {
            [1,1] = digital
            [1,2] = pwm
            [1,3] = spi0_ss
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,12] =

        scalar structure containing the fields:

          name = d11
          id = 11
          modes =
          {
            [1,1] = digital
            [1,2] = pwm
            [1,3] = spi0_mosi
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,13] =

        scalar structure containing the fields:

          name = d12
          id = 12
          modes =
          {
            [1,1] = digital
            [1,2] = pwm
            [1,3] = spi0_miso
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,14] =

        scalar structure containing the fields:

          name = d13
          id = 13
          modes =
          {
            [1,1] = digital
            [1,2] = pwm
            [1,3] = spi0_sck
            [1,4] = led
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,15] =

        scalar structure containing the fields:

          name = a0
          id = 14
          modes =
          {
            [1,1] = digital
            [1,2] = analog
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,16] =

        scalar structure containing the fields:

          name = a1
          id = 15
          modes =
          {
            [1,1] = digital
            [1,2] = analog
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,17] =

        scalar structure containing the fields:

          name = a2
          id = 16
          modes =
          {
            [1,1] = digital
            [1,2] = analog
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,18] =

        scalar structure containing the fields:

          name = a3
          id = 17
          modes =
          {
            [1,1] = digital
            [1,2] = analog
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,19] =

        scalar structure containing the fields:

          name = a4
          id = 18
          modes =
          {
            [1,1] = digital
            [1,2] = analog
            [1,3] = i2c_sda
          }

          owner =
          mode = unset
          altnames = {}(0x0)

      [1,20] =

        scalar structure containing the fields:

          name = a5
          id = 19
          modes =
          {
            [1,1] = digital
            [1,2] = analog
            [1,3] = i2c_scl
          }

          owner =
          mode = unset
          altnames = {}(0x0)

    }

    flags = 0

>>
>> clear
>>

And from the bash terminal:

ADM-L021269-MAC:~ c.z$ ls /dev/cu.*
/dev/cu.BLTH            /dev/cu.usbserial-1420
/dev/cu.Bluetooth-Incoming-Port
ADM-L021269-MAC:~ c.z$ ls -l /dev/cu.usbserial-1420
crw-rw-rw-  1 root  wheel  0x9000005 Mar 11 20:24 /dev/cu.usbserial-1420
ADM-L021269-MAC:~ c.z$ sudo lsof | grep usbserial-1420
Password:
ADM-L021269-MAC:~ c.z$ 
lostbard commented 7 months ago

ok - I have a elego board somewhere so will see if it has stopped working for me

Looking at the elego board with Debug, it doesnt get anything - I wonder if its either a baudrate mismatch due to usb serial implmentation on that baud or a control line (CTS or RS) issue.

You can try the baudrate as:

a=arduino('/dev/cu.usbmodem14201', '', 'Debug', 1, 'Baudrate', 9600)

(Note: assuming the default baudrate wasnt changed during programming?)

I will write a script you can run that will try out a couple of possible checks for the control line.

lostbard commented 7 months ago

also can you provide the results of this script (rename to a .m file) testarduino.txt

EkpuzC commented 7 months ago

I hope this isn't a duplicate post as I thought I'd answered this earlier today.

Trying the test program gave:

>> testScript

port = /dev/tty.usbmodem14201
baud = 9600
Serial port test 1 --------------------
a =

  Serial Port Object Serial-/dev/tty.usbmodem14201
    Port:     /dev/tty.usbmodem14201
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  1

ans =

  scalar structure containing the fields:

    CarrierDetect = 0
    ClearToSend = 0
    DataSetReady = 0
    RingIndicator = 1

>> 165 0 1 0
len = 4
<< 165 0 1 7
<< 30 149 15 0 50 5 0
Serial port test 2 --------------------
a =

  Serial Port Object Serial-/dev/tty.usbmodem14201
    status:   open
    port:     /dev/tty.usbmodem14201
    baudrate: 9600
    parity:   None
    bytesize: 8
    stopbits: 1
    timeout:  20

requesttosend = on
dataterminalreay = on
>> 165 0 1 0
len = 4
<< 165 0 1 7
<< 30 149 15 0 50 5 0

I also ran it using the Sparkfun board (the one that works) and as far as I can tell, it gave identical results (except for the device paths).

Also, setting the baudrate in the arduino() function gave the same error as without it:
>> a=arduino('/dev/cu.usbmodem14201', '', 'Debug', 1, 'Baudrate', 9600)
>> 165 0 1 0
<<
error: __initArduino__: failed valid response err=1 - Undersized packet header
error: called from
    __initArduino__ at line 49 column 8
    arduino at line 221 column 14
EkpuzC commented 7 months ago

One more factoid is that I tried some older Sparkfun Redboards and they seem to be problematic in the same was as the Elegoo board. I know different versions of the board have different serial chips which might suggest a driver issue. I don't know if it makes sense that some sort of driver issue would impact Octave/Arduino but not the Arduino IDE.

dasergatskov commented 7 months ago

FWIW -- I found some Sparkfun Redboard lying around. I can connect/upload drom arduino ide, but cannot connect with octave w/ the same (or similar error:

octave:6> a = arduino ("/dev/ttyUSB0","","Debug", 1, "Baudrate", 9600)
>> 165 0 1 0 
<<  
error: __initArduino__: failed valid response err=1 - Undersized packet header
error: called from
    __initArduino__ at line 49 column 8
    arduino at line 221 column 14

From lsusb -v this is the port description:

Bus 003 Device 004: ID 1a86:7523 QinHeng Electronics CH340 serial converter
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass          255 Vendor Specific Class
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x1a86 QinHeng Electronics
  idProduct          0x7523 CH340 serial converter
  bcdDevice            2.64
  iManufacturer           0 
  iProduct                2 USB Serial
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0027
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower               98mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass      1 
      bInterfaceProtocol      2 
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval               1
Device Status:     0x0000
  (Bus Powered)

Dmitri.

dasergatskov commented 7 months ago

And after some un-pluging and pluging back it works: (I think I did not run arduinosetup corectly first time.)

octave:3> a = arduino ("/dev/ttyUSB0","","Debug", 1, "Baudrate", 9600)
>> 165 0 1 0 
<< 165 0 1 7 
<< 30 149 15 0 50 5 0 
>> 165 0 8 1 0 
<< 165 0 8 5 
<< 0 67 111 114 101 
>> 165 0 8 1 1 
<< 165 0 8 4 
<< 1 73 50 67 
>> 165 0 8 1 2 
<< 165 0 8 4 
<< 2 83 80 73 
>> 165 0 8 1 3 
<< 165 0 8 6 
<< 3 83 101 114 118 111 
>> 165 0 8 1 4 
<< 165 0 8 14 
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114 
a =

  arduino object with fields of: 
            port = /dev/ttyUSB0
           board = uno
       libraries = {
              i2c
              spi
              servo
              shiftregister
        }
        availablepins = {
              d0 - d13
              a0 - a5
        }
       config = 
    board = uno
    baudrate = 9600
    mcu = atmega328p
    voltref = 5
    libs =
    {
      [1,1] =

        scalar structure containing the fields:

          id = 0
          name = core

      [1,2] =

        scalar structure containing the fields:

          id = 1
          name = i2c

      [1,3] =

        scalar structure containing the fields:

          id = 2
          name = spi

      [1,4] =

        scalar structure containing the fields:

          id = 3
          name = servo

      [1,5] =

        scalar structure containing the fields:

          id = 4
          name = shiftregister

    }

    port = /dev/ttyUSB0
    description = Arduino Uno R3 Board
    pins =
    {
      [1,1] =

        scalar structure containing the fields:

          name = d0
          id = 0
          modes =
          {
            [1,1] = digital
            [1,2] = uart
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,2] =

        scalar structure containing the fields:

          name = d1
          id = 1
          modes =
          {
            [1,1] = digital
            [1,2] = uart
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,3] =

        scalar structure containing the fields:

          name = d2
          id = 2
          modes =
          {
            [1,1] = digital
            [1,2] = interrupt
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,4] =

        scalar structure containing the fields:

          name = d3
          id = 3
          modes =
          {
            [1,1] = digital
            [1,2] = pwm
            [1,3] = interrupt
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,5] =

        scalar structure containing the fields:

          name = d4
          id = 4
          modes =
          {
            [1,1] = digital
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,6] =

        scalar structure containing the fields:

          name = d5
          id = 5
          modes =
          {
            [1,1] = digital
            [1,2] = pwm
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,7] =

        scalar structure containing the fields:

          name = d6
          id = 6
          modes =
          {
            [1,1] = digital
            [1,2] = pwm
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,8] =

        scalar structure containing the fields:

          name = d7
          id = 7
          modes =
          {
            [1,1] = digital
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,9] =

        scalar structure containing the fields:

          name = d8
          id = 8
          modes =
          {
            [1,1] = digital
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,10] =

        scalar structure containing the fields:

          name = d9
          id = 9
          modes =
          {
            [1,1] = digital
            [1,2] = pwm
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,11] =

        scalar structure containing the fields:

          name = d10
          id = 10
          modes =
          {
            [1,1] = digital
            [1,2] = pwm
            [1,3] = spi0_ss
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,12] =

        scalar structure containing the fields:

          name = d11
          id = 11
          modes =
          {
            [1,1] = digital
            [1,2] = pwm
            [1,3] = spi0_mosi
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,13] =

        scalar structure containing the fields:

          name = d12
          id = 12
          modes =
          {
            [1,1] = digital
            [1,2] = pwm
            [1,3] = spi0_miso
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,14] =

        scalar structure containing the fields:

          name = d13
          id = 13
          modes =
          {
            [1,1] = digital
            [1,2] = pwm
            [1,3] = spi0_sck
            [1,4] = led
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,15] =

        scalar structure containing the fields:

          name = a0
          id = 14
          modes =
          {
            [1,1] = digital
            [1,2] = analog
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,16] =

        scalar structure containing the fields:

          name = a1
          id = 15
          modes =
          {
            [1,1] = digital
            [1,2] = analog
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,17] =

        scalar structure containing the fields:

          name = a2
          id = 16
          modes =
          {
            [1,1] = digital
            [1,2] = analog
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,18] =

        scalar structure containing the fields:

          name = a3
          id = 17
          modes =
          {
            [1,1] = digital
            [1,2] = analog
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,19] =

        scalar structure containing the fields:

          name = a4
          id = 18
          modes =
          {
            [1,1] = digital
            [1,2] = analog
            [1,3] = i2c_sda
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

      [1,20] =

        scalar structure containing the fields:

          name = a5
          id = 19
          modes =
          {
            [1,1] = digital
            [1,2] = analog
            [1,3] = i2c_scl
          }

          owner = 
          mode = unset
          altnames = {}(0x0)

    }

    flags = 0
dasergatskov commented 7 months ago

also can you provide the results of this script (rename to a .m file) testarduino.txt

Somewhat a side-note -- github does something funny to text files. I usually gzip them prior to attaching.

EkpuzC commented 7 months ago

An update on Redboard. The older Redboard (which uses FTDI chip) is intermittant in its ability to create an arduino object. I'd say that most of the time it fails with the Undersized packet header but I have also seen "Unimplemented feature". The Redboard that works uses the CH340C Serial-USB Converter and works very consistently.

The Elegoo board uses a 16u2 serial chip.

Here is a string of attempts to create an arduino object with the older Redboard (with the FTDI chip): One of them captured the Unimplemented feature error, and the last one was successful.

a=arduino('/dev/tty.usbserial-DN03GDV8','','Debug',0) error: initArduino: failed get lib 1 err=1 - Undersized packet header error: called from initArduino at line 114 column 12 arduino at line 221 column 14 a=arduino('/dev/tty.usbserial-DN03GDV8','','Debug',0) error: initArduino: failed valid response err=10 - Unimplemented feature error: called from initArduino at line 49 column 8 arduino at line 221 column 14 a=arduino('/dev/tty.usbserial-DN03GDV8','','Debug',1) 165 0 1 0 << 165 0 1 7 << 30 149 15 0 50 5 0 165 0 8 1 0 << 165 0 8 5 << 0 67 111 114 101 165 0 8 1 1 << 165 0 8 4 << 1 73 50 67 165 0 8 1 2 << 165 0 8 4 << 2 83 80 73 165 0 8 1 3 << 165 0 8 6 << 3 83 101 114 118 111 165 0 8 1 4 << error: initArduino: failed get lib 4 err=1 - Undersized packet header error: called from initArduino at line 114 column 12 arduino at line 221 column 14 a=arduino('/dev/tty.usbserial-DN03GDV8','','Debug',1) 165 0 1 0 << 165 0 1 7 << 30 149 15 0 50 5 0 165 0 8 1 0 << 165 0 8 5 << 0 67 111 114 101 165 0 8 1 1 << 165 0 8 4 << 1 73 50 67 165 0 8 1 2 << 165 0 8 4 << 2 83 80 73 165 0 8 1 3 << 165 0 8 6 << 3 83 101 114 118 111 165 0 8 1 4 << error: initArduino: failed get lib 4 err=1 - Undersized packet header error: called from initArduino at line 114 column 12 arduino at line 221 column 14 a=arduino('/dev/tty.usbserial-DN03GDV8','','Debug',1) 165 0 1 0 << error: initArduino: failed valid response err=1 - Undersized packet header error: called from initArduino at line 49 column 8 arduino at line 221 column 14 a=arduino('/dev/tty.usbserial-DN03GDV8','','Debug',1) 165 0 1 0 << 165 0 255 21 << 85 110 105 109 112 108 101 109 101 110 116 101 100 32 102 101 97 116 117 114 101 error: initArduino: failed valid response err=10 - Unimplemented feature error: called from initArduino at line 49 column 8 arduino at line 221 column 14 a=arduino('/dev/tty.usbserial-DN03GDV8','','Debug',1) 165 0 1 0 << 165 0 1 7 << 30 149 15 0 50 5 0 165 0 8 1 0 << 165 0 8 5 << 0 67 111 114 101 165 0 8 1 1 << 165 0 8 4 << 1 73 50 67 165 0 8 1 2 << 165 0 8 4 << 2 83 80 73 165 0 8 1 3 << 165 0 8 6 << 3 83 101 114 118 111 165 0 8 1 4 << 165 0 8 14 << 4 83 104 105 102 116 82 101 103 105 115 116 101 114 a =

arduino object with fields of: port = /dev/tty.usbserial-DN03GDV8 board = uno libraries = { i2c spi servo shiftregister } availablepins = { d0 - d13 a0 - a5 } config = board = uno baudrate = 9600 mcu = atmega328p voltref = 5 libs = { [1,1] =

    scalar structure containing the fields:

      id = 0
      name = core

  [1,2] =

    scalar structure containing the fields:

      id = 1
      name = i2c

  [1,3] =

    scalar structure containing the fields:

      id = 2
      name = spi

  [1,4] =

    scalar structure containing the fields:

      id = 3
      name = servo

  [1,5] =

    scalar structure containing the fields:

      id = 4
      name = shiftregister

}

port = /dev/tty.usbserial-DN03GDV8
description = Arduino Uno R3 Board
pins =
{
  [1,1] =

    scalar structure containing the fields:

      name = d0
      id = 0
      modes =
      {
        [1,1] = digital
        [1,2] = uart
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,2] =

    scalar structure containing the fields:

      name = d1
      id = 1
      modes =
      {
        [1,1] = digital
        [1,2] = uart
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,3] =

    scalar structure containing the fields:

      name = d2
      id = 2
      modes =
      {
        [1,1] = digital
        [1,2] = interrupt
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,4] =

    scalar structure containing the fields:

      name = d3
      id = 3
      modes =
      {
        [1,1] = digital
        [1,2] = pwm
        [1,3] = interrupt
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,5] =

    scalar structure containing the fields:

      name = d4
      id = 4
      modes =
      {
        [1,1] = digital
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,6] =

    scalar structure containing the fields:

      name = d5
      id = 5
      modes =
      {
        [1,1] = digital
        [1,2] = pwm
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,7] =

    scalar structure containing the fields:

      name = d6
      id = 6
      modes =
      {
        [1,1] = digital
        [1,2] = pwm
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,8] =

    scalar structure containing the fields:

      name = d7
      id = 7
      modes =
      {
        [1,1] = digital
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,9] =

    scalar structure containing the fields:

      name = d8
      id = 8
      modes =
      {
        [1,1] = digital
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,10] =

    scalar structure containing the fields:

      name = d9
      id = 9
      modes =
      {
        [1,1] = digital
        [1,2] = pwm
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,11] =

    scalar structure containing the fields:

      name = d10
      id = 10
      modes =
      {
        [1,1] = digital
        [1,2] = pwm
        [1,3] = spi0_ss
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,12] =

    scalar structure containing the fields:

      name = d11
      id = 11
      modes =
      {
        [1,1] = digital
        [1,2] = pwm
        [1,3] = spi0_mosi
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,13] =

    scalar structure containing the fields:

      name = d12
      id = 12
      modes =
      {
        [1,1] = digital
        [1,2] = pwm
        [1,3] = spi0_miso
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,14] =

    scalar structure containing the fields:

      name = d13
      id = 13
      modes =
      {
        [1,1] = digital
        [1,2] = pwm
        [1,3] = spi0_sck
        [1,4] = led
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,15] =

    scalar structure containing the fields:

      name = a0
      id = 14
      modes =
      {
        [1,1] = digital
        [1,2] = analog
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,16] =

    scalar structure containing the fields:

      name = a1
      id = 15
      modes =
      {
        [1,1] = digital
        [1,2] = analog
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,17] =

    scalar structure containing the fields:

      name = a2
      id = 16
      modes =
      {
        [1,1] = digital
        [1,2] = analog
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,18] =

    scalar structure containing the fields:

      name = a3
      id = 17
      modes =
      {
        [1,1] = digital
        [1,2] = analog
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,19] =

    scalar structure containing the fields:

      name = a4
      id = 18
      modes =
      {
        [1,1] = digital
        [1,2] = analog
        [1,3] = i2c_sda
      }

      owner =
      mode = unset
      altnames = {}(0x0)

  [1,20] =

    scalar structure containing the fields:

      name = a5
      id = 19
      modes =
      {
        [1,1] = digital
        [1,2] = analog
        [1,3] = i2c_scl
      }

      owner =
      mode = unset
      altnames = {}(0x0)

}

flags = 0

I'd estimate that about one fifth of the attempts to make an arduino object succeed. It seems pretty random but maybe is more likely to succeed if the board is reset before every attempt. In light of the intermittant nature of the old Redboard failing to create an arduino object, I tried the Elegoo board over and over. It never worked, but I did notice it tended to switch between two flavors of the "undersized packet header" error. One bing a "failed valid response" and the other being "failed get lib 0". Here is a string of those:

a=arduino('/dev/tty.usbmodem14201') error: initArduino: failed get lib 0 err=1 - Undersized packet header error: called from initArduino at line 114 column 12 arduino at line 133 column 16 a=arduino('/dev/tty.usbmodem14201') error: initArduino: failed valid response err=1 - Undersized packet header error: called from initArduino at line 49 column 8 arduino at line 133 column 16 a=arduino('/dev/tty.usbmodem14201') error: initArduino: failed valid response err=1 - Undersized packet header error: called from initArduino at line 49 column 8 arduino at line 133 column 16 a=arduino('/dev/tty.usbmodem14201') error: initArduino: failed valid response err=1 - Undersized packet header error: called from initArduino at line 49 column 8 arduino at line 133 column 16 a=arduino('/dev/tty.usbmodem14201') error: initArduino: failed valid response err=1 - Undersized packet header error: called from initArduino at line 49 column 8 arduino at line 133 column 16 a=arduino('/dev/tty.usbmodem14201') error: initArduino: failed get lib 0 err=1 - Undersized packet header error: called from initArduino at line 114 column 12 arduino at line 133 column 16 a=arduino('/dev/tty.usbmodem14201') error: initArduino: failed valid response err=1 - Undersized packet header error: called from initArduino at line 49 column 8 arduino at line 133 column 16 a=arduino('/dev/tty.usbmodem14201') error: initArduino: failed valid response err=1 - Undersized packet header error: called from initArduino at line 49 column 8 arduino at line 133 column 16

error: initArduino: failed valid response err=1 - Undersized packet header error: called from initArduino at line 49 column 8 arduino at line 133 column 16 a=arduino('/dev/tty.usbmodem14201') error: initArduino: failed get lib 0 err=1 - Undersized packet header error: called from initArduino at line 114 column 12 arduino at line 133 column 16 a=arduino('/dev/tty.usbmodem14201')

One more observation with the older Redboard (FTDI, intermittant success). I did a string of a = arduino('/dev/tty.usbserial-DN03GDV8','','Debug',1,'Baudrate',9600) and saw more variation in the errors:

a=arduino('/dev/tty.usbserial-DN03GDV8','','Debug',1,'Baudrate',9600) 165 0 1 0 << 165 0 1 7 << 30 149 15 0 50 5 0 165 0 8 1 0 << 165 0 8 5 << 0 67 111 114 101 165 0 8 1 1 << 165 0 8 4 << 1 73 50 67 165 0 8 1 2 << 165 0 8 4 << 2 83 80 73 165 0 8 1 3 << error: initArduino: failed get lib 3 err=1 - Undersized packet header error: called from initArduino at line 114 column 12 arduino at line 221 column 14 a=arduino('/dev/tty.usbserial-DN03GDV8','','Debug',1,'Baudrate',9600) 165 0 1 0 << 165 0 1 7 << 30 149 15 0 50 5 0 165 0 8 1 0 << 165 0 255 21 << 85 110 105 109 112 108 101 109 101 110 116 101 100 32 102 101 97 116 117 114 101 error: initArduino: failed get lib 0 err=10 - Unimplemented feature error: called from initArduino at line 114 column 12 arduino at line 221 column 14 a=arduino('/dev/tty.usbserial-DN03GDV8','','Debug',1,'Baudrate',9600) 165 0 1 0 << 165 0 1 7 << 30 149 15 0 50 5 0 165 0 8 1 0 << 165 0 255 21 << 85 110 105 109 112 108 101 109 101 110 116 101 100 32 102 101 97 116 117 114 101 error: initArduino: failed get lib 0 err=10 - Unimplemented feature error: called from initArduino at line 114 column 12 arduino at line 221 column 14

I have no idea if any of this might be diagnostic. If this sort of experimentation is not helpful and there is something else I could be trying, please let me know.

dasergatskov commented 7 months ago

Try running arduinosetup at octave prompt. Once it finish uploading, click check-mark icon ("Verify") on arduino ide. If you get an arduino console with

Missing FQBN (Fully Qualified Board Name)

Compilation error: Missing FQBN (Fully Qualified Board Name)

arduino_fail

message, select (from "Select Board" drop-down menu) "Arduno Uno" and appropriate port (/dev/ttyUSB0 Serial Port (USB) in my case). Then click righ-arrow ("Upload") button. Now I see on the console:

Sketch uses 13224 bytes (40%) of program storage space. Maximum is 32256 bytes.
Global variables use 1135 bytes (55%) of dynamic memory, leaving 913 bytes for local variables. Maximum is 2048 bytes.

arduino_OK

After that quit arduino-ide and run a = arduino ("/dev/ttyUSB0","","Debug", 1, "Baudrate", 9600) .

lostbard commented 7 months ago

In that testscript I provided, what happens if you change the serialport line to:

a = serialport (port, 'BaudRate', baud, 'Timeout', 0.2)

dasergatskov commented 7 months ago

In that testscript I provided, what happens if you change the serialport line to:

a = serialport (port, 'BaudRate', baud, 'Timeout', 0.2)

If I do it in "bad" state:

octave:1> pkg load arduino
octave:2> a = arduino ("/dev/ttyUSB0","","Debug", 1, "Baudrate", 9600)
>> 165 0 1 0 
<<  
error: __initArduino__: failed valid response err=1 - Undersized packet header
error: called from
    __initArduino__ at line 49 column 8
    arduino at line 221 column 14
octave:3> testarduino
port = /dev/ttyUSB0
baud = 9600
Serial port test 1 --------------------
a =

  Serial Port Object Serial-/dev/ttyUSB0
    Port:     /dev/ttyUSB0
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

ans =

  scalar structure containing the fields:

    CarrierDetect = 0
    ClearToSend = 0
    DataSetReady = 0
    RingIndicator = 1

>> 165 0 1 0 
len = 4
<<  
Undersized packet header
Serial port test 2 --------------------
a =

  Serial Port Object Serial-/dev/ttyUSB0
    status:   open
    port:     /dev/ttyUSB0
    baudrate: 9600
    parity:   None
    bytesize: 8
    stopbits: 1
    timeout:  20

requesttosend = on
dataterminalreay = on
>> 165 0 1 0 
len = 4
<<  
Undersized packet header

After switching to "good" state (using the procedure described above):

octave:5> a = arduino ("/dev/ttyUSB0","","Debug", 1, "Baudrate", 9600)
>> 165 0 1 0 
<< 165 0 1 7 
<< 30 149 15 0 50 5 0 
>> 165 0 8 1 0 
<< 165 0 8 5 
<< 0 67 111 114 101 
>> 165 0 8 1 1 
<< 165 0 8 4 
<< 1 73 50 67 
>> 165 0 8 1 2 
<< 165 0 8 4 
<< 2 83 80 73 
>> 165 0 8 1 3 
<< 165 0 8 6 
<< 3 83 101 114 118 111 
>> 165 0 8 1 4 
<< 165 0 8 14 
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114 
a =

  arduino object with fields of: 
...<deleted>...
octave:6> testarduino
port = /dev/ttyUSB0
baud = 9600
Serial port test 1 --------------------
a =

  Serial Port Object Serial-/dev/ttyUSB0
    Port:     /dev/ttyUSB0
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

ans =

  scalar structure containing the fields:

    CarrierDetect = 0
    ClearToSend = 0
    DataSetReady = 0
    RingIndicator = 1

>> 165 0 1 0 
len = 4
<< 165 0 1 7 
<< 30 149 15 0 50 5 0 
Serial port test 2 --------------------
a =

  Serial Port Object Serial-/dev/ttyUSB0
    status:   open
    port:     /dev/ttyUSB0
    baudrate: 9600
    parity:   None
    bytesize: 8
    stopbits: 1
    timeout:  20

requesttosend = on
dataterminalreay = on
>> 165 0 1 0 
len = 4
<< 165 0 1 7 
<< 30 149 15 0 50 5 0 
octave:7> 
lostbard commented 7 months ago

ok - so once its in a 'good' state, it is forever ? and in can unplug and plug back in and still works ?

dasergatskov commented 7 months ago

ok - so once its in a 'good' state, it is forever ? and in can unplug and plug back in and still works ?

At least for some time. But I can switch it back to "bad" mode if e.g. I run (outside octave) ardunio-ide and upload say "Blink" demo from Examples.

EkpuzC commented 7 months ago

I don't think @dasergatskov is having the same issue as me. When I do arduinosetup I routinely select the board and I can verify that the board works in octave on a Windows machine. Verifying in the Arduino IDE before doing a successful upload doesn't do anything for either of the boards that tend to not work. To me, the behavior described by dasergotskov is consistent with the Octave/Arduino code being present or not present on the board. My issue is that my mac, and another I tested (I think the OS was Verona) can't make the arduino object on some boards--even when they've been properly programmed with arduinosetup.

I'll try the modified timeout value when I get a chance.

Again, I really appreaciate everyone's efforts to solve this issue. I just hope it is not me doing something incorrectly.

EkpuzC commented 7 months ago

Here are the results of re-running the testscript with the timeout value changed to 0.2. (first with the older FTDI Redboard, then with the Elegoo):

testScriptRB

port = /dev/tty.usbserial-DN03GDV8 baud = 9600 Serial port test 1 -------------------- a =

Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8 Port: /dev/tty.usbserial-DN03GDV8 BaudRate: 9600 Parity: None DataBits: 8 StopBits: 1 Timeout: 0.2

ans =

scalar structure containing the fields:

CarrierDetect = 0
ClearToSend = 0
DataSetReady = 0
RingIndicator = 1

165 0 1 0 len = 4 << 165 0 1 7 << 30 149 15 0 50 5 0 Serial port test 2 -------------------- a =

Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8 status: open port: /dev/tty.usbserial-DN03GDV8 baudrate: 9600 parity: None bytesize: 8 stopbits: 1 timeout: 20

requesttosend = on dataterminalreay = on

165 0 1 0 len = 4 << 165 0 1 7 << 30 149 15 0 50 5 0 clc testScriptRB port = /dev/tty.usbserial-DN03GDV8 baud = 9600 Serial port test 1 -------------------- a =

Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8 Port: /dev/tty.usbserial-DN03GDV8 BaudRate: 9600 Parity: None DataBits: 8 StopBits: 1 Timeout: 0.2

ans =

scalar structure containing the fields:

CarrierDetect = 0
ClearToSend = 0
DataSetReady = 0
RingIndicator = 1

165 0 1 0 len = 4 << 165 0 1 7 << 30 149 15 0 50 5 0 Serial port test 2 -------------------- a =

Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8 status: open port: /dev/tty.usbserial-DN03GDV8 baudrate: 9600 parity: None bytesize: 8 stopbits: 1 timeout: 20

requesttosend = on dataterminalreay = on

165 0 1 0 len = 4 << 165 0 1 7 << 30 149 15 0 50 5 0

testScript port = /dev/tty.usbmodem14201 baud = 9600 Serial port test 1 -------------------- a =

Serial Port Object Serial-/dev/tty.usbmodem14201 Port: /dev/tty.usbmodem14201 BaudRate: 9600 Parity: None DataBits: 8 StopBits: 1 Timeout: 0.2

ans =

scalar structure containing the fields:

CarrierDetect = 0
ClearToSend = 0
DataSetReady = 0
RingIndicator = 1

165 0 1 0 len = 4 << 165 0 1 7 << 30 149 15 0 50 5 0 Serial port test 2 -------------------- a =

Serial Port Object Serial-/dev/tty.usbmodem14201 status: open port: /dev/tty.usbmodem14201 baudrate: 9600 parity: None bytesize: 8 stopbits: 1 timeout: 20

requesttosend = on dataterminalreay = on

165 0 1 0 len = 4 << 165 0 1 7 << 30 149 15 0 50 5 0

lostbard commented 7 months ago

perhaps weird that on your problem board, running with debug for the arduin call fails to get data response from the first message sent of 165 0 1 0, yet the test script never seems to have any problem

EkpuzC commented 7 months ago

The test script is only making serialport objects, not an arduino object. Serialports seem to work fine. Perhaps you've replicated the exact steps that happen in initArduino in which case it would be puzzling why one works but the other doesn't. I've tried to make sense of everything that is happening in arduino.m, initArduino.m, sendCommand.m, sendCommand.m, recvResponse.m, etc., but I think I'm rusty with classes in general and have never worked with them in Octave so I can't follow what is going on with confidence.

I did notice these lines in recvResponse

# TODO: current serial doesnt have a way to know if any data is awaiting
# so try read what we need first without waiting ?

   # read in initial part
   [tmpdataOut, tmpdataSize] = fread (dev, 4);
   if (debug)
     printf("<< "); printf("%d ", tmpdataOut); printf("\n");
   endif
   if tmpdataSize < 4
     errcode = 1;
     dataOut = "Undersized packet header";
   elseif tmpdataOut(1) != hex2dec("A5") || tmpdataOut(2) != libid || (tmpdataOut(3) != cmd && tmpdataOut(3) < 253)
     errcode = 2;
     dataOut = "Malformed packet header";

Could the TODO somehow be relevant?

EkpuzC commented 7 months ago

@lostbard I think I see what you did with your test script (it looks like you are replicating what happens when making an arduino object)--maybe I'll try to do something similar to get more familiar with the code and be better able to do some experimentation.

lostbard commented 7 months ago

yeah it duplicates (somewhat) the start of the arduin initialization.

I was going to create a more indepth script to do get closer as well.

lostbard commented 7 months ago

The test script is only making serialport objects, not an arduino object. Serialports seem to work fine. Perhaps you've replicated the exact steps that happen in initArduino in which case it would be puzzling why one works but the other doesn't. I've tried to make sense of everything that is happening in arduino.m, initArduino.m, sendCommand.m, sendCommand.m, recvResponse.m, etc., but I think I'm rusty with classes in general and have never worked with them in Octave so I can't follow what is going on with confidence.

I did notice these lines in recvResponse

# TODO: current serial doesnt have a way to know if any data is awaiting
# so try read what we need first without waiting ?

   # read in initial part
   [tmpdataOut, tmpdataSize] = fread (dev, 4);
   if (debug)
     printf("<< "); printf("%d ", tmpdataOut); printf("\n");
   endif
   if tmpdataSize < 4
     errcode = 1;
     dataOut = "Undersized packet header";
   elseif tmpdataOut(1) != hex2dec("A5") || tmpdataOut(2) != libid || (tmpdataOut(3) != cmd && tmpdataOut(3) < 253)
     errcode = 2;
     dataOut = "Malformed packet header";

Could the TODO somehow be relevant?

That was what i initially thought may be happending and yet the test script works.

fread (dev, 4); will wait fpr the objects timeout time before returning, (set in that function by) set(dev, "timeout", timeout);

You could try
set(dev, "timeout", 5);

lostbard commented 7 months ago

How about testarduinoconnect.txt

EkpuzC commented 7 months ago

Running that on the older Redboard gave varying results, while running it on the Elegoo gave a more consistent error. I think these are in keeping with their behavior with creating an arduino object.

> T2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<<
Undersized packet header
Init arduino done ---------------
>> T2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> T2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<<
Undersized packet header
>> 165 0 8 1 4
<< 165 0 255 21
<< 85 110 105 109 112 108 101 109 101 110 116 101 100 32 102 101 97 116 117 114 101
lib: nimplemented feature
Init arduino done ---------------
>> T2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> T2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> T2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<<
Undersized packet header
Init arduino done ---------------
>>

Now try Elegoo board

>> T2

port = /dev/tty.usbmodem14201
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbmodem14201
    Port:     /dev/tty.usbmodem14201
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<<
Undersized packet header
Error: res(4): out of bound 0 (dimensions are 0x0)
>> T2

port = /dev/tty.usbmodem14201
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbmodem14201
    Port:     /dev/tty.usbmodem14201
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<<
Undersized packet header
Error: res(4): out of bound 0 (dimensions are 0x0)
>> T2

port = /dev/tty.usbmodem14201
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbmodem14201
    Port:     /dev/tty.usbmodem14201
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<<
Undersized packet header
Error: res(4): out of bound 0 (dimensions are 0x0)
>>

Finally, testing the newer Redboard (the one that always works) gives:

>> T2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-1420
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-1420
    Port:     /dev/tty.usbserial-1420
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>>

I haven't studied the code to see what is different from before, but whatever you've done, I think it may have captured the essential bits that replicate the problem. That seems like progress!

Again, I really appreciate your efforts here!

EkpuzC commented 7 months ago

I'll have to do some more experimentation to be sure as I'm not very experienced with using the debugger, but I think single stepping through the recent test code with the Elegoo board results in it going past the usual place where it ends. Maybe this points to a timing issue (which I believe you probably suspected with your changes to the timeout value).

I just put in a pause(.2) after the len = fwrite(a,msg); line, and I think the Elegoo board went all the way through normally.

I'm writing this on my PC so I'll switch to the Mac and give more details.

EkpuzC commented 7 months ago

Here is a snippet of the modified code:

   printf(">> "); printf("%d ", msg); printf("\n");
   len = fwrite(a, msg);
   pause(.2)
   set(a, "timeout", rt);

And here is the output:

>> TwPause

port = /dev/tty.usbmodem14201
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbmodem14201
    Port:     /dev/tty.usbmodem14201
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> TwPause
port = /dev/tty.usbmodem14201
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbmodem14201
    Port:     /dev/tty.usbmodem14201
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>>

The older Redboard seems to also work consistently with that pause added. I haven't tested to see how small of a pause will do the trick, but I hope that this might help figure out what is going on and how to fix it.

EkpuzC commented 7 months ago

I thought it might be interesting to try to examine the official Arduino IDE source code to see if it is obvious what they do to avoid the timing issue. However, I'm a github novice and could not identify anything that looked like source code in https://github.com/arduino/arduino-ide/tree/main

lostbard commented 7 months ago

cool that we now have a single file that seems to mimic the behaviour - yes I am wondering on timeout

rather than adding a pause, what happens if readtimeout is set to a bigger value ? say 2.0 ?

EkpuzC commented 7 months ago

Increasing readtimeout doesn't seem to have any effect (I went up to 5). The pause I put in can be as small as 0.03 and the test code seems to work robustly on the Elegoo board. After doing that, it still works even with readtimeout set to 0.001. I don't know much about USB communication hardware and protocols, but it doesn't look like a timeout problem. I've heard of Mac USB3 ports not working well with USB2 devices (not sure why) with a solution to have the right kind of hub that can handle the interface between the two. I don't have anything like that so I can't tell if there is a simple hardware fix. I think it would be nice to understand fundamentally what is responsible, but in the meantime, maybe a workaround for users experiencing this issue would be to put in the mystery pause in the right place. One thing that I wonder is if creating the arduino object is unique, or would the normal communications to interact with the Arduino also be prone to the same sort of errors?

Anyway, for chuckles I tried buting a pause(.2 to 5) at the beginning of the fread function. I don't know if initarduino is using fread in the same way as the test program, but it didn't work. Still got exactly the same error. I also tried putting into recvResponse and that did not have any effect either.

lostbard commented 7 months ago

Out of curiosity, running this scipt testtimeout.txt

DOes it pause around 10 seconds between the Waiting and Done prints ?

EkpuzC commented 7 months ago

Yes, there is about 10 seconds betwen Waiting and Done.

lostbard commented 7 months ago

and if add:

fwrite(a, "TEST")

just before the settimeout line ?

lostbard commented 7 months ago

also an updated testarduinoconnect to try testarduinoconnect2.txt

EkpuzC commented 7 months ago

Adding fwrite(a,"TEST") didn't seem to change anything.

The new script with the Elegoo gave:

>> testarduinoconnect2

port = /dev/tty.usbmodem14201
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbmodem14201
    Port:     /dev/tty.usbmodem14201
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<<
Undersized packet header
Error: res(4): out of bound 0 (dimensions are 0x0)
>>

And the older Redboard gave varied results, sometimes making it all the way through, and sometimes throwing an error:

 testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<<
Undersized packet header
>> 165 0 8 1 2
<< 165 0 255 21
<< 85 110 105 109 112 108 101 109 101 110 116 101 100 32 102 101 97 116 117 114 101
lib: nimplemented feature
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 255 21
<< 85 110 105 109 112 108 101 109 101 110 116 101 100 32 102 101 97 116 117 114 101
lib: nimplemented feature
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<<
Undersized packet header
>> 165 0 8 1 4
<< 165 0 255 21
<< 85 110 105 109 112 108 101 109 101 110 116 101 100 32 102 101 97 116 117 114 101
lib: nimplemented feature
Init arduino done ---------------
>>

I don't have time to study the code and experiment right now, but I do hope to keep making time to work on this. I'm heading into Finals Week so lots of grading to do.

lostbard commented 7 months ago

ok - so no change with either script ... i was hopeful but not surprised on results.

I think I have one change in instrument-control I could try, but need to take a look.

lostbard commented 7 months ago

A test instrument control to try instrument-control-0.9.2.tar.gz

EkpuzC commented 7 months ago

I hope I successfully installed the new instrument-control package. The results seem pretty similar to before, although I did observe (but did not save) at least one time where the old Redboard seemed to get stuck in an infinite loop of testing. I'll post in a sequence of tests that I just did and then I'll try again to replicate the infinite loop case.

First, the old Redboard:

>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<<
Undersized packet header
Init arduino done ---------------
>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<<
Undersized packet header
Error: res(4): out of bound 0 (dimensions are 0x0)
>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<<
Undersized packet header
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<<
Undersized packet header
>> 165 0 8 1 3
<< 165 0 255 21
<< 85 110 105 109 112 108 101 109 101 110 116 101 100 32 102 101 97 116 117 114 101
lib: nimplemented feature
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<<
Undersized packet header
Error: res(4): out of bound 0 (dimensions are 0x0)
>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<<
Undersized packet header
>> 165 0 8 1 3
<< 165 0 255 21
<< 85 110 105 109 112 108 101 109 101 110 116 101 100 32 102 101 97 116 117 114 101
lib: nimplemented feature
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>>

The Elegoo board seems to fail earlier, but also shows variability:

>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<<
Undersized packet header
Init arduino done ---------------
>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<<
Undersized packet header
Error: res(4): out of bound 0 (dimensions are 0x0)
>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<<
Undersized packet header
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<<
Undersized packet header
>> 165 0 8 1 3
<< 165 0 255 21
<< 85 110 105 109 112 108 101 109 101 110 116 101 100 32 102 101 97 116 117 114 101
lib: nimplemented feature
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<<
Undersized packet header
Error: res(4): out of bound 0 (dimensions are 0x0)
>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<<
Undersized packet header
>> 165 0 8 1 3
<< 165 0 255 21
<< 85 110 105 109 112 108 101 109 101 110 116 101 100 32 102 101 97 116 117 114 101
lib: nimplemented feature
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> testarduinoconnect2

port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 0.5000
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>>

I tried to reproduce the infinite loop behavior but couldn't. Basically, it seemed like it kept counting beyond the usual number of libraries. Like the 165 0 8 1 n sequence continued for n>4.

lostbard commented 7 months ago

Thanks for checking, it is perhaps reading more often?

Can you change the readtimeout to 2 and retry

The initial call in the test program for '165 0 1 0' isnt doing any error checking so may have returned 'unsuported' or something which would have then looked like a far bigger number for the lib count.

In the cases where we get a unimplmented feature right after a failed read, I can perhaps understand that if the arduino got some of the first request (not all so waiting on the full data), time out (since waiting) part of the next request - which ends up make a unknown command

Looking back at other attempts, each unimplmented feature error has occured after a undersized packet error, so is probally just a byproduct of whatever is going on.

Anyway, In theory the bigger read timeout with the new instrument control should be like doing the delay and then read, that previously seemed to work for you.

EkpuzC commented 7 months ago

I don't think the readtimeout=2 had much impact. old redboard:

port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 2
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> testarduinoconnect2
port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 2
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> testarduinoconnect2
port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 2
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<<
Undersized packet header
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> testarduinoconnect2
port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 2
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> testarduinoconnect2
port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 2
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<< 165 0 8 5
<< 0 67 111 114 101
lib: core
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<< 165 0 8 6
<< 3 83 101 114 118 111
lib: servo
>> 165 0 8 1 4
<< 165 0 8 14
<< 4 83 104 105 102 116 82 101 103 105 115 116 101 114
lib: shiftregister
Init arduino done ---------------
>> testarduinoconnect2
port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 2
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
<<  65 0 1 0
Undersized packet header
Error: res(4): out of bound 0 (dimensions are 0x0)
>> testarduinoconnect2
port = /dev/tty.usbmodem14201
port = /dev/tty.usbserial-DN03GDV8
baud = 9600
readtimeout = 2
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbserial-DN03GDV8
    Port:     /dev/tty.usbserial-DN03GDV8
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<< 165 0 1 7
<< 30 149 15 0 50 5 0
boardid = 0
voltref = 5
numlib = 5
>> 165 0 8 1 0
<<
Undersized packet header
>> 165 0 8 1 1
<< 165 0 8 4
<< 1 73 50 67
lib: i2c
>> 165 0 8 1 2
<< 165 0 8 4
<< 2 83 80 73
lib: spi
>> 165 0 8 1 3
<<
Undersized packet header
>> 165 0 8 1 4
<< 165 0 255 21
<< 85 110 105 109 112 108 101 109 101 110 116 101 100 32 102 101 97 116 117 114 101
lib: nimplemented feature
Init arduino done ---------------
>>

And with the Elegoo:

>> testarduinoconnect2

port = /dev/tty.usbmodem14201
baud = 9600
readtimeout = 2
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbmodem14201
    Port:     /dev/tty.usbmodem14201
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<<
Undersized packet header
Error: res(4): out of bound 0 (dimensions are 0x0)
>> testarduinoconnect2
port = /dev/tty.usbmodem14201
baud = 9600
readtimeout = 2
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbmodem14201
    Port:     /dev/tty.usbmodem14201
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<<
Undersized packet header
Error: res(4): out of bound 0 (dimensions are 0x0)
>> testarduinoconnect2
port = /dev/tty.usbmodem14201
baud = 9600
readtimeout = 2
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbmodem14201
    Port:     /dev/tty.usbmodem14201
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<<
Undersized packet header
Error: res(4): out of bound 0 (dimensions are 0x0)
>> testarduinoconnect2
port = /dev/tty.usbmodem14201
baud = 9600
readtimeout = 2
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbmodem14201
    Port:     /dev/tty.usbmodem14201
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<<
Undersized packet header
Error: res(4): out of bound 0 (dimensions are 0x0)
>> testarduinoconnect2
port = /dev/tty.usbmodem14201
baud = 9600
readtimeout = 2
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbmodem14201
    Port:     /dev/tty.usbmodem14201
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<<
Undersized packet header
Error: res(4): out of bound 0 (dimensions are 0x0)
>> testarduinoconnect2
port = /dev/tty.usbmodem14201
baud = 9600
readtimeout = 2
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbmodem14201
    Port:     /dev/tty.usbmodem14201
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<<
Undersized packet header
Error: res(4): out of bound 0 (dimensions are 0x0)
>> testarduinoconnect2
port = /dev/tty.usbmodem14201
baud = 9600
readtimeout = 2
Init arduino --------------------
a =

  Serial Port Object Serial-/dev/tty.usbmodem14201
    Port:     /dev/tty.usbmodem14201
    BaudRate: 9600
    Parity:   None
    DataBits: 8
    StopBits: 1
    Timeout:  0.2

cdata = [](0x0)
>> 165 0 1 0
<<
Undersized packet header
Error: res(4): out of bound 0 (dimensions are 0x0)
>>
>>

FYI, I tried putting the pause() back in before the fread in the send_cmd function, and it didn't seem to have a dramatic impact. Certainly did not make errors go away.

One thing I'm wondering is if the fundamental issue could be with the code on the Arduino board, rather than the Octave code communicating with it.

lostbard commented 7 months ago

for arduino code, its possible, however, same code regardless of whether its a redboard vs a real arduino, so should be have same on all ?

Ill take a look anyway, but in general its basically just looping around looking for serial data, and when it gets a full message, do whatever the command is and reponds back.

I guess one thing could try related to that, is program the arduino no additional modules and see if it behaves differently.

If you run arduinosetup, and then go to to settings.h file in the IDE and change:

define USE_SPI

define USE_I2C

define USE_SERVO

define USE_SHIFTREG

to

//#define USE_SPI //#define USE_I2C //#define USE_SERVO //#define USE_SHIFTREG

Then build and load that

lostbard commented 7 months ago

i guess also possibly related to code on the arduino, what version of the arduino baord software are you using ? (In boards manager on the IDE)