2018
April Sunday 22

Bookmark and Share

Related Articles...

MILWAUKEE WI Arduino Meet Up Make Space

WANTED: CORE TEAM MEMBER TO HELP START NON-PROFIT GROUP.

WANTED: Angle Investor Start-Up Funding

Large Industrial Zoned Arduino Make Space Acquired!

Email :

COASMailBox @ gmail.com

MILWAUKEE WI Raspberry Pi Meet Up Make Space

WANTED: CORE TEAM MEMBER TO HELP START NON-PROFIT GROUP.

WANTED: Angle Investor Start-Up Funding

Large Industrial Zoned Raspberry Pi Make Space Acquired!

Email :

COASMailBox @ gmail.com

MILWAUKEE WI Internet of Things (IoT) Meet Up Make Space

WANTED: CORE TEAM MEMBER TO HELP START NON-PROFIT GROUP.

WANTED: Angle Investor Start-Up Funding

Large Industrial Zoned Make Space Acquired!

Full Advanced Fabrication Facility, machine Shop, Welding, Electronics Lab Equipment Acquired!

Email :

COASMailBox @ gmail.com

MILWAUKEE WI Machine Repair, & Installation  - Tier 1 Business Support

Machine Technician Mechanic 20+ Years  Personal Experienced In Industrial Factory Machine Servicing, Rebuilding, Installation And Repair - Plus A 35+ Years Experienced Computer Engineer Service Technician Team Ready For Your Outsourced Market Advantage Needs!

Hartung Industrial - Member - CGI Science & Technology Group

Email :

COASMailBox @ gmail.com


2017 REVIEW

Arduino SD & microSD, Reading & Writing

Data Storage = Flash Memory/ Data Collector

by Gene Casanova


SD Reader/Writer Device

The 'LC Studio SD Card module' enables adding data-storage to an Arduino system.

The 'LC Studio SD Card module' can be used to save data to a SD flash-memory card.

The 'LC Studio SD Card' can be obtained from CGI Computer Wares.  This module is self-contained, with a SPI communication interface and features a twin-row pin-header for data logger applications.

SD/microSD Device Pins

The standard SPI pins are provided: CS, MOSI, SCK, MISO.

Power pins include: 3.3VDC, 5VDC, and two GND pins.

Twin Pin Header: two rows of pins, connected in parallel, provide connections for an additional SPI device; typically a digital sensor module with a SPI interface.

SD Card Format

SD Flash Memory Card SD Flash Memory Card FAT 32

Typically, the "FAT 16", and "FAT 32" 'memory format' (filesystem) is used with SD flash memory cards.  An SD flash-memory card is self contained, and sometimes requires being formatted before use.  When formatting is required, use the officially-approved SD memory formatting application; provided by the World SD standards organization.

SD Flash Memory Card FAT 16

SD Standard; Up to 2GB Capacity Cards.

SD Flash Memory Card FAT 32 FAT 32

SDHC Standard; more than 2GB, up to 32GB Capacity Cards.

SD mciroSD Card Pins

A microSD and SD card, has 8 contact printed circuit board (PCB) traces; sometimes referred to as pins. The table below describes the function of each pin.

PinNameDescription
1NCnot connected
2CSChip Select/Slave Select (SS)
3DIMaster Out/Slave In (MOSI)
4VDDSupply Voltage
5CLKClock (SCK)
6VSSSupply Voltage Ground
7DOMaster In/Slave Out (MISO)
8RSVReserved

Use this information to utilize the various models of SD and mciroSD card reader/writer devices available from CGI Computer Wares.

In an Arduino "sketch" C source code, define theĀ Arduino default 'Chip Select' (CS) pin as OUTPUT.  The CS pin on an Arduino UNO systemboard is pin-10, and pin-53 on an Arduino MEGA systemboard.

On the Arduino Ethernet Shield, the CS pin is pin 4.  The CS pin must be specified in the source code correctly to establish a SPI communication link; between the SD device and the Arduino systemboard.


Arduino Read SD Sketch - EXPERIMENT 1

Arduino reads content from a SD or microSD card.  The "SD.h" C library will be used for this experiment.

This source code will be using a file named "testfile.txt".

Using a computer with a SD reader/writer, prepare a SD or microSD card for testing.

Add to the card, a simple text file named "testfile.txt".  Add something simple to the contents of the file, like "This is the content of the test file.".

The Read SD/microSD Card Experiment 1 Sketch:

/*
 * EXPERIMENT - READ SD/MICROSD CARD
 * 2017, by Gene Casanova
*/
#include
const int cs = 4;
void setup()
{
  Serial.begin(9600);
  Serial.print("Initializing Card...");
  // Set Arduino CS Pin to OUTPUT mode:
  pinMode(10, OUTPUT);
  // Test if SD/microSD card is available:
  if (!SD.begin(cs))
  {
    Serial.println("Initialize Card Fail; Check card");
    return;
  }
  Serial.println("Card Initialized.");
  // Open the file named "testfile.txt"
  File myfile = SD.open("testfile.txt");
  // if the file is available, read the file:
  if (myfile)
  {
    while (myfile.available())
    {
     Serial.write(myfile.read());
    }
    myfile.close();
    }else{
     // if the file cannot be opened, then report error:
     Serial.println("error opening the text file");
  }
}
void loop()
{
}

Arduino Write SD Sketch - EXPERIMENT 2

Arduino writes content to a SD or microSD card.  The "SD.h" C library will be used for this experiment.

This source code will be used to create a file on a SD/microSD card, and write content to the file, then read the file content from the SD/microSD card.

The Write File And Data To A SD/microSD Card, Experiment 2 Sketch:

/*
 * EXPERIMENT - WRITE FILE TO SD/MICROSD CARD
 * 2017, by Gene Casanova
*/
#include
File myfile;
void setup()
{
  Serial.begin(9600);
  Serial.print("Initializing Card...");
  
  // Set Arduino CS Pin to OUTPUT mode:
  pinMode(10, OUTPUT);
  
  // Test if SD/microSD card is available:
  if (!SD.begin(cs))
  {
    Serial.println("Initialize Card Fail; Check card");
    return;
  }
  Serial.println("Card Initialized.");
  
  // Open the file named "testfile.txt" for writing to:
  myfile = SD.open("testfile.txt",FILE_WRITE);

  if (myfile)
{
Serial.print("Writing to testfile.txt ...");
myfile.println("Congratulations! You have successfully wrote on the text file.");
myfile.close(); // close file:
}else
{
// if the file did not open, then report an error:
Serial.println("Error opening the text file.");
} // Open testfile for reading: myfile = SD.open("testfile.txt"); if (myfile) // If file available, then read file: { Serial.println("testfile.txt:"); while (myfile.available()) { Serial.write(myfile.read()); } myfile.close(); }else{ // if file did not open, then report error: Serial.println("error opening the text file"); } } void loop() { }

Continuing Study

The experiments above, provided the foundation source code to reading and writing data to a flash memory storage device.  Continue to learn how to monitor the contents of an SD or MicroSD card, and the techniques to appending data to an existing file.


Use The Technology Wisely & Keep It Simple

- Cheers!

Gene Casanova


Need More?   Need Help? ........Software, Network, System & Data Center Builder & Developer | Development Services Available - Freelance Small Jobs; To Outsourced Long Term Service Provider Contract Labor Available.

CGI Computer Wares | EST 1979

Send E-MailCONTACT: [click]@CGIComputerWares.com