Arduino meets Processing via Wifi (DD-WRT)

Mai atasez un proiect preluat de pe www.geocities.jp . Eu am folosit o parte din acest proiect pentru a adauga intr-un mysql temperaturile preluate cuarduino cu ajutorul unor senzori digitali ds1820.

Pentru cei care vor sa faca rost de ds1820s la preturi aproape de O sa imi postele comentariu.

1. Demo Video

2.Concept Diagram

FON2100 internal serial pin-header

FON2200 internal serial pin-header

3.Schematics

4.Photo

5.Source Code

Server Side (Processing)

/*************************************/
/* Arduino meets Processing via Wifi */
/*   Processing Sever side sketch    */
/*************************************/

import processing.net.*;

int port = 5555; //Sever TCP-Port number
int x = 200;
int y = 200;
int z = 0;

Server server;
String strdata = "0";

void setup(){
  size(400,400,P3D);
  server = new Server(this, port);
  noStroke();
  colorMode(RGB, 1);
}

void draw(){
  Client client = server.available(); //
  /* Draw ColorCube */
  background(0);
  pushMatrix();
  translate(x,y,z);
  rotateX(PI/4);
  float r = float(strdata);
  rotateZ(PI*r/512.0-0.75);
  colorcube(80);
  popMatrix();
  /* Communication with client */
  if(client != null){      // if client is  connecting
      client.write("\n");
      if((strdata=client.readString()) != null){
          strdata=trim(strdata);
//        println(strdata);
      }
  }
  delay(10);
}

/* When a client is connected */
void serverEvent(Server s, Client c){
  println("Client connect - IP:"+c.ip()); // show IP
}

/* Draw ColorCube function */
void colorcube(int s){
   scale(s);
   beginShape(QUADS);

  fill(0, 1, 1); vertex(-1,  1,  1);
  fill(1, 1, 1); vertex( 1,  1,  1);
  fill(1, 0, 1); vertex( 1, -1,  1);
  fill(0, 0, 1); vertex(-1, -1,  1);

  fill(1, 1, 1); vertex( 1,  1,  1);
  fill(1, 1, 0); vertex( 1,  1, -1);
  fill(1, 0, 0); vertex( 1, -1, -1);
  fill(1, 0, 1); vertex( 1, -1,  1);

  fill(1, 1, 0); vertex( 1,  1, -1);
  fill(0, 1, 0); vertex(-1,  1, -1);
  fill(0, 0, 0); vertex(-1, -1, -1);
  fill(1, 0, 0); vertex( 1, -1, -1);

  fill(0, 1, 0); vertex(-1,  1, -1);
  fill(0, 1, 1); vertex(-1,  1,  1);
  fill(0, 0, 1); vertex(-1, -1,  1);
  fill(0, 0, 0); vertex(-1, -1, -1);

  fill(0, 1, 0); vertex(-1,  1, -1);
  fill(1, 1, 0); vertex( 1,  1, -1);
  fill(1, 1, 1); vertex( 1,  1,  1);
  fill(0, 1, 1); vertex(-1,  1,  1);

  fill(0, 0, 0); vertex(-1, -1, -1);
  fill(1, 0, 0); vertex( 1, -1, -1);
  fill(1, 0, 1); vertex( 1, -1,  1);
  fill(0, 0, 1); vertex(-1, -1,  1);

  endShape();
}
/* End of Sever side sketch */

/* Copyright by Kimio Kosaka 2008.08.20 */

Client Side (Arduino-0011)

/*************************************/
/* Arduino meets Processing via Wifi */
/*    Arduino Client side sketch     */
/*************************************/

/* Switch and LED settings */
#define start_sw 4
#define led 3

/* DD-WRT user-ID,password,serial-speed settings */
#define USER_ID "root"
#define PASSWD "admin"
#define SERIAL_SPEED 115200

/* Processing-Server IP and TCP-Port settings */
#define SERVER "192.168.10.129"
#define PORT "5555"

void setup()  {
  pinMode(led, OUTPUT);
  pinMode(start_sw,INPUT);
  Serial.begin(SERIAL_SPEED);
  /* waiting until start_sw was pushed */
  while(digitalRead(start_sw)==HIGH){
    digitalWrite(led,HIGH);
    delay(100);
    digitalWrite(led,LOW);
    delay(100);
  }
  while(digitalRead(start_sw)==LOW);
  /* login and connect */
  login();    //login DD-WRT
  connect();  //connect Processing-Server
  digitalWrite(led,HIGH);
}

void loop()
{
  int x = analogRead(0); // read voltage of potentiometer
  if(Serial.available()>0){
    Serial.read(); // read out data from Processing-Server
    Serial.println(x,DEC); //send data to Processing-Server
  }
  /* if start_sw is pushed */
  if(digitalRead(start_sw)==LOW){
      disconnect();  //disconnect from Processing-Server
      logoff();  // logoff from DD-WRT
      /* LED blink eternally */
      while(true){
         digitalWrite(led,LOW);
         delay(1000);
         digitalWrite(led,HIGH);
         delay(1000);
      }
  }
}

/* login to DD-WRT */
void login()
{
  Serial.print("\n");
  allflush(); // flushing serial read buffer
  Serial.println(USER_ID);
  delay(500);
  Serial.println(PASSWD);
  allflush();
}  

/* logoff from DD-WRT */
void logoff()
{
  Serial.print("\x03"); //CTRL+C
  delay(100);
  Serial.println("exit");
  allflush();
}

/* connect to Processing-Server */
void connect()
{
  Serial.print("\x03\n\n"); //CRTL+C,LF,LF
  allflush();
  /* telnet to Processing-Server */
  Serial.print("telnet ");
  Serial.print(SERVER);
  Serial.print(" ");
  Serial.println(PORT);
  allflush();
  /* telnet change "character mode".  cf: DD-WRT telnet command */
  Serial.print("\x03"); //CTRL+C
  Serial.print("c");
  allflush();
  Serial.print("\n");
  allflush();
  /* send first data to Processing-Server. first data is 0 */
  Serial.println("0");  //send 0
} 

/* disconnect form Processing-Server */
void disconnect()
{
  digitalWrite(led,HIGH);
  /* exit telnet.  cf:DD-WRT telnet command */
  Serial.print("\x1d");//CTRL+]
  delay(100);
  Serial.print("e");
  delay(100);
  allflush();
}

/* flushing serial read buffer */
void allflush()
{
  delay(100);
  while(Serial.available()>0) Serial.flush();
}

/* End of Client side sketch */

/* Copyright by Kimio Kosaka 2008.08.20 */
    The Arduino sketchIt’s sending characters over serial to a command line on the Fonera router.
    1. It’s doing is responding to „Username” and „Password” prompts with „root” and „admin”, so it’s logging in to the fonera as the root user.
    2. It’s running the „telnet” command to connect to the PC running a server written in Processing via wifi.
    3. It’s sending the value from an analogRead of a pin with potentiometer constantly.
    • It receives those values, and rotates the colour cube on the screen by those.
  1. The Arduino sketch It’s sending characters over serial to a command line on the Fonera router. The Processing sketch

6  Now I’m making and testing „Foneraduino” (Fonera + Arduino clone).

    Acest articol a fost publicat în Articole și etichetat cu , , . Salvează legătura permanentă.

    Un răspuns la Arduino meets Processing via Wifi (DD-WRT)

    Comentariile sunt închise.