Pages: [1]   Go Down
Author Topic: Is there an easy way to communicate 2 Arduino?  (Read 334 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm just a student and new to Arduino  smiley-razz. I have a project that  involves communication of 2 Arduino. I have found several tutorials but neither of them involves sending analog values(0-1023). The scenario is this, Arduino A is connected to a potentiometer while Arduino B is connected to a 16x2 LCD. is their a way to display the value of the potentiometer from Arduino A to the LCD of Arduino B? And if it is possible, can it still be used as an integer?
Logged

BCC AZ USA
Offline Offline
God Member
*****
Karma: 21
Posts: 929
It gets hot so it must be working
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure it's possible.  You could do it with serial, I2C or SPI.  There are lots of exmples showing how to do this.
Logged

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

I've seen a softserial tutorial and followed it but it didn't work.

Here's the code for Arduino A
Code:
#include <SoftwareSerial.h>

SoftwareSerial Arduino(2,3); //rx/tx
int i;
int value;
int potpin = A0;
char reader[10];

void setup(){
  Arduino.begin(9600);
}

void loop(){

  value = analogRead(potpin);
  Arduino.print(value);
}

Arduino B
Code:
#include <SoftwareSerial.h>
SoftwareSerial Arduino(2,3); //rx/tx
int i;
char reader[4];

void setup(){
  Arduino.begin(9600);
  Serial.begin(9600);
}

void loop(){
  if(Arduino.available()>1){
    for(i=0; i<3; i++){
      reader[i] = Arduino.read();
      delay(2);
    }
  }

  Serial.print(reader[0]);
  Serial.print(reader[1]);
  Serial.print(reader[2]);
  Serial.println(reader[3]);

 
  for(i=0;i<3;i++)
  reader[i] = 0;

}

Sorry for the bad program smiley-razz.
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 89
Posts: 3457
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In what way did it not work ?
Can you describe how you wired the 2 Arduinos together, which pin to which pin ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Sr. Member
****
Karma: 9
Posts: 254
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if(Arduino.available()>1){
    for(i=0; i<3; i++){
      reader[i] = Arduino.read();
      delay(2);
    }
  }
You only check if more than 1 character is available, then try and read 3 characters, just read as many characters as are available.
Logged

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

Okay, this time It worked! I replaced the potentiometer with a new one. But when i hooked-up my 16x2 LCD it won't display numbers instead it shows steady scribble-like characters.

I just changed the Serial.prints into:
Code:
  lcd.setCursor(0,0);
  lcd.print(reader[0]);
  lcd.print(reader[1]);
  lcd.print(reader[2]);
  lcd.print(reader[3]);
Logged

Offline Offline
Sr. Member
****
Karma: 9
Posts: 254
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did the Serial.print work properly?
Have you tried printing to the lcd on its own?
Break your program down into each individual component and test it. That's how to debug smiley
Logged

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11154
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

when i hooked-up my 16x2 LCD it won't display numbers instead it shows steady scribble-like characters.

If you send it garbage, it's going to display garbage.

If you want it to display a text message, construct the text message and then print it to the display. The sprintf() function is a convenient way to format data values into a text message, if that's what you're trying to do.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

0
Offline Offline
Tesla Member
***
Karma: 114
Posts: 8911
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Simple test code for sending text from one arduino to another. the code should work on both arduino A and B. Connect the two arduino grounds together, and connect the arduino A tx pin to the arduino B rx pin. Send text with an ending comma , in arduino A serial monitor and it should appear in the both the arduino A and arduino B serial monitors. If that works, setting up a pot on arduino A should be fairly easy.

Code:
//zoomkat 3-5-12 simple delimited ',' string parce
//from serial port input (via serial monitor)
//and print result out serial port
// CR/LF could also be a delimiter

String readString;

void setup() {
  Serial.begin(9600);
  Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}

void loop() {

  //expect a string like wer,qwe rty,123 456,hyre kjhg,
  //or like hello world,who are you?,bye!,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        Serial.print(readString); //prints string to serial port out
        Serial.println(','); //prints delimiting ","
        //do stuff with the captured readString
        readString=""; //clears variable for new input
      }
    } 
    else {     
      readString += c; //makes the string readString
    }
  }
}

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Full Member
***
Karma: 2
Posts: 145
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What library are you using for the LCD ?
Logged

Pages: [1]   Go Up
Jump to: