Go Down

Topic: serialEvent() on Yun (Read 577 times) previous topic - next topic

pakken

Hello friends!

I'm trying to get a ph sensor to work with the Yun. It works perfectly on the UNO, but I need it to run on the Yun because I have to publish the values on MQTT :)

The ph sensor is communicating through the the SoftwareSerial library, and I'm experiencing some strange problems when switching the wires from software RX(2) and software TX(3) pins on the UNO to the Yun. When trying to debug the serialEvent() I wrote a fast small program:

Code: [Select]
void setup() {
  Serial.begin(9600);

}

void serialEvent() {
char inchar = (char)Serial.read();
Serial.println(inchar);
}

void loop() {
  // put your main code here, to run repeatedly:
 
}


This works on the UNO as desired: when entering something in the serial and sending it, the char I write will be printed in the Serial monitor. Simple.
This test I did both in IDE 1.5.4 and 1.0.5 - in both cases UNO worked, but Yun didn't.

Is there any known issue on SoftwareSerial and Yun?

I read about that Yun is similar to Leonardo, which only support software serial on pin 8+. But I tried my sensor on those pins as well with no result, and anyways it shouldn't influence my little "test sketch"?

Hope you have some suggestions :)

Best, pakken!



raxpa

looks like the same problem  here

http://forum.arduino.cc/index.php?topic=203596.0

pakken

No. I'm aware that serial monitor doesn't work over WIFI - my problem occurs with a cable! Other Serial.prints works fine - it's the input that doesn't work in my case :)

noblepepper

The Serial object uses hardware serial so the sketch you posted has nothing to do with the software serial library.

The reference page for serialEvent() on hardware serial says it is not compatible with the Leonardo, perhaps this is why your sketch doesn't work?

pakken

You were right :)

Made a new one testing out the SoftwareSerial library:

Code: [Select]
#include <SoftwareSerial.h>

#define rxpin 8
#define txpin 9

SoftwareSerial phserial(rxpin, txpin);

void setup() {
 
  Serial.begin(9600);
  phserial.begin(9600);

}

void loop() {
 
  while(phserial.available()) {
   
      char inchar = (char)phserial.read();
      Serial.println(inchar);
     
  }
 
 
}


I have no idea why it worked now, because it looked alot like the one already running. The thing I did for a change pas underscores in the #define names and in the serial instance name - maybe that could help someone else :) But cool it works! Thanks for pointing out that serialEvent() was a stupid test case ;)

mamu

Now you are using Software Serial. Should work on Uno and Yun.

Go Up