Wireless Controlled Wearable EL Wire Dance Suit
Basic Example Code
For a sanity check when I started writing the code, I had the code turn off two channels to ensure that the code was receiving a character. To follow along, check out the GitHub repository for the project here:
Transmitting Glove Controller
You'll need to upload code to send characters out to the EL Sequencers. With the XBee Series 1 configured to broadcast, you would simply send a character out using a UART. In this case, the glove that was built used software serial pins. If the send button is pressed, a character will be broadcasted out. You'll notice that there is additional code to prevent the controller from sending out a character when the button is constantly being pressed down and for debouncing. This code is the simplest in terms of controlling all the channels.
If you have not already, unzip the GitHub repo and open the example code called XBee_ControllerV1.ino. The path of the example code will probably look similar to: ...\Wireless_Controlled_EL_Dance_Suit\Arduino\XBee_Controller\XBee_ControllerV1. You can also copy the code below and paste it into the Arduino IDE. Select the board (in this case the Arduino/Genuino Uno) and COM port that the board enumerated to. Make sure the switch is flipped to the DLINE before hitting the upload button.
language:c
/*******************************************************************
XBee_ELSequencer_ControllerV1.ino
Modified by Ho Yun Bobby Chan @ SparkFun Electronics May 10th, 2017
Taken from SparkFun XBee EL Sequencer Controller Example
Ho Yun Bobby Chan @ SparkFun Electronics June 20, 2014
Updated by Toni Klopfenstein @ SparkFun Electronics April, 2015
https://github.com/sparkfun/EL_Sequencer
Description:
This is a basic test of the wireless controller to control an EL Sequencer.
The wireless controller consists of an RedBoard Programmed with Arduino, XBee Shield,
XBee Series 1 transceiver, and LED Push Button. The EL Sequencer
uses an EL wire, 12V EL inverter, a 9V wall wart, 9V adapter, XBee female sockets soldered,
battery, and a XBee Series 1 transceiver. An XBee Series 2
can be used but the throughput of the Series 1 is much higher. To
reduce latency, I recommend using the XBee Series 1. The basic
configuration of the XBee module with point-to-point configuratin is
based on Digi's Example tutorial
=> http://examples.digi.com/get-started/basic-xbee-802-15-4-chat/ .
Page 5 of the tutorial shows you how to broadcast with
point-to-multipoint configuration so that multiple EL Sequencers
can be controlled.
Connect the XBee Shield to the Arduino with the switch flipped to the
software serial side labelled "DLINE".
By pushing the button, a character is sent from a remote microcontroller.
The corresponding EL Sequencer will receive the character and control
the EL component on a channel that is associated with that character.
A LED push button was used but not necessary for this to operate. A
normal momentary push button can be used.
Connect momentary LED tactile push buttons to Arduino:
C = pin 13, the cathode (+) of the LED
A = GND, the anode (-) of the LED
B1 = GND
B2 = pin 8
Using a RedBoard Programmed with Arduino, the XBee transceiver is connected to the
Software Serial pins. By pushing the button, the Arduino will
send one character through the XBee. Logic is used to control
how many characters are sent with the push button. The Arduino
will not send another character until the button is pressed again.
Note: This section of the code can be optimized. As the user is not
pressing down on the button, logic can be added so that the XBee is
not continuously sending serial characters to the receiving
EL Sequencer when idle.
Development environment specifics:
Arduino 1.6.5
This code is beerware; if you see me (or any other SparkFun employee) at the local,
and you've found our code helpful, please buy us a round!
Distributed as-is; no warranty is given.
**************************************************************************/
#include <SoftwareSerial.h>
SoftwareSerial xbee(2, 3); //Rx = 2, Tx = 3
//Declare variables and pin definitions
//Send
const int button1Pin = 8; //push button
const int ledPin1 = 13; //LED on the push button
//variables to check for button1 state
boolean prev_button1State = false;
boolean current_button1State = false;
/*******************Setup Loop***************************/
void setup() {
//Declare pin modes
pinMode(button1Pin, INPUT_PULLUP); //use internal pullup resistor with LED
pinMode (ledPin1, OUTPUT);//LED to indicate when character has been sent
//Declare serial connections for debugging
Serial.begin(9600);
Serial.println("Arduino started sending bytes via XBee");
xbee.begin(9600);
Serial.println("EL Sequencer Controller's XBee Ready to Communicate");
}
/*******************Main Loop***************************/
void loop() {
//initialize variables to read buttons
int button1State;
button1State = digitalRead(button1Pin);
/***button1state
- LOW or 0 means pressed
- HIGH or 1 means not pressed
****/
//if button is pressed, it will be pulled low
if (button1State == LOW) {
digitalWrite(ledPin1, HIGH); //turn push button LED ON
current_button1State = true; // button has been pressed once
if (prev_button1State != current_button1State) //check to see if button is still being pressed
{
Serial.println("Button is pressed.");
xbee.write("A");//Tell Sequencer to change to mode by sending a character
}
else {
//do nothing because finger is still on button
}
prev_button1State = current_button1State;
}
//button has not been pressed, it will be high again
else {
current_button1State = false;
digitalWrite(ledPin1, LOW); // turn push button LED OFF
prev_button1State = current_button1State;
}
}
Receiving EL Sequencer Blink Code
You'll also need to uploade code to receive the characters for each EL Sequencer. You will need another UART to connect to the XBee Series 1 configured to receive characters from the broadcasting XBee. In this case, the EL Sequencer was designed to connect the ATmega328P's hardware UART to the XBee Series 1's UART. Therefore, the Serial was used instead of SoftwareSerial.
Open the example code called XBee_ELSequencerV1.ino. The path of the example code will probably look similar to: ...\Wireless_Controlled_EL_Dance_Suit\Arduino\XBee_ELSequencer\XBee_ELSequencerV1. You can also copy the code below and paste it into the Arduino IDE. Select the board (in this case the Arduino Pro or Pro Mini, ATmega328P (3.3V, 8MHz) but it can also be LilyPad Arduino) and COM port that the USB-to-Serial Converter enumerated to. Hit the upload button.
language:c
/**********************************************************************
XBee_ELSequencerV1.ino
Created by Ho Yun Bobby Chan @ SparkFun Electronics May 10th, 2017
* Taken from SparkFun XBee EL Sequencer Demo Sketch
* Ho Yun Bobby Chan @ SparkFun Electronics June 20, 2014
* Updated by Toni Klopfenstein @ SparkFun Electronics April, 2015
* https://github.com/sparkfun/EL_Sequencer
*
* Description:
* This is a basic test of the EL Sequencer to control an EL Sequencer
* The wireless controller consists of an RedBoard Programmed with Arduino, XBee Shield,
* XBee Series 1 transceiver, and LED Push Button. The EL Sequencer
* uses an EL wire, 12V EL inverter, a 9V wall wart, 9V adapter, XBee female sockets soldered,
* battery, and a XBee Series 1 transceiver. An XBee Series 2
* can be used but the throughput of the Series 1 is much higher. To
* reduce latency, I recommend using the XBee Series 1. The basic
* configuration of the XBee module with point-to-point configuratin is
* based on Digi's Example tutorial
* => http://examples.digi.com/get-started/basic-xbee-802-15-4-chat/ .
* Page 5 of the tutorial shows you how to broadcast with
* point-to-multipoint configuration so that multiple EL Sequencers
* can be controlled.
*
* By pushing the button, a character is sent from a remote microcontroller.
* The corresponding EL Sequencer will receive the character and control
* the EL component on a channel that is associated with that character.
*
* EL Sequencer uses the hardware UART of the Atmega328 for communication:
* pin 0 = Rx
* pin 1 = Tx
*
* Note: Make sure to remove the XBee Series 1 on the EL Sequencer when
* uploading a new sketch file otherwise it will brick the XBee. You can
* always use the next generation XCTU software to unbrick and recover
* the transceiver.
*
* Development environment specifics:
* Arduino 1.6.3
*
* This code is beerware; if you see me (or any other SparkFun employee) at the local,
* and you've found our code helpful, please buy us a round!
* Distributed as-is; no warranty is given.
*
***********************************************************************/
//Declare character 'val'
char val;
//LED to check if the LED is initialized.
const int status_LED = 13;
/*******************Setup Loop***************************/
void setup() {
Serial.begin(9600); //Begin Serial communication for debugging
Serial.println("EL Sequencer's XBee is Ready to Receive Characters");
val = 'A';// button pressed, therefore sending letter A
//Initialize pins
pinMode(status_LED, OUTPUT); //Set pin mode as output for status LED
pinMode(2, OUTPUT); //Set pin mode as output for Channel A
pinMode(3, OUTPUT); //Set pin mode as output for Channel B
pinMode(4, OUTPUT); //Set pin mode as output for Channel C
pinMode(5, OUTPUT); //Set pin mode as output for Channel D
pinMode(6, OUTPUT); //Set pin mode as output for Channel E
pinMode(7, OUTPUT); //Set pin mode as output for Channel F
pinMode(8, OUTPUT); //Set pin mode as output for Channel G
pinMode(9, OUTPUT); //Set pin mode as output for Channel H
//Status LED to see if the EL Sequencer is initializing
for (int i = 0; i < 3; i++) {
digitalWrite(status_LED, HIGH);//set Status LED on
delay(50);
digitalWrite(status_LED, LOW); //set Status LED off
delay(50);
}
digitalWrite(2, HIGH); //Channel A
digitalWrite(3, HIGH); //Channel B
digitalWrite(4, LOW); //Channel C
digitalWrite(5, LOW); //Channel D
digitalWrite(6, LOW); //Channel E
digitalWrite(7, LOW); //Channel F
digitalWrite(8, LOW); //Channel G
digitalWrite(9, LOW); //Channel H
delay(1000); //Wait 1 second
}
/*******************Main Loop***************************/
void loop() {
//Check if XBee is receiving data from other XBee
if (Serial.available()) {
val = Serial.read();
//Check to see if character sent is letter A
if (val == 'A') {
digitalWrite(status_LED, LOW); //turn ON Status LED
digitalWrite(2, LOW); //Channel A
digitalWrite(3, LOW); //Channel B
delay(1000);
Serial.println("Character Received");
}
else {
//rewrote controller code to stop constantly sending Z
//toggled pins outside of this nested condition statement
}
}
digitalWrite(status_LED, HIGH); //turn OFF Status LED
digitalWrite(2, HIGH); //Channel A
delay(50);
digitalWrite(3, HIGH); //Channel B
}
When finished, you should see the EL Sequencer blink two EL wires connected to the channels when pressing the send button. You probably won't see the EL too well in a well lit room. Below is an image of all the EL Wire hoodies angled with the side of each pair of ppants when the room lights are turned on.
Turning off the lights, you should see the channels blink clearly.