Thursday, October 29, 2015

Halloween Candy Cauldron V2.1 upGRADE

video
Forget all that stuff in my last post about what I cooked.  I went back to the Uno version, really at a loss about why everything stopped working.  I decided to check power, first on the 5V rails--no power!  Then, I check what was coming from the 5V pin on the Uno. Nothing.  The only answer (other than a cooked Uno, which I did not believe) was a bad jumper wire.  Sure enough, I did continuity tests on the wires and one was bad.  I replaced them and it worked. So, the sensor and amp are both fine.



I went back to the Trinket.  It's putting out static only.  Same sensor, same amp. So, maybe I cooked the Trinket.  I'll have to decide whether I want to solder up another Trinket and perhaps sacrifice it this year or wait until next. As for now, I've spent a WHOLE LOT OF TIME working on something that already worked,  I have the bigger cauldron, and I have a switch, and it works again.

My other upgrade for next year is to put the Trinket--or Uno if I can't get the Trinket to work--into low-power mode while it's dormant to save battery and avoid having to turn it on and off so much. I've just learned how to do that in concept and this appears to be a good application.

So. I can take it to work tomorrow to entertain my co-workers. Since Halloween is a Saturday, I'll decide then if I want to spend more time (and maybe money) getting the Trinket version to work again.

I feel much better! On to 3.0!


Halloween Candy Cauldron V2.1 (update,not upgrade--more of a downgrade)

I was having a problem with my candy cauldron: the Pro Trinket was resetting at random intervals, and the circuit would not resume unless I powered off and back on.

I surmised that the problem was power.  I was powering the 5V rails from the 5V pin on the Trinket. (This worked on the Uno, but maybe the Trinket doesn't put out as much current).  So, I took the 9V Vcc to the BAT and GND pins of the Trinket, then to the IN and GND pins of an LM7805 voltage regulator, and powered the 5V rails from the OUT pin on the LM7805.

All was good. No more reset.  I took the cauldron to a meeting in the morning and had fun.

Then I got greedy. The cauldron is very small, which limits the candy.  It's limited anyway, and in addition if candy is piled too high the sensor sees it and sets off sounds. Also, there was a sound problem: since the HC-SR04 sensor is ultrasonic, if the sound being played is long the sensor detects it and plays the next sound even if no one reaches in, and will continue until it gets to a shorter sound. For example: the howl is long but the cackle is short--if the randomizer selects the howl, it will play at least one additional sound until it gets one like the cackle; if it selects the cackle, it plays only that one sound. I had put in a 5 second delay to wait for the sounds dissipate, but that wasn't enough for all sounds and I didn't want to make it longer because that makes the candy grabbers wait too long.

So, I got a bigger cauldron and that worked fine--briefly. It played only one sound at a time since there is more room for the sound to dissipate. Then the problems: I do not know what happened, but it started producing static only and resetting--at first randomly and then continuously, then stopped producing sound altogether.  I thought I might have cooked the Trinket, but it doesn't work on the Uno either. The sensor is not registering, so I probably cooked my last one. According to my meter, there is a signal on the speaker pin when there is supposed to be, so I may have cooked the amp too. I swapped that out, with no success...but the amp I swapped to was the one I thought was cooked earlier but discovered I wired it wrong--maybe I really did cook it. I have more, but I need to solder on headers and a terminal block before testing.

So, I don't know if I'll be ready for Halloween.  If I get the amp to work I may invest in a retail HC-SR04 at Radio Shack while I wait for my $0.88 ones to arrive from China.

I'm not happy.

Monday, October 26, 2015

Halloween Candy Cauldron V2.0

Last year I was enticed into a Halloween Project.  I was working on my donkey, which involved sound, at the same time many of  the +Adafruit Industries  weekly #ShowandTell and #WearableWednesday projects had a Halloween theme, and of course there's the #electroninchalloween hashtag.

So, I came up with the idea of a candy dish that made Halloween-ey sounds when someone reaches in for candy. It was a big hit with adults, but kids less impressed.  I realized that I had some design flaws.

Here's my appearance on the Adafruit Show and Tell, while I was still working on the SD card reader. It should start just before my section (after you skip the ad), but if not, I start at about minute 18.

First, I did not enclose the circuitry, so aggressive candy grabbers could introduce failure (adults were bigger offenders here).  Second, I wanted to use the +SeeedStudio SD Card Shield, which meant I needed to include an Arduino Uno. That was fine, because the shield sits on top of the Uno and the Adafruit Class D Amp uses 5V. Most SD card readers, particularly MicroSDs, want 3.3V.  I could do this off the Uno, but I needed another approach if I wanted to use a different board with one voltage level or the other.

I had a Adafruit Pro Trinket (5V) around, so I decided to use it.   I need the Pro Trinket as opposed to Trinket, because the smaller (non-Pro) version doesn't have enough pins to support SPI, which I need for the SD card.  I does not have a digital pin #7, which I was using for the Echo Pin on the ultrasonic sensor, so I has to change that to #6. Fortunately, I also had an LC Studios SD Card Reader that accepted 5V or 3.3V. That simplified matters, avoiding a voltage regulator and  logic level converter (which I have, but simpler is better),  The Pro Trinket can be powered from up to 16V, so I'll bring 9V  into it and power a 5V rail from the Trinket.

See issues, below,  I had 2 of the LC Studios boards. One would not work at all.  The other I got to work with the Uno but not with the Trinket. So, I ordered an Adafruit Micro SD Breakout Board. More expensive, but it works--and I am supporting a my favorite supplier.

Now I needed an enclosure.  This is a case where a 3D Printer would be really handy so I could design my own (I'm working on that).  Stock enclosures almost always have standoffs in the wrong places, so at best the standoffs are useless and at worst are in the way and have to be cut out, AND they're never exactly the right size.

To recap last year's project, I had:
Ultrasonic Distance Sensor and 3" speaker from a defunct clock radio as peripherals, with an Arduino Uno, SD card shield, and an amp--all loose in the bottom of the cauldron (except the speaker and sensor). The battery was external.

The changes are:
  1. add an enclosure; mine is 5" X 1.75" X 2.5"--bigger than I really need but everything fits, including a half-sized breadboard
  2. change from the Uno to a 5V Pro Trinket
  3. use a MicroSD reader instead of the SD shield
  4. I considered a circuit board or perma-proto), but decided to keep the half-sized breadboard for modularity and simplicity
  5. move the battery into the enclosure and use a switch to power on/off (last year I had the 9V battery outside the cauldron, inside a switched battery holder
  6. as noted below, I used long header pins to connect components to the breadboard
  7. change the pin assignment for the Echo Pin from 7 to 6
I will need to connect 8 wires from the enclosure: 4 to the distance sensor,  2 to the speaker, and 2 from the battery to the switch so I'll need to have holes in the enclosure and devise a way to connect them (short of hardwiring). I have some Radio Shack RCA phono plugs and jacks for the speaker, and holes for the sensor wires and power wires. I will use JST connectors for the power and sensor wires.
Since I'm keeping the breadboard, I can use long header pins in the breadboard, and just plug the JST female ends into them.

Everything else is as in V1.

Issues along the way:

After I got an SD card reader that worked (see above), I had it all working.  Then I must have messed up a connection, because I was getting no sound. I suspected that the HC-SR04 was cooked, so I put on my FTDI board so I could use the serial monitor to see the testing messages I put in the code. Sure enough, it was not registering.  I had 2 more, so I swapped one in. same result.  Swapped the other in--all is well.  I knew I would need more, and my options were 2 for $9 at amazon or $0.88 each off ebay. I ordered 5, If one works I break even with Amazon.  

Next problem:  still no sound. I check every connection and reran everything, so I concluded that the amp was bad too (this happened in another project with the same amp).  I ordered 4 more. As soon as they arrived I soldered the header and terminal block and swapped it in.  No sound. I turned the volume to see if that was the problem,  Just in case, I checked the wiring again. Sure enough, the wire that was supposed to connect A- to GND was misplaced. I moved it and tiedd again. Still no sound. Remembering that I had adjusted the volume, I turned it back. Sure enough, I had turned it down earlier, so now its all good.

New circuit:


Parts

  1. enclosure (mine is 5"L X 1.75"H X 2.5"W)--I don't remember where I got it, but Radio Shack has several that are close, so does Micro Center
  2. half-sized breadboard
  3. Adafruit Pro Trinket (5V)
  4. Adafruit Micro SD Breakout Board
  5. HC-SR04 Ultrasonic sensor (link for example--it can be found for
  6. Adafruit Class D Amp 
  7. 3in 8 Ohm speaker (I took mine from a clock radio)
  8. SPST toggle switch
  9. Sparkfun FTDI Basic Breakpout (for serial debugging)
  10. 9V Battery  (or any power supply > 5V)
  11. snap-on battery cap with leads (for 9V--other options for other power--e.g., a 4XAA enclosure)
  12. female-female jumpers
  13. JST connectors
  14. RCA phono plug and jack
  15. long header pins 

Construction:

  1. Upload the code to the Trinket.  I really didn't have to do this first, but since is was written for the UNO on an earlier version of the IDE, I wanted to make sure.  All good on IDE version 1.6.5...and I had to do it again once I realized that I needed to re-assign the Echo Pin
  2. I used long header pins (long on both sides) in the breadboard, and used JST female ends to connect to them, and soldered the JSTs to the leads to battery/switch, sensor,  and amp. I used female-female jumpers to connect to the SD breakout (also Speaker Pin to the amp). The amp itself is plugged into the breadboard via its header pins
  3. Drill holes in the enclosure (1/8" for the wires to the JST's, 3/8" for the RCA plug--yes I put the plug on the leads to the amp and the jack on the leads to the speaker)
  4. Solder header pins on the Trinket
  5. Solder leads to the RCA jack and plug (only need one of each since there's just one speaker), and the JST connectors
  6. Connect, test, and go

Code

/*2014-10-05
Halloween Candy Dish: Play random sound when kid reaches into bowl
*/
/*2014-10-05 HC_SR04 Distance sensor code added
 Need to modify pins for Halloween (13&12 used by SPI)
 2014-04-26 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)
*/
/* 2015-10-14
 Change to Pro Trinket from Uno to put the circuit in an enclosure
 Echo to 6 (Pro Trinket does not have pin 7)
 see virgilmachine.blogspot.com
*/

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

/*constants*/
#define SD_ChipSelectPin 10
#define trigPin 8
#define echoPin 6 //used to be 7 on Uno--Pro Trinket does not have a pin 7
/*variables*/
int song = 0;   // song number for random function
/*objects*/
TMRpcm speaker;   // create an object for use in this sketch

void setup(){
  randomSeed(analogRead(0));  //initialize random (A0 unconected)
  pinMode(trigPin, OUTPUT);   //pins for distance sensor
  pinMode(echoPin, INPUT);
  speaker.speakerPin = 9; //output to amp
  speaker.loop(0); //2014-10-05 do not 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.setVolume(7);   //attempt to increase volume
}

void loop() {
  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;
    Serial.print(distance);  //debug
    Serial.println(" cm");  //debug
//2014-10-05 If distance is <~5in someone has reached in 12/2.54cm=just under 5in
if (distance < 12)
    {
      song = random(1,10); //get random number from 1 to 9   sounds on SD card are 1.wav, etc.
      Serial.print("song: "); //for debugging
      Serial.println(song); //for debugging
      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;
      }
        delay(5000);
  }
delay(50);
}



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!




Thursday, October 8, 2015

Generator House--Better Than the Design




This is the reason why I have not been posting much lately. This carpentry project has held my attention.

A couple of months ago I used my generator house project to test out SketchUp and 123d-design (see this post).  Here's how the house came out.  Thanks to my brother-in-law, who has real skills, the design was modified to make it sturdier, by adding a lot of interior support, and by replacing the 1X2s I had for the floor with 6" 5/4 decking.  The only major shape change was to reduce the roof pitch from 30 degrees to 15 (I used 30 to make the calculations of rear elevation and roof width simple),


Here are some photos to show the construction: