Witam was serdecznie,
otóż od jakiegoś czasu składam zestaw, który będzie wykorzystany do balonu meteo. Jego zadaniem będzie pomiar temperatury, wilgotności i może ciśnienia oraz zapis danych z GPSa na kartę pamięci. Oprócz tego zestaw wyposażony jest w moduł GSM, dzięki któremu będę mógł lokalizować balon w czasie lotu oraz po wylądowaniu wysyłając do mojego zestawu smsa. W wiadomości zwrotnej otrzymuję współrzędne: Cały zestaw jest gotowy i poskładany, ale problem jest z programem. Otóż mam przygotowany pełen program na podstawie 3 różnych. Każdy z nich z osobna działa, ale już po połączeniu go w jeden nic się nie dzieje. Nie wiem, w czym jest rzecz.? Może ktoś przygotowywał taki zestaw lub jest w stanie zdiagnozować problem w kodzie?
Poniżej przedstawiam wam kod programu:
Proszę o pomoc.
otóż od jakiegoś czasu składam zestaw, który będzie wykorzystany do balonu meteo. Jego zadaniem będzie pomiar temperatury, wilgotności i może ciśnienia oraz zapis danych z GPSa na kartę pamięci. Oprócz tego zestaw wyposażony jest w moduł GSM, dzięki któremu będę mógł lokalizować balon w czasie lotu oraz po wylądowaniu wysyłając do mojego zestawu smsa. W wiadomości zwrotnej otrzymuję współrzędne: Cały zestaw jest gotowy i poskładany, ale problem jest z programem. Otóż mam przygotowany pełen program na podstawie 3 różnych. Każdy z nich z osobna działa, ale już po połączeniu go w jeden nic się nie dzieje. Nie wiem, w czym jest rzecz.? Może ktoś przygotowywał taki zestaw lub jest w stanie zdiagnozować problem w kodzie?
Poniżej przedstawiam wam kod programu:
Kod:
#include <SPI.h> // library for SPI devices (uSD board)
#include <TinyGPS.h> // library for GPS
#include <SoftwareSerial.h> // library for serial comm. with GPS
#include <SD.h> // library for the uSD board
#include <Wire.h> // library for comm. with I2C sensors
#include "DHT.h" // library for DHT temp and humidity sensor
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
#define DHTPIN 7
const byte chipSelect = 4; // the SD card CS pin is wired to pin 10
TinyGPS gps; // make the tinyGPS object
SoftwareSerial ss(1, 0); // Assign the SoftwareSerial TX and RX pins for the GPS
DHT dht(DHTPIN, DHTTYPE);
SoftwareSerial sgps(1, 0);
SoftwareSerial sgsm(2, 3);
int state = 0;
const int pin = 4;
float gpslat, gpslon;
void setup()
{
ss.begin(9600); // only the GPS uses this
Serial.begin(9600); // this is for displaying data on a serial monitor
dht.begin(); // Initialise the DHT sensor
pinMode(chipSelect, OUTPUT); // The CS pin on the SD card
if (!SD.begin(chipSelect)) // see if the card is present and can be initialized
{ while(1); } // Wait forever since we can't write data
sgsm.begin(9600);
sgps.begin(9600);
}
void loop()
//GPS I KARTA SD
{
bool newData = false;
for (unsigned long start = millis(); millis() - start < 1000;) // gather GPS data for 1 second
{
while (ss.available()) // while the GPS data is coming via software serial
{
char c = ss.read(); // read the characters into c
if (gps.encode(c)) newData = true; // Did a new valid sentence come in?
}
}
String dataString = ""; // start with an empty dataString
if (newData) // if a new valid GPS sentence was read
{
float flat, flon, falt; // these next 9 lines parse the GPS data
unsigned long age;
int year;
byte month, day, hour, minute, second, hundredths;
gps.f_get_position(&flat, &flon, &age);
falt = gps.f_altitude();
gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
char sz[32];
sprintf(sz, "%02d/%02d/%02d,%02d:%02d:%02d,", month, day, year, hour, minute, second);
File dataFile = SD.open("DANE.csv", FILE_WRITE); // write to this file
dataFile.print("Data i Czas: ");
dataFile.print(sz);
dataFile.print(" Długosc: ");// write date time data to SD card
dataFile.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6); // write GPS data to SD card
dataFile.print(",");
Serial.print(" Długość: ");
Serial.print(flon, 6);
dataFile.print(" Szerokosc: ");
dataFile.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6); // write GPS data to SD card
dataFile.print(",");
Serial.print(" Szerokość: ");
Serial.print(flat, 6);
dataFile.print(" Wysokosc: ");
dataFile.print(falt == TinyGPS::GPS_INVALID_ALTITUDE ? 0.0 : falt, 1); // write GPS data to SD card
dataFile.print(" m,");
Serial.print(" Wysokość: ");
Serial.print(falt, 1);
delay (100);
//TEMPERATURA i WILGOTNOSC
float temperature; // Temperature variable
delay (100);
float DHTh = dht.readHumidity(); // Read DHT sensor
Serial.print(" Wilgotnosc: ");
Serial.print(DHTh, 2);
dataFile.print(" Wilgotnosc: ");
dataFile.print(DHTh, 2); // write humidity data to SD card
dataFile.print("%,");
float DHTt = dht.readTemperature(); // Read temperature as Celsius (the default)
Serial.print(" Temperatura: ");
Serial.println(DHTt, 2);
dataFile.print(" Temperatura: ");
dataFile.print(DHTt, 2); // write temperature data to SD card and end line
dataFile.println(" st. C ");
dataFile.flush();
dataFile.close();
} // endif (newData)
delay (1000); // write data to SD card only every few seconds
while (sgps.available())
{
//WYSYŁANIE DANYCH SMSEM
int c = sgps.read();
if (gps.encode(c))
{
gps.f_get_position(&gpslat, &gpslon);
}
}
if (sgsm.available() > 0) {
String c = sgsm.readString();
c.trim();
if (c.indexOf("GET-GPS") > 0) {
sgsm.print("\r");
delay(1000);
sgsm.print("AT+CMGF=1\r");
delay(1000);
/*Replace XXXXXXXXXX to 10 digit mobile number &
ZZ to 2 digit country code*/
sgsm.print("AT+CMGS=\"+48790208796\"\r");
delay(1000);
//The text of the message to be sent.
sgsm.print("Szerokosc: ");
sgsm.println(gpslat, 6);
sgsm.print("Dlugosc: ");
sgsm.println(gpslon, 6);
delay(1000);
sgsm.write(0x1A);
delay(1000);
}
}
}
Proszę o pomoc.