Bluetooth: UNO <=> UNO

Hi Guys!

I'm completly new in this forum and hope you can help me
my "project" is like this: i have two UNOs and connected them with BT-modules. So far so good.
The master-module has an poti on A0 and doing a int val = analogRead(A0). Afterwards it's sending over a SoftwareSerial with SWIO.print(val)*.
When i check the function by connecting the module to the PC and listening the COM with puTTY everything is fine.

(*SWIO stands for SoftWareInOut, just a var-name)

The slavemodule is doing:
if (SWIO.available)
{
val = SWIO.read();
Serial.print(val);
}

So, read in the value over the BT-COM and write it to the USB-COM (listening with pUTTY for troubleshooting). Once again: connecting it to the comp, typing in pUTTY everything is perfect...

BUT...

When i connect the two UNOs over BT ans listening to the slave-usb-COM i get kind off random-value (not really).
I want the master to send link 1 45 89 140 ... 989 1024 (turning the poti) and the salve should give this out.

Can you help me? Please!

THANX A LOT
greetings from Austria
Martin

The slavemodule is doing:
if (SWIO.available)
{
val = SWIO.read();
Serial.print(val);
}

No, I really doubt that.

Can you help me?

Without seeing your real code, no.

I want the master to send link 1 45 89 140 ... 989 1024 (turning the poti)

You can twist the pot until you break it, and you'll never get analogRead() to return 1024.

Hi PaulS!

Thanks for your answer!
Here is my original code:

Master:

 #include <SoftwareSerial.h>
 
 #define rxPin 2
 #define txPin 3
 #define LedOutput 6
 
int Wert;

 SoftwareSerial SWIO(rxPin, txPin); 

void setup() {                

  pinMode(LedOutput, OUTPUT); 
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  
  pinMode(A0,INPUT);
  SWIO.begin(115200);
  Serial.begin(115200);
  SWIO.println("Software Serial OK!");
  Serial.println("Hardware Serial OK!");
}

void loop() {
  Wert=analogRead(A0);
  Serial.println(Wert);
  SWIO.print(Wert);
  delay(1000);
  
}

Slave

 #include <SoftwareSerial.h>
 #define rxPin 2
 #define txPin 3
 #define LedOutput 6
 int i=0;
 int Wert = 0;

 SoftwareSerial SWIO(rxPin, txPin); 

void setup() {                
  pinMode(LedOutput, OUTPUT); 
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  SWIO.begin(115200);
  Serial.begin(115200);
  SWIO.println("Software Serial OK!");
  Serial.println("Hardware Serial OK!");
}

void loop() {

  if(SWIO.available()) 
  {
  Wert = SWIO.read();
  Serial.write(Wert);
  }
}

Can you see my mistake?
Thanx for helping!!!!

and connected them with BT-modules.

Which bluetooth modules? How are they connected to the Arduinos?

  SWIO.begin(115200);

115200 is really stressing software serial.

Why does the slave do nothing but send the value back to the master that never reads it? How do you know that things aren't working just fine?

Why does the slave do nothing but send the value back to the master that never reads it? How do you know that things aren't working just fine?

it's just the beginning of understanding BT. but it's a very good idea to send something back.

115200 is really stressing software serial.

ok...the BT-modules handle it. i can try to change it.

but can you see a kind of "main"-mistake i did?

the modules:
Master:
http://www.dealextreme.com/p/arduino-bluetooth-shield-v1-2-expansion-board-green-138098?item=148

Slave:
http://www.dealextreme.com/p/jy-mcu-arduino-bluetooth-wireless-serial-port-module-104299?item=184

it's just the beginning of understanding BT. but it's a very good idea to send something back.

True. But, it's an even better idea to actually use the data on the slave, as another way of confirming that valid data was received. And, it you do send data back, it's a good idea to actually read that data. Otherwise, you have no idea whether the data was received by the slave, or not.

the problem is, that the slave GETS something. but not the right data (i guess).
could you sketch me the code for sending eg "hello" and the salves GETS "hello"?
THANX A LOT!!!

but not the right data (i guess).

How do you know? You send it a value. On the slave, you read the value sent, and then don't bother using it to set the PWM value of a pin. Instead, you just echo the value back to the master. On the master, you don't bother reading what the slave sends, if anything.

what i did was:
sending "1" from master to slave, and the slave sent the received value to the serial and gave out "49" (serial-monitor or pUTTY). so, this is the ASCII-value for "1".
so far i am. but what i want to do is to send commands like "up", "down", "left",... and with an "if" i can turn on/off different pins.
in this case i don't need a loopback. all i need is the correct code , better said the correct format/type for sending and receiving.

..not sure these two commands are compatible:

SWIO.print(Wert);

Wert = SWIO.read();

The first one prints String via swio (ie "1024"), the second one reads the first byte of incoming serial data available (or -1 if no data is available) into the Wert..
p.

hi pito!

Thanx for your comment!
the thing i don't understand: when i send SWIO.print("1") is only one byte (or?), and with SWIO.read i'll get the ASCII-code...even with SWIO.print(1).
Or SWIO.print("X") i'll also get the ASCII-code for X... :frowning:

yes.. :slight_smile: Have a look on this:

I think you have to parse the incoming bytes in order to get the number sent from the master..

hi pito!

great link! THANX!!!
what do you think about this: http://www.elecfreaks.com/3044.html
the thing is, this guy doesn't parse anything. his char-array is just used to store more serial.prints.
so i thought if i'd make my read val as char, i would work...but it doesn't. and i cannot be so hard to send a whole word (like "hello").
i'll go on trying.

i'll go on trying.

Feel free to post code where you actually read data on both ends. I still haven't seen any proof that you are having problems. In the code you have posted, you send data from one device to the other, but don't use that data. Then, on that device, you send a response, but you don't read the response on the first unit.

i READ the data on BOTH ends: serial.print and read it with pUTTY ...and i told already, that i will go on with an if. but the pUTTY gives out the wrong data.

new state:
i changed the read value on slave-side from int to char.
this works fine 'til the sent value is over 100: then the slave get only the first two numbers (like: sent 456 => 45).

You changed your code. You didn't post the modified code. You still want help with it? Not a chance.

batman1976:
the thing i don't understand: when i send SWIO.print("1") is only one byte (or?), and with SWIO.read i'll get the ASCII-code...even with SWIO.print(1).
Or SWIO.print("X") i'll also get the ASCII-code for X... :frowning:

Because Serial.Print(some_int) will convert some_int to ASCII and then send it. If you just want to send B00000001, then use Serial.write().

Hi Arrch!
so, if i want to send eg. 512, and do it with serial.write, i can read like val= (int)SWIO.read() and get 512 again?
this would mean, if i want to send a word (like "hello") i have to write a loop of serial.read, isn't it?
Thank you for your help!!!