Can't get Serial Monitor over wifi to work

Yun connected to Mac running OS X. I can run Blink and everything works. I tried switching Serial to Console and that works on some sketches but not all. Serial never works. i keep getting
Unable to connect: retrying (1)...
Unable to connect: retrying (2)...
Unable to connect: retrying (3)...
Unable to connect: retrying (4)...
Unable to connect: is the sketch using the bridge?

I searched and saw adding
while (!Serial) {}

was supposed to help but didn't. Also tried several other things. i am down to just a Hello World to see if i can get anything over serial. no luck. Here is my sketch.

#include <Console.h>

void setup() {
Serial.begin(115200);
while (!Serial); {}

Serial.print("Hello World");
}

void loop() {
// put your main code here, to run repeatedly:

}

can't get much simpler than this. any ideas?

Did you connect with USB cable between Mac and Yún?

yes. USB to micro USB

jcarls:
I tried switching Serial to Console and that works on some sketches but not all.

I would guess that you're not using the Console class correctly. Please post an example that does work, and one that doesn't.

Serial never works. i keep getting
Unable to connect: retrying (1)...
Unable to connect: retrying (2)...
Unable to connect: retrying (3)...
Unable to connect: retrying (4)...
Unable to connect: is the sketch using the bridge?

This is the typical output you get when you are trying to connect the Serial Monitor over the network, which requires that you use the Console class, but your sketch is instead using the Serial class. If you're connecting via USB, you need to use Serial, if connecting via the network you need to use Console. They are not interchangeable.

I searched and saw adding
while (!Serial) {}

was supposed to help but didn't.

That doesn't help connectivity. What it does is stop the sketch from running until you make a USB serial connection. That will give you time to make a connection and still see the initial Serial.print() output. Without it, the sketch will sail past the initial output statements before you can connect, and you'll never see them. The downside to this is that the sketch will always need to have a serial connection before it will do anything - this causes a lot of people problems when they try to run the sketch without being connected to their computer.

This could also cause the above problem with the Console connection complaining about using the Bridge: if you are using byte Console, but you have the wait in the for the Serial connection, it will never get past that wait, and the Serial Monitor won't be able to connect to the Console object.

#include <Console.h>

You are including the Console library, but not actually using it. That's OK, as long as you realize that simply including Console.h is not enough to switch your sketch over to be actually using the Console class. Since the rest of the sketch uses Serial, including this header should not affect it's operation.

while (!Serial); {}

You can use a semicolon to give the while statement a null statement that does nothing, or you can use the pair of curly braces to do the same thing. (I like using the curly braces since the semicolon is easy to miss while reading.) You don't need both, but it doesn't hurt and is not the reason for your problem.

can't get much simpler than this. any ideas?

Yes, that's pretty basic, and should work. I have a few questions about your setup, forgive me if some are obvious, I don't want to make assumptions that might be wrong.

Are all of these statements true?

  • You are using an actual Arduino Yun, and not a Yun Shield connected to a different Arduino board
  • You have the Yun micro-USB port connected to your computer
  • You are using a working data cable, and not a charging only cable that doesn't connect the data lines
  • You have the Arduino IDE's board type set to be a Yun
  • You have the Yun's USB port selected in the Arduino IDE's Port menu
  • You do not have the Yun's network address selected in the Arduino IDE's Port menu
  • You are able to load your posted sketch onto the Yun using the IDE and the above conditions
  • You are then trying to open the IDE's Serial Monitor with the above settings
    If all of this is true, and you are unable to use the USB serial port with the Serial Monitor, then you have something strange going on, possibly a driver problem on your computer? If something on the list above is not true, then fix it, as it's a requirement for successfully using the Serial Monitor with the USB port.

Now, for the Console class over the network, the list is a little different:

  • You have a working network connection (WiFi or Ethernet) between your Yun and your computer
  • You have the Arduino IDE's board type set to be a Yun
  • You have the Yun's network address selected in the Arduino IDE's Port menu
  • You do not have the Yun's USB port selected in the Arduino IDE's Port menu
  • You have modified your sketch to include Bridge.h and Console.h, it calls Bridge.begin and then Console.begin, ALL occurrences of Serial have been replaced with Console, and you do not have a while (!Serial) construct in your sketch
  • You are able to load your Console modified sketch onto the Yun using the IDE and the above conditions
  • You are then trying to open the IDE's Serial Monitor with the above settings

To summarize:

  • To use the USB serial connection, you need a good cable (the charger cables included with a lot of devices don't have data wires as a cost savings measure) and you need to do all I/O with the Serial class. You need to have the USB port selected in the IDE.
  • To use a network connection, you need a working network connection, you need to call Bridge.begin() then Console.begin(), and you need to do all I/O using the Console class, not the Serial class. You need to have the network port selected in the IDE.

Hi, Could you give example sketch? I want to receive load sensor data over wi-fi to editor (and ultimately to a webpage that can turn conditions to triggers). Thanks for your help.
My sketch:

#include "HX711.h"
#include <Bridge.h>
#include <Console.h>

HX711 cell(3, 2);

void setup() {
Bridge.begin();
Console.begin();
}

long val = 0;
float count = 0;

void loop() {
count = count + 1;

// Use only one of these
//val = ((count-1)/count) * val + (1/count) * cell.read(); // take long term average
val = 0.5 * val + 0.5 * cell.read(); // take recent average
//val = cell.read(); // most recent reading

Console.println( (val - 7998000) / 13104.f );
}