Go Down

Topic: [Solved] Sending Serial Data between Esplora and Uno (Read 2255 times) previous topic - next topic

chummer1010

Jul 02, 2016, 03:24 pm Last Edit: Jul 03, 2016, 03:42 pm by chummer1010
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:

Code: [Select]

#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) :

Code: [Select]

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

#include <signature.h>

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
Two or three hours spent thinking and reading documentation solves most programming problems.

groundFungus


sterretje

#3
Jul 02, 2016, 05:42 pm Last Edit: Jul 02, 2016, 05:46 pm by sterretje
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?


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)..
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Robin2

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
Two or three hours spent thinking and reading documentation solves most programming problems.

chummer1010

#5
Jul 02, 2016, 09:57 pm Last Edit: Jul 02, 2016, 09:59 pm by chummer1010
Esplora pinouts-



I tried this:

Esplora:
Code: [Select]

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

Code: [Select]

#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.
#include <signature.h>

jbellavance

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
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

chummer1010

Thanks for the tip, but yes D8 connected to Uno's D3 and D1 is connected to Uno's D2. Still no luck however.
#include <signature.h>

jbellavance

Hi,

Everything looks fine to me.

Could you try with pins D14 and D15 on the Esplora?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

chummer1010

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:

Code: [Select]

#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?
#include <signature.h>

runaway_pancake

With the following sketch, I can confirm that I have data out on "D1" --
Code: [Select]

#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
"Who is like unto the beast? who is able to make war with him?"
When all else fails, check your wiring!

chummer1010

#11
Jul 03, 2016, 01:43 am Last Edit: Jul 03, 2016, 01:51 am by chummer1010
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)
#include <signature.h>

runaway_pancake

You're connecting Esplora D1 to Uno D2, and Esplora Gnd to Uno Gnd ?
"Who is like unto the beast? who is able to make war with him?"
When all else fails, check your wiring!

chummer1010

#include <signature.h>

runaway_pancake

#14
Jul 03, 2016, 02:23 am Last Edit: Jul 03, 2016, 02:24 am by Runaway Pancake Reason: specify 'for Uno'
Can we try another sketch (for the Uno)?
Code: [Select]

//  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 ).
"Who is like unto the beast? who is able to make war with him?"
When all else fails, check your wiring!

Go Up