domingo, 30 de junio de 2013

Hydrogen Arduino WiFi Shield

El Hydrogen es una tarjeta del fabricante DIY Sandbox. Llamada también "Hydrogen Arduino WiFi Shield". Respecto al uso de esta tarjeta, no experimenté todas sus funcionalidades pero aquí ustedes tienen el link de su, digamos, DATASHEET hydrogen_quickstart_guide_rev03. Ese documento, indica paso a paso como instalar su librería y como usar la tarjeta.
El ejemplo que hice consisten en prender y apagar un led conectado en el pin 13 del Arduino desde una aplicación Web creada en el mismo código. 
Lo que hice fué agregarle unas lineas de código a un ejemplo dado por el propio fabricante (el ejemplo es cambiar el color del led de la tarjeta HYDROGEN desde la aplicación Web).

###########################################################################
CÓDIGO
###########################################################################
/*
LedDemoAp.pde - Hydrogen board LED demo sketch

Copyright (C) 2011 DIYSandbox LLC

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 2
of the License, or (at your option) any later version.

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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include <Wirefree.h>
#include <WifiServer.h>

WIFI_PROFILE wireless_prof = {
                        /* SSID */ "diysandbox",
         /* WPA/WPA2 passphrase */ "12345678",
                  /* IP address */ "192.168.1.1",
                 /* subnet mask */ "255.255.255.0",
                  /* Gateway IP */ "192.168.1.1", };
                             
// port 80 is default for HTTP
WifiServer server(80, PROTO_TCP);
int led = 13;

void setup()
{
   pinMode(led, OUTPUT);
  // connect as AP & start server
  Wireless.begin(&wireless_prof, AP_MODE);
  server.begin();
 
  delay(1000);
}

void loop()
{
  // Listen for incoming clients
  WifiClient client = server.available();
  int count = 0;
 
  if (client) {
    // an HTTP request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c;
        int  b;
       
        while((b = client.read()) == -1);
        c = b;
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          count = 0;
         
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");    
          client.println("");    
          //client.println("");    
                    
          // Output HTML page
          client.println("<html><head><title>LED PIN</title></head><body>");
          client.println("<center><h1>DIY Sandbox LED Color Change Demo and LED PIN</h1>");

          client.println("<p><form method=\"get\" action=\"\"><select name=\"l\">");
          client.println("<option value=\"r\">Red</option>");
          client.println("<option value=\"g\">Green</option>");
          client.println("<option value=\"b\">Blue</option>");
          client.println("<option value=\"c\">Cyan</option>");
         
          client.println("<option value=\"m\">Magenta</option>");      
          client.println("<option value=\"y\">Yellow</option>");
          client.println("<option value=\"w\">White</option>");
          client.println("<option value=\"p\">pinON</option>");
          client.println("<option value=\"f\">pinOFF</option>");
          client.println("</select><input type=\"submit\" value=\"Change\" /></form></p>");

          client.println("</center></body></html>"); 
          client.println(""); 

          client.flush();

          break;        
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
          count = 0;
        }
        else if (c != '\r'){
          // you've gotten a character on the current line
          currentLineIsBlank = false;
          count++;
          if ((c == '=') && (count == 8)){
             while((b = client.read()) == -1);
             c = b;
             if ( c == 'r')
             Wireless.setLED(LED_RED);
             else if ( c == 'g')
             Wireless.setLED(LED_GREEN);
             else if ( c == 'b')
             Wireless.setLED(LED_BLUE);
             else if ( c == 'c')
             Wireless.setLED(LED_CYAN);
             else if ( c == 'm')
             Wireless.setLED(LED_MAGENTA);
             else if ( c == 'y')
             Wireless.setLED(LED_YELLOW);
             else if ( c == 'w')
             Wireless.setLED(LED_WHITE);
             else if ( c == 'p'){
             digitalWrite(led, HIGH);
             }
              else if ( c == 'f'){
             digitalWrite(led, LOW);
             }
          }         
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection        
    client.stop();            
  }
}


Graba el programa de arriba y conéctate al WIFI de la tarjeta:

Despues de conectarte, digita en tu navegador:




La pagina web diseñada es:
Las dos ultimas opciones: pinON y pinOFF sirven para prender y apagar un led conectado al pin 13 del Arduino.

En la figura de abajo, el led de la derecha fue prendido con pinON:

En la siguiente figura el led fue apagado con el pinOFF:

La luz de la izquierda, es del led multicolor de la tarjeta. Cambia utilizando las opciones: RED, GREEN, BLUE, CYAN, MAGENTA, YELLOW, WHITE.





























































































































































































































































































martes, 29 de enero de 2013

Instalación del TinyOS 2.1.1 en Ubuntu 12.04



Holas,
Ahora estoy haciendo algo con wireless sensor network (WSN) específicamente los Mica2 y Micaz. Para trabajar con ellos tuve que instalar el TinyOS. Voy a colocar paso a paso la instalación :]

TinyOS es un sistema operativo proyectado para dispositivos inalambricos de bajo consumo de energia, como los usados ​​en redes de sensores, computacion ubicuas, redes de área pessoal, edifícios inteligentes y medidores inteligentes.


Paso 1: en Ubuntu
primero vamos a quitar algun repositorio antiguo y agregar los nuevos para esta version:


$ Sudo gedit / etc / apt / sources.list
se abre un archivo y alli copiamos lo siguiente:

deb http://tinyos.stanford.edu/tinyos/dists/ubuntu lucid main
deb http://tinyos.stanford.edu/tinyos/dists/ubuntu natty main
deb http://tinyos.stanford.edu/tinyos/dists/ubuntu maverick main

despues de copiar se debe ser ver una imagen asi: 
luego guarda los cambios.

Paso 2: actualizacion

Ahora vamos a actualizar las modificaciones hechar

$ Sudo apt-get update
Paso 3: instalando tinyOS

ahora si, vamos a instalar el TinyOS 2.1.1

$ Sudo apt-get install TinyOS-2.1.1

Paso 4: el tinyos.sh

vamos a colocar el CLASSPATH correcto dentro del archivo que se abre con el codigo:

sudo gedit / opt/tinyos-2.1.1/tinyos.sh
dentro, el texto debe estar igual a lo siguiente

#! /usr/bin/env bash
# Here we setup the environment
# variables needed by the tinyos
# make system

echo "Setting up for TinyOS 2.1.1 Repository Version"
export TOSROOT=
export TOSDIR=
export MAKERULES=

TOSROOT="/opt/tinyos-2.1.1"
TOSDIR="$TOSROOT/tos"
CLASSPATH=$CLASSPATH:$TOSROOT/support/sdk/java/tinyos.jar:.
MAKERULES="$TOSROOT/support/make/Makerules"

export TOSROOT
export TOSDIR
export CLASSPATH
export MAKERULES
como en la siguiente figura:
compara con tu archivo .sh e modifica, luego guarda y cierra la ventana de texto.
Paso 5: mas modificaciones
ejecuta el siguiente comando:
$ Gedit ~ /. Bashrc
dentro del archivo agrega lo siguiente:

#Sourcing the tinyos environment variable setup script
source /opt/tinyos-2.1.1/tinyos.sh
guarda el archivo.
Paso 6: verificamos instalacion
para ver que no hay error en nuestra instalación:

$ Tos-check-env
debe ver como la imagen:

Proximos post sera: primeros pasos con el mica2 :]