access yun serial

Hello to everybody,

i was thinking to replace Yun bridge with my own code…

First of all, here is my scenario

| myBoard | – UART 57600 – pin 10,11 32u4 (SoftwareSerial) – | 32u4 | – Serial1 57600 – | Linux |

Actually, i have one custom made board that is streaming lot of data over a 57600 serial connected to the 32u4 configured with a software serial.
My sketch is simply bridging software serial with Serial1 byte per byte

#include <SoftwareSerial.h>
#include <avr/wdt.h>

#define rxPin 10
#define txPin 11
#define led 13

SoftwareSerial mySerial(rxPin, txPin); // RX, TX

void setup() {
  // settaggio dei pin IN/OUT per la seriale software
  pinMode(rxPin, INPUT_PULLUP);
  pinMode(txPin, OUTPUT);
  // settaggio pin LED
  pinMode(led, OUTPUT);

  mySerial.begin(57600); //inizializzazione della seriale Software
  Serial1.begin(57600);

  wdt_enable(WDTO_8S);
}
void loop() {
  if (mySerial.available()) {
    digitalWrite(led, HIGH);
    Serial1.write(mySerial.read());
    //Serial1.flush();
    digitalWrite(led, LOW);
  }

  if (Serial1.available()) {
    mySerial.write(Serial1.read());
  }
  // resetto il watchdog
  wdt_reset();
}

On Linux, i have disable console in /etc/inittab and run this:

stty -F /dev/ttyATH0 57600

and i read serial data coming with

screen /dev/ttyATH0 57600

Now strange things happen:

If i leave Serial1.flush uncommented, sketch freeze and watchdog reset it but as soon as sketch is working (for few seconds) data are coming in correctly.

If i comment flush command, i’m getting incorrect character:

000/09999/000/000/000/000/000/000/16/000|00000/08999/°16/00/00¯000/001/00000/0°°|00000/10999/000/0/000¯°°0/00000/1¶2/092000°00|00000/09999/00/000/000/00/00°/°00/0/000ü00000/08999/16/°0/00°/000/0/000/°00/00|00000/1099/000/000/0°1/000±6/092000/000|0000/0999900/0°°

(should be number, slashes or pipes)

I thought it was a speed problem but if i use Serial and not Serial1 i can see on the serial monitor all the correct data

I also know that original bridge function is running at 250000…

Do you have any idea ?

Thanks
Best Regards
Ettore

It seems to be something related to the baudrate.

By the way, why not connecting your board directly to the pin 0 and 1 (TX and RX) of the Yun?

Just put these pin of the Atmega as input so they don't interfere with the communication. In this way you don't need to use the 32u4 as serial bridge.

I wonder if the info about disabling the bridge in this Thread is relevant?

…R

Mistaken response and withdrawn. My bad. I create enough personal noise not to mention the embarrassment of public noise!

Hello,

i have tried to connect my board directly to the Atheros and it works perfectly......
unfortunately, the board was designed to oonnect to Arduino pins 10 and 11 so it is not easy to change the connection (board is already in production...and the idea to remove bridge is intended as a software improve).....

Do you think what can be wrong on the 32u4 ?

What is strange is that if i use Serial on the 32u4 on the pc i can read everything correct......

Thanks
Ettore

AFAIK when you use Serial on the PC it is accessing the 32u4 over the USB connection - like a Leonardo. Whereas the Linux side of the Yun connects to the 32u4 using Serial1 on the 32u4.

I don't understand what you mean about pins 10 and 11. They could never have been serial I/O pins unless you are using SoftwareSerial - and I don't know if that works on the 32u4.

I think it is time for you to explain WHAT you want to do rather than HOW you think it should be done.

...R

Robin2:
I don't understand what you mean about pins 10 and 11. They could never have been serial I/O pins unless you are using SoftwareSerial - and I don't know if that works on the 32u4.

Yes, he is using SoftwareSerial.

@ettore8: I think that the intensive use of SoftwareSerial together with the hardware serial causes synchronization problems. The SoftwareSerial has no dedicated hardware for the communication, so if the CPU is busy with a lot of interrupts (like the intensive use of the hardware serial) sync problems are likely to occur.

Angelo9999:
Yes, he is using SoftwareSerial.

OOPS … I missed that.

But that just leaves me more confused. Now I can’t make any sense of Reply #4

Looking back at the code in the original post I suggest that the OP should reduce the speed of SoftwareSerial and at least temporarily add a short delay at the end of loop().

…R

Hello,

yes i'm using software serial.....

Anyhow my problem was solved upgrading Arduino IDE from 1.5.6-r2 to 1.6.2

I have recompiled my sketch and now everything is working great....

I have tried to read changelog but i did not find any useful information related to SoftwareSerial.....

Thank you everybody

Ettore

ettore8:
I have tried to read changelog but i did not find any useful information related to SoftwareSerial.....

From the revisions list, listed under v 1.6.1:

I'm not sure what the actual changes are, but it looks like they changed something, apparently for the better.

Robin2:
But that just leaves me more confused. Now I can't make any sense of Reply #4

I assume you're talking about this:

ettore8:
i have tried to connect my board directly to the Atheros and it works perfectly......

Which I'm sure was in response to this:

Angelo9999:
By the way, why not connecting your board directly to the pin 0 and 1 (TX and RX) of the Yun?

Just put these pin of the Atmega as input so they don't interfere with the communication. In this way you don't need to use the 32u4 as serial bridge.

By not initializing the Serial1 class or the Bridge, and making pins 0 and 1 inputs, that makes the pins high impedance and essentially removes the '32U4 from the connection. He can now connect his external hardware to pins 0 and 1 and directly communicate with the Atheros processor.

A good, quick, and elegant test to see if the problem was being created by the '32U4 processor, and proved that was the issue was not with the Atheros processor, nor the external hardware.

ShapeShifter:
From the revisions list, listed under v 1.6.1:
I'm not sure what the actual changes are, but it looks like they changed something, apparently for the better.

I apologize....i missed that row!
I think that that improvement made things lot easier!

ettore8:
I apologize....i missed that row!

No need to apologize, there's a lot there and it's easy to miss. I actually had a hard time finding it at first, the only reason I went looking for it was because I remember a discussion about SoftwareSerial in the thread about the new IDE.