Go Down

Topic: Connecting two arduinos using bluetooth (JY-MCU) (Read 4081 times) previous topic - next topic

thrinker

Hello!

Im trying to connect two arduinos using bluetooth but i have no idea how to accomplish this. So far i've made an android application that can communicate with my arduino application.

This is the arduino code:

Code: [Select]
/* Include the software serial port library */
#include <SoftwareSerial.h>
char incomingByte;  // incoming data
int LED = 8;      // LED pin
int tx = 2;       // TX pin
int rx = 3;       // RX pin


SoftwareSerial BluetoothSerial(tx, rx);

void setup() {
  Serial.begin(9600); // initialization
  pinMode(LED, OUTPUT);
  BluetoothSerial.begin(9600);
  Serial.println("Press 1 to LED ON or 0 to LED OFF...");
 
}

void loop() {
  if (BluetoothSerial.available()){
    Serial.println("asd");
    digitalWrite(LED, HIGH);

    incomingByte = BluetoothSerial.read();
   
    Serial.println((char)incomingByte);
    //Serial.println(BluetoothSerial.read());
    if(incomingByte == '0') {
       digitalWrite(LED, LOW);  // if 1, switch LED Off
       Serial.println("LED OFF. Press 1 to LED ON!");  // print message
    }
    if(incomingByte == '1') {
       digitalWrite(LED, HIGH); // if 0, switch LED on
       Serial.println("LED ON. Press 0 to LED OFF!");
    }
  }
}


I got two Arduino UNOs and two JY-MCU bluetooth modules.

Is there a way to send a message to one arduino and then receive the message on the other UNO and for example, light a LED?

Thanks in advance!

Riva

There are different flavours of bluetooth dongles, some are slave only (other BT device initiates pairing), and some are/can also be master and initiate pairing with other BT devices. If your devices can be switched to master mode then find it's datasheet so you know what AT commands are needed to set one of the cards into master mode and pair with the other card left in slave mode.
Try and find the datasheet and maybe we can help more.

thrinker

Hi!

Yeah, ive been reading about the JY-MCU and it comes with diffrent versions. The one i have is Linvor 1.5 firmware and the AT commands for it is basically change device name, password, baud. More about that in this post:

http://byron76.blogspot.se/2011/09/one-board-several-firmwares.html

So what i need is to upgrade my firmware to Linvor 1.6 who comes with more AT commands so i can set my bluetooth devices to master/slave

Riva

Not sure what version number you need to change to but yes, it looks like your going to need a firmware re-flash. Not something I have done but the link you supplied is interesting.

thrinker

:) Alright, lets say that I succeed to reflash my bluetooths, make one master and one slave. What is the next step? How do i pair them together? Is it by a AT command or is it done by using arduino code?

Thanks in advance!

Riva

In a document linked to from the link you posted is a short section...
Quote
2. How to set this module be the master role.
Step 1: Input high level to PIO11.
Step 2: Supply power to the module. And the module will enter to the order-response
work mode.
Step  3:  Set  the  parameters  of  the  super  terminal  or  the  other  serial  tools  (baud  rate:
38400, data bit:8, stop bit:1, no parity bit, no Flow Control)   
Step  4:  Sent  the  characters  "AT+ROLE=1\r\n"  through  serial,  then  receive  the
characters "OK\r\n". Here, "\r\n" is the CRLF.   
Step 5: Input low level to PIO, and supply power to the module again. Then this module
will become master role and search the other module (slave role) automatically to build
the connection.

Beyond this I'm not sure if you have to then pair the device with the other slave and store this authenticated device or if it just auto connects to a slave with same name/passkey.

Riva

I have been looking hard into this and maybe the cheaper and simpler options could be to buy a master module & backplane instead of going to the hassle of re-flashing an existing device.
Master/Slave BT module and backplane for about £8 GBP.

thrinker

Thats real interesting. 4gbp is real cheap and the backpane is not really necessary. Do you have any experience about the pairing? If the slave and  the master is setup with the same name and password will it autoconnect on startup or do you have to program your arduino to connect to a specific mac adress?


Riva


Thats real interesting. 4gbp is real cheap and the backpane is not really necessary. Do you have any experience about the pairing? If the slave and  the master is setup with the same name and password will it autoconnect on startup or do you have to program your arduino to connect to a specific mac adress?

Do you realize the module is 3.3V only and the backplane should/will convert 5V power and TTL signal levels to suit.
I have no experience of trying to pair these devices as mine are slave only so pairing is initiated via PC. This is why I had a hard look at re-programming them but in the end the hassle outweighs the cost of buying a master device to play with.

Go Up