Logging/Recording Ethernet or Serial data to SD card

Hello,

I'm trying to see whether Arduino (with appropriate peripherals/shields) is a suitable candidate for a project that requires logging/recording ethernet or serial data to an SD card. An external trigger would signal the start/end of recording.

The Arduino Ethernet Shield 2 may not be appropriate since it's documentations states:

Note that because the W5500 and SD card share the SPI bus, only one at a time can be active

Are there other options that may be suitable?

Thanks in advance for the guidance!

consider using a Raspberry pi ? you can also communicate with it using WiFi, Bluetooth, etc

WiFi using and ESP8266 (such as a WeMOS D1 Mini) - which is voltage compatible with an SD card - instead of an Arduino,

Thank you for the suggestion.

Do you have specific modules in mind? The data stream will be wired for this project, so wifi/bluetooth are not options.

And is there a speed/throughput penalty with the OS on Raspberry Pi?

I know very little about Arduino, even less about Raspberry Pi :frowning:

Thank you for your suggestion. I forgot to mention in my original post that the data stream will be wired ethernet or RS485, so wifi is not an option for this project.

the raspberry-pi-3-model-b has built in Ethernet, SD card and a powerful 64bit processor so for data logging should have no problems. In the end writing speed to the SD card would probably be the limiting factor- how much data per second and how much data are you looking at?

Regarding RS485 I have never used RS485 with a pi but have used 3.3V TTL serial so should be no problem. connecting a TTL-RS485 converter.

Thank you for that information. I'll look into Raspberry Pi and conveeters.
The data rate is expected to be ~ 200 to 500 kilobits/s, and the total recording time ~ 200 seconds.

I don't know if something like an Uno would be fast enough for that, but a Mega should be able to handle it. But the biggest problem may be the card itself. SD cards deal with data 512 bytes at a time, which is the size of a sector. And sometimes there is a significant delay on a sector write because the card's controller has to erase sectors before writing, or even move data around if it does wear leveling. And if the file system is involved in the write, then you have to deal with updating the directory entry and the FAT tables. So while the average write speed may be ok, you might need a very large buffer to carry you through these delays without losing data.

There are ways to reduce your exposure to these problems, the best of which I've found to be illustrated in the LowLatencyLogger example in the SdFat library. Basically, he bypasses the file system altogether, and does sequential low-level sector writes to the data portion of a pre-defined, pre-erased file. Only at the end are the directory entry and FAT tables modified to reflect what was actually written. And I believe he saves to the card in binary, and has routines to convert that to a CSV readable file later when time is not pressing.

What it ususally means is that you select the Ethernet shield when you send/receive data and the SD card when you want to read/write. Libraries handle that for you. If you post the link to the shield, somebody might be able to verify.

And with any processor that is not multi-core and does not have multiple SPI buses, it will never be truely 'the same time'.

I don't think wear levelling involves "moving data around" - that would clearly be quite counter-productive. :roll_eyes:

50kbytes/sec is a lot of data/sec where is it comming from?
over 200 seconds that is 10Mbytes in total
never attempted 10Mbyte arrays on a pi - works OK on a Win10 PC using Java - will try on a pi

edit: ran following program on a Raspberry Pi 3B

// create 10Mbyte array - fill with data and print some elements to check 

public class Array10Meg {

    public static void main(String[] args) {
    int p[]=new int[10000000];
    for(int i=0;i<10000000;i++) {
      p[i]=i;
    }   
    for(int i=0;i<010;i++) {
      p[i]=i;
      System.out.println(p[i]);
    }   
    for(int i=9000000;i<9000010;i++) {
      p[i]=i;
      System.out.println(p[i]);
    }   
    }
}

runs in under a second and displays

0
1
2
3
4
5
6
7
9000000
9000001
9000002
9000003
9000004
9000005
9000006
9000007
9000008
9000009

extended program to write the array to SD card

// create 10Mbyte array - fill with data and print some elements to check 
import java.io.*;

public class Array10MegWrite {

public static void main(String[] args) {
  try {
    // create a writer
    FileOutputStream fos = new FileOutputStream(new File("output.dat"));
    BufferedOutputStream writer = new BufferedOutputStream(fos);
    int p[]=new int[10000000];
    // fill array with data
    for(int i=0;i<10000000;i++) {
      p[i]=i;
    }  
    // write array to a file
    for(int i=0;i<10000000;i++) {
      writer.write(p[i]);
    }  
    writer.close();// close file
    fos.close();
  }
 catch (IOException ex) {
    ex.printStackTrace();
 }
 try {
    // now read file back
    int p1[]=new int[10000000];
    FileInputStream fis = new FileInputStream(new File("output.dat"));
    BufferedInputStream reader = new BufferedInputStream(fis);
    int ch, i=0;
    while ((ch = reader.read()) != -1) {
        p1[i++]=ch;
    }
    System.out.println("read " + i + " bytes");
    // and print contents
    for(i=0;i<010;i++) {
      p1[i]=i;
      System.out.println(p1[i]);
    }   
    for(i=9000000;i<9000010;i++) {
      p1[i]=i;
      System.out.println(p1[i]);
    }   
 }
 catch (IOException ex) {
    ex.printStackTrace();
 }
 }
}

run of program (takes 4 or 5 seconds)

root@hotspotpi:~/Public# java Array10MegWrite
read 10000000 bytes
0
1
2
3
4
5
6
7
9000000
9000001
9000002
9000003
9000004
9000005
9000006
9000007
9000008
9000009
root@hotspotpi:~/Public# ls
Array10Meg.class  Array10MegWrite.class  output.dat
Array10Meg.java   Array10MegWrite.java
root@hotspotpi:~/Public# ls -l
total 9784
-rw-r--r-- 1 root root      736 Nov 30 01:24 Array10Meg.class
-rw-r--r-- 1 root root      361 Nov 30 01:24 Array10Meg.java
-rw-r--r-- 1 root root     2032 Nov 30 01:50 Array10MegWrite.class
-rw-r--r-- 1 root root     1299 Nov 30 01:50 Array10MegWrite.java
-rw-r--r-- 1 root root 10000000 Nov 30 01:50 output.dat

the directory listing shows a file output.dat length 10000000 has been created

no requirement to use Java - you can use C++, Python, etc etc

The data source can be one of the following:

  1. IENA/INETX UDP Ethernet: https://www.curtisswrightds.com/secure/content/documents/KAD-ETH-102-Product-sheet.pdf?ref=https%3A%2F%2Fwww.curtisswrightds.com%2Fproducts%2Fflight-test%2Fdata-acquisition%2Facrakam500%2Fmodules%2Ftransmitter%2Fkadeth102.html
  2. PCM - RS422: https://www.curtisswrightds.com/secure/content/documents/ENC_106.pdf?ref=https%3A%2F%2Fwww.curtisswrightds.com%2Fproducts%2Fflight-test%2Fdata-acquisition%2Facrakam500%2Fmodules%2Ftransmitter%2Fkadenc106.html
    Less likely (and I can only post 2 links, so I posted the ones above; but the two units below are in the same "family"as above)
  3. MIL-STD-1553: KAD/MBI103
  4. ARINC 429: KAD/ARI002

the Raspberry PI 3B has onboard 100 base Ethernet and there is a rs422-rs485-serial-hat

knowing how end users tend to add more requirements with time the pi 3B also has WiFi, BLE, HDMI video port, four USB ports, GPIO , etc etc

before you make up your mind it may be worth going onto the Reaspberry pi forum and specifing your requirements - see what feedback you get

what programming language would you use?

p.s. I found when I was running the program of post #12 using remote terminal from a Win10 PC there was a video playing in a loop on the HDMI port

"The SAMD SPI driver is often slower than UNO or Mega2560. I have given up on SAMD so I don't want a board.

To log at high rates you need something like this Teensy program that logs an ADC as text at 25,000 samples per second.

I have logged at over 1,000,000 samples per second with DMA ADC in binary on a Teensy."
ref: Need for speed · Issue #372 · greiman/SdFat · GitHub

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.