My Cart

Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks

Difficulty Level: Intermediate -


The current tutorial explains how to take the most of the Galileo board by using on it the Arduino and Raspberry Pi shields and modules designed by Cooking Hacks:

Galileo comes with a single-core 32-bit, 400MHz Quark SoC X1000 processor, supports 3.3 or 5 volt shields and has an Ethernet and USB port. Compatible with Windows, Mac OS and Linux, the software of Galileo also has support for the Arduino shield ecosystem.

We have tested all our shields, boards and modules designed for Arduino and Raspberry Pi over Intel Galileo. It includes also the possibility of connecting digital, analog sensors, communication protocols..., using the same pinout of Arduino but with the power and capabilities of Intel core.

In order to make complete the compatibility we have created some examples which allows to use our shields.

Let's summarize what we can do using our shields over Intel Galileo:

  • Connect any Arduino Wireless module. Some examples: RFID, NFC, Bluetooth, Bluetooth Pro, Wifi, GPRS,3G
  • Connect any sensor and actuator(analog 0-5V, digital).
  • Connect any Arduino specific shield such as: Radiation sensor shield, ...
  • Connect any electronic module or actuator which works over i2C, SPI, UART...

New tools for innovation

Introducing the Intel® Galileo development board, the first product in a new family of Arduino-compatible development boards featuring Intel® architecture. The platform is easy to use for new designers and for those looking to take designs to the next level. Intel recognizes that the people who take creating beautiful things into their own hands with innovation and technology are the same ones that propel us forward.

The Intel Galileo development board is a great tool for quickly prototyping simple, interactive designs such as LED light displays that respond to social media, or for tackling more complex projects, from automating home appliances to building life-size robots controlled by a smartphone.

This platform provides the ease of Intel architecture development through support for the Microsoft Windows*, Mac OS* and Linux* host operating systems. It also brings the simplicity of the Arduino software integrated development environment (IDE). It's all about delivering Intel performance and quality to the DIY maker community to support invention and creativity.

1. The board

1.1 Getting started

Overview

Galileo is a microcontroller board based on the Intel® Quark SoC X1000 Application Processor, a 32-bit Intel Pentium-class system on a chip (datasheet). It's the first board based on Intel® architecture designed to be hardware and software pin-compatible with Arduino shields designed for the Uno R3. Digital pins 0 to 13 (and the adjacent AREF and GND pins), Analog inputs 0 to 5, the power header, ICSP header, and the UART port pins (0 and 1), are all in the same locations as on the Arduino Uno R3. This is also known as the Arduino 1.0 pinout.

Galileo is designed to support shields that operate at either 3.3V or 5V. The core operating voltage of Galileo is 3.3V. However, a jumper on the board enables voltage translation to 5V at the I/O pins. This provides support for 5V Uno shields and is the default behavior. By switching the jumper position, the voltage translation can be disabled to provide 3.3V operation at the I/O pins.

Of course, the Galileo board is also software compatible with the Arduino Software Development Environment (IDE), which makes usability and introduction a snap. In addition to Arduino hardware and software compatibility, the Galileo board has several PC industry standard I/O ports and features to expand native usage and capabilities beyond the Arduino shield ecosystem. A full sized mini-PCI Express slot, 100Mb Ethernet port, Micro-SD slot, RS-232 serial port, USB Host port, USB Client port, and 8MByte NOR flash come standard on the board.

For details, see the Intel® Galileo website

Processor Features

  • 400 MHz 32-bit Intel® Pentium® instruction set architecture (ISA)-compatible processor
  • 16 KByte L1 cache
  • 512 KBytes of on-die embedded SRAM
  • Simple to program: Single thread, single core, constant speed
  • ACPI compatible CPU sleep states supported
  • Integrated Real Time Clock (RTC), with optional 3V "coin cell" battery for operation between turn on cycless

Communication

  • 10/100 Mb Ethernet RJ45 port
  • USB 2.0 Client port
  • USB 2.0 Host port
  • RS-232 UART port and 3.5mm jack
  • Mini PCI Express (mPCIe) slot with USB2.0 Host support

1.2 Intel Galileo Development Board Documents

Where do you find out more information about Intel® Galileo?

Get the latest documents for your Intel® products:

https://communities.intel.com/community/makers/galileo/documentation/galileodocuments

1.3 Arduino compatible notes

Galileo is a microcontroller board based on the Intel® Quark SoC X1000 Application Processor, a 32-bit Intel Pentium-class system on a chip.

It's the first board based on Intel® architecture designed to be hardware and software pin-compatible with Arduino shields designed for the Uno R3. Digital pins 0 to 13 (and the adjacent AREF and GND pins), Analog inputs 0 to 5, the power header, ICSP header, and the UART port pins (0 and 1), are all in the same locations as on the Arduino Uno R3.

We are going to talk about a few features where Galileo is not completely compatible with the Arduino, but consider the following:

    1. Galileo have a lot more memory in comparison with other boards. With the Arduino Uno, Mega, etc. you are constantly running out of memory, making it hard to combine many libraries, hard to do things like keep a frame for large displays or logging data, etc.
    2. Galileo get built-in networking, and it's not bottlenecked by SPI or UART communication protocols speeds.
    3. Galileo get USB host support . This opens up a whole other class of devices to interface with, like cheap webcams.
    4. Galileo allow to boot off and store drivers in the SD card.

Galileo is different, but has its own strengths (and inevitable weaknesses, which of course Intel will try to address over time).

Arduino Shield Supported Features

Galileo is compatible with Arduino Uno shields and is designed to support 3.3V or 5V shields, following the Arduino Uno Revision 3, including:

  • 14 digital input/output pins.
  • A0-A5 : 6 analog inputs.
  • I2C bus, TWI, with SDA and SCL pins that are near to the AREF pin.
  • SPI. Defaults to 4MHz to support Arduino Uno shields. Programmable up to 25MHz.
  • UART (serial port) Programmable speed UART port (Pins 0 (RX) and 1 (TX))
  • ICSP (SPI) - a 6 pin in-circuit serial programming (ICSP) header, located appropriately to plug into existing shields. These pins support SPI communication using the SPI library.
  • VIN. The input voltage to the Galileo board when it's using an external power source (as opposed to 5 volts from the regulated power supply connected at the power jack).
  • 5V output pin. This pin outputs 5V from the external source or the USB connector.
  • 3.3V output pin.
  • GND. Ground pins.
  • IOREF. The IOREF pin on Galileo allows an attached shield with the proper configuration to adapt to the voltage provided by the board.
  • RESET button/pin.
  • AREF is unused on Galileo. Providing an external reference voltage for the analog inputs is not supported.

UART TTL serial communication

Galileo has a number of facilities for communicating with a computer, another Arduino, or other microcontrollers. Galileo provides UART TTL (5V/3.3V) serial communication, which is available on digital pin 0 (RX) and 1 (TX). In addition, a second UART provides RS-232 support and is connected via a 3.5mm jack. The USB Device ports allows for serial (CDC) communications over USB. This provides a serial connection to the Serial Monitor or other applications on your computer. However, usage is slightly different than with an arduino, due to the fact that the UART on pins 0 and 1 is a different serial port than the one which communicates with the IDE serial monitor.

Consider the code below:

Serial.begin(115200);
Serial.println("hello world!");
                

This will print "hello world!" to the IDE Serial monitor.

If you want to talk to the UART on pins 0 and 1, then you need to use Serial1, like this:

Serial1.begin(115200);
Serial1.println("hello world!");
                

AVR-specific code

Another problem could occur if you try to import a library. A lot of shield libraries use AVR specific code. Whether it compiles or not will depend on whether there is any AVR-specific code in the library.

Some Arduino boards use atmel microprocessors, and there is no OS running on them , apart from the 'OS' you write yourself in the Arduino IDE. You can directly manipulate low-level registers.

On the other hand, Galileo uses a full x86 system-on-a-chip, which runs Linux. Your arduino sketch runs as a userspace program on top of Linux, and from userspace you don't have direct access to anything as low-level as setting individual bits in hardware control registers.

So, the solution is not an easy search-and-replace job. However if you know what this code is doing then you should be able to replicate its functionality without all of the AVR-specific parts.

2. Programming the board

2.1 Basic steps

Get a board

Buy Intel Galileo Board

Download the programming IDE

Download the latest IDE and firmware files here:

https://downloadcenter.intel.com/Detail_Desc.aspx?agr=Y&DwnldID=23171

Connect the board

WARNING: You must use the power supply or you will damage the board.

Connect the 5V power cable to the Galileo board and to a power outlet.

Note: Always connect the 5V power before any other connection.

The green power LED (labelled PWR) will turn on.

Drivers and other software

Install the drivers for the Arduino IDE and the board.

Launch the Arduino IDE application

Use the Arduino IDE software to create programs for Galileo called “sketches.” To run a sketch on the board, simply connect a power supply, connect Galileo's USB Client port to your computer, and upload the sketch using the IDE interface.

Update your board firmware

The IDE contains the release-specific firmware for your board. Follow the Intel Getting Started Guide steps to update your board firmware using the IDE.

Open the blink example

The green power LED (labelled PWR) will turn on.

Select your board

Open the LED blink example sketch: File > Examples > 1.Basics > Blink.

Select your serial port

Select Tools > Board > Intel Galileo Fab D.

NOTE: If the IDE was closed and then reopened, it will default to a board that was previously selected. You may need to explicitly select Intel Galileo Fab D.

Upload the program

Click the Upload button in the IDE and wait a few seconds. If the upload is successful, the message Done uploading. will appear in the status bar.

A few seconds after the upload finishes, you will see a green LED on the board start to blink. Congratulations! You've gotten your board up and running

More steps

For details, see the Intel® Galileo Getting Started Guide.

2.2 Power

Galileo is powered via an AC-to-DC adapter, connected by plugging a 2.1mm center-positive plug into the board's power jack. The recommended output rating of the power adapter is 5V at up to 3 A.

Electrical Summary

  • Input Voltage (recommended) : 5V
  • Input Voltage (limits) : 5V
  • Digital I/O Pins : 14 (of which 6 provide PWM output)
  • Analog Input Pins : 6
  • Total DC Output Current on all I/O lines : 80mA
  • DC Current for 3.3V Pin : 800mA
  • DC Current for 5V Pin : 800mA

3. Arduino Basic Functions

3.1 Basics

To get started, simply connect the board to power with the 5V AC-to-DC adapter and then connect to the computer with the micro-USB cable. Connect Galileo's port labelled USB Client (the one closest to the Ethernet) to your computer. Rather than requiring a physical press of the reset button before an upload, Galileo is designed to be reset by software running on a connected computer.

When the board boots up two scenarios are possible:

  • If a sketch is present in persistent storage, it is executed.
  • If no sketch is present, the board waits for upload commands from the IDE.

There are some simple programs that demonstrate basic Arduino commands. These are included with the IDE environment; to open them, click the Open button on the toolbar and look in the examples folder.

We should start with the Blink example. This example shows the simplest thing you can do to see physical output: it blinks an LED. When we upload successfully this code we see the green Galileo-integrated led blinking.

3.2 UART

Galileo provides UART TTL (5V/3.3V) serial communication, which is available on digital pin 0 (RX) and 1 (TX). In addition, a second UART provides RS-232 support and is connected via a 3.5mm jack.

All this functions have the same functionality as the Arduino. You can find more information at:

http://arduino.cc/en/Reference/serial

3.3 I2C

Galileo probides I2C bus, TWI, with SDA and SCL pins that are near to the AREF pin. TWI: A4 or SDA pin and A5 or SCL pin. Support TWI communication using the Wire library. The Arduino software includes a Wire library to simplify use of the TWI/I2C bus.

Here we show another example using the BlinkM RGB i2C controlled led.

BlinkM uses a high quality, high power RGB LED and a small AVR microcontroller to allow a user to digitally control an RGB LED over a simple i2C interface. In the example we will change the led color using fade transitions and also changing it directly. More information about the LED and the commands we can send to it can be found in the datasheet.

Connect the (-) pin of the led with the GND pin of the shield.

Connect the (+) pin of the led with the 5V pin of the shield.

Connect the d pin of the led with the SDA pin of the shield.

Connect the c pin of the led with the SCL pin of the shield.

Here is the code:

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n
 */

#include "Wire.h"


void setup(){
	Wire.begin();
	Wire.beginTransmission(9);
	Wire.write('o'); //End the current Light script
	Wire.endTransmission();
}

void loop(){
	for (int i=0;i < 5;i++){
		Wire.beginTransmission(9);
		Wire.write('n'); //Change to color
		Wire.write(byte(0xff)); //Red component
		Wire.write(byte(0x00)); //Green component
		Wire.write(byte(0x00)); //Blue component
		Wire.endTransmission();

		delay(500);
		
		Wire.beginTransmission(9);
		Wire.write('n'); //Change to color
		Wire.write(byte(0x00)); //Red component
		Wire.write(byte(0x00)); //Green component
		Wire.write(byte(0xff)); //Blue component
		Wire.endTransmission();
		
		delay(500);
	}
	
	for (int i=0;i < 10;i++){
		Wire.beginTransmission(9);
		Wire.write('c'); //Fade to color
		Wire.write(byte(0xff)); //Red component
		Wire.write(byte(0x00)); //Green component
		Wire.write(byte(0x5a)); //Blue component
		Wire.endTransmission();

		delay(150);
		
		Wire.beginTransmission(9);
		Wire.write('c'); //Fade to color
		Wire.write(byte(0x55)); //Red component
		Wire.write(byte(0x20)); //Green component
		Wire.write(byte(0x5a)); //Blue component
		Wire.endTransmission();

		delay(150);
	}
}
                

Connecting the led to the Intel Galileo and using the code below, it alternate from red to blue five times and then make some smooth transitions between purplish colors.

3.4 SPI

Galileo provides SPI communication. Defaults to 4MHz to support Arduino Uno shields. Programmable up to 25MHz. For SPI communication, use the SPI library.

Note: While Galileo has a native SPI controller, it will act as a master and not as an SPI slave. Therefore, Galileo cannot be a SPI slave to another SPI master. It can act, however, as a slave device via the USB Client connector.

It is possible to communicate with SPI devices. In this example we use the SPI functions for printing messages on the ST7920 LCD12864 (SPI LCD).

First of all, we need to put the switch of the LCD in SPI mode. Now we proceed with the connection between the LCD and the Raspberry Pi to arduino shield:

    VCC of the LCD to 5v of the shield

    GND of the LCD to GND of the shield

    SCK of the LCD to SCK of the shield

    SID of the LCD to MOSI of the shield

    CS of the LCD to 8 pin of the shield

As you can see we are using the pin number 8 of the Intel Galileo as chip select. So when we need to select the LCD as the target device for the SPI communication we need to put the 8 pin to HIGH.

Connecting the LCD to the Intel Galileo and using the code below, it will show the messages "Cooking Hacks" and "SPI LCD for Raspberry Pi" with a delay of 2 seconds in between.

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n
 */

// include the SPI library:
#include <SPI.h>

int latchPin = 8;
unsigned char char1[]=" Cooking Hacks  ";
unsigned char char2[]="  SPI LCD for   ";
unsigned char char3[]="  Raspberry Pi  ";

void setup(){
	SPI.begin();
	SPI.setBitOrder(MSBFIRST);
	SPI.setDataMode(SPI_MODE0);
	SPI.setClockDivider(SPI_CLOCK_DIV128);

	initialise();
}

void loop(){
	displayString(0,0,char1,16);
	delay(2000);
	clear();
	displayString(1,0,char2,16);
	displayString(2,0,char3,16);
	delay(2000);
	clear();
}

void initialise(){
	pinMode(latchPin, OUTPUT);     
	digitalWrite(latchPin, LOW);

	delayMicroseconds(80);

	writeCommand(0x30);
	writeCommand(0x0c);
	writeCommand(0x01);
	writeCommand(0x06);
}


void displayString(int X,int Y,unsigned char *ptr,int dat){
	int i;

	switch(X){
		case 0:  Y|=0x80;break;

		case 1:  Y|=0x90;break;

		case 2:  Y|=0x88;break;

		case 3:  Y|=0x98;break;

		default: break;
	}

	writeCommand(Y);

	for(i=0;i < dat;i++){ 
		writeData(ptr[i]);
	}

}

void writeCommand(int CMD){
	int H_data,L_data;
	H_data = CMD;
	H_data &= 0xf0;
	L_data = CMD;
	L_data &= 0x0f;
	L_data <<= 4;
	writeByte(0xf8);
	writeByte(H_data);
	writeByte(L_data);
}

void writeData(int CMD){
	int H_data,L_data;
	H_data = CMD;
	H_data &= 0xf0;
	L_data = CMD;
	L_data &= 0x0f;
	L_data <<= 4;
	writeByte(0xfa);
	writeByte(H_data);
	writeByte(L_data);
}

void writeByte(int dat){
	digitalWrite(latchPin, HIGH);
	delayMicroseconds(80);
	SPI.transfer(dat);
	digitalWrite(latchPin, LOW);
}

void clear(){
	writeCommand(0x30);
	writeCommand(0x01);
}
                

4. Modules and shields for Intel Galileo












4.1 e-Health Sensor Platform

The e-Health Sensor Shield V2.0 allows Arduino, Raspberry Pi and Intel Galileo users to perform biometric and medical applications where body monitoring is needed by using 10 different sensors: pulse, oxygen in blood (SPO2), airflow (breathing), body temperature, electrocardiogram (ECG), glucometer, galvanic skin response (GSR - sweating), blood pressure (sphygmomanometer), patient position (accelerometer) and muscle/eletromyography sensor (EMG).

This information can be used to monitor in real time the state of a patient or to get sensitive data in order to be subsequently analysed for medical diagnosis. Biometric information gathered can be wirelessly sent using any of the 6 connectivity options available: Wi-Fi, 3G, GPRS, Bluetooth, 802.15.4 and ZigBee depending on the application.

Data can be sent to the Cloud in order to perform permanent storage or visualized in real time by sending the data directly to a laptop or Smartphone. iPhone and Android applications have been designed in order to easily see the patient's information.

The e-health Sensor Platform counts with a C++ library that lets you read easily all the sensors and send the information by using any of the available radio interfaces. This library offers an simple-to-use open source system compatible with Intel Galileo board.

In order to ensure the code is compatible in both platforms (Arduino and Intel Galileo) we use a modified e-Health library which allows developers to use the same code.

The pack we are going to use in this tutorial is the eHealth Sensor platform from Cooking Hacks.

The e-Health Sensor Shield and some features are compatible with Intel Galileo:

  • 6 non-invasive + 1 invasive medical sensors.
  • Storage and use of glucose measurements.
  • Monitoring ECG signal.
  • Monitoring EMG signals.
  • Airflow control of patient.
  • Body temperature data.
  • Galvanic skin response measurements.
  • Pulse and oxygen functions.
  • Blood pressure control device.
  • Multiple data visualization systems.
  • Compatible with all UART device.

Currently these sensors are not supported but we're working on compatibility:

  • Patient Position Sensor (Accelerometer)
  • Pulse and Oxygen in Blood Sensor (SPO2)
Complete Kit: e-Health Sensor Platform Complete Kit V2.0 [Biometric / Medical Applications] - Now 10 Sensors available Refer to e-Health tutorial for more information.

Compatible library

The eHealth sensor platform includes a high level library functions for a easy manage of the board. Before start using this functions you should download the files from this link. Copy this folders in the IDE folder "libraries". Don't forget include these libraries in your codes.

Download the e-Health library for Intel Galileo

Libraries are often distributed as a ZIP file or folder. The name of the folder is the name of the library. Inside the folder will be the .cpp files, .h files and often a keywords.txt file, examples folder, and other files required by the library.

To install the library, first quit the IDE application. Then uncompress the ZIP file containing the library. For installing eHealth library , uncompress eHealth.zip. It should contain a folder called "eHealth" , with files like eHealth.cpp and eHealth.h inside. Drag the eHealth folder into this folder (your libraries folder). Under Windows, it will likely be called "My Documents\Arduino\libraries". For Mac users, it will likely be called "Documents/Arduino/libraries". On Linux, it will be the "libraries" folder in your sketchbook.

The library won't work if you put the .cpp and .h files directly into the libraries folder or if they're nested in an extra folder. Restart the IDE application. Make sure the new library appears in the Sketch->Import Library menu item of the software.

That's it! You've installed a library! Now you can use the examples included in the library.

  • Glucometer Sensor

Glucometer is a medical device for determining the approximate concentration of glucose in the blood. A small drop of blood, obtained by pricking the skin with a lancet, is placed on a disposable test strip that the meter reads and uses to calculate the blood glucose level. The meter then displays the level in mg/dl or mmol/l.

The Intel Galileo code used in this program is presented next:

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Ahmad Saad
 */


#include #include <eHealth.h>
#include "Wire.h"

void setup() { 
  delay (1000);
  eHealth.readGlucometer();
  Serial.begin(115200);
  delay(1000);    
}

void loop() { 

  uint8_t numberOfData = eHealth.getGlucometerLength();   
  Serial.print("Number of measures : ");    
  Serial.println(numberOfData, DEC);   
  delay(100);


  for (int i = 0; i<numberOfData; i++) { 
    // The protocol sends data in this order 
    Serial.println("==========================================");

    Serial.print("Measure number ");
    Serial.println(i + 1);

    Serial.print("Date -> "); 
    Serial.print(eHealth.glucoseDataVector[i].day); 
    Serial.print(" of "); 
    Serial.print(eHealth.numberToMonth(eHealth.glucoseDataVector[i].month));
    Serial.print(" of ");
    Serial.print(2000 + eHealth.glucoseDataVector[i].year);    
    Serial.print(" at ");

    if (eHealth.glucoseDataVector[i].hour < 10) {
      Serial.print(0); // Only for best representation.
    }

    Serial.print(eHealth.glucoseDataVector[i].hour);
    Serial.print(":");

    if (eHealth.glucoseDataVector[i].minutes < 10) {
      Serial.print(0);// Only for best representation.
    }
    Serial.print(eHealth.glucoseDataVector[i].minutes);

    if (eHealth.glucoseDataVector[i].meridian == 0xBB)
      Serial.println(" pm");
    else if (eHealth.glucoseDataVector[i].meridian == 0xAA)
      Serial.println(" am"); 

    Serial.print("Glucose value : "); 
    Serial.print(eHealth.glucoseDataVector[i].glucose);
    Serial.println(" mg/dL");
  }

  delay(20000);
}
                
  • Body Temperature Sensor

Body temperature depends upon the place in the body at which the measurement is made, and the time of day and level of activity of the person. Different parts of the body have different temperatures. The commonly accepted average core body temperature (taken internally) is 37.0°C (98.6°F). In healthy adults, body temperature fluctuates about 0.5°C (0.9°F) throughout the day, with lower temperatures in the morning and higher temperatures in the late afternoon and evening, as the body's needs and activities change.

The Intel Galileo code used in this program is presented next:

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Ahmad Saad
 */

#include <eHealth.h>
#include "Wire.h"

// the setup routine runs once when you press reset:
void setup() {
  Serial.begin(115200);  
}

// the loop routine runs over and over again forever:
void loop() {
  float temperature = eHealth.getTemperature();

  Serial.print("Temperature (ÂşC): ");       
  Serial.print(temperature, 2);  
  Serial.println(""); 

  delay(1000);	// wait for a second 
}
                
  • Blood Pressure Sensor (Sphygmomanometer) V2.0

Blood pressure is the pressure of the blood in the arteries as it is pumped around the body by the heart. When your heart beats, it contracts and pushes blood through the arteries to the rest of your body. This force creates pressure on the arteries. Blood pressure is recorded as two numbers: the systolic pressure (as the heart beats) over the diastolic pressure (as the heart relaxes between beats).

The Intel Galileo code used in this program is presented next:

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Ahmad Saad
 */


#include <eHealth.h>
#include "Wire.h"


void setup() { 
  delay(1000); 
  eHealth.readBloodPressureSensor();
  Serial.begin(115200);
  delay(100);    
}

void loop() { 

  uint8_t numberOfData = eHealth.getBloodPressureLength();   
  Serial.print("Number of measures : ");    
  Serial.println(numberOfData, DEC);   
  delay(100);


  for (int i = 0; i<numberOfData; i++) { 
    // The protocol sends data in this order 
    Serial.println("==========================================");

    Serial.print("Measure number ");
    Serial.println(i + 1);

    Serial.print("Date -> "); 
    Serial.print(eHealth.bloodPressureDataVector[i].day); 
    Serial.print(" of "); 
    Serial.print(eHealth.numberToMonth(eHealth.bloodPressureDataVector[i].month));
    Serial.print(" of ");
    Serial.print(2000 + eHealth.bloodPressureDataVector[i].year);    
    Serial.print(" at ");

    if (eHealth.bloodPressureDataVector[i].hour < 10) {
      Serial.print(0); // Only for best representation.
    }

    Serial.print(eHealth.bloodPressureDataVector[i].hour);
    Serial.print(":");

    if (eHealth.bloodPressureDataVector[i].minutes < 10) {
      Serial.print(0);// Only for best representation.
    }
    Serial.println(eHealth.bloodPressureDataVector[i].minutes);

    Serial.print("Systolic value : "); 
    Serial.print(30+eHealth.bloodPressureDataVector[i].systolic);
    Serial.println(" mmHg");
    
    Serial.print("Diastolic value : "); 
    Serial.print(eHealth.bloodPressureDataVector[i].diastolic);
    Serial.println(" mmHg");
    
    Serial.print("Pulse value : "); 
    Serial.print(eHealth.bloodPressureDataVector[i].pulse);
    Serial.println(" bpm");
  }
  
  delay(20000);
}
                
  • Airflow Sensor (Breathing)

Anormal respiratory rates and changes in respiratory rate are a broad indicator of major physiological instability, and in many cases, respiratory rate is one of the earliest indicators of this instability. Therefore, it is critical to monitor respiratory rate as an indicator of patient status. AirFlow sensor can provide an early warning of hypoxemia and apnea.

The nasal / mouth airflow sensor is a device used to measure the breathing rate in a patient in need of respiratory help or person. This device consists of a flexible thread which fits behind the ears, and a set of two prongs which are placed in the nostrils. Breathing is measured by these prongs.

The Intel Galileo code used in this program is presented next:

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Ahmad Saad
 */


#include <eHealth.h>
#include "Wire.h"

// The setup routine runs once when you press reset:
void setup() {
  Serial.begin(115200);  
}

// the loop routine runs over and over again forever:
void loop() {

  int air = eHealth.getAirFlow();   
  eHealth.airFlowWave(air);  
}
                
  • Galvanic Skin Response Sensor (GSR - Sweating)

Skin conductance, also known as galvanic skin response (GSR) is a method of measuring the electrical conductance of the skin, which varies with its moisture level. This is of interest because the sweat glands are controlled by the sympathetic nervous system, so moments of strong emotion, change the electrical resistance of the skin. Skin conductance is used as an indication of psychological or physiological arousal. The Galvanic Skin Response Sensor (GSR - Sweating) measures the electrical conductance between 2 points, and is essentially a type of ohmmeter.

The Intel Galileo code used in this program is presented next:

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Ahmad Saad
 */

#include <eHealth.h>
#include "Wire.h"

// the setup routine runs once when you press reset:
void setup() {
  Serial.begin(115200);  
}

// the loop routine runs over and over again forever:
void loop() {

  float conductance = eHealth.getSkinConductance();
  float resistance = eHealth.getSkinResistance();
  float conductanceVol = eHealth.getSkinConductanceVoltage();

  Serial.print("Conductance : ");       
  Serial.print(conductance, 2);  
  Serial.println("");         

  Serial.print("Resistance : ");       
  Serial.print(resistance, 2);  
  Serial.println("");    

  Serial.print("Conductance Voltage : ");       
  Serial.print(conductanceVol, 4);  
  Serial.println("");

  Serial.print("\n");

  // wait for a second  
  delay(1000);            
}
                
  • Electrocardiogram Sensor (ECG)

The electrocardiogram (ECG or EKG) is a diagnostic tool that is routinely used to assess the electrical and muscular functions of the hear.

The Electrocardiogram Sensor (ECG) has grown to be one of the most commonly used medical tests in modern medicine. Its utility in the diagnosis of a myriad of cardiac pathologies ranging from myocardial ischemia and infarction to syncope and palpitations has been invaluable to clinicians for decades.

The Intel Galileo code used in this program is presented next:

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Ahmad Saad
 */

#include <eHealth.h>
#include "Wire.h"

// The setup routine runs once when you press reset:
void setup() {
  Serial.begin(115200);  
}

// The loop routine runs over and over again forever:
void loop() {

  float ECG = eHealth.getECG();

  Serial.print("ECG value :  ");
  Serial.print(ECG, 2); 
  Serial.print(" V"); 
  Serial.println(""); 

  delay(1);	// wait for a millisecond
}
                
  • Electromyography Sensor (EMG)

An electromyogram (EMG) measures the electrical activity of muscles at rest and during contraction.

Electromyography (EMG) is a technique for evaluating and recording the electrical activity produced by skeletal muscles. EMG is performed using an instrument called an electromyograph, to produce a record called an electromyogram. An electromyograph detects the electrical potential generated by muscle cells when these cells are electrically or neurologically activated. The signals can be analyzed to detect medical abnormalities, activation level, recruitment order or to analyze the biomechanics of human or animal movement.

The Intel Galileo code used in this program is presented next:

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Ahmad Saad
 */

#include <eHealth.h>
#include "Wire.h"

// The setup routine runs once when you press reset:
void setup() {
  Serial.begin(115200);  
}

// The loop routine runs over and over again forever:
void loop() {

  int EMG = eHealth.getEMG();

  Serial.print("EMG value :  ");
  Serial.print(EMG);  
  Serial.println(""); 

  delay(100);	// wait for a millisecond
}
                
  • Patient position and falls

The Patient Position Sensor (Accelerometer) monitors five different patient positions (standing/sitting, supine, prone, left and right.)

In many cases, it is necessary to monitor the body positions and movements made because of their relationships to particular diseases (i.e., sleep apnea and restless legs syndrome). Analyzing movements during sleep also helps in determining sleep quality and irregular sleeping patterns. The body position sensor could help also to detect fainting or falling of elderly people or persons with disabilities.

The Intel Galileo code used in this program is presented next:

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Ahmad Saad
 */

#include#include <eHealth.h>
#include "Wire.h"

void setup() {
    Serial.begin(115200);  
    eHealth.initPositionSensor();     
}

void loop() {  
  
  Serial.print("Current position : ");
  uint8_t position = eHealth.getBodyPosition(); 
  eHealth.printPosition(position);  
  
  Serial.print("\n");
  delay(1000); 
  
}
                

Others

eHealth Sensor Platform allows to share medical data with the cloud, and perform real-time diagnosis. Thanks to many communications modules can send data over several transmission protocols.

This example shows the way to send a text message with the corporal temperature using the GPRS module. Upload the next code:

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Ahmad Saad
 */
 
// For more information about the GPRS shield please see our tutorial
// in cooking-hacks web site. http://www.cooking-hacks.com


#include <eHealth.h>
#include "Wire.h"

// the pin to switch on the module (without press on button) 
int pinModuleOn = 2;      

// ********* is the number to call
char phoneNumber[]="**********";    


void switchModule(){       
  digitalWrite(pinModuleOn,HIGH);
  delay(2000);
  digitalWrite(pinModuleOn,LOW);
}

void setup() {

  // UART baud rate
  Serial1.begin(115200);               
  delay(2000);  

  for (int i=0;i < 5;i++){
    Serial.println("Push the button");
    delay(5000);
  }
  // Sets the SMS mode to text
  Serial1.println("AT+CMGF=1");         
  delay(100);
}

void loop(){

  delay(100);
  float temperature = eHealth.getTemperature();     

  delay(1500);
  // send the SMS number 
  Serial1.print("AT+CMGS=\"");     
  Serial1.print(phoneNumber);
  Serial1.println("\"");
  // the SMS body 
  while(Serial1.read()!='>');      
  Serial1.print(temperature);

  delay(1000);
  //sends ++
  Serial1.write(0x1A);       
  Serial1.write(0x0D);
  Serial1.write(0x0A);
  delay(5000);

}
                

This example shows how to send data using 3G shield and making a connection to a server. Upload the next code:

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Ahmad Saad
 */

// For more information about the 3G shield please see our tutorial
// in cooking-hacks web site. http://www.cooking-hacks.com

#include <eHealth.h>
#include "Wire.h"

char data[512];
char tosend[128];
int led = 13;
int onModulePin = 2;        // the pin to switch on the module (without press on button) 

int x = 0;

char name[20];

char server[ ]="192.198.1.1"; //Your server IP address
char port[ ]="5555"; // Your port. 

void switchModule(){
  digitalWrite(onModulePin,HIGH);
  delay(2000);
  digitalWrite(onModulePin,LOW);
}

void setup(){

  Serial1.begin(115200);         // UART baud rate
  delay(2000);
  pinMode(led, OUTPUT);
  pinMode(onModulePin, OUTPUT);
  switchModule();              // switches the module ON

  for (int i=0;i< 5;i++){
    delay(5000);
  } 

  Serial1.println("AT+CGSOCKCONT=1,\"IP\",\"internetmas\"");
  Serial1.flush();
  x=0;
  do
  {
    while(Serial1.available()==0);
    data[x]=Serial1.read();  
    x++;  
  } while(!(data[x-1]=='K'&&data[x-2]=='O')); //waits for response "Network opened"


}

void loop()
{
  float temperature = eHealth.getTemperature();    
  int longitud = sprintf(tosend,"%d", temperature); 

  Serial1.print("AT+NETOPEN=\"TCP\",");
  //Opens the socket with the type of protocol and the port 
  Serial1.println(port);        
  Serial1.flush();
  x=0;
  
  do
  {
    while(Serial1.available()==0);
    data[x]=Serial1.read();  
    x++;  
  }
  while(!(data[x-1]=='K'&&data[x-2]=='O'));        //waits for response "Network opened"

  Serial1.print("AT+TCPCONNECT=\""); //Connects with the server
  Serial1.print(server);
  Serial1.print("\",");    
  Serial1.println(port);

  Serial1.flush();
  while(Serial.read()!='K');  

  Serial1.print("AT+TCPWRITE=");
  Serial1.println(longitud, DEC);    //Sends TCP data
  Serial1.flush();



  do 
  { 
    while (Serial1.available() == 0) {};      
    //Serial.println(char(Serial.read()));      
  } while(Serial1.read()!='>');  

  Serial1.println(tosend); 

  x=0;

  do
  {
    while(Serial1.available()==0);
    data[x]=Serial1.read();  
    x++;                        
  }
  while(!(data[x-1]=='K'&&data[x-2]=='O'));

  Serial1.println("AT+NETCLOSE"); //Opens the socket with the type of protocol and the port 
  Serial1.flush();
  while(Serial1.read()!='K'); 

  while(1);

}
                

Wifi module - e-Health APPs

We will use the wifi module Roving RN-171. This module fits in the XBee socket of our Communication Shield and allows to connect your Intel Galileo to a WiFi network.

The RN-XV module by Roving Networks is a certified Wi-Fi solution especially designed for customer who want to migrate their existing 802.15.4 architecture to a standard TCP/IP based platform without having to redesign their existing hardware.

Wifi examples in the e-Health tutorial shows the way to communicate with the Wifi Demo Android and iPhone app.

The wifi module may perform direct communications with iPhone and Android devices without the need of an intermediate router by creating an Adhoc network between them.

We have developed the application e-Health Sensor Plattform, for both iPhone and Android platforms. The application may be also downloaded from the official App markets or from the Libelium website for free: http://www.cooking-hacks.com/apps

iPhone app tutorial

The use of the app is very simple, first you have to connect to one of the Intel Galileo nodes selecting it in Settings->Wi-Fi, and then launch the application.

To connect to the network created by the wifi module of Arduino: Go to Settings->Wi-Fi and select iPHONE_ADHOC.

The Intel Galileo code used in this program is presented next:

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Ahmad Saad
 */
 

#include <eHealth.h>
#include "Wire.h"

char recv[256];
uint8_t cont = 0;


void setup(){ 

  //eHealth.readGlucometer();
  Serial1.begin(9600);

} 

void loop(){ 

  Serial1.print("$$$"); 
  check();  

  // 1. Configure the transport protocol (UDP, TCP, FTP, HTTP...)  
  Serial1.print("set i p 3\r");  check();   
  // 2. Configure the way the modules will resolve the IP address. 
  Serial1.print("set i d 2\r");  check();   
  // 3. Configure how to connect the AP. 
  Serial1.print("set w a 6\r");  check();   
  // 3.1 Sets the name of the ADhoc network.  
  Serial1.print("set w s iPHONE_ADHOC\r");  check();   
  // 3.2 Sets the channel of the ADhoc network     
  Serial1.print("set w c 6\r");  check();

  Serial1.print("set w j 4\r");  check();
  Serial1.print("save\r");  check();
  Serial1.print("exit\r");  check();
  Serial1.print("$$$");  check();
  // Configures UDP host and ports.
  Serial1.print("set i h 255.255.255.255\r");  check();
  Serial1.print("set i r 12345\r");  check();
  Serial1.print("set i l 2000\r");  check();
  // Checks if everything is Ok, even if It's correctly connected.

  // Exits from command mode, and then the UDP messages 
  // can be sent and received.
  Serial1.print("exit\r");
  check();

  delay(1000);  


  while(1){     

    //1. Read from eHealth. 
    int airFlow = eHealth.getAirFlow();     
    float temperature = eHealth.getTemperature();     
    float conductance = eHealth.getSkinConductance();   
    float resistance = eHealth.getSkinResistance();
    float conductanceVol = eHealth.getSkinConductanceVoltage();
    int BPM = 0;     
    int SPO2 = 0;     
    uint8_t pos = 0;      
    //int syst = eHealth.getSystolicPressure(1);
    //int diast = eHealth.getDiastolicPressure(1);         
    float ECG = eHealth.getECG();
    //uint8_t glucose = eHealth.glucoseDataVector[0].glucose;

    // 2. Send data to the Android smartphone    
    Serial1.print(int(airFlow));         Serial1.print("#");
    Serial1.print(ECG);                  Serial1.print("#");
    Serial1.print(temperature);          Serial1.print("#");
    Serial1.print(int(BPM));             Serial1.print("#");
    Serial1.print(int(SPO2));            Serial1.print("#");
    Serial1.print(conductance);          Serial1.print("#");
    Serial1.print(int(resistance));      Serial1.print("#");
    Serial1.print(int(airFlow));         Serial1.print("#");
    Serial1.print(0);                    Serial1.print("#");  //Systolic is not implemented
    Serial1.print(0);                    Serial1.print("#");  //Diastolic is not implemented 
    Serial1.print(int(0));               Serial1.print("#");  //Glucose is not implemented
    Serial1.print(int(pos));             Serial1.print("#");
    Serial1.print("\n");    
    
    // Reduce this delay for more data rate
    delay(100);  
  }

}

//=========================================================================

void check(){
  cont=0; 
  delay(500);
  while (Serial1.available()>0)
  {
    recv[cont]=Serial1.read(); 
    delay(10);
    cont++;
  }
  recv[cont]='\0';
  Serial.println(recv);
  Serial1.flush(); 
  delay(100);
}
                

Android app tutorial

The use of the app is very simple, first you have to create an AP from your Android device and then set Intel Galileo to connect to it.

To create the AP from the Android device:

Go to Settings->Tethering & Portable Hotspot or Settings->Wifi-> My Wifi Zone (depending of the version of mobile).

Then configure the WLAN hotspot (name= ANDROID, Security= None).

The Intel Galileo code used in this program is presented next:

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Ahmad Saad
 */
 

#include <eHealth.h>
#include "Wire.h"

char recv[128];
uint8_t cont = 0;


void setup()
{ 
  Serial1.begin(9600);
  delay(1000);
  
}

void loop()
{
  while (Serial1.available()>0) {}
  // Enters in command mode    
    Serial1.print("$$$"); check();  
  // Sets DHCP and TCP protocol
    Serial1.print("set ip dhcp 1\r"); check();
    Serial1.print("set ip protocol 1\r"); check();
  // Configures the way to join the network AP
    Serial1.print("set wlan join 0\r"); check();
    Serial1.print("join ANDROID\r"); check();
  
    Serial1.print("set i h 255.255.255.255\r"); delay(1000);
    
    Serial1.print("set i r 12345\r"); check();
    Serial1.print("set i l 2000\r"); check();
    Serial1.print("exit\r"); check();

    while(1){     
      
      //1. Read from eHealth. 
       int airFlow = eHealth.getAirFlow();     
       float temperature = eHealth.getTemperature();     
       float conductance = eHealth.getSkinConductance();   
       float resistance = eHealth.getSkinResistance();
       float conductanceVol = eHealth.getSkinConductanceVoltage();
       int BPM = 0;     
       int SPO2 = 0;     
       uint8_t pos = 0;      
       //int syst = eHealth.getSystolicPressure(1);
       //int diast = eHealth.getDiastolicPressure(1);     
       float ECG = eHealth.getECG();
       //uint8_t glucose = eHealth.glucoseDataVector[0].glucose;      

      //Data sensor must be sent in this order to mobile android application 
      Serial1.print(int(airFlow));     Serial1.print("#");
      Serial1.print(int(ECG));         Serial1.print("#");
      Serial1.print(int(0));           Serial1.print("#"); //Systolic is not implemented
      Serial1.print(int(0));           Serial1.print("#"); //Diastolic is not implemented 
      Serial1.print(int(0));           Serial1.print("#"); //Glucose is not implemented
      Serial1.print(int(temperature)); Serial1.print("#");
      Serial1.print(int(BPM));         Serial1.print("#");
      Serial1.print(int(SPO2));        Serial1.print("#");
      Serial1.print(int(conductance)); Serial1.print("#");
      Serial1.print(int(resistance));  Serial1.print("#");
      Serial1.print(int(airFlow));     Serial1.print("#");
      Serial1.print(int(pos));         Serial1.print("#");
      Serial1.print("\n");    
    
      // Reduce this delay for more data rate
      delay(250);  
  }
}

void check(){
  cont=0; delay(500);
  while (Serial1.available()>0)
  {
     recv[cont]=Serial1.read(); delay(10);
     cont++;
  }
  recv[cont]='\0';
  Serial.println(recv);
  Serial.flush(); delay(100);
}
                
Refer to Wifi tutorial for more information.

4.2 3G / GPRS / GPS

GPRS (SIM900) - SMS and lost calls

GPRS Quadband Module (SIM900) offers GPRS connection to your Arduino/RasberryPi/IntelGalileo board. You can send your data by SMS or do missed calls from your device to mobile devices... or to another Arduino/RasberryPi/IntelGalileo connected to this module.

Originating voice calls

The code example shown below are used to make a lost call:

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Alejandro Gallego
 */
 
 
int8_t answer;
int onModulePin = 2;
int button = 12;
char aux_str[30];

char phone_number[]="*********";     // ********* is the number to call

void setup(){

    pinMode(onModulePin, OUTPUT);
    pinMode(button, INPUT);
    Serial1.begin(115200);
    Serial.begin(115200);      

    Serial.println("Starting...");
    power_on();
    
    delay(3000);
    
    // sets the PIN code
    sendATcommand("AT+CPIN=****", "OK", 2000);
    
    delay(3000);
    
    Serial.println("Connecting to the network...");

    while( (sendATcommand("AT+CREG?", "+CREG: 0,1", 500) || 
            sendATcommand("AT+CREG?", "+CREG: 0,5", 500)) == 0 );

    sprintf(aux_str, "ATD%s;", phone_number);
    sendATcommand(aux_str, "OK", 10000);
    
    // press the button for hang the call 
    while(digitalRead(button)==1);        

    //Serial.println("ATH");            // disconnects the existing call
    

}

void loop(){

}

void power_on(){

    uint8_t answer=0;
    
    // checks if the module is started
    answer = sendATcommand("AT", "OK", 2000);
    if (answer == 0)
    {
        // power on pulse
        digitalWrite(onModulePin,HIGH);
        delay(3000);
        digitalWrite(onModulePin,LOW);
    
        // waits for an answer from the module
        while(answer == 0){     // Send AT every two seconds and wait for the answer
            answer = sendATcommand("AT", "OK", 2000);    
        }
    }
    
}

int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout){

    uint8_t x=0,  answer=0;
    char response[100];
    unsigned long previous;

    memset(response, '\0', 100);    // Initialice the string
    
    delay(100);
    
    while( Serial1.available() > 0) Serial1.read();    // Clean the input buffer
    
    Serial1.println(ATcommand);    // Send the AT command 


    x = 0;
    previous = millis();

    // this loop waits for the answer
    do{
        // if there are data in the UART input buffer, reads it and checks for the asnwer
        if(Serial1.available() != 0){    
            response[x] = Serial1.read();
            x++;
            // check if the desired answer is in the response of the module
            if (strstr(response, expected_answer) != NULL)    
            {
                answer = 1;
            }
        }
    // Waits for the asnwer with time out
    }while((answer == 0) && ((millis() - previous) < timeout));    

    return answer;
}
                

Command summary

Command Response Description
ATD********* ********* is the number to call
ATA OK Answer an incoming call
ATH OK Cancel voice calls

Using the shield in standalone mode - Sending and receiving SMS

The next code is used to send a SMS:

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Alejandro Gallego
 */

int8_t answer;
int onModulePin= 2;
char aux_string[30];
char phone_number[]="*********";

void setup(){

    pinMode(onModulePin, OUTPUT);
    Serial1.begin(115200);    
    Serial.begin(115200);
    Serial.println("Starting...");
    power_on();
    
    delay(3000);
    
    // sets the PIN code
    sendATcommand("AT+CPIN=****", "OK", 2000);
    
    delay(3000);
    
    Serial.println("Connecting to the network...");

    while( (sendATcommand("AT+CREG?", "+CREG: 0,1", 500) || 
            sendATcommand("AT+CREG?", "+CREG: 0,5", 500)) == 0 );

    Serial.print("Setting SMS mode...");
    sendATcommand("AT+CMGF=1", "OK", 1000);    // sets the SMS mode to text
    Serial.println("Sending SMS");
    
    sprintf(aux_string,"AT+CMGS=\"%s\"", phone_number);
    answer = sendATcommand(aux_string, ">", 2000);    // send the SMS number
    if (answer == 1)
    {
        Serial1.println("Test-Arduino-Hello World");
        Serial1.write(0x1A);
        answer = sendATcommand("", "OK", 20000);
        if (answer == 1)
        {
            Serial.print("Sent ");    
        }
        else
        {
            Serial.print("error ");
        }
    }
    else
    {
        Serial.print("error ");
        Serial.println(answer, DEC);
    }

}


void loop(){

}

void power_on(){

    uint8_t answer=0;
    
    // checks if the module is started
    answer = sendATcommand("AT", "OK", 2000);
    if (answer == 0)
    {
        // power on pulse
        digitalWrite(onModulePin,HIGH);
        delay(3000);
        digitalWrite(onModulePin,LOW);
    
        // waits for an answer from the module
        while(answer == 0){     // Send AT every two seconds and wait for the answer
            answer = sendATcommand("AT", "OK", 2000);    
        }
    }
    
}

int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout){

    uint8_t x=0,  answer=0;
    char response[100];
    unsigned long previous;

    memset(response, '\0', 100);    // Initialice the string
    
    delay(100);
    
    while( Serial1.available() > 0) Serial1.read();    // Clean the input buffer
    
    Serial1.println(ATcommand);    // Send the AT command 


    x = 0;
    previous = millis();

    // this loop waits for the answer
    do{
        // if there are data in the UART input buffer, reads it and checks for the asnwer
        if(Serial1.available() != 0){    
            response[x] = Serial1.read();
            x++;
            // check if the desired answer is in the response of the module
            if (strstr(response, expected_answer) != NULL)    
            {
                answer = 1;
            }
        }
    // Waits for the asnwer with time out
    }while((answer == 0) && ((millis() - previous) < timeout));    

    return answer;
}
                

Command summary

Command Response Description
AT+CMGF= OK Specifies the input and output format of the short messages. 0 for PDU mode and 1 for text mode
AT+CMGS Sends a message
AT+CMGR=* Reads a message. * is the number of the message.
Refer to GPRS tutorial for more information

GPS module

The GPS module is a small electronic circuit that allows to connect to your Intel Galileo board to get position and altitude, as well as speed, date and time on UTC (Universal Time Coordinated). It uses the standard NMEA protocol (http://www.nmea.org) to transmit the position data via serial port.

For connecting the GPS module to a Intel Galileo we need to use the Rx and Tx pins of the shield.

Once the GPS is connected, you have to connect power to it. Using two small wires (red for 5V and black for GND). See the picture.

Use the following serial port configuration: 4800 baud, 8 data bits, no parity, 1 stop bit, no flow control.

You'll se the NMEA sentences coming from the GPS module.

Connect the GPS to Intel Galileo as shown in the picture.

There are some NMEA commands that we can use for controlling the output NMEA messages of the GPS module. We can activate / deactivate each NMEA message (GGA, GLL, GSA, GSV, RMC and VTG) sending to the module these commands.

Refer to GPS tutorial for more information

GPRS+GPS (SIM908)

The new shield designed for Arduino and Raspberry Pi integrates the SIM908 module which counts with both GPRS and GPS technologies what allows to easily perform realtime tracking applications. It is compatible with Intel Galileo board.

The board (shield) we are going to use in this section is the GPRS+GPS Quadband Module for Arduino (SIM908) from Cooking hacks.

Using the shield in standalone mode - GPS

The SIM908 includes a GPS receive.

The next sketch shows how to power on the GPS and get the NMEA strings when the satellites had been fixed:

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Alejandro Gallego
 */
 
 
int8_t answer;
int onModulePin= 2;
int counter;
long previous;


char Basic_str[100];
char GGA_str[100];
char GLL_str[100];
char RMC_str[100];
char VTG_str[100];
char ZDA_str[100];

void setup(){
    
    pinMode(onModulePin, OUTPUT);
    Serial.begin(115200);
    Serial1.begin(115200);      
    
    Serial.println("Starting...");
    power_on();
    
    delay(3000);
    
    // sets the PIN code
    sendATcommand("AT+CPIN=****", "OK", 2000);
    
    delay(3000);
    
    // sets APN, user name and password
    sendATcommand("AT+CGPSPWR=1", "OK", 2000);
    sendATcommand("AT+CGPSRST=0", "OK", 2000);
    
    
    // waits for fix GPS
    while( (sendATcommand("AT+CGPSSTATUS?", "2D Fix", 5000) || 
            sendATcommand("AT+CGPSSTATUS?", "3D Fix", 5000)) == 0 );
    

}

void loop(){
    // Basic
    // Clean the input buffer
    while( Serial.available() > 0) Serial.read();    
    delay(100);
    // request Basic string
    sendATcommand("AT+CGPSINF=0", "AT+CGPSINF=0\r\n\r\n", 2000);
    
    counter = 0;
    answer = 0;
    memset(Basic_str, '\0', 100);    // Initialize the string
    previous = millis();
    // this loop waits for the NMEA string
    do{

        if(Serial.available() != 0){    
            Basic_str[counter] = Serial.read();
            counter++;
            // check if the desired answer is in the response of the module
            if (strstr(Basic_str, "OK") != NULL)    
            {
                answer = 1;
            }
        }
        // Waits for the asnwer with time out
    }while((answer == 0) && ((millis() - previous) < 2000));  
    
    Basic_str[counter-3] = '\0';
    
    //**********************************************************
    // GGA
    // Clean the input buffer
    while( Serial.available() > 0) Serial.read();    
    delay(100);
    // request GGA string
    sendATcommand("AT+CGPSINF=2", "AT+CGPSINF=2\r\n\r\n", 2000);
    
    counter = 0;
    answer = 0;
    memset(GGA_str, '\0', 100);    // Initialize the string
    previous = millis();
    // this loop waits for the NMEA string
    do{

        if(Serial.available() != 0){    
            GGA_str[counter] = Serial.read();
            counter++;
            // check if the desired answer is in the response of the module
            if (strstr(GGA_str, "OK") != NULL)    
            {
                answer = 1;
            }
        }
        // Waits for the asnwer with time out
    }while((answer == 0) && ((millis() - previous) < 2000));  
    
    GGA_str[counter-3] = '\0';
    
    //**********************************************************
    // GLL
    // Clean the input buffer
    while( Serial.available() > 0) Serial.read();    
       
    delay(100);
    // request GLL string
    sendATcommand("AT+CGPSINF=4", "AT+CGPSINF=4\r\n\r\n", 2000);   
    
    counter = 0;
    answer = 0;
    memset(GLL_str, '\0', 100);    // Initialize the string
    previous = millis();
    // this loop waits for the NMEA string
    do{

        if(Serial.available() != 0){    
            GLL_str[counter] = Serial.read();
            counter++;
            // check if the desired answer is in the response of the module
            if (strstr(GLL_str, "OK") != NULL)    
            {
                answer = 1;
            }
        }
        // Waits for the asnwer with time out
    }while((answer == 0) && ((millis() - previous) < 2000)); 
    
    GLL_str[counter-3] = '\0';
        
    //**********************************************************
    // RMC
    // Clean the input buffer
    while( Serial.available() > 0) Serial.read();    
       
    delay(100);
    // request RMC string 
    sendATcommand("AT+CGPSINF=32", "AT+CGPSINF=32\r\n\r\n", 2000);
    
    counter = 0;
    answer = 0;
    memset(RMC_str, '\0', 100);    // Initialize the string
    previous = millis();
    // this loop waits for the NMEA string
    do{

        if(Serial.available() != 0){    
            RMC_str[counter] = Serial.read();
            counter++;
            // check if the desired answer is in the response of the module
            if (strstr(RMC_str, "OK") != NULL)    
            {
                answer = 1;
            }
        }
        // Waits for the asnwer with time out
    }while((answer == 0) && ((millis() - previous) < 2000)); 
    
    RMC_str[counter-3] = '\0';
    
    //**********************************************************
    // VTG
    // Clean the input buffer
    while( Serial.available() > 0) Serial.read();    
       
    delay(100);
    // request VTG string
    sendATcommand("AT+CGPSINF=64", "AT+CGPSINF=64\r\n\r\n", 2000); 
    
    counter = 0;
    answer = 0;
    memset(VTG_str, '\0', 100);    // Initialize the string
    previous = millis();
    // this loop waits for the NMEA string
    do{

        if(Serial.available() != 0){    
            VTG_str[counter] = Serial.read();
            counter++;
            // check if the desired answer is in the response of the module
            if (strstr(VTG_str, "OK") != NULL)    
            {
                answer = 1;
            }
        }
        // Waits for the asnwer with time out
    }while((answer == 0) && ((millis() - previous) < 2000)); 
    
    VTG_str[counter-3] = '\0';
    
    //**********************************************************
    // ZDA
    // Clean the input buffer
    while( Serial.available() > 0) Serial.read();    
       
    delay(100);
    // request ZDA string
    sendATcommand("AT+CGPSINF=128", "AT+CGPSINF=128\r\n\r\n", 2000);
    
    counter = 0;
    answer = 0;
    memset(ZDA_str, '\0', 100);    // Initialize the string
    previous = millis();
    // this loop waits for the NMEA string
    do{

        if(Serial.available() != 0){    
            ZDA_str[counter] = Serial.read();
            counter++;
            // check if the desired answer is in the response of the module
            if (strstr(ZDA_str, "OK") != NULL)    
            {
                answer = 1;
            }
        }
        // Waits for the asnwer with time out
    }while((answer == 0) && ((millis() - previous) < 2000));
    
    ZDA_str[counter-3] = '\0';
    
    Serial.println("*************************************************");
    Serial.print("Basic string: ");
    Serial.println(Basic_str);
    Serial.print("GGA string: ");
    Serial.println(GGA_str);
    Serial.print("GLL string: ");
    Serial.println(GLL_str);
    Serial.print("RMC string: ");
    Serial.println(RMC_str);
    Serial.print("VTG string: ");
    Serial.println(VTG_str);
    Serial.print("ZDA string: ");
    Serial.println(ZDA_str);
   
    delay(15000);

}

void power_on(){

    uint8_t answer=0;
    
    // checks if the module is started
    answer = sendATcommand("AT", "OK", 2000);
    if (answer == 0)
    {
        // power on pulse
        digitalWrite(onModulePin,HIGH);
        delay(3000);
        digitalWrite(onModulePin,LOW);
    
        // waits for an answer from the module
        while(answer == 0){    
            // Send AT every two seconds and wait for the answer
            answer = sendATcommand("AT", "OK", 2000);    
        }
    }
    
}


int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout){

    uint8_t x=0,  answer=0;
    char response[100];
    unsigned long previous;

    memset(response, '\0', 100);    // Initialice the string
    
    delay(100);
    
    while( Serial1.available() > 0) Serial1.read();    // Clean the input buffer
    
    Serial1.println(ATcommand);    // Send the AT command 


    x = 0;
    previous = millis();

    // this loop waits for the answer
    do{
        // if there are data in the UART input buffer, reads it and checks for the asnwer
        if(Serial1.available() != 0){    
            response[x] = Serial1.read();
            x++;
            // check if the desired answer is in the response of the module
            if (strstr(response, expected_answer) != NULL)    
            {
                answer = 1;
            }
        }
    // Waits for the asnwer with time out
    }while((answer == 0) && ((millis() - previous) < timeout));    

    return answer;
}
                

Command summary

AT command Response Description
AT+CGPSPWR OK Powers the GPS
AT+CGPSRST OK Sets the reset mode
AT+CGPSSTATUS Gets the status: Unknown, Not Fix, 2D Fix and 3D Fix
AT+CGPSINF NMEA string Gets NMEA strings
Refer to GPRS+GPS tutorial for more information.

3G+GPS - Videocalls

The new 3G + GPS Shield enables the connectivity to high speed WCDMA and HSPA cellular networks in order to make possible the creation of the next level of worldwide interactivity projects inside the new "Internet of Things" era.

The module counts also with an internal GPS what enables the location of the device outdoors and indoors combining standard NMEA frames with mobile cell ID triangulation using both assisted-mobile (A-GPS) and mobile-based (S-GPS) modes.

Other interesting accessories which can be connected to the module are a video camera which enables the record of video in high resolution (640x480), an audio kit including microphone, speaker, hands free and headphones sets and a SD socket to save directly all the data coming from the 3G network or recorded from the video camera. You can even reproduce audio files stored in the SD card (almost and mp3 player!).

Features

  • WCDMA and HSPA 3G networks compatibility
  • Internal GPS for Assisted A-GPS and Supported S-GPS modes
  • High Resolution Camera (2MP) for photo and video recordings available
  • Audio Kit including microphone, speaker, hands free and headphones available
  • Works as a standard 3G modem in Linux/Windows/MacOS (~7.2Mbps download, ~5.5Mbps upload)
  • Talk directly to web servers by HTTP/HTTPS (secure)
  • Upload and download files directly by FTP/FTPS (secure)
  • Send and receive mails by POP3/SMTP
  • Play compressed audio files

Camera features

This module allows to connect a camera for video recording and taking photos. Once saved the video or image file can be sent to an FTP or FTPS as you'll see later.

Video call

The SIM5218 allows video calls, but to carry them out correctly the operator and the network must be able to allow it. The example code is below. Cooking Hacks not ensure that the video call functions correctly.

Please, be sure that your SIM card have activated the videocall feature, with your network operator and with the phone that you want to call, before to test the next sketch:

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n
 */


int8_t answer;
int onModulePin = 2;
int button = 12;
char aux_str[30];

char phone_number[]="619913824";     // ********* is the number to call

void setup(){

    pinMode(onModulePin, OUTPUT);
    pinMode(button, INPUT);
    Serial1.begin(115200);      
    Serial.begin(115200);   

    Serial.println("Starting...");
    power_on();
    Serial.println("Starting...");
    delay(3000);

    // sets the PIN code
    sendATcommand2("AT+CPIN=****", "OK", "ERROR", 2000);

    delay(3000);

    Serial.println("Connecting to the network...");

    while(sendATcommand2("AT+CREG?", "+CREG: 0,1", "+CREG: 0,5", 1000) == 0 );


    // Starts the camera
    answer = sendATcommand2("AT+CCAMS", "OK", "CAMERA NO SENSOR", 3000);
    if (answer == 1)
    {
        // Sets resolution
        sendATcommand2("AT+CCAMSETD=320,240", "OK", "ERROR", 2000);

        sprintf(aux_str, "AT+VPMAKE=%s", phone_number);
        answer = sendATcommand2(aux_str, "VPCONNECTED", "VPEND", 30000);
        if (answer == 1)
        {
            delay(20000);
            sendATcommand2("AT+VPEND", "OK", "", 30000);
        }
        else
        {
            Serial.println("Error originating the call");    
        }
    }
    else if (answer == 2)
    {
        Serial.println("Camera not detected");    
    }
    else
    {
        Serial.println("Error starting the camera");    
    }

}


void loop(){

}



void power_on(){

    uint8_t answer=0;

    // checks if the module is started
    answer = sendATcommand2("AT", "OK", "OK", 2000);
    
    Serial.println("Error starting the camera");  
    if (answer == 0)
    {
        // power on pulse
        digitalWrite(onModulePin,HIGH);
        delay(3000);
        digitalWrite(onModulePin,LOW);
Serial.println("Error");  
        // waits for an answer from the module
        while(answer == 0){    
            // Send AT every two seconds and wait for the answer
            answer = sendATcommand2("AT", "OK", "OK", 2000);    
        }
    }

}


int8_t sendATcommand2(char* ATcommand, char* expected_answer1,
    char* expected_answer2, unsigned int timeout)
{

    uint8_t x=0,  answer=0;
    char response[100];
    unsigned long previous;

    memset(response, '\0', 100);    // Initialize the string

    delay(100);

    // Clean the input buffer
    while( Serial1.available() > 0) Serial1.read(); 

    Serial1.println(ATcommand);    // Send the AT command 


        x = 0;
    previous = millis();

    // this loop waits for the answer
    do{
   int hola = Serial1.available();
      Serial.println(hola,DEC);  
        if(Serial1.available() != 0){    
            response[x] = Serial1.read();
            Serial.println(response[x]);  
            x++;
            // check if the expected answer 1 is in the response of the module
            if (strstr(response, expected_answer1) != NULL)    
            {
                answer = 1;
            }
            // check if the expected answer 2 is in the response of the module
            if (strstr(response, expected_answer2) != NULL)    
            {
                answer = 2;
            }
        }
        // Waits for the asnwer with time out
    }
    while((answer == 0) && ((millis() - previous) < timeout));    

    return answer;
}
                

Command summary

Command Response Description
AT+CCAMS OK Starts camera
AT+CCAME OK Stops camera
AT+CCAMSETD=xxx,yyy OK Sets dimension of camera. xxx is the width and yyy is the height
AT+CCAMSETF=* OK Sets the frames per second. * is the frame rate option
AT+CCAMRS OK Starts video recording. Also responds with the path and name of the file
AT+CCAMRP OK Pauses the record
AT+CCAMRR OK Resumes video record
AT+CCAMRE OK Stops video record
AT+CCAMTP OK Takes a picture
AT+CCAMEP OK Saves a picture taken by last AT+CCAMTP. Also responds with the path and name of the file
AT+VPMAKE Makes a video call
AT+VPEND Ends a video call
Refer to 3G tutorial for more information.

4.3 RFID

RFID (Radio Frequency Identification) is a technology that uses electromagnetic fields to identify objects in a contactless way; it is also called proximity identification. There are 2 elements in RFID communications: the RFID module (or reader/writer device) and an RFID card (or tag). The RFID module acts as the master and the card acts as the slave; this means the module queries the card and sends instructions to it. In a normal RFID communication, the RFID module is fixed and the user takes his card near it when he needs to start the interaction.

RFID 125 Khz

RFID 125 KHz Shield can be connected to Intel Galileo using a XBee shield and will communicate it using the Intel Galileo serial port (UART).

Setting up the hardware is very easy, just plug the XBee shield with the RFID module. The jumpers in the XBee shield have to be set to XBEE position. Now you can program the Intel Galileo and communicate it with the RFID module using the serial port (Serial.read(), Serial.print()...).

Reading EM4100 cards (read only cards):

In this part we show an example of the Intel Galileo reading EM4100 cards. We use the Auto Read mode. Intel Galileo is waiting all the time, when a card is detected, we read its code, blink the LED and print the code over USB port.

Command

0x87 - Set Auto Mode: EM4102 Mode - Parity decoded - Manchester RF/64

FF 01 09 87 01 03 02 00 10 20 30 40 37

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Marcos Yarza
 */

// var
int led = 13;
byte data_1 = 0x00;
byte data_2 = 0x00;
byte data_3 = 0x00;
byte data_4 = 0x00;
byte data_5 = 0x00;
int val = 0;

void setup(){
// Start serial port 19200 bps
Serial.begin(19200);
Serial1.begin(19200);


pinMode(led, OUTPUT);
delay(500);
  
// Setting Auto Read Mode - EM4102 Decoded Mode - No password
// command: FF 01 09 87 01 03 02 00 10 20 30 40 37
Serial1.write(0xFF);
Serial1.write(0x01);
Serial1.write(0x09);
Serial1.write(0x87);
Serial1.write(0x01);
Serial1.write(0x03);
Serial1.write(0x02);
Serial1.write((byte)0x00);
Serial1.write(0x10);
Serial1.write(0x20);
Serial1.write(0x30);
Serial1.write(0x40);
Serial1.write(0x37);

delay(500);
Serial1.flush();
Serial.println();
Serial.println("RFID module started in Auto Read Mode");
}

void loop(){

val = Serial1.read();
while (val != 0xff){
  Serial.println("Waiting card");
  val = Serial1.read();
  delay(1000);
}

// Serial.read();    // we read ff
Serial1.read();    // we read 01
Serial1.read();    // we read 06
Serial1.read();    // we read 10
data_1 = Serial1.read();    // we read data 1
data_2 = Serial1.read();    // we read data 2
data_3 = Serial1.read();    // we read data 3
data_4 = Serial1.read();    // we read data 4
data_5 = Serial1.read();    // we read data 5
Serial1.read();    // we read checksum

// Led blink
for(int i = 0;i<4;i++){
  digitalWrite(led,HIGH);
  delay(500);
  digitalWrite(led,LOW);
  delay(500);
}

// Printing the code of the card
Serial.println();
Serial.print("EM4100 card found - Code: ");
writeByte(data_1);
writeByte(data_2);
writeByte(data_3);
writeByte(data_4);
writeByte(data_5);
Serial.println();
Serial.println();

}

//Write a byte (hex) in ASCII
void writeByte(byte data){
int aux_1 = 0;
int aux_2 = 0;

  aux_1=data/16;
  aux_2=data%16;
  if (aux_1<10){
  Serial.write(aux_1 + 48);
  }
  else{
  Serial.write(aux_1+55);
  }
  if (aux_2<10){
  Serial.write(aux_2 + 48);
  }
  else{
  Serial.write(aux_2 + 55);
  }
Serial.print(" ");
}
                

Reading T5557 cards:

The next example of use of the RFID module is the reading of T5557 rewritable cards using Intel Galileo.

Command

0x87 - Set Auto Mode: Byte track mode - Parity decoded - Manchester RF/64, 7 blocks, without password.

FF 01 09 87 01 01 07 00 10 20 30 40 3A

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Marcos Yarza
 */

// var
int led = 13;
byte block1_byte1 = 0x00;
byte block1_byte2 = 0x00;
byte block1_byte3 = 0x00;
byte block1_byte4 = 0x00;

byte block2_byte1 = 0x00;
byte block2_byte2 = 0x00;
byte block2_byte3 = 0x00;
byte block2_byte4 = 0x00;

byte block3_byte1 = 0x00;
byte block3_byte2 = 0x00;
byte block3_byte3 = 0x00;
byte block3_byte4 = 0x00;

byte block4_byte1 = 0x00;
byte block4_byte2 = 0x00;
byte block4_byte3 = 0x00;
byte block4_byte4 = 0x00;

byte block5_byte1 = 0x00;
byte block5_byte2 = 0x00;
byte block5_byte3 = 0x00;
byte block5_byte4 = 0x00;

byte block6_byte1 = 0x00;
byte block6_byte2 = 0x00;
byte block6_byte3 = 0x00;
byte block6_byte4 = 0x00;

byte block7_byte1 = 0x00;
byte block7_byte2 = 0x00;
byte block7_byte3 = 0x00;
byte block7_byte4 = 0x00;

int val = 0;

void setup(){
// Start serial port 19200 bps
Serial.begin(19200);
Serial1.begin(19200);

pinMode(led, OUTPUT);
delay(500);
  
// Setting Auto Read Mode - T5557 7 blocks without password
  
Serial1.write(0xFF);
Serial1.write(0x01);
Serial1.write(0x09);
Serial1.write(0x87);
Serial1.write(0x01);
Serial1.write(0x01);
Serial1.write(0x07);
Serial1.write((byte)0x00);
Serial1.write(0x10);
Serial1.write(0x20);
Serial1.write(0x30);
Serial1.write(0x40);
Serial1.write(0x3A);

delay(500);
Serial1.flush();
Serial.println();
Serial.println();
Serial.println("RFID module started in Auto Read Mode");
}

void loop(){

val = Serial1.read();
while (val != 0xff){
  Serial.println("Waiting card");
  val = Serial1.read();
  delay(1000);
}

// Serial.read();    // we read ff
Serial1.read();    // we read 01
Serial1.read();    // we read 1d
Serial1.read();    // we read 10

block1_byte1 = Serial1.read();    // we read block 1 byte 1
block1_byte2 = Serial1.read();    // we read block 1 byte 2
block1_byte3 = Serial1.read();    // we read block 1 byte 3
block1_byte4 = Serial1.read();    // we read block 1 byte 4

block2_byte1 = Serial1.read();    // we read block 2 byte 1
block2_byte2 = Serial1.read();    // we read block 2 byte 2
block2_byte3 = Serial1.read();    // we read block 2 byte 3
block2_byte4 = Serial1.read();    // we read block 2 byte 4

block3_byte1 = Serial1.read();    // we read block 3 byte 1
block3_byte2 = Serial1.read();    // we read block 3 byte 2
block3_byte3 = Serial1.read();    // we read block 3 byte 3
block3_byte4 = Serial1.read();    // we read block 3 byte 4

block4_byte1 = Serial1.read();    // we read block 4 byte 1
block4_byte2 = Serial1.read();    // we read block 4 byte 2
block4_byte3 = Serial1.read();    // we read block 4 byte 3
block4_byte4 = Serial1.read();    // we read block 4 byte 4

block5_byte1 = Serial1.read();    // we read block 5 byte 1
block5_byte2 = Serial1.read();    // we read block 5 byte 2
block5_byte3 = Serial1.read();    // we read block 5 byte 3
block5_byte4 = Serial1.read();    // we read block 5 byte 4

block6_byte1 = Serial1.read();    // we read block 6 byte 1
block6_byte2 = Serial1.read();    // we read block 6 byte 2
block6_byte3 = Serial1.read();    // we read block 6 byte 3
block6_byte4 = Serial1.read();    // we read block 6 byte 4

block7_byte1 = Serial1.read();    // we read block 7 byte 1
block7_byte2 = Serial1.read();    // we read block 7 byte 2
block7_byte3 = Serial1.read();    // we read block 7 byte 3
block7_byte4 = Serial1.read();    // we read block 7 byte 4
  
Serial1.read();    // we read checksum

// Led blink
for(int i = 0;i<4;i++){
  digitalWrite(led,HIGH);
  delay(500);
  digitalWrite(led,LOW);
  delay(500);
}

// Printing the code of the card
Serial.println();
Serial.println("T5557 card found - Data read: ");
Serial.println("---------------------------------------");
Serial.print("-- Block 1 -- | ");  writeByte(block1_byte1);
Serial.print(" | ");  writeByte(block1_byte2);
Serial.print(" | ");  writeByte(block1_byte3);
Serial.print(" | ");  writeByte(block1_byte4);
Serial.println(" |");
Serial.print("-- Block 2 -- | ");  writeByte(block2_byte1);
Serial.print(" | ");  writeByte(block2_byte2);
Serial.print(" | ");  writeByte(block2_byte3);
Serial.print(" | ");  writeByte(block2_byte4);
Serial.println(" |");
Serial.print("-- Block 3 -- | ");  writeByte(block3_byte1);
Serial.print(" | ");  writeByte(block3_byte2);
Serial.print(" | ");  writeByte(block3_byte3);
Serial.print(" | ");  writeByte(block3_byte4);
Serial.println(" |");
Serial.print("-- Block 4 -- | ");  writeByte(block4_byte1);
Serial.print(" | ");  writeByte(block4_byte2);
Serial.print(" | ");  writeByte(block4_byte3);
Serial.print(" | ");  writeByte(block4_byte4);
Serial.println(" |");
Serial.print("-- Block 5 -- | ");  writeByte(block5_byte1);
Serial.print(" | ");  writeByte(block5_byte2);
Serial.print(" | ");  writeByte(block5_byte3);
Serial.print(" | ");  writeByte(block5_byte4);
Serial.println(" |");
Serial.print("-- Block 6 -- | ");  writeByte(block6_byte1);
Serial.print(" | ");  writeByte(block6_byte2);
Serial.print(" | ");  writeByte(block6_byte3);
Serial.print(" | ");  writeByte(block6_byte4);
Serial.println(" |");
Serial.print("-- Block 7 -- | ");  writeByte(block7_byte1);
Serial.print(" | ");  writeByte(block7_byte2);
Serial.print(" | ");  writeByte(block7_byte3);
Serial.print(" | ");  writeByte(block7_byte4);
Serial.println(" |");
Serial.println("---------------------------------------");

Serial.println();

}

//Write a byte (hex) in ASCII
void writeByte(byte data){
int aux_1 = 0;
int aux_2 = 0;

  aux_1=data/16;
  aux_2=data%16;
  if (aux_1<10){
Serial.write(aux_1 + 48);
  }
  else{
Serial.write(aux_1+55);
  }
  if (aux_2<10){
Serial.write(aux_2 + 48);
  }
  else{
Serial.write(aux_2 + 55);
  }
Serial.print(" ");
}
                
Refer to RFID125KHZ tutorial for more information.

RFID 13.56 MHz/NFC

RFID 13.56 MHz/NFC Shield can be connected to Intel Galileo using a XBee shield and will communicate it using theserial port (UART).

Setting up the hardware is very easy, just plug the XBee shield with the RFID/NFC module to Intel Galileo. The jumpers in the XBee shield have to be set to XBEE position.

In this part we show an example of the Intel Galileo reading Mifare tags. We use the Auto Read mode. Intel Galileo is waiting all the time, when a tag is detected, we read its code, and print the code over USB port.

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Ahmad Saad
 */

uint8_t dataRX[35];//Receive buffer.
uint8_t dataTX[35];//Transmit buffer.
uint8_t _UID[4];// stores the UID (unique identifier) of a card.
uint8_t keyAccess[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } ;// stores the key or password.
uint8_t address = 0x04;//Address to read.
uint8_t ATQ[2];//Answer to request
uint8_t state;//state of the process
uint8_t aux[16];//Auxiliar buffer. 

void setup()
{
	//Start serial port 115200 bps:
	Serial.begin(115200);
	Serial1.begin(115200);
	delay(100);
	Serial.print("RFID/NFC @ 13.56 MHz module started");
	delay(1000);
	//!It is needed to launch a simple command to sycnchronize
	getFirmware();
	configureSAM();
}

void loop()
{
	Serial.print("\n");
	Serial.println("Ready to read...");
	/////////////////////////////////////////////////////////////
	//Get the UID Identifier
	init(_UID, ATQ);
	Serial.print("\n");
	Serial.print( "The UID : ");
	print(_UID , 4);
	/////////////////////////////////////////////////////////////
	//Auntenticate a block with his keyAccess
	state = authenticate(_UID, address, keyAccess);
	Serial.print("\n");

	if ( state == 0) {
		Serial.println("Authentication block OK");
	} else {
	Serial.println("Authentication failed");
	}
	/////////////////////////////////////////////////////////////
	//Read from address after authentication
	state = readData(address, aux);
	Serial.print("\n");

	if (state == 0) {
		Serial.println("Read block OK");
	} else {
		Serial.println("Read failed");
	}

	Serial.print("\n");
	Serial.print("Data readed : ");
	print(aux , 16);
	Serial.print("\n");
	delay(2000);
}
//**********************************************************************
//!The goal of this command is to detect as many targets (maximum MaxTg)
// as possible in passive mode.
uint8_t init(uint8_t *UID , uint8_t *ATQ)   //! Request InListPassive
{
  Serial1.flush();

	dataTX[0] = 0x04; // Length
	lengthCheckSum(dataTX); // Length Checksum
	dataTX[2] = 0xD4;
	dataTX[3] = 0x4A; // Code
	dataTX[4] = 0x01; //MaxTarget
	dataTX[5] = 0x00; //BaudRate = 106Kbps
	dataTX[6] = 0x00; // Clear checkSum position
	checkSum(dataTX); 

	sendTX(dataTX , 7 ,23);

	for (int i = 17; i < (21) ; i++){
		_UID[i-17] = dataRX[i];
	UID[i-17] = _UID[i-17];
	}

	ATQ[0] = dataRX[13];
	ATQ[1] = dataRX[14];

	if ((dataRX[9]== 0xD5) & (dataRX[10] == 0x4B) & (dataRX[11] == 0x01)) {
		return 0;
	} else {
		return 1;
	}
}
//**********************************************************************
//!A block must be authenticated before read and write operations
uint8_t authenticate(uint8_t *UID, uint8_t blockAddress, uint8_t *keyAccess)
{
	dataTX[0] = 0x0F;
	lengthCheckSum(dataTX);
	dataTX[2] = 0xD4;
	dataTX[3] = 0x40; // inDataEchange
	dataTX[4] = 0x01; //Number of targets
	dataTX[5] = 0x60; // Authentication code
	dataTX[6] = blockAddress;
	for (int i = 0; i < 6 ; i++) {
		dataTX[i + 7] = keyAccess[i];
	}
	dataTX[13] = UID[0];  dataTX[14] = UID[1];
	dataTX[15] = UID[2];  dataTX[16] = UID[3];
	dataTX[17] = 0x00;
	checkSum(dataTX);
	sendTX(dataTX , 18 ,14);

	if ((dataRX[9]== 0xD5) & (dataRX[10] == 0x41) & (dataRX[11] == 0x00)) {
		return 0;
	} else {
		return 1;
	}
}
//**********************************************************************
//!Write 16 bytes in address .
uint8_t writeData(uint8_t address, uint8_t *blockData)  //!Writing
{
	Serial1.print("                ");
	dataTX[0] = 0x15;
	lengthCheckSum(dataTX); // Length Checksum
	dataTX[2] = 0xD4;
	dataTX[3] = 0x40;//inDataEchange CODE
	dataTX[4] = 0x01;//Number of targets
	dataTX[5] = 0xA0;//Write Command
	dataTX[6] = address; //Address		

	for (int i = 0; i < 16; i++) {
		dataTX[i+7] = blockData[i];
	}

	dataTX[23] = 0x00;
	checkSum(dataTX);
	sendTX(dataTX , 24 ,14);		

	if ((dataRX[9]== 0xD5) & (dataRX[10] == 0x41) & (dataRX[11] == 0x00)) {
		return 0;
	} else {
		return 1;
	}
}
//**********************************************************************
//!Read 16 bytes from  address .
uint8_t readData(uint8_t address, uint8_t *readData) //!Reading
{
	Serial1.print("                ");

	dataTX[0] = 0x05;
	lengthCheckSum(dataTX); // Length Checksum
	dataTX[2] = 0xD4; // Code
	dataTX[3] = 0x40; // Code
	dataTX[4] = 0x01; // Number of targets
	dataTX[5] = 0x30; //ReadCode
	dataTX[6] = address;  //Read address
	dataTX[7] = 0x00;
	checkSum(dataTX);
	sendTX(dataTX , 8, 30);
	memset(readData, 0x00, 16);  

	if ((dataRX[9]== 0xD5) & (dataRX[10] == 0x41) & (dataRX[11] == 0x00)) {
		for (int i = 12; i < 28; i++) {
			readData[i-12] = dataRX[i];
		}
		return 0;
	} else {
		return 1;
	}
}
//**********************************************************************
//!The PN532 sends back the version of the embedded firmware.
bool getFirmware(void)  //! It is needed to launch a simple command to sycnchronize
{
  Serial1.print("                ");

	memset(dataTX, 0x00, 35);
	dataTX[0] = 0x02; // Length
	lengthCheckSum(dataTX); // Length Checksum
	dataTX[2] = 0xD4; // CODE
	dataTX[3] = 0x02; //TFI
	checkSum(dataTX); //0x2A; //Checksum   

	sendTX(dataTX , 5 , 17);
	Serial1.print("\n");
	Serial.print("Your Firmware version is : ");

	for (int i = 11; i < (15) ; i++){
		Serial1.print(dataRX[i], HEX);
		Serial1.print(" ");
	}
	Serial1.print("\n");
}

//**********************************************************************
//!Print data stored in vectors .
void print(uint8_t * _data, uint8_t length)
{
	for (int i = 0; i < length ; i++){
		Serial.print(_data[i], HEX);
		Serial.print(" ");
	}
	Serial.print("\n");
}
//**********************************************************************
//!This command is used to set internal parameters of the PN532,
bool configureSAM(void)//! Configure the SAM
{
	Serial1.print("               ");

	dataTX[0] = 0x05; //Length
	lengthCheckSum(dataTX); // Length Checksum
	dataTX[2] = 0xD4;
	dataTX[3] = 0x14;
	dataTX[4] = 0x01; // Normal mode
	dataTX[5] = 0x14; // TimeOUT
	dataTX[6] = 0x00; // IRQ
	dataTX[7] = 0x00; // Clean checkSum position
	checkSum(dataTX);

	sendTX(dataTX , 8, 13);
}
//**********************************************************************
//!Send data stored in dataTX
void sendTX(uint8_t *dataTX, uint8_t length, uint8_t outLength)
{
	Serial1.print(char(0x00));
	Serial1.print(char(0x00));
	Serial1.print(char(0xFF)); 

	for (int i = 0; i < length; i++) {
		Serial1.print(char(dataTX[i]));
	}

	Serial1.print(char(0x00));
	getACK();
	waitResponse();// Receive response
	getData(outLength);
}
//**********************************************************************
//!Wait for ACK response and stores it in the dataRX buffer
void getACK(void)
{
	delay(5);
	waitResponse();
	for (int i = 0; i < 5 ; i++) {
		dataRX[i] = Serial1.read();
	}
}
//**********************************************************************
//!Wait the response of the module
void waitResponse(void)
{
	int val = 0xFF;
	int cont = 0x00;
	while(val != 0x00) { //Wait for 0x00 response
		val = Serial1.read();
		delay(5);
		cont ++;
	}
}
//**********************************************************************
//!Get data from the module
void getData(uint8_t outLength)
{
	for (int i=5; i < outLength; i++) {
		dataRX[i] = Serial1.read();//read data from the module.
	}
}
//**********************************************************************
//!Calculates the checksum and stores it in dataTX buffer
void checkSum(uint8_t *dataTX)
{
	for (int i = 0; i < dataTX[0] ; i++) {
		dataTX[dataTX[0] + 2] += dataTX[i + 2];
	}
	byte(dataTX[dataTX[0] + 2]= - dataTX[dataTX[0] + 2]);
}
//**********************************************************************
//!Calculates the length checksum and sotres it in the buffer.
uint8_t lengthCheckSum(uint8_t *dataTX)
{
	dataTX[1] = byte(0x100 - dataTX[0]);
}
                
Refer to RFID/NFC tutorial for more information.

4.4 Bluetooth

BT module

Bluetooth Module is able to be plugged into the XBee Shield and get a serial communication between the computer and an Intel Galileo through Bluetooth protocol.

Technical characteristics:

    Bluetooth Chip: eUnistone 31308/2
    Version: Bluetooth 2.0 + EDR (Configurable BT 1.2)
    TX Power: 2.5dBm
    RX Sensitivity: -86dBm
    Antenna: 2dBi
    Outdoor Range: 60 m LOS (Line of sight)
    Indoor Range: 40 m NLOS (Non line of sight)

    (Range measured between the Bluetooth module for Arduino and the BT Linksys dongle)

Special Options:

  • Minimum and Maximum RSSI thresholds control
  • Adaptive Frequency Hopping
  • Security: Authentication, Pairing and Encryption
  • Store 5 different trusted devices in its internal memory
  • Master or Slave operation supported

In this basic example we'll use an Intel Galileo with bluetooth module (Connected using a XBee shield) and a PC with a bluetooth USB dongle (Linksys Bluetooth Adapter).

The Intel Galileo will send a message (Hola caracola...) every 2 seconds and we receive it in the PC.

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Marcos Yarza
 */


int led = 13;
int val = -1;

void setup(){
	delay(2000);
	Serial1.begin(115200);
	delay(2000);
	Serial1.print("AT+JSEC=1,1,1,04,1111\r\n"); // Enable security command
	delay(2000);
	Serial1.print("AT+JDIS=3\r\n"); // Discorable command
	delay(2000);
	Serial1.print("AT+JRLS=1101,11,Serial Port,01,000000\r\n"); // Register local sevice command
	delay(2000);
	Serial1.print("AT+JAAC=1\r\n");// Auto accept connection requests command
	delay(2000);
	pinMode(led, OUTPUT);
	digitalWrite(led,HIGH);
	Serial1.flush();
	val = Serial1.read();
	while (val != 'R'){
	  val = Serial1.read();
	}
	delay(1000);
	Serial1.print("AT+JSCR\r\n"); // Stream Connection Request command
}

void loop(){
	Serial1.println("Hola caracola...");
	delay(2000);
}
                
Refer to BT tutorial for more information.

BT PRO module

The Bluetooth PRO module has been mainly designed to discover high amount of bluetooth devices along with its RSSI and Class of Device (CoD). It can be connected in a Xbee shield to work.

This section describes some features of Bluetooth module PRO for Arduino / Raspberry Pi which has been mainly designed to discover high amount of bluetooth devices in a variable area.

Bluetooth module PRO supports Serial Port Profile (SPP) to exchange data with other devices. This profile allows to create connections to another device using the same profile (p2p connection). It sends data to the specified device. This device is the one which the connection has been created to.

Refer to BT PRO tutorial for more information.

4.5 Geiger Counter - Radiation Sensor Board

The Geiger Counter - Radiation Sensor Board has two main parts, the power circuit and the signal circuit.

The power part is used to provide the voltage necessary for the tube (400V - 1000V) and the signal circuit is used to adapt the pulses output from the tube and connect it to the input of the microcontroller.

Once the tube is powered, we can receive the pulses in the microcontroller and count them, then with an easy calculation we can get the value of radiation.

The code we use for the board is counting pulses for 10 seconds, then we multiply the number of pulses by 6, so we get the number of pulses by minute (cpm), then, according to the tubes documentation we divide cpm by the conversion factor of the tube (360 by default) and we have the value of radiation in µSV/h.

Depending on the tube you use, maybe you need to change the calculation, you should try with different values and comment us witch value is working better.

The electronic used in the radiation board could be divided in five parts:

  1. High voltage power supply

    For the high voltage power supply we use a circuit based on an oscillator connected to a voltage multiplier made with diodes, transistors, resistors and capacitors (see schematic for detail). With this circuit we get a power of 500V in the tube. We've added a line of zener diodes connected in series that can be used if we need more than 500V for powering the tube. We'll add as volts to the output as volts in zener diodes we add.

  2. Adaptation circuit for the Geiger output

    The adaptation circuit for the output is based on a NPN transistor, this transistor will trigger the interrupt pin in the microcontroller, this transistor is also activating/deactivating the piezo speaker and LED indicator generating the audio/visual signal.

  3. Piezo speaker and LED indicator

    The piezo speaker and LED indicator are connected to the adaptation circuit, so the LED will blink with each pulse and the speaker will sound with each pulse.

  4. LCD screen

    The LCD screen is connected to the microcontroller using the 4-bit mode (4 data lines in addition to RS, Enable and RW control lines).

  5. LED bar

    The LED bar is made with five standard LEDs, 3 green and 2 red. These leds are connected to digital pins of the microcontroller with a series resistor.

This example shows how to get the signal from the Geiger Tube in Intel Galileo. We count the time (ms) between two pulses of the Geiger tube.

Code:
/*  
 *  Using Intel Galileo with the Arduino and Raspberry Pi Shields designed by Cooking Hacks
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis MartĂ­n & Marcos Yarza
 */



// Threshold values for the led bar
#define TH1 45
#define TH2 95
#define TH3 200
#define TH4 400
#define TH5 600

// Conversion factor - CPM to uSV/h
#define CONV_FACTOR 0.00812

// Variables
int ledArray [] = {10,11,12,13,9};
int geiger_input = 2;
long count = 0;
long countPerMinute = 0;
long timePrevious = 0;
long timePreviousMeassure = 0;
long countPrevious = 0;
float radiationValue = 0.0;

void setup(){
  pinMode(geiger_input, INPUT);
  //digitalWrite(geiger_input,HIGH);
  for (int i=0;i<5;i++){
    pinMode(ledArray[i],OUTPUT);
  }

  Serial.begin(19200);
}

void loop(){
  count = 0;
  timePreviousMeassure = millis();
  while (millis()-timePreviousMeassure < 10000)
  {
    if(digitalRead(geiger_input) == 0)
    {
      count++;
      while(digitalRead(geiger_input) == 0); // do nothing until pin goes back to HIGH
    }
  }
  radiationValue = 6.0*count * CONV_FACTOR;
  countPerMinute = 6*count;
  Serial.print("CPM = ");
  Serial.print(count*6);
  Serial.print(" | uSV/h = ");
  Serial.println(radiationValue);   

    //led var setting  
    if(countPerMinute <= TH1) ledVar(0);
    if((countPerMinute <= TH2)&&(countPerMinute>TH1)) ledVar(1);
    if((countPerMinute <= TH3)&&(countPerMinute>TH2)) ledVar(2);
    if((countPerMinute <= TH4)&&(countPerMinute>TH3)) ledVar(3);
    if((countPerMinute <= TH5)&&(countPerMinute>TH4)) ledVar(4);
    if(countPerMinute>TH5) ledVar(5);

}



void ledVar(int value){
  if (value > 0){
    for(int i=0;i<=value;i++){
      digitalWrite(ledArray[i],HIGH);
    }
    for(int i=5;i>value;i--){
      digitalWrite(ledArray[i],LOW);
    }
  }
  else {
    for(int i=5;i>=0;i--){
      digitalWrite(ledArray[i],LOW);
    }
  }
}
                
Refer to Geiger Counter tutorial for more information.