Show Posts
Pages: [1] 2 3
1  Using Arduino / Networking, Protocols, and Devices / Re: problem receiving OSC (Oscuino + UIP ethernet ) on: June 22, 2014, 07:14:07 am
Happy to hear it worked out  and good news that the ENC28J60 and OSCuino play well together smiley
2  Using Arduino / Networking, Protocols, and Devices / Re: problem receiving OSC (Oscuino + UIP ethernet ) on: June 19, 2014, 04:36:51 pm
Hi,

what are the messages you are sending like? I've no experience with the OSCuino lib, but unless you're sending some very complex stuff it can be done using UDP.

Tell more about what your trying to achieve and include your full code.

cheers
3  Using Arduino / Networking, Protocols, and Devices / Re: Ethercard and Servo wobble strangeness on: June 06, 2014, 12:12:28 pm
After more research I started to suspect that the Ethercard library was using the same timer as the Servo library so I tried the ServoTimer2 library which uses a different timer, but the twitch was still there.

Then I tried the UIPEthernet library and the problem was not there.  So this is for sure something with the Ethercard lib.

I have a problem with dropouts, latency and loosing connection with the UIPEthernet lib, so I would much prefer to use Ethercard. Anyone know where to go from here?
4  Using Arduino / Networking, Protocols, and Devices / Re: Ethercard and Servo wobble strangeness on: June 06, 2014, 05:37:07 am
I have now boiled down the code to the only necessary parts, and only one servo:

Code:
#include <EtherCard.h>
#include <IPAddress.h>
#include <Servo.h>

static byte myip[] = { 172,16,1,153 };
static byte mymac[] = { 0x70,0x69,0x69,0x2D,0x30,0x04 };
// gateway ip
static byte gwip[] = { 172,16,1,2 };

byte Ethernet::buffer[500]; // tcp/ip send and receive buffer

Servo Servo1;

//callback that prints received packets to the serial port
void udpSerialPrint(word port, byte ip[4], const char *data, word len) {

}

void setup(){
  ether.begin(sizeof Ethernet::buffer, mymac, 10);
  ether.staticSetup(myip, gwip);
  //register udpSerialPrint() to port 8888
  ether.udpServerListenOnPort(&udpSerialPrint, 8888);
  
  Servo1.attach(3);  // Servo 1 on pin 3
  Servo1.write(62);

}

void loop(){
  //this must be called for ethercard functions to work.
  ether.packetLoop(ether.packetReceive());
}

- The servo twitches when sending any values to the ip address.
- When set to of these values (7, 18, 26, 37, 54, 62, 68, 73, 81, 92, 103, 111, 117, 122, 147, 153, 158, 166) the servo will stay twitching even when not receiving any packets over UDP. On other values it remains still unless I send it any values.

Edit: and still if I comment out
ether.packetLoop(ether.packetReceive());
in void loop(), the twitching stops.

After reading this topic http://forum.arduino.cc/index.php?topic=235765.0 it seems probable that the Ethercard library is obstructing the Servo lib from updating the servo, or that there is a fault in the Servo library.

Any ideas? Am I asking in the right forum?

cheers,
g
5  Using Arduino / Networking, Protocols, and Devices / Re: Ethercard and Servo wobble strangeness on: June 04, 2014, 10:15:09 am
Hi Paul,

hm, you suggested using atoi in this context in this thread http://forum.arduino.cc/index.php?topic=235019.msg1691170#msg1691170.
My knowledge on this is limited, what should I use to process the incoming UPD packet instead of atoi? Do you think that this could be the problem?
6  Using Arduino / Networking, Protocols, and Devices / Re: Ethercard and Servo wobble strangeness on: June 04, 2014, 08:06:47 am
The comment should say
// This part pisses away resources unnecessarily

Haha! Thanks, I made the change (to the code, not the comment smiley-wink), but it did not change the behavior though :/
7  Using Arduino / Networking, Protocols, and Devices / Re: Ethercard and Servo wobble strangeness on: June 04, 2014, 07:26:03 am
How are you supplying power to the servos?
Hi Ray,

With the Pro Mini I power them from a 5v, 1A power supply, which also powers the Pro Mini. The issue is still there when only one servo is connected. I have measured the ampere pull and it is sufficient.

With the Uno I power just one servo from the 5v pin on the board.

8  Using Arduino / Networking, Protocols, and Devices / Ethercard and Servo wobble strangeness on: June 04, 2014, 06:49:58 am
Hi all,

I've got 4 servos hooked up to my Uno and a ENC28J60 ethernet module, sending messages to the servos over UDP, and I am getting some strange twitching of the servos, at different intervals, when they are not receiving any values. Here is a video of one of them http://tinypic.com/r/zb7yv/8 (bit out of focus, but you hear it at least). The twitching also often happens if I send messages to other servos...!

I have boiled it down to being a problem with the code or Ethercard/Servo library (see below for the things I have ruled out as being the issue).

When I comment out:
ether.packetLoop(ether.packetReceive());
in void loop() the problem disappears, but it also does not read any UDP packets anymore.

Also, strangely, when I comment out some of the servos, to leave me with just two, the twitching is reduced, but not gone, and it increases with more servos added in the code.

Code:

#include <EtherCard.h>
#include <IPAddress.h>
#include <Servo.h>

// ethernet interface ip address
static byte myip[] = { 172,16,1,152 };
// gateway ip address
static byte gwip[] = { 172,16,1,2 };
// mac
static byte mymac[] = { 0x70,0x69,0x69,0x2D,0x30,0x03 };

byte Ethernet::buffer[500]; // send and receive buffer

// initialization of the servos - pin 10 is used by the Ethernetshield
Servo Servo1;  // Servo 1 on pin 3
Servo Servo2;  // Servo 2 on Pin 4 
Servo Servo3;  // Servo 3 on Pin 5
Servo Servo4;  // Servo 4 on Pin 6


//callback that prints received packets to the serial port
void udpSerialPrint(word port, byte ip[4], const char *data, word len) {
 
  char command[4];      // commandstring
  unsigned int vnumber; // the value as integer
 
  if (len > 0) {
       
          command[0]=data[0];
          command[1]=data[1];
          command[2]=data[2];
          command[3]='\0';
         
          vnumber = atoi(&data[3]); // convert to integer
   
    // this part converts the command to hardware
    if (String(command) == "SR1")
    {
      Servo1.write(vnumber);
    }

    if (String(command) == "SR2")
    {
      Servo2.write(vnumber);
    }

    if (String(command) == "SR3")
    {
      Servo3.write(vnumber);
    }
   
    if (String(command) == "SR4")
    {
      Servo4.write(vnumber);
    }

  }
}

void setup(){
  Serial.begin(9600);
  Serial.println("\n[backSoon]");

  if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)
    {Serial.println( "Failed to access Ethernet controller"); };

  Serial.println("ether begin ok");

  ether.staticSetup(myip, gwip);

  Serial.println("static ip set");

  //register udpSerialPrint() to port 8888
  ether.udpServerListenOnPort(&udpSerialPrint, 8888);
 
  Servo1.attach(3);  // Servo 1 on pin 3
  Servo2.attach(4);  // Servo 2 on Pin 4
  Servo3.attach(5);  // Servo 3 on Pin 5
  Servo4.attach(6);  // Servo 4 on Pin 6
  Servo1.write(65);
  Servo2.write(65);
  Servo3.write(65);
  Servo4.write(65);

  Serial.println("setup ok");
}

void loop(){
  //this must be called for ethercard functions to work.
  ether.packetLoop(ether.packetReceive());
}



Other things I have tried:
- using different servos (so it's not the servo)
- using a pro mini board (so it's not the uno board)
- different ENC28J60 modules (so it's not the module)
- powering from a 9v power adapter
- powering from USB only from the laptop running on batteries (so it's not unstable current or something)
- using the servos with plain example code for servos.

Any insight or tips of other things I can try to pinpoint this is greatly appreciated! I am hoping something is obvious in my code, as I'm not a very experienced coder...

Cheers!
9  Using Arduino / Project Guidance / Re: Battery advice for my project on: May 07, 2014, 04:18:57 pm
Quote
- one charge should last
how long?
hah, dont know how that disappeared.. 2 hours at least

Thanks for the suggestions! It's true, I'm not sure where to look.

Can I use all these batteries even when they are charging? And can they stay in the charger safely for a long time?
10  Using Arduino / Project Guidance / Battery advice for my project on: May 07, 2014, 02:18:01 pm
Hi all,

I need to power my project with batteries, and the different modules needs different voltages:
- arduino uno with wifi board 5v pulls ~ 160mA
- servos 5v pulls ~ 800mA
- amplifier 6...16v (i want to use as much voltage as i can, within limits..) ~ 300mA
- radio receiver 3v pulls ~ 150mA
overall ~ 1600mA

These are my goals:
- I want to be able to recharge it "like a laptop", so that it can run while it is charging (like it's in a docking station).
- size and weight is important, should not be much bigger than a fist, not more than 1kg, as this will be a semi portable "robot".
- safety is an issue, that is, I'd best avoid batteries that explode and such  smiley-wink
- one charge should last 2 hours at the least

What would be a good approach to this? Lipo? Nimh? Charger? A good way to regulate the voltage?

(I've looked a bit into lipo batteries, but I cant find any over 3.7v that have a protection circuit.. and the voltage seem to stop at 7.4v..)

thanks for any hints or suggestions!
11  Using Arduino / Programming Questions / Re: get a integer from char* ...? on: April 30, 2014, 07:43:14 am
I ended up using a different library, but now it works smoothly. The finished code is here:
http://forum.arduino.cc/index.php?topic=178024.msg1702783#msg1702783

Thanks for your help all of you!
12  Using Arduino / Networking, Protocols, and Devices / Re: new library UIPEthernet: uIP adapted to Arduino for ENC28J60 on: April 30, 2014, 07:31:20 am
So, to answer myself  -

I redid the code with the Ethercard library and now it's working smoothly, no dropped UDP packages so far.

I was worried that it might have been the ENC28J60 or the cheap fake 4 euro "arduino pro mini" I'd gotted over ebay that was causing the dropouts, but no! So now I'm really happy that I have a fully working 7 euro ethernet arduino smiley-grin

Here's the code in case anyone else is in the same situation:
(but beware, its using the Ethercard lib)

Code:
// Modified from the Ethercard udpServer example
// This code takes simple strings like SR145 where SR1 means "servo 1" and 45 is the value
// I use pin 10 for CS from the ENC28J60. Pin 8 is default in the Ethercard library. This has to be defined in ether.begin


#include <EtherCard.h>
#include <IPAddress.h>
#include <Servo.h>        // Servo library

// ethernet interface ip address
static byte myip[] = { 172,16,3,10 };
// gateway ip address
static byte gwip[] = { 172,16,3,17 };


// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x70,0x69,0x69,0x2D,0x30,0x05 };

byte Ethernet::buffer[500]; // tcp/ip send and receive buffer

// Servo init
Servo Servo1;  // Servo 1 on pin 7
Servo Servo2;  // Servo 2 on Pin 6 



//callback that prints received packets to the serial port
void udpSerialPrint(word port, byte ip[4], const char *data, word len) {
 
  char command[4];      // commandstring
  unsigned int vnumber; // the value as integer
 
  //IPAddress src(ip[0], ip[1], ip[2], ip[3]);
  //Serial.println(src);
  //Serial.println(port);
  //Serial.println(data);
  //Serial.println(len);
 
  if (len > 0) {
   
        //Serial.print("received: ");
        Serial.println(data); // print all received data
       
          // store SR1 in command
          command[0]=data[0];
          command[1]=data[1];
          command[2]=data[2];
          command[3]='\0';
         
          // store value here
          vnumber = atoi(&data[3]); // convert to integer
   
        //Serial.print("command: ");
        //Serial.println(command);
        //Serial.print("value: ");
        //Serial.println(vnumber);
   
    // write to the servos
    if (String(command) == "SR1")
    {
      Servo1.write(vnumber);
      Serial.println("servo 1 go!");
    }

    if (String(command) == "SR2")
    {
      Servo2.write(vnumber);
    }

  }
}

void setup(){
  Serial.begin(9600);
  Serial.println("\n[backSoon]");

  if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0) // the 10 because I use pin 10 for CS, not 8 as is default in Ethercard
    {Serial.println( "Failed to access Ethernet controller"); };

  Serial.println("ether begin ok");

  ether.staticSetup(myip, gwip);

  Serial.println("static ip set");
  //ether.printIp("IP:  ", ether.myip);
  //ether.printIp("GW:  ", ether.gwip);
  //ether.printIp("DNS: ", ether.dnsip);

  //register udpSerialPrint() to port 8888
  ether.udpServerListenOnPort(&udpSerialPrint, 8888);
 
  Servo1.attach(7);  // Servo 1 on pin 7
  Servo2.attach(6);  // Servo 2 on Pin 6
  Serial.println("setup ok");
}

void loop(){
  //this must be called for ethercard functions to work.
  ether.packetLoop(ether.packetReceive());
}


13  Using Arduino / Networking, Protocols, and Devices / Re: new library UIPEthernet: uIP adapted to Arduino for ENC28J60 on: April 28, 2014, 06:56:16 am
Hi there!

Thanks for the efforts for making this library! I'm trying now to convert a project I have controlling servos over udp from the Wiznet W5100 to using the ENC28J60 and this library. It works sort of like an RC car, that is, I'm sending a lot of values to go to the servos, and this works fine with the W5100, but now with the ENC28J60 I'm getting a lot of dropouts

Reading through this thread that the W5100 does some processing of the packages by itself, while the ENC28J60 leaves this for the Arduino makes me hope that this problem is somehow fixable...

Thus I'm wondering if this is a problem with the ENC28J60 itself, the UIPEthernet library, or my inexperienced coding not being optimized.

So I would like to ask if anyone could have a look at my code and see if it can be made better. Any input would be greatly apprechiated  smiley

The messages sent over UDP are short strings, SR10 to SR1127, SR1 meaning Servo nr 1, and then the value 0-127.

Code:

#include <UIPEthernet.h>
#include <Servo.h>        // Servo library

EthernetUDP udp;

IPAddress ip(172,16,3,200);

unsigned int localPort = 8888;      // local port to listen on

// initialization of the servos - pin 10 is used by the Ethernetshield
Servo Servo1;  // Servo 1 on pin 7
Servo Servo2;  // Servo 2 on Pin 8

void setup() {

  Serial.begin(9600);

  uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};

  Ethernet.begin(mac,IPAddress(172,16,3,200));
  Servo1.attach(7);  // Servo 1 on pin 7
  Servo2.attach(8);  // Servo 2 on Pin 8
  int success = udp.begin(8888);

  Serial.print("initialize: ");
  Serial.println(success ? "success" : "failed");

}

void loop() {
 
  // initialization of the variables
  char command[4];      // commandstring
  unsigned int vnumber; // the value as integer
 
  Ethernet.maintain();
 
  //check for new udp-packet:
  int size = udp.parsePacket();
  if (size > 3) {

        char msg[7];
        int len;
        memset(msg, '\0', 7);   // Set all elements to null
        len = udp.read(msg,7);
        msg[len] = '\0';

        vnumber = atoi(&msg[3]); // convert to integer

        Serial.print("received: ");
        Serial.println(msg);
       
          command[0]=msg[0];
          command[1]=msg[1];
          command[2]=msg[2];
          command[3]='\0';

    //finish reading this packet:
    udp.flush();
   
        Serial.print("command: ");
        Serial.println(command);
        Serial.print("value: ");
        Serial.println(vnumber);
   
    // write to servos
    if (String(command) == "SR1")
    {
      Servo1.write(vnumber);
      //Serial.println("servo 1 go!");
    }

    if (String(command) == "SR2")
    {
      Servo2.write(vnumber);
    }

  }
  delay(10);
  Ethernet.maintain();
}
14  Using Arduino / Programming Questions / Re: get a integer from char* ...? on: April 22, 2014, 02:08:04 pm
Quote
I think it does answer your questions

It does indeed! Thank you for your help  smiley I'll post the code here after it's cleaned up a bit.
15  Using Arduino / Programming Questions / Re: get a integer from char* ...? on: April 22, 2014, 01:24:00 pm
Hi econjack,

Thanks for this, it reduces the udp.read process to something more understandable for me.

It does not however answer my question; I still have to convert the last 3 (or 4 with the null) characters of the msg into an integer..
Pages: [1] 2 3