Reporgramming sparkfun openlog

Found main logging routine (lines 611-740):

//Appends a stream of serial data to a given file
//Assumes the currentDirectory variable has been set before entering the routine
//We use the RX interrupt and a circular buffer of 1024 bytes so that we can capture a full stream of
//data even at 115200bps
//Does not exit until Ctrl+z (ASCII 26) is received
//Returns 0 on error
//Returns 1 on success
uint8_t append_file(char* file_name)
{
  //44051
  //This is the size of the receive buffer. The bigger it is, the less likely we will overflow the buffer while doing a record to SD.
  //But we have limited amounts of RAM (~1100 bytes)
  #define BUFF_LEN 250 //50 works well. Too few and we will call file.write A LOT. Too many and we run out of RAM.
  //#define BUFF_LEN 400 //Fails horribly for some reason. Oh right, readSpot only goes to 255.
  //#define BUFF_LEN 100 //Works well.
  char inputBuffer[BUFF_LEN];
  char escape_chars_received = 0;
  byte readSpot = 0; //Limited to 255
  byte incomingByte;

  // O_CREAT - create the file if it does not exist
  // O_APPEND - seek to the end of the file prior to each write
  // O_WRITE - open for write
  if (!file.open(currentDirectory, file_name, O_CREAT | O_APPEND | O_WRITE)) error("open1");

#if DEBUG
  PgmPrintln("File open");
  PgmPrintln("Recording");
#endif

  Serial.print('<'); //give a different prompt to indicate no echoing
  digitalWrite(statled1, HIGH); //Turn on indicator LED

  //Clear out the serial buffer
  Serial.flush();

  //Start recording incoming characters
  //HardwareSerial.cpp has a buffer tied to the interrupt. We increased this buffer to 512 bytes
  //As characters come in, we read them in and record them to FAT.
  while(1){
    uint16_t timeout_counter = 0;

#if BOOTTIME_TESTING
    boottime = millis(); //Get the time from power on to ready to receive
    PgmPrint("Time until ready to recieve (ms): ");
    Serial.println(boottime);
#endif

#if RAM_TESTING
    PgmPrint("Free RAM receive ready: ");
    Serial.println(FreeRam());
#endif

    //Testing to try to get rid of long delay after the first synch
    //This forces OpenLog to scan the fat table and get the pointers ready before the wave of data starts coming in
    //currentDirectory.sync();
    //file.write("123", 3);
    //file.sync();
    //file.close();
    //if (!file.open(currentDirectory, file_name, O_CREAT | O_APPEND | O_WRITE)) error("open1");

    while(!Serial.available()){ //Wait for characters to come in
      if(timeout_counter++ > 1200){ //If we haven't seen a character for about 3 seconds, then record the buffer, sync the SD, and shutdown
        timeout_counter = 0;

        if(readSpot != 0){ //There is unrecorded stuff sitting in the buffer
          //Record the buffer
          if(file.write((byte*)inputBuffer, readSpot) != readSpot)
            PgmPrintln("error writing to file");
        }
        file.sync(); //Push these new file.writes to the SD card
        Serial.flush(); //Clear out the current serial buffer. This is needed if the buffer gets overrun. OpenLog will fail to read the escape character if
        //the buffer gets borked.
        
        //Reset the points so that we don't record these freshly recorded characters a 2nd time, when the unit receives more characters
        readSpot = 0;

        //Now power down until new characters to arrive
        while(!Serial.available()){
          digitalWrite(statled1, LOW); //Turn off stat LED to save power
          sleep_mode(); //Stop everything and go to sleep. Wake up if serial character received
        }
      }
      delay(1); //Hang out for a ms
    }

    incomingByte = Serial.read(); //Grab new character from hardwareserial.cpp buffer (could be 512 bytes)

    //Scan for escape character
    if(incomingByte == setting_escape_character){
#if DEBUG
      Serial.print("!");
#endif
      if(++escape_chars_received == setting_max_escape_character) break;
    }
    else
      escape_chars_received = 0;

    inputBuffer[readSpot++] = incomingByte; //Record character to the local buffer

    if(readSpot == BUFF_LEN){ //If we've filled the local small buffer, pass it to the sd write function.
      //Record the buffer
      if(file.write((byte*)inputBuffer, BUFF_LEN) != BUFF_LEN){
        PgmPrintln("error writing to file");
        break;
      }
      readSpot = 0; //Wrap the buffer
    }

    STAT1_PORT ^= (1<<STAT1); //Toggle the STAT1 LED each time we receive a character
  } //End while - escape character received or error

  //Upon receiving the escape character, we may still have stuff left in the buffer, record the last of the buffer to memory
  if(readSpot != BUFF_LEN){
    //Record the buffer
    if(file.write((byte*)inputBuffer, readSpot) != readSpot)
      PgmPrintln("error writing to file");
  }

  file.sync();
  file.close(); //Done recording, close out the file
  digitalWrite(statled1, LOW); //Turn off indicator LED

#if DEBUG
  PgmPrintln("Done!");
#endif
  PgmPrint("~"); //Indicate a successful record

  return(1); //Success!
}

Its core:

    while(!Serial.available()){ //Wait for characters to come in
      if(timeout_counter++ > 1200){ //If we haven't seen a character for about 3 seconds, then record the buffer, sync the SD, and shutdown
        timeout_counter = 0;

        if(readSpot != 0){ //There is unrecorded stuff sitting in the buffer
          //Record the buffer
          if(file.write((byte*)inputBuffer, readSpot) != readSpot)
            PgmPrintln("error writing to file");
        }
        file.sync(); //Push these new file.writes to the SD card
        Serial.flush(); //Clear out the current serial buffer. This is needed if the buffer gets overrun. OpenLog will fail to read the escape character if
        //the buffer gets borked.
        
        //Reset the points so that we don't record these freshly recorded characters a 2nd time, when the unit receives more characters
        readSpot = 0;

        //Now power down until new characters to arrive
        while(!Serial.available()){
          digitalWrite(statled1, LOW); //Turn off stat LED to save power
          sleep_mode(); //Stop everything and go to sleep. Wake up if serial character received
        }
      }
      delay(1); //Hang out for a ms
    }

    incomingByte = Serial.read(); //Grab new character from hardwareserial.cpp buffer (could be 512 bytes)

    //Scan for escape character
    if(incomingByte == setting_escape_character){
#if DEBUG
      Serial.print("!");
#endif
      if(++escape_chars_received == setting_max_escape_character) break;
    }
    else
      escape_chars_received = 0;

I should change first line of the "core" to make it sensitive to a switch rather than serial input, so logging will stop upon turning on or off or pressing the switch: this will prevent data loss and file corruption w.r.t. just unplugging the device.

Then I'll have to change this line to properly read sensors and write data:

if(file.write((byte*)inputBuffer, readSpot) != readSpot)

Here's the link for Openlog V3 sources on GitHub:

Old versions also available here:

How do I update the firmware once it's ready? Should I just connect Vcc, GND, TX and RX to Arduino? And which board should I select on IDE?

Looking at the board, I would guess that the pro-mini 328 would be similar to the open-log board. Try that and if it does work try other 328 board choices.

Reprogrammable ATmega328 using the Arduino IDE

Found in google cache:

IDE: “Arduino Pro or Pro Mini 5V/16MHz w/ ATmega328”

Get an FTDI Basic and a crossover board
Download a new copy of the Arduino IDE version 0022 into a different directory than your normal Arduino installation. For example ‘c:\arduino-0022-openlog\’. Note that Arduino v1.0 is not yet supported. Please use v0022.
Download the OpenLog firmware either directly here or by checking out the repository (more advanced and not necessary for more people)
Replace the file located here: C:\arduino-0022-openLog\hardware\arduino\cores\arduino\HardwareSerial.cpp with the HardwareSerial.cpp found in the OpenLog firmware zip file that you just downloaded. More information below.
Open the OpenLog_v2 sketch in this special version of Arduino-OpenLog and compile. (If you experience problems, make sure that Arduino isn’t referencing a newer SdFat library in your home/Arduino/libraries folder)
Connecting the FTDI Basic, then the crossover board, then the OpenLog
** Select the “Arduino Pro or Pro Mini 5V/16MHz w/ ATmega328” under the Arduino Boards tab**
Select the right COM port to connect to the FTDI Basic
Upload the code
High five your nearest neighbor

I also found this:

Version 3 of firmware looks quite different; this appears to be the code part I'll have to modify to get analog pins logged:

  //Start recording incoming characters
  while(escape_chars_received < setting_max_escape_character) {

    uint8_t n = NewSerial.read(localBuffer, sizeof(localBuffer)); //Read characters from global buffer into the local buffer
    if (n > 0) {

      if (localBuffer[0] == setting_escape_character) {
        escape_chars_received++;

        //Scan the local buffer for esacape characters
        for(checkedSpot = 1 ; checkedSpot < n ; checkedSpot++) {
          if(localBuffer[checkedSpot] == setting_escape_character) {
            escape_chars_received++;
            //If n is greater than 3 there's a chance here where we receive three esc chars
            // and then reset the variable: 26 26 26 A T + would not escape correctly
            if(escape_chars_received == setting_max_escape_character) break;
          }
          else
            escape_chars_received = 0; 
        }
      }

      file.write(localBuffer, n); //Record the buffer to the card

      STAT1_PORT ^= (1<<STAT1); //Toggle the STAT1 LED each time we record the buffer

      idleTime = 0; //We have characters so reset the idleTime

      if(timeSinceLastRecord++ > maxLoops) { //This will force a sync approximately every second
        timeSinceLastRecord = 0;
        file.sync(); //Sync the card
      }

    }
    else if(idleTime > MAX_IDLE_TIME_MSEC) { //If we haven't received any characters in 2s, goto sleep
      file.sync(); //Sync the card before we go to sleep

      STAT1_PORT &= ~(1<<STAT1); //Turn off stat LED to save power

      power_timer0_disable(); //Shut down peripherals we don't need
      power_spi_disable();
      sleep_mode(); //Stop everything and go to sleep. Wake up if serial character received

      power_spi_enable(); //After wake up, power up peripherals
      power_timer0_enable();

      escape_chars_received = 0; // Clear the esc flag as it has timed out
      idleTime = 0; //A received character woke us up to reset the idleTime
    }
    else {
      idleTime++;
      delay(1); //Burn 1ms waiting for new characters coming in
    }

  }

I received the device but can't get it working: upon connecting to FTDI and to PC, LEDs blink (in a "random" sequence", the they completely stop blinking; no prompt visible in terminal; I switch off and I extract the card, which put into a card reader shows several log files, all empty, and a log file setting baud rate to 9600 bps, just like my terminal was set.

How can I know the meaning of LEDs sequences? How can I get this thing working?!?

Remember, if you get OpenLog stuck into an unknown baud rate, there is a safety mechanism built-in. Tie the RX pin to ground and power up OpenLog. You should see the LEDs blink back and forth for 2 seconds, then blink in unison. Now power down OpenLog and remove the RX/GND jumper. OpenLog is now reset to 9600bps with an escape character of ‘ctrl+z’ pressed three consecutive times.

cyclegadget:

Remember, if you get OpenLog stuck into an unknown baud rate, there is a safety mechanism built-in. Tie the RX pin to ground and power up OpenLog. You should see the LEDs blink back and forth for 2 seconds, then blink in unison. Now power down OpenLog and remove the RX/GND jumper. OpenLog is now reset to 9600bps with an escape character of ‘ctrl+z’ pressed three consecutive times.

Command Set · sparkfun/OpenLog Wiki · GitHub

Thanks, but the config fils lets me think it's already configured at 9600 bps.

So no news from anybody?
Tips about the "led error code"?
Explanations for empty files?

I also would like to see more information from anyone who has sucessfully used OpenLog as a stand alone logging device. I am having significant issues using a seperate RTC(SPI) and Openlog to try to make a standalone logger capable of timestamping.
There is very little informtation or examples (any?) of a modified firmware for openlog.

I know this thread is 7 months old with no activity, but hopefully someone will see this.

madd0c:
I also would like to see more information from anyone who has sucessfully used OpenLog

I switched to PIC32 Pinguino Micro: PIC32-PINGUINO-MICRO - Open Source Hardware Board

Sadly to large a form factor for my needs. I appreciate the information, I do hope someone who has been able to actually get a moddded OpenLog working will chime in.
I just would like to see some examples, especially of multiple SPI devices.

Thanks in advance

I have modified the OpenLog firmware to make a portable serial uSD card data logger. This was relatively easy using the sources from the SparkFun OpenLog GitHub.

More info on my modifications can be found at http://dlkeng.cwahi.net/AVR/SD_Logger/My SD Data Logger Info.html

Unfortunately, I didn't use the SPI interface in my modifications.

It sounds very interesting!
Could you please explain how exactly to upload your firmware to openlog? Sparkfun instructions are old and unsatisfactory.

On the SparkFun Flashing Firmware web page (Flashing Firmware · sparkfun/OpenLog Wiki · GitHub), they suggest using their FTDI Basic and Crossover Breakout for FTDI boards to connect to the OpenLog board. I just used a RS-232 serial-to-TTL adapter I had instead (in the schematic on my web page for the portable serial data logger, you can see I used a MAX233 device - note, it is wired as a DTE so a null-modem adapter is needed to connect the correct signals on the DB-9 to the COM port on the PC). The signals that need to be connected are: Rx, Tx, DTR, and GND.

Anyway, after connecting the OpenLog to the PC, the Arduino software environment (Arduino 1.0 or later) is used to reprogram the OpenLog device similar to what would be done if you were programming/uploading to a standard Arduino board. In fact, the OpenLog appears to operate as an Arduino Uno, so, in the Arduino software environment, set the board under Tools->Board to Arduino Uno.

All of this is spelled out reasonably well in the Updating Firmware on OpenLog v3 section on their Flashing Firmware web page. If you follow their instructions, including obtaining the needed SerialPort and SdFat libraries, you should be able to recompile the OpenLog_v3.ino from their GitHub site and load that on your OpenLog device as a start. From there, its just a matter of modifying the original source for the feature changes you need. (If you look at the source files on my web site, you will notice I split the original OpenLog_v3.ino into multiple .ino files to make it easier to manage as separate functional modules that all get compiled into one executable by the Arduino software environment.)

hello friends...
i`ll try to edit openlog source code, but many errors when i opened this file.
some people can help?

some people can help?

Based on pictures? No.

Post the code, and the TEXT of the error messages.

mikrodb:
hello friends...
i`ll try to edit openlog source code, but many errors when i opened this file.
some people can help?

If all you are wanting is just a simple 9600 BAUD serial logger, you may want to look over this project on my page:
http://www.hackster.io/rayburne/sd-card-serial-logger

i just tried compiling with 1.0.5r2 and no issues. it ONLY uses the SD.h from the standard Arduino library, so you should not need to worry about any other code.

Ray