Pages: [1]   Go Down
Author Topic: problem with Ethernet Shield and Access Point  (Read 1029 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hi everybody!  smiley
i'm creating a project for my school final exam..  smiley-roll-blue
i would create a minirobot controlled by pc, on the robot there will be an ip camera..
my arduino and my ipcamera are connected to an access point, connecting my pc to the network i could control the robot with arduino and see the frontal video from the webcam.  smiley-cool  smiley-mr-green

my problem is using the ethernet shield: my arduino is the server and my pc a client, in java on the pc i've just created a program who sends strings (byte to byte) to arduino and it receive it..
my first communication works: if the character received is 'a' i turn on a led, if the char is 's' i turn it off  smiley
then i tried to create another program with many characters for the movements of my robot: 'w','a','s','d','x', and so on... it seems that digitalWrite(...,HIGH) doesn't works..  smiley-sad
(all the motor control is already created and it works perfectly!)
i don't know if it's a logic problem.. someone can help me? smiley

these are the programs:
Led On Off Program (it works):
Code:
#include <SPI.h>
#include <Ethernet.h>
#include <stdlib.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 
byte ip[] = { 192, 168, 0, 177 };   
byte gateway[] = { 192, 168, 0, 1 };
byte subnet[] = { 255, 255, 255, 0 };

// telnet defaults to port 23
EthernetServer server = EthernetServer(23);

void setup()
{
  pinMode(2, OUTPUT);
  Serial.begin(9600);
  Ethernet.begin(mac, ip, gateway, subnet);

  server.begin();
}

void loop()
{
  char temp;
  EthernetClient client = server.available();
  if (client == true) {
    temp=client.read();
   
    Serial.println(temp);
    if(temp=='a')
      digitalWrite(2, HIGH);
    else if(temp=='s')
      digitalWrite(2, LOW);

    server.write(temp);
  }   
}

Motor Code (it doesn't work):
Code:
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 
byte ip[] = { 192, 168, 0, 177 };   
byte gateway[] = { 192, 168, 0, 1 };
byte subnet[] = { 255, 255, 255, 0 };
EthernetServer server = EthernetServer(23);

int motor_left[] = {7, 8};   // pin 15, pin 10 (dell'integrato)
int motor_right[] = {5, 6};  // pin 2, pin 7 (dell'integrato)
int velocita = 9;            // PWM, pin 1,9 (dell'integrato)

void setup()
{
  Ethernet.begin(mac, ip, gateway, subnet);
 
  for(int i = 0; i < 2; i++){
    pinMode(motor_left[i], OUTPUT);
    pinMode(motor_right[i], OUTPUT);
  }
  pinMode(velocita, OUTPUT);
  pinMode(2, OUTPUT);
  Serial.begin(9600);
 
  server.begin();
}

void loop()
{
  char temp;
  EthernetClient client = server.available();
  if (client == true) {
    temp=client.read();
   
    Serial.println(temp);
   
    if(temp=='s')
      motor_stop();
    else if(temp=='w')
      drive_forward();
    else if(temp=='x')
      drive_backward();
    else if(temp=='a')
      turn_left();
    else if(temp=='d')
      turn_right();
    else if(temp=='m')
      analogWrite(velocita, 255);
    else if(temp=='n')
      analogWrite(velocita, 140);

   server.write(temp);
  }
}

void motor_stop(){
  digitalWrite(motor_left[0], LOW);
  digitalWrite(motor_left[1], LOW);
 
  digitalWrite(motor_right[0], LOW);
  digitalWrite(motor_right[1], LOW);
}

void drive_forward(){
  digitalWrite(motor_left[0], HIGH);
  digitalWrite(motor_left[1], LOW);
 
  digitalWrite(motor_right[0], HIGH);
  digitalWrite(motor_right[1], LOW);
}

void drive_backward(){
  digitalWrite(motor_left[0], LOW);
  digitalWrite(motor_left[1], HIGH);
 
  digitalWrite(motor_right[0], LOW);
  digitalWrite(motor_right[1], HIGH);
}

void turn_left(){
  digitalWrite(motor_left[0], LOW);
  digitalWrite(motor_left[1], HIGH);
 
  digitalWrite(motor_right[0], HIGH);
  digitalWrite(motor_right[1], LOW);
}

void turn_right(){
  digitalWrite(motor_left[0], HIGH);
  digitalWrite(motor_left[1], LOW);
 
  digitalWrite(motor_right[0], LOW);
  digitalWrite(motor_right[1], HIGH);
}
Logged


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

anyone can help me?  smiley-cry
Logged


Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 148
Posts: 6104
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What version of the Arduino IDE are you using? The IDE v1.0 would be best.

The Ethernet.begin() parameter format changed in v1.0. This is the new format:

Ethernet.begin(mac);
Ethernet.begin(mac,ip);
Ethernet.begin(mac,ip,dns);
Ethernet.begin(mac,ip,dns,gateway);
Ethernet.begin(mac,ip,dns,gateway,subnet);

Check the basic stuff first.
Logged

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

the problem was only that i hadn't set the analog out of motors  smiley-roll smiley-mr-green
if someone is interested there's the video of the project completed!  smiley
thank you for the help smiley-wink

« Last Edit: June 14, 2012, 03:39:24 pm by Attalo » Logged


Pages: [1]   Go Up
Jump to: