Recorded on SD card. Arduino: writing and reading micro-SD cards

For most people, microSD is just a form factor, but in reality it is not. You can easily insert any microSD card into a standard slot, but not all of them will work, since the cards differ in many ways.

Format

There are three different SD formats, available in two form factors (SD and microSD):

  • SD (microSD) - drives up to 2 GB, work with any equipment;
  • SDHC (microSDHC) - drives from 2 to 32 GB, work on devices supporting SDHC and SDXC;
  • SDXC (microSDXC) - drives from 32 GB to 2 TB (currently maximum 512 GB), work only on devices with SDXC support.

As you can see, they are not backward compatible. Memory cards of the new format will not work on old equipment.

Volume

Support for microSDXC declared by the manufacturer does not mean support for cards of this format with any capacity and depends on the specific device. For example, the HTC One M9 works with microSDXC, but officially only supports cards up to 128 GB inclusive.

Another important point is related to the storage capacity. All microSDXC cards use the exFAT file system by default. Windows has supported it for more than 10 years, it appeared in OS X starting with version 10.6.5 (Snow Leopard), Linux distributions support exFAT, but it does not work out of the box everywhere.

High speed UHS interface


An I or II is added to the UHS card logo depending on the version

SDHC and SDXC cards can support the Ultra High Speed ​​interface, which, with hardware support on the device, provides higher speeds (UHS-I up to 104 MB/s and UHS-II up to 312 MB/s). UHS is backward compatible with earlier interfaces and can work with devices that do not support it, but at standard speeds (up to 25 MB/s).

2. Speed


Luca Lorenzelli/shutterstock.com

Classifying the write and read speeds of microSD cards is as complex as their formats and compatibility. The specifications allow you to describe the speed of cards in four ways, and since manufacturers use them all, there is a lot of confusion.

Speed ​​class


The speed class macro for regular cards is a number inscribed in the Latin letter C

The Speed ​​Class is associated with the minimum write speed to a memory card in megabytes per second. There are four in total:

  • Class 2- from 2 MB/s;
  • Class 4- from 4 MB/s;
  • Class 6- from 6 MB/s;
  • Class 10- from 10 MB/s.

By analogy with the marking of regular cards, the speed class of UHS cards fits into the Latin letter U

Cards running on the high-speed UHS bus currently have only two speed classes:

  • Class 1 (U1)- from 10 MB/s;
  • Class 3 (U3)- from 30 MB/s.

Since the speed class designation uses the minimum entry value, theoretically a card of the second class may well be faster than a card of the fourth. Although, if this is the case, the manufacturer will most likely prefer to indicate this fact more explicitly.

Maximum speed

The speed class is quite enough for comparing cards when choosing, but some manufacturers, in addition to it, use the maximum speed in MB/s in the description, and more often than not even the write speed (which is always lower), but the read speed.

These are usually the results of synthetic tests under ideal conditions, which are unattainable in normal use. In practice, speed depends on many factors, so you should not rely on this characteristic.

Speed ​​multiplier

Another classification option is the speed multiplier, similar to the one used to indicate the read and write speed of optical discs. There are more than ten of them, from 6x to 633x.

The 1x multiplier is 150 KB/s, that is, the simplest 6x cards have a speed of 900 KB/s. The fastest cards can have a multiplier of 633x, which is 95 MB/s.

3. Objectives


StepanPopov/shutterstock.com

Choose the right card taking into account specific tasks. The biggest and fastest is not always the best. In certain use cases, the volume and speed may be excessive.

When buying a card for a smartphone, capacity plays a bigger role than speed. The advantages of a large drive are obvious, but the advantages of high transfer speeds on a smartphone are practically not felt, since large files are rarely written and read there (unless you have a smartphone with 4K video support).

Cameras that shoot HD and 4K video are a completely different matter: both speed and volume are equally important here. For 4K video, camera manufacturers recommend using UHS U3 cards, for HD - regular Class 10 or at least Class 6.

For photos, many professionals prefer to use several smaller cards to minimize the risk of losing all the images in force majeure circumstances. As for speed, it all depends on the photo format. If you shoot in RAW, it makes sense to invest in microSDHC or microSDXC class UHS U1 and U3 - in this case they will reveal themselves fully.

4. Fakes


jcjgphotography/shutterstock.com

No matter how trivial it may sound, it is now easier than ever to buy a fake under the guise of original cards. Several years ago, SanDisk claimed that a third of SanDisk memory cards on the market were counterfeit. It is unlikely that the situation has changed much since then.

To avoid disappointment when purchasing, just use common sense. Refrain from buying from untrustworthy sellers, and beware of offers of “original” cards that are significantly lower than the official price.

Attackers have learned to fake packaging so well that sometimes it can be very difficult to distinguish it from the original. You can judge with complete confidence the authenticity of a particular card only after checking using special utilities:

  • H2testw- for Windows;
  • If you have already experienced the loss of important data due to a memory card failure for one reason or another, then when it comes to choosing, you will most likely prefer a more expensive card from a well-known brand than an affordable “no-name” one.

    In addition to greater reliability and safety of your data, with a branded card you will receive high speed and a guarantee (in some cases even lifetime).

    Now you know everything you need to know about SD cards. As you can see, there are many questions that you will have to answer before purchasing a card. It's probably a best idea to have different cards for different needs. This way you can take full advantage of the equipment without exposing your budget to unnecessary expenses.

How to set up recording on a micro SD card, and then view the recordings on your computer.

Let's look at an example with an IP cameraOMNY PRO: 500 PRO,606M,A52,A12

1 . You bought a microSD card in the first place check it on your computer
2 .Disconnect the power to the IP camera.
3 .Unscrew the front part in dry room! It is very important! Otherwise, the camera will begin to fog up, because moisture will get inside and condensation will form over time.
4 . In front of you is a slot for installing a microSD card (max. 128 GB MicroSD)
5 . Install the microSD card, screw the front part of the IP camera tightly.
6 .Go to the WEB interface Settings/Recording Management/Memory Cards.
Make sure the camera sees the memory card. It is better to do this before installing the camera.

7 .Format the memory card by clicking "Start Disk"
The camera formats the memory card for its file system, which means that if you insert the card into a PC, you will not be able to read it, and therefore you will not be able to view the recordings either. To view recordings, use the camera's WEB interface.

Let's move on to setting up recording to an SD card.

Recording management/recording policy tab

Select the desired type.
Manually- when manually pressing the record button
By alarm- alarm events, including recording by
motion detector.
On schedule- recording in accordance with the specified schedule.

The picture shows an example, alarm recording, go to settings Anxieties and reactions

As an example, consider the most common option - motion detector (MD)

1. Check the On box to activate DD
2 .Set the sensitivity level.
Please note that on IP cameras OMNY PRO
the lower the value, the higher the sensitivity!

3 .Indicate the work schedule of the DD
4 . Reaction: We don’t put anything. If a snapshot is required, select a snapshot.
5 . Draw the detection area. An object falling into the marked area gives a DD reaction.
6 ..Save.

As a result: The motion detector is configured, the recording policy is configured, that’s enough.
DO NOT forget to set your clock!


Go to the Archive tab and select a date.
You can view the recordings and download two ways:

1. Select a file to view, the list is on the right.
This method is for viewing and downloading an entire file, starting from 1024MB in size. If the file size is less than 1024MB, you you won't see!
You can see a short recording in the timeline.

On the right we see a list of files indicating the start time and end time of the file. Check the box for files with the desired time period and click play or download. If the required file is not in the list, (in time) we turn the pages. Nearby is the download control button, where you can monitor the download status and the path to save the files.


2 .Using a timeline.
To do this, click on the view icon files/time.
Point the mouse at the time, click play, watch the recording.
Please note that by default the start time is set to 00:00:00
For example, if the SD card is not enough to record for a day, and there is a recording at 15:00, then you will not see the recording in the timeline, you need to scroll with the mouse on the scale left/right. Please also note to us the current date and time. The recordings on the SD card will be correspond set date on the IP camera. If the date on the camera was incorrect, then look for the recording using the date set on the camera.
If you need to cut and download a short segment, click on the scissors icon while viewing, this is the beginning of the segment, watch the recording until the moment you need, click again on the scissors, this is the end of the segment, the segment automatically starts downloading in sdv format
The path to save files can be found on the system-wide tab/File paths/save clips to../
Red passages indicate activation of motion detection recording.

To increase or decrease the timeline, use the icon
plus/minus.

Below are three options for opening an sdv file:

1. Open the file in the browser using the NVR recorder or OMNY PRO IP camera

Click the browse button, then specify the path and watch the video

Setting up OMNY Base

Let's look at an example with an OMNY miniCUBE (II) IP camera
I would like to immediately note that playback from WEB is at the development stage, not all functionality works.

1 . You bought an SD card in the first place check it on your computer! Otherwise, you will wonder whether the camera does not support it or the SD card is defective.
2 .Disconnect the power to the IP camera.
3 .Install microSD card(max. 128 GB Kingston, Samsung, SanDisk)
4 .Go to the WEB interface Settings/Archive, click format.
make sure the camera sees the SD card. It is better to do this before installing the camera
If the volume is very different from the real one, then some error occurred during formatting. (for example, the volume became 62MB)
You need to turn off the power to the camera, remove the memory card, insert it into the computer and carry out the recovery procedure. Then try to insert it into the camera again.

Let's move on to setting up recording to an SD card. Let's consider the option of recording using motion detection.

Events Tab/Event Types/ Double click On "motion detection" an additional option opens. configuration window

Alarm mode means exactly the detector's operating schedule.
Reaction - mark the required reactions + archive recording.
We do not touch the next tab, recording schedule. It is for permanent recording.

Go to the Video/Audio/Motion Detection tab.
Select the sensitivity level of the detector, where 1 is the minimum level.
Draw the detection area. An object falling into the marked area gives a DD reaction.
Save.

Recording to SD card using motion detection configured.
DO NOT forget to set your clock! The camera will record according to the set time.

We check that the recording is carried out exactly according to the DD and the recordings appear on the memory card.
We recommend checking it before installing the camera.

There are four options:
1) Go to the Playback tab, select a date.
The playback tab only works in Internet Explorer with the plugin installed.
You cannot download recordings using WEB, but you can play them. (Downloading has been implemented in the version since 2017)

Double click on the file from the list on the right to play.

2. The second option is to use the IPCmanager program.
Right-click on the found camera and select playback.

3) The third option is to download the recording.
Disconnect the camera, remove the memory card, insert it into the computer and upload the files.
The files will be in avi format but cannot be played using Windows., you will need a special
Briefly why this is so: Additional options have been added to avi. codecs for control (rewind playback, etc.) standard avi cannot do this.

4) The fourth option is to access the camera via FTP through Windows Explorer
Open Explorer, enter the camera address ftp://IP_ADDRESS/mnt/mmc/
If there is an error, update the folder. We copy the necessary records to our computer. To playyou will need a special
The new version of IPCManager contains a file converter

There are many different types of storage media based on so-called flash memory. We use regular flash drives to transfer files to each other, micro-SD cards to increase free space in smartphones, even instead of the good old hard drive in modern laptops we use SSD media - the same flash memory.

Flash memory has no moving parts, unlike vintage floppy disks and newer hard drives. The reading and writing speed of such memory is higher than that of all previous media, and power consumption is, on the contrary, lower. In other words, if we want to store some data in our electronic devices and robots, then it would be rational to use flash memory.

Why might you need a memory card? For example, in order to record data from various sensors of our device onto it. In addition to the sensor readings themselves, it is also rational to record the time these readings were taken - this is called logging. Thus, by connecting temperature, humidity and pressure sensors to Arduino, as well as a real-time clock and a memory card, we can make a real weather station!

Let's look at exactly how the memory card is connected to Arduino and how it is written and read.

1. Connecting the micro-SD card module to Arduino

The module is connected to Arduino via the SPI bus, which means you need to connect the contacts already familiar from other lessons in the standard order:

Micro-SD card module GND VCC C.S. MOSI MISO SCK
Arduino Uno GND +5V 4 11 12 13

Schematic diagram

Layout appearance

2. Program for reading micro-SD cards

To check the operation of the device, we will write a simple program that will only read service information from the card: card type, file system type, size of the first partition and a list of files on it.

#include #include Sd2Card card; SdVolume volume; SdFile root; const int chipSelect = 4; void setup() ( Serial.begin(9600); Serial.print("\nInitializing SD card..."); if (!card.init(SPI_HALF_SPEED, chipSelect)) ( // incorrect connection or card is faulty Serial.println ("initialization failed"); return; ) else ( // everything is ok! Serial.println("Wiring is correct and a card is present."); ) // read the card type and output it to the COM port Serial.print ("\nCard type: "); switch (card.type()) ( case SD_CARD_TYPE_SD1: Serial.println("SD1"); break; case SD_CARD_TYPE_SD2: Serial.println("SD2"); break; case SD_CARD_TYPE_SDHC: Serial .println("SDHC"); break; default: Serial.println("Unknown"); ) // initializing the file system if (!volume.init(card)) ( // invalid file system Serial.println("Could not find FAT16/FAT32 partition."); return; ) // read the type and calculate the size of the first partition uint32_t volumesize; Serial.print("\nVolume type is FAT"); Serial.println(volume.fatType(), DEC); Serial.println();volumesize = volume.blocksPerCluster(); // blocks per cluster volumesize *= volume.clusterCount(); // clusters volumesize *= 512; // 512 bytes in a block, total bytes.. Serial.print("Volume size (bytes): "); Serial.println(volumesize); Serial.print("Volume size (Kbytes): "); volumesize /= 1024; Serial.println(volumesize); Serial.print("Volume size (Mbytes): "); volumesize /= 1024; Serial.println(volumesize); Serial.println("\nFiles found on the card (name, date and size in bytes): "); root.openRoot(volume); // display a list of files root.ls(LS_R | LS_DATE | LS_SIZE); ) void loop(void) ( )

Load the program into Arduino and open the COM port monitor:

If such information appears, then everything is in order with the card and module. You can begin further work.

3. Program for recording data on a micro-SD card

Now let’s try to create a new file on the map and write a simple phrase “Hello from robotclass” there.

#include #include const int chipSelect = 4; void setup() ( Serial.begin(9600); if (!SD.begin(chipSelect)) ( Serial.println("Card failed, or not present"); return; ) // the string that we will write to the file String dataString = "Hello from RobotClass"; // open the file into which the string will be written File dataFile = SD.open("test.txt", FILE_WRITE); if (dataFile) ( // write the string to the file dataFile.println(dataString ); dataFile.close(); Serial.println("Success!"); ) else ( // print an error if the file could not be opened Serial.println("error opening file"); ) ) void loop() ( )

Download the program. Then turn off the Arduino, remove the micro-SD card from the module and check its contents on the computer. The file test.txt with our phrase “Hello from RobotClass” should appear in the root of the map.

Note! The file name specified in the open function must not contain more than 8 letters (not including the extension).

4. Program for reading data from a micro-SD card

Finally, we will read the test.txt file and output the text from it to the COM port.

#include #include const int chipSelect = 4; void setup() ( Serial.begin(9600); if(!SD.begin(chipSelect))( Serial.println("initialization failed!"); return; ) // open the file for reading File myFile = SD.open( "test.txt"); if (myFile) ( // read all bytes from the file and output them to the COM port while (myFile.available()) ( Serial.write(myFile.read()); ) // close file myFile.close(); ) else ( // print an error if the file could not be opened Serial.println("error opening test.txt"); ) ) void loop() ( )

Load the program and open the COM port monitor. All text from the test.txt file should appear on the screen

Conclusion

In the next lesson we will try to add a real time clock and a temperature sensor to the circuit. By leaving such a device for the whole day, we can eventually build a daily temperature graph.

An attempt to save new information on a micro CD will fail if it is write-protected. There may be different reasons for the access denied message to appear. You can remove protection from microSD using several methods - software and physical. Let's look at the most relevant ones.

Unlocking microSD

Place the memory card on a flat surface or in the palm of your hand with the label facing up. On the top left side of the card body, find the small lock switch lever - the Lock button. “Locker” serves to protect information from accidental erasure. The lever can be flat and only slightly protrude from the body, and be white or silver in color. There is no such switch directly on microSD. Insert the card into the adapter and locate the Lock switch on the adapter itself. Move it all the way in the opposite direction.

After moving the Lock lever to the position of canceling the data protection status, the reappearance of the write error notification window may be caused by moving the Lock back to the protection position. This happens due to the weakening of the switch; when you insert a memory card into the card reader, it moves and turns on the memory lock. Secure it with a piece of rubber band, cardboard, or remove it completely.

You can avoid automatic blocking of recording on microSD by removing its contact with the Lock button on the adapter body. Find a small notch on the left side of the micro-flash drive, solder it with plastic or seal it with tape. Soldering must be done very carefully. The option with tape is simpler, but it can get stuck when inserting the card into the adapter.

Changing disk properties

If the memory card protection does not allow you to copy information to another drive, but you need to save it, then try removing the protection as follows. Connect the micro CD to your computer, find its name in the list of devices and right-click on it. From the menu, select the “Properties” line, then the “Access” tab. In the next window there is “Advanced settings”, open it and check the box “Share”, confirm the settings - “Ok”.

Formatting a microSD memory card

Sometimes, to remove protection from a memory card, it is recommended to format it if the “locker” is missing or did not help. Save important information to another disk, because... it will be completely deleted. You can programmatically remove the write lock on the card using Windows.

Install a microSD memory card on a personal computer via a special adapter directly or through a card reader. Modern laptops already have such a connector; it is usually marked with a “card” icon and looks like a narrow slot. The operating system will recognize the drive and its name will appear in the list of devices on your computer.

Right-click on the CD disk icon and select “Format ...” from the expanded menu. Set the file system to the one that your device supports, usually NTFS. Click "Get Started." All information on the disk has now been deleted and the protection status has been removed.


Changing the file system

When writing a file larger than 4 GB to a memory card, an error notification window may appear due to file system limitations. If the memory card is formatted with FAT32, the file size is one of its limitations for recording data. You should change the file system to NTFS, as described in paragraph 3.


Software tools for microSD

You can reset the write protection on a disk using software without deleting the information. There are various scripts and utilities for this, for example reset.zip. When downloading software from the Internet, you should be careful - it may contain viruses. It is better to use proven applications to remove protection. Low-level formatting of a disk with the Hard Disk Low Level Format Tool erases all data, but will help restore even hopeless flash drives that were not formatted using Windows internal means.

Removing microSD protection via a mobile device

Modern mobile devices: players, PDAs, phones, cameras have a microSD formatting function. Try to find this option through the settings and format the flash drive directly on this device. Memory protection could be software installed in the device to ensure data confidentiality. You can also remove protection in the settings. All types of electronic devices have their own characteristics, so if you have any difficulties, read the gadget’s instructions or get an explanation from a specialist at the service center.

Use only the “native” adapter with a microSD card. With another adapter, even if you were able to format the phone, you most likely won’t be able to write the information to disk.

For most people, microSD is just a form factor, but in reality it is not. You can easily insert any microSD card into a standard slot, but not all of them will work, since the cards differ in many ways.

Format

There are three different SD formats, available in two form factors (SD and microSD):

  • SD (microSD) - drives up to 2 GB, work with any equipment;
  • SDHC (microSDHC) - drives from 2 to 32 GB, work on devices supporting SDHC and SDXC;
  • SDXC (microSDXC) - drives from 32 GB to 2 TB (currently maximum 512 GB), work only on devices with SDXC support.

As you can see, they are not backward compatible. Memory cards of the new format will not work on old equipment.

Volume

Support for microSDXC declared by the manufacturer does not mean support for cards of this format with any capacity and depends on the specific device. For example, the HTC One M9 works with microSDXC, but officially only supports cards up to 128 GB inclusive.

Another important point is related to the storage capacity. All microSDXC cards use the exFAT file system by default. Windows has supported it for more than 10 years, it appeared in OS X starting with version 10.6.5 (Snow Leopard), Linux distributions support exFAT, but it does not work out of the box everywhere.

High speed UHS interface


An I or II is added to the UHS card logo depending on the version

SDHC and SDXC cards can support the Ultra High Speed ​​interface, which, with hardware support on the device, provides higher speeds (UHS-I up to 104 MB/s and UHS-II up to 312 MB/s). UHS is backward compatible with earlier interfaces and can work with devices that do not support it, but at standard speeds (up to 25 MB/s).

2. Speed


Luca Lorenzelli/shutterstock.com

Classifying the write and read speeds of microSD cards is as complex as their formats and compatibility. The specifications allow you to describe the speed of cards in four ways, and since manufacturers use them all, there is a lot of confusion.

Speed ​​class


The speed class macro for regular cards is a number inscribed in the Latin letter C

The Speed ​​Class is associated with the minimum write speed to a memory card in megabytes per second. There are four in total:

  • Class 2- from 2 MB/s;
  • Class 4- from 4 MB/s;
  • Class 6- from 6 MB/s;
  • Class 10- from 10 MB/s.

By analogy with the marking of regular cards, the speed class of UHS cards fits into the Latin letter U

Cards running on the high-speed UHS bus currently have only two speed classes:

  • Class 1 (U1)- from 10 MB/s;
  • Class 3 (U3)- from 30 MB/s.

Since the speed class designation uses the minimum entry value, theoretically a card of the second class may well be faster than a card of the fourth. Although, if this is the case, the manufacturer will most likely prefer to indicate this fact more explicitly.

Maximum speed

The speed class is quite enough for comparing cards when choosing, but some manufacturers, in addition to it, use the maximum speed in MB/s in the description, and more often than not even the write speed (which is always lower), but the read speed.

These are usually the results of synthetic tests under ideal conditions, which are unattainable in normal use. In practice, speed depends on many factors, so you should not rely on this characteristic.

Speed ​​multiplier

Another classification option is the speed multiplier, similar to the one used to indicate the read and write speed of optical discs. There are more than ten of them, from 6x to 633x.

The 1x multiplier is 150 KB/s, that is, the simplest 6x cards have a speed of 900 KB/s. The fastest cards can have a multiplier of 633x, which is 95 MB/s.

3. Objectives


StepanPopov/shutterstock.com

Choose the right card taking into account specific tasks. The biggest and fastest is not always the best. In certain use cases, the volume and speed may be excessive.

When buying a card for a smartphone, capacity plays a bigger role than speed. The advantages of a large drive are obvious, but the advantages of high transfer speeds on a smartphone are practically not felt, since large files are rarely written and read there (unless you have a smartphone with 4K video support).

Cameras that shoot HD and 4K video are a completely different matter: both speed and volume are equally important here. For 4K video, camera manufacturers recommend using UHS U3 cards, for HD - regular Class 10 or at least Class 6.

For photos, many professionals prefer to use several smaller cards to minimize the risk of losing all the images in force majeure circumstances. As for speed, it all depends on the photo format. If you shoot in RAW, it makes sense to invest in microSDHC or microSDXC class UHS U1 and U3 - in this case they will reveal themselves fully.

4. Fakes


jcjgphotography/shutterstock.com

No matter how trivial it may sound, it is now easier than ever to buy a fake under the guise of original cards. Several years ago, SanDisk claimed that a third of SanDisk memory cards on the market were counterfeit. It is unlikely that the situation has changed much since then.

To avoid disappointment when purchasing, just use common sense. Refrain from buying from untrustworthy sellers, and beware of offers of “original” cards that are significantly lower than the official price.

Attackers have learned to fake packaging so well that sometimes it can be very difficult to distinguish it from the original. You can judge with complete confidence the authenticity of a particular card only after checking using special utilities:

  • H2testw- for Windows;
  • If you have already experienced the loss of important data due to a memory card failure for one reason or another, then when it comes to choosing, you will most likely prefer a more expensive card from a well-known brand than an affordable “no-name” one.

    In addition to greater reliability and safety of your data, with a branded card you will receive high speed and a guarantee (in some cases even lifetime).

    Now you know everything you need to know about SD cards. As you can see, there are many questions that you will have to answer before purchasing a card. It's probably a best idea to have different cards for different needs. This way you can take full advantage of the equipment without exposing your budget to unnecessary expenses.