Showing posts with label arduino. Show all posts
Showing posts with label arduino. Show all posts

Hello, That Conference Scientists!

Did you join us for Circuits in Play Dough? I'm glad you're here!

Keep in touch: Let's use #thatCircuits to tie our posts together.

Post your pictures: Please share your pictures from the workshop! You can use the #thatCircuits hashtag on your photo-sharing service. Add a comment here with the link to your photo set.

Review what we did: Here are the Circuits in Play Dough hand-outs that we used. This whole endeavor was inspired by AnnMarie Thomas's TED talk, "Hands-on science with squishy circuits," and the Squishy Circuits project at St. Thomas University.

Keep learning: If you want to understand why electronics work, chemistry is the science you want to explore. I learned so much from The Joy of Chemistry: The Amazing Science of Familiar Things. Ask your grown-up lab assistant to help you try out the experiments in this book.

Do more: If you learned about Scratch from Katelyn, you can apply programming to your electronics projects with the Hummingbird and Arduino microcontrollers. Make robots!

Give thanks: Thanks to Amy and Lance Larsen for bringing the bowls and spoons I needed to mix up a bunch of play dough in a hotel room. Thanks to my mom for making fond memories of sculpting play dough while it was still warm, and for showing me that girls are good at programming. Thanks to the TSA for not balking at a bag containing LEDs, wire cutters, and 80 9-volt batteries.

You don't have to be an expert to be a teacher

Just in time for my session at That Conference, benefit from my recent discovery: Pin 13 Considered Harmful.

I've heard folks tell me they're not ready to present at conferences, because they're not experts yet. I look at it the opposite way: I barely know electronics, yet I built a robot. I built a robot, and you can, too! Take inspiration by what I've achieved despite my lack of expertise.

You don't have to be an expert to inspire passion. You don't have to be an expert to teach. You just have to care.

And you can fix things with a follow-up blog post. Eheh.

Arduino-Powered Clank

I've often said, incorporating an Arduino microcontroller into your costume can open up all new kinds of fun. For Halloween, I dressed as Agatha Clay, Girl Genius (seemed fitting). I just created a better video of my little clank:



Photos of the construction.

Source code that drives it.

Hello, Arduino. Let's get started.

Hi, CodeMash! Here are resources to get you started with the Arduino microcontroller, a prototyping platform to build crafty electronics projects (electronicky craft projects?).

My clank

You need the Arduino IDE, the editor in which you'll write your sketches.

You need the microcontroller board. There are many form factors to choose from. I have an Arduino Uno, and that's a great default choice. You might want one with additional capabilities, such as Ethernet or the extra processing power of the Mega, or you might enjoy the LilyPad, designed for being incorporated into costumes and wearables.

Note that a "shield" is a thing that plugs into an Arduino, so it doesn't have any brains on its own. Feel free to pick up some shields, they're a hoot, but be aware that you still also need an Arduino board.

Sources to buy from: AdaFruit Industries, Sparkfun Electronics, Maker Shed, RadioShack.

The slides from my talk are on SlideShare, and the sketch for the robot is on GitHub (along with a number of other sketches).

Pictures of building the robot, the video game, my ambient clock, and the thing under your bed.

What are you going to make? Leave a comment here or send me a note on Twitter (@scichelli). I can't wait to hear about it!

Showdown at Unobtanium—for SCIENCE!

Hello, my fellow mad scientists. If you attended my talk at Showdown at Unobtanium, thank you for being part of a fantastic audience—the enthusiasm you fed back to me was infectious and inspiring. Make things and tell me about it!

Please join us at Polyglot Programmers of Austin,  our co-working study group for learning a new programming language (including your first). Breadboards are as welcome as keyboards. Also, I'll be there, happy to answer your Arduino questions.

Some details about my small robot friend, to amuse you. My costume was an homage to Agatha Clay (and her clank) of the Girl Genius comic book. I posted some pictures of the clank's construction process. What makes it fidget is a servo motor on its back, driven by an Arduino in my purse, running an Arduino sketch I wrote (source code).

You might appreciate the Nerd Nite wrapup from the last time I spoke on this topic. There are useful links in there, pertinent to the presentation you saw at the Showdown, specifically the slide deck that contains links to resources for learning more.

Some of you talked to me about presenting to your students at your schools. Yes, please! Get in touch.

Thanks for being awesome. Make fantastic things.

Hello, Nerds. Hello, World. Hello, Arduino.

Thank you to Nerd Nite Austin for a fantastic venue, and my thanks to all of you who were there, creating a palpable enthusiasm for Making Stuff! What a hoot. Resources for ya...

The slidedeck: Hello, Arduino

Samples of my Arduino code are on GitHub, because I like to think out loud in code.

A description of the blinky-eyeball Halloween costume

That "hang out and code with other people learning to code" study group is Polyglot Programmers of Austin, our next meeting is tomorrow, and you should totally join us.

Lest you need some motivation for making nerd presentations of your own, check this out. Some months back, I presented at a Dorkbot meeting at the ATX Hackerspace. Afterwards, someone approached me with "I don't know if you remember me, but..." And kapow! Timewarp! Here was my friend from nerd camp, whom I hadn't seen in 20 years! Wow! We've had a blast catching each other up. Then, I'm presenting at Nerd Nite tonight, and after that, another friend from nerd camp comes up and says hello.

Dude, I'm telling you. Take your awesome hobbies, go to nerdy things and present your awesomeness, and fantastic nerdy friends whom you miss will discover you and reconnect with your life. What a delightful unexpected benefit.

Running JavaScript... With Sneakers!

Code-review time. I haven't written significant JavaScript in forevs, but I hit upon a use case well suited to it, had a blast coding it up, and am confident that I'll be completely mystified by it three months from now. That is, unless we refactor it for maintainability (this is where you come in).

I'll explain the use case. The Couch-to-5K running plan is an excellent exercise regimen for learning to run. I followed it to successfully transform myself from sedentary software developer to 5K finisher. The runners among you know that five kilometers is a beginner-level distance; the sedentary software developers may find it as daunting as I once did. You train in intervals, alternating walking and running, gradually shifting the ratios to more running in successive workouts. If you can walk a moderate distance, following the program is totally doable (or modify it for easy walking/fast walking, if you're not up for jogging). Definitely check it out.

The thing is, timing the intervals—especially at the beginning, where you're alternating a minute of running with 90 seconds of walking—needs a complex timing device (a fancy runners watch), and if you're using a treadmill, it is really annoying to your fellow gym users, as your watch is beeping every minute or two. Or, well, maybe gym people don't care, but it's really annoying to me, since the dang thing is on my own wrist. For running indoors, I want a C25K timer that is tactile or visual. I've been thinking about an Arduino-powered timer that reads from a dip switch to determine which workout you're running and signals the changes with a vibration motor (like in a cell phone). Thinking, and not so much doing. Finally one Sunday I forced myself to focus on the problem: what do you have, with a visual display, that is really small and runs code?

My Nokia N810 internet tablet has a web browser that runs JavaScript, can open html files stored locally, and can do this while also playing a podcast. Win!

Here's what you can't do with JavaScript, though: Thread.Sleep(walkInterval). Instead, you use setTimeout() to say "execute this function after this interval," asynchronously. That's the part that currently works but I daren't touch it. In other words, that's the part that needs your code review advice. Remember that the intended scenario is to rest the tablet on the treadmill's magazine lip, so the app flashes the background of the page to catch my eye when I'm not looking directly at it. It's high-contrast because it isn't meant to be watched, just kept at hand, in my periphery.

If you choose to use the app (in addition to reviewing it), please only use it on a treadmill. Stay safe; don't try to wrangle something you need to look at while you're on the trail.

The Running Timer code is on github. A representative sample is below. How would you make it better?

var exercise = function(setup) {
 var workout = getWorkout(setup.week, setup.day);
 doExercise(workout, 0);
}

var cooldown = function() {
 walk('Cool Down');
 window.setTimeout(function() { transition(function() { walk('Done!'); })}, 
  minToMilli(RT.cooldownDuration));
}

var doExercise = function(workout, i) {
 workout[i].mode();
 if (i === workout.length - 1) {
  window.setTimeout(function() { transition(cooldown) }, 
   minToMilli(workout[i].minutes));
 } else {
  window.setTimeout(function() { transition(function() { doExercise(workout, i + 1); })}, 
   minToMilli(workout[i].minutes));
 }
}

var getWorkout = function(week, day) {
 return eval('C25K.W' + week + 'D' + day);
}

var transition = function(callback) {
 var indicatorDiv = $('.runCountdown');
 var body = $(document.body);
 transitionBlink(6, indicatorDiv, body, callback);
}

Microcontroller Projects and Source Code

Welcome, Ignite/Dorkbot Science Fair Party Goers. Here are details on the two projects I had with me at the Science Fair.

I used the open-source Arduino microcontroller. Arduino programs are called "sketches." I keep my Arduino sketches on the collaborative source-code repository GitHub, in my Arduino-Sketches repository. You can browse the code in a web browser without installing Git, so go check it out. And then learn Git and post your own sketches.

Ambient Clock

The Ambient Clock is an information radiator for the passage of time. It was written up on the Makezine blog. (pictures | program)


Blinky Eyeball Halloween Costume

The Blinky Eyeball Halloween Nightmare is, um, pretty self-describing. (write-up | pictures | program)

Happy Hack-o-ween: Electronics and a microcontroller spice up the haunt

Ah, Halloween, when a young woman's fancy turns to love. And zombies.

I had two personal requirements for the costume I would build this year:
  1. It shall be spooky.
  2. It shall blink.


I'll tell you about the final result, the electronics and the software that went into it, plus the techniques I used to achieve wearable electronics. I'll introduce you to the Arduino, an open-source microcontroller prototyping platform, which is an exhilarating tool/toy for making your software skills manifest in the physical world.

My husband and I have been teaching ourselves electronics. A few months ago, Dad taught me to solder. I recently read Syuzi Pakhchyan's excellent primer on wearable electronics and smart materials, Fashioning Technology. And I've been making things with my Arduino. All these ideas were swirling and combining in my head to inspire this year's Halloween project. Er, costume. Same difference.

What was I? I was a nightmare... the thing under your bed... the reason for your well developed sense of paranoia...
The thing under your bed

I sported a crop of writhing eyeballs erupting from my head. Each eyeball has an LED inside it, and they blink randomly and independently, until I trigger a hidden switch, which causes the blinky ones to go dark and two red eyes to pulse menacingly. In the Flickr photoset, you can see the construction process.

The Arduino Sketch


The term "Arduino" is overloaded to mean:
  1. a particular chip and circuit board which you can buy or build;
  2. the IDE in which you write programs for the chip;
  3. the language, which is C-flavored;
  4. fun.


Arduino programs are called sketches. Every sketch must contain two functions: setup (runs once) and loop (runs continuously). Here's my sketch, with extra explanatory comments, that blinks the six regular eyeballs and responds to the switch by pulsing the red eyeballs.
    1 #define SWITCH 8
    2 int ledPins[] = {2, 3, 4, 5, 6, 7};
    3 const int ledPinsCount = 6;
    4 int redEyePins[] = {10, 11};
    5 const int redEyePinsCount = 2;
    6 long durations[ledPinsCount];
    7 int ledStates[ledPinsCount];
    8 long previousTimes[ledPinsCount];
    9 int i;
   10 
   11 void setup()
   12 {
   13   pinMode(SWITCH, INPUT); //Specify the switch pin as an input.
   14 
   15   for (i = 0; i < redEyePinsCount; i++)
   16   {
   17     pinMode(redEyePins[i], OUTPUT); //Specify each red-eye LED pin as an output.
   18   }
   19 
   20   for(i = 0; i < ledPinsCount; i++)
   21   {
   22     pinMode(ledPins[i], OUTPUT); //Specify each regular LED pin as an output.
   23     ledStates[i] = random(1); //Randomly set the LEDs to on or off (1 or 0).
   24     durations[i] = GetRandomDuration(); //Define a random duration for each LED to stay in that state.
   25     previousTimes[i] = 0; //At time of setup, the "last time we changed" is at 0 milliseconds, the start of time.
   26   }
   27 }
   28 
   29 void loop()
   30 {
   31   if (digitalRead(SWITCH) == HIGH)
   32   {
   33     TurnOffLeds();
   34     PulseRedEyes();
   35   }
   36   else
   37   {
   38     for(i = 0; i < redEyePinsCount; i++)
   39     {
   40       digitalWrite(redEyePins[i], LOW); //Turn the red eyes all the way off.
   41     }
   42 
   43     for(i = 0; i < ledPinsCount; i++) //For each LED:
   44     {
   45       if (millis() - previousTimes[i] > durations[i])
   46       {
   47         ChangeLed(i); //If this one's duration is up, then flip it.
   48       }
   49     }
   50   }
   51 }
   52 
   53 void TurnOffLeds()
   54 {
   55   for(i = 0; i < ledPinsCount; i++)
   56   {
   57     digitalWrite(ledPins[i], LOW);
   58   }
   59 }
   60 
   61 void PulseRedEyes()
   62 {
   63   //Fade on, then off.
   64   int j;
   65   for(j = 0; j < 255; j+=5)
   66   {
   67     for(i = 0; i < redEyePinsCount; i++)
   68     {
   69       analogWrite(redEyePins[i], j);
   70       delay(10);
   71     }
   72   }
   73   for(j = 255; j > 0; j-=5)
   74   {
   75     for(i = 0; i < redEyePinsCount; i++)
   76     {
   77       analogWrite(redEyePins[i], j);
   78       delay(10);
   79     }
   80   }
   81 }
   82 
   83 void ChangeLed(int ledPin)
   84 {
   85   previousTimes[ledPin] = millis(); //Update the "last time we changed" to now.
   86   durations[ledPin] = GetRandomDuration(); //Give it a new random duration.
   87   ledStates[ledPin] = 1 - ledStates[ledPin]; //Flip the state between on and off.
   88   digitalWrite(ledPins[ledPin], ledStates[ledPin]); //Set the LED to that state.
   89 }
   90 
   91 long GetRandomDuration()
   92 {
   93   //Random number between 1 and 10, then multiplied by 400 to give it a detectable duration.
   94   return random(1, 10) * 400;
   95 }


I like the way the eyes blink independently. If they all flashed in unison, they would look like Christmas lights, and you would notice that two were "special" because they weren't flashing. Instead, the duration that any given eyeball is lit or dark constantly changes.

The blinking is managed by a collection of arrays. One array represents each of my LED pins, so that I can address them in a for loop. The three other arrays hold: the state (on/off) of each LED; the duration each LED should stay in that state; the reading from the millisecond counter when the LED last flipped its state. Each time the loop function executes, if the switch is not connected, then I look at each LED; if the difference between the current time and the time when it previously changed is greater than its duration, flip its state (from off to on, or from on to off), randomly assign it a new duration, and record "now" as the new "previously changed" time. If the switch is connected, then I make the red eyes fade on and fade off.

Fading with PWM


PWM (Pulse-Width Modulation) is a technique for making a digital component (one that turns on or off) simulate analog behavior (be a little bit on, and then a little bit more on). If you turn an LED off and on really quickly, you won't perceive the flickering, but it will look half as bright, because it is actually off for half the time. If you let it spend a little more time off than on, it will appear even dimmer. So by varying the width of the pulses, you can control how bright the LED looks.

The Arduino comes with built-in PWM functions; some pins are already set up to be PWM pins. If you plug an LED into one of the PWM pins, then you can write to it as if it were an analog component. That's why, in my sketch above, I set the brightness of the red eyes using analogWrite(), instead of digitalWrite(). My for loop increments the counter j from 0 to 255, and sets the brightness of both red eyes to the value of j. The Arduino takes care of (imperceptibly) flickering the LEDs with the right ratio of on-time and off-time to achieve a j amount of brightness. So the eyes get gradually brighter, then gradually dimmer. (Then control returns to the main loop function, but if my switch is still connected, the red eyes will throb again.)

Snaps: Wearable Plugs


A metal sewable snap is like a plug for your clothing, an interface between the world of textiles and the world of wires. This is handy when you need the electronics to be separate while you are getting into the clothing, or if you want to wash the clothing. My Arduino hung out at the base of my neck, to be near the LEDs on my head but hidden underneath my wig, but my control switch was near my hip. I could have run a wire down to the switch, but conductive thread was more subtle and more comfortable.

To complete the connection, I soldered a short wire to one side of the snap. That wire plugged into a pin on the Arduino. The conductive thread ran from the switch at my hip up to the back of my dress near the Arduino, and I sewed that conductive thread to the other half of the snap. When the two halves are snapped together, the wire and the thread make a complete connection, as if they were one continuous wire.
Soldered snaps / Sewn snaps

I had two threads (going out to the switch and back), so I encased them each in a bias tape tube, to prevent them from touching each other and shorting out.

I've been saying "switch," but actually, I simplified at the 11th hour. I tied each thread around a safety pin, and stuck the pins to my dress. When the safety pins touched each other, they completed the circuit, which the Arduino sketch interpreted as triggering the switch—cue red-eye glare.

What's Next


Soldering and sewing are both liberating skills to possess—they free up your creativity to make wilder and more integrated stuff. If you are currently proficient with only one, ask around and see if you can find a buddy who's good at the other, and teach each other.

The Arduino comes with a great community of hackers and makers, lots of people to learn from and collaborate with. Definitely check it out. There is lots of fun to be had, and blinking LEDs is the barest beginning of what it can do.