arduino hangs while doing bridge.get

Hi all,

i have tried to connect arduino to linino with the bridge get/put but the arduino side hangs while doing get. It happens random and the linux side is not doing any job except for the standard preinstalled packages.

Here is my arduino sketch:

#include <SoftwareSerial.h>
#include <Bridge.h>

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

//vars
char buffer_flagcan[2] = "0";
char buffer_canmessage[45];
int k;
unsigned long timer;

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

void setup() {
  // settaggio dei pin IN/OUT per la seriale software
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  // settaggio pin LED
  pinMode(led, OUTPUT);
  
  mySerial.begin(57600); //inizializzazione della seriale Software
  Serial.begin(57600); //inizializzazione della seriale hardware 
  
  Bridge.begin(); //inizializzo la comunicazione con linux
  Bridge.put("flagcan","8"); //valorizzo il flagcan a 8
  
  timer = millis();
  
  digitalWrite(led, HIGH);   //lampeggio
  delay(1000);
  digitalWrite(led, LOW);
  delay(1000);
  digitalWrite(led, HIGH);   //lampeggio
  delay(1000);
  digitalWrite(led, LOW);
  
}

void loop() {

  if (millis() - timer > 500) {
    timer = millis();
    digitalWrite(led, HIGH);   //lampeggio
    delay(20);
    // leggo se c'è da spedire un msg can
    Bridge.get("flagcan", buffer_flagcan,2); 
    k = atoi(buffer_flagcan);
    if (k == 1) {
      //Serial.write(k);
      Bridge.get("canmessage",buffer_canmessage,45); 
      mySerial.print(buffer_canmessage); 
      k=0;
      Bridge.put("flagcan","0");
      Bridge.put("canmessage","");
    }
    digitalWrite(led, LOW);
  }
}

the board has a software serial connecting to another board (mySerial).

What happens is that if i run the sketch commenting the Bridge part everything works fine but when i insert th bridge code, i can see it working for some time (the led i blinking), maybe 10 seconds or 5 minutes but suddenly the led stay on.

On the linino side, bridge is called by the library for php.

Someone have any hint ?

Thank you
Ettore

Have you made tests that make you say it gets stuck at Bridge.get instead of mySerial.print?
I'm running your sketch (I've removed the mySerial stuff as I don't have your shield) and it's blinking fine.

Hi,

actually it seems you are right. I did not think about mySerial as it was only a print and i can not imagine why it hangs.
Anyway commenting it make the sketch working fine over time.

I will recompile my other board software to slow down serial speed to 9600 or 19200 from 57600 and i will try again.

As the other board is continuosly sending data over serial to the Arduino, i think that can be the problem. How is the serial software handled ? Is there a kind of interrupt in the library that can be the origin of the problem ?

Thank you for your help

Indeed SoftwareSerial uses interrupts http://arduino.cc/en/Reference/SoftwareSerial

I have tried downgrading the speed to 19200 with no luck. I have also reprogrammed the secondary board to send some data over the serial at 2 seconds interval (instead of 1 sec) but nothing changed.

Now, i created a fakeSerial software serial and changed in this way:

 if (millis() - timer > 500) {
    fakeSerial.listen();
    digitalWrite(led, HIGH);   //lampeggio
    timer = millis();
    // leggo se c'è da spedire un msg can
    Bridge.get("flagcan", buffer_flagcan,2); 
    k = atoi(buffer_flagcan);
    if (k == 1) {
      //Serial.write(k);
      delay(10);      
      Bridge.get("canmessage",buffer_canmessage,45); 
      delay(10);      
      mySerial.print(buffer_canmessage); 
      k=0;
      Bridge.put("flagcan","0");
      delay(10);      
      Bridge.put("canmessage","");
    }
    digitalWrite(led, LOW);
    mySerial.listen();
  }

it is 20 minutes now it is working without blocking......i will keep this thread updated!
Meantime if anybody have a possible explanation is of course welcome :slight_smile: