Go Down

Topic: Datalogger (Read 1 time) previous topic - next topic

Hi all
I just started with Arduino with UNO . If i try the Example file " Datalogger " it works well, until
the values are not higher then 99. Ower 99 the programm stops and hanging up.
the second problem on I2C the level of SCL is ok the Level of SDA goes not low enough.
Thanks for help.

PaulS

Quote
If i try the Example file " Datalogger " it works well, until
the values are not higher then 99.

You compiled, linked, and uploaded some code. Whether that was an example or not is irrelevant. We need to see that code. We need to know what you have connected to the Arduino that is providing these numbers that are or are not higher than 99 and are or are not causing problems.

Quote
the second problem on I2C the level of SCL is ok the Level of SDA goes not low enough.

And you know this how? What I2C device are you talking to?

Hi Paul
Here is the code that i tryed.
i d'ont know if it is correct to post the code here. sorry
on the 3 analog inputs i have a Pot. ( same values on the 3 analog inputs.
I think it's not the problem with the SD Card, the same result when i only send via serial.
the second problem i write to 2 boards with Atmega16 configured as Slaves ( adress 30 and 32 ).
With Bascom it works well when by writing from a Master to the 2 Slaves.
Greetings John
 
/*
  SD card datalogger

This example shows how to log data from three analog sensors
to an SD card using the SD library.
   
The circuit:
* analog sensors on analog ins 0, 1, and 2
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4

created  24 Nov 2010
modified 9 Apr 2012
by Tom Igoe

This example code is in the public domain.
   
*/

#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");
  }
}


PaulS

There is no reason to use a String. Open the file. Then loop through the array of pins, reading a value and writing to the file. Then, close the file.

The String class has known issues. Don't use it (like this) just to be lazy.

Hi Paul i read up to 32 values per second. i prefer to put the 32 values in a string and then
write the string to the SD Card.
i read in the tutorial that dataString += "," is the same like dataString = dataString + ",";
buth with dataString += "," i have the problem and with  dataString = dataString + ","; it works well.
must i calculate with more bugs like this in Arduino ? ;-)
Greetings John

PaulS

Quote
Hi Paul i read up to 32 values per second. i prefer to put the 32 values in a string and then
write the string to the SD Card.

What you prefer matters very little to the Arduino.

You could look at the source code for the String class to see what the + operator is doing, and what the += operator is doing. There are constructor and destructor calls involved, and the destructor calls free() which, in the version currently used by the Arduino IDE, has a serious bug.

You can continue shooting yourself in the foot if that makes you happy.

jwatte

Use a static char array and the "sprintf" and "strcat" functions instead.

ok Paul thanks for your tips i store all values on SD without strings.
the other problem is that the I2C will not work. when i look the signals on the Arduino board
A4 and A5 with the scope, it seems like the ports are not configured as output.
without Slaves the Port's changes when i touch only with the fingers.
I tryed with Pullup, Pulldown resistances, no change.
the board is an Arduino UNO with Atmega 328.

jwatte

SD cards use SPI (pins 11/12/13) not I2C. Is your problem related to the SD card, or related to some other device that actually uses I2C? If you're using I2C, have you called Wire.begin() ?

hello shure i use the SD Card with TWI. the I2C i use to switch analog values (32) over speed relays to an analog Input.
I have 2 Slaves Boardes with ATmega16. adress 30 and 32.
just before the void loop() i have the Wire.begin();
Must i give an adress instead of the () ?
Best regards John

Go Up