Debugging USB

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
rpochet
Posts: 4
Joined: 14 Jun 2016 22:30

Debugging USB

Post by rpochet »

Hi,

I try to use USB Debugging to test my sketch.
Arduino 1.6.5-rc5
Ubuntu 16.04 LTS
PC <> Z-UNO: USB cable

I'm using the following sketch:

Code: Select all

#include "Wire.h"

// LED pin number
// 13 pin - user LED of Z-Uno board
#define LED_PIN 13

void setup() {
    Serial.begin();
    Serial.println("starting!");
    pinMode(LED_PIN, OUTPUT);
    digitalWrite(LED_PIN, HIGH);
    delay(20000);
    
    Serial.println("setup done!");
    digitalWrite(LED_PIN, LOW);
}
    
void loop() {
    Serial.println("loop");
    digitalWrite(LED_PIN, HIGH);
    delay(2000);
    digitalWrite(LED_PIN, LOW);
    delay(2000);
}
No log is displayed inside the setup method.
Port "switch" between /dev/ttyACM0 and /dev/ttyACM1

1. Upload sketch (Port selected: /dev/ttyACM0)
2. Restart (Port selected: /dev/ttyACM0)
3. Setup method ends (No port selected, /dev/ttyACM1 available)
4. Select port /dev/ttyACM1
5. Open serial monitor: Log "loop" OK
6. Reset Z-Uno
7. Setup method ends (No port selected, /dev/ttyACM0 available)
8. Select port /dev/ttyACM1
9. Open serial monitor: Log "loop" OK

Is it the correct behaviour in this use case?
Any idea?

R.
rpochet

Jeedom on RPI 3
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

Re: Debugging USB

Post by petergebruers »

I can confirm this behaviour, on a windows PC, so the fact that it does not print in setup() is probably a firmware issue. I noticed this behavior a while ago, but I forgot to report it. It might have worked on an older firmware, I cannot remember, I am on 2.1.1 now. But I do know, it does not depend on which serial you select. At the moment, I am using Serial1 and it does not print from setup() either. I do not have a workaround, I just got used to it...
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: Debugging USB

Post by p0lyg0n1 »

Hi, you can't see the output of the Serial in setup() because it's a native USB port and it goes to reboot with the Z-Uno, but Serial0/Serial1 + UART2USB have to work properly for debug. It's more comfortable way to use UART0 for debug purposes. Use external software to look for the output of Serial0. It could be CoolTerm/picocom or something like it. You can select logging of the system events to UART0 too. Please look to the menu Tools->Logging->UART0. It's available since 2.1.1.
I checked Serial1 and it works on 2.1.1 in setup() as expected.
Could you double check this Peter? If you can't see the output to Serial1 in setup() it's very strange.
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

Re: Debugging USB

Post by petergebruers »

You are absolutely right. Not that I ever doubted that ;)

Serial0 and Serial1 do print from setup(). Sorry if I have caused confusion...

I do not know why I thought they didn't. It's probably my memory, because I use macro's to print and so it is very unlikely for me to select the "wrong Serial" only in setup(), then use the "good Serial" in loop()...

Code: Select all

 CODE SNIPET (edited)
 
 // ****** DEBUGGING HELPER MACROS  BEGIN ****** //

#define PG_DEBUG_OUT 10

#if PG_DEBUG_OUT == 10
#define PG_DEBUG_OUT_SER Serial0

#elif PG_DEBUG_OUT == 11
#define PG_DEBUG_OUT_SER Serial1

#elif PG_DEBUG_OUT == 99
#define PG_DEBUG_OUT_SER Serial

.... some more definitions

#define PG_DEBUG_PRN(...) PG_DEBUG_OUT_SER.print(__VA_ARGS__)

.... some more definitions

void setup() {
 .... stuff to do
 
  PG_DEBUG_PRN("Setup done\n");
}
So, in conclusion, only USB does not print from setup()

But because it doesn't print in that particular case, and I want to have the option to print to any possible port, I am going to avoid printing from setup() anyway... So as not to confuse myself or other users...
Post Reply