Feather MO Wifi - Can't connect to Serial Monitor

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
geobob
 
Posts: 3
Joined: Wed Sep 17, 2014 8:50 pm

Feather MO Wifi - Can't connect to Serial Monitor

Post by geobob »

Hi,
I have a new Adafruit Feather MO wifi. I've been working through your on-line tutorial to get it set up. I've been able to load and run the blink sketch. When I move to the next step, checking the connection and firmware, I run into problems because I get errors when I open the Serial Monitor. I've loaded the WiFi101 library and the CheckWiFi101FirmwareVersion sketch and inserted the code to identify the WiFi.setpins(8,7,4,2);

I can upload the sketch and by every indication it is running correctly on the Feather, but when I open the serial window I get an error:
Error opening serial port '/dev/ttyACM0'. (Port busy)

I created the simplest sketch I could devise to test the Serial Monitor and when I run it I get the same error.

void setup() {

Serial.begin(9600);
Serial.println("Bob talking here");
}

void loop() {
// Main Loop
}

I'm working on an Ubuntu machine running Ubuntu 16.04
I'm using the Arduino IDE 1.8.2

I've seen somewhat similar problems posted, but couldn't find any information directly applicable to my problem

Thanks

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Feather MO Wifi - Can't connect to Serial Monitor

Post by adafruit_support_mike »

The microcontroller for the M0 handles USB internally, and it takes a little while for it to open a USB connection and configure the Serial object when the code starts running. If you call Serial.begin() before that happens, it will fail silently.

You need to add something like this to the top of your setup() function:

Code: Select all

    while ( ! Serial ) { delay( 1 ); }
    Serial.begin( 9600 );
That will wait until Serial.begin() works properly.

Once you've added that, it's easy to forget it's there, and to wonder why your code doesn't work when you boot the Feather without a USB connection (it's waiting for a Serial connection, just like you've told it to).

This version uses a few more lines of code, but makes it easier to see what's happening:

Code: Select all

    void waitForSerial() {
        pinMode( 13, OUTPUT );
        while ( ! Serial ) { delay( 100 ); digitalWrite( 13, ! digitalRead( 13 )); }
        digitalWrite( 13, LOW );
    }

    void setup() {
        waitForSerial();
        Serial.begin( 9600 );
    }

User avatar
dcfusor
 
Posts: 39
Joined: Sun Nov 16, 2014 1:18 pm

Re: Feather MO Wifi - Can't connect to Serial Monitor

Post by dcfusor »

I am getting the exact same error on a feather m0 LORA board and this fix does NOT work.
If I select some wrong port in the ide after an upload, I can then use a terminal program (gtkterm) to see the serial port and that works, but that's rather a a pain.

In fact, just to re burn a sketch, it *never* works unless I both double click the reset button, deselect the proper serial port in the ide, reselect it, and only THEN click upload. 100% failure rate on all the other workarounds here and elsewhere that I have found. ~15% failure rate doing this - but I just get

Code: Select all

Sketch uses 10952 bytes (4%) of program storage space. Maximum is 262144 bytes.
Forcing reset using 1200bps open/close on port /dev/ttyACM0
PORTS {/dev/ttyACM0, /dev/ttyS0, /dev/ttyUSB0, } / {/dev/ttyACM0, /dev/ttyS0, /dev/ttyUSB0, } => {}
PORTS {/dev/ttyACM0, /dev/ttyS0, /dev/ttyUSB0, } / {/dev/ttyS0, /dev/ttyUSB0, } => {}
PORTS {/dev/ttyS0, /dev/ttyUSB0, } / {/dev/ttyS0, /dev/ttyUSB0, } => {}
PORTS {/dev/ttyS0, /dev/ttyUSB0, } / {/dev/ttyACM0, /dev/ttyS0, /dev/ttyUSB0, } => {/dev/ttyACM0, }
Found upload port: /dev/ttyACM0
/home/doug/.arduino15/packages/arduino/tools/bossac/1.7.0/bossac -i -d --port=ttyACM0 -U true -i -e -w -v /tmp/arduino_build_698249/M0workarounds.ino.bin -R 
Set binary mode
readWord(addr=0)=0x20007ffc
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
version()=v2.0 [Arduino:XYZ] Mar  5 2016 17:46:52
chipId=0x10010005
Connected at 921600 baud
readWord(addr=0)=0x20007ffc
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
Atmel SMART device 0x10010005 found
write(addr=0x20004000,size=0x34)
writeWord(addr=0x20004030,value=0x10)
writeWord(addr=0x20004020,value=0x20008000)
Device       : ATSAMD21G18A
readWord(addr=0)=0x20007ffc
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
Chip ID      : 10010005
version()=v2.0 [Arduino:XYZ] Mar  5 2016 17:46:52
Version      : v2.0 [Arduino:XYZ] Mar  5 2016 17:46:52
Address      : 8192
Pages        : 3968
Page Size    : 64 bytes
Total Size   : 248KB
Planes       : 1
Lock Regions : 16
Locked       : readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
none
readWord(addr=0x41004018)=0
Security     : false
Boot Flash   : true
readWord(addr=0x40000834)=0x7000a
BOD          : true
readWord(addr=0x40000834)=0x7000a
BOR          : true
Arduino      : FAST_CHIP_ERASE
Arduino      : FAST_MULTI_PAGE_WRITE
Arduino      : CAN_CHECKSUM_MEMORY_BUFFER
Erase flash
chipErase(addr=0x2000)
done in 5.005 seconds

Write 11208 bytes to flash (176 pages)
write(addr=0x20005000,size=0x1000)
writeBuffer(scr_addr=0x20005000, dst_addr=0x2000, size=0x1000)

[==========                    ] 36% (64/176 pages)write(addr=0x20005000,size=0x1000)
writeBuffer(scr_addr=0x20005000, dst_addr=0x3000, size=0x1000)

[=====================         ] 72% (128/176 pages)write(addr=0x20005000,size=0xc00)
writeBuffer(scr_addr=0x20005000, dst_addr=0x4000, size=0xc00)

[==============================] 100% (176/176 pages)

SAM-BA operation failed
done in 0.058 seconds

Verify 11208 bytes of flash with checksum.
checksumBuffer(start_addr=0x2000, size=0x1000) = f31c
checksumBuffer(start_addr=0x3000, size=0x1000) = 5eee
checksumBuffer(start_addr=0x4000, size=0xbc8) = 834c
Verify successful
done in 0.008 seconds
CPU reset.
readWord(addr=0)=0x20007ffc
readWord(addr=0xe000ed00)=0x410cc601
An error occurred while uploading the sketch
Known good cable, plugged into a USB2 hub on an intel NUC. (all of which work fine with all other boards)

Arduino 1.8.7
Mint 18.3, and 100% of all other arduino boards that I have (esp8266, 32, uno, teensy, etc) work fine.
Maybe a noob mistake but I'm no noob.

User avatar
dcfusor
 
Posts: 39
Joined: Sun Nov 16, 2014 1:18 pm

Re: Feather MO Wifi - Can't connect to Serial Monitor

Post by dcfusor »

Intuition on this one - and the apparent randomness with which any of this works (worst experience with an adafruit product EVER - and there's been a lot of them here) tells me it might be the fault of that "write once, debug everywhere" Java? I have openjdk 8...anyone have a clue if one of the numerous "identical but you're kidding, right?" other available JREs might make this work reliably with this port that comes and goes?

These are the other workaround that make things all seem ok sometimes - I still have to de and re select the port 100% of the time to get serial monitor to work, vs just deselecting it and using gtkterm for it to work.

I adapted the blink example and called it MO_Workarounds. I guess I could add a timeout on that "while (!Serial)" baloney as well?

Code: Select all

/*
  Blink

  Turns an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino
  model, check the Technical Specs of your board at:
  https://www.arduino.cc/en/Main/Products

  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Blink
*/


#include <stdio.h>

char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
  asm(".global _printf_float");

  char fmt[20];
  sprintf(fmt, "%%%d.%df", width, prec);
  sprintf(sout, fmt, val);
  return sout;
}
int i = 0;
float f = 3.1415927;
char fbuf[80];

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(13, OUTPUT);
  while ( ! Serial ) { delay( 100 );}  // @@@ remove for production code!
  Serial.begin(115200);
  sprintf (fbuf,"f=%.3f   ",f);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(50);                       // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
  Serial.println(fbuf);
  Serial.print ("i=");
  Serial.println (i);
  i++;
}

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Feather MO Wifi - Can't connect to Serial Monitor

Post by adafruit_support_mike »

The Linux USB stack has some known issues that interfere with the bootloader.

Try installing the udev rules linked from this tutorial page and see if that helps:

https://learn.adafruit.com/adafruit-fea ... e-fix-6-35

User avatar
dcfusor
 
Posts: 39
Joined: Sun Nov 16, 2014 1:18 pm

Re: Feather MO Wifi - Can't connect to Serial Monitor

Post by dcfusor »

Thanks Mike, that hammered the issues pretty decently.

This should probably get more prominent mention elsewhere (and on the linux mailing lists too?).
FWIW, I've not had this issue with other uPs that linux assigns to ttyACM#, just this one, which is why I didn't try that first.
(udev rules can be kind of chainsaw-like...)

One thing - if you've put in that while(!Serial) stuff - your sketch won't start now until you open the serial monitor or other program (like gtkterm), which is mentioned elsewhere on adafruit. The fix for me is to do this instead:

setup()
{
byte t = 0;
while(!Serial && t++ < 10) delay(1000); // curlies not needed for a one liner
Serial.begin (115200); // well, that's the speed I use here

// other stuff, of course
}

Which lets the sketch start in 10 seconds regardless. Obviously depends on what you want to happen.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”