Serial port enumeration

Total noob here...

How do I go about listing all of the serial ports on my board? Or is that a silly question? :slight_smile:

I have a Pro Micro that has Serial1 which seems to be leds on board and a few other pins on board that can act as Serial. I have a LCD hooked up and was want to write to it over one serial port and to the Serial Monitor for debugging.

I'm sure this post reeks of noobness. Any help appreciated. More than happy to RTFM if you point me to it. :slight_smile:

I'm a noob myself - so, no worries. I also have a pro-micro. From the git-go, it has one set of pins dedicated to serial comms. To use the default pins, your code should be Serial.print("Hello World"). If you use the "software serial" library, or the like, you can define any of your pins to be RX and TX and define the name of your serial output like below:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
  mySerial.println("Hello, world?");
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

Hope this helps.

To use the LCD, you must define the pins connected to the LCD and use a library - such as "LiquidCrystal".

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}

I believe he has one of these:
Serial enabled LCD

I think you only have one hardware serial port. Use that to talk to the serial monitor and use Software Serial to turn two GPIO's into serial pins.

A Pro Micro uses the 32u4 MCU and it has one spare Hardware Serial Port (Serial1) which appears on pins 0 and 1. The USB connection to the PC (Serial) is handled by the 32u4 and does not appear on any of the I/O pins.

All the hardware details will be found in the relevant Atmel (now Microchip) datasheet for the microprocessor.

...R

Thanks everyone with your help! I've got one of those DIYMALL $10 screens that uses the adafruit sd3306 and gfx libraries. http://www.diymalls.com/0.96-oled-lcd-display

I think I confused myself a bit trying to figure out the serial ports while having this display plugged in. The display is connected to the SDA/SDL lines on the Pro Micro. I had assumed that this was the device "Serial"...but was wrong. Even though this device connects to SDA/SDL, it doesn't seem to be tied to Serial* device, unless the i2c address is a serial device....haven't read up on that yet.

Anyways, I found that I can write to Serial for debugging to the serial monitor. I have no idea where Serial1 goes.

I have downloaded the PDF of the datasheet for this board, haven't quite digested all of that yet.

Interesting about the software serial library, that might come in handy someday.

Is there anyway to list all of the serial devices on a given board? In the linux world I usually do "dmesg | grep tty" to see what's there.

Thanks again everyone!

No. You have to find out which board you have and then you can write your program to do different things on different boards. There's a number of different parameters which are defined by the compiler when it compiles for different boards.

Some Arduinos have more than one I2C port (the SDA/SCL pair) and some have up to 6 serial ports. But those ports may actually have different hardware capabilities, which affects some of the (extremely rare) advanced functions you can do with a port.

The best way to discover the different parameters is to pull apart a library which works on multiple boards. Then find the one which seems to suit the particular distinction that you have to make. Another way to find these is to pull apart the pins.h file for your specific board, which is in your Arduino distribution. Then you can see that SERIAL_PORT_MONITOR is defined for each different type of board to always go to the serial port which is connected to the USB.

Just to detect the Pro Micro might be difficult to differentiate from a regular Micro. Plus the core processor of the Micro is the same as a Leonardo and even though you don't intend to install it on a Leonardo, you could probably write your code in a way that doesn't care if you change your mind in the future:

#ifdef __AVR_ATmega32U4__
  //put code specific to the 32U4 Arduino variants here
#endif

fixthisser:
I have no idea where Serial1 goes.

It does not go anywhere unless you connect a suitable device to the Rx and Tx pins for Serial1

...R

Got it! Thanks everyone for your replies.