Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
So You Got an Arduino (codelord.net)
23 points by abyx on May 14, 2009 | hide | past | favorite | 17 comments


When I was first learning microcontroller programming, nobody told you this stuff. The great thing about the Arduino community is that it makes casual hacking so much easier to get into.

Another great resource for hardware hacking is the SparkFun tutorials:

http://www.sparkfun.com/commerce/tutorials.php


There are builtin “software” pull-up resistors

Cool, didn't know that. I've seen it used in code once, but I couldn't understand why someone would write to an input pin.


They're not really software resistors; they're hardware that's controllable from software. </pedantry>

And this is very useful; this will definitely save some resistor wiring. Now if only there was some easy way to debounce a switch in software....


It's not too bad: keep an exponentially decaying average of the pin state, and use some hysteresis (different levels for on/off) on that value. You should be most of the way there.

It'll take (worst case) 8 bits for the average and 1 for the current state. You could probably still get reasonable results with a 7-bit average so that the whole thing still fits in a byte of RAM.


Is it just me, or does this idiom sound very similar to one of the critiqued "incorrect" programming idioms in the recently analyzed breathalyzer code?


Yes; it's almost identical. It's one of the simplest digital low-pass filters you can write. Basically, it does the same thing that an analog R/C filter would do (given sufficient precision and sampling rates).

The issue with the breathalyzer code wasn't that the algorithm was incorrect, but that the programmer used the wrong algorithm.


After reading a button press, wait a while for the level to settle (say 50ms or so). This kind of thing is normally done from a timer interrupt that polls all buttons and saves their state for the foreground thread (I'd think this would be in the Arduino library somewhere).


It (debouncing) is available as a library from the arduino site: [http://www.arduino.cc/playground/Code/Debounce](http://www.a...


I really wish the ATMega chip family had built in usb functionality. That would make them a good competitor to the Microchip PIC 18F family.



Yes, thank you very much.


Out of curiosity, is it possible to get USB functionality out of the chip at the software level? Or is speed the issue?


Yes, you can, but obviously speed is an issue. You will never saturate an USB 2.0 link with a pure software stack on an ATMega, but reading out a few sensors or some input device that is limited by the speed of the user's fingers is possible, search for avr-hid or hidkeys (can't copy and paste URLs in Opera Mini).


Cool, thanks.


I was hoping to have some examples of projects.

I'm interested in Arduino but have yet to find a good project to begin with.


The critter-guitari Pocket Piano is a great shield for Arduino, and it has the advantage that it gives you a lot of hardware to play with as well ..

http://www.critterandguitari.com/home/store/arduino-piano.ph...

I built one for fun, and ended up using it in jam sessions as a serious synth. Great!


USB is serial.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: