OFFscope - Offline Oscilloscope (Arduino + SD Card Fast Logging)

14,542

125

13

Introduction: OFFscope - Offline Oscilloscope (Arduino + SD Card Fast Logging)

This is not real time oscilloscope!

First you acquire signal by saving/logging it to SD card. Then you review the acquired signal on your PC.

This oFFline oscilloscope is intended for automotive sensor diagnostic. 99% of automotive sensors work in range from 0v to 5v. Ideal for Arduino. Of course, you can use it wherever you like as long you obey 0v to 5v input range.

There are many Arduino oscilloscope modifications. If you by some external hardware + arduino you will get usable real time oscilloscope. If you use only arduino as oscilloscope sampling rate will be very small, almost unusable for anything. After searching the web I found that arduino can fast log of his analog pins to SD card. Combining that with some “Processing 2” code you can have some sort of offline oscilloscope.

It is accurate and you can have up to 50000 samples per second. All, that for under 15$ ...

I will show you in 2 examples how this combination is performing against real oscilloscope.

Step 1: Stuff You Need

You have to be familiar with car oscilloscope sensor diagnostic. Probably the best tool for that is Picotech .
Price is high. Luckily here is an alternative.

You will need 3 things

Arduino Uno
(any Chinese arduino clone will be ok, e.g.: Uno R3 ch340, under 5$) Drivers for CH340

Arduino SD shield
(any Chinese clone will be ok, e.g.: “Arduino Logger Module Shield V1.0”, under 6$)

SD card (any class 10, full size 2 or 4 GB card will be ok, under 5$)

Total: arduino + SD shield + SD card = under 15$

Please note that max sampling rate will be determined by how fast is your SD card. Every SD card is unique and only by testing the card inside arduino you can see how it is performing. It is trial and error process until you find maximum sampling rate. There is NO other way!

Also there is no point in using more than 4 GB card because you have to format it in FAT16 mode.

Step 2: Hardware + Software Upload to Arduino

If you are a beginner with arduino please find some arduino tutorials on instructables

Format the SD card on your PC to fat16.

a) Connect SD shield to Arduino R3, just snap on the SD shield to arduino.
Connect + from sensor to A0 and - from sensor to GND pin on arduino

b) Download the arduino “oFFscope_v2.zip” code on the PC and extract the ZIP
and place the folders inside your Arduino 1.6.3 developer folders. You have to copy
folder “SDfat” from ZIP to your arduino install folder: Arduino-1.6.3 -> Libraries

c) Start Arduino-1.6.3 go to: File -> Examples -> Sdfat -> oFFline_scope_v2 and load the program.

Inside code you have to change this line to get the maximum logging speed from your SD card:

// Sample rate in samples per second.
const float SAMPLE_RATE = 10000;

In the example above you have set 10000 samples per one second. If you divide 1/ 10000 you will get:
100 microsecond per interval. That means arduino will read voltage on A0 (analog pin 0) every 100 microsecond
and write that value to SD card.

To achieve that speed arduino writes to binary file. After acquiring the signal and you finish logging to SD card you have to convert that binary file to CSV file (comma separated txt file) so you can work with the file.

oFFscope_v2.ino is modified work of one and only the great “fat16lib”(William Greiman). He is the master mind behind fast logging to SD card and be sure to visit his official site about fast SD logging.

On my SD card I can log up to 50000 samples per second without losing any data.

Set you sampling interval to 10000 then acquire some data and if you don’t have overruns (skipped samples) increase the sampling interval to 20000 and try logging again. After that try 30000 and so on...

When you start getting overruns that means you have hit your SD logging speed limit.

Only modification I have made is to remove file header from CSV file, log only pin 0, and change the name of the file. Everything else is the same as “fat16lib” -> “AnalogBinlogger”.

Step 3: Acquiring/logging the Data...

Upload your modified oFFscope program to your arduino and open serial monitor
from Arduino-1.6.3 (PIC1) .

You will get this small menu:

c - convert file to csv
d - dump data to Serial
e - overrun error details
r - record ADC data

To start logging press “r” on the keyboard and press enter. Arduino will show something like this (PIC2)

Press “s” key to stop logging. You will get something like this (PIC3) . Check for dropped samples!

Now press “c” to convert binary file to CSV file. You will get something like this (PIC4) .

Now you have CSV file that you can load in “processing” and review the acquired data.

Remove SD card from arduino insert SD card in some card reader and transfer CSV files to your PC.

Step 4: Review Data in Processsing 2 and Sigscope

If you are a beginner with processing check this link .

Download "Processing 2".
Download “oFFscope_v2_processing.zip”.
Extrac ZIP file and load "oFFscope_v2_processing.pde" inside “Processing 2”.

Change this line to load your CSV file :
String filename = "offSco03.csv"; // name of the file to load

Note: csv file must be in the same folder as pde file.

“RUN” the program and observe the wave form you have captured with arduino.

Inside program there are hotkeys. Feel free to explore them.
They are used to pause, move back and forward inside file, zoom in, zoom out and so on…

This great processing code is taken from other instructables. I have only
changed the part to load CSV file inside as table and browse through data.
Please read this instructables for original code.

You can also use this great tool “Sigscope” for CSV to review data. I will use this program in examples.

Step 5: Example 1 - Seconday HT Pickup From Spark Plug

If you are new to oscilloscope car sensor checking please download
from Picosope webpage their software. Install it on you PC. Inside you
will find all the explanation and examples you need to get you started.
Software is totally free.

After you install the program you can browse through help and find how
to hook up oscilloscope and get usable data from the sensors. The best
part is large waveform database.

We will use that waveforms and compare them to our oFFscope logging files.

I have captured secondary HT spark ignition waveform. That signal is fast
and you need high sampling rate to capture it. I have setup my arduino at
SAMPLE_RATE = 50000; and collected the signal.
You can download this exapmle "offSco04.csv"

Here is the piscosope example vaweform (PIC1)

Here is oFFscope_processing vaweform (PIC2)

Here is Sigscope review of the acquired data (PIC3)

Pretty solid, you can see all the crucial parts of the waveform. Not bad for 15$ :)

Step 6: Example 2 - Relative Compression - Petrol

This CSV was acquired combining oFFscope and UT-203 .

You can download this example "offSco05.csv"

Picosope example waveform (PIC1)

oFFscope waveform opened in Sigscope (PIC2)

Not bad at all :)

You can see that one cylinder has lower compression than other 3.

This is not an easy tool to work with. You have to be familiar how real
oscilloscope works and how it can help you in diagnostic. It is better to
capture multiple times same signal so you can rule out problems in
capture itself. Some signals don’t need high amount of sampling.
You can lower amount of sampling and get descent waveforms.
Compare them to Picosope waveforms.

When you got the hang of it, it can help you in diagnosing faulty
sensors in minutes.

P.S. I am not a programmer. I have modified files the best I could. If you
have some ideas to make this even better please contact me.


Be the First to Share

    Recommendations

    • Big and Small Contest

      Big and Small Contest
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • For the Home Contest

      For the Home Contest

    13 Comments

    0
    MaciejK34
    MaciejK34

    5 years ago

    Hi,

    How long signal can I record from 2 channels? Is it possible record for example 5 minutes, If I set frequency sampling 25kHz per one channel?

    Fs=25kHz per channel so 5 minutes should be 25000*60*5 = 7500000 samples ????

    Best regards

    Maciej

    0
    LelandC
    LelandC

    6 years ago

    I keep getting "Invalid Format, reformat SD." errors. I've tried two different SD cards and yes they're formated to FAT16. I tried a few other sample SD card sketches and they see the SD card just fine.

    0
    brajomobil
    brajomobil

    Reply 6 years ago

    It's best to use 2gb card. If you have 16gb or 8gb card than you have to create 2gb partition on that card and format that partition to fat16. To create partitions on SD card use "diskpart" from windows. Find on Google how to use diskpart for SD card.

    0
    SwapA
    SwapA

    6 years ago

    What a great project, hats off. Anyway to add time frame column, so the graph will actually show time vs analog values.

    0
    brajomobil
    brajomobil

    Reply 6 years ago

    Hi SwapA

    Thank you. Feel free to modify the code as you like.

    Best regards,
    brajomobil

    0
    ИгорьА1

    Cool! Frequency oscilloscope is 50K. What do you think increase frequency is possible ?

    0
    brajomobil
    brajomobil

    Reply 7 years ago

    You can go faster if you use arduino due. It has more ram for buffering before writing to SD card. Limitation is only slow SD write

    0
    brajomobil
    brajomobil

    Reply 7 years ago

    oFFscope is all fat16lib custom sd write. I have modified only the csv part. All the credits goes to him.
    I used the code from links you provided.

    0
    nqtronix
    nqtronix

    7 years ago on Introduction

    Especially when designing electronics for anything automotive related you should always add a decent input protection.

    The atmega328p microcontroller or any other from the AVR series feature ESD input protection diodes: If the voltage is higher than the system voltage + 0.5V one conducts current into the system power supply rail, the other diode conducts if the input voltage is -0.5V or lower. In one appnote they mention that those diodes can carry up to 1mA. Thus ever per 1k the inputs are proteccted from 1V over- or undervoltage.

    Also you want to add a low pass filter matching your sampling rate. The maximum measurable frequency is half the sampling rate, everything higher is noise. For more details on that look up the "nynquist sampling theorem"

    Luckely both funtions can be fulfilled with two parts, a simple passive RC low pass filter. The schematic for a 23kHz passive filter is attached. You should choose a NPO or C0G type ceramic capacitor as they provide highest accuracy over all conditions. The resistor doubles as an over- and undervoltage protection of up to 68V (transients up to 60V can be expected in automotive systems).

    Apart from this little tiny bit this is a nice solution. Of cource it can't compete with any commercial ocilloscope, but this project needs only stuff many people have at home anyway (an SD card doesn't absolutely require a shield, it can also be botched into the circuit), so it's prefect for those "I have an idea and want to do it now" situations.

    Thanks for sharing!

    0
    brajomobil
    brajomobil

    Reply 7 years ago

    You are right. Thank you for idea and shematic.

    0
    nqtronix
    nqtronix

    Reply 7 years ago on Introduction

    Uuups, forgot the schematic. Here you go:

    low pass and input protection.jpg