Connect with us

Problem with data logging in arduino environment

Discussion in 'Microcontrollers, Programming and IoT' started by sunandhan, Nov 1, 2020.

Scroll to continue with content
  1. sunandhan

    sunandhan

    2
    0
    Nov 1, 2020
    HI guys, iam recently making a projects that include arduino, mpu6050 and bmp280 and finally i have to log that data so, iam using a microSD card module

    info of the the microSD card:

    Initializing SD card...Wiring is correct and a card is present.

    Card type: SDHC
    Clusters: 1914880
    Blocks x Cluster: 8
    Total Blocks: 15319040

    Volume type is: FAT32
    Volume size (Kb): 7659520
    Volume size (Mb): 7480
    Volume size (Gb): 7.30

    Files found on the card (name, date and size in bytes):

    first i always try to test every modules one by one to find whether they are working good and i will do that with the help Arduibo IDE example codes and my every modules including microSD card module is working well and for microSD card first used cardinfo and it works perfectly and then i used datalogger code and i also logged the data perfectly and it is actually working very very well. Then i started to write my code first for mpu6050 and bmp280 and there is no mistakes in that code and i also so got good values and then i just included the datalogger code from example in my code and after that also there is no mistakes, actually everything is perfect and i just uploaded that code to my arduino nano and see the serial monitor and it shows :

    ⸮?>8>?⸮8⸮>>⸮>⸮⸮?8⸮?⸮??⸮?⸮⸮?⸮

    and this is the only thing that serial monitor shows !!

    iam also posting last lines of upload pane, the ones that say how much program and RAM memory iam using so it will help u :

    Sketch uses 27078 bytes (88%) of program storage space. Maximum is 30720 bytes.
    Global variables use 1924 bytes (93%) of dynamic memory, leaving 124 bytes for local variables. Maximum is 2048 bytes.
    Low memory available, stability problems may occur.

    and the baud rate in serial monitor is equal to baud rate in Serial.begin() and i choosed the baud rate 9600

    and if i delete the data logging code from my main code then it works perfectly but if i include the data logging code in my main code then only it is not working and it shows ⸮?>8>?⸮8⸮>>⸮>⸮⸮?8⸮?⸮??⸮?⸮⸮?⸮ in serial monitor

    and main thing is, this problem comes after iam adding a countdown code(basically if a press a button then for loop starts) in my main code after that only the serial shows ⸮?>8>?⸮8⸮>>⸮>⸮⸮?8⸮?⸮??⸮?⸮⸮?⸮ but my countdown code doesn't have any mistakes in it and i also checked it with out adding in my main code and it works well but when i add that in my main code it shows like that and if i delete the data logging code from my main code then everything works well including countdown and if i delete countdown code from my main code then everything works well including data logging and if i add both(data logging and countdown) in my main code then only it serial monitor shows like ⸮?>8>?⸮8⸮>>⸮>⸮⸮?8⸮?⸮??⸮?⸮⸮?⸮ and then it is not working properly

    Code:
    void setup() {
    
      Serial.begin(9600);
    
      pinMode(led1, OUTPUT);
      pinMode(led2, OUTPUT);
      pinMode(buzz, OUTPUT);
      pinMode(chipSelect, OUTPUT);
      pinMode(but, INPUT_PULLUP);
    
      s.attach(6);
    
      imuconfig();
    
      checking();
    
      countdown();
    
      delay(1000);
    
    }
    
    void loop() {
    
      oldtime = newtime;
      newtime = millis();
      elapsedTime = (newtime - oldtime) / 1000 ;
    
      imu();
    
      Serial.print(" X axis = ");
      Serial.print(totalX);
      Serial.print(" | ");
      Serial.print(" Y axis = ");
      Serial.print(totalY);
      Serial.print(" | ");
    
      Serial.print(F("Temperature = "));
      Serial.print(bmp.readTemperature());
      Serial.print(" *C");
      Serial.print(" | ");
    
      Serial.print(F("Pressure = "));
      Serial.print(bmp.readPressure());
      Serial.print(" Pa");
      Serial.print(" | ");
    
      Serial.print(F("Approx altitude = "));
      Serial.print(bmp.readAltitude(1011.7));// Adjusted to local forecast!
      Serial.print(" m");
      Serial.print(" | ");
    
      Serial.println("");
    
      data();
    }
    
    void countdown() {
    
      v = digitalRead(but);
    
      if (v == 0) {
        for (int b = 0; b < 6; b++) {
          int buz;
          buz = buz + 1000;
          tone(buzz, buz);
          delay(100);
          noTone(buzz);
          delay(100);
        }
     
        Serial.println("COUNTDOWN STARTS !!");
        Serial.println("DURATION IS 60s");
     
        for (int x = 0; x < 60; x++) {
      
          Serial.println(y);
          v = digitalRead(but);
      
          if (v == 0) {
        
            Serial.println("LAUNCH SCRUBBED !!");
            tone(buzz, 100);
            delay(1000);
            noTone(buzz);
            while (w) {
          
              v = digitalRead(but);
              if ( v == 0) {
            
                w = 0;
            
              }
            }
          }
          if (y <= 60 && y > 45) {
            digitalWrite(led2, HIGH);
            delay(500);
            digitalWrite(led2, LOW);
            delay(500);
          }
          else if (y <= 55 && y > 30) {
            digitalWrite(led1, HIGH);
            delay(500);
            digitalWrite(led1, LOW);
            delay(500);
          }
          else if (y <= 30 && y > 10) {
            digitalWrite(led1, HIGH);
            digitalWrite(led2, HIGH);
            delay(500);
            digitalWrite(led1, LOW);
            digitalWrite(led2, LOW);
            delay(500);
          }
          else if (y <= 10 && y > 1 ) {
            digitalWrite(buzz, HIGH);
            delay(500);
            digitalWrite(buzz, LOW);
            delay(500);
          }
          else if (y = 1) {
            tone(buzz, 600);
            delay(1000);
            noTone(buzz);
            delay(500);
          }
          y = y - 1;
        }
      }
    }
    
    void data() {
    
      File dataFile = SD.open("datalog.txt", FILE_WRITE);
      if (dataFile) {
        dataFile.println(totalX);
        dataFile.close();
      }
    
      else {
    
        Serial.println("error opening datalog.txt");
    
      }
    }
    and this not my full code but this is where the problem is

    and i really don't know why this is happening and if anyone know what is really going on pls pls pls pls say and pls help me to solve this problem, pls pls
     
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    10,591
    2,360
    Nov 17, 2011
    Looks like a mismatch in the serial communication.
    Do the number of stop bits and the parity match, too?
     
  3. sunandhan

    sunandhan

    2
    0
    Nov 1, 2020
  4. bertus

    bertus Moderator

    1,158
    439
    Nov 8, 2019
  5. Harald Kapp

    Harald Kapp Moderator Moderator

    10,591
    2,360
    Nov 17, 2011
    The "datalogging code" is which part? This one?
    Code:
    void data() {
    
      File dataFile = SD.open("datalog.txt", FILE_WRITE);
      if (dataFile) {
        dataFile.println(totalX);
        dataFile.close();
      }
    
      else {
    
        Serial.println("error opening datalog.txt");
    
      }
    }
    Check the pins used by the serial port (Rx, TX) and by the SD card. If they use shared pins, Using the SD card will interfere with the serial communication.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-