Author Topic: Moteino M0 Serial USB output not working after sleep  (Read 806 times)

moallen

  • NewMember
  • *
  • Posts: 12
Moteino M0 Serial USB output not working after sleep
« on: December 31, 2019, 06:26:57 PM »
I've searched the forum and see this issue has been discussed before, but I haven't found an explanation for my situation. Printing to the Moteino M0 USB Port works fine for me in simple sketches but not in more complex sketches. For example, the "Example periodic sleep using RTCZero library" sketch on the Moteino M0 guide doesn't print for me. I can tell the sketch is running, because the LED blinks every 3 seconds. But nothing prints.

If I change all the prints to Serial1 and connect those pins to a separate USB serial adapter on my computer, print works ok in "Example periodic sleep using RTCZero library". I'm sure this has nothing to do with that particular sketch. Right now I'm getting data from a bathroom scale using a HX711 loadcell amplifier. It has the same print issue. Works fine on Serial1 but not on the built-in USB port.

I'm running Windows 10 Pro on a HP ProBook. I'm using Arduino 1.8.10.


Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6531
  • Country: us
    • LowPowerLab
Re: Printing to Moteino M0 USB Port Not Working
« Reply #1 on: January 02, 2020, 12:51:31 PM »
Printing to the Moteino M0 USB Port works fine for me in simple sketches but not in more complex sketches. For example, the "Example periodic sleep using RTCZero library" sketch on the Moteino M0 guide doesn't print for me. I can tell the sketch is running, because the LED blinks every 3 seconds. But nothing prints.

If I change all the prints to Serial1 and connect those pins to a separate USB serial adapter on my computer, print works ok in "Example periodic sleep using RTCZero library".

While M0 is a much more powerful and complex processor than the basic AVRs, it also comes with a load of challenges.

In this case the problem boils down to the disabling of clocks and USB module. Ie breaking the USB link between M0 and PC/computer.
First of all, if the USB is disabled/detached, then even if you don't sleep, and the Serial monitor is kept open, the serial connection is lost and there is no more USB serial output. This problem doesn't exist with a traditional UART, that is why you always get the output directly from the pins because that "special" USB link is not broken.

So TLDR; would be: IMO you're better off with UART for logging purposes, it's simple and it works. Read below for more explanations.

When you sleep, even if the libs you use do not specifically disable or detach from USB, sleep code will turn off a lot of modules in the MCU to be able to achieve the low power sleep.

At this moment I'm not entirely sure if it's even possible to revive that USB connection after sleep mode, and continue to get serial via USB. From what I've read so far it's not possible and at least the IDE cannot do it. But I could be wrong and things might have changed recently. I would need to look at the DS and determine if there's a way to keep the clock domains running while also sleeping the rest of the MCU to ensure the USB link is not broken in any way and that after wakeup it is completely ready to continue serial output.

But in my own practice I haven't seen a case where the M0 is USB powered and you have to be worried about sleep current, while also requiring to keep a USB connection alive.

moallen

  • NewMember
  • *
  • Posts: 12
Re: Moteino M0 Serial USB output not working after sleep
« Reply #2 on: January 02, 2020, 02:08:09 PM »
Thanks - I thought that might be the case but wanted to verify I wasn't missing something. I'm in the habit of using print statements while troubleshooting a new program. But it's no problem to use an UART port instead of the USB port. I agree it wouldn't be very practical to use the sleep mode while attached to a USB com port in a live application.




ianraustralia

  • NewMember
  • *
  • Posts: 8
Re: Moteino M0 Serial USB output not working after sleep
« Reply #3 on: March 13, 2020, 01:59:46 AM »
Developing an application requiring MoteinoM0 to log its activity using UART Serial ...  and a sleep/wakeup cycle ... when my UART Serial log vanished after waking up!! Then I realised after a few RESETs it also would not report the setup() logging!

Yesterday after upgrading the board in Arduino IDE 1.8.12 to Felix's latest release Moteino SAMD V1.5.0  board, suddenly all my previously working UART logging stopped! ... I spent a couple of hours looking for what had happened, even programming other MoteinoM0's with the same code ... problem persisted, so not hardware I thought.

...then I remebered I had updated the board in the IDE the day before ... then I looked at Felix's  UPDATE page here: https://lowpowerlab.com/category/updates/

SerialUSB is now completely removed from the MoteinoM0 and CurrentRanger variant definitions:
On MoteinoM0 Serial is now the USB serial, Serial0 is the UART on pins 30/31, and Serial1 is the UART on pins 0/1.
On CurrentRanger Serial is now the USB serial.
SERIAL_PORT_USBVIRTUAL is now Serial by default


So for my pins 30/31 UART, I changed all the Serial.print and Serial.println code lines to Serial0.print and Serial0.println

All working fine now ... so just to save anyone else having this issue, I decided to post this experience.

Thanks Felix for the documentation.

arf

  • NewMember
  • *
  • Posts: 2
Re: Moteino M0 Serial USB output not working after sleep
« Reply #4 on: April 11, 2021, 12:50:49 PM »
Sorry, UART noob here.  To use Serial0 on the M0 as Ian described, I have some questions. 

1) Would I use a 6 pin FDTI adapter (like from the low power store below)?
2) If the moteino is being powered from a battery or the USB port, would I then only use the RX and TX pins of the FDTI adapter?
3) If I am not supposed to use the FDTI adapter with anything in the M0's usb port, I presume then I'd need to use all 6 pins of the FDTI connector.  I see where TX, RX, GND, and VCC go. but where does CTS and RTS connect to on the M0?

FDTI: https://lowpowerlab.com/shop/product/90
M0 Monteino: https://lowpowerlab.com/guide/moteino/moteinom0/