sábado, 8 de noviembre de 2014

Contact-less Infrared Thermopile Sensor Breakout - TMP006

Contact-less Infrared Thermopile Sensor Breakout - TMP006

            The TMP006 have the capacity to measure the temperature of an object without touching it. Simply point the sensor towards what you want to measure and it will detect the temperature by absorbing IR waves emitted. The embedded thermopile sensor generates a very very small voltage depending on how much IR there is, and using some math, that micro voltage can be used to calculate the temperatureThis sensor comes as an ultra-small 0.5mm pitch BGA. The sensor works  with 5V.

                                              



As a design guideline, the TMP006 should only be used to calculate the surface temperature of target objects with emissivity values greater than 0.7, and preferably greater than 0.9. The emissivity values of common objects are listed in next table.

     Materials:

       1. Arduino
       2. Protoboard
       3. TMP006 sensor(from adafruit)
       4. Four connecting wires



   Wiring:

       1. Place the TMP006 sensor in the protoboard.
       2. Connect the sensor VCC to 5V.
       3. Connect the sensor GND to GND.
       4. Connect the sensor SDA to "A5" analogpin.
       5. Connect the sensor SCL to "A4" analogpin.
       6. Download the file. Libraries

 Code:

   /***************************************************

  This is an example for the TMP006 Barometric Pressure & Temp Sensor

  Designed specifically to work with the Adafruit TMP006 Breakout
  ----> https://www.adafruit.com/products/1296

  These displays use I2C to communicate, 2 pins are required to 
  interface
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries. 
  BSD license, all text above must be included in any redistribution
 ****************************************************/

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

// Connect VCC to +3V (its a quieter supply than the 5V supply on an Arduino
// Gnd -> Gnd
// SCL connects to the I2C clock pin. On newer boards this is labeled with SCL
// otherwise, on the Uno, this is A5 on the Mega it is 21 and on the Leonardo/Micro digital 3
// SDA connects to the I2C data pin. On newer boards this is labeled with SDA
// otherwise, on the Uno, this is A4 on the Mega it is 20 and on the Leonardo/Micro digital 2

Adafruit_TMP006 tmp006;
//Adafruit_TMP006 tmp006(0x41);  // start with a diferent i2c address!

void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit TMP006 example");

  // you can also use tmp006.begin(TMP006_CFG_1SAMPLE) or 2SAMPLE/4SAMPLE/8SAMPLE to have
  // lower precision, higher rate sampling. default is TMP006_CFG_16SAMPLE which takes
  // 4 seconds per reading (16 samples)
  if (! tmp006.begin()) {
    Serial.println("No sensor found");
    while (1);
  }

  Serial.println("Send s to enter sleep mode, or w to wake up.  Measurements are not updated while asleep!");
}

void loop() {
  // Check for sleep/wake command.
  while (Serial.available() > 0) {
    char c = Serial.read();
    if (c == 'w') {
      Serial.println("Waking up!");
      tmp006.wake();
    }
    else if (c == 's') {
      Serial.println("Going to sleep!");
      tmp006.sleep();
    }
  }

  // Grab temperature measurements and print them.
  float objt = tmp006.readObjTempC();
  Serial.print("Object Temperature: "); Serial.print(objt); Serial.println("*C");
  float diet = tmp006.readDieTempC();
  Serial.print("Die Temperature: "); Serial.print(diet); Serial.println("*C");
  
  delay(4000); // 4 seconds per reading for 16 samples per reading
}

Serial print and example from library:



       

More information:


More information about the sensor can be found on the TMP006datashit




Sensor de temperatura infrarrojo sin contacto TMP006

    El TMP006 tiene la capacidad para medir la temperatura de un objeto sin tener contacto con él. Simplemente dirija el sensor hacia la dirección del objeto que se desee medir y este lo detectará por medio de absorción de las ondas IR emitidas. El sensor de termopila incrustado genera una pequeña diferencia de voltaje, dependiendo de cuánto IR existe, y el uso de algunos cálculos, que los micro voltajes se pueden utilizar para calcular la temperatura. Este sensor viene como ultra-pequeño de 5mm pitch BGA,el mismo se trabaja en un tablero (protoboard). El sensor trabaja con 5V.



                 


Como directriz de diseño, el TMP006 sólo debe utilizarse para calcular la temperatura de la superficie de objetos de destino con valores de emisividad mayor que 0.7, y preferiblemente mayor que 0.9. Los valores de emisividad de los objetos comunes se enumeran en la siguiente tabla.




  Materiales:

         1. Arduino
         2. Tablero (protoboard)
         3. Sensor TMP006 (de adafruit)
         4.  Cuatro cables de conexión 


   Cableado:

        1. Coloque el sensor TMP006 en el tablero.
        2. Conecte  el VCC del sensor  a 5V.
        3. Conecte el GND del sensor a GND.
        4. Conecte el SDA del sensor  al puerto análogo "A5".
        5. Conecte el SCL del sensor al puerto análogo "A4''.
        6. Descargue el documento. - Librerías
              TMP006 - https://github.com/adafruit/Adafruit_TMP006


    Código:

  /***************************************************

  This is an example for the TMP006 Barometric Pressure & Temp Sensor

  Designed specifically to work with the Adafruit TMP006 Breakout
  ----> https://www.adafruit.com/products/1296

  These displays use I2C to communicate, 2 pins are required to 
  interface
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries. 
  BSD license, all text above must be included in any redistribution
 ****************************************************/

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

// Connect VCC to +3V (its a quieter supply than the 5V supply on an Arduino
// Gnd -> Gnd
// SCL connects to the I2C clock pin. On newer boards this is labeled with SCL
// otherwise, on the Uno, this is A5 on the Mega it is 21 and on the Leonardo/Micro digital 3
// SDA connects to the I2C data pin. On newer boards this is labeled with SDA
// otherwise, on the Uno, this is A4 on the Mega it is 20 and on the Leonardo/Micro digital 2

Adafruit_TMP006 tmp006;
//Adafruit_TMP006 tmp006(0x41);  // start with a diferent i2c address!

void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit TMP006 example");

  // you can also use tmp006.begin(TMP006_CFG_1SAMPLE) or 2SAMPLE/4SAMPLE/8SAMPLE to have
  // lower precision, higher rate sampling. default is TMP006_CFG_16SAMPLE which takes
  // 4 seconds per reading (16 samples)
  if (! tmp006.begin()) {
    Serial.println("No sensor found");
    while (1);
  }

  Serial.println("Send s to enter sleep mode, or w to wake up.  Measurements are not updated while asleep!");
}

void loop() {
  // Check for sleep/wake command.
  while (Serial.available() > 0) {
    char c = Serial.read();
    if (c == 'w') {
      Serial.println("Waking up!");
      tmp006.wake();
    }
    else if (c == 's') {
      Serial.println("Going to sleep!");
      tmp006.sleep();
    }
  }

  // Grab temperature measurements and print them.
  float objt = tmp006.readObjTempC();
  Serial.print("Object Temperature: "); Serial.print(objt); Serial.println("*C");
  float diet = tmp006.readDieTempC();
  Serial.print("Die Temperature: "); Serial.print(diet); Serial.println("*C");
  
  delay(4000); // 4 seconds per reading for 16 samples per reading
}

Impresión de serie y ejemplo de la libreria:

    

Más información:

Para más información acerca del sensor la puede encontrar TMP006datashit


Arduino-Analog K-Type Thermocouple Amplifier-AD8495 Breakout


      Arduino - Analog K-Type Thermocouple Amplifier-AD8495

The k-Type thermocouple sensor is analog-output amplifier that is very simple to use with arduino. The power of board with 3-18VDC and measure the output voltage on the out pin. To convert the voltage to temperature use the following equation:
Temperature = (Voltage obtained – 1.25)/ 0.005 V.

For example, if the voltage is 1.50VDC, the temperature is (1.50-1.25)/0,005=50°C. If you connect 5V power the temperature range is -250°C to 750°C output (0 TO 5VDC)  but is connect  to 3.3V power the temperature range is -250°C to 410°C (0 to 3.3VDC).



  Materials:

  1. AD8495 sensor(from adafruit)     
  2. Protoboard
  3. Arduino
  4. Three connecting wires 
  5. K-Type Thermocouple

 Wiring:

  1. Connect de K-Type thermocouple to AD8395 sensor.
  2. Place the sensor  in the  the protoboard.
  3. Connect  the GND of the sensor with the GND of the arduino.
  4. Connect the V+ of sensor  to 5v or 3.3v  according the range of  temperature  that you want to read.
  5. Connect the Out  to the A4 analogpin.

  Code:

//Analog read pin

const int Out = A4;

void setup(){
  Serial.begin(9600);
}

void loop(){

int A4 = analogRead(4);
// equation to calculated temperature
   double Vin=(5*A4);
   float vinl=Vin/1024;
  double Vout=vinl-1.25;
  double T = Vout/0.005;

  Serial.print("Vin= ");
  Serial.print(Vin);
  Serial.print(" | vinl= ");
  Serial.print(vinl);
  Serial.print(" | Vout= ");
  Serial.print(Vout);
  //print temperature in Celsius
  Serial.print(" | T= ");
  Serial.print(T);
  //print voltage read
  Serial.print(" | A4= ");
  Serial.println(A4);

  delay (1000);
  }

Serial monitoring display:


      
     

Termoeléctrico amplificador AD8495 tipo K


El sensor amplificador termoelélectrico tipo K con salida análoga es muy facil para utilizarse con arduino. Alimentar la tarjeta con 3-18VDC y medir el voltaje de salida. Para  convertir el voltaje a temperatura use la siguiente ecuación: Temperatura = (Voltaje obtenido -1.25)/.0005V.


Por ejemplo si el voltaje es is 1.50 VDC, la temperatura es ( 1.50-1.25)/.0005= 50 grados Celsius.
Si alimentas con 5V  el rango de temperatura esta entre -250 a 750 grados celsius de salida (0 a VDC) pero si es conectado a 3.3V el rango en la temperatura esta entre -250 a 410 grados celsius (0 a 3.3VDC).


Materiales:

     1. Sensor AD8495 (de adafruit)
     2. Tablero (protoboard)
     3. Arduino
     4. Tres cables de conexión
     5. Termoeléctrico tipo K

Cableado:

   1.  Conecte el termoeléctrico tipo K al sensor.
   2.  Coloque el sensor en el tablero.
   3.  Conecte el GND del sensor con el GND del arduino.
   4.  Conecte el V+ del sensor a 5V ó 3.3V dependiendo del rango de temperatura que quieres leer.
   5.  Conecte la salida al puerto  A4.


 Código:

  //Analog read pin

const int Out = A4;

void setup(){
  Serial.begin(9600);
}

void loop(){

int A4 = analogRead(4);
// equation to calculated temperature
   double Vin=(5*A4);
   float vinl=Vin/1024;
  double Vout=vinl-1.25;
  double T = Vout/0.005;

  Serial.print("Vin= ");
  Serial.print(Vin);
  Serial.print(" | vinl= ");
  Serial.print(vinl);
  Serial.print(" | Vout= ");
  Serial.print(Vout);
  //print temperature in Celsius
  Serial.print(" | T= ");
  Serial.print(T);
  //print voltage read
  Serial.print(" | A4= ");
  Serial.println(A4);

  delay (1000);
  }

Pantalla de monitoreo:







   

Arduino - Accelerometer ADXL335


Arduino - Accelerometer ADXL335


 The accelerometer is an analog device used to measure the proper acceleration in the three different axis(x-y-z).



  Materials:

       1. Arduino Uno (from sparkfun)
       2. adxl335 sensor (from sparkfun)

   Wiring:

   1. Connect the VCC to A5.
   2. Connect the GND to A4.
   3. Connect "X" to A3 analogpin.
   4. Connect "Y" to A2 analogpin.
   5. Connect "Z" to A1 analogpin.

        

 Code:

 //Analog read pins

const int groundpin = 18;
const int powerpin = 19;
const int xPin = A3;
const int yPin = A2;
const int zPin = A1;

void setup(){
  Serial.begin(9600);

//analog to gnd & 5v
pinMode(groundpin,OUTPUT);
pinMode(powerpin,OUTPUT);
digitalWrite(groundpin,LOW);
digitalWrite(powerpin,HIGH);
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
pinMode(zPin, INPUT);
}

 void loop(){


   int x = analogRead(xPin);
 //
 //add a small delay between pin readings.  I read that you should
 //do this but haven't tested the importance
   delay(1);
 //
 int y = analogRead(yPin);
 //
 //add a small delay between pin readings.  I read that you should
 //do this but haven't tested the importance
   delay(1);
 //
 int z = analogRead(zPin);
 //
 //zero_G is the reading we expect from the sensor when it detects
 //no acceleration.  Subtract this value from the sensor reading to
 //get a shifted sensor reading.
 float zero_G = 512.0;
 //
 //scale is the number of units we expect the sensor reading to
 //change when the acceleration along an axis changes by 1G.
 //Divide the shifted sensor reading by scale to get acceleration in Gs.
 float scale = 102.3;
 //
 Serial.print("x: ");
 Serial.print(((float)x - zero_G)/scale);
 Serial.print("\t");
 //
 Serial.print(" | y: ");
 Serial.print(((float)y - zero_G)/scale);
 Serial.print("\t");
 //
 Serial.print(" | z: ");
 Serial.print(((float)z - zero_G)/scale);
 Serial.print("\n");

  delay(100);//just here to slow down the serial output - Easier to read
}


Serial print display


                                                                 Acelerometro ADXL335

El acelerometro es un dispositivo análogo utilizado para medir la acceleración propia en los tres differentes ejes(x-y-z).

   




Materiales:


   1. Arduino Uno (de sparkfun)

   2. Sensor ADXL 335 ( de sparkfun)


 Cableado:


   1. Conecte el VCC a 5V.
   2. Conecte el GND a A4.
   3. Conecte "X'' al puerto análogo A3.
   4. Conecte "Y" al puerto análogo  A2.
   5. Conecte ''Z" al puerto análogo A1.


     

                             


Código:

//Analog read pins

const int groundpin = 18;
const int powerpin = 19;
const int xPin = A3;
const int yPin = A2;
const int zPin = A1;

void setup(){
  Serial.begin(9600);

//analog to gnd & 5v
pinMode(groundpin,OUTPUT);
pinMode(powerpin,OUTPUT);
digitalWrite(groundpin,LOW);
digitalWrite(powerpin,HIGH);
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
pinMode(zPin, INPUT);
}

 void loop(){


   int x = analogRead(xPin);
 //
 //add a small delay between pin readings.  I read that you should
 //do this but haven't tested the importance
   delay(1);
 //
 int y = analogRead(yPin);
 //
 //add a small delay between pin readings.  I read that you should
 //do this but haven't tested the importance
   delay(1);
 //
 int z = analogRead(zPin);
 //
 //zero_G is the reading we expect from the sensor when it detects
 //no acceleration.  Subtract this value from the sensor reading to
 //get a shifted sensor reading.
 float zero_G = 512.0;
 //
 //scale is the number of units we expect the sensor reading to
 //change when the acceleration along an axis changes by 1G.
 //Divide the shifted sensor reading by scale to get acceleration in Gs.
 float scale = 102.3;
 //
 Serial.print("x: ");
 Serial.print(((float)x - zero_G)/scale);
 Serial.print("\t");
 //
 Serial.print(" | y: ");
 Serial.print(((float)y - zero_G)/scale);
 Serial.print("\t");
 //
 Serial.print(" | z: ");
 Serial.print(((float)z - zero_G)/scale);
 Serial.print("\n");

  delay(100);//just here to slow down the serial output - Easier to read
}

Pantalla de monitoreo:

   




Accelerometer with LCD and SD



Arduino - Accelerometer with LCD & SD

This project consist in the measurement of acceleration in 3 axis (x-y-z) with an ArduinoUno as a microcontroler. The accelerometer used was the adxl335. Results of the measurements are shown on a LCD screen (Adafruit 1.8" Color TFT Shield w/microSD and Joystick). The Data obtained is saved on a SD memory card, included on the LCD screen. The Data is save on the microSD by creating a data.txt file. The shield's Joystick allow the program to pause (moving the joystick down) and run again (moving the joystick up).




      Materials:

  1. Arduino Uno (from Arduino store)
  2. adxl335 sensor (from sparkfun)
  3. Adafruit 1.8" Color TFT Shield w/microSD and Joystick (from adafruit)

Assembly and wiring:

  1. Assembly of the 1.8" TFT Shield  (detailed assembly process can be obtain from adafruit)
  2. Connect 1.8" TFT Shield to Arduino 
  3. Connect adxl335 to the 1.8" TFT Shield  (A3 cannot be used because it is already be in used by the shield Joystick)
    1. Connect the VCC to A5.
    2. Connect the GND to A4.
    3. Connect "X" to A2
    4. Connect "Y" to A1
    5. Connect "Z" to A0

Libraries:

For this project to be able to run properly it must have two aditional libraries and posibly a library actualization. A guide for installing libraries can be obtain from Arduino (Installing Additional Arduino Libraries). The libraries are:
If the library is installed right it can be seen the codes in the examples, as shown in the picture.

 

The adafruit ST7735 examples allow to learn how to use the LCD display of the TFT shield.

Code


#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SD.h>
#include <SPI.h>

#if defined(__SAM3X8E__)
    #undef __FlashStringHelper::F(string_literal)
    #define F(string_literal) string_literal
#endif

// TFT display and SD card will share the hardware SPI interface.
// Hardware SPI pins are specific to the Arduino board type and
// cannot be remapped to alternate pins.  For Arduino Uno,
// Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK.
#define SD_CS    4  // Chip select line for SD card
#define TFT_CS  10  // Chip select line for TFT display
#define TFT_DC   8  // Data/command line for TFT
#define TFT_RST  -1  // Reset line for TFT (or connect to +5V)

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
#define BUTTON_NONE 0
#define BUTTON_DOWN 1
#define BUTTON_RIGHT 2
#define BUTTON_SELECT 3
#define BUTTON_UP 4
#define BUTTON_LEFT 5

//Analog read pins
const int groundpin = 18;
const int powerpin = 19;
const int xPin = A2;
const int yPin = A1;
const int zPin = A0;
boolean run = false;

File dataFile;
const int chipSelect = 4;

void setup(){
  Serial.begin(9600);
//analog to gnd & 5v
pinMode(groundpin,OUTPUT);
pinMode(powerpin,OUTPUT);
digitalWrite(groundpin,LOW);
digitalWrite(powerpin,HIGH);
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
pinMode(zPin, INPUT);
  // Initialize 1.8" TFT
  tft.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab
  Serial.println("OK!");
  tft.fillScreen(ST7735_BLACK);

Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
   pinMode(SS, OUTPUT);
  
  if (!SD.begin(chipSelect)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  if (SD.exists("data.txt")){
    SD.remove("data.txt");
  }
  dataFile = SD.open("data.txt", FILE_WRITE);
  if (! dataFile) {
    Serial.println("error opening datalog.txt");
    // Wait forever since we cant write data
    while (1) ;
  }
}
 
uint8_t readButton(void) {
  float a = analogRead(3);
 
  a *= 5.0;
  a /= 1024.0;
 
  //Serial.print("Button read analog = ");
  //Serial.println(a);
  if (a < 0.2) return BUTTON_DOWN;
  if (a < 1.0) return BUTTON_RIGHT;
  if (a < 1.5) return BUTTON_SELECT;
  if (a < 2.0) return BUTTON_UP;
  if (a < 3.2) return BUTTON_LEFT;
  else return BUTTON_NONE;
}


void loop() {
  uint8_t b = readButton();
  if (b == BUTTON_UP) {
    //if (run == false){
      run = true;
      // create new file of data, if it already exist it will be deleted
      // and create new data file
      if (SD.exists("data.txt")){
        SD.remove("data.txt");
        dataFile = SD.open("data.txt", FILE_WRITE);
      }
      tft.setTextSize(2);
      tft.setTextColor(ST7735_BLACK);
      tft.setCursor(0, 120);
      tft.print("Pause");
      tft.setTextColor(ST7735_MAGENTA);
      tft.setCursor(0, 120);
      tft.print("Running"); 
    }
   
  if (b == BUTTON_DOWN) {
      run = false;
      tft.setTextColor(ST7735_BLACK);
      tft.setCursor(0, 120);
      tft.print("Running"); 
      tft.setTextColor(ST7735_MAGENTA);
      tft.setCursor(0, 120);
      tft.print("Pause");      
    }
   
  if (run == true) {
  //read the analog values from the accelerometer
  int x = analogRead(xPin);
  int y = analogRead(yPin);
  int z = analogRead(zPin);
  float zero_G = 512.0;
  float scale = 102.3;
  double xnw = ((float)x - zero_G)/scale;
  double ynw = ((float)y - zero_G)/scale;
  double znw = ((float)z - zero_G)/scale;
 
  Serial.print(xnw);
  Serial.print("\t");
  Serial.print(ynw);
  Serial.print("\t");
  Serial.print(znw);
  Serial.print("\n");
 
  //print on sd
  dataFile.print(xnw);
  dataFile.print("\t");
  dataFile.print(ynw);
  dataFile.print("\t");
  dataFile.print(znw);
  dataFile.print("\n");
 
  // print on screen
  tft.setTextSize(2);
  tft.setTextColor(ST7735_BLUE);
    tft.setCursor(0, 10);
    tft.print("x = ");
    tft.setCursor(50, 10);
    tft.print(xnw);
  tft.setTextColor(ST7735_RED);
    tft.setCursor(0, 40);
    tft.print("y = ");
    tft.setCursor(50, 40);
    tft.print(ynw);
  tft.setTextColor(ST7735_GREEN);
    tft.setCursor(0, 70);
    tft.print("z = ");
    tft.setCursor(50, 70);
    tft.print(znw);
   
  dataFile.flush();

  delay(100);//just here to slow down the serial output - Easier to read
 
    tft.setTextColor(ST7735_BLACK);
    tft.setCursor(50, 10);
    tft.print(xnw);
    tft.setCursor(50, 40);
    tft.print(ynw);
    tft.setCursor(50, 70);
    tft.print(znw);
  }
}
   

SD file

Plus the results shown in the LCD, seen in the first picture, the date is save inside the SD card and be used in your computer.


 



Arduino - Accelerometro con LCD y SD


 Este projecto consiste  el la medición de la acceleración en los tres differentes ejes(x-y-z) utilizando un arduino como microcontrolador. El accelerometro utilizado es el ADXL335. Los resultados de las mediciones se muestran es una pantalla LCD (Adafruit  1.8" Color TFT Shield w/ micro SD and Joystick). La data obtenida es salvada en la tarjeta de memoria(microSD) creando un documento data.text. La palanca de mando del TFT Shield permite que el programa haga pausas (moviendo la palanca de mando hacia abajo) y corriendo de nuevo (moviendo la palanca de mando hacia arriba).



Materiales:

     1. Arduino Uno (de arduino store)
     2. Adxl 335 (de sparkfun)
     3. Adafruit  1.8" Color TFT Shield w/ micro SD and Joystick( de adafruit)

Ensamblaje y Cableado:

 1. Ensamble 1.8" TFT Shield (el proceso detallado puede ser encotrado en adafruit).
 2. Conecte el 1.8'' TFT Shield al arduino.
 3. Conecte el adxl 335 al 1.8'' TFT Shield (A3 no puede ser usado porque ya esta en uso con la palanca de mando)

    1. Conecte el VCC a 5V.
    2. Conecte el GND a A4.
    3. Conecte "X'' a A2.
    4. Conecte ''Y"a A1.
    5. Conecte "Z'' a A0.


   Líbrerias:

Para que este proyecto sea capaz de ejecutarse correctamente debe tener dos bibliotecas adicionales y posiblemente una actualización de biblioteca. Una guía para la instalación de las bibliotecas se puede obtener de Arduino (Instalación Adicional de Librerías de Arduino) Las librerías son:



 Si se instalan la librerías los ejemplos pueden ser observados como se muestran en la siguiente figura.
   
   

Los ejemplos ST7735 adafruit permiten aprender cómo utilizar la pantalla LCD de la pantalla TFT.

 Código:

#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SD.h>
#include <SPI.h>

#if defined(__SAM3X8E__)
    #undef __FlashStringHelper::F(string_literal)
    #define F(string_literal) string_literal
#endif

// TFT display and SD card will share the hardware SPI interface.
// Hardware SPI pins are specific to the Arduino board type and
// cannot be remapped to alternate pins.  For Arduino Uno,
// Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK.
#define SD_CS    4  // Chip select line for SD card
#define TFT_CS  10  // Chip select line for TFT display
#define TFT_DC   8  // Data/command line for TFT
#define TFT_RST  -1  // Reset line for TFT (or connect to +5V)

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
#define BUTTON_NONE 0
#define BUTTON_DOWN 1
#define BUTTON_RIGHT 2
#define BUTTON_SELECT 3
#define BUTTON_UP 4
#define BUTTON_LEFT 5

//Analog read pins
const int groundpin = 18;
const int powerpin = 19;
const int xPin = A2;
const int yPin = A1;
const int zPin = A0;
boolean run = false;

File dataFile;
const int chipSelect = 4;

void setup(){
  Serial.begin(9600);
//analog to gnd & 5v
pinMode(groundpin,OUTPUT);
pinMode(powerpin,OUTPUT);
digitalWrite(groundpin,LOW);
digitalWrite(powerpin,HIGH);
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
pinMode(zPin, INPUT);
  // Initialize 1.8" TFT
  tft.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab
  Serial.println("OK!");
  tft.fillScreen(ST7735_BLACK);

Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
   pinMode(SS, OUTPUT);
  
  if (!SD.begin(chipSelect)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  if (SD.exists("data.txt")){
    SD.remove("data.txt");
  }
  dataFile = SD.open("data.txt", FILE_WRITE);
  if (! dataFile) {
    Serial.println("error opening datalog.txt");
    // Wait forever since we cant write data
    while (1) ;
  }
}

uint8_t readButton(void) {
  float a = analogRead(3);

  a *= 5.0;
  a /= 1024.0;

  //Serial.print("Button read analog = ");
  //Serial.println(a);
  if (a < 0.2) return BUTTON_DOWN;
  if (a < 1.0) return BUTTON_RIGHT;
  if (a < 1.5) return BUTTON_SELECT;
  if (a < 2.0) return BUTTON_UP;
  if (a < 3.2) return BUTTON_LEFT;
  else return BUTTON_NONE;
}


void loop() {
  uint8_t b = readButton();
  if (b == BUTTON_UP) {
    //if (run == false){
      run = true;
      // create new file of data, if it already exist it will be deleted
      // and create new data file
      if (SD.exists("data.txt")){
        SD.remove("data.txt");
        dataFile = SD.open("data.txt", FILE_WRITE);
      }
      tft.setTextSize(2);
      tft.setTextColor(ST7735_BLACK);
      tft.setCursor(0, 120);
      tft.print("Pause");
      tft.setTextColor(ST7735_MAGENTA);
      tft.setCursor(0, 120);
      tft.print("Running"); 
    }
   
  if (b == BUTTON_DOWN) {
      run = false;
      tft.setTextColor(ST7735_BLACK);
      tft.setCursor(0, 120);
      tft.print("Running"); 
      tft.setTextColor(ST7735_MAGENTA);
      tft.setCursor(0, 120);
      tft.print("Pause");      
    }
   
  if (run == true) {
  //read the analog values from the accelerometer
  int x = analogRead(xPin);
  int y = analogRead(yPin);
  int z = analogRead(zPin);
  float zero_G = 512.0;
  float scale = 102.3;
  double xnw = ((float)x - zero_G)/scale;
  double ynw = ((float)y - zero_G)/scale;
  double znw = ((float)z - zero_G)/scale;

  Serial.print(xnw);
  Serial.print("\t");
  Serial.print(ynw);
  Serial.print("\t");
  Serial.print(znw);
  Serial.print("\n");

  //print on sd
  dataFile.print(xnw);
  dataFile.print("\t");
  dataFile.print(ynw);
  dataFile.print("\t");
  dataFile.print(znw);
  dataFile.print("\n");

  // print on screen
  tft.setTextSize(2);
  tft.setTextColor(ST7735_BLUE);
    tft.setCursor(0, 10);
    tft.print("x = ");
    tft.setCursor(50, 10);
    tft.print(xnw);
  tft.setTextColor(ST7735_RED);
    tft.setCursor(0, 40);
    tft.print("y = ");
    tft.setCursor(50, 40);
    tft.print(ynw);
  tft.setTextColor(ST7735_GREEN);
    tft.setCursor(0, 70);
    tft.print("z = ");
    tft.setCursor(50, 70);
    tft.print(znw);
   
  dataFile.flush();

  delay(100);//just here to slow down the serial output - Easier to read

    tft.setTextColor(ST7735_BLACK);
    tft.setCursor(50, 10);
    tft.print(xnw);
    tft.setCursor(50, 40);
    tft.print(ynw);
    tft.setCursor(50, 70);
    tft.print(znw);
  }
}

Documento en SD

Además de los resultados mostrados en la LCD, vistos en la figura mostrada al inicio, la data se guarda en el SD y puede ser visto desde su computadora.