Using SoftwareSerial for using a second serial port on the H

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
bluzcat
 
Posts: 2
Joined: Thu Oct 15, 2015 7:16 pm

Using SoftwareSerial for using a second serial port on the H

Post by bluzcat »

Hi. I have a Huzzah ESP8266 board that I'm going to use to hook up one of this ultrasonic rangefinder to:

https://www.adafruit.com/products/1137

This particular Maxbotix device outputs the distance in cm scale as an ascii string on a serial pin. Since I'm using the regular serial port on the board for debug printouts and uploading the sketches from the Arduino IDE, I thought I'd hook it up to a second serial port on the board. So I found the SoftwareSerial library that is ported to work on the Huzzah board:

https://github.com/plerup/espsoftwareserial

However, reading about the board pinout, it seems like there's only one serial port, and that it's basically routed both to the RX/TX pins, as well as the header for the console cable. Is there a way of achieving what I want, or do I simply need an external UART? Or is there another way of hooking up the Maxbotix rangefinder? Thanks,

User avatar
Franklin97355
 
Posts: 23940
Joined: Mon Apr 21, 2008 2:33 pm

Re: Using SoftwareSerial for using a second serial port on t

Post by Franklin97355 »

Software serial is to allow you to use the pins that are NOT the hardware serial. Check out the example in the library.

User avatar
bluzcat
 
Posts: 2
Joined: Thu Oct 15, 2015 7:16 pm

Re: Using SoftwareSerial for using a second serial port on t

Post by bluzcat »

Thanks for the reply. That was what I thought, and I wrote the code based on the example. However, I don't seem to get any data on the pin that I'm using. So I thought maybe I misunderstood the purpose of the library. I'm attaching the relevant code snippet. The example used port 14 for RX and port 12 for TX, but I don't seem to be getting any data. I've verified the Maxbotix rangefinder using the USB/TTL console cable, and it sends data constantly, so that's not the problem. Here's the relevant pieces of code:

#include <SoftwareSerial.h>

// Serial port to read sensor data from
SoftwareSerial mySerial(14, 12, 128);

void setup() {
Serial.begin(115200);
mySerial.begin(9600);
}

byte serialData;

void loop() {
delay(3000);
Serial.print("Polling sensor serial port...");

if (mySerial.available()) {
serialData = mySerial.read();
Serial.print(", distance is: ");
Serial.println(serialData);
} else {
Serial.println(", nothing to read from sensor");
}
}

User avatar
iesre
 
Posts: 273
Joined: Mon Jun 10, 2013 1:58 pm

Re: Using SoftwareSerial for using a second serial port on t

Post by iesre »

Hi. This is another question rather than an answer, but... I have run Adafruit's Plantower PM5003 successfully with software serial on the HUZZAH using

#include <SoftwareSerial.h>
SoftwareSerial pmsSerial(13,15);

I would like to upload these PM data to Adafruit IO. However, when I try to do this the Plantower no longer works. It automatically sends about 1 data stream per second. I would like to average a couple hundred if these values and send the average to Adafruit IO. But, all I get is a checksum error -- I think from the failed Plantower data stream. Does this make sense? Can anybody suggest a solution?

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

Return to “Microcontrollers”