Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Fun things to do with an Arduino Uno board?

Author
Message
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 27th Aug 2012 03:18
This semester at uni we will get to build what's called a 'Boe-bot'. So far we have only fiddled around with an Arduino Uno board and programmed a few LEDs, switches and logic gates. I'm very new to the electrical/hardware side of programming/computers and so to gain a bit more experience my Uncle lent me an Arduino Uno to play with. I'm going to buy myself a breadboard, few LEDs, resistors and switches but I think I'll get bored of programming flashing lights very soon. So what are some fun (but not too expensive) things to do with the Arduino board?

Cheers

TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Aug 2012 18:38 Edited at: 27th Aug 2012 18:40
Here are a few fun projects.

0. Learn the basics

I wrote this section last, but it's important before you continue with the other 3.

I've never used an Arduino before, I have however programmed loads of micro controllers so I'm assuming they are about the same thing. You need to have a basic understanding of it's functionality. This includes:

-Know the language you're programming in
-Know your chip
--> Configuring pins (Analog, digital, Input, Output, High Impedance etc.)
--> Using memory (EEPROM, RAM etc.) (although most of this is built in to the programming language)
--> Configuring the system clock (internal, external?)
-Know how to use the built in modules of the chip
--> Interrupts (very important!)
--> Timer modules
--> A/D and D/A converters
--> PWM modules (if any)
--> Communication modules (I2C, UART, etc.)

1. Programmable signal filter

In the electronics world today you will face a lot of problems where you'll have to manipulate analog signals. This should give you a small idea of how these filters work. The first most basic filters you'll learn of are:

-High-pass filter
-Low-pass filter
-Band-pass filter
-Band-reject filter
-All-pass filter

There are much more complex ones such as zobel networks, but that's something for later.

More info about basic filters here

Usually these filters are realised using analog components, for example, a passive high-pass filter is nothing more than a capacitor in series with a resistor.

Getting back to the Arduino.

1) Use the A/D converters on the Arduino board to convert an analog signal into a form which can be processed by a program.
2) Process the converted signal by simulating one of the filters listed above.
3) Output the digital signal through a D/A converter back to an analog signal.

That's the basic layout of this project.

Useful notes

I've heard from DBD79 that the analog outputs of an arduino use a PWM module clocked at a very low frequency. This means that the output signal isn't exactly pure analog, it's a square wave with different duty cycles. In order to convert it to an analog signal you'll need to use this circuit : http://forum.thegamecreators.com/xt/xt_apollo_pic.php?i=2389100

2. PWM project #1

Another huge thing you'll face in the electronics world and programming world are PWM signals. Pulse Width Modulation is nothing more than a square wave, but you change the on-time to off-time ratio (also known as "duty cycle"). A duty cycle of 100% means you're outputting a "high" signal all the time, a duty cycle of 0% means you're outputting a "low" signal all the time. A duty cycle of 75% means it's "high" for 3/4 of the time and "low" for 1/4 of the time. The frequency doesn't matter, it's the ratio that matters.

Before moving on to PWM project #2 I suggest you try controlling an LED with this signal. If you do it correctly, you will be able to change the brightness of the LED (as long as the frequency >60Hz so you can't see it flash).

3. PWM Project #2

PWM signals can also be used to amplify music. Look up "Class D amplifier" for more on that subject. Here's a small video showing what can be done with PWMs:



I hope that's sufficient.

TheComet

"if you don't understand recursion than you probably don't understand recursion." ~Jerico2day

Attachments

Login to view attachments
The Wilderbeast
19
Years of Service
User Offline
Joined: 14th Nov 2005
Location: UK
Posted: 27th Aug 2012 23:05
Nice post above.

I would further that by suggesting that you do some audio projects with it - they're a great example of DSP and any changes you make will have a really noticeable outcome - very rewarding!

Here's a suggestion:
Solder on a 3.5mm socket to one of the analogue pins and try adding some effects processing before routing the signal back out of another analogue pin and into a speaker.

This site has some great sample code - http://www.musicdsp.org/archive.php?classid=4

Be warned though that the ADCs are going to be far from stellar!

TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Aug 2012 23:09
Here's a good article on PWM signals : http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM

And again, use this circuit to filter the analog output before you hook it up to anything:



TheComet

"if you don't understand recursion than you probably don't understand recursion." ~Jerico2day
MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 28th Aug 2012 02:20 Edited at: 28th Aug 2012 02:59
TAG





EDIT

I want to learn to make stuff like this... eventually for when I get bored...



think you should also have a look at this... as i really want to make these suits...



I especially love the sound of those old printers ^^

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 28th Aug 2012 05:58 Edited at: 28th Aug 2012 12:30
Quote: "0. Learn the basics"

That's where I'm at .

Quote: "-Know your chip
--> Configuring pins (Analog, digital, Input, Output, High Impedance etc.)
--> Using memory (EEPROM, RAM etc.) (although most of this is built in to the programming language)
--> Configuring the system clock (internal, external?)
-Know how to use the built in modules of the chip
--> Interrupts (very important!)
--> Timer modules
--> A/D and D/A converters
--> PWM modules (if any)
--> Communication modules (I2C, UART, etc.)"

These are the bits I need to learn right now. We program the Arduino using C which I'm comfortable with but the rest of the things listed are what I need experience with. Would you be able to list a few small projects (links are fine) which demonstrates some of these?

Quote: "Nice post above."

TheComet writes some of the best posts on this forum.

Dark Java Dude 64
Community Leader
14
Years of Service
User Offline
Joined: 21st Sep 2010
Location: Neither here nor there nor anywhere
Posted: 28th Aug 2012 08:37 Edited at: 28th Aug 2012 08:41
Do you have the Arduino IDE or are you using some other 3rd party application?

Quote: "I'm going to buy myself a breadboard, few LEDs, resistors and switches but I think I'll get bored of programming flashing lights very soon."
Get some sort of audio transducer as well! I'd recommend a piezo electric earbud! No idea where to get one but I have one in my electronics kit. Radio Shack, Mouser, and DigiKey are excellent places to look for something as the such!

Some places are a tad on the rip off side, not to mention any names... ***cough***RadioShack***cough***

"MOVE R1,R2"~~Genesis 1:1, Bible
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 28th Aug 2012 12:29
Quote: "Do you have the Arduino IDE or are you using some other 3rd party application?"

I program the arduino using the Arduino IDE.

Quote: "Get some sort of audio transducer as well! "

Is that a fancy word for a speaker? If they're not too expensive I might pick one up.

Quote: "I'd recommend a piezo electric earbud!"

Is that common? If not will any (small) audio transducer do?

That Guy John
15
Years of Service
User Offline
Joined: 30th Apr 2010
Location: United States
Posted: 31st Aug 2012 15:25 Edited at: 31st Aug 2012 16:04
Hodgey,

There are a ton of resources for Arduino. Ive been playing with it for a couple months now , here and there.

Interfacing between Arduino and your own application on your desktop is really simple with serialport communication too.
I have a really simple sample I made when I was trying to figure out how to interface with it. The desktop app is done in vb.net using serialport. The Arduino code sends values from an analog sensor through the serialport. Then the vb app reads those values and performs actions based on the values. Very simple proof of concept.

Working with analog sensors is a lot more fun and functional than playing with LEDS.


[Attached] Read Analog project files for anyone that is interested. Includes the Arduino ".ino" and the vb.net source. The circuit is using the Photo-resistor for the Analog sensor.

And Here Is A Penguin:
FPSC OneSource [DeskTop App] - Bringing everything together into one.

Attachments

Login to view attachments
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 31st Aug 2012 16:55 Edited at: 31st Aug 2012 17:02
Quote: "Would you be able to list a few small projects (links are fine) which demonstrates some of these?"


Most of those features listed can be applied in projects in the first post I made. I cannot stress the importance of interrupts enough, so here's a small post to get you started on that.

What is an interrupt? (or to use the proper term: ISR -> "Interrupt Service Routine")

An interrupt is - as the name suggests - an interruption which is triggered at any point in the program. It literally stops your program from being executed, immediately jumps to the interrupt service routine and begins executing the code there. Once that's done, it jumps back to where the program was stopped and resumes it again.

This is a technique introduced into micro controllers and computers today in general for multiple reasons.

1) By using interrupts you can create the illusion of processing multiple things at once.
2) It enables the micro controller to react to things immediately.
3) Interrupts can be used for time controlled things (we'll look at an example soon)
4) It allows the micro controller to do literally nothing when there's nothing to do. No really, the CPU is actually turned off when it finishes processing whatever, and the micro controller goes into sleep mode. This saves a lot of power and is very useful for low power applications (With "lower power" we're talking micro amps). Interesting fact: The "Game Boy" from nintendo had the CPU in idle mode for over 80% of the time.

Important things to know

ISRs have to contain as little code as possible. Actual processing of the data should be avoided if possible (and in almost all cases they are avoidable). The reason for this is to keep the execution time of the ISR below the time intervals between calling it. If your ISR takes longer to execute than the time it takes to call it, it will be "swallowed". The main program won't have any time to execute at all, and you'll be opening new interrupts again and again.

This leads me to explaining the technique of how to handle interrupts. Here is a very common example:



So lets go through that by making up an example. An old man is sleeping in his chair next to a telephone. Suddenly, the telephone rings. The old man wakes up and answers the phone. He gets loads of information which he writes down onto a piece of paper. Angry, he hangs up the phone and begins doing all of the things listed on the piece of paper. Half way through the phone rings again! Damn it, the old man drops what he's doing and answers the phone. More things to do! The old man notes these things down onto the paper as well, hangs up the phone, and continues working his way down the list of things to do. Finally, he finishes the last instruction. Satisfied, he sits back onto his chair and goes to sleep.

There's no difference between that story and what's happening with your micro controller. Note how the old man wrote onto a piece of paper what he had to do. Imagine if the old man had sat on the phone and did all of the things directly, what do you think would have happened? That's right, he would have missed the second call completely. That's why it's important to do as little as possible in ISRs.

How does the micro controller handle them?

First of all, there's a global flag for interrupts stored in the CPU status register (SREG). You can think of this as a main switch. If this switch is turned off, interrupts won't work at all. If it's turned on, then they will work.

There is also a local flag for every individual interrupt stored in another register. With these you are able to enable/disable specific ISRs at any time you wish.

There might be a time where you don't want to be interrupted during your processing. That's when you can temporarily disable specific or all interrupts in the system. After you've finished processing whatever you are doing, you can re-enable them.

So what happens when an interrupt occurs during the time when you have them disabled? Quite simple really, the interrupt is queued. So when you re-anble the interrupt flags, all of the queued interrupts will execute. The only time when you'll lose a queued interrupt is if the exact same interrupt service routine is called again. Then it will just replace the last one.

Getting familiar

In order to get familiar with interrupts, I first suggest to do one of the simples things possible: A flashing LED at exactly 1 Hz. Here's pretty much the procedure:

There are different types of timer modules, so I'll explain the one I use to you.

Mine has a 16 bit counter (it's able to count from 0-65535). You are able to specify the starting value (from where it begins to count) and the end value (where it should stop counting). From there I can also tell it to reload the starting value and begin counting again (so it does this continuously).

It also has a divider of either 2,8 or 12 (strange numbers, I know). This means that it divides the clock frequency by said number, and passes that to the counter.

So for example, my clock frequency is 40 MHz. I tell the timer module to divide it by 12, which gives me 3.333 MHz. Still way to high for creating any interrupts, but that's what the counter is for. The end frequency I want is 100 Hz, so now all I have to do is solve for the maximum counter value : Counter = 3.333 MHz / 100 Hz = 33'333. Excellent, I set my counter to count from 0-33333, and that means that the counter reaches 33333 every 10ms.

The last thing I do is I tell the timer module to trigger an interrupt when it resets.

This means that the interrupt is triggered once every 10ms. So logically, in order to get the LED to flash at 1 Hz, you'll have to count how many times the interrupt occurs, and invert the LED when it reaches a value of 50.

My boss is staring at me and I think he knows that I'm not doing what I'm supposed to.

Hope this helped!

TheComet

"if you don't understand recursion than you probably don't understand recursion." ~Jerico2day
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 1st Sep 2012 00:30
@That Guy John,
Thanks, I'll look into that.
Quote: "The desktop app is done in vb.net using serialport. "

I assume I can do the same thing in the Arduino IDE using C? I don't feel like installing VB.NET (it's a bit much for the simple things I'd like to do) .

@TheComet
Thanks for the above post, you're very good at summarizing while including key details. I still need to get a few bits and pieces but I'll try out the demo as soon as I can.

Quote: "My boss is staring at me and I think he knows that I'm not doing what I'm supposed to."

If you lose your job, move to Australia and become a tutor at Sydney Uni.

TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 1st Sep 2012 01:00
Quote: "If you lose your job, move to Australia and become a tutor at Sydney Uni. "


It's funny you should say that, for it is my intention to go and study electronics engineering at Melbourne university.

Glad to help.

TheComet

"if you don't understand recursion than you probably don't understand recursion." ~Jerico2day
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 1st Sep 2012 01:28
Quote: "it is my intention to go and study electronics engineering at Melbourne university."

I've heard Melbourne university is pretty good, I hope you get in mate.

That Guy John
15
Years of Service
User Offline
Joined: 30th Apr 2010
Location: United States
Posted: 1st Sep 2012 02:57 Edited at: 1st Sep 2012 03:07
Hodgey,

For your desktop interface you can use any language you want. As long as you can read and write to the serialport.

Since you are a student I suggest registering at DreamSpark.com . You will get access to quite a bit of free (expensive) software. I did it last semester and my licenses are good til 2015.

Visual Studio Professional and Microsoft Expression Ultimate come in handy.

Just so you understand, I use the Arduino IDE to code the Arduino. Then I use Visual Studio to code my desktop app to interface with the Arduino.

Most people around the Arduino community use Processing to interface with Arduino though.

[Attached] You got me digging through my Arduino Folders now.
The project attached to this post has a vb app that writes to the serialport then the Arduino reads the serialport and turns on \ off LEDS depending on what is sent by the vb app. I did this one to get the jest of talking back and forth to the Arduino. Source code for the Arduino and VB app included.

And Here Is A Penguin:
FPSC OneSource [DeskTop App] - Bringing everything together into one.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2025-05-18 07:53:19
Your offset time is: 2025-05-18 07:53:19