📜 ⬆️ ⬇️

How I logged on SD card Shield V2.0

Hi, Habr!

image It took me an urgent need to collect a simple data logger for one old industrial gas analyzer, which had only current outputs on paper recorders. It seems a simple task, but she amused me notably. Details of this story under the cut. Conclusions there.


')
The task was really the simplest. But as always, everything is urgent. I did not want to spend money on an industrial logger, and Arduino UNO was in the supply. A five-minute question walk and found a suitable nameplate that was well suited for this task. The DOG-4 industrial gas analyzer, which needed to be connected to a logger, has only outputs to paper recorders. Conclusions current 0..5 mA for each analyzed gas (NO and SO2).
By the way, the optical gas analyzer is an excellent and reliable design, but the obsolete electronics inside spoils the whole thing. The task was to pologigirovat data during the week and write them in electronic form for calculations to technologists. No further details were said.
The label found on the Internet was ordered at this (by the way, very good) store and was delivered the next day to Tomsk from Novosibirsk. The description label is very convenient, it has a prototyping area, which I hoped to use in this simple project. It is enough to load the current outputs of the recorders, for example, on 1 kOhm resistors pulled up in the ground and you will receive digital data from the device for the entire measurement range. Arduino’s ADC bit size of 10 bits was quite convenient for technologists (of course, it’s much more fun to rip data off paper tapes). Parcel arrived, beautiful packaging, description as in the online store. Indicated the presence of a site for prototyping, on which it was necessary to solder only two resistors.

However, the autopsy showed that the nameplate does not match the description. That's what actually was in the box. Instead of a prototyping site, there was a power switch of 5 - 3.3 V, the purpose of which remained unclear to me, since initially it would have been more sensible to take 3.3 V power from the Arduino board and power the SD card without the risk of burning the card. Switching the switch to 5 V immediately supplies five-volt power to the card, thereby conscientiously disabling it in the future. Fun Chinese electronics. It is clear that the power supply was immediately served correctly at 3.3 V. The library for working with the device downloaded from the manufacturer’s official page also turned out to be a highlight. She just did not work.
The nameplate uses 4 pins of Arduino, according to this table. Here, thank God, nothing is confused.

Already thinking about starting to program the correct operation of this device myself, I remembered that in versions of the Arduino IDE 1.0+, developers everywhere for some reason began to use the definition #include “Arduino.h” instead of #include “WProgram.h "And therefore the old libraries stopped working in later versions of the Arduino IDE. Returning to the library from the manufacturer’s website, I discovered that it is for this reason that I cannot “start” it. Treated the situation is quite simple. In files with the .h and .cpp extensions, the line #include "WProgram.h" must be replaced with such a construction

#if defined(ARDUINO) && ARDUINO >= 100 #include "Arduino.h" #else #include "WProgram.h" #endif 


After that, the library will work in any version of the Arduino IDE. You can do it yourself, or you can download the already updated version of the library at this link .

The final code of my logger for the gas analyzer is unlikely to be interesting for the post, but I give a simple example for familiarization. This is how the working code will look like to write data to the SD card, which will write the phrase “Hello, Habrahabr!” To the file every 5 seconds.

 #include "FileLogger.h" //     3,3   8  #define MEM_PW 8 void setup(void) { pinMode(MEM_PW, OUTPUT); //   8      digitalWrite(MEM_PW, HIGH); } void loop(void) { byte buffer[] = "Hello, Habrahabr! \r\n"; unsigned long length = sizeof(buffer)-1; // ! int result = FileLogger::append("data.log", buffer, length); delay(5000); //  5  } 


A few important notes. Before you start recording, you must format the card (FAT16) and open an empty file with the name that will be used in the program. In the example, this is data.log. Do not pull the card out of the nameplate on the "hot". It is better to provide for software power off with the digitalWrite command (MEM_PW, LOW);
If your data is a variable length, use the string length calculation. In the example, this is unsigned long length = sizeof (buffer) -1. Inaccuracies in the length of the phrases lead to a failure of the recording process and you can get a broken file instead of data.

findings

The nameplate turned out to be quite working. Excellent data writing speed. Of course, it is not very pleasant that the description is not true, but it is even amusing and makes it possible to think a little about brains. By the way, the same label can be used for mini SD. Connector for such a card is on the reverse side.

Have a nice day, everyone!

Source: https://habr.com/ru/post/239171/


All Articles