surerdra
Junior Member level 1
I am doing one project using ARDUINO UNO, which is ADC(ADS1115, 3 analog inputs) data and GPS(NEO-6M-0-001) data to store in microSD card.
Here the the GPS contains UART(Tx, Rx) communication, SD card contains SPI communication and ADS1115 contains I2C communication.
Here when i'm connected GPS and Sd card, The GPS data is stored in SD card and Like this when i'm connecting ADS1115 and SD card the data is stored in SD card
But the problem is while i'm connecting all (GPS, ADS1115, SD card) at a time it is not storing data in sd card. (Some one told me that is using of different communications in single program)
how to solve this issue ?
i tagged my code also please find it.
CODE :
Here the the GPS contains UART(Tx, Rx) communication, SD card contains SPI communication and ADS1115 contains I2C communication.
Here when i'm connected GPS and Sd card, The GPS data is stored in SD card and Like this when i'm connecting ADS1115 and SD card the data is stored in SD card
But the problem is while i'm connecting all (GPS, ADS1115, SD card) at a time it is not storing data in sd card. (Some one told me that is using of different communications in single program)
how to solve this issue ?
i tagged my code also please find it.
CODE :
Code C++ - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 #include <TinyGPS++.h> // Tiny GPS Plus Library #include <SoftwareSerial.h> // Software Serial Library so we can use other Pins for communication with the GPS module TinyGPSPlus gps; // Create an Instance of the TinyGPS++ object called gps static const uint32_t GPSBaud = 9600; #include <SPI.h> #include <SD.h> #include <Wire.h> #include <Adafruit_ADS1015.h> Adafruit_ADS1115 ads; /* Use this for the 16-bit version */ SoftwareSerial ss(6, 5); // The serial connection to the GPS device void setup() { Serial.begin(9600); // Update display while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } ss.begin(GPSBaud); // Set Software Serial Comm Speed to 9600 if (!SD.begin(4)) { Serial.println("Card failed, or not present"); return; } ads.begin(); } void loop() { ///////////////// float flat = gps.location.lat(); float flon = gps.location.lng(); ///////////////// int16_t adc0, adc1, adc2, adc3; float xdir, ydir, zdir, Tfield; ///////////////// adc0 = ads.readADC_SingleEnded(0); adc1 = ads.readADC_SingleEnded(1); adc2 = ads.readADC_SingleEnded(2); xdir = adc0 * (0.1875 / 1000) / 0.000025; ydir = adc1 * (0.1875 / 1000) / 0.000025; zdir = adc2 * (0.1875 / 1000) / 0.000025; Tfield = sqrt(sq(adc0 * (0.1875 / 1000)) + sq(adc1 * (0.1875 / 1000)) + sq(adc2 * (0.1875 / 1000))) / 0.000025; ////////////////// File myFile; ///////////////////// while (ss.available() > 0) { gps.encode(ss.read()); } if (gps.location.isUpdated()) { myFile = SD.open("test2.txt", FILE_WRITE); if (myFile) { myFile.print(F(" Date/Time: ")); myFile.print(gps.date.month()); myFile.print(F("/")); myFile.print(gps.date.day()); myFile.print(F("/")); myFile.print(gps.date.year()); myFile.print(F("/")); if (gps.time.isValid()) { if (gps.time.hour() < 10) Serial.print(F("0")); myFile.print(gps.time.hour()); myFile.print(F(":")); if (gps.time.minute() < 10) Serial.print(F("0")); myFile.print(gps.time.minute()); myFile.print(F(":")); if (gps.time.second() < 10) Serial.print(F("0")); myFile.print(gps.time.second()); myFile.print(F(":")); if (gps.time.centisecond() < 10) Serial.print(F("0")); myFile.println(gps.time.centisecond()); myFile.print(F(" ")); myFile.print("Latitude : "); myFile.println(flat, 6); myFile.print(F(" ")); myFile.print("Longitude : "); myFile.println(flon, 6); myFile.print(F(" ")); myFile.print("fieldX in nT: "); myFile.println(xdir); myFile.print(F(" ")); myFile.print("fieldY in nT: "); myFile.println(ydir); myFile.print(F(" ")); myFile.print("fieldZ in nT: "); myFile.println(zdir); myFile.print(F(" ")); myFile.print("Total field in nT: "); myFile.println(Tfield); } } myFile.close(); } myFile = SD.open("test2.txt"); if (myFile) { // read from the file until there's nothing else in it: if (myFile.available()) { Serial.write(myFile.read()); } // close the file: myFile.close(); } else { // if the file didn't open, print an error: Serial.println("error opening test2.txt"); } }
Last edited by a moderator: