Go Down

Topic: WiFi Serial setup disrupting GPS serial data (Read 436 times) previous topic - next topic

ReverendShack

Hi there!

I have an Arduino Uno, a SIM 900 GPRS, an LCD screen and an ESP8266 WiFi board.

I'm trying to get the GPS Co-ordinates to display on the WiFi board Serial Monitor.


I can get the uno to transfer data to the WiFi board - but when I add in the GPS it stops working.

The GPS and LCD work if I comment out the WiFi board serial port start - but add it in again and nothing does anything.

Why is it when I try and start up the WiFi communication everything else falls over?

WiFi Board Code:

/* Create a WiFi access point and provide a web server on it. */
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

//Talk To Uno
SoftwareSerial NodeMCU(D7,D8);
//Talk To Uno End
/* Set these to your desired credentials. */
const char *ssid = "BoatWifi";
const char *password = "thereisnospoon";

ESP8266WebServer server(80);

/* Just a little test message.  Go to http://192.168.4.1 in a web browser
   connected to this access point to see it.
*/
void handleRoot() {
  server.send(200, "text/html", "<h1>BoatServer Online</h1>");
}

void setup() {
//Talk To Uno
   Serial.begin(9600);
   NodeMCU.begin(115200);
   pinMode(D7,INPUT);
   pinMode(D8,OUTPUT);
  //Talk To Uno END
 
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.print("Configuring access point...");
  /* You can remove the password parameter if you want the AP to be open. */
  WiFi.softAP(ssid, password);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);
  server.begin();
  Serial.println("HTTP server started");

}

void loop() {
  server.handleClient();
  String content = "";
char character;

  while(NodeMCU.available()) {
      character = NodeMCU.read();
      content.concat(character);
  }
  if (content != "") {
    Serial.println(content);
  }
 Serial.println("Temperature");
 Serial.println(content.substring(1, 6));
 Serial.println("Humidity");
 Serial.println(content.substring(7, 12));
   delay(2000);
}

Uno Board Code:
/*
 * Rui Santos
 * Complete Project Details http://randomnerdtutorials.com
 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
 
#include <TinyGPS++.h>
//#include <SoftwareSerial.h>
#include <NeoSWSerial.h>

static const int RXPin = 8, TXPin = 9;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
NeoSWSerial ss(RXPin, TXPin);

//Set Up Wifi Module Comms
NeoSWSerial ArduinoUno(10,13);
String f;
String l;
//Set Up Wifi Module Comms END

void setup(){

     Serial.begin(9600);
  ss.begin(GPSBaud);

    //Talk To Wifi Module
//   ArduinoUno.begin(115200);
   //Talk To Wifi Module END
 
   // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);


}

void loop(){
 

  // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0){
    gps.encode(ss.read());
    if (gps.location.isUpdated()){
     
       lcd.setCursor(0, 0);
       lcd.print("Lat= ");
       lcd.print(gps.location.lat(), 4);
       
         Serial.print("Latitude= ");
         Serial.print(gps.location.lat(), 6);

       lcd.setCursor(0, 1);
       lcd.print("Lon= ");
       lcd.print(gps.location.lng(), 4);
   
//    float i = (gps.location.lat(), 2);
//  float j = (gps.location.lng(), 2);
// 
// f = String('H')+String(i)+String('T')+String(j);
//  ArduinoUno.println(f);
//  delay(2000);
     
         Serial.print(" Longitude= ");
         Serial.println(gps.location.lng(), 6);
    }
  }
}


END OF CODE


Thanks in advance!

Shack



ReverendShack

To add I have an UNO code that actually fits the WiFi code perfectly, and that does all it is supposed to do so I know my wiring is good! Here's the one that works:

UNO Code:

/*
* bismillah hir rahman nir raheem
* UNO/Nano = Pin 6 & Pin 7
* Note: Uno and ESP8266 cross connection
*/
#include <SoftwareSerial.h>
SoftwareSerial ArduinoUno(10,13);
String f;
void setup(){
   Serial.begin(9600);
ArduinoUno.begin(115200);
}
void loop(){
float i = (random(100) + 1);
float j = (random(100) + 1);

f = String('H')+String(i)+String('T')+String(j);
ArduinoUno.println(f);
delay(2000);
}

PaulS

Code: [Select]
// The serial connection to the GPS device
NeoSWSerial ss(RXPin, TXPin);

//Set Up Wifi Module Comms
NeoSWSerial ArduinoUno(10,13);

So, you have an ss and an ArduinoUno connected to the Arduino UNO?

Why do the names not make sense?

Code: [Select]
    gps.encode(ss.read());
The encode() method returns an important value. Why are you ignoring the value?

With the LCD disconnected, and locked in a drawer, are you able to read GPS data using one software serial instance, and write data to the ESP using another one?

Why are you not using an Arduino with multiple hardware serial ports, so you don't need any software serial instances?
The art of getting good answers lies in asking good questions.

ReverendShack

Thanks for the reply Paul!

Yes, fair point, the names do not makes sense. The ArduinoUno in the uno code is talking to the WiFi board - it should be named WiFiComms I suppose.

I have literally no idea why I'm ignoring it. I thought the lat/lon data I'm trying to pass over depended on it - isn't that telling the board how to interpret the GPS data?

I'll try that now... No, even with the lcd locked in a drawer it doesn't work - not even to the serial monitor on the pc, so it's not getting GPS data at all. It's the GPS and the WiFi serials that seem to conflict.

And lastly, I don't know what an arduino with hardware serial ports is.

Nick_Pyner

Here's the one that works:

UNO Code:
..........
#include <SoftwareSerial.h>
SoftwareSerial ArduinoUno(10,13);
...........
ArduinoUno.begin(115200);
That works?

ReverendShack

That works?
Yes - the WiFi serial monitor prints exactly what it's supposed to.

Odd, huh?

ReverendShack

This code works fine until one uncomments the line:
WifiBoard.begin(115200);
so it's defo a conflict between the GPS and the WiFi. No idea why though.



//START UNO CODE
#include <TinyGPS++.h>
//#include <SoftwareSerial.h>
#include <NeoSWSerial.h>

static const int RXPin = 8, TXPin = 9;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
NeoSWSerial ss(RXPin, TXPin);

//Set Up Wifi Module Comms
NeoSWSerial WifiBoard(10,13);
String f;
String l;
//Set Up Wifi Module Comms END

void setup(){

     Serial.begin(9600);
  ss.begin(GPSBaud);

    //Talk To Wifi Module
//   WifiBoard.begin(115200);
   //Talk To Wifi Module END
 


}

void loop(){
 

  // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0){
    gps.encode(ss.read());
    if (gps.location.isUpdated()){
     

       
         Serial.print("Latitude= ");
         Serial.print(gps.location.lat(), 6);

//    float i = (gps.location.lat(), 2);
//  float j = (gps.location.lng(), 2);
// 
// f = String('H')+String(i)+String('T')+String(j);
//  ArduinoUno.println(f);
//  delay(2000);
     
         Serial.print(" Longitude= ");
         Serial.println(gps.location.lng(), 6);
    }
  }
}
??END UNO CODE

ReverendShack

Sorted it.

I set the wifi port up before setting the serial and the GPS in the UNO setup section.

I figure that it can only listen on the last port it opened, whereas it can write to any port at any point.

Thanks for the replies.

Go Up