I need to send one transmission and record multiple distances with 4 receivers, but everytime I use more than 2 receivers, the serial data does not print. What can I do?

P.S. I'm using 5 SRF-02 Sensors, 1 transmitter and 4 receivers all via I2C.

#include <Wire.h>

#define cmdByte 0x00                                 // Command byte
#define rangeByte 0x02                             // Byte for start of ranging data

byte highByte = 0x00;                                // Stores high byte from ranging
byte lowByte = 0x00;                                // Stored low byte from ranging
int range = 0; 
int rangeData;

void setup() {

void loop() {
   D0_1= getRange(0x70, 0x71);  
   D0_2= getRange(0x70, 0x72);  
   D0_3= getRange(0x70, 0x73);  
   D0_4= getRange(0x70, 0x74);  

 int getRange (uint8_t send_address, uint8_t rec_address)

  Wire.beginTransmission(send_address);             // Start communticating with SRF02
  Wire.write((uint8_t)cmdByte);                         // Send Command Byte
  Wire.write((uint8_t)0x5C);        // Transmit an 8 cycle 40khz burst - no ranging takes place

  delay(80);                                                           // Wait for ranging to be complete

  Wire.beginTransmission(rec_address);       // start communicating with SRFmodule
  Wire.write((uint8_t)rangeByte);                 // Call the register for start of ranging data

  Wire.requestFrom(rec_address, 2);            // Request 2 bytes from SRF module

  while(Wire.available() < 2);                    // Wait for data to arrive
  highByte = Wire.read();                           // Get high byte
  lowByte = Wire.read();                           // Get low byte

  range = (highByte << 8 ) + lowByte;              // Put them together


 return(range);                                                    // Returns Range
  • My magic crystal ball tells me that.... You didn't even say what ultrasonic sensor you are using!
    – frarugi87
    Dec 1, 2015 at 11:48
  • Whoops, my apologies, I'm using SRF-02 sensors.
    – Umbus
    Dec 1, 2015 at 11:52
  • Now it's easier ;) Did you check the addresses on the bus? Check also the LEDS (see here for the led coding). And... Can you timeout when the I2C does not reply? Check with the main library or try to use a software one which does timeout...
    – frarugi87
    Dec 1, 2015 at 12:08
  • the LEDS don't blink if I try to use more than 3 receivers.
    – Umbus
    Dec 1, 2015 at 12:13
  • @Umbus your code doesn't compile. Missing declarations of D0_x variables. Also did you changed the addresses of 4 sensors to 0xE2, 0xE4, 0xE6, 0xE8 and tested every single one alone? Did they respond correctly?
    – brtiberio
    Dec 1, 2015 at 12:36


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.