So i basically want to communicate between two microcontrollers, first is arduino and second is a standalone using atmega8L. i want the sensor reading from atmega8L to be send to arduino via bluetooth. i have 2 bluetooth modules and i have configured them in master and slave mode using at command. But i am not able to receive the data. I have written a simple code to just check if i can receive anything but i am not getting it. The serial monitor shows 10 50 13 10 50 13.... even though my code send 2. Any help would be appreciated.
FOR SLAVE(ARDUINO CONNECTED TO PC)
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
if(Serial.available()>0)
{
int a= Serial.read();
Serial.println(a);
}
}
FOR STANDALONE MASTER
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(2);
delay(100);
}
You don't say if you have paired the devices, or if you have proven you have a connection.
Arduino need not be involved with the connection.
yes they are paired. i did that auto pairing thing when both master and slave are active, they connect to each other. to indicate that leds on both the bluetooth module blink like they do when paired(not fast blinking)
they connect just fine, its the code that i don't get. even that simple piece of code doesn't work. am i doing something wrong? is my code wrong? or any links where they have explained how to transfer data between two arduinos using bluetooth?
Your program is working correctly, but not as you hoped.
Serial.println() is sending an ascii representation of the number, followed by a line feed and carriage return.
Serial.read() reads one character from the serial port. The value of a line feed character is 10; a carriage return is 13, etc.
Study Serial Input Basics, then make sure the connection working without Bluetooth. Do that by connecting RX on one Arduino to TX on the other and vice versa. Also connect the grounds.
nachiket_waghambare:
leds on both the bluetooth module blink like they do when paired(not fast blinking)
I asked you if the devices have been paired, and you have a proven connection. What you have said probably implies "no" to both.
The LED activity can vary with the firmware versions but I believe
-
With all versions, fast blinking suggests - power on, ready to connect to a previously paired device, or to pair with a new device.
-
With all versions, a slow blink, i.e. "not fast blinking", the device is in AT mode.
-
With most versions, the LED is permanently on when a connection is made, but with some later versions it is off but gives a quick double flash, either when data is actually transmitted, or at long regular intervals.
I understand case 3 above prevails even when you are using auto-connect since, when the connection is actually made the master reverts from AT mode to communications mode. In short, I don't think you are in communications mode, and I don't think you understand the difference between pairing and communicating either. This is something for the heavier gurus, but I believe that, when you are using auto-connect, you pre-programme the master with the MAC of the slave, thereby absolving you from the need to go through the pairing procedure.
Assuming the Arduino code is kosher, all your problems are with bluetooth configuration or procedure, and I think you need to ensure the LED signals are what you think they are and do what they should to fit the procedure.
@Nick_Pyner
they are paired and they are connected that is it is case 3 (double flash) i have done the auto pairing thing in at mode for the master it was the code that i was worried about
@jremington
you are right i just checked the ascii for 2 is 50 and you explained 10 and 13. i will definitely try what you have suggested
thank you both for the advice