I am VERY happy to say that I have made the jacket work successfully; meaning the left arrow will blink when the left button is pressed and vice versa! It was quite difficult because there were several obstacles to overcome, and not only that, but the code found from the
Instructables link did not seem to do the task I wanted it to do.
Now, in the post before this, I had mentioned that the LEDs were not blinking during the testing phase because there was a high resistance between the battery and the board. However, it turned out the cause of all my pain was that there was a short circuit that caused the battery to burn up and die before it could provide power to the Lilypad. My mistake was not cutting the loose threads around the battery short enough. After cutting off the extra strands, I put in a fresh battery... only to find a few more obstacles ahead of me.
Major problems encountered were:
- The LEDs of both arrows wouldn't blink at the same time
- The pins on the Lilypad board (specifically 9 and 4) weren't working.
- Insufficient power supply
Minor problems encountered:
- Unnecessary panicking from misreading the multi-reader due to lack of knowledge in different range settings. helpful link here.
- Program compiled and uploaded to board with no problem, but nothing happened... because driver wasn't installed for the FTDI. helpful link here.
The first major problem, was found when the test program was uploaded to the Lilypad board. It was to test if the arrows could simply blink on and off. No code for the buttons or anything yet.
Here is the test program for the jacket arrow LEDs: (retrieved from the same instructables link.
int ledPin = 13; // the LED on the LilyPad
int leftSignal = 9; // my left turn signal is attached to petal 9
int rightSignal = 11; // my right turn signal is attached to petal 11
int signalLow = 10; // the - sides of my signals are attached to petal 10
void setup()
{
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
pinMode(leftSignal, OUTPUT); // sets the leftSignal petal to be an output
pinMode(rightSignal, OUTPUT); // sets the rightSignal petal to be an output
pinMode(signalLow, OUTPUT); // sets the signalLow petal to be an output
digitalWrite(signalLow, LOW); // sets the signalLOW petal to LOW (-)
}
void loop() // run over and over again
{
delay(1000); // wait for 1 second
digitalWrite(leftSignal, LOW); // turn the left signal off
delay(1000); // wait for 1 second
digitalWrite(rightSignal, HIGH); // turn the right signal on
delay(1000); // wait for 1 second
digitalWrite(rightSignal, LOW); // turn the right signal off
delay(1000); // wait for 1 second
}
Only the LEDs connected to pin 11 would work. LEDs connected to pin 9 weren't blinking at all!
After a ton of trial and error (and much help from my programmer-savy dad!) that the short was found to have busted pin 9 on my Lilypad. When testing the conductivity between pin 9 (+) and pin 10 (-), there was no power from the battery coming through to light up the LEDs. While on the other hand, pin 11(+) and pin 10 (-) had about 2V lighting up the LEDs to make it blink.
Goal: find a pin that does work!
And so, luckily, pin 8 was able to conduct with pin 10. With just a little bit more conductive thread, pin 8 was connected to pin 9, and the code was changed from 9 to 8.
That seemed to work! ...but then LEDs connected to pin 11 stopped working. Now, that leads to the insufficient power supply. Whenever the board was connected to the FTDI cable, it seemed to follow the test program with no problem! Without the cable though, only one side could blink. The jacket was concluded to need at least 4.5V to work as each side needs at least 2-ishV to work, whereas the battery used only had 3V (this wasn't including the notifying LEDs on the shoulders). Thus, the entire time in testing the jacket, the FTDI cable was connected to it.
|
Me using my chopstick skills to measure battery voltage
while using the other hand to take a photo. Ha! |
However, it is until much later did we realize that we were entirely wrong in the assumption that a better power supply was needed. 4V is needed to power
both sides of the jacket. We only need one side to work at a time (since a turn signal shouldn't have both signals on at the same time), so a 3V battery should be enough. (and I've tested this, so no worries!)
|
the exciting moment when both arrows were able to blink!! |
Once the arrows were able to work, next up was implementing the buttons! Since I connected my threads using the same pins as from the Instructables link, I thought I could just copy the same code. ...However, I'm not sure why, but the code seemed unusually complicated and was only able to make all the LEDs blink on and off randomly whether the buttons were pressed or not. So, despite how new to Arduino I am, I attempted to write my own code for this, and somehow, it worked!
My source code to make arrows blink according to which button is pressed:
int boardLED = 13; //LED on Lilypad
int leftSignal = 11; //LEDs for left arrow
int rightSignal = 8; //LEDs for right arrow
int signalLow = 10; //negative for arrows
int rightLow = 3; //negative for right shoulder LED
int leftSwitch = 7; //button for left
int rightSwitch = 5; //button for right
int leftLED = 12; //left shoulder LED
int rightLED = 6; //right shoulder LED
int x; //variable for for-loop
//setup copied from instructables link
void setup() // run once, when the sketch starts
{
pinMode(boardLED, OUTPUT);
pinMode(leftSignal, OUTPUT);
pinMode(rightSignal, OUTPUT);
pinMode(signalLow, OUTPUT);
pinMode(rightLow, OUTPUT);
pinMode(leftSwitch, INPUT);
digitalWrite(leftSwitch, HIGH);
pinMode(rightSwitch, INPUT);
digitalWrite(rightSwitch, HIGH);
pinMode(leftLED, OUTPUT);
pinMode(rightLED, OUTPUT);
digitalWrite(boardLED, HIGH);
digitalWrite(signalLow, LOW);
digitalWrite(rightLow, LOW);
}
void loop()
{
if (digitalRead(leftSwitch) == LOW) //if left button is pressed
{
left();
}
else
{
digitalWrite(leftLED, LOW);
digitalWrite(leftSignal, LOW);
}
if (digitalRead(rightSwitch) == LOW) //if right button is pressed
{
right();
}
else
{
digitalWrite(rightLED, LOW);
digitalWrite(rightSignal, LOW);
}
}
void left() //method for left turn signal
{
digitalWrite(leftLED, HIGH); //left shoulder LED is on
for (x = 0; x < 10; x++) //arrow will blink 10 times
{
digitalWrite(leftSignal, HIGH);
delay(1000);
digitalWrite(leftSignal, LOW);
delay(1000);
}
digitalWrite(leftLED, LOW); //left shoulder LED is off
}
void right() //method for right turn signal
{
digitalWrite(rightLED, HIGH);
for (x = 0; x < 10; x++)
{
digitalWrite(rightSignal, HIGH);
delay(1000);
digitalWrite(rightSignal, LOW);
delay(1000);
}
digitalWrite(rightLED, LOW);
}
This code seemed to work wonderfully for the right side!! It would blink 10 times once the button is pressed, and stop. When testing the leftside however, it would just blink on and off before even pressing the button, and stay that way. After testing the conductivity between pin 4 and pin 3, there seemed to be a negative polarity (which isn't supposed to happen). And taking a shot in the dark, it was assumed that pin 4 may have been busted like pin 9. Thus, taking some speaker wire, I jumped one end of the wire to the positive of the left button and the other end to pin 7 using non-conductive thread to sew it down. (that's why in the code, leftSwitch is 7 instead of 4).
After that, the sweater worked completely in every way!! Yay :-)
Lesson of the story: Don't short the circuit because it'll cause you more problems than you need...
Note: When washing, take out the battery first! It is also advised that the jacket be hand washed and hang-dried.
PS. Forgot to take a photo/gif of jacket working. Maybe I'll include it later because right now is 1:40am so... no.