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.
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!!!
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.
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.
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...
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.
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).
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...
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!!!