Tag Archives: SD-card

Raspberry Pi Backup Guide

Make a sustainable Raspberry Pi backup server and save your files from occasional loss.

Raspberry Pi backup is what you really need if you work on Raspbian. Believe me, you do! If you backup your Raspberry Pi SD card in due course, someday it may save your files and your project. Alike any other hardware, the RPi devices may sometimes simply stop working.

It can occur due to a number of reasons: overheating, errors, energy supply issues, cable connection failure… All these problems will make you unplug and plug-in again the device to restart it. And such actions taken repeatedly will certainly lead to spoiling your SD card you are saving your work files to.

On the other hand, you can damage or delete your files occasionally with your own hands! There a lot of examples when we do something wrong because of the overall tiredness, inattentiveness or just being in a hurry.

IdIoTware SD Card Temperature Logger

In this tutorial at hackster.io you will learn how to log data from LM35 temperature sensor values to an SD card and store it as CSV file.

In order to build this project you need the following parts:

  1. Arduino UNO
  2. idIoTware Shield
  3. USB-A to B Cable
  4. SD Card (up to 8GB)
  5. 2x Generic Jumper (0.1″)

 

The Idiotware Shield is a learning platform that offers both novices and advanced Arduino users
the opportunity to bring hundreds of projects to life quickly. it offers a large variety of wireless communication options, input sensors, outputs, storage and device extensibility.

 

The idIoTware shield has a built in lm35 sensor that has a sensitivity of 10mV / oC, that means according to this equation: Temperature ( oC) = Vout * (100 oC/V)

That if Vout is 0.5V , then, Temperature = 50 oC. However, this built-in sensor gives a higher analog voltage on pin A0 if a higher temperature was applied.

To set up the IdIoTware shield you need to connect  LM35 sensor to SEL0 3 pin header by using a jumper. The SD card should be connected to D6 and SD pin header, thus we need antoher jumper to enable it.
By uploading this code to your Arduino, you will create a CSV file with every one minute for 15 minutes. The temperature will be logged to the file thanks to the SdFat library used. You can edit the rate and duration as you prefer.

/* 
 The circuit:
 * LM35 sensor on analog pin A3
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
 */

#include <SPI.h>
#include <SdFat.h>
SdFat sd;
const uint8_t chipSelect = 6;

//const int chipSelect = 4;   //cs pin of SD card shield
int tempPin = A3;      // LM 35 is connected to A3 pin.
int buzzerPin = A2;    // buzzer is connected to A2 pin

File dataFile;   // the logging file
char filename[] = "Temp000.CSV";
float tempInCelcius;
float tempInFarenheit;
unsigned long time=0;
int samplingTime = 10;  //this variable is interval(in Seconds) at which you want to log the data to SD card.
int duration = 15;     //this variable is duration(in Minutes) which is the total time for which you want to log data.


void setup() 
    {
      // Open serial communications and wait for port to open:
      Serial.begin(9600);
      while (!Serial)
          {
            ; // wait for serial port to connect. Needed for native USB port only
          }

      Serial.print("Initializing SD card...");

     // see if the card is present and can be initialized:
     if (!sd.begin(chipSelect))  
        { sd.initErrorHalt();
          Serial.println("Card failed, or not present");
          // don't do anything more:
          return;
        }
     Serial.println("card initialized.");

     // create a new file
     for(unsigned int i = 0; i < 1000; i++) 
        {
          filename[4] = i/100 + '0';
          filename[5] = ((i%100)/10) + '0';
          filename[6] = i%10 + '0';
          if(! sd.exists(filename)) 
            {
              // only open a new file if it doesn't exist
              dataFile = sd.open(filename, FILE_WRITE);
              break;  // leave the loop!
            }
        }

      if(! dataFile) 
        { //alert user
          Serial.println("couldnt create file");
          int alertAlarm1[] = { 1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,
                           1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,};
          int noteDurations[] = { 5,5,5,5,5,5,5,5,5,5,5,
                                  5,5,5,5,5,5,5,5,5,5,5 };
          for (int thisNote = 0; thisNote < 20; thisNote++) 
             {
               // Duration = 1 second / note type
               // e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
               int noteDuration = 2500 / noteDurations[thisNote];
               tone(A2,alertAlarm1[thisNote], noteDuration);
               //pause for the note's duration plus 100 ms:
               delay(noteDuration + 100);
             }
        }

     Serial.print("Logging to: ");
     Serial.println(filename);
     
     dataFile = sd.open(filename, FILE_WRITE);
     // if the file is available, write to it:
     if (dataFile) 
       { 
         dataFile.print("Logging Temperature for ");
         dataFile.print(duration);
         dataFile.print(" minutes at interval of ");
         dataFile.print(samplingTime);
         dataFile.println(" seconds.");
         
         dataFile.close();
       }
      // check availble space on SD Card
      uint32_t freeKB = sd.vol()->freeClusterCount();
      freeKB *= sd.vol()->blocksPerCluster()/2;
      Serial.print("Free space KB: ");
      Serial.println(freeKB);
      uint32_t freeMB= freeKB/1024;
      Serial.print("Free space in MB: ");
      Serial.println(freeMB); 
      
      if(freeKB <= 500)
        {
          Serial.println("LOW SPACE!!!");
          int alertAlarm2[] = { 1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,
                               1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000};
          int noteDurations[] = { 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
                                  15,15,15,15,15,15,15,15,15,15,15,15,15,15,15  };
          for (int thisNote = 0; thisNote < 20; thisNote++) 
             {
               // Duration = 1 second / note type
               // e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
               int noteDuration = 2500 / noteDurations[thisNote];
               tone(A2,alertAlarm2[thisNote], noteDuration);
               //pause for the note's duration plus 50 ms:
               delay(noteDuration + 50);
             }
        }
     duration *= 60;   //convert durartion in minutes to seconds   
   }

void loop() 
    {
      dataSamples();    // here we are logging data at interval of 1 minute for 15 mintutes, i.e, 15 samples.
                            // if you want to save data for 2 hours then simply multiply 2 by 60 which will give 
                            // you value of 120 minutes then use 120 as second parameter.
    }

// this method will log data to SD card at particular interval and for paricular duration
int dataSamples()
   { 
     // here we are logging data at interval of 1 minute for 15 mintutes, i.e, 15 samples.
     // if you want to save data for 2 hours then simply multiply 2 by 60 which will give 
     // you value of 120 minutes then change the varible duration to 120. 

      tempInCelcius = ( 5.0 * analogRead(tempPin) * 100.0) / 1024.0;
      
      // uncomment following line to get temperature values in Farehniet
      //tempInFarenheit = ((tempC*9)/5) + 32;            //convert celcius to farenheit
      
      unsigned long  elapsedTime = millis()/1000;   // this variable will keep track of elapsed time
      while(((millis()/1000)-elapsedTime) < 1);    // this loop will do nothing until a second has passed 
      time++;                                       //increment time after each second.
 
      if((duration >= time) && (time % samplingTime == 0))
        {
          LogToSDcard();  //Log to SD using commands under void LogToSD()  
          // print to the serial port too:              
          Serial.print("Temperature: ");
          Serial.print(tempInCelcius);
          Serial.print(char(176)); 
          Serial.println("C");     
        }
           
   }
   
void LogToSDcard()
   {
     // open the file. note that only one file can be open at a time,
     // so you have to close this one before opening another.
     dataFile = sd.open(filename, FILE_WRITE);
     // if the file is available, write to it:
     if (dataFile) 
       { 
         dataFile.print(tempInCelcius);   
         dataFile.println("°C");
         dataFile.println(",");
         dataFile.close();
         
     // to print temperature values in Farehniet uncomment following code.    
         
      /*  dataFile.print(tempInFarenheit);
         dataFile.print("°C");
         dataFile.println(",");
         dataFile.close();   */
       } 
  
      //if the file isn't open, pop up an error:
     else 
        {
          Serial.println("error opening datalog.txt");
          delay(2000);
        }
   }   
 

As soon you get the CSV file copied from the SD card, you can visualize the data in graphs.

This video by IdIoTware team demonstrates how to build this project in details, check it out:

You can check the project’s page for more information and detailed tutorial.

 

Orange Pi PC2 $20 Quad core Linux Computer

Shenzhen Xunlong Software CO., Limited is now offering  a new addition to the community of single board computers. The latest edition of Orange Pi is the $20 Orange Pi PC 2.
Even though this 85mm×55mm board isn’t as cheap as the $4 VoCore2 Lite, its $20 price tag is justified by the hardware it packs inside. And, it also saves you $15 if you don’t want to go for the $35 Raspberry Pi 3. Orange Pi PC 2 is a single-board quad-core 64-bit computer capable of running Android 4.4, Ubuntu, Debian, Banana Pi, and Raspberry Pi images.

best-seller-orange-pi-pc-h3-support-the-lubuntu-linux-and-android-mini-pc-beyond-raspberry

The board includes an Ethernet port and three USB ports. It has 1GB of memory, H5 High Performance Quad-core 64-bit Cortex-A53, and a standalone graphics chip. It supports camera input as well as HDMI out and even has a physical power switch and IR blaster. It takes power using a separate power connector despite the fact that it has a micro-USB port. The absence of WiFi and Bluetooth is a slight turn-down but USB 2.0 ports can be used to add these things.

orangepipc2_info

Full hardware specifications

CPU: Allwinner H5 64-bit Quadcore (Cortex-A53).
RAM: 1GB DDR3.
GPU: Mali-450.
Storage: 2MB NOR Flash, up to 64GB via MicroSD card.
Connectivity: 2xUSB 2.0, 1xUSB 2.0 OTG, HDMI, 10/1000 RJ45, IR receiver, camera interface, 40-pin header.
Audio: 3.5mm jack, inbuilt mic.
Operating System: Ubuntu Debian, Raspbian, Android.
This board is an advanced edition of the recent Orange Pi PC with different CPU, GPU and Ethernet connection.

Getting Started with Orange Pi PC 2

  1. You need to get these accessories to start using your Orange Pi:
    TF card (minimum 8 GB), HDMI to HDMI lead or HDMI to DVI lead (for monitors with DVI input), AV video lead, DC power adapter, keyboard and mouse, plus Ethernet cable/USB WiFi and Audio lead as an option.rms
  2. Prepare your TF card
    1. Insert your TF card into your computer. The size of TF should be larger than the OS image size, generally 8GB or greater.
    2. Format the TF card. (using this tool for Windows, and some commands for Linux)
      1. Run fdisk –l  /dev/sdx command to check the TF card node.
      2. Run umount /dev/sdxx to unmount all the partitions of the TF card.
      3. Run sudo fdisk /dev/sdx command to configure TF card. Use o command to delete all partition of TF card and use n command to add one new partition. Use w command to save change.
      4. Run sudo mkfs.vfat /dev/sdx1 command to format the new created partition of TF card as FAT32.
        (x should be replaced according to your TF card node)
    3. Download the OS image from the Downloads webpage.
    4. Unzip the download file to get the OS image
    5. Write the image file to the TF card using this software on Windows and this command on Linux: sudo dd bs=4M if=[path]/[imagename] of=/dev/sdx (x should be replaced according to your TF card node)
  3. Set up your Orange Pi PC following the steps in the diagram
    sketch_map_pipc_en
    Note : Avoid using the micro-usb power connector, because micro-usb power does not supply power.
  4. Shut down your board
    You can use the GUI to shut down the Orange Pi PC2 safely or just run this command in the terminal:  sudo halt or  sudo shutdown –h now
    This will shutdown the PI safely, (just use the power key to turn off might damage the TF-cards file system). After that you can press the power key for 5 seconds to turn it off. Full guide and any updates on the OS image will be available here.

This open source SBC (single board computer) is a great option to start building IoT devices, DIY projects and for development purposes. You can use it as a mini-computer, a wireless server, music and video player,etc. You should remember that the limit is the sky when it comes to open source boards.

The Orange Pi PC 2 is up for sale on AliExpress and you can get it now for $20. You can apply for free products from Orange Pi through this application by defining your purpose of using the product and following the steps mentioned here.

You can check the official website to find more details and updates about Orange Pi PC2 and other boards from Orange Pi. Codes and source files are available at Github.

SD Card Sound Player

audio3

fasoft @ elektormagazine.com has a new project proposal about a SD Card Sound Player.

Searching for a powerful gong or acoustic notifier? The “Card Sound” consists of audio amplifier TDA7266 having 2x 7 W output, the AD converter CS4344, one STM32F401 and a slot for micro sd card. Objective is to play different sounds stored on an SD card. Current schematic has one TWI port for control. Amend other interfaces like RS-485, UART, SPI etc. is also possible.

SD Card Sound Player – [Link]

ulibSD – a library for use SD cards in SPI mode with uControllers

SD_Card_SPI

electronictechnician.wordpress.com has published a library for use SD cards in SPI completely written in C.

It’s a library for use SD cards in SPI mode with uControllers, entirely written in C. This library can work with SD cards and also has the possibility to emulate the behavior in a PC file (GNU/Linux) using the macro _M_IX86. It’s for debugging purposes. The data transfer is oriented to 512 byte size, remember this.

ulibSD – a library for use SD cards in SPI mode with uControllers – [Link]

WiGPSFi – ESP8266 + GPS module

image-3

euerdesign.de has connected the ESP8266 to an GPS and a SD-Card to scan networks – coded a MySQL-DB with some PHP parsers and dynamic maps – and get fascinated by all the 2,4 GHz radiation arround him.

In this blogpost, you can only read about finding and printing out maps with WiFi-Accesspoints and not how to crack them! I did not connected to any of this WiFis and you should also refrain. The ESP is only listening passivly!

WiGPSFi – ESP8266 + GPS module – [Link]

Soil Moisture Sensor with SD logging

FB0O74GIK8KSP3E.MEDIUM

WojciechM3 @ instructables.com has build an Arduino based soil moisture sensor with character LCD, real time clock and SD card logging.

It can be very helpful with a master degree biotechnology/biology/botanics works, however remember that kind of a project can be only add as a bonus as it is in my Master thesis. Good luck with building it!

Soil Moisture Sensor with SD logging – [Link]

Hacking the Zsun WiFi SD Card Reader

zsun_top_annot

makers @ hackerspace.pl decided to hack the Zsun Wifi SD Card Reader and run OpenWrt on it and turn it on a awesome wifi device.

Hacking the Zsun WiFi SD Card Reader – [Link]

Datalogging Accelerometer Data To An SDCard

msp430_datalogger_sdcard

MindForge @ 43oh.com build a datalogger board which logs accelerometer values on a SD Card. The datalogger is built around an MSP430G2755 microcontroller and ADXL335 accelerometer sensor from Analog Devices.

his project started as an EMG datalogger to study my dad’s Parkinson’s disease, but after some testing I determined wearing electrodes wasn’t practical for the long term datalogging that I wanted to do, the data ended up very noisy due to RF interference and shoddy electrode to skin connections.
I moved away from the EMG idea and began working on a low-cost low-power consumption accelerometer datalogger instead.

Datalogging Accelerometer Data To An SDCard – [Link]

Simple Arduino SD-Card GPS/NMEA Datalogger

20160122_134926-1024x576

KF5OBS @ jaunty-electronics.com shows us how to build a minimalistic GPS datalogger. The GPS logger is based on the Arduino platform and stores raw NMEA sentences from pretty much any GPS module to a SD card.

For a project I needed to log GPS information. I had various GPS modules and plenty of Arduinos laying around the lab. At first I intended for the Arduino to capture data from the GPS module, process it and then store it onto a SD card. However, I discarded that idea in favor of more flexibility and now use the arduino merely as pass-thru device for the raw GPS data.

Simple Arduino SD-Card GPS/NMEA Datalogger – [Link]