(Fast question) Micro SD card Data Loger, Write/Serial.print

So there is my simple problem, i got a dataloger and i record data on sd card
but the actual arduino start recording only if i open Serial Monitor once if i plug the arduino
on non usb external power/ battery the (TX Led) don't start transmit data/ record data.

Is there a way to active the dataloger without the computer/Serial Monitor?

Code:

File dataFile = SD.open("mpu.txt", FILE_WRITE);

if (dataFile){
dataFile.print(Ax);dataFile.print(" , ");   //
dataFile.print(Ay);dataFile.print(" , ");  // Acceleromiter output data
dataFile.print(Az);                       //
dataFile.print("   ,   ");
dataFile.print(xG, 3);dataFile.print(" , ");   //
dataFile.print(yG, 3);dataFile.print(" , ");  // Acceleromiter x,y,z G-Force
dataFile.println(zG, 3);                     //
dataFile.close();
}
else{
  delay(1);
}

That's all the dataloger recording data and above that :

       Serial.print(ax); Serial.print("\t");
        Serial.print(ay); Serial.print("\t");
        Serial.print(az); Serial.print("\t");

Nothing else.

How do i make the arduino to start record when it's powered with external battery?

Domino60:
How do i make the arduino to start record when it's powered with external battery?

Perhaps by ensuring that the battery is appropriate for the job. If it is a 9v pp3, it surely isn't. The code looks rather incomplete, but if it works when you get power off the USB, I guess it isn't the problem.

I didn't posted all the code because I have multiple sensors and the code is big as hell to post it here
I just posted the main sensor serial and datalog to give an example how it works.

the arduino/SD card module start record data when the serial monitor opens at least once if i plug off the USB and power the module from external battery there is no way how to open serial monitor and the arduino/ SD card don't run (the loop) to record the data.

In the other way if i don't type my sensors output data the SD card had no way how to read the data and
record it on sd card. Im not sure what to do, is there a way to active the serial without the IDE help?

Perhaps by ensuring that the battery is appropriate for the job. If it is a 9v pp3, it surely isn't.

I got a USB power bank I just plug the arduino USB and it's powering up, there is no problem with power
I've been worked in the past like that. (Power Bank 7v 4000mAh -> (circuit regulator) USB 5v).

Opening the Serial Monitor application resets the Arduino. It has NO impact on the ability of the code to write to the SD card.

I didn't posted all the code because I have multiple sensors and the code is big as hell to post it here

Not the part that writes to the SD card. Test THAT part BY ITSELF! If it works when not connected to the PC, then power IS the issue.

A 9000 volt power supply, capable of delivery 3.5 microamps, is useless. That power supply may indeed be able to deliver that current for years.

You have not said what amount of current your power supply can deliver, only the length of time that it can deliver some current.

I can't understand how power can be issue, the arduino operate at 5v with a input voltage from 7 to 20v

The website confirm it:

I use 2x Li-Ion 3.7v = 7.4v 4Ah, how that could be a power supply problem? I tested even 12v not being tarded
but the power supply is not the problem.

To be able to record on the SD card i had the tablet serial always open if even i closed it for a sec the arduino stop serial printing and there is no any data recorded on the sd card, the TX led on the arduino (loop loops) stop looping.

So what i say is maybe from the code but what? I don't know..

So what i say is maybe from the code but what? I don't know..

Since you won't share it, we don't either. So quit whining.

Domino60:
I use 2x Li-Ion 3.7v = 7.4v 4Ah, how that could be a power supply problem? I tested even 12v

Quite easily and power may still be your problem. The batteries are capable enough but barely relevant. You are only talking about input, you don't talk about output but, to the Arduino, output is the only thing that matters. Furthermore, if that is the problem, leaning 12v against the input isn't going to fix it.

Quite easily and power may still be your problem. The batteries are capable enough but barely relevant. You are only talking about input, you don't talk about output but, to the Arduino, output is the only thing that matters. Furthermore, if that is the problem, leaning 12v against the input isn't going to fix it.

The USB power the arduino with a 5v 800mA and the hell battery wont power up the arduino? come on.

Since you won't share it, we don't either. So quit whining.

#include <SD.h>

// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 4;

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
}

void loop()
{
  // make a string for assembling the data to log:
  String dataString = "";

  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < 3; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 2) {
      dataString += ","; 
    }
  }

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }  
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  } 
}

Domino60:
The USB power the arduino with a 5v 800mA and the hell battery wont power up the arduino? come on.

I note with only faint interest that this is the first time you have bothered to properly enlighten anybody about the 800mA output.

I don't know if it is pertinent to the problem but, clearly, opening the file every time you go round the loop, and never closing it, seems rather pointless. One also wonders at the frequency with which you whizz round the loop. Maybe it is tripping over itself.

Nick_Pyner

clearly, opening the file every time you go round the loop, and never closing it, seems rather pointless.

File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();

DataFile = SD.open ....
dataFile.close();

There is NO reason, in that code, to be using a String AT ALL.

Open the file. Loop to read the pins and write the reading to the file. Close the file.

Quit pissing away resources needlessly.

There is NO reason, in that code, to be using a String AT ALL.

Open the file. Loop to read the pins and write the reading to the file. Close the file.

Quit pissing away resources needlessly.

The code in the comment Nr.9 it's actually Library DataLog example, it's not mine

The main question which still need to be answered in this topic is why the arduino/sd card is not recording data without opening the serial port 1st?

The code in the comment Nr.9 it's actually Library DataLog example, it's not mine

Are you, or are you not, using that code? If you are, it IS your code. Feel free to remove all the stupid shit it does.

Feel free to remove all the comments, and code, that refer to Arduinos that you do not have.

If you are not using a Leonardo or Micro, waiting for Serial to be ready is WHY your code does not work without opening the serial monitor.

If you are not using a Leonardo or Micro, waiting for Serial to be ready is WHY your code does not work without opening the serial monitor.

I'm using Uno.

The main question of this topic:

So there is my simple problem, i got a dataloger and i record data on sd card
but the actual arduino start recording only if i open Serial Monitor....

Is there a way to active the dataloger without the computer/Serial Monitor?

So I'm using a dataloger example to record some data from a sensor which I print the data on serial monitor
then the SD Card module store the data on sd card but the SD card module / arduino start recording data only if i open 1st the Serial monitor.

Question:

  1. Is there any way to skip the serial monitor and storing the data on sd card without opening the serial monitor?

My point of keeping the serial monitor and having in the code Serial.print(sensor); and
dataFile.println(sensor); is because I wanna see in any time i need what kind of data is the sd card recording thru (phone/tablet/device).

I'm using Uno.

So why do you have this code?

   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

This is my actual code:

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
// ^^^^^^^^^^^^BMP180 ^^^^^^^^^^^^^^^------------------------

#include <SD.h>
const int chipSelect = 10;
// ^^^^^^^^^^^^SD CARD ^^^^^^^^^^^^^^^------

#include "I2Cdev.h"
#include "MPU6050.h"
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif
MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;
#define OUTPUT_READABLE_ACCELGYRO
bool blinkState = false;


void setup() {
    #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        Wire.begin();
    #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
        Fastwire::setup(400, true);
    #endif
    Serial.begin(9600);
    
    
    // BMP -----------------------------------------------------------------------|
      if(!bmp.begin())
  {
  //  Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }
    // BMP ------------------------------------------------------------------------|
    
    
// SD CARD ------------------------------------|    
      if (!SD.begin(chipSelect)) {
    return;
      }
    pinMode(10, OUTPUT);
//^^^^^^^^^^^^^^SD CARD ^^^^^^^^^^^^^^^^--------|
    
    
    delay(2000);
    accelgyro.initialize();

}

//  LOOP ------------------------------------------------------------------------------------------------===//

void loop() {
  

  

// BMP 180 AirPressure, Alt, Temp -----------------------------| 
  sensors_event_t event;
  bmp.getEvent(&event);
if (event.pressure)
{
  // Serial.print("Pressure:    ");
Serial.print(event.pressure);
   Serial.print(" hPa |");
    
        float temperature;
    bmp.getTemperature(&temperature);
 //   Serial.print("Temperature: ");
   Serial.print(temperature);
    Serial.print(" C |");
    
        float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
  //  Serial.print("Altitude:    "); 
    Serial.print(bmp.pressureToAltitude(seaLevelPressure,
                                       event.pressure)); 
    Serial.println(" m ");
    
    
               // SD CARD - BMP180-------------------------------------------------------------------|        
               File dataFile = SD.open("bmp.txt", FILE_WRITE);

               if (dataFile){
               dataFile.print(event.pressure);dataFile.print(" , ");   
               dataFile.print(temperature);dataFile.print(" , ");   
               dataFile.println(bmp.pressureToAltitude(seaLevelPressure,
                                       event.pressure));                       
               dataFile.close();
               }
                else{
                     delay(1);
                    }
               // SD CARD - BMP180-------------------------------------------------------------------| 
  }
  else{
    delay(1);
  }
// BMP 180 AirPressure, Alt, Temp -----------------------------| 

  
// MPU6050 ACC, GYRO -----------------------------------|
    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    #ifdef OUTPUT_READABLE_ACCELGYRO
       
        //Serial.print("a/g:\t");
        Serial.print("| X :");Serial.print(ax); 
        Serial.print("| Y :");Serial.print(ay); 
        Serial.print("| Z :");Serial.println(az); 
        //Serial.print(gx); Serial.print("\t");
        //Serial.print(gy); Serial.print("\t");
        //Serial.println(gz);
    #endif
// MPU6050 ACC, GYRO -----------------------------------|


    //X ,Y ,Z in G Force --------| MPU6050 16G Range so divide data by 2048.
    float xG;
    float yG;
    float zG;
    xG = ax / 2048.0;
    yG = ay / 2048.0;
    zG = az / 2048.0;
    //X ,Y ,Z in G Force --------|
        Serial.print("| Xg :");Serial.print(xG); 
        Serial.print("| Yg :");Serial.print(yG); 
        Serial.print("| Zg :");Serial.println(zG); 


// SD CARD - MPU6050-------------------------------------------------------------------| 
String Ax = "";         
String Ay = "";     
String Az = "";     

Ax = String(ax);   
Ay = String(ay);   
Az = String(az);   

File dataFile2 = SD.open("mpu.txt", FILE_WRITE);

if (dataFile2){
dataFile2.print(Ax);dataFile2.print(" , ");   //
dataFile2.print(Ay);dataFile2.print(" , ");  // Acceleromiter output data
dataFile2.print(Az);                       //
dataFile2.print("   ,   ");
dataFile2.print(xG, 3);dataFile2.print(" , ");   //
dataFile2.print(yG, 3);dataFile2.print(" , ");  // Acceleromiter x,y,z G-Force
dataFile2.println(zG, 3);                     //
dataFile2.close();
}
else{
  delay(1);
}
// SD CARD - MPU6050-------------------------------------------------------------------| 


Serial.println(" ");
delay(200);

}
//  LOOP ------------------------------------------------------------------------------------------------===//

This is my actual code:

Which is full of #ifdef statements. Why? You are not trying to use the code on different boards, are you? If not, ditch the code that is not needed.

                else{
                     delay(1);
                    }

What do you expect this to accomplish, if you can't open the file?

  else{
    delay(1);
  }

What do you expect this to accomplish, if you can't read from the sensor?

String Ax = "";         
String Ay = "";     
String Az = "";     

Ax = String(ax);   
Ay = String(ay);   
Az = String(az);

Pure, unadulturated bullshit.

else{
  delay(1);
}

More useless crap.

Get an LED. On every pass through loop(), toggle the state of the pin that the LED is attached to. With the Serial Monitor open, observe the flashing of the LED.

Close the Serial Monitor. Reset the Arduino. Does the LED flash?

Look I worked on this code yesterday, someone asked me to do some tests outside so i made a fast code,
i didn't worked to perfectionate it i just made it to run. about the else_delay(1) i forgot about them, i focused on the code part and make it work fast because i didn't had time.

Get an LED. On every pass through loop(), toggle the state of the pin that the LED is attached to. With the Serial Monitor open, observe the flashing of the LED.

Close the Serial Monitor. Reset the Arduino. Does the LED flash?

On arduino board there is Rx and Tx leds, the Tx led flashes (no needed to put another led), when i open the serial monitor the data starts to print out and led flashes, when I close the serial monitor the led keeps flashing (meaning the data keeps running), when i reset the board there's nothing happening, i need to open the serial monitor to "activate the loop".

I'm not sure why that's happening but i need help and a solution.

On arduino board there is Rx and Tx leds, the Tx led flashes (no needed to put another led), when i open the serial monitor the data starts to print out and led flashes, when I close the serial monitor the led keeps flashing (meaning the data keeps running), when i reset the board there's nothing happening, i need to open the serial monitor to "activate the loop".

That is nonsense. The RX and TX LEDs are controlled by the USB-to-serial converter chip. If the Serial Monitor is not opened, the RX and TX LEDs are not going to blink. Using the fact that they don't blink as proof that the Arduino is not running is silly.

Ok let me put a blink loop led and test:
With PC power
With PC power and serial / closing the serial and open / reset
With external power

I will give results in few min.