Is there an upper limit to Arduino (specifically, Leostick) D0/1 serial rx speed?

127 views
Skip to first unread message

AndrewMc

unread,
Apr 9, 2013, 9:27:27 AM4/9/13
to hackerspac...@googlegroups.com
Hiya

(BTW wasn't MakerFaire awesome?)

I am trying to use D0 / Serial1 to receive TTL serial data and relay it to my PC.
I have verified using a digital CRO that the data is 57600 baud 8n1, but all I get is garbage.

If I loopback D1 to D0 it works, but I dont think that really replicates 'reality'

Does anyone know if there is an upper limit to the RX speed on the TTL serial with Arduino? Does it deal well with small variations in clocking speeds?

thanks,
--Andrew

int led_green = 9;
int baud_device = 57600;
int baud_pc = 115200;

void setup() {
  Serial.begin(baud_pc);
  Serial.setTimeout(100);
  Serial1.begin(baud_device);
  Serial1.setTimeout(100);
  pinMode(led_red, OUTPUT);    
  pinMode(led_green, OUTPUT);    
  pinMode(led_blue, OUTPUT);    
  digitalWrite(led_blue, LOW);
  digitalWrite(led_green, LOW);
  digitalWrite(led_red, LOW);
}

const int blen = 32;
char buffer[blen+1];
int b = 0;
boolean enable_loopback_test = false;

void do_echo_loop() {
  if (enable_loopback_test) {
    if (Serial.available() > 0) {
      char c = Serial.read();
      digitalWrite(led_blue, HIGH);
      Serial1.print(c);
      digitalWrite(led_blue, LOW);
      return;
    }
  }

  int n = 0;
  n = Serial1.readBytesUntil( '\n', buffer, blen);
  if (n > 0) {
    digitalWrite(led_green, HIGH);
    buffer[n] = 0;
    Serial.print(n); Serial.print(": ");
    for (int i=0; i < n; i++) {
      Serial.print(buffer[i], HEX);
      Serial.print(" ");
    }
    Serial.println(buffer);   
  } else {
    digitalWrite(led_green, LOW);
  }
}

void loop() {
  do_echo_loop();
}

Thomas

unread,
Apr 9, 2013, 3:37:56 PM4/9/13
to hackerspac...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Andrew,

On 09/04/13 22:57, AndrewMc wrote:
> Hiya
>
> (BTW wasn't MakerFaire awesome?)

YES!

> I am trying to use D0 / Serial1 to receive TTL serial data and
> relay it to my PC. I have verified using a digital CRO that the
> data is 57600 baud 8n1, but all I get is garbage.
>
> If I loopback D1 to D0 it works, but I dont think that really
> replicates 'reality'
>
> Does anyone know if there is an upper limit to the RX speed on the
> TTL serial with Arduino? Does it deal well with small variations
> in clocking speeds?

Is Serial1 a soft-serial device or are you using somethiug like a mega
with multiple UARTs?

soft-serial devices don't have a hardware buffer. If you're not
reading when the data arrives you miss it.

Even the 'real' serial port uses an ISR to feed an internal buffer.
I hacked the wiring library once to increase the size of the buffer
and to add a callback; you could use something like that to send the data.

Also, 57600 and 115200 are reasonably quick, especially as the arduino
lacks any kind of HW handshaking.

Don't make your cables too long:
http://www.lammertbies.nl/comm/info/RS-232_specs.html#phys
We used to run data between 2 PCs over a 10m cable or so and had to
drop the baud rate below 57600.


Thomas

> thanks, --Andrew
>
> int led_green = 9; int baud_device = 57600; int baud_pc = 115200;
>
> void setup() { Serial.begin(baud_pc); Serial.setTimeout(100);
> Serial1.begin(baud_device); Serial1.setTimeout(100);
> pinMode(led_red, OUTPUT); pinMode(led_green, OUTPUT);
> pinMode(led_blue, OUTPUT); digitalWrite(led_blue, LOW);
> digitalWrite(led_green, LOW); digitalWrite(led_red, LOW); }
>
> const int blen = 32; char buffer[blen+1]; int b = 0; boolean
> enable_loopback_test = false;
>
> void do_echo_loop() { if (enable_loopback_test) { if
> (Serial.available() > 0) { char c = Serial.read();
> digitalWrite(led_blue, HIGH); Serial1.print(c);
> digitalWrite(led_blue, LOW); return; } }
>
> int n = 0; n = Serial1.readBytesUntil( '\n', buffer, blen); if (n
> > 0) { digitalWrite(led_green, HIGH); buffer[n] = 0;
> Serial.print(n); Serial.print(": "); for (int i=0; i < n; i++) {
> Serial.print(buffer[i], HEX); Serial.print(" "); }
> Serial.println(buffer); } else { digitalWrite(led_green, LOW); } }
>
> void loop() { do_echo_loop(); }
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJRZG4RAAoJEHqA0UHc+pSDORwP/ipkFAxh5bP9nXe6RUl7Fnpn
kuHiEF59mGuzycijx4hWDUjiVMYwDC4Y9TSbi+jMmIhF7CYv5z6en77BSmWG223c
mJ81TIJpINEv2BbQMFAxPSqHUOXNXfL/3D5eUE5YA+wrkAijUyYF4BRNaqnUG14E
HXTkUsbIuG673jh4e/5oeYQy27yKmpa6kaexX5p2B8qcPN/7a4POKGaY5JUfG+TO
X3Jkh2tlQbhlko35lHovd9cjmbLhJRDVkuEJT32sRSUaLoQgM1JfjltWOIKI/Tvr
hS0Vf8ZJAbct9QfDWiyF2FgYwbIeEL1QdzTnqZXN1460rdY9HnOWV4laD2FprS/G
BkR7c8aM1+gJQDdkL1DnwdxOGjp+ca7gsimV4n0m9cOM5mpkGbVwUPC+Z+sFh6Xs
k949t3VBAQVURsqM1yGzN4C5On3aVMxjaFeeQJuPdwIl1jG9OwzWx4Vxn6N4tKz1
BAGGI4QPMKjGP/jmSxljYafKrRhEpk8+XS5Jc9Xl2sDkOq8CbA1KczvvIcLnqtvb
b2oB8+9OOhtK+LVupFZgK9NZK63p1UlTR7OFz9v0FL2U2rnmH7/qREj3z/CoRa0R
JNC67AKZXR+D1wAMZb9qrTdJCOpO81a43dIYFHDoGkVUdZQIVleYnpB81xyRZT3z
6TPEHwKxRLqFMZaLAC9W
=7pVk
-----END PGP SIGNATURE-----

Kim Hawtin

unread,
Apr 9, 2013, 8:04:13 PM4/9/13
to hackerspac...@googlegroups.com
> I am trying to use D0 / Serial1 to receive TTL serial data and
> relay it to my PC. I have verified using a digital CRO that the
> data is 57600 baud 8n1, but all I get is garbage.
 
Don't make your cables too long:

I've also had to add decent shielding on higher speed serial runs.
only terminate the shield on one end, say the peecee instead of the arduino.

i've had interesting effects terminating the other way around, due to induced RF.
try to make the cables not a quarter or half wave length on FM broadcast radio bands ;)

also pays to use those clip on ferrites ;)

cheers,

kim

Steve Roehrs

unread,
Apr 9, 2013, 8:56:26 PM4/9/13
to hackerspac...@googlegroups.com
MAX485 chips are cheap on ebay too, if you want to go differential mode for your cables you can get up to 1Mbps over twisted pair, which is surely faster than the arduino can support.
 
I've got some spare here if you want to try some, I bought a rail of them off ebay.
 
Steve

--
You received this message because you are subscribed to the Google Groups "HackerSpace - Adelaide, South Australia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hackerspace-adel...@googlegroups.com.
To post to this group, send email to hackerspac...@googlegroups.com.
Visit this group at http://groups.google.com/group/hackerspace-adelaide?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Mark Jessop

unread,
Apr 9, 2013, 9:14:33 PM4/9/13
to hackerspac...@googlegroups.com
I thought the arduino nanos in the lantern were using some crazy >1mbit uart speed? The signal wouldn't have to go far though, just from the FTDI chip on the pcbs to the AVR.

- Mark

Thomas Sprinkmeier

unread,
Apr 9, 2013, 10:49:22 PM4/9/13
to hackerspac...@googlegroups.com
On 10 April 2013 10:44, Mark Jessop <lennieth...@gmail.com> wrote:
I thought the arduino nanos in the lantern were using some crazy >1mbit uart speed? The signal wouldn't have to go far though, just from the FTDI chip on the pcbs to the AVR.


Are they RS232, SPI or I2C?

I've used I2C, it's multi-drop and the spec is for 400kbps in 'fast' mode, seems ideal for something like the lantern.


Thomas

Damien P

unread,
Apr 10, 2013, 7:13:41 AM4/10/13
to hackerspac...@googlegroups.com
On Tuesday, April 9, 2013 10:57:27 PM UTC+9:30, AndrewMc wrote:
(BTW wasn't MakerFaire awesome?)

Sure was... I'm still surprised how many people were there!

I am trying to use D0 / Serial1 to receive TTL serial data and relay it to my PC.

If that's all you're doing, there are adapters for a few bucks on Ebay which do that.
 
I have verified using a digital CRO that the data is 57600 baud 8n1, but all I get is garbage.


Where are you seeing this? At the computer?  Is it random junk, or are you only seeing parts of what you expect (ie. "Attack at dawn" comes out as "Atc t an")?
 
Does anyone know if there is an upper limit to the RX speed on the TTL serial with Arduino?

The hardware UART on these pins (aka "Serial1" on a Leonardo, apparently) will happily run at 2Mbps, if your software can keep up.  It has a 1 byte buffer though, so it's easy to drop data.
 
Does it deal well with small variations in clocking speeds?

If the board uses a crystal, that should be fine.  Have a look at the AVR datasheet about the UART speeds - there's a few pages of tables about the allowed error.

Damien P

unread,
Apr 10, 2013, 7:16:26 AM4/10/13
to hackerspac...@googlegroups.com
On Wednesday, April 10, 2013 12:19:22 PM UTC+9:30, thomas wrote:
I've used I2C, it's multi-drop and the spec is for 400kbps in 'fast' mode, seems ideal for something like the lantern.

I tried that, but had problems running an open-collector protocol like I2C over a long wire (~3 metres), because line capacitance becomes a problem.  See the wiki page about the lantern.  Also 400kbps is a bit slow.

AndrewMc

unread,
Apr 10, 2013, 9:02:15 AM4/10/13
to hackerspac...@googlegroups.com
Thanks for all the input everyone !

This was RS232 @ TTL level, on the console port of a router.  The output was true random junk, not just odd characters.

Shielding and cable length are desirable in a proper project, this was a hack / experiment because I had no spare TTL / USB adaptor and am waiting for a couple more in the post :-)  and I really wanted  to push on with my real project.  I do know it should work on 9600 baud at least!

I _think_ that D0 on the Leostick is using a hardware serial, I didnt find out for sure; I tried to make SoftwareSerial work on a different set of pins but it didnt compile on the leostick and when I hacked in changes from Leonardo to make it compile I got nothing...
Going by what @DamienP says it should have kept up, the program is doing nothing other than relaying it

In the end I found a max232 in the shed and did it direct to the PC - see attached birdnest photo :-)  The leostick now is serving solely to provide +5V!
The excess capacitors are because I had no 1uF so I had to run2x 2.2uF in serial.  This actually worked!



What I am wondering now about the Leostick is whether it is a speed accuracy is an issue on certain baud rates.

I found the following site whilst trying to sort this out:

http://www.wormfood.net/avrbaudcalc.php

I used to be all across this serial stuff many years ago but am rusty now, but I think, if there is a stream of characters which are close together, a small error in frequency can lead to corruption, whereas single characters may be OK.  And 2% error on 57600 gives nearly 58800?

--Andrew


Reply all
Reply to author
Forward
0 new messages