Showing posts with label trinket. Show all posts
Showing posts with label trinket. Show all posts

Monday, June 26, 2017

Fourth of July Lights


With my grandchildren coming for the Fourth of July, I went looking for projects to do. This is one, thanks to John Wargo--original and Fourth of July Version.

I made slight modifications to the Fourth of July version, using a Trinket instead of the Pro Trinket, because I had some of the smaller ones inventory. I also decided to leave off the LiPo charging backpack,  used a pushbutton switch, and used perf board for tidiness.

I used John Wargo's code almost exactly. The only difference is that he used pins 9, 10, and 11 but the Trinket does not have those pins.  Only pins 0, 1, and 4 on the Trinket handle PWM, so I replaced the array provided in the code "int ledPins[] = { 9, 10, 11 };" with "int ledPins[] = { 0, 1, 4 };".

Fritzing Diagram of Circuit

Construction

Parts (references to Radio Shack are good as of writing--no guarantee how long they will last)
  • Adafruit Trinket 3V
  • pushbutton switch (example--any SPST switch will do)
  • Radio Shack Dual Proto Board (or any perf board)
  • Wire Light LED Strands (1 each red, white, and blue)
  • 47 Ohm Resistors (3)
  • JST-PH Breakout Board
  • 1 Quart Ball Mason Jar (any jar with a lid will do--this size works well)
  • Wire Light LED Strands: Red, White, and Blue (note that these are NOT what's shown in the Fritzing diagram--I used the closest image they had in the parts bin).
  • 47 Ohm Resistors (3, one for each LED strand): see Adafruit descriptions of the lights, above--no resistor is needed with coin cells, but " If you want to use a 4.5V power supply, use 20-220 ohms (or larger)"--so I chose 47 for the 3,3V Trinket (having noticed how much brighter the LEDs were off the Trinket vs. off the CR2032s with no current-limiting resistor).
  • Tinned copper bus wire  and hookup wire-- like this, for example--depending on distances and how much insulation you need
  • Gaffer Tape
  • 500 mAh LiPo battery
  • JST-RCY cable Note:  the battery I used (see link above) has a JST-RCY connector and the JST breakout board has a JST-PH connector, I needed this cable and the next to use it. If yours has a different connector, you may not need these at all,  or you may need something instead of the -RCY cable. The 100mAh version shown in the Fritzing diagram, and most (or all) of Adafruit's LiPos, have JST-PH connectors, making all this unnecessary. I could have just cut the -RCY connector off and spliced on the -PH cable, but that was too permanent for me...and now I have a useful -RCY to -PH adapter.
  • JST-PH 2-pin Cable
Tools
  • Drill (I used my drill press--you just need a way to drill holes)
  • Step Bit (I needed ~16mm for my switch--different switches will have different requirements)
  • Wire tools: strippers, flush cutters, etc.
  • Normal soldering equipment: iron, sucker, helping hands, etc.
Process

The bulk of the time was spent in design--mostly how to fit everything where I wanted.  The mason jar lid cramped my style. Even thought the Trinket is small, it took some maneuvering to get the perf board, theTrinket, and the JST breakout next to the whole I drilled.
  1. I laid out the space requirements on the inside of the lid, then cut the perf board to size and experimented with positioning until I was no unhappy
  2. I drilled the hole in the lid for the switch
  3. I made the RCY to PH JST cable to connect the battery: I just soldered the 2 together and heat shrinked
  4. The LED strands referenced above come with coin cell battery holders. I needed to cut the leads from the battery holders to use them, taking care to note which lead is positive (mine had white markings on the + lead, but I tested it to be sure and marked each with red and black Sharpies).
  5. Wire it up
  6. Test and correct as necessary.
  7. Solder.
    I used tinned copper bus wire to make a ground bus down one side of the perf board, fed by the negative pin on the JST-PH breakout.
    To that, I soldered the GND pin on the Trinket and the negative leads of all 3 LED strands.
    I soldered one resistor to each positive LED lead and heat shrinked it for insulation, then soldered the other leads of the resistors to the proper Trinket pins. 
  8. I used gaffer tape to secure the circuit to the lid and the battery to the jar

Video






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)

}

Friday, May 8, 2015

Adafruit Neopixel Tiara on a breadboard

I decided to make the Adafruit Neopixel Tiara.  I have ordered some tiara's (plural to allow for error), and will fix the gemma and neopixels to it.  When I was thinking about it my town was getting ready for the annual "Brewster in Bloom" festival, which features daffodils, so I decided to see if I could do a similar project using fake daffodils.  The same day Becky Stern has a neopixel boquet project with fake flower on Wearable Wednesday. So, I figured I was on the right track.



After I got the products, I decided to test everything on a breadboard.  I soldered headers on one of my 3V Trinkets (I'll use a Trinket for the daffodils).

Here's the video

More after I start building.

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.









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

}