Go Down

Topic: Udp/EthernetUdp error (Read 1 time) previous topic - next topic

Jomn

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 :)

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;
    }
Be patient, I'm new here :)

PaulS

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

Jomn

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? :)
Be patient, I'm new here :)

SurferTim


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? :)


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.


pittom

try this
Code: [Select]
/************************************
  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;
}

Bruce_Anderson

Pittom
Had the same problems and your solution worked  - thanks

Bruce

Go Up