Reader small image

You're reading from  C Programming for Arduino

Product typeBook
Published inMay 2013
Reading LevelIntermediate
PublisherPackt
ISBN-139781849517584
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Julien Bayle
Julien Bayle
author image
Julien Bayle

Julien Bayle owns his Master Degree of biology & computer sciences in 2000. After several years in pure IT System Design, he founded Design the Media early 2010 in order to provide his own courses, training & tools for art fields. As a digital artist, he designed some huge new media art installations, like the permanent exhibition of La Maison des Cinématographies de la Méditerranée (Château de la Buzine) in Marseille, France, in 2011. He also works as a new media technology consultant for some private & public entities. As an A/V live performer, he plays his cold electronic music from New York to Marseille, where he actually lives. Arduino framework is one of his first electronic hardware studies early 2005 and he designed the famous protodeck controller with some opensource framework too. As an art & technology teacher, also certified by Ableton in 2010, he teaches a lot of courses about the digital audio workstation named Ableton Live, about the real-time graphical programming framework Max6 and also about Processing and Arduino. As a minimalist digital artist, he works at the crossroads of sound, visual and data. He explores relationships between sounds and visuals through his immersive A/V installations, his live performances and his released music. His work, often described as “complex, intrigating and relevant”, tries to break classical codes to bring audience a new vision of our world through his pure digital and real-time generated stimuli. He's deeply involved in the open source community and loves to share and provide workshops and masterclasses online and on-site too. His personal website is http://julienbayle.net.
Read more about Julien Bayle

Right arrow

Chapter 8. Designing Visual Output Feedback

Interaction is everything about control and feedback. You control a system by performing actions upon it. You can even modify it. The system gives you feedback by providing useful information about what it does when you modify it.

In the previous chapter, we learned more about us controlling Arduino than Arduino giving us feedback. For instance, we used buttons and knobs to send data to Arduino, making it working for us. Of course, there are a lot of point of view, and we can easily consider controlling an LED and giving feedback to Arduino. But usually, we talk about feedback when we want to qualify a return of information from the system to us.

Arkalgud Ramaprasad, Professor at the Department of Information and Decision Sciences at the College of Business Administration, University of Illinois, Chicago, defines feedback as follows:

"Information about the gap between the actual level and the reference level of a system parameter which is used to...

Using LEDs


LEDs can be monochromatic or polychromatic. Indeed, there are many types of LEDs. Before going though some examples, let's discover some of these LED types.

Different types of LEDs

Usually, LEDs are used both to block the current coming from a line to its cathode leg and to give light feedback when the current goes into its anode:

The different models that we can find are as follows:

  • Basic LEDs

  • OLED (Organic LED made by layering the organic semi-conductor part)

  • AMOLED (Active Matrix OLED provides a high density of pixels for big size screens)

  • FOLED (Flexible OLED)

We will only talk about basic LEDs here. By the term "basic", I mean an LED with discrete components like the one in the preceding image.

The package can vary from two-legged components with a molded epoxy-like lens at the top, to surface components that provide many connectors, as shown in the following screenshot:

We can also sort them, using their light's color characteristics, into:

  • Monochromatic LEDs

  • Polychromatic LEDs...

Multiplexing LEDs


The concept of multiplexing is an interesting and efficient one. It is the key to having a bunch of peripherals connected to our Arduino boards.

Multiplexing provides a way to use few I/O pins on the board while using a lot of external components. The link between Arduino and these external components is made by using a multiplexer/demultiplexer (also shortened to mux/demux).

We spoke about input multiplexing in Chapter 6, Playing with Analog Inputs.

We are going to use the 74HC595 component here. Its datasheet can be found at http://www.nxp.com/documents/data_sheet/74HC_HCT595.pdf.

This component is an 8-bit serial-in / serial-or-parallel-out. This means it is controlled through a serial interface, basically using three pins with Arduino and can drive with eight of its pins.

I'm going to show you how you can control eight LEDs with only three pins of your Arduino. Since Arduino Uno contains 12 digital usable pins (I'm not taking 0 and 1, as usual), we can easily imagine using...

Using RGB LEDs


RGB stands for Red, Green, and Blue, as you were probably guessing.

I don't talk about LEDs that can change their color according to the voltage you apply to them. LEDs of this kind exists, but as far as I experimented, these aren't the way to go, especially while still learning steps.

I'm talking about common cathode and common anode RGB LEDs.

Some control concepts

What do you need to control an LED?

You need to be able to apply a current to its legs. More precisely, you need to be able to create a difference of potential between its legs.

The direct application of this principle is what we have already tested in the first part of this chapter, which remind us how we can switch on an LED: we you need to control the current using digital output pins of our Arduino, knowing the LED we want to control has its node wired to the output pin and its cathode wired to the ground, with a resistor on the line too.

We can discuss the different ways of controls, and you are going to understand...

Building LED arrays


LED arrays are basically LEDs wired as a matrix.

We are going to build a 3 x 3 LEDs matrix together. This is not that hard, and we'll approach this task with a really nice, neat and smart concept that can really optimize your hardware designs.

Let's check the simplest schematic of this book:

An LED can blink when a current feeds it, when a voltage is applied to its legs

In order to switch off the LED shown in the preceding screenshot, we can stop to create the 5 V current at its node. No voltage means no current feeding. We can also cut the circuit itself to switch off the LED. And at last, we can change the ground by putting adding a 5 V source current.

This means that as soon as the difference of potential is cancelled, the LED is switched off.

An LED array is based on these double controls possible.

We are going to introduce a new component right here, the transistor.

A new friend named transistor

A transistor is a special component that we introduced a bit in the first part...

Simulating analog outputs with PWM


As we know very well by now, it's okay to switch on/off LEDs, and as we are going to see in the next chapter, to switch on/off many things too by using digital pins as output on the Arduino.

We also know how to read states from digital pins set up as inputs, and even values from 0 to 1023 from the analog inputs from in the ADC.

As far as we know, there isn't analog output on the Arduino.

What would an analog output add? It would provide a way to write values other than only 0 and 1, I mean 0 V and 5 V. This would be nice but would require an expensive DAC.

Indeed, there isn't a DAC on Arduino boards.

The pulse-width modulation concept

The pulse-width modulation is a very common technique used to mimic analog output behavior.

Let's put that another way.

Our digital outputs can only be at 0 V or 5 V. But at a particular time-interval, if we switch them on/off quickly, then we can calculate a mean value depending on the time passed at 0 V or 5 V. This mean can easily...

Quick introduction to LCD


LCD means Liquid Crystal Display. We use LCD technology everyday in watches, digicode display, and so on. Look around you, and check these small or great LCDs.

There exist two big families of LCD displays:

  • Character LCD is based on a matrix of characters (columns x rows)

  • Graphical LCD , is based on a pixel matrix

We can find a lot of printed circuit boards that include an LCD and the connectors to interface them with Arduino and other systems for cheap, nowadays.

There is now a library included in the Arduino Core that is really easy to use. Its name is LiquidCrystal, and it works with all LCD displays that are compatible with the Hitachi HD44780 driver. This driver is really common.

Hitachi developed it as a very dedicated driver, that includes a micro-controller itself, specifically to drive alphanumeric characters LCDs and to connect to the external world easily too, which can be done by a specific link using, usually, 16 connectors, including power supply for the...

Summary


In this long chapter, we learned to deal with many things, including monochromatic LEDs to RGB LEDs, using shift registers and transistor arrays, and even introduce the LCD display. We dug a bit deeper into displaying visual feedbacks from the Arduino without necessarily using a computer.

In many cases of real life design, we can find projects using Arduino boards totally standalone and, without a computer. Using special libraries and specific components, we now know that we can make our Arduino feeling, expressing, and reacting.

In the following chapter, we are going to explain and dig into some other concepts, such as making Arduino move and eventually generating sounds too.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
C Programming for Arduino
Published in: May 2013Publisher: PacktISBN-13: 9781849517584
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Julien Bayle

Julien Bayle owns his Master Degree of biology & computer sciences in 2000. After several years in pure IT System Design, he founded Design the Media early 2010 in order to provide his own courses, training & tools for art fields. As a digital artist, he designed some huge new media art installations, like the permanent exhibition of La Maison des Cinématographies de la Méditerranée (Château de la Buzine) in Marseille, France, in 2011. He also works as a new media technology consultant for some private & public entities. As an A/V live performer, he plays his cold electronic music from New York to Marseille, where he actually lives. Arduino framework is one of his first electronic hardware studies early 2005 and he designed the famous protodeck controller with some opensource framework too. As an art & technology teacher, also certified by Ableton in 2010, he teaches a lot of courses about the digital audio workstation named Ableton Live, about the real-time graphical programming framework Max6 and also about Processing and Arduino. As a minimalist digital artist, he works at the crossroads of sound, visual and data. He explores relationships between sounds and visuals through his immersive A/V installations, his live performances and his released music. His work, often described as “complex, intrigating and relevant”, tries to break classical codes to bring audience a new vision of our world through his pure digital and real-time generated stimuli. He's deeply involved in the open source community and loves to share and provide workshops and masterclasses online and on-site too. His personal website is http://julienbayle.net.
Read more about Julien Bayle