Show Posts
Pages: [1] 2 3 ... 5
1  Products / Arduino Due / Re: ArduinoDue serialUSB sends bad messages. on: June 06, 2014, 04:16:41 am
ah that's interesting! I can more or less reproduce the problem consistently.
I forgot to mention I'm on OSX 10.9.3, also no external hub.
I hadn't considered the OS might be the problem.
2  Products / Arduino Due / Re: ArduinoDue serialUSB sends bad messages. on: May 21, 2014, 03:59:01 am
The problem seems to appear less often when adding a bit of delay after every SerialUSB.print() and SerialUSB.println() call. for example:
Code:
SerialUSB.println("hello");
delayMicroseconds(500);

I'm still curious about the reason why this problem shows itself sometimes and other times not at all..
Maybe it has something to do with this:
Quote
As of version 1.0, serial transmission is asynchronous; Serial.print() will return before any characters are transmitted.
from
http://arduino.cc/en/Serial/Print
3  Products / Arduino Due / ArduinoDue serialUSB sends bad messages. on: May 17, 2014, 09:25:37 am
Hi all,
I've had this problem for a few months now and haven't been able to figure it out. Every once and a while my Arduino Due sends data out in the wrong order over SerialUSB (native USB -> SAM3X). I have seen this when compiling with Arduino 1.5.2 and Arduino 1.5.6-r2.
To try to catch the problem I have reduced the code to this sample sketch:
Code:
/*
    ArduinoDue SerialUSB bug test
*/

long counter = 0;

void setup() {
  while(!SerialUSB);      // wait for the serialUSB to come up
  delay(100);
  SerialUSB.println("Arduino DUE SerialUSB (SAM3X native USB)");
  SerialUSB.println("This demonstrates how SerialUSB sends messages in the wrong order sometimes");
  SerialUSB.println("Just start the Arduino serial monitor while this sketch runs on an Arduino DUE");
  SerialUSB.println("If the serial messages arrive correctly, just close and open the serial monitor again");
  SerialUSB.println("After a few iterations you'll see the messages get mixed up");
  SerialUSB.println(" --- ");
  SerialUSB.println("Tested with Arduino 1.5.6-r2");
}

void loop() {
  if(SerialUSB){
      counter ++;
     SerialUSB.print(counter);
     SerialUSB.print(" - I have sent ");
     SerialUSB.print(counter);
     SerialUSB.println(" messages so far.");
     delay(200);
  }
}

After uploading this to the Arduino Due I just open the Serial Monitor. The expected feedback is something like this:

Code:
61 - I have sent 61 messages so far.
62 - I have sent 62 messages so far.
63 - I have sent 63 messages so far.
64 - I have sent 64 messages so far.
65 - I have sent 65 messages so far.
66 - I have sent 66 messages so far.
67 - I have sent 67 messages so far.

But when i restart the serial monitor I sometimes get something like this:

Code:

m - I have sent 16 messages so far.
17 - I have sent 17 messages so far.
18 - I have sent 18 messages so far.
 m - I have sent 19 messages so far.
20 - I have sent 20 messages so far.
21 - I have sent 21 messages so far.
 m - I have sent 22 messages so far.
or
Code:
16 - I have sent 16 messages so far.
17 - I have sent  m messages so far.
18 - I have sent 18 messages so far.
19 - I have sent 19 messages so far.
20 - I have sent  m messages so far.
21 - I have sent 21 messages so far.
22 - I have sent 22 messages so far.

The problem sometimes happens right from the start, without re-starting the serial connection.
I have created an OpenFrameworks app that feeds me back the serial messages and see the same problem appear, so it's not related to the Arduino IDE
I have tried different BAUD rates, and have seen it every time.
I have tested this with different Arduino Due (all R3) boards, they all do it.

Does this ring a bell for anyone? I'm out of ideas..
4  Products / Arduino Due / Re: speed of digitalWrite and digitalRead on Arduino Due. on: June 06, 2013, 11:45:33 am
I've finally cleaned up the source of my drawing machine and did an initial commit to github.
It's Arduino Due + micro sD reader + 3 A4988 stepper drivers
You can check it here http://github.com/timknapen/Longhand-Firmware
5  Using Arduino / Networking, Protocols, and Devices / Re: Arduino WiFi Shield UDP Support on: April 23, 2013, 09:27:15 am
Indeed while copying the code I added a "z" in it but it "works" here it is with the same bug i was talking about earlier :

Hi Ohhopi,

So I understand you still get the same feed back from Serial: "ntp server update failed"

What did you try to find where the bug is? Did you try my suggestion to start from a tested working example and seeing when it starts failing? Another good thing to do is add a lot of debug printouts. So everytime you think your code does something the Serial prints this out for you so you are sure it is actually the way you expect it to be.

One thing I see that is probably not right is this:
in getTimeAndDate() :
Code:
  sendNTPpacket(timeServer);
   delay(1000);
Which means you are doing this request every second. According to this pagehttp://tf.nist.gov/tf-cgi/servers.cgi you shouldn't query the servers more than once every 4 seconds. You'll see in the UDPNTPClient example that they wait 10 seconds between each call.
6  Products / Arduino Due / Re: speed of digitalWrite and digitalRead on Arduino Due. on: April 15, 2013, 08:12:15 pm
Hi Sam,
Very cool! I'm not really using it for Reprap, but something very similar: a drawing machine (this one: http://www.flickr.com/photos/worldreceiver/8215231164/in/set-72157622815511236 ) but it's easier to say "reprap-like"
I think digitalWriteFast is implemented only with macros if I'm not mistaken. If you get direct pin manipulation to work on the Due, would you mind releasing it? I for one would find it very interesting.
7  Using Arduino / Networking, Protocols, and Devices / Re: Arduino WiFi Shield UDP Support on: April 15, 2013, 05:55:59 pm
I also read that page when I was still trying with the old buggy firmware.
You can ignore everything on that page except the part about updating ports. That's the only thing I didn't document in my post I think.
8  Using Arduino / Networking, Protocols, and Devices / Re: Arduino WiFi Shield UDP Support on: April 15, 2013, 05:40:31 pm
Quote
IP Address: 192.168.2.6
Just a wild guess: is it possible the receiving ip should be something like 192.168.2.something... instead of the 192.168.1.212 you were using? usually when you are on the same network, the range of IPs is limited so only the last byte is different.

I have no idea why you get this weird output like
Quote
signal strength (RSSI): 0
Encryption Type: 0
did you correctly upgrade the WifiShield firmware? Are you using the correct library?
9  Using Arduino / Networking, Protocols, and Devices / Re: Arduino WiFi Shield UDP Support on: April 15, 2013, 03:41:42 pm
Is the initialization of your class correct? Is it right I'm initializing it like this:

Code:
Udp.begin(receiverPort);

...using receiverPort as argument?

Is the composition of the UDP message correct?
Well yes and no.
If you look at the header file of WifiUDP ( https://github.com/mlafauci/Arduino/blob/wifishield-bugfix/libraries/WiFi/WiFiUdp.h ), you'll see that the method is commented like this:
Code:
  virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
so it's expecting you to pass the port the Arduino should listen on, not the one to send to. But since you are not listening on the Arduino and the local and remote port can be the same, this shouldn't be a problem.

The construction of your UDP message
Code:
Udp.beginPacket(receiverIP, receiverPort); //start udp packet
  Udp.write(valueInBytes, 8); //write sensor data to udp packet
  Udp.endPacket(); // end packet
looks right to me.
It's difficult to debug these kind of things from a distance. What I would do in such a case is try with the simplest setup that works and then change the code until it breaks. Step by step, compiling and testing with every change. At a certain point it will stop working.
So I would suggest you start with my example, start changing things and see how far you can get.
I would start by checking these:
- do you really want delay(10000); // 10sec delay?
- is the receiving computer really at IP 192.168.1.212 ? and is it listening at port 9100 ?
- more really obvious mistakes that are easy to overlook :-)
10  Products / Arduino Due / Re: speed of digitalWrite and digitalRead on Arduino Due. on: April 15, 2013, 01:25:32 pm
so I've changed my test like this:

Code:
//#include <digitalWriteFast.h> // uncomment for Arduino UNO

/*
I'm trying to see how fast some instructions are on Arduino UNO and Arduino DUE
*/

long sampleSize = 1000000; // do a million times!
long lastTime;

//-----------------------------------------------------------------------------
void setup(){
  delay(50); // wait a bit. (Arduino Due prints nonsense to the serial port...??)
  Serial.begin(115200); // go really fast serial!
  Serial.print("Sample size: ");
  Serial.println(sampleSize);
  // I will store my value in this:
  int n;
 
  // and use these pins for writing or reading
  pinMode(2, OUTPUT);
  pinMode(3, INPUT);

  Serial.println("digitalWrite:");
  lastTime = micros();
  for(long i =0; i < sampleSize; i++){
    digitalWrite(2, HIGH);
    digitalWrite(2, LOW);
  }
  printTime( micros() - lastTime);

#ifdef digitalWriteFast // not working with Arduino Due
  Serial.println("digitalWriteFast:");
   lastTime = micros();
   for(long i =0; i < sampleSize; i++){
   digitalWriteFast(2, HIGH);
   digitalWriteFast(2, LOW);
   }
   printTime( micros() - lastTime);
#endif

  Serial.println("digitalRead:");
  lastTime = micros();
  for(long i =0; i < sampleSize; i++){
    n = digitalRead(3);
  }
  printTime( micros() - lastTime);
 
#ifdef digitalReadFast
  Serial.println("digitalReadFast:");
  lastTime = micros();
  for(long i =0; i < sampleSize; i++){
    n = digitalReadFast(3);
  }
  printTime( micros() - lastTime);
#endif

}

//-----------------------------------------------------------------------------
void loop(){
  // do nothing
}


//-----------------------------------------------------------------------------
void printTime( long microsecs){
  int mins, secs, msecs, usecs;

  msecs = floor(microsecs / 1000);
  usecs = microsecs % 1000;

  secs = floor(msecs / 1000);
  msecs = msecs % 1000;

  mins = floor(secs / 60);
  secs = secs % 60;
  Serial.print("time: ");
  Serial.println(microsecs);

  Serial.print(mins);
  Serial.print(" min ");
  Serial.print(secs);
  Serial.print(" sec ");
  Serial.print(msecs);
  Serial.print(" msec ");
  Serial.print(usecs);
  Serial.println(" usecs");
  Serial.println("");
  delay(20);
}

and the new results are:

Arduino UNO
Sample size: 1000000
digitalWrite:
time: 8991484
0 min 8 sec 991 msec 484 usecs

digitalWriteFast:
time: 754608
0 min 0 sec 754 msec 608 usecs

digitalRead:
time: 5721828
0 min 5 sec 721 msec 828 usecs

digitalReadFast:
time: 691724
0 min 0 sec 691 msec 724 usecs


Arduino Due
Sample size: 1000000
digitalWrite:
time: 5148742
0 min 5 sec 148 msec 742 usecs

digitalRead:
time: 1275278
0 min 1 sec 275 msec 278 usecs

Much better! :-)
So I guess I won't be needing to worry about the speed of digitalWrite or read.
11  Products / Arduino Due / Re: speed of digitalWrite and digitalRead on Arduino Due. on: April 15, 2013, 01:14:13 pm
nice catch stimmer!  smiley-red
12  Using Arduino / Networking, Protocols, and Devices / Re: Arduino WiFi Shield UDP Support on: April 15, 2013, 01:03:52 pm
srrichie,

Quote
Your suggestion was already implemented in my code (I'm not THAT noob   )
Sorry about that, I didn't mean to call you a noob, it's just difficult to hunt down bugs when you don't post full code.

the sketch you posted compiles just fine. Could you provide more information about the errors you get?

best,
tim.
13  Products / Arduino Due / speed of digitalWrite and digitalRead on Arduino Due. on: April 15, 2013, 12:41:25 pm
hi all,

I'm think about using the Arduino Due as the brains of a Reprap like machine. It will read commands from an SD card (or from it's memory, maybe Due has enough?), parse them and control stepper motors.
So I ordered one and started doing some tests. I've found that digitalWrite and digitalRead are remarkably slower on the Due than the UNO.

I used this sketch as a test:
Code:
#include <digitalWriteFast.h>

/*
I'm trying to see how fast some instructions are on Arduino UNO and Arduino DUE
*/

int sampleSize = 1000000; // do a million times!
long lastTime;

//-----------------------------------------------------------------------------
void setup(){
  delay(50); // wait a bit. (Arduino Due prints nonsense to the serial port...??)
  Serial.begin(115200); // go really fast serial!
 
  // I will store my value in this:
  int n;
 
  // and use these pins for writing or reading
  pinMode(2, OUTPUT);
  pinMode(3, INPUT);

  Serial.println("digitalWrite:");
  lastTime = micros();
  for(int i =0; i < sampleSize; i++){
    digitalWrite(2, HIGH);
    digitalWrite(2, LOW);
  }
  printTime( micros() - lastTime);

#ifdef digitalWriteFast // not working with Arduino Due
  Serial.println("digitalWriteFast:");
   lastTime = micros();
   for(int i =0; i < sampleSize; i++){
   digitalWriteFast(2, HIGH);
   digitalWriteFast(2, LOW);
   }
   printTime( micros() - lastTime);
#endif

  Serial.println("digitalRead:");
  lastTime = micros();
  for(int i =0; i < sampleSize; i++){
    n = digitalRead(3);
  }
  printTime( micros() - lastTime);
 
#ifdef digitalReadFast
  Serial.println("digitalReadFast:");
  lastTime = micros();
  for(int i =0; i < sampleSize; i++){
    n = digitalReadFast(3);
  }
  printTime( micros() - lastTime);
#endif

}

//-----------------------------------------------------------------------------
void loop(){
  // do nothing
}


//-----------------------------------------------------------------------------
void printTime( long microsecs){
  int mins, secs, msecs, usecs;

  msecs = floor(microsecs / 1000);
  usecs = microsecs % 1000;

  secs = floor(msecs / 1000);
  msecs = msecs % 1000;

  mins = floor(secs / 60);
  secs = secs % 60;
  Serial.print("time: ");
  Serial.println(microsecs);

  Serial.print(mins);
  Serial.print(" min ");
  Serial.print(secs);
  Serial.print(" sec ");
  Serial.print(msecs);
  Serial.print(" msec ");
  Serial.print(usecs);
  Serial.println(" usecs");
  Serial.println("");
  delay(20);
}

I commented out "#include <digitalWriteFast.h>" when compiling for the Due.

These are the results:

Arduino Due:
digitalWrite:
time: 5196306
0 min 5 sec 196 msec 306 usecs

digitalRead:
time: 1156070
0 min 1 sec 156 msec 70 usecs

Arduino UNO:
digitalWrite:
time: 142964
0 min 0 sec 142 msec 964 usecs

digitalWriteFast:
time: 8624
0 min 0 sec 8 msec 624 usecs

digitalRead:
time: 87508
0 min 0 sec 87 msec 508 usecs

digitalReadFast:
time: 7544
0 min 0 sec 7 msec 544 usecs

Sanguino ATMEGA664A  (Reprap motherboard v1.2)
digitalWrite:
time: 142964
0 min 0 sec 142 msec 964 usecs

digitalWriteFast:
time: 8628
0 min 0 sec 8 msec 628 usecs

digitalRead:
time: 86440
0 min 0 sec 86 msec 440 usecs

digitalReadFast:
time: 7548
0 min 0 sec 7 msec 548 usecs

Does anyone know why I find this difference? Is there already a digitalWriteFast library for Due available?

best,
tim.
14  Using Arduino / Networking, Protocols, and Devices / Re: Arduino WiFi Shield UDP Support on: April 15, 2013, 11:27:29 am
srrichie,

just strip your sketch from all the calls to ethernetUDP and replace it with the appropriate parts of WifiUDP calls in the example I posted above in this thread.

so
Code:
EthernetUDP Udp;
becomes
Code:
WiFiUDP Udp;

etc...
and if something doesn't work, post your complete code then we can take a look at it and quickly see any mistakes.
I would also suggest to always compile with verbose output. You can switch verbose output on in Arduino > Preferences 
15  Using Arduino / Networking, Protocols, and Devices / Re: Arduino WiFi Shield UDP Support on: April 15, 2013, 07:20:00 am
So this is the IP address you are getting back from the example sketch I posted here?
well... http://en.wikipedia.org/wiki/0.0.0.0 :-)

it seems your router is not giving you an IP.
Pages: [1] 2 3 ... 5