Go Down

Topic: LED Custume - Choice of wireless medium.  (Read 170 times) previous topic - next topic

murraywcourt

My post boils down to two questions:

 - Is bluetooth the best wireless medium for a low-bandwidth, low-latency application over a short distance (<2m) with no line of sight?

 - If it is, what could be going wrong with by current bluetooth setup (problems described beneath)?


 Background: I am trying to build an LED Lion Dance costume where the 'head' of the lion sends a signal to the other parts of the lion (including the trousers worn by dancers) to say how bright the LEDS should be. This cant be done using a wire as any wire between the lion and the two dancers would quickly become damaged during the performance.

 My first thought was Bluetooth, however my master/slave prototype using HC-05 units ran into a few snags:

 - There is a lot of latency between the transmitting and receiving units, about 1.5 seconds. This would not be acceptable my purposes.

 - The sending unit crashes periodically. I've rebuilt the project several times and stripped out any complicating factors and I can't work out why the transmitting unit keeps crashing. The receiving unit then has a Serial.available = 0 (instead of the usual 63 when all is working) and so the whole thing doesnt work.

All I need is for a single byte of data (brightness, 0 = off, 255 = fully on) to be sent from the 'lion head' to the 'lion tail' with minimal latency, no regard for lost packets and no line of sight. A useful addition would be the ability to send 3 more bytes in a packet (red green and blue for the LEDS).


 The master code:


Code: [Select]


//Master Simple Murray Court 31/12/2017


byte  brightness_led;

int transmission;

float brightness, cos_brightness;

#define LED 9

void setup() {
 
    // initialize serial communication
    // (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
    // it's really up to you depending on your project)
    Serial.begin(38400);

    // configure Arduino LED pin for output
    pinMode(LED, OUTPUT);
    brightness = 0;
   
  }

void loop() {

brightness = brightness + 0.001;
if (brightness > (3.14159 + 3.14159))
  {
    brightness = 0;
  }

cos_brightness = cos(brightness);

cos_brightness = (cos_brightness + 1) * 127;

transmission = cos_brightness;

analogWrite(LED,transmission); // local LED shows current brightness state

//Serial.println(cos_brightness);
Serial.write(transmission); // sened brightness state to SLAVE machine     

}


 The slave code is beneath.


 
 
Code: [Select]


//Lion Slave Murray Court 2017 - 12 - 28


#define LED_GREEN 9
#define LED_RED 10
#define LED_BLUE 11

 int brightness_led = 0;
 
void setup() {

    Serial.begin(38400);

    pinMode(LED_GREEN, OUTPUT);
    pinMode(LED_RED, OUTPUT);
    pinMode(LED_BLUE, OUTPUT);
 
}

void loop() {
 
   if(Serial.available() > 0){ // Checks whether data is comming from the serial port
      brightness_led = Serial.read(); // Reads the data from the serial port
   }


  Serial.print("Serial Availability:");
  Serial.print(Serial.available());
  Serial.print("    Received Brightness:");
  Serial.println(brightness_led);
   
  analogWrite(LED_GREEN, brightness_led);       
  analogWrite(LED_RED, brightness_led);                   
  analogWrite(LED_BLUE, brightness_led);                             

}



 Thanks for your time.

Robin2

I think Bluetooth would work and it is simple to implement - but you would need to do some tests.

Bluetooth is just serial-by-wireless. Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

I know it seems illogical but I suspect your system will work better if you do not send data as often, Remember that an Arduino can work very much faster than serial communication so you are probably overloading everything. Temporarily add delay(200); into loop() in your master program and see what happens.

Also you have Serial.write(transmission); and brightness_led = Serial.read(); where both variables are defined as int. An int is two bytes but Serial.write() and Serial.read() only send and read a single byte.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

murraywcourt

Hi Robin2,

 This is really excellent. Adding in a delay(10); has totally solved my latency problems.

 Furthermore, getting rid of my (pointless) Serial.Print commands from the slave code has prevented the crashing problems I was experiencing, as I presume these serial.print commands were getting sent to the Bluetooth module and jamming up some buffer or other.

 Furthermore, the tutorial that you pointed me towards will help me form more complete data packets with RGB values.

 Many thanks,

 - Murray.

murraywcourt

 Hi,

 I just just discovered that Bluetooth only supports one - to - one connections! I will need the 'master' device to pass off serial data to two 'slave' devices. What would be the easiest way of doing that? Againw ith no line of sight and range of about 2 meters.

 Thanks again,

 - Murray

Robin2

My preference would be to use nRF24L01+ transceivers. Have a look at this Simple nRF24L01+ Tutorial

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

murraywcourt

Hi Robin2,

 Do you think that Xbee modules will work?  http://www.instructables.com/id/How-to-Use-XBee-Modules-As-Transmitter-Receiver-Ar/

 I'd prefer to use something that still uses serial as I have built my project around this.

 Cheers,
 
 - M

Robin2

Do you think that Xbee modules will work? 
Possibly. But I have never used Xbee modules - they are too expensive for me.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up