Hardware connection and also programming issue with sensors(gps neo6m module, esp8266 etc) connecting to arduino uno via atlas scientific serial port expander 8:1
Hardwares:
1)Arduino Uno
2)Atlas scientific serial port expander 8:1
3)gps neo6m module
4)ESP8266 Wifi module
Below Code which we are following for "gps data" output to serial monitor:
#include <TinyGPS.h>
#include <SoftwareSerial.h> //we have to include the SoftwareSerial library, or else we can't use it
#define rx 2 //define what pin rx is going to be
#define tx 3 //define what pin tx is going to be
SoftwareSerial myserial(rx, tx); //define how the soft serial port is going to work
TinyGPS gps;
String inputstring = ""; //a string to hold incoming data from the PC
String sensorstring = ""; //a string to hold the data from the Atlas Scientific product
boolean input_string_complete = false; //have we received all the data from the PC
boolean sensor_string_complete = false; //have we received all the data from the Atlas Scientific product
int s1 = 6; //Arduino pin 6 to control pin S1
int s2 = 5; //Arduino pin 5 to control pin S2
int s3 = 4; //Arduino pin 4 to control pin S3
int port = 0; //what port to open
void setup() {
Serial.begin(9600); //Set the hardware serial port to 9600
myserial.begin(9600); //set baud rate for the software serial port to 9600
inputstring.reserve(10); //set aside some bytes for receiving data from the PC
sensorstring.reserve(30); //set aside some bytes for receiving data from Atlas Scientific product
pinMode(s1, OUTPUT); //Set the digital pin as output
pinMode(s2, OUTPUT); //Set the digital pin as output
pinMode(s3, OUTPUT); //Set the digital pin as output
}
void serialEvent() { //This interrupt will trigger when the data coming from the serial monitor(pc/mac/other) is received
inputstring = Serial.readStringUntil(13); //read the string until we see a
input_string_complete = true; //set the flag used to tell if we have received a completed string from the PC
}
void loop() {
if (input_string_complete) { //if a string from the PC has been received in its entirety
pars(); //call the pars function to decode the string
open_port(); //call this function to open the correct port (p1-p8)
if (inputstring != "") { //if there is a message in the string (example 4:cal,1413) then send that message (cal,1413) through the open port
myserial.print(inputstring); //TX the message (cal,1413)
myserial.print("\r"); //and a craage return (cal,1413)
inputstring = ""; //clear the sent message so we don't send it again by mistake
}
}
