Pages: [1]   Go Down
Author Topic: serialEvent() on Yun  (Read 548 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley

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:
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 smiley

Best, pakken!


Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

looks like the same problem  here

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

Offline Offline
Newbie
*
Karma: 0
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
Logged

Nashville Tennessee, USA
Offline Offline
Sr. Member
****
Karma: 15
Posts: 370
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You were right smiley

Made a new one testing out the SoftwareSerial library:

Code:
#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 smiley But cool it works! Thanks for pointing out that serialEvent() was a stupid test case smiley-wink
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 226
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: