Issue with sensors connecting to arduino uno via Hardware serial portexpander8:1

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
}
}

33 post and nobody told you to use code-tags? I would say it's high time to have a look at How to get the most out of this forum.

VeeraSekhar:
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

Something like this maybe to interface between the various modules using the UART expander (I let you do the tweaking to send the intended strings to the respective modules! :wink: )
(Compiles, Not tested!)

/*atlas scientific serial port expander 8:1 example*/

#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

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

const uint8_t module_count = 8;                       //number of modules connected to the serial port expander 1=Port1, 2= Port2 and so on

void setup() {
  Serial.begin(115200);                                 //Set the hardware serial port to 115200
  mySerial.begin(9600);                               //set baud rate for the software serial port to 9600

  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 loop() {
  if (Serial.available()) {                           //if we get data from the computer
    char c = Serial.read(); 
    
    for (uint8_t i = 1; i <= module_count; i++) {    // loop through the modules
      Serial.print("Connecting to Port: ");
      Serial.println(i);
      open_port(i);                                  // open the port
      
      mySerial.print(c);                             //print character to port
      delay(100);                                    //insert a delay to wait for the reply

      if (mySerial.available()) {                   //print reply to serial monitor
        while (mySerial.available()) {
        Serial.println(mySerial.read());
        }
      }
      else{
        Serial.print("No response received");
      } 

      Serial.println();
    }
    
  }
  
}

void open_port(uint8_t _port) {                                  //this function controls what port is opened on the serial port expander

  if (_port < 1 || module_count > 8)_port = 1;                //if the value of the port is within range (1-8) then open that port. If it’s not in range set it to port 1
  uint8_t port_bits = _port - 1;

  digitalWrite(s1, bitRead(port_bits, 0));               //Here we have two commands combined into one.
  digitalWrite(s2, bitRead(port_bits, 1));               //The digitalWrite command sets a pin to 1/0 (high or low)
  digitalWrite(s3, bitRead(port_bits, 2));               //The bitRead command tells us what the bit value is for a specific bit location of a number
  delay(2);                                         //this is needed to make sure the channel switching event has completed
}

Hope that helps...

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.