It's tempting to dive right into robot navigation. We understand! But, as with any vehicle, it's wise to get familiar with the controls before attempting to drive.
In this section you will:
Take a quick tour of the Propeller Activity Board WX to get acquainted (or re-acquainted) with its feautres. You've already connected cables to the servo ports and have plugged the battery pack into the power jack. You've been programming it a bit already, so you have been using the USB port.
Next, let's take a closer look at two features in particular: the power switch and the breadboard. These features are found on both versions of the Activity Board.
All versions of the Propeller Activity Board have a 3-position power switch:
The breadboard lets you build your own circuits with common electronic components. It's 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.
The Activity Board's breadboard (original or WX version) 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.
Welcome back! Did you watch the video? If you did, you now know why it's called a "breadboard." History can be pretty interesting!
Your Activity Board WX version has two built-in lights, near the bottom-right corner of the board. These tiny light-emitting diodes (LEDs) are already electrically connected to I/O pins P26 and P27. These LEDs are helpful when developing applications that use sensors. The idea is to write your program so that if a sensor is activated, an LED lights up to give you, the roboticist, a quick visual cue that the sensor is actually detecting something.
We'll experiment with the "O" (output) feature of an I/O pin by programming the Propeller to use an I/O pin to turn a light on and off.
Our light circuit is already built into the Propeller Activity Board WX. Here is what the schematic looks like for this circuit:
See the Schematic Symbols reference. [4]
Let’s try running an example program that blinks the LED light connected to P26.
The function call high(26) 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(100) makes the program do nothing for 100 ms, which keeps the light on for 1/10 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(100) makes the light stay off for 1/10 of a second.
Those four commands are in a code block in a while(1) loop, which repeats endlessly, so the light keeps blinking.
/* Blink Light.c Blink light circuit connected to P26. */ #include "simpletools.h" // Include simpletools int main() // main function { while(1) // Endless loop { high(26); // Set P26 I/O pin high pause(100); // Wait 1/10 second low(26); // Set P26 I/O pin low pause(100); // Wait another 1/10 second } }
The simpletools library has lots of useful functions for controlling and monitoring circuits; high, low, and pause are just three examples. Click the SimpleIDE Help menu and choose Simple Library Reference to see a link to the simpletools library's functions.
You can make the light blink faster by reducing the pause function’s parameter value. For example, to blink the light twice as fast, just reduce the pauses to half as long.
Try controlling the P27 light along with the P26 light.
Even though the Propeller chip can play WAV files and synthesize speech, sometimes a simple beep is all the noise you need to get the job done. 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.
The first breadboard circuit we'll build for the ActivityBot is a simple piezo speaker.
(1) Piezo speaker (#900-00001)
(2) Jumper wires
It is very easy to make this speaker beep with a single line of code:
freqout(4, 1000, 3000); // pin, duration, frequency
You can optionally add this line code at the beginning of your ActivityBot example programs. Then, If your robot's batteries run low, the Propeller microcontroller will reset and restart the program—the beep will let you know if this has happened. We include it because it can be very helpful when experimenting with navigation programs, and trying to figure out why your robot is behaving in an unexpected manner.
Let's try it.
The test code will make the piezospeaker beep for one second with fairly high-pitched tone.
The freqout function has parameters of pin, msTime, and frequency. The function call freqout(4, 1000, 3000) sends an alternating high/low signal to pin 4, for 1000 ms (or 1 second), at a frequency of 3000 Hz (3000 times per second). Since the speaker is connected to P4, this rapid 3.3 V to 0 V high/low sequence makes the piezoelectic element in it vibrate 3000 times per second. The result is a high-pitched tone.
/* Piezo Beep.c Beep a piezo speaker connected to P4. */ #include "simpletools.h" // Include simpletools int main() // main function { freqout(4, 1000, 3000); // pin, duration, frequency }
If you want to make your code do something while it's broadcasting the tone, use the squre_wave function instead. It's the "set it and forget it" version of freqout. Check the simpletools library documentation for more info. You can find it at: ...\Documents\SimpleIDE\Learn\Simple Libraries\Utility\libsimpletools\Documentation simpletools Library.html
When you press a key on a piano, it makes a small hammer strike a tightly pulled wire, causing the wire to vibrate at a certain frequency. Here are the frequencies of some higher keys to the right side of the piano keyboard:
You can use an array to store note values, and then play them with a for loop. (See Array Variables [5] for a refresher.)
You can also use #define to give your frequencies note names, and then you can use those note names in your array in place of the numbers. It’ll make your digital composing a lot easier.
Links
[1] https://www.parallax.com/package/propeller-activity-board-wx-product-guide/
[2] https://www.parallax.com/downloads/propeller-activity-board-wx-product-guide
[3] https://learn.parallax.com/reference/breadboard-basics
[4] https://learn.parallax.com/support/reference/schematic-symbols
[5] https://learn.parallax.com/node/620