Arduino Forum

Using Arduino => Programming Questions => Topic started by: chummer1010 on Jul 02, 2016, 03:24 pm

Title: [Solved] Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 02, 2016, 03:24 pm
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 (http://forum.arduino.cc/index.php?topic=396450)) :

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

Title: Re: Sending Serial Data between Esplora and Uno
Post by: Robin2 on Jul 02, 2016, 03:34 pm
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
Title: Re: Sending Serial Data between Esplora and Uno
Post by: groundFungus on Jul 02, 2016, 03:36 pm
Grounds must be connected.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: sterretje on Jul 02, 2016, 05:42 pm
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)..
Title: Re: Sending Serial Data between Esplora and Uno
Post by: Robin2 on Jul 02, 2016, 07:02 pm
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
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 02, 2016, 09:57 pm
Esplora pinouts-

(https://3.bp.blogspot.com/-FUB5sgEM9h4/UPrYdnd3BvI/AAAAAAAAAQ4/qUT9V3gdoxU/s1600/EsploraPinsRevB.jpg)

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 (https://github.com/TheKitty/EsploraSerial) page as a reference also, I thought I would share.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: jbellavance on Jul 02, 2016, 11:22 pm
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
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 02, 2016, 11:31 pm
Thanks for the tip, but yes D8 connected to Uno's D3 and D1 is connected to Uno's D2. Still no luck however.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: jbellavance on Jul 02, 2016, 11:57 pm
Hi,

Everything looks fine to me.

Could you try with pins D14 and D15 on the Esplora?
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 03, 2016, 12:46 am
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?
Title: Re: Sending Serial Data between Esplora and Uno
Post by: runaway_pancake on Jul 03, 2016, 01:35 am
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
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 03, 2016, 01:43 am
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)
Title: Re: Sending Serial Data between Esplora and Uno
Post by: runaway_pancake on Jul 03, 2016, 01:53 am
You're connecting Esplora D1 to Uno D2, and Esplora Gnd to Uno Gnd ?
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 03, 2016, 01:56 am
You're connecting Esplora D1 to Uno D2, and Esplora Gnd to Uno Gnd ?
Yes.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: runaway_pancake on Jul 03, 2016, 02:23 am
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 ).
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 03, 2016, 02:38 am
No luck. I tried this with and without a resistor.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: runaway_pancake on Jul 03, 2016, 03:00 am
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.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 03, 2016, 03:05 am
The LED won't turn on at all for me. Completely unresponsive..
Title: Re: Sending Serial Data between Esplora and Uno
Post by: runaway_pancake on Jul 03, 2016, 03:10 am
It turns off after about 20 sec, but the Esplora is not transmitting that whole time.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: runaway_pancake on Jul 03, 2016, 03:11 am
Maybe one Esplora button push sends more than one 'U' and the Uno buffer is getting stuffed.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 03, 2016, 03:17 am
Maybe one Esplora button push sends more than one 'U' and the Uno buffer is getting stuffed.

This could be! When I tested if the buttons were being read in reply 9 (http://forum.arduino.cc/index.php?topic=410482.msg2824837#msg2824837), the letter would be printed countless times from a quick tap of the button.

How could I solve this? Perhaps a small delay() just for testing purposes right now?
Title: Re: Sending Serial Data between Esplora and Uno
Post by: runaway_pancake on Jul 03, 2016, 03:18 am
HA!
That's it!

If I change the Esplora code thus:
Code: [Select]

  if (Esplora.readButton(SWITCH_UP)==LOW)
  {
    //confirmation();
    Dataline.println("U");
    delay(5000);  //  "debounce"
  }


effecting a crude "debounce" (by bludgeon)
then the Uno behaves as expected.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: runaway_pancake on Jul 03, 2016, 03:19 am
The superior method would be to run the Esplora buttons inside the "state machine" paradigm.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: runaway_pancake on Jul 03, 2016, 03:22 am
Just now, I increased the series resistor to 20k and it's still good (better).
Definitely required.

> > > I know that you're doing this as a test, proof of concept, till you get your XBee together.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 03, 2016, 03:25 am
It still doesn't work for me... WTH?

edit: let me try what you said in post 22 and 23
Title: Re: Sending Serial Data between Esplora and Uno
Post by: runaway_pancake on Jul 03, 2016, 03:33 am
Use 'chummerremote', for the Esplora, and 'chummerrx', for the Uno - the sketches that I posted.
(The picture attached shows that I'm working this with you, not that you doubt me,)

> > > Adding my .INOs
Title: Re: Sending Serial Data between Esplora and Uno
Post by: runaway_pancake on Jul 03, 2016, 03:40 am
In chummerrx (for the Uno), I changed the Dataline pins to 15,16 (A1 and A2) - using A1 was more convenient for me.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 03, 2016, 03:47 am
I really appreciate your help, I'm just baffled that I can't manage to get this to work.. I tried everything in post 25 with no success..
Title: Re: Sending Serial Data between Esplora and Uno
Post by: runaway_pancake on Jul 03, 2016, 03:54 am
? ? ?
Attaching a wiring diagram.
Confirm the serial out from the Esplora (as previously described), no connections to anything but the LED/resistor.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 03, 2016, 04:02 am
My setup looks just like the diagram. I'll go as far as taking a video of me uploading both codes and me pressing the buttons. This is probably a dumb mistake I'm not seeing that I'm wasting your time with.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: runaway_pancake on Jul 03, 2016, 04:08 am
If you're using my INOs, unmodified, then it's the wiring.
Please confirm that you've verified the serial out of the Esplora with the LED test.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 03, 2016, 04:15 am
If you're using my INOs, unmodified, then it's the wiring.
Please confirm that you've verified the serial out of the Esplora with the LED test.
yes, it passes the LED test.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: runaway_pancake on Jul 03, 2016, 04:19 am
Well, I'll wait for your pics, or video, so long as things can be scrutinized.
If you need a youtube, I can manage that, too.  ( I don't have a tripod or a cameraman though. )
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 03, 2016, 04:28 am
Thank you so much for helping me to this point... I have a video uploading now.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: runaway_pancake on Jul 03, 2016, 04:34 am
I was wondering why my Uno 'L' LED was so dim.
It's because there's a mistake in the pinMode (chummerrx) - it should be pinMode(Lpin,OUTPUT);
(I wrote LOW instead of OUTPUT - it's much better with 'OUTPUT'!)
:smiley-mr-green:
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 03, 2016, 04:36 am
I made that change, still no luck. I made a video, this is before the change - https://youtu.be/hnazgOnk0wg (https://youtu.be/hnazgOnk0wg)
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 03, 2016, 04:39 am
I'll upload a clearer photo as well. One moment
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 03, 2016, 04:55 am
(http://i.imgur.com/cwDxpPa.jpg)

(http://i.imgur.com/eE7a4J7.jpg)
Title: Re: Sending Serial Data between Esplora and Uno
Post by: runaway_pancake on Jul 03, 2016, 05:07 am
Your resistor is brown-black-yellow looks like?
If so, that is 100k.  Might be too much.
Brown-black-orange is 10k, red-red-orange is 22k.

> > > (Yellow LED with no resistor - unrelated, but stop that.)
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 03, 2016, 05:13 am
My resistor is brown, black, orange ; it's a 10k resistor, just poor lighting

>>> regarding the led, sorry, bad habit, it's just convenient
Title: Re: Sending Serial Data between Esplora and Uno
Post by: runaway_pancake on Jul 03, 2016, 05:53 am
OK, it may make no difference, but could you try it with A1 (in case anything "happened" to D3)?

> > > Hoping your jumper-dudes there are solid. I'm uploading an "unlisted" to youtube, very slow.
Title: Re: Sending Serial Data between Esplora and Uno
Post by: chummer1010 on Jul 03, 2016, 03:10 pm
My LED was not wired correctly  :-[

Solutions on reply 21 (http://forum.arduino.cc/index.php?topic=410482.msg2824911#msg2824911)  and 25 (http://forum.arduino.cc/index.php?topic=410482.msg2824919#msg2824919).
Title: Re: [Solved] Sending Serial Data between Esplora and Uno
Post by: nicolopadovandev on Jan 13, 2019, 01:01 pm
Hi. I followed the whole thread but I'm not having results... I uploaded the files chummerx and chummerremote, connected the Esplora's TXD1 to a resistor (Brown, black, red, yellow) and then the resistor to the 3~ pin on the UNO. Then I connected a led to the 13 pin and a resistor to the ground, and the grounds of the arduinos together