Go Down

Topic: Wireless Proto to Wireless Proto Communication Issue (Read 461 times) previous topic - next topic

Paulito240

I've got two Arduino Unos with two wireless protos and two xbee S1s and I would like to have a pot sent from one arduino to the other wirelessly.  On the sender arduino it outputs to the serial monitor nicely, but the receiver serial monitor is spiting out random numbers and I can't quite figure out why.  Am I not formatting the data correctly?  Syntax problem? or baud rate problem?

Here is my code:

Sender Arduino
Code: [Select]
#include <SoftwareSerial.h>

const int analogInPin = A0;           // Analog input pin that the potentiometer is attached to
const int analogInPin2 = A1;           // Analog input pin that the potentiometer is attached to

int sensorValue = 0;        // value read from the pot
int sensorValue2 = 0;       // value read from the pot

int outputValue = 0;
int outputValue2 = 0;

void setup() {

  Serial.begin(9600);
  delay(500);
}

void loop() {
 
  sensorValue = analogRead(analogInPin);             // read the analog in value:
  sensorValue2 = analogRead(analogInPin2);             // read the analog in value:
  outputValue = map(sensorValue, 0, 1023, 0, 255);   // map it to the range of the analog out: 
  outputValue2 = map(sensorValue2, 0, 1023, 0, 255);   // map it to the range of the analog out: 
 

      Serial.println(outputValue);

  delay(50);                     
}


Receiver Arduino
Code: [Select]
int GotInt = 0;

void setup ()
{
     Serial.begin(9600);
     delay(500);
}

void loop()
{
while(Serial.available() > 0)
     {
       GotInt = Serial.read();
       Serial. println(GotInt);
     }
}


The sender serial monitor is currently showing: repeating 16
The receiver serial monitor is currently showing:
10
49
54
13
(repeat)

This seems like this should be an easy fix.

PaulS

The sender is sending ASCII data. The mapped pot reading is output one character at a time.

The receiver has some bizarre idea that the sender has sent an int, and that the reading, storing, and conversion of the character to an int happens automagically. Here's a clue. It doesn't.

What you are getting is not 10, 49, 54, 13 repeated. It's 45, 54, 13, 10. The 49 is the ASCII code for a 1. 54 is the ASCII code for 6. The 13 and 10 are carriage return and line feed (that println() added).
The art of getting good answers lies in asking good questions.

dan007


.................
What you are getting is not 10, 49, 54, 13 repeated. It's 45, 54, 13, 10. The 49 is the ASCII code for a 1. 54 is the ASCII code for 6. The 13 and 10 are carriage return and line feed (that println() added).


You mean it's 49, 54, 13, 10 repeated? I presume it was a typo.

Dan

oric_dan

You don't appear to actually be using the SoftSerial. You cannot have both the XBee and
the PC-USB port connected to the Arduino RX,TX pins at the same time, as the signals
will conflict.

Go Up