Arduino Wireless SD Shield Tutorial: First Steps

From Embedded Lab Vienna for IoT & Security
Jump to: navigation, search

Summary

The Wireless Proto Shield for Arduino is an Arduino Shield that provides wireless communication capabilities to an Arduino board. For this purpose, a chip for wireless communication is attached to the shield. This Wireless Proto Shield is based on Digi's Xbee module, but can be used by any model of the same size. The module can communicate indoors at a distance of up to 30 metres and outdoors at a distance of up to 90 metres (without obstacle). The module can be used as a replacement for a USB-to-serial adapter or configured in control mode for a wide range of networking options.

The Wireless Proto Shield for Arduino has no SD socket.

An integrated switch on the shield allows the wireless module (Xbee chip) to communicate with the USB to serial converter or the microcontroller. To learn more about the WireLess Proto Shield, see the product data sheet on the Arduino website: ArduinoWirelessProtoShield

  • Arduino_Wireless_SD_Shield_Tutorial

Description

As the name implies, the Arduino Wireless SD shield serves two functions. Foremost, this shield allows you to easily interface with Xbee transceiver modules to create mesh networks, and other wireless devices. Secondly, the micro SD socket allows you to store and access a large amount of data. Whether using these functions by on their own or together, this chip greatly enhances the capabilities of a standard Arduino. The best part about this shield is how easy it is to use. In no time flat, you can have its various components up and running.

Step 1: Plug in the Xbee

  • Arduino_Wireless_SD_Shield_Tutorial-Step1

 1. Plug in your Xbee modules in order to use the shield as a wireless transceiver.

 2. Make sure the module's pointy end is lined up with the edge of the board.

 3. If you are using the shield for wireless data transfer, you will need two or more of them.

Step 2: Plug It In

  • Arduino_Wireless_SD_Shield_Tutorial-Step2

 ➥ Plug your shields into your Arduinos.

Step 3: Features

  • Arduino_Wireless_SD_Shield_Tutorial-Step3

 1. The wireless SD shield supports Xbee modules. These modules allow for easy wireless serial communication.
  A standard module has the range of 100 - 300 feet.

 2. It also boasts a micro SD socket. This can easily be interfaced with the Arduino SD library. Unfortunately, this library
   does not come bundled with the Arduino development environment, so you will have to set it up yourself.

 3. The shield also boasts a perfboard grid for prototyping your own circuit, and a micro switch for toggling between the USB port and micro SD port.

Step 4: Program the Receiver

  • Arduino_Wireless_SD_Shield_Tutorial-Step4

 ➥ Plug one of the Arduinos into the computer. Make certain the micro switch is toggled to the "USB" option.

Upload the following code:

//Xbee receiver

int sentDat;

void setup() {
  Serial.begin(9600);   
  pinMode(2, OUTPUT); 
}

void loop() {
  if (Serial.available() > 0) {
	sentDat = Serial.read(); 

	if(sentDat == 'h'){
          //activate the pumpkin for one second and then stop
  	  digitalWrite(2, HIGH);
          delay(1000);
          digitalWrite(2, LOW);
	}
  }
}

Step 5: Setup the Receiver

  • Arduino_Wireless_SD_Shield_Tutorial-Step5

 1. Unplug the Arduino from the computer. Toggle the micro switch from "USB" to "MICRO".

 2. Plug the red wire from a 9V battery connector into the Vin pin. Plug the black wire into the GND pin.

 3. Connect the positive leg of an LED to pin D2 and the other leg in series with a 220 ohm resistor to ground.

 4. Plug in your battery.

 5. It is now a standalone receiver.

Step 6: Program the Transmitter

  • Arduino Wireless SD Shield Tutorial-Step6

 1. Plug in the Arduino for the transmitter. Make certain the micro switch is toggled to the "USB" option.

 2. Before you upload any code to the Arduino, open the serial monitor. Type in "h" and hit the "send" button.
  The LED on your receiver should light up. You have made a wireless connection!

 3. Now upload the following code:

/*
  
  Wireless transmitter demo  

  
  Based on Button example code
  http://www.arduino.cc/en/Tutorial/Button
 
 
 The circuit:
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground
 
 This code is in the public domain.
 
 */

// constants won't change. They're used here to 
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize serial communication:
  Serial.begin(9600); 
     
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    //transmit a High command to the pumpkin and delay a second so that it does not receive more than one command
    //per button press
    Serial.println('h');
    delay(1000); 
  } 
}

Step 7: Setup the Transmitter

  • Arduino_Wireless_SD_Shield_Tutorial-Step7

 1. Unplug the Arduino from the computer. Toggle the micro switch from "USB" to "MICRO".

 2. Plug the red wire from a 9V battery connector into the Vin pin. Plug the black wire into the GND pin.

 3. Connect a 10K resistor between pin D2 and ground. Also connect a push button switch between pin D2 and 5v.

 4. Plug in your battery.

 5. It is now a standalone transmitter.

Step 8: Prepare the SD Card

Note: Before you can use the micro SD card, it needs to be formatted to either FAT16 or FAT32.
  • Arduino Wireless SD Shield Tutorial-Step8

On Windows:

 ➥ Open "My Computer"

 ➥ Right-click on the disk and select "Format"

 ➥ Select "FAT" and click "start"

 ➥ It is now formatted to FAT16

Once the disk is formatted, the next thing you have to do is make sure that you have the SD Card Library. For instructions on how to setup the library, check out the bottom of Adafruit's extremely thorough micro SD card tutorial.

Plug the SD card into the socket on the shield.

To test the SD card, plug the Arduino into the computer and upload the following code:

/*
  SD card read/write
 
 This example shows how to read and write data to and from an SD card file 	
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
 
 	 
 */
 
#include <SD.h>

File myFile;

void setup()
{
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
   pinMode(10, OUTPUT);
   
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
  
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
	// close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
  
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
    
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    	Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
  	// if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{
	// nothing happens after setup
}

Used Hardware

 ➠ ARDUINO Wireless Proto Shield

 ➠ Arduino Board Uno Rev3 DIP Version, ATmega328, USB

References

 ➠ https://forum.arduino.cc/index.php?board=63.0

 ➠ https://www.arduino.cc/en/Reference/SD

 ➠ https://store.arduino.cc/arduino-wireless-proto-shield

 ➠ https://store.arduino.cc/arduino-wireless-proto-shield

 ➠ http://www.ladyada.net/products/microsd/

 ➠ https://github.com/adafruit/SD