Pages: [1]   Go Down
Author Topic: Arduino + Wifly RN-XV + Processing  (Read 2574 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone,

I have an Arduino UNO with a Wifly RN-XV sending values to my PC by wireless (telnet).
Now I want to get this values on Processing, but I don't know how to do it.
Is there some project like this??Someone can help me with this?

Thanks in advance

Rúben Teixeira
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm having the same problem Rubeix.
There's a lot of information/code on internet, but until now i couldn't put working on my project...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which is the best and easiest way to do this connection?Via UDP or TCP/IP??
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
www.buildinginternetofthings.com
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I suggest you implement your own server in Processing and talk to it through the Arduino

check the following code:
Code:

import processing.net.*;
Server myServer;

void setup() {
  size(200, 200);
  // Starts a myServer on port 1234, change this to whatever suits you!
  myServer = new Server(this, 1234);
}

void draw() {
  // Get the next available client
  Client thisClient = myServer.available();
  // write the output of the client
  if (thisClient !=null) {
    String whatClientSaid = thisClient.readString();
    if (whatClientSaid != null) {
      println(thisClient.ip() + "t" + whatClientSaid);
    }
  }
}


and the Arduino code (for Ethernet example, easy to adopt):
Code:

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);

// Enter the IP address of the server you're connecting to:
IPAddress server(192,168,1,1);

// Initialize the Ethernet client library
// with the IP address and port of the server
EthernetClient client;

void setup() {
  // start the Ethernet connection:
  Ethernet.begin(mac, ip);
  // start the serial library:
  Serial.begin(9600);
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 1234)) {
    Serial.println("connected");
  }
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop() {
 
  //The following code will simply send characters for Terminal input to the server - use it as a test
  while (Serial.available() > 0) {
    char inChar = Serial.read();
    if (client.connected()) {
      client.print(inChar);
    }
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    // do nothing:
    while(true);
  }
}

Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello charalamposdoukas,

I have been trying to adapt the arduino code from Ethernet to Wifly. I did that looking at the diferences between Wifly_WebServer example from WiFly Shield code library alpha 2 (source:http://forum.sparkfun.com/viewtopic.php?f=32&t=25216) and WebServer example from Ethernet library.
The result is the following code, but it doesn´t run. It has an error that says: "No matching function for call to 'Client::Client()' ". Can you help me with this please?

Thanks in advance

Code:
#include "WiFly.h"
#include "Credentials.h"

Server server(80);

void setup() {
  // start the WiFly connection:
  WiFly.begin();
 
  if (!WiFly.join(ssid, passphrase)) {
    while (1) {
      // Hang on failure.
    }
  }

  Serial.begin(9600);
  Serial.print("IP: ");
  Serial.println(WiFly.ip());
 
  server.begin();

  // give the WiFly shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 1234)) {
    Serial.println("connected");
  }
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop() {
  Client client = server.available();
 
  //The following code will simply send characters for Terminal input to the server - use it as a test
  while (Serial.available() > 0) {
    char inChar = Serial.read();
    if (client.connected()) {
      client.print(inChar);
    }
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    // do nothing:
    while(true);
  }
}

At the credentials sketch tab the code is:

Code:
#ifndef __CREDENTIALS_H__
#define __CREDENTIALS_H__

// Wifi parameters
char passphrase[] = "passphrase";//my passphrase
char ssid[] = "Wifly";

#endif

« Last Edit: May 19, 2012, 07:47:10 pm by Rubeix » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
www.buildinginternetofthings.com
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

You have misplaced some of the code in your sketch, check the following code. Have not tested if it runs properly but I least it compiles smiley

Code:
#include "WiFly.h"
#include "Credentials.h"

Server server(80);

void setup() {
  // start the WiFly connection:
  WiFly.begin();
 
  if (!WiFly.join(ssid, passphrase)) {
    while (1) {
      // Hang on failure.
    }
  }

  Serial.begin(9600);
  Serial.print("IP: ");
  Serial.println(WiFly.ip());
 
  server.begin();

  // give the WiFly shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");
 
  //------rest shall be implemented inside loop()
 
  // if you get a connection, report back via serial:
  //if (client.connect(server, 1234)) {
  // 
  //  Serial.println("connected");
  //}
  //else {
  //  // if you didn't get a connection to the server:
  //  Serial.println("connection failed");
  //}
}

void loop() {
  Client client = server.available();
 
  //If client has been instantiated
  if (client) {
    //check for client connection
    while (client.connected()) {
      //if client has connected
      if (client.available()) {
        //The following code will simply send characters for Terminal input to the server - use it as a test
        while (Serial.available() > 0) {
          char inChar = Serial.read();
            if (client.connected()) {
              client.print(inChar);
            }
        }
      }
    }
  }
  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    // do nothing:
    while(true);
  }
}
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 22
www.buildinginternetofthings.com
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, previous post contains server code for the WiFly, but you need the Client code to connect to the Processing sketch (which is creating a server).

Code:

#include "WiFly.h"
#include "Credentials.h"

byte server[] = { 192,168,1,1 }; // Your PC IP

Client client(server, 1234);


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

  WiFly.begin();
 
  if (!WiFly.join(ssid, passphrase)) {
    Serial.println("Association failed.");
    while (1) {
      // Hang on failure.
    }
  } 

  Serial.println("connecting...");

  if (client.connect()) {
    Serial.println("connected");
    client.println("Hello World!\n");
    client.println();
  } else {
    Serial.println("connection failed");
  }
 
}

void loop() {
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
 
  while (Serial.available() > 0) {
          char inChar = Serial.read();
            if (client.connected()) {
              client.print(inChar);
            }
    }
 
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}


Logged


Pages: [1]   Go Up
Jump to: