Author Topic: Arduino IDE issues using Moteino M0 [explained]  (Read 17859 times)

gbsmith

  • NewMember
  • *
  • Posts: 7
Arduino IDE issues using Moteino M0 [explained]
« on: August 03, 2018, 04:10:15 PM »
I have not used the samd21 chip before so maybe this not just a Moteino M0 issue.

The Moteino M0 does not maintain a stable USB port number for uploading Arduino sketches.

The Moteino M0 will drop the USB connection just before downloading starts  The IDE
says to do a hardware reset.  OK.  Now the Moteino M0 enters boot loader mode and
changes the port number.  The download now works but the Moteino M0 switches back to
the original port number after the download finishes. 
Before opening the IDE serial monitor I have to switch the port number back again.

Sometimes I have to re-plugin the USB connection to restart the whole process again.

My application uses the SerialUSB serial port so maybe there is a conflict?
Is there any way to stabilize this development environment?
I did not see this using a ESP8266 based Node MCU board.
« Last Edit: August 06, 2018, 02:06:41 PM by Felix »

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Arduino IDE issues using Moteino M0
« Reply #1 on: August 03, 2018, 06:34:29 PM »
Sparkfun hookup guide (https://learn.sparkfun.com/tutorials/samd21-minidev-breakout-hookup-guide/troubleshooting) on their M0 processor explains the sequence you need to follow to download programs to the M0 and then use the Serial port for debugging.

UPDATE: Zeroed in on troubleshooting guide...
« Last Edit: August 04, 2018, 11:21:06 AM by TomWS »

gbsmith

  • NewMember
  • *
  • Posts: 7
Re: Arduino IDE issues using Moteino M0
« Reply #2 on: August 03, 2018, 07:39:10 PM »
I tried a Blink sketch with Serial to a FDTI adapter and the SerialUSB to the IDE serial port.
No problem.  I could upload 3 times without losing the USB connection.
When I went back to my MySensors sketch and it uploaded once OK.
For subsequent uploads the USB connection is dropped just before the upload starts
and I have to use the boot loader where the USB port number changes as described in my first post.

I suspect that there is a problem with the Mysensors.h library that I am using.  It must be messing with the SerialUSB port since it uses it for debug messages even though they are turned OFF.
Time to report this to the MySensors forum  ;D

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Arduino IDE issues using Moteino M0
« Reply #3 on: August 06, 2018, 02:06:23 PM »
There is always confusion about the serial devices on this apparently very complex ARM Cortex M0+ microcontroller.
The following applies for Moteino M0 as it is defined in the current Arduino board package definition.

The USB device on the M0 is just like any other hardware device (SPI, I2C, Serial, RTC, etc).
It requires to be ENABLED (ie. via SerialUSB.begin(baud does not matter)) - this causes the USB to enumerate the board as a USB serial device.
For it to accept a new sketch from the IDE, the MCU also has to be awake, not sleeping, or else the board will enumerate/show as a serial device but it will not be active and will not respond to serial commands. Sometimes, depending what your sketch does, if the MCU is busy burning cycles doing other things, it will not respond to the IDE's "hey I have a new sketch for you" call. In these cases you will have to manually reset the board, and put it in bootloader mode by double-tapping the onboard button.

The bootloader does this and emulates 1 serial port via the USB, and when it jumps to the sketch - if any and if that sketch has SerialUSB enabled - it will enumerate another new serial Port.

Otherwise, if SerialUSB.begin is not called or USB is specifically disabled (ex. during deep sleep), the D- and D+ lines are simply 2 GPIO pins that don't do anything and your PC will not recognize the board as any type of device.

It's also worth mentioning there are 2 additional GPIO serial devices available on the Moteino M0 (Serial on pins 30,31, and Serial1 on pins 0,1).
« Last Edit: August 06, 2018, 02:27:42 PM by Felix »

gbsmith

  • NewMember
  • *
  • Posts: 7
Re: Arduino IDE issues using Moteino M0 [explained]
« Reply #4 on: August 06, 2018, 06:55:38 PM »
This makes sense.  If I had a SerialUSB.begin() statement in my previous sketch the COM port was stable.
For my final sketch I want to save power and comment out this statement.
This is when the strange port behavior occurs.
With the MySensors.h library examples they don't have a SerialUSB.begin() statement .

ianraustralia

  • NewMember
  • *
  • Posts: 9
Re: Arduino IDE issues using Moteino M0 [explained]
« Reply #5 on: January 28, 2019, 06:57:44 PM »
I installed FTDI VCP drivers on my win10 laptop from here:     https://www.ftdichip.com/Drivers/VCP.htm     to fix this issue with my dev setup.

Previously I had the 2006 Microsoft USB driver installed.
Previously I had to manually always re-select the Port  before every sketch upload. :(

Now the Arduino IDE automatically selects the MoteinoM0 Port number attached to my laptop using the FTDI cable, with no action by me. :)

May be helpful to others. See image below from Device Manager screen after the FTDI driver  was installed.
« Last Edit: January 28, 2019, 07:01:15 PM by ianraustralia »