[Solved] Sending Serial Data between Esplora and Uno

Hey all,

I'm working on serial communication between two arduinos and I am having a bit of trouble... What the code should do is when a button on the Esplora is pressed, it sends a character to the Uno and gets printed on the Serial monitor. However, this does not happen.

As for connections, I have Esplora D0 connected to Arduino D1, and Esplora D1 to Arduino D0. I also tried connecting the GND pins, even though I'm not sure this step was necessary.

Here is my code:

Esplora:

#include <Esplora.h>

void setup() {

  Serial.begin(9600);
  
  while (!Serial) {

    ;
    
  }

  Serial1.begin(9600);
  
}

void loop() {

  int upButton = Esplora.readButton(SWITCH_UP);
  int downButton = Esplora.readButton(SWITCH_DOWN);
  int leftButton = Esplora.readButton(SWITCH_LEFT);
  int rightButton = Esplora.readButton(SWITCH_RIGHT);

  if (upButton == LOW) {

    Serial1.print("U");
    
  }

  else if (downButton == LOW) {

    Serial1.print("D");
    
  }

  else if (leftButton == LOW) {

    Serial1.print("L");
    
  }

  else if (rightButton == LOW) {

    Serial1.print("R");
    
  }

  
}

Uno (From Serial Input Basics) :

char receivedChar;
boolean newData = false;

void setup() {

  Serial.begin(9600);
  Serial.println("<Arduino is ready>");

}

void loop() {

  recvOneChar();
  showNewData();
}

void recvOneChar() {

  if (Serial.available() > 0) {

    receivedChar = Serial.read();
    newData = true;

  }
}

void showNewData() {

  if (newData == true) {

    Serial.print("This just in ... ");
    Serial.println(receivedChar);
    newData = false;

  }
}

Any guidance would be greatly appreciated. Hopefully this isn't something embarrassingly dumb that I'm overlooking. Thanks!

Marco

If you are connecting the Esplora to Pins 0 and 1 on the Uno how do you expect to see the data on the Serial Monitor? Pins 0 and 1 are used for communicating with the PC.

You need to use SoftwareSerial to create another serial port on the Uno for communication with the Esplora.

...R

Grounds must be connected.

Not familiar with Esplora. Looking at your code you have two serial ports on it and you send via Serial1. Are those indeed D0/D1 or are there other pins that you need to use?

Robin2:
If you are connecting the Esplora to Pins 0 and 1 on the Uno how do you expect to see the data on the Serial Monitor? Pins 0 and 1 are used for communicating with the PC.

You need to use SoftwareSerial to create another serial port on the Uno for communication with the Esplora.

...R

Not quite true. Load TX code in Arduino 1, load the RX code in Arduino 2.

Connect RX and TX and vice versa (as OP did); a ground is required but if both are powered from PC, the ground is achieved via the USB cable.

It might be advisable to add 220 Ohm resistors in series for each wire.

It does work in OP's scenario; tested with 2 Unos (without using 220 Ohm resistors)..

sterretje:
Not quite true. Load TX code in Arduino 1, load the RX code in Arduino 2.

I think it keep things simpler to plan for bi-directional comms. When that works the OP can refine his system as required.

...R

Esplora pinouts-

I tried this:

Esplora:

#include <Esplora.h>
#include <SoftwareSerial.h>

SoftwareSerial Dataline(8, 1);

void setup() {

  Serial.begin(9600);
  
  while (!Serial) {

    ;
    
  }

  Dataline.begin(9600);
  
}

void loop() {

  int upButton = Esplora.readButton(SWITCH_UP);
  int downButton = Esplora.readButton(SWITCH_DOWN);
  int leftButton = Esplora.readButton(SWITCH_LEFT);
  int rightButton = Esplora.readButton(SWITCH_RIGHT);

  if (upButton == LOW) {

    Dataline.print("U");
    
  }

  else if (downButton == LOW) {

    Dataline.print("D");
    
  }

  else if (leftButton == LOW) {

    Dataline.print("L");
    
  }

  else if (rightButton == LOW) {

    Dataline.print("R");
    
  }

  
}

Uno:

#include <SoftwareSerial.h>

SoftwareSerial Dataline(2, 3);

char receivedChar;
boolean newData = false;

void setup() {

  Serial.begin(9600);
  Serial.println("<Arduino is ready>");

  Dataline.begin(9600);

}

void loop() {

  recvOneChar();
  showNewData();
  
}

void recvOneChar() {

  if (Dataline.available() > 0) {

    receivedChar = Dataline.read();
    newData = true;

  }
}

void showNewData() {

  if (newData == true) {

    Serial.print("This just in ... ");
    Serial.println(receivedChar);
    newData = false;

  }
}

But still no luck. I'm using this page as a reference also, I thought I would share.

Hi,

Do you have Esplora's pin D8 connected to the uno's pin D3 and
Esplora's pin D1 connected to uno's pin D2?

SoftwareSerial's constructor's arguments are RX and TX : SoftwareSerial Dataline(RX,TX);
RX is for Recieve and TX is for Transmit

So : The TX (transmit) of Esplora should be connected to RX (recieve) of Uno (and vice versa)

Hope this helps

Thanks for the tip, but yes D8 connected to Uno's D3 and D1 is connected to Uno's D2. Still no luck however.

Hi,

Everything looks fine to me.

Could you try with pins D14 and D15 on the Esplora?

Good idea, still no luck though.

I ran a test to see if the code for reading buttons was correct. I disconnected all of the wires and did this:

#include <Esplora.h>

void setup() {

  Serial.begin(9600);

  while (!Serial) {

    ;

  }

}

void loop() {

  int upButton = Esplora.readButton(SWITCH_UP);
  int downButton = Esplora.readButton(SWITCH_DOWN);
  int leftButton = Esplora.readButton(SWITCH_LEFT);
  int rightButton = Esplora.readButton(SWITCH_RIGHT);


  if (upButton == LOW) {

    Serial.println("U");

  }

  else if (downButton == LOW) {

    Serial.println("D");

  }

  else if (leftButton == LOW) {

    Serial.println("L");

  }

  else if (rightButton == LOW) {

    Serial.println("R");

  }


}

And had the data printed to the Esplora's Serial Monitor. That seemed to work just fine. So what am I doing wrong in sending the data to the Uno?

With the following sketch, I can confirm that I have data out on "D1" --

#include <Esplora.h>
#include <SoftwareSerial.h>
SoftwareSerial Dataline(8,1);  // rx, tx
byte Lpin = 13;
void setup() 
{
  //Serial.begin(9600);
  //while (!Serial) 
  //{
  //  ; 
  //}
  //pinMode(Lpin,OUTPUT);
  Dataline.begin(9600);
  digitalWrite(Lpin,LOW);
}
void loop() 
{
  if (Esplora.readButton(SWITCH_UP)==LOW)
  {
    //confirmation();
    Dataline.print("U");
  }
  else if (Esplora.readButton(SWITCH_DOWN)==LOW)
  {
    //confirmation();
    Dataline.print("D");
  }
  else if (Esplora.readButton(SWITCH_LEFT)==LOW)
  {
    //confirmation();
    Dataline.print("L"); 
  }
  else if (Esplora.readButton(SWITCH_RIGHT)==LOW)
  {
    //confirmation();
    Dataline.print("R");
  } 
}

//void confirmation ()
//{
  //digitalWrite(Lpin,HIGH);
  //delay(1000);
  //digitalWrite(Lpin,LOW);
//}

(Used an LED and resistor in series between +5 and 'D1'.)
+5-----A_K----2K----D1

Thanks for thinking this, that takes away a possibility of the problem.. So that means it must be an issue on the receiving end of the code? (not saying that there is something wrong with Robin2's code, but that I'm applying it incorrectly)

You're connecting Esplora D1 to Uno D2, and Esplora Gnd to Uno Gnd ?

Yes.

Can we try another sketch (for the Uno)?

//  chummerRX
//
#include <SoftwareSerial.h>
SoftwareSerial Dataline(2, 3);
byte incoming;
byte Lpin = 13;
void setup ()
{
  Dataline.begin(9600);
  pinMode(Lpin,LOW);
}

void loop ()
{
  if (Dataline.available() > 0)
  {
    incoming = Dataline.read();
    if(incoming == 85)   // ascii for 'U'
    {
      digitalWrite(Lpin,HIGH);
      delay(1000);
      digitalWrite(Lpin,LOW);
    }
  }
}

I think it might be a good idea to have a little resistance between Esplora data out and Uno data in ( >= 100ohms ).

No luck. I tried this with and without a resistor.

Definitely have that resistor, a 1K, in there to keep the Esplora from "powering" the Uno when the Uno is unpowered.
I get Uno 'L' to turn on with an Esplora UP - but it won't turn off.

The LED won't turn on at all for me. Completely unresponsive..

It turns off after about 20 sec, but the Esplora is not transmitting that whole time.

Maybe one Esplora button push sends more than one 'U' and the Uno buffer is getting stuffed.