Learn to build simple circuits on a Propeller microcontroller development board, and create BlocklyProp graphical programs to interact with them. In no time, you will be blinking LEDs, controlling LEDs with pushbuttons, playing notes on a piezo speaker, and more. The circuits are built on on the Propeller Activity Board (original or WX) or on a breadboard with a Propeller FLiP module. Using a multicore microcontroller, standard breadboard, and basic electronic components, you will be building real-world STEM skills.
You will be ready to make your own projects that combine these simple electronic components. How about making an LED blink faster by turning a dial, or using pushbuttons to make the piezo speaker beep different tunes?
Once you have learned Simple Circuits, you will be ready to put those new skills to the test!
The Propeller microcontroller has 32 input/output pins, or I/O pins, labeled P0 through P31. The Propeller can interact with other circuits connected to these I/O pins, through programs that use these labels. A Propeller I/O pin can do three things:
We'll experiment with the "O" (output) feature of an I/O pin by programming the Propeller to turn a light on and off. The light circuit, which includes a small LED and resistor, is already built into the Propeller Activity Board (original or WX) or the Propeller FLiP module. That built-in circuit is connected to I/O P26, so our code will use P26 instead of P14 (like in the picture above.)
Note: if you are using a different Propeller board that does not have a built-in lights connected to P26 and P27, build the equivalent circuit using the schematic.
In BlocklyProp, you can turn an LED on or off with a single block: the Pin states block make PIN (dropdown).
The first make PIN block sets the Propeller chip's P26 I/O pin to output-high, which connects the pin to its 3.3 V supply. The pin applies 3.3 V of electrical pressure to the LED circuit, causing electric current to pass through it and the light to turn on. After that, pause(500) makes the program do nothing for 500 ms, which keeps the light on for half of a second.
Next, low(26) sets P26 to output-low, which connects the pin to its 0 V ground supply voltage instead. This takes away the electrical pressure, so the current stops flowing through the circuit and the light turns off. Another pause(500) makes the light stay off for half of a second.
The picture below is called a timing diagram. It is a graph with voltage on the vertical axis, and time on the horizontal axis. Timing diagrams are often used to describe the electrical interaction between microcontrollers and circuits or other devices. This timing diagram shows the output of I/O pin P26 from the test code above.
You can make the light blink faster or slower by changing the value in the pause block. You can also make the on-time different from the off-time by using different values in the two pause blocks.
Try controlling the P27 light along with the P26 light, according to the timing diagrams below.
Building and controlling circuits with the Propeller microcontroller is a great way to learn about electricity, and to experiment with making your own inventions. Building experimental circuits to design your own projects is called prototyping, and it is a real-world engineering skill. Before you start your Propeller prototyping, there are three important Reference pages you should have handy, especially if you have never built circuits on a breadboard before. Just click on each link at the page will open in a new tab or window.
Propeller Activity Board WX Product Guide [7]
The Propeller Activity Board has a breadboard mounted on it. Here, you can build your own circuits with common electronic components. (It also has lots of pre-built circuits for using a speaker, SD card, wireless RF module; read all about them in the Product Guide if you like, but they won't be used in the Circuit Practice tutorial.
The Propeller Activity Board's breadboard is surrounded on three sides by black sockets. These make it convenient to connect circuits on the breadboard to power, ground, and the Propeller I/O pins. There are also sockets to connect to a digital-to-analog converter and an analog-to-digital converter.
You had to set this switch to position 1 for the Hello World program, and to blink its built-in LEDs. Now, let's see how to use it when building circuits.
Propeller FLiP Module Product Guide [8]
The Propeller FLiP module is designed to plug right into a standard breadboard, where you can connect it to other circuits that you build. You can connect to any of its pins by inserting a wire or component lead into the same 5-socket row. Be sure to check each pin label on the board before making a connection. To learn more about what each pin does, see the Product Guide linked above.)
The FLiP Module's breadboard is made of several sections: two wider prototyping areas with 5-socket rows in two columns, and three narrow power rails with one long row for postitive connections and the other for ground. You use jumper wires to connect the power rails to power and ground connections on the Propeller FLiP module.
The Circuit Practice tutorial examples can all use power supplied by your computer's USB port. Most of the circuits will access 3.3V through the Propeller I/O pin connections. Some circuits will need to get power through Propeller FLiP module's 3.3V► pin. And all circuits will need a connection to ground.
Not every circuit needs every connection shown above. Each example circuit will have a wiring diagram to show which connections are necessary.
Since your Propeller FLiP module is powered through the USB port, you will need to unplug the USB cable to disconnect power. Always disconnect power before building or modifying circuits. To reset the Propeller chip to run a program over again, you only need to push the Reset button; you do not need to disconnect power just to reset.
You have blinked the built-in LEDs on your board. Now it's time to build your own LED circuits on your Propeller prototyping area.
A diode is an electrical part that only lets electricity flow through it in one direction. A light-emitting diode (LED) emits light when current passes through it. You have to make sure to connect an LED the right way for it to light up. If you plug an LED in backwards it will not hurt it, but it will not emit light.
An LED has two terminals: the anode and the cathode. The anode lead is labeled with the plus-sign (+), and it is the wide part of the triangle in the schematic symbol. The cathode lead is labeled with a minus-sign (-), and it is the line across the point of the triangle in the schematic symbol.
You can tell the anode and cathode apart by the shape of the LED’s plastic case. Look closely — it’s mostly round, but there is a small flat area near the cathode lead. Also note that the LED’s leads are different lengths. Usually, the shorter lead is connected to the cathode.
Always check the LED’s plastic case. Sometimes the leads have been clipped to the same length, or a manufacturer does not follow this convention.
Let's build three LED circuits on your breadboard. In addition to the three LEDs, you will need three resistors. Unlike the LEDs, the resistors do not have positive and negative leads, so you don't have to worry about plugging them in backward. Resistors resist the flow of electrical current. Each one has a value that tells how strongly it resists current flow, measured in ohms, often noted by Greek letter omega: Ω. Take a look at that Resistor Color Codes [6] page to see how its bands indicate its value.
This is the same test code that was used to blink the built-in P26 LED earlier in this tutorial, with the I/O pin number updated.
If you've verified that all three of your LED circuits are working, great! Continue on!
The make PIN block comes in two versions. The original one we have been using has a drop-down list for selecting the I/O pin number. The programmable version accepts a number value block, a use variable block, or any expression that resolves to a number.
Let's take advantage of the programmable make PIN blocks. Paired with the repeat item loop, its easy to make them light up one at a time in order.
Perhaps you want the LEDs to light up out of order! Instead of using the repeat item block, you could use the random operator to choose which LED should light up each time through the loop. It's available under Operators > Number.
Save your code, and click the Run Once button.
Can you imagine using this technique to make twinkling stars, scary eyes, or fireflies in a project?
Many items you use every day have pushbuttons. Cell phones, microwave ovens, TV remotes, and computer keyboards might all have pushbuttons. Can you think of others?
Let's use a common pushbutton circuit and build a program for monitoring it with your microcontroller. Then, let's use a pushbutton's state to control LED circuits. LEDs are just one example of a device you can turn on and off with a microcontroller. Your invention might instead use pushbuttons to control circuits for motors, heating elements, or other devices.
A pushbutton is a device that makes an electrical connection between two of its terminal leads when its button is pressed. When the button is released into its normally-open state, the electrical connection is broken and no current flows through the device. Here is the schematic symbol:
...and here is a drawing that resembles a breadboard-friendly pushbutton:
The Propeller I/O pins connected to pushbutton circuits must be set to inputs. If the pushbutton is pressed, the circuit applies 3.3 V to the I/O pin through the pushbutton, and a small amount of current also passes through the 10 kΩ resistor to ground. When the pushbutton is not pressed, the connection to the 3.3 V supply is broken, and so the circuit applies GND (0 V) to the I/O pin.
This circuit uses your board's built-in P26 and P27 LEDs, along with two pushbutton circuits you will build onto your breadboard. You may use either 220 ohm or 100 ohm resistors to connect the pushbutton circuits to the Propeller I/O pins. However, you must use 10 k-ohm resistors to connect the circuits to ground.
This test code will display the state of the button connected to P3 in the BlocklyProp Terminal. The Terminal displays 1 if the button is pressed, or 0 if it is not pressed.
After a Terminal clear screen block, the rest of the project is in a repeat forever loop. First, a Terminal print text block supplies a useful label "P3 button = " for our data. Next comes a Terminal print number block. Inside it, the check PIN 3 block sets the P3 I/O pin to input. If the Propeller senses 0 V on P3 while the button is not pressed, the block provides a 0, and that gets printed in the Terminal. If the Propeller senses 3.3 V on P3, the block provides a 1, and that gets printed instead. A pause (ms) 200 block slows down the loop just enough to display properly before repeating.
Now it is time to control an LED with a pushbutton! Remember if...do block from from the BlocklyProp Making Decisions [9] activity? It comes in very handy for this.
Let's get you modify your program to make the LED connected to P27 blink when the button connected to P4 is pressed?
Many devices beep to get your attention. Microwave ovens let you know your food is ready, alarm system keypads respond when you press a number key, and smoke alarms warn you something is burning. These devices often use piezospeakers because they are inexpensive, yet make clear, audible tones. If you make a project that needs to beep to get someone’s attention, consider using a piezospeaker.
Ever notice how a guitar string has to vibrate to make sound? The same applies to the element in a piezospeaker (short for piezoelectric speaker). The piezoelectric element in the speaker bends when voltage is applied to it. If you turn the voltage on and off rapidly, it will vibrate rapidly and make a sound.
It's easy to program the Propeller to make an I/O pin turn on/off rapidly. Let's connect a piezospeaker's positive (+) terminal to P4, and its unmarked negative terminal to GND.
(1) Piezo speaker (#900-00001)
(2) Jumper wires
The Audio > Frequency out block can make piezospeaker beep.
The frequency out block has three fields to set. PIN specifies the Propeller I/O pin connected to the piezospeaker, 4 in our circuit. The duration field sets how long the beep will last, 1000 ms (1 second) in this example. The frequency (Hz) field sets the pitch of the beep, 3000 Hz in this example. To generate this frequency, the Propeller sets P4 to an output and rapidy toggles it between 0 V to 3.3 V, causing the piezoelectric element inside the speaker to vibrate 3000 times per second. The result is a high-pitched tone.
To play a tune, you could use a stack of frequency out blocks, one block per note played. This works, but makes for a very long program that is cumbersome to edit. This next example stores a whole list of frequency values in an array, which are then accessed and played in order using a repeat item loop.
First, the array initialize block sets an array we named Notes, with 8 elements. The next block fills the Notes array with eight values. These are the frequencies for notes C8 to C7, taken from the keyboard chart above. Each value can be retrieved from the array later, by its index number. With arrays, index counting starts at zero, going from left to right. So, this eight-element array has an index range of 0 to 7, with the 0th element being 4160, and the 7th element being 2093.
Next comes a repeat item loop, with a variable named play to keep track of the trips thorugh the loop. The value of play starts at zero and increases by one each time up through trip 7, for a total of eight repetitions.
Inside the loop, the frequency out block is using PIN 4, and a duration of 500 ms. But instead of a number value block, the frequency (Hz) field has an array get element block attached: array Notes element play. This means "from the Notes array, use the element at the index position play."
The first time through the loop, play equals 0. The 0th element in the Notes array is 4160 (since counting starts at zero). So, the piezospeaker emits a 4186 Hz frequency. The next time through the loop, play increments by one, so the frequency at index position 1 is used: 3951 Hz. In this manner, the loop plays each frequency in the array until play equals 7, and you hear the last frequency of 2093 Hz.
The last example program, each note played for the same length of time, 500 ms. You can make it more interesting by playing notes for different durations. Just set up a second array to hold duration values, and use a second get array get element block for the
If you were to take the knob or dial off of an electronic device, you might find a potentiometer underneath it. A potentiometer is a variable resistor, and the kind shown below changes resistance as the knob turns. This particular one has a resistance range from 0 ohms to 10,000 ohms.
A capacitor is made of two metal plates placed very close together. When voltage is applied, electrons leave one of the plates and accumulate on the other to store an electrical charge, like a tiny battery. Its capacity to hold the charge is measured in farads. The one below is very tiny, just 0.1 microfarads. This one is not polar—it can be plugged into the circuit either way. (But be aware, some types of capacitors are polarized [10].)
These two components together form an RC (resistor-capacitor) circuit. We can figure out the position of the potentiometer's knob by inferring the resistance it is providing to the circuit. To do this, we'll charge up the capacitor-battery, and then let the charge drain through the resistor. The higher the resistance value in ohms, the longer it will take the charge to drain. We can monitor this discharge time with a Propeller I/O pin and the RC charge/discharge block.
(1) 10 k-ohm potentiometer
(1) resistor 220 ohm (red-red-brown)
(1) capacitor, 0.1 µF (yellow, may be marked 104)
(1) capacitor, 0.01 µF (red, may be marked 103)
(misc.) jumper wires
The example code below charges the capacitor, then measures the RC discharge time in microseconds and displays the value in the Terminal.
The code is inside a repeat forever loop, so it can check the circuit and update the measured value continuously. The next three blocks work together to take the RC discharge time measurement. They must appear in this order, with no other blocks in between.
After that, a Terminal clear screen block erases any old data and returns the cursor to the top-left position. Then the Terminal print number block displays the value of knob. A pause (ms) 200 block gives us enough time to see the measured value before the loop repeats.
RC Time: Not Just for Pots! — The RC circuit and RC time measurement technique can be employed with other components that create a variable resistance, or otherwise influence the flow of current out of a circuit. This includes photoresistors, phototransistors, thermistors, and some types of pressure sensors, for example.
You've changed the RC discharge time across a specific range by changing the resistance in the circuit with the potentiometer's knob. Changing the size of the capacitor in the circuit will change the RC discharge time range.
It's fun to use the potentiometer knob to control another device. Instead of displaying the value of knob, use it as a value in blocks that set the behavior of an LED, speaker, or similar device.
When a street light turns itself on at at dusk, or a camera knows when to use auto-flash, a light-sensing phototransistor may be at work. Let’s try using a phototransistor with the Propeller microcontroller for measuring light levels.
A transistor is like a valve that allows electric current to flow through its collector (C) and emitter (E) terminals. The base (B) terminal controls the rate of flow. Depending on the type of transistor, flow rate may be affected by voltage, by applied current, or by light as with phototransistor. The more light striking its base, the more current it will let flow.
We'll use the phototransistor along with a capacitor and a resistor in a charge transfer or QT circuit. This circuit lets us read a very wide range of light levels, and it does so without needing A/D conversion. QT circuits are a simple option for a variety of analog sensors.
The QT circuit behaves very similarly to the RC time circuit used with the potentiometer. The capacitor in the circuit acts like a very small battery, and the phototransistor influences the rate its charge drains by acting as light-controlled current valve. More light = quicker capacitor discharge, less light = slower discharge. The Propeller’s job will be to measure and report the discharge time, using the RC charge/discharge block.
(1) Phototransistor (#350-00029)
(1) 0.01 µF capacitor (labeled 103, #200-01031)
(1) 0.1 µF capacitor (labeled 104, #200-01040)
(1) 220 ohm resistor (red-red-brown, #150-02210)
The Sense Light application will display a number that corresponds with the light level the QT circuit detects.
If you tried the BlocklyProp potentiometer example, this code should look very similar! Only the I/O pin number and variable name have changed.
The code is inside a repeat forever loop, so it can check the circuit and update the measured value continuously. The next three blocks work together to take the capacitor discharge time measurement. They must appear in this order, with no other blocks in between.
After that, a Terminal clear screen block erases any old data and returns the cursor to the top-left position. Then the Terminal print number block displays the value of shade. A pause (ms) 200 block gives us enough time to see the measured value before the loop repeats.
Photoresistor CdS cells are light-controlled variable resistors that also work well with RC-time measurements. CdS cells were once common, but because cadminum is environmentally unfriendly, phototransistors have replaced them in many simple applications.
Photodiodes are also common. Though less sensitive than phototransistors, they are much faster at taking measurements, and overall better suited to the design of specialty equipment. Some devices only sense light in a certain part of the spectrum.
Infrared receivers detect light waves only in the infrared spectrum, not visible to the human eye. These sensors look for infrared light switching on/off in timed bursts, which correspond to different key presses on devices such as a TV remote.
If you use a capacitor that’s 10 times as large, your decay measurements will take ten times as long. So, the value rc_time returns will be 10 times larger.
A 7-segment LED is a great way to display numbers using your Propeller microcontroller. They are made up of eight LEDs in one case. Seven bar-shaped LEDs form the segments of the digit, labelled A through G in the picture below. The eighth one is the decimal point.
You can find these in many products, such as clocks, kitchen appliances, and digital scales. This module actually uses seven LEDs arranged in a special pattern that makes it possible to show any number from 0 to 9, plus an eighth LED for a decimal point. This tutorial will show you exactly how to control the module, and use it to count.
Each individual LED in the module needs a resistor between it and the Propeller chip’s I/O pin. When each I/O pin is set to high (outputs 3.3 V), the LED it is connected to lights up. Any resistor value between 100 Ω and 1 kΩ will work; the lower the resistance, the brighter the LED segment will shine. It’s best to use resistors of the same value so all the segments light up evenly.
(8) resistors, either 100 Ω (brown-black-brown), or 220 Ω (red-red-brown)
(1) 7-Segment Green LED (Part #350-00027)
(5) jumper wires
This is known as a common cathode 7-segment LED display, since the cathode for each LED segment is routed to one ground connection for the module.
The test code will turn on all of the segments in the LED at the same time, to make sure you have built your circuit properly. It is made of just two binary set pins blocks. The first one sets all of the I/O pin directions to output, using binary value 11111111. The second one sets the ouput states to high with the same binary value, connecting each LED to 3.3 V.
All eight LEDs should light up - seven bar segments plus the decimal point. If they don't all light up, go back and check your circuits.
Once your circuit is working, you can try attaching different bit patterns to the set binary states block. The graphic below shows which display LED segment is connected to which Propeller I/O pin. The first, left-most bit sets the P13 LED, in order from left to right until the last, right-most bit sets the P6 LED.
CC vs CA: Notice in the schematic that there is one ground connection for the module. This is known as a CC or common cathode 7-segment LED display, since the cathode for each LED segment is routed to one ground connection for the module. With a CA, or common anode display, the anode for each LED segment is connected to the same power supply pin. The cathode of each LED segment is connected to an I/O pin, and setting the I/O pin to output low (ground) will cause the segment to light up. If you were trying to use a CA 7-segment display in this tutorial, you would need to reverse all of the bits in the binary patterns,changing 1's for 0's and 0's for 1's (in addition to building your circuit as directed by its manufacturer.)
Digits and Letters Too: 7-segment LEDs can also be used to display letters. Although every letter of the English alphabet can be represented (in capital and/or lowercase form) using a single device, some letters are a bit more difficult to display in an easily recognizable way. Want to learn more? Visit the Wikipedia article about 7-segment display character representations at http://en.wikipedia.org/wiki/Seven-segment_display_character_representations [11].
A convenient way to display numbers on a 7-segment display is to store each binary pattern in an array and then reference the array elements later in the code. Here, we do just that, using a repeat item loop to count down the digits from 0 to 9.
Hint: each numbered element stores the binary pattern for its matching digit, 0 to 9, copied from the list above.
Just as in the test code, the first block sets I/O pin directions P13-P6 to output, using the binary set pins block with the binary value 11111111 attached.
Next, an array initialize block creates an array named digits that can store 10 elements (one for each digit, 0 to 9). A list of set array elment blocks fills the digits array, one element at a time. The first block defines array element 0 with the attached binary value block that holds the bit pattern for displaying a zero on the 7-segment LED. Likewise, nine more set array element blocks define the remaining digits: element 1 stores the binary pattern for displaying a 1, and so forth.
After the array is filled, the code reaches a repeat item loop, with a variable named trip to track each repetition through the loop. The block starts with trip at 9, counting down from there to 0 by 1, for a total of 10 "trips" through the loop. Inside the loop is the binary set pins block, this time with an array get element block attached. The first time through the loop, trip equals 9, so the binary set pins block uses the value stored in element 9 of the digits array. That is binary 11110110, the pattern for displaying a 9.
After a 1 second pause, the loop repeats again. This time trip equals 8, so the binary value from element 1 in the digits array is used with the binary set pins block: 11110111. The loop keeps repeating, displaying digits in descending order through its last round when trip equals 0.
Sometimes you may want to use array items in a different order than they are listed. One way to do that is to access the array using another array! Try modifying the program so it displays the 7-Segment LED stock code 350-00027. This will take several steps
First, you will need to add an element to the digits array, and then create and initialize a second array to hold the sequence of digits in the stock code.
Then, you will need to make some additions to the repeat trip... loop to make the
Yes, you could have put the get array sku element trip block right inside of the get array digits block's element field, instead of using the variable fetch as a go-between. But, that is a little more confusing to understand on the first time making one array reference another, not to mention it also makes for a really long block. But, try it if you like, it is a neat trick to know for future programs!
Links
[1] https://learn.parallax.com/tutorials/language/blocklyprop/getting-started-blocklyprop-solo
[2] https://learn.parallax.com/tutorials/language/blocklyprop/simple-blocklyprop-programs-abwx
[3] https://learn.parallax.com/tutorials/language/blocklyprop/blocklyprop-functions-and-multicore/functions-blocklyprop
[4] https://learn.parallax.com/node/667
[5] http://learn.parallax.com/support/reference/schematic-symbols
[6] http://learn.parallax.com/support/reference/resistor-color-codes
[7] https://www.parallax.com/downloads/propeller-activity-board-wx-product-guide
[8] http://www.parallax.com/product/32123
[9] http://learn.parallax.com/tutorials/language/blocklyprop/simple-blocklyprop-programs/making-decisions
[10] http://learn.parallax.com/support/reference/schematic-symbols#polarcap
[11] http://en.wikipedia.org/wiki/Seven-segment_display_character_representations