element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum pls how do i go about communicating with 2 arduinos with the use of the tx/rx pin.
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 17 replies
  • Subscribers 392 subscribers
  • Views 1659 views
  • Users 0 members are here
Related

pls how do i go about communicating with 2 arduinos with the use of the tx/rx pin.

Former Member
Former Member over 10 years ago

i have codes for pulse sensor, temp sensor, GPS  and i need the readings from the sensors and gps to be sent to the other arduino's LCD. i just dont know how to go about doing it and i was wondering if there is someone that could help guide me.

 

//sender

int inpin=A0;

int TEMP=0;

int heartratepin=A1;

int difference;

int newHeartReading = 0;

int lastHeartReading = 0;

int measurements[5] = {0,0,0,0,0};

int historySize = 5;

int recenttotal = 0;

int Index = 0;

boolean highChange = false;

int minimumdifference = 2;

int num[5];

int average=0;

 

 

// Heart rate timing

long lastHeartbeatTime = 0;

long debounceDelay = 150;       // the debounce time; increase if the output flickers

int currentHeartrate = 0;

int lastHeartrate = 0;

//Heart rate LED

//int ledState = LOW;

//long ledOnMillis = 0;

//long ledOnInterval = 50;

int slope = ((newHeartReading-lastHeartReading)/(debounceDelay-lastHeartrate));

 

 

 

 

 

 

// Debugging string

String debugOutput = "";

void setup() {

   // start serial port at 9600 bps:

   Serial.begin(9600);

    pinMode(heartratepin,INPUT);

   establishContact();

}

void establishContact() {

while (Serial.available() <= 0) {

      Serial.println("hello");   // send a starting message

      delay(300);

   }

}

void loop() {

   // read analog input, divide by 4 to make the range 0-255:

   int analogValue = analogRead(inpin);

   float millivolts = (analogValue/1024.0)*5000;

   float celsius = millivolts/10-50;

   Serial.println(analogValue);

   Serial.print(celsius);

   Serial.print("c");

   Serial.print((celsius*9)/5+32);

   Serial.print("F");

   newHeartReading = analogRead(heartratepin);

    //calculation

  difference = newHeartReading - lastHeartReading;

  lastHeartReading = newHeartReading;

 

  // Find new recent total

  recenttotal = recenttotal - measurements[Index] + difference;

  // replace indexed recent value

  measurements[Index] = difference;

   //index + 1 index = (index + 1) % historySize;

    for (int i=0; i<5; i=i+1){

               num[i]=0;        

   }

    

              if (Index>=5)

              Index=0;

              //calculating the average

              average=recenttotal/5;

              Serial.println(average);

              delay(10);

  if (recenttotal >= minimumdifference)

  {

    // possible heart rate check timing

    if (millis() - lastHeartbeatTime >= debounceDelay)   // whatever the reading is at, it's been there for longer

    // than the debounce delay, so take it as the actual current state:

 

 

    {

  // Heart rate

// digitalWrite(ledPin, HIGH);

  currentHeartrate = 60000 / (millis() - lastHeartbeatTime);

    lastHeartbeatTime = millis();

   Serial.println(newHeartReading);

      if (currentHeartrate <= 200)// && currentHeartrate > 20)

    { 

                 

                  Serial.print("Heart Rate =" + String(currentHeartrate) + "  ");

                  delay(10);

    }

            if (currentHeartrate <= 39 and currentHeartrate >= 0){

                

                  Serial.print("I Am Sick");

                }

                 delay(10);

          if (currentHeartrate<= 79 and currentHeartrate >= 70){

                

                  Serial.print("Night Mare");

                }

                delay(10);

            if (currentHeartrate <= 69 and currentHeartrate >= 40){

               

                  Serial.print("kid Is At Sleep");

          }

              delay(10);

              if (currentHeartrate <= 99 and currentHeartrate >= 80){

                 

                  Serial.print("Kid Is Resting");

             }

                delay(10);

                if (currentHeartrate <= 119 and currentHeartrate >= 100){

                

                  Serial.print("Kid Is Playing");

               }

             

                  if(currentHeartrate > 120){

                   

                    Serial.print(" The Kid Is Having ");

                    //lcd.setCursor(0,1);

                    //lcd.print(" A Heart Attack");

                }

  

  

 

 

   // print different formats:

   Serial.write(analogValue);  // Print the raw binary value

   Serial.print('\t');             // print a tab

   Serial.write(newHeartReading);  // Print the raw binary value

   Serial.print('\t');             // print a tab

 

}

  }

}

 

 

 

//receiver

#include <SPI.h>

#include <LiquidCrystal.h>

int heartratepin=A1;

int inpin=A0;

LiquidCrystal lcd(30,31,32,33,34,35);

void setup()

{

  lcd.begin(16,2);

  Serial.begin(9600);

}

void loop()

{

  if(Serial.available()>0)

  {

    int inByte=Serial.read();

    int analogValue=analogRead(inpin);

    lcd.print(analogValue);

    lcd.print(",");

   

    int newHeartReading=analogRead(heartratepin);

    lcd.print(newHeartReading);

    lcd.print(",");

   

   

 

 

  }

}

 

i dont know what i am doing wrong

  • Sign in to reply
  • Cancel

Top Replies

  • bobcroft
    bobcroft over 10 years ago in reply to Former Member +2
    Richard, in order to see the Easy Transfer library just Google Arduino Easy Transfer library. There are informative notes and code examples. To answer your other question, yes you can display the data…
  • clem57
    clem57 over 10 years ago +1
    ricardo240 I cannot comment on the sender code since it has many things going on. But here are the things I would do: Make sure the pins are connected as TX to RX on the UART on sender and UART on receiver…
  • clem57
    clem57 over 10 years ago in reply to Former Member +1
    To understand: 1) the sensors are reading fine. 2) The UNO sends on UART to the MEGA UART but does not work. What pins are connected on each to the other? 3) The code you sent looks like snippets especially…
Parents
  • bobcroft
    0 bobcroft over 10 years ago

    Richard,

                   I am not sure why you want to use two Arduinos if the purpose of the second one, the MEGA is to just run the LCD display.  An option which may be cheaper is to use a serial driven LCD, in fact I serial drive all my LCD's using the I2C interface.  There are loads of the I2C to LCD interfaces on EBAY.  If you use this method you could use the I2C pins on the Arduino even if you already have an I2C devices on these pins provided the address is different.

     

    If you want to carry on using two Arduinos then I highly recommend the Easy Transfer library for transferring data between the devices, in both directions if you wish.  The Easy Transfer library can use the software serial pins on the Uno and one set of the 4 normal serial pins on the Mega but not TX0 and RX0 because these are used with the USB for programming.

    I use the Easy Transfer library to send data wirelessly between various flavours of UNO's and Mega's using the Ciseco wireless modules.  These modules are incredibly reliable and extremely easy to use.

     

    I hope that helps

    Bob

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • bobcroft
    0 bobcroft over 10 years ago

    Richard,

                   I am not sure why you want to use two Arduinos if the purpose of the second one, the MEGA is to just run the LCD display.  An option which may be cheaper is to use a serial driven LCD, in fact I serial drive all my LCD's using the I2C interface.  There are loads of the I2C to LCD interfaces on EBAY.  If you use this method you could use the I2C pins on the Arduino even if you already have an I2C devices on these pins provided the address is different.

     

    If you want to carry on using two Arduinos then I highly recommend the Easy Transfer library for transferring data between the devices, in both directions if you wish.  The Easy Transfer library can use the software serial pins on the Uno and one set of the 4 normal serial pins on the Mega but not TX0 and RX0 because these are used with the USB for programming.

    I use the Easy Transfer library to send data wirelessly between various flavours of UNO's and Mega's using the Ciseco wireless modules.  These modules are incredibly reliable and extremely easy to use.

     

    I hope that helps

    Bob

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • Former Member
    0 Former Member over 10 years ago in reply to bobcroft

    pls can i see a sample of this easy transfer library that u are talking about so i can try it

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to bobcroft

    the thing is i need the info to show on the lcd so with the easy transfer library that u mensioned, would it still be possible to display the info on an lcd?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • bobcroft
    0 bobcroft over 10 years ago in reply to Former Member

    Richard,  in order to see the Easy Transfer library just Google Arduino Easy Transfer library.  There are informative notes and code examples.

     

    To answer your other question, yes you can display the data sent by Easy Transfer on an LCD.  In essence you set up matching structures on the UNO and the Mega.  The data that you place in the 'structure' on the UNO is sent to the MEGA's matching structure.  Then on the MEGA you process the data from the structure sending the data to the LCD.  The power of the library lies in the fact that a structure can contains data in any format, char, int, etc as well as arrays.  The sensor data can be sent in its native format and then have the format changed for display on the MEGA / LCD.

     

    There have been some very good replies to your queries and the approach mentioned by Neil to get each aspect of the code working is exactly what I do.  So in the case of, say, the Easy Transfer library try the given examples, get them working, then modify them to suit your need.  Once the modified version is working you can integrate it into your main project.

     

    The Easy Transfer library will initially look more involved than a simple serial send, however once mastered it is a powerful tool and very flexible.

     

    Bob

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube