Pages: [1]   Go Down
Author Topic: Udp/EthernetUdp error  (Read 1160 times)
0 Members and 1 Guest are viewing this topic.
Norway
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Be patient, I'm new here :)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I wanted to try to try the IP Gamepad (1) on my Android phone with my Arduino Ethernet. So i downloaded the example (2) and tried to upload it to the Arduino, but i got this error: "The Udp class has been renamed EthernetUdp.". So i thought I could change "Udp" to "EthernetUdp" (all of them), but then I get this error: "'EthernetUdp' was not decleared in this scope".

What could be wrong? I'm kinda new to Arduino and programming, please help smiley

LINKS:
1) IP Gamepad: http://code.google.com/p/ipgamepad/
2) Example code: http://code.google.com/p/ipgamepad/downloads/detail?name=ArduinoRobotControl_v0.1.zip&can=2&q=

Here's the example code, "Udp" replaced with "EthernetUdp":

Quote
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Servo.h>

//Set the MAC address, static IP, gateway, and subnet of the network
byte mac[] = { 0x00, 0x1D, 0x60, 0xAF, 0x03, 0x35 };
byte ip[]  = { 192, 168, 1, 22 };

//EthernetUdp Stuff
const int PORT = 4444;            //Port of incoming EthernetUdp data
const int PACKET_SIZE = 4;        //Size of the joystick data packet
byte joystick_data[PACKET_SIZE];  //Byte array for incoming data -
  • = leftY, [1] = leftX, [2] = rightY, [3] = rightX

//Robot specific stuff
boolean lastState = false;           //Keeps track of when we go between enabled/disabled or vice versa   
unsigned long lastUpdate = 0;        //Keeps track of the last time (ms) we received data

//Define outputs
int pwm01 = 5;  //Digital Pin 5
int pwm02 = 3;  //Digital Pin 3

//Speed Controller/Servo Objects
Servo leftDrive;
Servo rightDrive;

void setup() {
  Serial.begin(9600);  //Setup serial comms for debugging
 
  // Start Ethernet and EthernetUdp
  Ethernet.begin(mac,ip);
  EthernetUdp.begin(PORT);
 
  Serial.println("Control system initialized.");
}


void loop() {
    xferdata();
 
    //Only allow to be enabled if we've received data in the last 100ms and robot is set to enabled
    if (((millis() - lastUpdate) <= 100) && (millis() > 500))  // disabled for first 500ms of runtime
      enabled();
    else
      disabled();
}


/* This function's sole purpose is to receive data and shove it into the joystick_data byte array */
void xferdata()
{
  if (EthernetUdp.available()) {
    EthernetUdp.readPacket(joystick_data,PACKET_SIZE);
    lastUpdate = millis();
  }
}


void enabled()
{
    //If we were last disabled, we need to attach the PWM outputs
    if (lastState == false) {
      leftDrive.attach(pwm01);
      rightDrive.attach(pwm02);
    }
 
    //Output the left/right drive PWMs based on joystick input (0-180)
    leftDrive.write(map((long)joystick_data[0], 0, 255, 0, 180));
    rightDrive.write(map((long)joystick_data[2], 0, 255, 0, 180));
   
    //We are enabled
    lastState = true;
}


void disabled()
{
    //disabled, detach PWM outputs
    leftDrive.detach();
    rightDrive.detach();
   
    //We are disabled
    lastState = false;
}
Logged

Be patient, I'm new here smiley

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46113
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There are example sketches that come with the Ethernet library with the Arduino IDE. Have you looked at them?
Logged

Norway
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Be patient, I'm new here :)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, I've looked at the examples in Arduino, but that one is designed to recieve a "char". It just gives me lots of unreadable signs/letters when I use it with IPGamePad. I've tried to change "char" to "byte", but then I get other errors.

Is anyone able to help me? smiley
Logged

Be patient, I'm new here smiley

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

Yes, I've looked at the examples in Arduino, but that one is designed to recieve a "char". It just gives me lots of unreadable signs/letters when I use it with IPGamePad. I've tried to change "char" to "byte", but then I get other errors.

Is anyone able to help me? smiley

If you are sending bytes in the UDP packet rather than printable characters, then the challenge is in your IPGamePad. It is displaying the character for that value instead of the byte value. Try reprogramming the IPGamePad, or convert the byte values to an asciii string before sending it.

Logged

scranton,pa
Offline Offline
Newbie
*
Karma: 2
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

try this
Code:
/************************************
  Arduino Based Robot Control System v0.1
  by Eric Barch (ttjcrew.com)
************************************/
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Servo.h>

//Set the MAC address, static IP, gateway, and subnet of the network
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[]  = { 192, 168, 1, 55 };

//UDP Stuff
unsigned int localPort = 55;            //Port of incoming UDP data
const int PACKET_SIZE = 4;        //Size of the joystick data packet
byte joystick_data[PACKET_SIZE];  //Byte array for incoming data - [0] = leftY, [1] = leftX, [2] = rightY, [3] = rightX

//Robot specific stuff
boolean lastState = false;           //Keeps track of when we go between enabled/disabled or vice versa   
unsigned long lastUpdate = 0;        //Keeps track of the last time (ms) we received data

//Define robot outputs
int pwm01 = 5;  //Digital Pin 5
int pwm02 = 6;  //Digital Pin 6

//Speed Controller/Servo Objects
Servo leftDrive;
Servo rightDrive;

EthernetUDP Udp;

void setup() {
  Serial.begin(9600);  //Setup serial comms for debugging
 
  // Start Ethernet and UDP
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);
 
  Serial.println("Robot control system initialized.");
}


void loop() {
    xferdata();
 
    //Only allow robot to be enabled if we've received data in the last 100ms and robot is set to enabled
    if (((millis() - lastUpdate) <= 100) && (millis() > 500))  //Robot is disabled for first 500ms of runtime
      enabled();
    else
      disabled();
}


/* This function's sole purpose is to receive data and shove it into the joystick_data byte array */
void xferdata()
{
  if (Udp.available()) {
    Udp.read(joystick_data,PACKET_SIZE);
    lastUpdate = millis();
  }
}


void enabled()
{
    //If we were last disabled, we need to attach the PWM outputs
    if (lastState == false) {
      leftDrive.attach(pwm01);
      rightDrive.attach(pwm02);
    }
 
    //Output the left/right drive PWMs based on joystick input (0-180)
    leftDrive.write(map((long)joystick_data[0], 0, 255, 0, 180));
    rightDrive.write(map((long)joystick_data[2], 0, 255, 0, 180));
   
    //We are enabled
    lastState = true;
}


void disabled()
{
    //Robot is disabled, detach PWM outputs
    leftDrive.detach();
    rightDrive.detach();
   
    //We are disabled
    lastState = false;
}
Logged

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

Pittom
Had the same problems and your solution worked  - thanks

Bruce
Logged

Pages: [1]   Go Up
Jump to: