0

I have configured a hc-05 bluetooth module as master and a hc-06 module as slave an since the LED on the hc-05 is blinking in a 2s delay they should be paired but no matter what I do I can't send data between the two Arduinos.

Here is the code for the slave (I use the example code from the EasyTransfer module github repo: https://github.com/madsci1016/Arduino-EasyTransfer):

    #include <Wire.h>
    #include <EasyTransferI2C.h>
    
    //create object
    EasyTransferI2C ET; 
    
    struct RECEIVE_DATA_STRUCTURE{
      //put your variable definitions here for the data you want to receive
      //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
      int16_t blinks;
      int16_t pause;
    };
    
    //give a name to the group of data
    RECEIVE_DATA_STRUCTURE mydata;
    
    //define slave i2c address
    #define I2C_SLAVE_ADDRESS 9
    
    void setup(){
      Wire.begin(I2C_SLAVE_ADDRESS);
      //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc. 
      ET.begin(details(mydata), &Wire);
      //define handler function on receiving data
      Wire.onReceive(receive);
      
      pinMode(13, OUTPUT);
      
    }
    
    void loop() {
      //check and see if a data packet has come in. 
      if(ET.receiveData()){
        //this is how you access the variables. [name of the group].[variable name]
        //since we have data, we will blink it out. 
        for(int i = mydata.blinks; i>0; i--){
          digitalWrite(13, HIGH);
          delay(mydata.pause * 100);
          digitalWrite(13, LOW);
          delay(mydata.pause * 100);
        }
      }
    }
    
    void receive(int numBytes) 

here is the code for the master:

#include <Wire.h>
#include <EasyTransferI2C.h>

//create object
EasyTransferI2C ET; 

struct SEND_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to send
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  int16_t blinks;
  int16_t pause;
};

//give a name to the group of data
SEND_DATA_STRUCTURE mydata;

//define slave i2c address
#define I2C_SLAVE_ADDRESS 9

void setup(){
  Wire.begin();
  //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
  ET.begin(details(mydata), &Wire);
  
  pinMode(13, OUTPUT);
  
  randomSeed(analogRead(0));
  
}

void loop(){
  //this is how you access the variables. [name of the group].[variable name]
  mydata.blinks = random(5);
  mydata.pause = random(5);
  //send the data
  ET.sendData(I2C_SLAVE_ADDRESS);
  
  //Just for fun, we will blink it out too
   for(int i = mydata.blinks; i>0; i--){
      digitalWrite(13, HIGH);
      delay(mydata.pause * 100);
      digitalWrite(13, LOW);
      delay(mydata.pause * 100);
    }
  
  delay(5000);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.