Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[moved] How to use communications I2C, SPI AND UART in single program ARDUINO UNO

Status
Not open for further replies.

surerdra

Junior Member level 1
Joined
Feb 15, 2014
Messages
18
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Activity points
237
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 :


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:

Hi,

A complete schematic could help.

Klaus
 

Hi sir, thanks for your reply
the rough schematic i drawn on proteus with slight modifications in modules.

Instead od ads1115 - i used pcf8591 in proteus
instead od 3axis magnetometer which have sensitivity of 25microvolt/ nanotesla- i used 3 potentiometers

i tagged the image of proteus schematic please find it.
Untitled.jpg
 

Hi,

Why is the GPS module not connected to the Rx and Tx of the Arduino?

Besides this I see no problem with the SPI and I2C wiring.

I recommend to include some debugging code (set/clear I/Os at perticular places of code) to check where the program hangs.

Klaus
 

I used software serial library of arduino which is we can use any i/o pins used as tx and rx.

I connected my arduino to my laptop via usb which communicating my laptop with 0 and 1 pins (tx and rx)
 

I am not used delay here, if it is necessary please tell me whwre i can add delay.
 

Dont think it's a Delay problem. It Could be a SRAM memory problem.

Dealing with the long NMEA sentences, comming at 1 second intervals, at the 9600 default baud on most GPS receivers, is always an arduous task for any microcontroller, particularly when the serial interface is implemented by software (SoftwareSerial.h), thus wasting the opportunity to buffer the received data, which if it were done via UART, implemented w/ built-in peripherals, could even take the advantage of the legacy interrupt on reception made on the Arduino AVR standard driver of Serial (although not accessible via program). In short, it sounds like there were chosen unsuited approach to interface with the GPS module.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top