Serial.print not working on Xenon

xenon
Tags: #<Tag:0x00007fe225f890f8>

#1

Still some trouble with basic USB serial functionality on the Xenon. FWIW it’s on firmware version 1.4.0. Using the Arduino IDE as a basic terminal program, I can enter ‘i’ and the Xenon happily identifies itself, however Serial.println() does nothing. The sample code in the SDK looks like this:

// EXAMPLE USAGE
void setup()
{
  Serial.begin(9600);   // open serial over USB
  // On Windows it will be necessary to implement the following line:
  // Make sure your Serial Terminal app is closed before powering your device
  // Now open your Serial Terminal!
  while(!Serial.isConnected()) Particle.process();

  Serial1.begin(9600);  // open serial over TX and RX pins

  Serial.println("Hello Computer");
  Serial1.println("Hello Serial 1");
}

I can cut and paste this sample, compile, and flash, and … nothing. Though ‘i’ still works. Thinking that perhaps my “Hello Computer” was getting swallowed, I added:

// loop() runs over and over again, as quickly as it can execute.
void loop() {
  Serial.println("Hello Computer");
}

…to no avail. Suggestions?


#2

Although you don’t explicitly state it from your info that the device reacts to the i command sent via Serial Terminal I suspect your device is still blinking blue (aka Listening/Setup Mode) and consequently the behaviour that you don’t see your serial print output is not surprising as your code is not running in Listening Mode.

Have you got a gateway device (Argon, Boron or Xenon with EtherWing) that creates a mesh network to which your Xenon can connect?


#3

Hi, @ScruffR - Thanks for replying again. Nope. I’m just working out the basics of some sensor code. If I can, I’d like to avoid all the wireless business for now. Have I unknowingly chosen the much harder path? Coming from an Arduino background, Serial.* is sort of the last thing I expected to stumble over.

As you say, the blue light is blinking. Despite that flashing of the code is (supposedly) successful, the device enters listening mode when powered on or reset. So if that means my code isn’t running, I’m obviously missing some extremely basic steps here. :-/


#4

Ack! Just spotted this:
https://docs.particle.io/support/particle-devices-faq/mesh-setup-over-usb/#marking-setup-done

Perhaps this is my answer. Giving it a shot now…


#5

Since these are first of all meant to be IoT devices they will by default try to connect to the big I and if they can’t they won’t be very happy executing your code (default SYSTEM_MODE(AUTOMATIC) blocks code execution till the cloud connection is established).
If you don’t want that you need to tell it that via code.

Slap these two lines of code at the top of your sketch and try again (after you maked it as “setup done”)

SYSTEM_MODE(MANUAL)
SYSTEM_THREAD(ENABLED)

#6

Thanks @ScruffR. Done and working!

Yeah, the ultimate goal is for the thing to be connected, of course, but I suspect it will be much easier for me to develop and debug the sensor code over a wire, so I’m glad to have that working first.

I did one project with a Photon sometime last year and don’t recall jumping through any unusual hoops to realize USB functionality, but of course that’s a different device, and other stuff has surely changed as well.


#7

I’m pretty sure you had to use non-AUTOMATIC and/or SYSTEM_THREAD(ENABLED) on the Photon for the exact same reasons too :wink:


#8

@ScruffR, thinking back, I believe I went through the web setup for the Photon straight off, as there was no requirement of a hub. I definitely didn’t connect the two at the time, but that obviously would have enabled the USB.

Hindsight == 20/20