Main > Everything Else

Halloween costume

<< < (5/6) > >>

SavannahLion:

--- Quote from: Mysterioii on October 17, 2012, 03:48:38 pm ---Pretty easily really.  The arduino has several GPIO pins....  you'd just need to define some as inputs then wire some pushbuttons to them....  your wire runs could be pretty long and it wouldn't hurt anything, if you wanted to put the pushbuttons on his belt or something.  I would just put a pulldown resistor to ground on each input pin to keep them from floating, then connect one side of each momentary pushbutton to +5v and the other to an input.

Because of the pulldown resistors to ground you'll get a nice clean ground on each input when you don't press a button (otherwise they'd float and you might get some false positives).  Then your code just needs to loop forever and constantly check the inputs.  If you see a high, tell the wave shield to play the appropriate sound, then start checking for high inputs again.

--- End quote ---

OK....

To begin with. Wave shield from ADA is very very nice and it saves a lot of soldering so for anyone who doesn't know or care to solder, go get it. However.....

If you're good, you have basic soldering skills and you know how to port code, look for the AVR335 (this is the one I'm referencing) document or check out http://elm-chan.org/he_a_e.html or http://avrpcm.blogspot.in/ for alternative solutions (read: cheaper). Just don't wire the I/O pin directly from the AVR to the speaker. Fine for testing, but you'll burn it out in the long run.

Second...
Don't use pull down resistors. The AVR doesn't need to read buttons that way. The AVR's (Arduino's included) have built-in pull-ups. Use them and save yourself some soldering. It's even outlined in one of the manufacturers docs. Set the desired port(s) for INPUT then activate the PULLUPs for whatever pins you need.

Finally, contrary to what some... experts might tell you. This isn't going to hurt the AVR. You don't need resistors in series. If you want to know what the ohmage is it's squirreled away in the individual controller's docs. But unless you're doing some funky stuff, it's not really crucial in this kind of application. Remember, set to INPUT then switch on the pull-ups. The specific steps are, again, detailed in the docs.

I have copies of the docs squirreled away on my laptop, if you're jonesing for the file names, I can see if I can dig around and find them. I probably accumulated about 50 or so docs related to the AVR lines.

But I digress. The technique I describe is the exact same method that both Andy's and Randy's products use to read arcade buttons. So, wiring everything up is no different. Common ground, each switch gets their own IO.

If you want to get fancy and start using matrix's or whatever. Arduino has libraries that handle those as well OR you can search around for what kind of heavy lifting that involves. My preference is to use C or ASM instead of the Arduino libraries. Mostly because I don't feel like shelling out $100 or more for a bunch of shields when I can tear apart what's in my scrap bin and pay only $15 or so for an AVR board (I purchased one that's Arduino compatible similar to a Teensie).

Mysterioii:
A thousand pardons good sir, I don't have an arduino in front of me and I was typing that up 10 minutes before I had to leave so I failed to fact check.  The last thing I worked on used an I2C GPIO expander that did not have any built-in pullup or pulldown resistors so I had to handle it myself to avoid floating inputs.  When rolling my own I prefer to pulldown inputs to ground then switch high, because to me 'high' = 'on', but yes, if you've got pullups built into the device then definitely use them then switch ground to the pins to keep it simple.

I don't think I anywhere implied that anything would damage the device?  In the absence of built in pullups, which I forgot about, then the pulldowns are just to ensure that there is a ground at the pin when you're not pressing the switch at that input.  Otherwise you'd get a floating input, which could give you some false readings.  It's not damaging at all, it's just not clean and can lead to undesired behavior.  You don't need both pullups and pulldowns simultaneously, I agree.  But you need one or the other.


--- Quote --- To begin with. Wave shield from ADA is very very nice and it saves a lot of soldering so for anyone who doesn't know or care to solder, go get it.
--- End quote ---

The wave shield is available only as a kit, so it doesn't save you all that much soldering really.  It's an easy to assemble kit though, and they walk you through it very well on the web page.

https://www.adafruit.com/products/94

It sounds like the arduino environment didn't support enabling the internal pullups directly until recently?  The very most recent release actually.  True you don't have to program AVRs using the arduino interface, but for a beginner it makes it very easy to get started.


--- Quote ---As of Arduino 1.0.1, it is possible to enable the internal pullup resistors with the mode INPUT_PULLUP.  Additionally, the INPUT mode explicitly disables the internal pullups.
--- End quote ---

The code you linked to about playing sounds directly from the AVR is cool, however it looks like you have to actually store the audio as program memory in the code itself.  That's fine if you don't mind re-encoding the audio and recompiling then reprogramming your controller every time you want to change the sound clip.  You're also limited to the memory space within the controller (you could of course interface with external memory, but that's outside the scope of the example).  The wave shield reads files off an SD card, no need to recompile or reprogram anything if you just want to swap some sounds out.  You're not limited to program memory space, it's got a volume thumbwheel, headphone jack etc.  It also uses a real DAC instead of trying to approximate things using the PWM outputs.

As always, there's more than one way to skin a cat, use whatever meets your needs.   :cheers:  There's "cheaper" and there's "beginner friendly".  If someone without much electronics experience is trying to throw together a costume for their kid two weeks before Halloween I'd spend a few more bucks and go for the easier implementation.


--- Quote ---Mostly because I don't feel like shelling out $100 or more for a bunch of shields when I can tear apart what's in my scrap bin and pay only $15 or so for an AVR board (I purchased one that's Arduino compatible similar to a Teensie).
--- End quote ---

Yes I agree with you...  not everyone has the time to do that though, nor the expertise to know where to begin.  The arduino is a gateway drug for hobby electronics, it's not suited for everything, but it's a good way for people to get their foot in the door.  There's a large established community, example code all over the place for just about anything.  It's a good place to start...  I also have some Teensy boards... the guy just released an ARM version, Teensy 3.0.  He just finished up a kickstarter for it, I got some for about $19.  Regular price will be a bit higher than that I believe.

One more note... the wave shield is apparently not pin compatible with the arduino leonardo version... so if you get one, either use it with an older arduino model or be prepared to clip a couple of pins and do some rewiring.

SavannahLion:
My apologies if it sounded like I was getting on you about damaging the AVR via the pullups. That's in reference to a different thread where I brought that up and was pounced on by a different member. At the time I couldn't articulate the logic behind it. After working with my selected AVR, I can now.

The Wave is kit only? I missed that blurb. I saw the $20 price tag for something I'm already halfway through and didn't read much further into it. Well, i stand corrected.

I wasn't aware that Arduino didn't allow support of the internal pullups until recently. Another annoyance from a substandard language everyone keeps humping. As far as I know, the Arduino was always on the AVR platform until recently and Atmel's introduction of internal pullups pre-date Arduino's creation.

I have never liked how the Arduino handles the ports. It's borderline absurd to enforce dynamic pin assignments for a microcontroller when those assignments could be done at the compiler. I see why it was done, it's just a massive waste of resources. It appears I'm not the only one that feels that way as I see a lot of people shift down to direct pin handling.


Apologies out of the way....

I had a hard time dealing with the concept of 0==on until I realized how easy it was to handle the states within ASM. Most of the time, I was looking for a change in state, not whether it was on or off.  Using pulldowns is valid, just not the sensible thing to do with the AVR series.

Whoops, I thought I included a link that outlines how to use an SD card of your own. I know the AVR335 doc uses a bit of memory via SPI which should easily be adaptable to any other serial memory.

However, the link where you compile in the audio shouldn't be ignored. This one allows audio using the absolute minimum amount of hardware. Using this project as a base gives you a way to test construction of a speaker setup without going through the headache of getting a bit of memory expansion working correctly. In any case, if you look around, you'll find the .wav file is just a contaimer format that adds a lot of fat and overhead to a microcontroller. Why have stereo when you only have one speaker? Make it mono, set a standard bit rate, strip the container and voila! Anyone who can write C and solder should have enough skills to pull that off. Hell, I actually found it easier to do the audio files. It was a lot harder to work out which of the registers I needed to set to get PWM going.

Mysterioii:
No problem man, and sorry if I got a bit defensive.  It sounds like you truly have worked with AVRs more than I have so I give you props.  My background is EE but I have been out of the field for like 10 years and only recently have been making an effort to get back into things, but the field has evolved and I'm quite a bit behind the curve, and thus I came back into things at the hobby electronics level and am building back up from there.  Lots of cobwebs regarding uC's that I am still shaking out of my head.

I like the arduino for what it is...  a good introduction.  I build a water monitor system for my home with an arduino and an ethernet shield that I talked about in another thread...  monitors a bunch of water sensors, tilt switches on a sewage shutoff valve, disconnects power to a sewage ejector pump when the valve is closed, has a warning buzzer, LED indicators on the device and by the front door to alert you to the status...  It serves up a web page so you can check the status of all the sensors from anywhere in the world, and will send me an email/text whenever a critical status is detected (ie. water in my basement).  It does other stuff too, but I won't bog things down here.  The code compiles down to 19K, I'm fairly proud of it, I think I got the most out of the arduino there.  Going forward I won't feel constrained to sticking with the arduino platform, but it was a nice way to get back into things.  And if you ever need to do something basic really quick, like blink some LEDs, it's a pretty quick way to make it happen.

One thing I like about the community is that it's mostly open source, so you can see the schematics for the arduinos and most of the shields themselves.  For my next big project I'd like to try my hand at PCB design (rather than prototyping on perfboard and wirewrapping a ton of stuff), and having a bunch of open source shield designs would help one cannibalize the designs and pull everything of interest together into one custom board.

Anyhoo, yeah there are different approaches.  It actually irks me a bit that they just now included the ability to use the internal pullups...  I'd have to go back and check my monitor system design but since I did it on their platform and thus couldn't enable the internal ones at the time I bet I did use some external pullups or pulldowns (actually I really think I used that I2C GPIO chip for most inputs and only used the arduino pins for outputs, so it was a non-issue there).

SavannahLion:
Now I remember your name. I saw that discussion. Gave you props IIRC.

That's the kind of project that deserves a writeup, not that constant stream of ---smurfy--- "look at me I can turn an led on" that keeps cropping up all over the place.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version