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

Friday, May 26, 2017

Head Move Donkey V02: progress


After this post on my donkey update I learned some things, much of it from Adafruit Support on the forum in this thread.

First I was concerned with a statement in the MusicMaker Learning Guide "Don't forget to make sure you have a good strong 5V power supply - especially if you're using the 3W 4 ohm speakers! " It turns out that I was able to do what I needed with the 3.7V LiPo--I noticed no difference in output using the 5V 2A  wall wart.  I was even able to run everything off the 4xAA battery pack (using NiMHs only give 1.2V each, 4.8V total).  However, when I added the second Servo. I needed 2 power supplies.

Second I had trouble getting decent volume from an 8Ohm .5W speaker. I was directed to use 4Ohm 3W speakers.  I tried an 8Ohm 2.5W speaker I took out of a CRT television amd that was fine, but it's too big for the donkey.  I got some 1.25" 4Ohm 3W speakers off ebay, but they did not produce enough sound.  The smaller Adafruit version did the trick.

Third, I cooked an SD card and a MusicMaker.  I think it was while I was experimenting with power options...I may have mis-connected something.  First symptom was that it could not initialize the SD card.  I replaced it, and it got past initialization and said it was playing music but it wasn't.  Back to Adafruit for replacement board.

The reason for the second Servo is that I decided to move the donkey's tail, too.  I move the Servos in opposite directions, just because for grins.

Here's my appearance with the project on Adafruit's Show and Tell. I'm on from about 11:30 to 14:00.




Monday, May 1, 2017

Head Move Donkey V02 in-process


Adafruit Feather M0, with MusicMaker and PWM/Servo FeatherWing stacked, running the Head Move Donkey code: plays
"Donkey Serenade" while moving the servo about 60 deg right and left to move the head.
As described in detail in this post, I recreated a wind-up toy that I bought for my daughter (an infant in 1978) with a Pro Trinket 3V and other components.  In the 2.5 years since, I've gotten a little smarter and the available technology has gotten a lot better, so I thought I'd try a version 2.  The biggest difference is that I needed fewer components. 
Donkey V01 
In the original, I needed an SD card reader, an amplifier, and a PWM/Servo Board. I still need those things, but the Adafruit Feather System makes it a lot simpler, eliminating most of the wiring and some of the code.  Also the Feather uses a ATSAMD21G18 @ 48MHz with 3.3V logic/power and 256KB of FLASH + 32KB of RAM while the Trinket uses the ATmega328P  at 12MHz with 28K of flash, and 2K of RAM...so, the M0 is much more powerful.

Power management is slightly different. I was able to power the Trinket from a 4xAA battery pack, using the 3V output to power the SD card and the 6V to power the Amp and servo driver.  Logic levels were not a problem.  I power the M0 from a 3.7V LiPo and the Servo Wing from the 4xAA--again, the Servo is forgiving with respect to logic levels.  I probably should have had separate power sources in V01. One twist is that I'll need a DPST switch to turn on both power sources together.


Donkey V02 Circuit Working


Next steps are to construct and enclose the completed circuit and re-stuff the donkey.  Since the enclosure will be smaller, I'm going to try to get the batteries inside the donkey this time.
Fritzing Diagram of Circuit

Wednesday, November 9, 2016

Halloween Candy Cauldron V3.1

V3.1 in the enclosure. Ignore the external speaker--it's a vestige. Ready to tidy up for V4.
As I said in my last post on this project, all that was left to do was tidy up the connections and enclose the electronics. I decided that the enclosure I was using was too big. The reason it was too big was that I had the project on a breadboard instead of soldering the components to a PCB. I have always wondered why places like Radio Shack that sell enclosures and PCBs don't sell PCBs that fit in the enclosures--with mounting holes and screws.  So, I went looking and found this enclosure with matching PCB and a battery compartment. A little pricey, but good quality and they have a variety of sizes and features. (I'm using the term PCB to include proto boards here.) Follow-up note: I found that the soldering pads on the pcb were insufficient.  I'll accept blame for my soldering technique, but I had more trouble with this than any other I've worked with.

Since the new enclosure was a little smaller, I decided to use an  +Arduino Pro Mini (actually an Arducam clone) instead of the +Adafruit Industries Pro Trinket.  It's a little smaller, and I had a few in inventory. It needs an FTDI to serial module to program, but I was using one anyway for the Trinket to be able to use the serial monitor.

The code compiled with no changes.  (See link to last post in opening sentence to see code.) In order to upload to the board, the IDE required some changes (to point to the right board--Nano, not mini), and the USB Port needed a tweak in Windows Device Manager (I'm on Windows 10). Arduino.cc has a clear and concise getting started article describing this better than I can.

Interrupt

Note that the interrupt code also works as-is.  I need to work on the program to make the sleep more useful. As you can see in the video (the blue LED is on when it's sleeping), it doesn't sleep much, I'm using the Echo pin on the HC-SR04 sensor to wake it up. I put it to sleep at the top of the loop, then wait for Echo to go LOW or HIGH. It works the same either way, at least to the naked eye.

I used LOW because IDLE is the only mode that can be woken from anything other than LOW, and I wanted to be able to play with other modes. I'm thinking about using an inverter so I can set the interrupt on LOW, but have the pin go LOW when the Echo pin goes HIGH. +Home DIY Electronics has a good article on interrupts and the HC-SR04.

Since the sensor is ranging constantly, it wakes up pretty quickly. If I try to put it in power down mode, it does not wake up (maybe because the sensor shuts down?):  The LED indicating sleep stays on and no gesture will wake it up. There are 5 sleep modes and these are only the 2 extremes. I will play with some of the intermediate modes--next year, or the next time I'm playing with interrupts on an AVR board.

Construction
  1. Test the mini
    Since I changed boards, I needed to upload the code, wire the circuit on a breadboard, and test. As described above, all was well.
  2. Prep the enclosure
    In this design, the speaker and the battery are now inside the enclosure, I only need holes to bring in wires from the switch and from the HC-SR04. I also drilled 7 holes to let the sound out, places where I planned to put the speaker.
  3. Design the board layout
    I needed to mount the Pro Mini, then find room for the amplifier and Micro SD Reader.  This required some planning, so I simulated with header pins on the PCB and marked where I would place the components.  All the components had male headers attached, because I originally set set this up for a breadboard, so I soldered the headers to the printed side of the board.
  4. Wire the busses
    I created power and ground busses on the inside edge of the board, next to the battery, using tinned copper bus wire. The board has pairs of adjacent rows of connected holes, so I used two of these pairs (one row for each bus, each adjacent row for connections to the circuit).  The power rail is supplied from the voltage regulator circuit 5V output, and the ground from the 9V battery's negative lead. The positive lead from the battery goes to a 2-wire JST connector, which mates to another connector with leads going to a toggle switch. The other lead from the case (with the + from the battery) is the 9V input to the voltage regulator.
  5. Test the Voltage Regulator Circuit
    Since I have habit of messing up connections, and power is a key part of this, I wanted to be sure that I was getting 5V out of this part of the circuit before completing the soldering. When I got it right (after some stupid soldering tricks), I was ready to move on.
  6. Mount the components
    All the components had male headers attached, because I originally set set this up for a breadboard, so I soldered the headers to the printed side of the board. I also added an LED and resistor for visual representation of the sleep mode (the code for this was already included, so what the heck).
  7. Test the circuit
    Before fastening the circuit board to the enclosure, make sure everything works.  Here's where I ran into trouble.  I worked the continuity function of my multi-meter extensively. I thought I had everything in order, but it failed. I went back to a version of the sketch that had serial commands for testing in it, and saw that the SD board was not initializing.  I rechecked the connections, checked the SD card to see if it could be read, and then got drastic:  clipped the jumpers from the mini to the SD reader, and connected them via alligator leads to another reader.  Still not initializing, so I was pretty sure it was my connections.  One more continuity test revealed a problem with one of the jumpers. I re-soldered, put it back together, and it worked. Stupid soldering tricks, indeed!
    Working circuit, mounted. Clockwise from upper left: Adafruit Class D Mono Amp (wires to speaker), voltage regulator circuit, indicator LED and resistor, Pro Mini, Micro SD Card Reader. Yellow and green wires go to HC-SR04, red and black wires on right are power to HC-SR04 (red and black) and from 9V battery and switch (black and gray). 
  8. Put it in the box
    See photo at the top of this post.  Enclosing was a matter of adding screws in the prepared holes to secure the PCB, then passing the 4 wires to the HC-SR04 through one hole and the battery connection through another, position the speaker under the holes, and closing the box.
  9. Video
    Available on Youtube (my channel)



Wednesday, October 19, 2016

Halloween Candy Cauldron V3

Cauldron V3 in-process.
The large speaker will be removed--replaced by the small green on in the enclosure.
The red FTDI Friend and USB cable are there for programming.
We'll shorten the wires, neaten it up, and put the cover on the enclosure.
The red LED is for testing--turned on before sleeping, turned off on waking.

When last we looked a this (last Halloween), I was having trouble making the electronics small. To recap, I started out with an +Arduino Uno, an SD card shield, +Adafruit Industries class D mono amp, and an HC-SR04 Ultrasonic Sensor.  Then someone reaches in to grab a piece of candy, the sensor reacts, code on the arduino then chooses one of nine sounds to play, via the amp and an 8 Ohm speaker.

Objective

The big issue is that the electronics are loose in the bottom of the cauldron, so I wanted to use a smaller board and smaller SD breakout (like a MicroSD), and put the whole thing in an enclosure. I tried the Adafruit Pro Trinket 5V last year and ran out of time before I could get it to work.

Turns out this was a stupid wiring trick. The circuit is powered by a 9V battery, run through a 7805 5V Voltage Regulator circuit.  The dumb thing I did last year was connect the BAT pin on the Trinket to the battery.  I'm not sure what, if anything, else I did wrong (I may have also connected that same pin to the 5V rail), but this year I connected the BAT pin to the 5V rail. Last year I got only static, this year it works. In both cases I powered the peripherals from the 5V rail (output of the VR circuit), to provide enough current, since the Trinket's 5V pin provides 150mA max.

Further, I wanted to put the Trinket to sleep while waiting for trick-or-treaters to save battery.

Video

Interrupts

Sleep mode turned out to be simple, but required some learning.  As described in this post on interrupts on the M0, I just completed my first successful Arduino project using interrupts.  So, I started with a __WFI(); instruction to wait for an interrupt. It turns out that different processors use different instructions, since interrupts are so hardware dependent, so this did not compile.

My main source of information was here. The avr\sleep.h library (which does not work with the M0), was the key, since the main differences between the 2 processor families is how you put the processor to sleep, and the sleep modes. On the M0, the top of loop tested to see if one of our interrupts had been fired, and if not issued a wfi--back to sleep.  If so, go on to process In the case of the Trinket, also at the top of loop, we attached the interrupt, enabled sleep, went to sleep, and on waking, disabled sleep and detached the interrupt. The code:
//*****sleep**************************
    digitalWrite(ledPin, HIGH);  //turn on the LED (testing)
    attachInterrupt(digitalPinToInterrupt(echoPin), echoISR, HIGH); //attach interrupt
    sleep_enable();          // enables the sleep bit in the mcucr register
    sleep_mode();            // here the device is actually put to sleep!!
//***********************************/

//wait here for echoPin interrupt--ignore all others
//*****wake up************************
    sleep_disable();         // first thing after waking from sleep: disable sleep...
    detachInterrupt(digitalPinToInterrupt(echoPin));      // disables interrupt because pin stays high
//***********************************/

echoPin is Trinket pin 3, the only one that sees interrupts
echoISR just sets a volatile boolean, handIn
The next code tests handIn to see if it was set, meaning that we woke up because of the interrupt we care about, then goes on to reset the boolean and process.

In set up, we enabled interrupts ("interrupts();") and set the sleep mode ("set_sleep_mode(SLEEP_MODE_IDLE);"). According to the article cited above, IDLE is the only mode that can be awakened by a mode other than LOW, and I thought since we want to be interrupted when echoPin goes HIGH, we're stuck with it, even though it saves the least power of all modes.

However, some experimentation yielded that LOW works similarly to HIGH on the attachInterrupt.  I tried SLEEP_MODE_PWR_DOWN, AND it seemed to sleep a little more, but the board hung with regularity, so I went back to IDLE.

I'm sure there are more and better ways to do this, but this is working for me.

Other Enhancements

I was never happy with how the code looked, There's a lot of function-specific processing that made the loop long. So, I broke out the code to calculate the distance based on the sensor pin values and the code to choose which sound to play and put them in functions.  Not rocket science, but good programming practice.

I replaced the 3.5" speaker with a 1.5". That allowed me to enclosed the speaker in the box, reducing wires. I also made it a little quieter--young trick-or-treaters don't like the loud version. Yes I know I can control the volume on the amp, but this works well.

Fritzing Diagram


Code

/*2014-10-05 Virgil Machine Halloween Candy Dish: Play random sound when kid (or greedy adult) reaches into bowl

2016-10-18 V3 VM  never got Trinket to work last year, this week I did (stupid wiring trick)
 also replaced external speaker with a 1.5" that dit in the enclosure
 Added interrupt  handling to put it to sleep to save battery (thanks to http://playground.arduino.cc/Learning/ArduinoSleepCode)
 had  to change echoPin to #3--only pin on Trinket that is interruptable; changed trigPin to 4 to be
side-by-side for wiring, added ledPin for testing
Also, put the song selection/playing and distance calculation code in functions to make loop more readable.

2015-10-14 V2 VM change to Pro Trinket from Uno to put the circuit in an enclosure
 Echo to 6 (Pro Trinket does not have pin 7)

2014-10-05 VM HC_SR04 Distance sensor code added
Neeed to modify pins for Halloween (13&12 used by SPI)

2014-04-26 VM Downloaded from Instructables
 HC-SR04 Ping distance sensor]
 VCC to arduino 5v GND to arduino GND
 Echo to Arduino pin 13 Trig to Arduino pin 12 (used 8&7 instead--need SPI pins for SD reader)
*/

/******* see virgilmachine.blogspot.com*****/

/*includes*/
#include    //SPI library
#include     //SD card library
#include //library for playing sound
#include  //sleep functions
#include  //interrupt functions

/*constants*/
#define SD_ChipSelectPin 10
#define echoPin 3 //so we can have an interrupt (D3 is the only one)
#define trigPin 4 //to be next to echo for wiring
#define ledPin  5

/*variables*/
int song = 0;   // song number for random function
volatile boolean handIn = false; //variables in ISR need to be volatile
/*objects*/
TMRpcm speaker;   // create an object for use in this sketch


void echoISR() //ISR for distrance sensor
{
    handIn = true;  //someone put his or her hand in
}

void setup(){
  randomSeed(analogRead(0));  //initialize random (A0 unconected)
  pinMode(trigPin, OUTPUT);   //pins for distance sensor
  pinMode(echoPin, INPUT);
  pinMode(ledPin, OUTPUT);   //LED fot testing
  digitalWrite(ledPin, LOW);  //default to off
  speaker.speakerPin = 9; //output to amp
  speaker.loop(0); //2014-10-05 do not play repeatedly
//  Serial.begin(9600); //Serial is for testing--comment to reduce time/power consumption
  if (!SD.begin(SD_ChipSelectPin))
     {  // see if the card is present and can be initialized:
//Serial.println("SD not initialized");
      return;   // don't do anything more if not
      }
//   else
//      {
//       Serial.println("SD initialized");
     //
//     }  
  speaker.volume(1);
//  speaker.setVolume(7);   //attempt to increase volume

interrupts(); //enable interrupts (should not need to do this, but just for drill...)
set_sleep_mode(SLEEP_MODE_IDLE);   // sleep mode is set here
//set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // PWR_DOWN hangs periodically
}

void loop() {

//*****sleep**************************
    digitalWrite(ledPin, HIGH);  //turn on the LED (testing)
    attachInterrupt(digitalPinToInterrupt(echoPin), echoISR, LOW); //attach interrupt
    sleep_enable();          // enables the sleep bit in the mcucr register
    sleep_mode();            // here the device is actually put to sleep!!
//***********************************/

//wait here for echoPin interrupt--ignore all others
//*****wake up************************
    sleep_disable();         // first thing after waking from sleep: disable sleep...
    detachInterrupt(digitalPinToInterrupt(echoPin));      // disables interrupt because pin stays high
//***********************************/
  while (handIn) {   //someone wants candy, hcsr04 interrupted
    digitalWrite(ledPin, LOW);  //turn off LED (testing)
    handIn=(!handIn); //reset the boolean
//2014-10-05 If distance is <8in cm="" hand="" his="" in="" nbsp="" p="" put="" someone="">//2016-10-18 (the getDistance function calculates that)
    if (getDistance() < 20)
    {
      playSong(); //function to select and play a random song
    } //distance
      delay(2500);  //give the song a chance to play
  } //while

} //loop

void playSong() {
        song = random(1,10); //get random number from 1 to 9
//      Serial.print("song: "); //for testing
//      Serial.println(song); //for testing
      switch (song) {
        case 1:
          speaker.play("1.wav");
          break;
        case 2:
          speaker.play("2.wav");
          break;
        case 3:
          speaker.play("3.wav");
          break;
        case 4:
          speaker.play("4.wav");
          break;
        case 5:
          speaker.play("5.wav");
          break;
        case 6:
          speaker.play("6.wav");
          break;
        case 7:
          speaker.play("7.wav");
          break;
        case 8:
          speaker.play("8.wav");
          break;
        case 9:
          speaker.play("9.wav");
          break;
      } //switch/case
} //playSong

long getDistance() {
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
//trigPin must me high for 10 microsecs to do ranging
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
//duration is the time between pings of the sensor  in microseconds as returned on echoPin
  duration = pulseIn(echoPin, HIGH);
//duration is a round-trip, so divide by 2; speed of sound is 29.1 cm/microsec, so distance is in cm
  distance = (duration/2) / 29.1;
  return distance;
} //getDistance  


Saturday, March 26, 2016

Adafruit OLED display on Arduino

I have been neglecting my Arduino interests in favor of amateur radio recently. So, I bought a book "Arduino for Ham Radio."

One simple project to get me started is a compass display.  The book call for a LCD module, which I have, but I also have an +Adafruit Industries OLED 128X64 display that I haven used yet.  So, I dug it out, soldered on the header pins, downloaded the Adafruit libraries, and uploaded an example to an +Arduino Uno clone that I had lying around.  I'm now sensitive to clones, and from now on will only by genuine Arduinos, but since I had this one I used it.

I made one small change to the program, just for grins:  changed "Hello World" to "Hello Town" and passed that message as a variable rather than a literal. No big deal, but I'm refreshing my Arduino skills.

I have ordered the compass module--after I get it I'll finish the project and post results here.

Here's a video.

Saturday, October 10, 2015

@Make: Electronics Experiment 33 - Moving in Steps

This chapter ends with the concept for another robot, this time one that responds to light with photoresistors. I decided not to go all the way with that, because I just spent a whole lot of time on the last cart (much of it on fabrication), and because I plan to follow Charles' upgrade of Experiment 32 as published in Make Magazine (March 2015).

Actually, I had a little trouble with this. First, Charles said to use 12V motors, and I could only find 5V.  I found a set of that came with UL2003A driver boards on Amazon. I did not get the results I expected on the breadboard just using LEDs...I expected to see the cycle of pulses repeat, but it only did one cycle at a time.  I checked the connections many times, with no success.  This particular breadboard has been flaky in the past, but I'm, not willing to rewire the whole thing.

I drove the stepper using an Arduino Uno and some code I found in a tutorial on Instructables.

I made a video.

On to the Picaxe in Experiment 34!




Monday, August 24, 2015

+Adafruit Neopixel Tiara on an Actual Tiara- Almost Built

Design change:  I have ruled out the CR1220's (not enough battery life, too hard to change), and the CR2032's (too bulky). +Becky Stern  was trying to push me towards a LiPo battery, and I resisted...but finally realized she is right. The 100mAh version is small and the right size to fit the tiara.

I sewed eacghneopixel to the tiara using silver
thread.  Here's the first, ready to go..
The "V2" on the back side happens to be on the
"data-in" pin, so I started there with each one.
Here's the tiara with pixels shown. I'm still have to clean up the stray threads.
The sewing took me an afternoon (not an expert), but I got it done and it's not too ugly.

Next I soldered the neopixels together (+ to +, - to -, DO to DI), then connected the Gemma to the first neopixel for a test, using alligator test leads--see the video. The soldering took a couple of hours. For each wire, I used calipers to measure the distance between neopixel pads, stripped 14", marked the desired length of unstripped wire (from the calipers), cut the wire 1/4" beyond, and stripped 1/4" off that end.

I did the data bus first, and used stranded wire.  That turned out to be a huge pain--it's too flexible and the ends are hard to deal with.  I switched to 22awg solid core wire for the power and GND busses. Much easier.  I will go back to stranded when I wire the Gemma, because I will need the flexibility.

Also, I discovered (or remembered, not sure which) that Gemma has an on-off switch on board.  That simplifies this circuit (I don't need to add a switch).

Next:

  • trim stray threads and wire to clean up as much as possible
  • re-sew at least one of the neopixels (some threads got burned during soldering)
  • secure and insulate the threads and wires with nail polish
  • add the 100mAh battery
  • glue the Gemma to the tiara
  • solder the Gemma connections to the circuit, attach the battery to the tiara.


Parts list:

Saturday, August 22, 2015

+adafruit Neoplxel Tiara on an actual tiara

This is an ongoing saga. I got the idea to put the neopixel tiara on an actual tiara for my granddaughter's Nursery School graduation in June. I could not find a suitable plastic tiara, and the the metal one I built needed so much insulation that it was ugly. Also, the Gemma and battery back make it unwieldy for a 5-year-old. Here's a video:



I found some plastic tiara's that are not great but the may do the rick. Here's a photo comparing the two:

I took the metal one down for her graduation, and I brought my spare, unwired.  She wore the plain tiara all day every day, but was not impressed by my circuit--as I said, ugly and unwieldy.So, back to the workshop. I'm planning something for her 6th Birthday this Fall.

I got lots of help from Becky Stern of Adafruit, on air on Wearable Wednesday, and on the Adafruit Support Forums. The code is the same as my Twinkling Daffodils, except that I use a different pin on the Gemma than I did on the Trinket for the Daffodils (convenience).

I took out another Gemma and programmed it.  BTW, since I last worked on this the Arduino IDE wend from 1.6.3 to 1.6.5.  I had 1.6.4 installed, with the Adafruit boards added in.  After I upgraded to Windows 10 last week, I upgraded the IDE to 1.6.5.  It was a completely painless upgrade.  I didn't have to reload any of the Adafruit stuff or any drivers, and Windows 10 did not interfere at all.

I plan to glue the Gemma behind the middle of the tiara, sew or glue the 6 neopixels in the loops (as in the metal one), and glue the battery pack to the front of the comb.  I can try CR1220s, but they will provide 40mAh.  With 20A for the Gemma and 20 for the neopixels (varyung colors and brightness and not on at the same time), they might last an hour.  (Thanks to Becky's tutorial on batteries.) The problem is that it's hard to change them.  I may have to glue a CR2032 battery holder, or maybe use the sewable holders.

Anyway, I have a fun project to work on while I'm doing the Robot Cart at the same time...and, Halloween is coming!

Saturday, May 16, 2015

Twinkling Daffodils Based on Adafruit Neopixel Tiara (As Seen On Adafruit Show-and-Tell)

This was a fun project.  The final tiara project its for my granddaughter's pre-school graduation. I would have done a mortar board, but I think it might be unseemly for a 5-year old to wear a tricked-out costume in her procession, so I decided on a tiara that should could wear at family events to celebrate her accomplishment.

Rather than the headband plus wires in the tutorial, I decided to buy a tiara and add the neopixels to it.  I looked all over Michael's, AC Moore, ToysRUs, Itzaparty, etc, and found nothing suitable, but I found this online and bought 2 so I'd have one for backup.

Meanwhile, I was preparing for our local "in-Bloom" festival and decided to see what I could do with fake daffodils. That same day (but I had the idea first) Wearable Wednesday had a floral bouquet project, so I knew I was on the right track. It turns out fake daffodils are hard to find, but AC Moore had a fake potted plant.

Here's what I bought to add neopixels to

I'm in this to learn, and I was not disappointed by this project.

What I learned (or at least some of it...some things re-learned)

Screen shot from video re tiara on a breadboard
That's a 3V Trinket with 4 neopixels connected to 3V pin on Trinket via breadboard
Powered by a DIY 5V regulated power supply
  1. See my post on setting up the neopixels on a breadboard...that was the initial test. I got it going with 4 neopixels, both a Gemma and a 3V Trinket, and some alligator clips
  2. I wanted to add colors to the code supplied.  The comments are pretty clear:  
    // Here is where you can put in your favorite colors that will appear!
    // just add new {nnn, nnn, nnn}, lines. They will be picked out randomly
    //                          R   G   B
    uint8_t myColors[][3] = {{232, 100, 255},   // purple
                             {200, 200, 20},   // yellow
                             {30, 200, 200},   // blue
                              };                   
    // don't edit the line below
    #define FAVCOLORS sizeof(myColors) / 3
    However, I was not sure about the  [][3] construct (i.e., not specifying one dimension of the array).  Some Googling revealed that if the array is initialized, the dimension can be omitted. This one is initialized, so all I had to do was  more colors (more rows of {R,G,B}). The comments in the example code say that, but not why.  I have been programming for 40 years in a variety of languages, so arrays are very familiar--sometimes I just have to learn the details to apply them with understanding. So, I added 5 colors.  
  3. The tiara example shows the neopixels powered from the 3.3V pin on the Gemma, and that works with both a Gemma and a 3V Trinket. The Adafruit Neopixel Uberguide says to always power neopixels separately from the power pin on the microcontroller, and that they need 5V. As far as I can tell the guide is accurate, but for projects using a few neopixels from a Gemma or 3V Trinket, powering from the 3.3V pin works. The guide also says not to use alligator clips, but I didn't have any trouble with them for testing.
  4. The Uberguide says to add a 1000uf capacitor across the + and - pins of the power supply, and also a 300-500Ohm Resistor between the data pin and the first neopixel.  I will reserve that knowledge for future projects. Becky's tiara tutorial does not mention this, and the circuit works without them. Just for grins, I will add the cap and resistor to the daffodil circuit.
  5. Further, the guide says that if you're using a 3V microcontroller and power the neopixels from a 5V supply, you need a logic level shifter. I decided to stick with the tutorial for the tiara (3V Gemma with neopixels connected to 3.3V and GND on the Gemma), but for the daffodils I will use a 5V Trinket to avoid the need for a level shifter, and power the neopixels from power rail. not the 5V pin on the Trinket. I was going to power the circuit from  my 5V regulated power supply, but that adds an extra component, so I'll just solder a barrel jack on the perma-proto and use a 5V wall wart (I'd need power anyway to power the 5V supply). I'm using the Adafruit Compact Switching Power Supply.
  6. After fussing with ideas about an enclosure, I decided that I didn't need one. The circuit is very simple, and I don't need a lot of internal connections. So, I'm putting it on a small mint tin size perma-proto, with a barrel jack for the connection to power. Since the power rails are down the center, I can place the trinket horizontally across the board, with the BAT and GND pins over the power rails, supplied by the barrel jack.  Since pin #4 is next to GND, I can modify the data pin in the code and connect DATA, GND, and Vcc to header pins to connect to the 3-wire connector and on to the daffodils.  That's it.  I will put 3/4" standoffs on the 4 corners of the perma proto to provide clearance.I don't need to solder anything other than the 3 wires to the Trinket...that will make it easier to reuse.
  7. Speaking of the 3-wire connector, I found some, labeled B2-2832, that I ordered a while back, I don't remember from where. Googling the number doesn't yield anything useful. Anyway, it simplified the wiring a lot.  I'll cut it in half, use the receptacle end to attached to  the Trinket pin and power rails, and solder the other ends to data. power and ground coming from the circuit.  I'll put the resistor in the connection on the data wire. 
  8. I had originally planned to put the neopixels inside the corona (trumpet part of daffodil). My wife, who understands crafty stuff better than I, suggested just positioning the neopixels outside of the flowers, to let flowers diffuse the light. This turned out to look better, and also simplify the project.  I would have had to clip out the flowery stuff inside the corona (fake pistil, stigma, and anther), poke holes in the corona for wires, and solder the inter-flower data wires and heat shrink on the flower.I made more work for myself because I started out with the original design in mind, but the tutorial reflects the improved process.

Finished Product

Parts, Supplies, and Tools

  1. Barrel Jack
  2. 5V Trinket
  3. 1000uf Capacitor
  4. 470 Ohm Resistor
  5. Breadboard (size not important, I used a half-size)
  6. Silicone-Coated stranded wire
  7. 22-gauge solid core hookup wire
  8. Heat shrink tubing
  9. 3-wire connector (optional, here's an example for illustration--or use what you have)
  10. header pins (also optional, but it made it easier for me)
  11. flora neopixels V2 (6) (I bought this sheet of 20--they also come in quantities of 4)
  12. small mint tin size perma proto-board
  13. 3/4 inch nylon standoffs & screws (4)
  14. 5V or switchable wall adapter
  15. Short alligator clips
  16. In-line power switch
  17. Fake daffodils in fake flower pot (you're on your own here--I found mine at AC Moore, try Michael's, etc.)
  18. Green florist's tape 
  19. Soldering Iron and requisite accessories--solder, stand, sucker, helping hands, etc
  20. Multimeter
  21. Flush Clippers
  22. Heat gun 
  23. If you really want to finish it off, put it in a suitable encosure and drill holes for power input and output to flowers--I did not do that

Construction/testing process

Note: this project could be accomplished without soldering, but it would not be as tidy, and you would need clips, and/or solderless wire connectors and/or a larger Arduio (like an Uno) to make connections via jumber wires. Making reliable connections to neopizels without soldering is tough. It's easy soldering, though.

1st neopixel soldered
Red to power, black to ground, white to data pin, yellow to next neopixel
Neopixels wired and ready for test

  1. See Fritzing diagram above.  The circuit is really simple, but the construction has a lot of steps, so...the first thing I did was verify that the above circuit works with a 5V Trinket, external power, and one neopixel.  (Note, this requires modifying the Adafruit NeoPixel_Tiara sketch to use just 1 neopixel.  See above for other possible changes--colors and timing, for example).
    That was fine, so I added the cap and resistor and that was also fine. As expected, but it's good to start with something that has been proven to work. Note that I recommend a lot of testing as you go through the project. It's a lot easier to find and fix problems as you build, rather than trying to figure out where you went wrong after the project is all put together.
  2. Next step, build up to a pre-assembly test.
    Solder + and - leads to neopixels in the lengths we'll need to go from the flowers to the circuit. Watch the data arrows on the neopixels--take care to match output of one to input of the next.
    Solder leads to BAT, GND, and pin 4 on the Trinket, in the lengths you'll need to connect to the perma-proto when you're ready.
    Using alligator clips, connect all the + wires to the power rail, all the - wires to the GND rail, the data wire to the resistor, and the other data wires to each other, and also to connect the Trinket pins to the + and - rails and to the resistor
  3. Fire up the circuit for a test (still on the breadboard). Make sure all the neopixels light up. If you want different colors, more or less colors, or different speed, change the code (see below). If it doesn't work, there are probably some missed connections or bad soldering.connections.  Check the direction of the arrows on the neopixel data pins. Keep the Trinket connected for the next test. Here's a video of this step.
  4. Now we're ready for the flowers.I had orginally planned to put the neopixels in then corona (the trumpet part).  My wife convinced me that the flowers diffusing the light would be a better effect, so I changed the design.
    Run the power wires, and the data wire to the 1st neopixel, down the stems and secure the wires to the stems temporarily. I used plastic twist ties. Continue the wires down the pot to join together in a common location at the bottom.Twist the + wires together for a power connection and the - wires together for the GND connection.
  5. Test
    Connect the flowers to the circuit on the breadboard again using alligator clips. If you left the Trinket connected it should be all set. Power it up verify and correct as before.
  6. Final Assembly
    a) Remove the alligator clips. [Making sure to check that the out arrow from one neopixel will be wired to to the in arrow of the next, put heat shrink wrap on one side of the data connection between flowers, solder the two sides together, move the head shrink over the connection and shrink with a lighter or heat gun.  Repeat for all 5 inter-flower connections. ] Not necessary if you connect directly, per new design.
    b) Solder the barrel jack to the perma-proto board. Plug the wall wart into the barrel jack and test the pins of the jack with a multimeter to be sure a) that the connections are sound and b) that you know which pin is + and which is -. With the multimeter on DC voltage, the reading should be about +5V. If it is not, there is a bad connection. If it says -5V, the meter leads are reversed.  Solder the + pin of the jack to the + rail (the one with the red line on it) on the perma-proto, and the - to the GND rail (blue line) using a short insulated wire.  The jack should be connected to holes that are part of the rail (i.e. with vertical interconnections--the first holes are not connected to the rail. (see photo)
    c) Solder a 3-pin header to horizontally across the power rails. One pin will be +, one -, and the one to the side of the rail will be connected to a perma proto row (holes horizontally interconnected).
    d) Solder one side of the 470Ohm resistor to the row the header pin is connected to, and the other side to the row to which you will connect the data wire (pin 4) from the Trinket.
    e) Solder the 1000uf capacitor across the power rail (watch the polarity: +pin to +rail, -pin to -rail)
    f) For stability, I attached a five pin long header with the plastic stopper above the perma proto through to female headers.  The holes that the top of the perma-proto are not connected to anything, and I did not solder this--it's just to hold the Trinket in place so I can reuse it easily.
    g) Place the top row of holes on the Trinket over the header pins from the last step. Solder the Trinket leads: BAT to + rail, GND to - rail, Pin 4 to the row the resistor is on.
    h) If the 3-wire connector has plugs.jacks at two ends, cut it in two pieces. You want the jack (female) end, so it will fit over the 3-pin header. Using alligator clips, connect the data, power, and ground connections to the 3-wire connector. Plug the connector to the header, and test. If there are problems, check all connections (and that you have powered the circuit).
    i) Using heat shrink wrap as with the inter-flower connections, solder and heat shrink the flowers to the 3-wire connector (taking care that the correct wires are connected).
    Here's a video of the circuit working from the perma proto...I just need to hide the wires and position the neopixels and finish soldering.
  7. Finish
    Test
    the final connection, and correct any problems.
    Remove the temporary twist ties, or whatever, from the stems, and wrap the wires and stems together with green florists tape.
    I wanted to be able to power on/off without unplugging, so I added the in-line power switch. I also added a second 3-wire connector as an extension.
    You're done

Bottom of perma-proto
Note vertical and horizontal connections

Top of perma-proto
Notte power rails in center

Perma-proto bottom, after soldering
Top view after soldering










Code (NeoPixel_Tiara by Adafruit, as modified by Virgil Machine)


/Random Flash animation for Neopixel circuits
//by Dano Wall and Becky Stern for Adafruit Industries
//based on the Sparkle Skirt, minus the accelerometer
/*2015-05-10 vm Daffodil project
Nneopixels in 6 of 11 fake daffodils in fake pot.
Designed for "Brewster in Bloom", advised by Becky's LED Bouquet project.based on the neopixel tiara project.
Uses 5V Trinket with pixels powered directly from power rails (not 5V pin on Trinket).
Powered by 5V Regulated power supply, which can be powered by wall wart or battery.
2015-05-10 */
#include <Adafruit_NeoPixel.h>

#define PIN 4  //2015-05-11 changed from pin 1 to pin 4 for ease of connection

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) 2015-05-10 vm we're using Flora neopixels v2
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//2015-05-10  changed parameter 1 to 6 for 6 neopixels in daffodils
Adafruit_NeoPixel strip = Adafruit_NeoPixel(6, PIN, NEO_GRB + NEO_KHZ800);

// Here is where you can put in your favorite colors that will appear!
// just add new {nnn, nnn, nnn}, lines. They will be picked out randomly
/*2015-05-09 vm note the [][3] specifying the dimensions of this 2-D array
1st dimension (number of rows--colors in this case--is empty, which is legal
as long as the array is initialized in-line, which this is.  The second dimension, the columns,
is the RGB components. We can add a row (color) without changing anything else. I added 5 clors
to the purple, yellow, blue that were supplied in the example.
Line 40, declaring FAVCOLORS, calculates the # of colors using the size of the initialized array.
Line 58 gets a random number between 1 and FAVCOLORs do decide which color to use, at random
2015-05-09*/
//                          R   G   B
uint8_t myColors[][3] = {{232, 100, 255},  // purple
                         {200, 200, 20},   // yellow
                         {30, 200, 200},   // blue
                         {(0,255,255)},    // cyan
                         {(255,69,0)},     // orange red
                         {(0,255,0)},      // lime
                         {(255,0,255)},    // magenta
                         {(255,0,0)},      // red
                          };
                             
// don't edit the line below
#define FAVCOLORS sizeof(myColors) / 3

void setup() {
  strip.begin();
  strip.setBrightness(40);
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
flashRandom(15, 2);  // first number is 'wait' delay, shorter num == shorter twinkle 2015-05-08 vm changed this to 15 from 5--better for flowers
flashRandom(15, 4);  // second number is how many neopixels to simultaneously light up 2015-05-08 vm changed this to 2-4-3 from 1-3-2 for grins
flashRandom(15, 3);
}

void flashRandom(int wait, uint8_t howmany) {

  for(uint16_t i=0; i<howmany; i++) {
    // pick a random favorite color!
    int c = random(FAVCOLORS);
    int red = myColors[c][0];
    int green = myColors[c][1];
    int blue = myColors[c][2];

    // get a random pixel from the list
    int j = random(strip.numPixels());
 
    // now we will 'fade' it in 5 steps
    for (int x=0; x < 5; x++) {
      int r = red * (x+1); r /= 5;
      int g = green * (x+1); g /= 5;
      int b = blue * (x+1); b /= 5;
   
      strip.setPixelColor(j, strip.Color(r, g, b));
      strip.show();
      delay(wait);
    }
    // & fade out in 5 steps
    for (int x=5; x >= 0; x--) {
      int r = red * x; r /= 5;
      int g = green * x; g /= 5;
      int b = blue * x; b /= 5;
   
      strip.setPixelColor(j, strip.Color(r, g, b));
      strip.show();
      delay(wait);
    }
  }
  // LEDs will be off when done (they are faded to 0)

}

Sunday, January 25, 2015

@MAKE Electronics Experiment 18 - 7-segment displays, 4026 counters, 555 timers

Here's the latest, from +Make: Electronics. Experiment 18 uses 3 single digit 7-segment displays, 3 4026 decade counter chips (1 for each digit, chained together so they roll over), 3 555 timers to get the circuit to run by itself.

I did a video but it was too big for Blogger to handle. See it in this post on Google Plus.

After I did the video, I added another 555 (actually the other side of the 556), an LED, and some additional resistors and capacitors.  The book gives really clear directions, My only variations were using the 556 (because I thought that would be interesting), using 3 1-digit displays instead of a 3 (my 3s are not individually addressable--only 12 pins as opposed to the 28-pin version Charles used). Also, I turned on the decimal point between digits 2 and 3 just for grins.

This was fun.  I just got a bunch of 7-segment displays from ebay, and it's interesting to see how to control them through chips only--no programming,

On power up, the counter runs. You stop it and clear it, then hit the start switch, After a delay, the LED lights and the counter starts.  You the hit the stop switch to time your reflexes. I almost got there, but I had some sparks and some component is likely fried. Since I got it almost working, I'll move on.

The next exercise is using logic chips, and I really want to do that. I ordered a whole bunch of them from ebay, but not all have arrived yet, including one of the 2 chips I need for this experiment.

While I'm waiting, I think I'll get the 7-segment displays working with arduino. In addition to the 1-digit displays I have some 3- and 4-digit ones., That could be interesting.  Less clutter on the breadboard...kind of cheating, which is why I wanted to do it Charles' way first.

Update 01/26/2014:  it turns out that the only thing I fried was the LED.  I got it working again (there were a couple of loose connections, too).  I think I will go on and fuss with the capacitor values to see if I can get it to count close to real time by 1/100s of seconds. could be fun. That, and the Arduino thing.

Update 1/27/2014:  the closest I could get was replacing R8 (2K2Ohms) with a 10K potentiometer (actually a knob I took from a fried clock radio) and 22 microfarad capacitor for C2.  Spec for C2 was 68uF but all I had was a 47.  Charles said to use a .1uF (then on the next page he said 1, which I think is what he meant because he said a 10 was 10 times the value).  I tried several values from 1 to 100, and settled on 22 because that gave me the most responsiveness from the pot.

This whole thing was really interesting--using different chips in multiple configurations, playing wiht the speed of the timer displayed on the 7-segment devices, etc.

Monday, January 19, 2015

Mario Question Block from @adafruit - Final(?)

It's finished. See video

The final steps were:
  1. desolder the floating wire on the LED+
  2. desolder the GND wire, cut it to the same length as the + wire, resolder
  3. cut wires to go from LED1 to LED2
  4. solder LED1+ to LED2+ and LED1- to LED1-
  5. uncscrew the Piezo, drill the holes to expand, and refasten
  6. use tack to fix the backpack on the Trinket
  7. place the switch in it's holder
  8. mount the Trinket (this was not great--the screw head strips, but I got enough in to hold it)
  9. close it up (this was hard, because there's a lot of stuff in there and the cover still does not fit perfectly, but I got it)
This was not +Adafruit Industries' greatest tutorial.
  1. It says that the LEDs should be connected in series when only a parallel connection works
  2. There is no mention of the battery--where to position it, etc--the answer apparently is "stuff it in any way you can."
  3. The wiring diagram shows all wires coming out of the top of  the Trinket. Some must come out of the bottom. There is no mention of that in the text.
  4. The stuff about tolerances for 3D printing was not obvious (to me which is OK because I don't know anything, but it was also not clear to the 3D printing service I used)
But, it's done. On to the next project.

Sunday, January 18, 2015

Mario Question Block from @adafruit - Part V

I got the LEDs to work.

  • I verified all the other connections
  • I tried a 5mm LED in the circuit instead of the LED sequin I desoldered--no change
  • I put the LED sequins in series on a breadboard, powered by a 5V 1500mA wall wart--they both lit
  • I checked the datasheet for the LED sequins, Max forward current is 25mA. Average forward voltage is 3.4V at 20mA.
Trinket Pin #4 puts out 20mA.  I'm not sure there's enough juice juice to power the LED sequins in series.  Everything I've read says to put them in parallel, but I'm going by the instructions in the tutorial. I never got a response to my query on the Adafruit Support Forum.

However, I wired the LEDs in parallel as opposed to series, and they both light. I have given feedback on the tutorial.

Next: put it all back together and wear!


Friday, January 16, 2015

Mario Question Block from @adafruit - Part IV

I drilled the hole in the case for connecting the Trinket.  From the webs, I ascertained that I needed about a 1/16" bit (.0625 for a .067 screw).  That worked. I was able to attach the Trinket, but I'm holding off on the final solution until I get through some of the following issues. I got some 2-56 3/8" screws, Philips head, and they work much better (I replaced the screws for the Piezo, also).

I put my meter on the circuit (DUH--learning the obvious lesson: do this DURING assembly to assure the connections will work).

First, I verified what the switch was telling me--I did not completely remove the trace between the pads on the backpack, so the circuit is always open and the switch had no effect. It looked OK to me, but I did some more scraping and now it works.

Second, I checked the LED connections.  My meter showed continuity throughout.  Using alligator clips to jump various connections, I could get one or the other LEDs to light, but not both.  I desoldered one, and tried various combinations of connections with no luck. It occurred to me that maybe the battery did not have enough juice, but according to my meter it's putting out 3.96V, and it's rated at 3,7V. I also tried it connected via USB--no change.

Meanwhile, the Piezo wires came loose from the Trinket and I had to resolder.

I have posted a query on the Adafruit Support Forum about the LEDs. If I get an answer, I'll move on. If not, I may try it with 1 LED (which was the original design).


Sunday, January 11, 2015

Mario Question Block from @adafruit - Part III

OK. Problem 1 is that, despite +Phillip Burgess ' warning, I soldered the Piezo to the Trinket before I wired it correctly (in my defense, I did heed the warning, I just wired it wrong). I thought I knew which hole to pass the wires through, but after I did it I realized something was wrong.  Here's what that was:

  1. the tutorial is not crystal clear
  2. the hole I was supposed to used was partially obstructed by printing debris so I did not recognize it as a hole
  3. I did not pay attention closely enough
So, today's work:
  1. search local stores for shorter 2-56 screws
    I got 3/16" flat, slotted heads--the Phillips were beveled and did not provide enough thread (I would have liked more detail in the tutorial for this because I'm ignorant, but I got there)
  2. detach the Piezo and re-attach it with shorter screws (as noted in the last post, the ones I used were too long)
  3. deburr the hole for the Piezo wires
  4. cut the wires from the Piezo, string them through the newly deburred hole, and splice them to the other part of the wires connected to the Trinket
  5. tack the backpack to the Trinket
  6. cover the on-board LEDs with black tape (I know I have several rolls someplace, but in the interest of sanity I went back to the hardware store)
  7. screw the Trinket to the enclosure
  8. modify the diffuser so it will fit in the new cover  (also had to clean up the location for the diffuser--I guess I should have anticipated this, but I expected a cleaner print from the service--now I know why Charles Platt in +Make: Electronics wanted me to by a bunch of files and deburring tools)
  9. hook up the LiPo and charge it
  10. test and rework as required
However, I have some serious problems.
First, the screw hole for the Trinket is filled in and I cannot get it to screw in.  
Second, the switch does not turn the circuit off--I have to disconnect the battery. I followed the instructions on clearing the connection between the holes on the backpack--maybe I did not get it right.
Third, the Piezo chimes, but the LEDs do not flash. The connections look right to me.

So, I have more work to do.

Saturday, January 10, 2015

Mario Question Block from @adafruit - Part II

When last we saw this, I was waiting to get replacement 3D printed parts back from the service I used. The first print was missing the handle and the cover did not fit. New parts arrived yesterday.  It has the handle, and the cover fits. I'm a little disappointed because I started this about 6 weeks ago, but I'm ready to go. I'll put on my white lab coat and get to it.

The first thing I tried to do was upload the code to the Trinket (so I will have when I get the product assembled).  After I located a mini-USB cable I found that I forgot to update my Arduino IDE (I knew that because I got "PLLCSR not defined in scope" etc. on compiling).   DUH--I needed to set the board to Trinket 8MHz, but first I needed to update my hardware folder. Then, I went to upload and got my favorite avrdude messages.  DUH--I forgot to add some other changes. Of course, the Adafruit Learning System has all this spelled out here.  I'm sure I saved some frustration later on when I'll be anxious to try this out.

Later that day...
The good news is that my new soldering iron and heated solder sucker work really well. I made it mostly through the project, to get here:
I got the soldering done, following the tutorial I had one issue: the first diagram shows all the wires from the backpack coming out of the top. That's wrong: the wires to the slide switch come out the top, but the 5V, BAT, and GND wires go out the bottom. So, I got out the new solder sucker and re did them.  I am supposed to attach the backpack to the trinket with tack...I need to redo that.  I also need to fix screw the trinket to a standoff.  T

Also he only 2-56 screws my local hardware store had were too long too attach the piezo. I can make do until I get a shipment from sparkfun next week. 

The only other problem I have is that since my frindly 3D printing service did not re-print the diffuser, it doesn't fit. I'll had to do some modifications..  

I should get back to this tomorrow.









Thursday, January 1, 2015

Great things in 2014

Here are some of the great things that happened in 2014 (maybe the best year ever):
  1. I found Adafruit!
    +Adafruit has made my life better. Through this company have have learned more than I imagined I could, and watched and participated in multiple internet shows (4 appearances on Show-and-Tell, a question answered on air on Wearable Wednesday).  My questions on the support forums always get prompt, clear, informative responses. Adafruit is a community more than a company, and I am really happy to be a part of it. AND--I love their products, too.
  2. My electronics projects (and learning to solder)
    I asked for and received a bunch of electronics stuff for Christmas last year (+Arduino, books, etc.). In addition to Adafruit, I got help from +JeremyBlum 's tutorials, and Charles Platt's book "+Make: Electronics." 
    I constructed a bunch of circuits for learning purposes, and will get back to that next year. I also recruited my former (and now current) boss to teach me to solder once I could go no further without soldering.  I'm now have adequate soldering skill. I plane to learn to solder surface-mount components next year.  Some highlights:
        .  In an early success, I could not get the component I needed for Jeremy Blum's tutorial #8 involving digital potentiometers. His spec was for a quad from Analog Devices, but I could not find one.  I got 2 duals from Microchip Technologies.  I ran into trouble following the datasheet to daisy-chain the 2 devices. In the process, I learned about schematics and Eagle CAD. I sought help on the Arduino Forum , but did not get an answer.  Finally, I went to Microchip tech support, and after a phone call I got the answer I needed to get it to work.
        .  The Adafruit candle-flicker hair bow for my granddaughter. She loved it. I made one for my daughter, too. She was less impressed.    . An exhaust fan for soldering using a case fan from an old computer, scrap wood for the frame (it's what I had), some brackets and screws for mounting, a toggle switch, a potentiometer to make it variable speed, a power jack, and a 12V power adapter from a dead laptop. I use it every time I solder.    . A useless flashy thing from the Charles Platt book--taking it a step further by putting it in an enclosure and adding a toggle switch.
        . Talking Halloween Candy Cauldron (see entry on this blog)
        . The Head Move Donkey--also on this blog
  3. My granddaughters continue to be wonders
    Nora loves "playing electronics with Grandpa," including  the candle flicker hair bow, "the E is for Electronics coloring book," and the Adafruit videos (which she calls "Adabot Videos"). We made a lemon battery that she thinks is really neat.
    Frankie turned one this year.  We had the great fortune to have her here for over two months in the summer, including her birthday, and got to see her learn to walk.
  4. My daughters and their husbands are great
    I am very proud of all of them and all they have accomplished.  What a blessing!
  5. Our trip to Canada
    I have always wanted to see the Maritimes, and we were able to go to Prince Edward Island, returning through Maine with a stop in Bar Harbor, where we honeymooned 43 years ago.  It was wonderful.
    PEI was beautiful and peaceful, just the break we needed form Cape Cod in July/August.  Bar Harbor was crowded, but the hotel we stayed in kept us out of craziness, and there was good public transportation into town.

Friday, December 19, 2014

Mario Question Block from Adafruit Part I

This is my next project, from a tutorial on the Adafruit Learning System.  I enjoyed working with the Pro Trinket in the Donkey project, so I thought this could be interesting.  Also, the enclosure is 3D printed, and I am intrigued by 3D printers, so that was a draw.

I found a local 3D printing service through http://www.makexyz.com/ and this is what he produced:
It's pretty good. The top does not fit right on the body, so I'll have to do some modification, and it's not as clean as I'd like, but I'll work with it.  It cost $20 for the print, including mailing it to me, plus $3 for the service.  When I get the time, I will do the modification to the enclosure and the construction. I have the parts, so it should go OK.

Here's what I've learned so far:
  • At first I thought the print was backwards, because I was comparing what I got with the photos in the tutorial. However, when I took a photo of the print to send to the guy who printed it, I realized that the photos reverse the image...so I'm believing that it's OK.
  • In all the photos in the tutorial, it looks like the handle is part of the print. The printer said no, then I read the fine print in the tutorial and it said "attach a handle--you figure out how."  But, the handle DOES seem to be part of the print.
I have posted questions on the Adafruit Support Forum.  When I get some clarification I'll pursue this further. Meanwhile, I'm kind of stuck.

More when I get to construction.




Friday, November 28, 2014

The Head Move Donkey



In 1978, I bought a wind-up donkey for my daughter, then an infant. The donkey moved its head while playing “Donkey Serenade.”  I figured that I could replicate that with an Arduino, a motor, sound on an SD card, and a speaker.  It took me 10 weeks, but I did it. Here’s the story.

I got sidetracked for a while doing my Halloween Candy Cauldron, which came out of this one. While I was working on the donkey, learning about playing sound with an Arduino, I began seeing lots of Halloween projects on Adafruit shows, so I decided to try my hand on Halloween sounds.

This was an incredibly rewarding project that was challenging, fun, interesting, and educational—all the reasons I wanted to start with Arduino in the first place!

Here’s a video, and another pre-completion, and there are links to two appearances on Adafruit’s Show-And-Tell under “Resources” below.

Parts List (about $80 in parts done this way, assuming you have all the tools and supplies)

2.1mm power plug and jack (doesn’t matter what you get as long as they match)
Micro SD Card
Speaker (I used a 2” 8ohm speaker from an MFC printer I took apart)
Sound editing software, like Audacity
Hook-up wire (I used 22 gauge solid wire to connect the speaker, and to run from the terminal block on the PWM board to the power connector because that was easier
Adafruit silicone-coated stranded wire in various colors (very flexible--helpful for connections inside the enclosure)
Header pins (male, female, and right-angle)
Soldering iron and accessories
Heat Shrink tubing
Dremel or similar tool for cutting out the stand-offs on the enclosure
Drill and bits for making holes in the enclosure (1 for the power jack and 1 for the wires to the speaker and servo)
Electrician’s tape to keep stuffing out of the wire hole
Sewable Velcro strips for closing up the donkey
Needle and thread

Step 1:  play music
First, I located and downloaded the song from http://www.mp3olimp.net/donkey-serenade/ .
Using a Seeed Studio SD shield, the TMRpcm library and this tutorial (http://www.instructables.com/id/Playing-Wave-file-using-arduino/) I was able to play the song. Note the need for specific sound file format, that’s where Audacity came in. I also shortened the song to delete a couple of the more jazzy parts.  Nothing against the music, but this is a child’s toy. The sound needed amplification so I tried the diy amp from http://vcctoground.com/tutorials/simple-pocket-audio-amplifier/   but did not get much improvement (NPN and PMP transistors, etc.).

Step 2:  operate servo
I had a micro servo and an example from Jeremy Blum’s tutorial (http://www.jeremyblum.com/2011/01/31/arduino-tutorial-5-motors-and-transistors/) and got that to work fine.

Step 3: put it together
I could get the servo to move or the music to play, but not both. With help from Adafruit support (https://forums.adafruit.com/viewtopic.php?f=25&t=59793), buying a PWM breakout board (https://www.adafruit.com/product/815), and some soldering, I got it to work. The problem was a timer conflict.

Step 4: getting small
I asked Becky Stern, Director of Wearable Technology at Adafruit, for some advice on getting all this in a donkey. She answered my question on Wearable Wednesday (~21:30)!  I also needed to change some components. First I swapped out the Arduino Uno for a Pro Mini 5V (I thought).  Next I bought a microSD breakout to replace the shield. The Micro SD runs on 3.3V, so I thought I needed a voltage regulator and maybe something else (http://forums.adafruit.com/viewtopic.php?f=19&t=60813 ).  In the process I found out that the 5V pro mini was really a 3.3V, and figured out that that was really what I wanted (power the Pro Mini, the amplifier, the PWM board, and the servo from the battery, and power the SD from the Mini).

Step 5: refine
I figured out how to play the song in a loop without resetting the Arduino (TMRpcm.loop(1)). In the process of doing all this I cooked my Mini—it won’t put out 3.3V anymore (more like .9V) so I’m back on the Uno until my 3V Pro Trinket comes next week.  I also decided to go with a 6V coin cell holder with switch (https://www.adafruit.com/product/783 ) for power.  I gave up on the amplifier and put in an LM386 circuit.  It works OK, but I also ordered an amplifier breakout (https://www.adafruit.com/product/2130) just in case I can’t get the sound I want out of a smaller speaker.

Step 6: construction
Donkey arrived 10/4/2014.  It will accommodate a small project box, servo, speaker, and battery holder. Now I need to be sure I can get the whole circuit on a board small enough to fit into the enclosure. The Altoids tin will fit in the donkey, but I also have a project box if I can’t get the circuit in the Altoids tin.
Programming the Pro Trinket was somewhat flaky at first. I needed to install the hardware updates for the Arduino IDE so it would recognize the board. Also, had to set the programmer to USBTinyUSB. When that didn’t work (“can’t find USBTiny”) I discovered I needed the Windows drivers.  After I got that all done I was able to upload the example blink program, so I’m in business, I think. Now I need to solder the headers so I can test the circuit. I have another Pro Trinket coming tomorrow, so I will use that for the real thing, soldering directly, but I’ll need this one with the headers anyway. UPDATE:  there may be an issue with the ProTrinket and device recognition on Windows (or at least my Windows systems).  I got it to work with Ubuntu, and in the process discovered that the upload took longer than the bootloader was active, so I have to wait to press the reset button to activate the bootloader, but leave enough time in the compile process for it to initialize.  Kind of a pain, but it’s working. I never did get it working on Windows 7 (that may be my fault), but it’s working OK on Windows 8 and Ubuntu.

Step 7: more construction
I tested the 6V coin cell battery, and the power lights on the boards come on but no music and no motion.  I need find another power source. I’m considering a 9V with a voltage regulator to bring it to 5V. A 4bXAA works (6V) but it’s big. Also I got the Adafruit mono amp, and it puts out more volume than the LM386. I also takes up a lot less space. Next, I got some SMT breakout boards (https://www.adafruit.com/product/1208) so I’ll see if I can solder the TSSOP-28 PCA9685 to it and save more space. That didn’t work—not skilled enough. I will try to make a DIY breakout. I shorted something and cooked my amp, just got new amps today and will try again. The servo moves but no music…hopefully the new amp will get me back where I was. The new amp fixed the problem. I decided to stick with the Adafruit PCA9685 PWM board because my surface mount skills are not there yet.

Step 9: The enclosure
I got a 4x2x1 enclosure from Radio Shack.  I fixed an Adafruit 1/8 size Perma-Proto Board to the enclosure with a screw, and drilled a ½” hole for a power receptacle and a 3/8” hole for the servo and speaker wires. In another 3V Pro Trinket, I soldered female headers to A4&A5 and Adafruit silicone coated flexible wires to the pins I need for the circuit. I put right angle headers on the I2C pins of the PWM board, so I can slide those into the female headers and have the bigger board flat with the Trinket on its side perpendicular to the PWM board. All the power and ground connections will go to the Perma-Proto Board + and - rails, with the power connector supplying those rails.  The power supply will be an Adafruit 4xAA battery pack with switch so there is an external switch  access to batteries for changing without opening the donkey, and less space to take up inside.

Step 10: new Trinket
I tried wiring up the circuit with the new, newly soldered Trinket. It powers up, and puts out 3.3V on that
Rail, but it does not play sound or move the motor. Either I did not wire it correctly or there is something wrong with my soldering.  More testing tomorrow.
The next week:  I wired it up again.  After some fussing with connections I got the whole thing to work. I spent some design time on the enclosure, so on to soldering/enclosing.

Step 11: The enclosure, part 2
Day 1:  I discovered that I could not fit the Perma-Proto board and the other components in the enclosure.  The next size larger is too big for the donkey.  Also, the internal stand-offs in the enclosure were in the way, so it was redesign time.  I moved the power connector/receptacle from the end to the side to give more room. I used my Dremel knock-off tool to cut out the internal standoffs. Now everything fits.  Without the Perma-Proto Board, I will need to connect the wires for power and ground directly to the connector. Next I got to soldering:
1.       I connected a 2.1mm jack (to plug into the power receptacle) to the battery pack and covered the splices with heat shrink tubing.
2.       I soldered new, solid core wire leads to the speaker.  Solid core works better in the terminal blocks.
3.       I connected solid core wire to the external power terminal block on the PWM board, and ran them under the board to the power connections.
4.       I removed the jumper wires from the amplifier, and soldered wires directly to the header pins.  The A- and GND wires to go to GND, the Vin to go to power, and the A+ pin is soldered to the wire going to digital pin 9 on the Trinket (SpeakerPin).
So far, so good. Tomorrow I’ll replace the six jumper wires on the SD card with direct soldered connections, and test the audio. Assuming that works, I’ll do the 4 remaining wires on the PWM board.

Step 11: The enclosure, part 3
It works!  Without the circuit board there was a lot of soldering. I soldered all the power leads together, two at a time, adding the next one in turn until I had one lead to connect to the power connector + lead, then did the same with the grounds, to the – lead.  I left the jumper wires on the SD board because they’re pretty secure and didn’t want to risk cross-connections due to sloppy soldering.  I did solder leads to the headers for Vcc and GND on the PWM board.  For the SD board, I cut and stripped the jumpers and connected them to the correct leads:
·         GND to the GND complex
·         3.3V to the 3.3V pin on the Trinket
·         SPI pins to the leads I already had soldered to Trinket pins 10-13
I used heat shrink tubing on the splices to protect the connections from touching.
Everything fits—I can close up the enclosure and secure it with screws. The music plays and the servo moves.
Tomorrow: open up the donkey.

Step 12: the donkey 1
I used an x-acto knife to cut the donkey’s belly along a seam, and took out some stuffing.  I got the servo in the neck, and it will turn the head, but I need to fix it to something solid so the horn of the servo turns the donkey instead of the donkey holding the horn while the servo turns. Meanwhile, I stripped the plastic gears on the servo.  This is the second servo I’ve ruined.  So, I ordered two new servos, one micro and one standard, both with metal gears from Adafruit. Hopefully one of them will do the trick.

Step 13: the donkey 2
I used the standard servo. It’s substantial, and it does the trick. I was able to close up the enclosure and screw on the cover with only one mishap: the ground lead on to the power connector broke and I had to de-solder/re-solder it.  I pulled more stuffing out of the head to get the servo in closer. It moves a little, but with more stuffing, it should be even better than it is now.  There’s a little interference from the servo (actually I think it’s from the PWM board) but it’s OK.
Next: sew on the Velcro and re-stuff.

Step 14: the donkey 3
First, I sewed on strips of Velcro that I had cut to the length of the slit in the donkey’s belly.  I’m not great at sewing, so it was a little frustrating, but I got through it.  Next, I tried different positions for the servo to get it to move the head. I re-stuffed the neck to try to keep the servo in position, placed the speaker, re-stuffed the rest of the donkey put the enclosure in and closed the Velcro.  After one more iteration to get the servo better positioned, it’s done.  I’d like more range of motion on the head, but it does move.

Step 15: futures
1.       I’d like to get more movement from the Servo. I have to experiment with different horns, different positions, and different programming.  I was time-limited on this one—I needed to have it ready for Thanksgiving Dinner, so I haven’t been able to pursue more options yet.
2.       I would shorten the wires inside the enclosure, and probably move the power connector to the end of the box (rather than coming up from the bottom). 
3.       I’d also like to find a box that fits the components a little better, and to fasten the boards to the enclosure (right now, they’re loose, and any jostling by grandchildren may disconnect something). I think I could put standoffs on the end of the enclosure for the Trinket and the bottom for the PWM Board.
4.       Rather than connect the Pro Trinket to the PWM board via right-angle headers, I might want to solder wires directly from the holes on the Trinket to the holes on the PWM board.
5.       To accomplish #3 and other improvements, I would need to hold off on soldering header pins to any components until I know how I really want to wire up and solder the whole project. I soldered the headers first thinking generically, then when I got inside I found that some of the pins were in the way.
6.       I’d like to see if I can make a PCA9685 breakout on my own to save space. New Year’s Resloution #1:  get some SMT soldering skills.
7.       Investigate 60MHz vs 50MHz on the Servo (see comment in sketch)



Circuit as laid out on a breadboard



Resources

Presentation on Adafruit Show-and-Tell
In-Process https://www.youtube.com/watch?v=Y8tFcF2-klw about minute 13 to 16:30
Finished  http://www.adafruit.com/blog/2014/11/26/show-and-tell-google-live-hangout-wednesday-night-at-730pm-et-112614-video/ about 4:50 to 6:45
 
Discussion on Wearable Wednesday
http://www.adafruit.com/blog/2014/09/17/wearable-electronics-with-becky-stern-9172014-live-2pm-et/

Donkey:

Sound:

Tutorial:

Sound from SD:

Micro SD:

TMRpcm library

Power servo

PWM/Servo Breakout

Amplifier

Increase volume (LM386)

Amplifier I used

Servo I finally used

Arduino Sketch

/*September-November 2014
THE HEAD MOVE DONKEY
Uses TMRpcm library to play music from and SD card, and Adafruit_PWMServoDriver library to drive the servo.
Some comments are from example code that came with those libraries
Objective is to move the donkey's head with the servo while playing "Donkey Serenade.
When I was on the Uno and had the serial monitor, I used an led to prove that I was moving through the loop. That is now commented.
Circuit uses the Adafruit Class D mono amp, Adafruit PWM servo board driving a micro servo, a micro SD card board, an 8 ohm speaker, and a 4xAA batter holder
It now runs on an Adafruit 3V Pro Trinket, feeding 3V to the SD card and using battery power for the Trinket, Servo, PWM board, and amp
*/
/*includes*/
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

#include <SD.h> // need to include the SD library
#include <TMRpcm.h>           //  also need to include this library...

/*constants*/

// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!
#define SERVOMIN  200 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  350 // this is the 'maximum' pulse length count (out of 4096)
/*SERVOMAX reduced from 600 in example to 500 to save the servo (I stripped the gears on one already).  That gave me ~160 degrees. 
I reduced it again to 350, so it goes ~90 degrees: 45 to left and 45 to right if I have the motor and horn positioned properly. That's what I want
*/

// our servo # counter

#define SD_ChipSelectPin 10  //using digital pin 4 on arduino nano 328 2014-09-03 changed to 10 to match datalogger
//#define ledPin 5   //pin to control led   2014-10-25 testing
/*variables*/
int angle = 0;   // servo position in degrees
uint8_t servonum = 0;
/*objects*/
TMRpcm speaker;   // create an object for use in this sketch


void setup(){

 
  speaker.speakerPin = 9; //11 on Mega, 9 on Uno, Nano, etc
  speaker.loop(1); //2014-10-03 play repeatedly
  Serial.begin(9600);
  if (!SD.begin(SD_ChipSelectPin))
     {  // see if the card is present and can be initialized:
     Serial.println("SD not initialized");
      return;   // don't do anything more if not
      }
   else
      {
       Serial.println("SD initialized");
     }    
  speaker.volume(1);
  speaker.play("hmd.wav"); //play Donkey Serenade each time the arduino powers up, or is reset (as of 2014-10-03, plays repeatedly)
  pwm.begin();
  pwm.setPWMFreq(50);  // Analog servos run at ~60 Hz updates (says Adafruit--I found that 50 worked better with my servo from Radio Shack—never set it back for the Adafruit servo)
}

void loop()

{
//blink led to show arduino is looping through this whether servo moves or not
//  digitalWrite(ledPin, LOW); // 2014-10-25 testing only
  delay(1000);
//  digitalWrite(ledPin, HIGH); //testing
    for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
    pwm.setPWM(servonum, 0, pulselen);
    delay (100); //was 50, doubling the delay to move the head more slowly
  }
  delay(1000); //pause when limit is reached
  for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) {
    pwm.setPWM(servonum, 0, pulselen);
    delay (100);
  }
  delay(1000); //pause when limit is reached

}