Im using 2 arduinos sender and reciever, the sender arduino have neo6mv2 a gps module and i want to send the latitude and longitude to second arduino using SoftwareSerial. How do recieve the exact values in the reciever and print the exact value ?
Which Arduino boards are you using ?
Is the GPS on Arduino number 1 using SoftwareSerial ?
If not, then how is it connected ?
Why do you need to use 2 Arduinos ?
im using arduino uno and yes the gps on arduino 1 is using softwareserial. Im just trying to learn serial communication.
here are the codes:
//code for the sender
#include <SoftwareSerial.h>
#include <TinyGPSPlus.h>
static const int RXpin =4;
static const int TXpin = 3;
static const uint32_t GPSbaud = 9600;
TinyGPSPlus gps;
SoftwareSerial ss(RXpin, TXpin);
SoftwareSerial latGPS(11, 10);
SoftwareSerial lonGPS(9, 8);
float lat, lon;
void setup() {
Serial.begin(9600);
ss.begin(GPSbaud);
lotGPS.begin(9600);
lonGPS.begin(9600);
}
void loop() {
gps_read();
sending_GPS();
}
void gps_read(){
while(ss.available() > 0){
if(gps.encode(ss.read())) gps_location();
}
if(millis() > 5000 && gps.charsProcessed() < 100){
Serial.println(F("No GPS detected, check wiring."));
while(true);
}
}
void gps_location() {
Serial.print(F("Location: "));
if(gps.location.isValid()){
lat = (gps.location.lat());
lon = (gps.location.lng());
Serial.print(lat, 7);
Serial.print(F(", "));
Serial.print(lon, 7);
}
else Serial.print(F("Invalid"));
Serial.print(F(" Date: "));
if(gps.date.isValid()){
Serial.print(gps.date.month());
Serial.print(F("/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
}
else Serial.print(F("Invalid"));
Serial.println();
}
void sending_GPS(){
latGPS.write(lat); // i dont know if this is right
lonGPS.write(lon);
}
//code for the receiver
#include <SoftwareSerial.h>
SoftwareSerial recieveLAT(10, 11); //RX, TX
SoftwareSerial recieveLON(8, 9);
float lat, lon;
void setup() {
Serial.begin(9600);
receiveLAT.begin(9600);
receiveLON.begin(9600);
}
void loop() {
//please help what is the code for receiving
}
start there: Serial Input Basics
If you are using SoftwareSerial for the GPS then you will not be able to use it to communicate with the second Uno. Only a single instance of SoftwareSerial can be used reliably on an Arduino
You should avoid using hardware Serial (pins 0 and 1) on either Arduino as they are used to upload code to the board and for the Serial monitor, which you will need for debugging
Some solutions :
- use a different software serial library for the interface to the second Arduino (AltSoftSerial)
- use an Arduino with more hardware UARTs such as a Mega
- use a different interface such as SPI or I2C to communicate with the second Arduino
Example 5 of Serial input basics demo's how you can send 2 or more float's (and/or other datatypes) across the serial line. Why do you need 2 Arduino's?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.