MATLAB

First step…Gives you the way to start a long journey…


The goal of this tutorial (also called starting and exiting sessions) is to learn the
First steps:
  •               How to log on
  •               Invoke MATLAB
  •               How to quit MATLAB
    
Starting MATLAB


After logging into your account, you can enter MATLAB by double-clicking on the MATLAB shortcut icon on your Windows desktop. When you start MATLAB, a special window called the MATLAB desktop appears about which I discussed in the previous tutorial itself. The desktop is a window that contains other windows. The major tools within or accessible from the desktop are:
  •        The Command Window
  •        The Command History
  •        The Workspace
  •        The Current Directory
  •        The Help Browser
  •        The Start button



The graphical interface to the Matlab


Note: - Many new version of the Matlab are now available.

When MATLAB is started for the first time, the screen looks like the one that shown in the above Figure. This illustration also shows the default configuration of the MATLAB desktop. You can customize the arrangement of tools and documents to suit your needs.
       
      Invoke MATLAB

You are now faced with the MATLAB desktop on your computer, which contains the prompt (>>) in the Command Window.

Usually, there are 2 types of prompt:
>>” for full version
“EDU>” for educational version

Note: - To simplify the notation, I am using this prompt, >>, as a standard prompt sign, throughout all the tutorials henceforth.

   Quitting MATLAB

To end your MATLAB session, type quit in the Command Window, or select File à Exit MATLAB in the desktop main menu.

This is the basic start and quitting of the Matlab.
Hope to see you in next tutorial…!!!

Written By, Dheeraj Mor

Student @ VIT University


Directories…. The address of your programs…


In the previous article on Matlab Desktop, you may have got idea how this software works. You need to save the files for the future use. Now where to save these files? It should be saving in the manner where it can be access by the MATLAB. You can create your own directory/folder anywhere, save your files, and direct MATLAB to find those files. It is convenient to save files in the same folder of the MATLAB where its application files are installed because it gives all the user written files an automatically accessible by MATLAB.
But I always prefer to save my written files in the folder which contains my data about the relevant project as MATLAB also provides you an alternative to above method i.e. change directory command when you press ‘run button’ , which looks like the following window.

             

·         Change folder Option: - This option changes the current directory of the Matlab and will only allow you to access files of that folder/directory.

·         Add to Path: - This option unable you to add the path of your program to the existing list of the path/directories in the Matlab. Due to this option , you will be able to access the current directory as well as the folder in which your current program is.

·         Cancel: - To cancel your operation.

·         Help: - Help provides the necessary information of how you can use this dialog box in case you find it difficult or confusing.

You can also change the path command or change the working directory of MATLAB to the desired directory with the cd command.

Let us see how to do it in PC’s
Step-1
Create a folder inside the MATLAB folder and save your files there.

Step-2
Create a file in notepad or any word doc. And save this file with the extension of “.m”, let us take “fun.m” and now launch MATLAB by double-clicking on the ‘fun.m’ file in your folder.

Step-3
This way Matlab automatically accesses all files in your folder. You can open, write and save M-files by selecting appropriate commands from the File menu in MATLAB.

Hope to see you in next tutorial...!!!

Written By, Dheeraj Mor

Student @ VIT University

Receiving SMS Through Arduino & GSM Shield

Receive SMS

This sketch waits for a SMS message and prints it to the serial monitor. It requires an Arduino with a connected GSM shield and SIM card.

Hardware Required

  • Arduino board
  • Arduino + Telefonica GSM/GPRS Shield
  • SIM card

Circuit

image of the Arduino GSM Shield on top of an Arduino Uno

First, import the GSM library
#include <GSM.h>

SIM cards may have a PIN number that enables their functionality. Define the PIN for your SIM. If your SIM has no PIN, you can leave it blank :
#define PINNUMBER ""

Initialize instances of the classes you're going to use. You're going to need both the GSM and GSM_SMS class.

GSM gsmAccess;
GSM_SMS sms;

Create a char array to hold the number that is sending the message :
char remoteNumber[20];

In setup, open a serial connection to the computer. After opening the connection, send a message indicating the sketch has started.
void setup(){
  Serial.begin(9600);
  Serial.println("SMS Messages Receiver");

Create a local variable to track the connection status. You'll use this to keep the sketch from starting until the SIM is connected to the network :
boolean notConnected = true;
Connect to the network by calling gsmAccess.begin(). It takes the SIM card's PIN as an argument. By placing this inside a while() loop, you can continually check the status of the connection. When the modem does connect, gsmAccess() will return GSM_READY. Use this as a flag to set the notConnected variable to true or false. Once connected, the remainder of setup will run.
while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }
Finish setup with some information to the serial monitor.
Serial.println("GSM initialized.");
  Serial.println("Waiting for messages");
}





SMS messages are received by the modem. SIM cards have some memory space to store incoming SMS. The number of SMS the card can hold can be as few as 10, or as many as 200, depending on the SIM. You should check with your provider to determine how many your SIM can keep in memory.

In loop(), create a variable of type char to temporarily hold characters from any SMS received. Use sms.available() to check for the presence of any messages on the SIM :
void loop() {
  char c;
  if (sms.available())
  {

If a SMS is available, retrieve the remote sender's number by calling sms.remoteNumber(remoteNumber, 20). the remoteNumber argument is the char array you declared in the beginning of the sketch, it can be no longer than 20 characters. Send this number to the serial monitor.
Serial.println("Message received from:");
    sms.remoteNumber(remoteNumber, 20);
    Serial.println(remoteNumber);

It's possible to delete SMS messages by calling sms.flush(). Using sms.peek() it's possible to identify the message index number, which could be helpful for removal
The code below won't remove any from the SIM, but you could iterate through a for loop, or identify a specific index number to remove, instead of the dummy # used below
if(sms.peek()=='#')
    {
      Serial.println("Discarded SMS");
      sms.flush();
    }

To read a message, use sms.read(). Here, you'll store each character from the message into the variable c and print it out as it gets read.
while(c=sms.read())
      Serial.print(c);

Indicate the message is complete and remove it from memory with sms.flush().
Serial.println("\nEND OF MESSAGE");  
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }

Add a brief delay and close the loop.
delay(1000); }


Once your code is uploaded, open the serial monitor. With a phone, or other SMS enabled service, send a SMS to the number of your SIM. You should see the message print out on screen when it is received.
/*
SMS receiver

 This sketch, for the Arduino GSM shield, waits for SMS messages
 and displays them through the Serial port.

 Circuit:
 * GSM shield

*/

// libraries #include <GSM.h>
// PIN Number #define PINNUMBER ""
// initialize the library instance
GSM gsmAccess; // include a 'true' parameter for debug enabled
GSM_SMS sms;

char remoteNumber[20];  // Holds the emitting number
void setup() {
  // initialize serial communications
  Serial.begin(9600);

  Serial.println("SMS Messages Receiver");

  // connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");
}
void loop() {
  char c;

  // If there are any SMSs available()  
  if (sms.available())
  {
    Serial.println("Message received from:");

    // Get remote number
    sms.remoteNumber(remoteNumber, 20);
    Serial.println(remoteNumber);

    // This is just an example of message disposal    
    // Messages starting with # should be discarded
    if(sms.peek()=='#')
    {
      Serial.println("Discarded SMS");
      sms.flush();
    }

    // Read message bytes and print them
    while(c=sms.read())
      Serial.print(c);

    Serial.println("\nEND OF MESSAGE");

    // delete message from modem memory
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }

  delay(1000);

}

GSM library

The GSM library is included with Arduino IDE 1.0.4 and later.
With the Arduino GSM Shield, this library enables an Arduino board to do most of the operations you can do with a GSM phone: place and receive voice calls, send and receive SMS, and connect to the internet over a GPRS network.
The GSM shield has a modem that transfers data from a serial port to the GSM network. The modem executes operations via a series of AT commands. The library abstracts low level communications between the modem and SIM card. It relies on the Software Serial library for communication between the moden and Arduino.
Typically, each individual command is part of a larger series necessary to execute a particular function. The library can also receive information and return it to you when necessary.

Library structure

As the library enables multiple types of functionality, there are a number of different classes.
  • The GSM class takes care of commands to the radio modem. This handles the connectivity aspects of the shield and registers your system in the GSM infrastructure. All of your GSM/GPRS programs will need to include an object of this class to handle the necessary low level communication.
  • Voice call handling, managed by the GSMVoiceCall class.
  • Send/receive SMS messages, managed by the GSM_SMS class.
  • The GPRSClass is for connecting to the internet.
  • GSMClient includes implementations for a client, similar to the Ethernet and WiFi libraries.
  • GSMServer includes implementations for a server, similar to the Ethernet and WiFi libraries. NB : A number of network operators do not allow for incoming connections from the public internet, but will allow them from inside their own. Check with your operator to see what restrictions there are on data use.
  • A number of utility classes such as GSMScanner and GSMModem


Ethernet library compatibility

The library tries to be as compatible as possible with the current Ethernet library. Porting a program from an Arduino Ethernet or WiFi library to an Arduino with the GSM Shield should be fairly easy. While it is not possible to simply run Ethernet-compatible code on the GSM shield as-is, some minor, library specific, modifications will be necessary, like including the GSM and GPRS specific libraries and getting network configuration settings from your cellular network provider.


GSM class

This class prepares the functions that will communicate with the modem.
  • GSM
  • begin()
  • shutdown() 
  •  

GSMVoiceCall class

Enables voice communication through the modem. A microphone and speaker need to be added for full use.
  • GSMVoiceCall
  • getVoiceCallStatus()
  • ready()
  • voiceCall()
  • answerCall()
  • hangCall()
  • retrieveCallingNumber() 
  •  

GSM_SMS class

Facilitates sending and receiving Short Message Service (SMS) messages.
  • GSM_SMS
  • beginSMS()
  • ready()
  • endSMS()
  • available()
  • remoteNumber()
  • read()
  • write()
  • print()
  • peek()
  • flush() 
  •  

GPRS class

This class is responsible for including the files that are part of the library that involve TCP communication.
  • GPRS
  • attachGPRS() 
  •  

GSMClient class

The client class creates clients that can connect to servers and send and receive data.
  • GSMClient
  • ready()
  • connect()
  • beginWrite()
  • write()
  • endWrite()
  • connected()
  • read()
  • available()
  • peek()
  • flush()
  • stop() 
  •  

GSMServer class

The Server class creates servers which can send data to and receive data from connected clients (programs running on other computers or devices).
  • GSMServer
  • ready()
  • beginWrite()
  • write()
  • endWrite()
  • read()
  • available()
  • stop() 
  •  

GSMModem class

The GSMModem class facilitates diagnostic communication with the modem.
  • GSMModem
  • begin()
  • getIMEI() 
  •  

GSMScanner class

The GSMScanner class provides diagnostic information about the network and carrier.
  • GSMScanner
  • begin()
  • getCurrentCarrier()
  • getSignalStrength()
  • readNetworks() 
  •  

GSMPIN class

The GSMPIN class has utilities for communicating with the SIM card.
  • GSMPIN
  • begin()
  • isPIN()
  • checkPIN()
  • checkPUK()
  • changePIN()
  • switchPIN()
  • checkReg()
  • getPINUsed()
  • setPINUsed() 
  •  

GSMBand class

The GSMBand class provides information about the frequency band the modem connects to. There are also methods for setting the band.
  • GSMBand
  • begin()
  • getBand()
  • setBand()