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 (original or WX version) to get acquainted (or re-acquainted) with its features. 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 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.
If you have never built circuits on a breadboard before, watch this video about breadboards and how to build circuits on them. History can be pretty interesting!
Your Activity Board has two built-in light-emitting diodes (LEDs) near the bottom-right corner of the board. They are already electrically connected to Propeller I/O pins P26 and P27. These LEDs are helpful when developing applications that use sensors. The idea is to build a program that turns on an LED when a sensor is activated. Then you, the roboticist, can get a quick visual cue that the sensor is actually detecting something.
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 Board of Education.
In BlocklyProp, you can turn an LED on or off with a single block: the Pin states category's make PIN block.
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.
The first breadboard circuit we'll build for the ActivityBot is a simple piezo speaker. Many devices in our daily lives use beeps to communicate with us, such as microwave ovens, car locks, smoke detectors, forklifts driving in reverse—can you think of more examples? Likewise, it is useful to equip your ActivityBot to communicate with you via sound.
Inside the piezo speaker is a thin piece of material called a piezoelectric element that deforms when voltage is applied to it, and returns to its original shape afterwards. When voltage is switched on/off rapidly, the vibration emits a tone. The faster the switching frequency, the higher the tone produced. A Propeller I/O pin can provide this rapidly toggling voltage at specific rates.
(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.
Know when you are low — A brownout indicator signals to you, the roboticist, when your ActivityBot's batteries are running low. If the battery voltage drops too low, the Propeller microcontroller will reset and restart the program. This can look like a programming or circuit error if you don't know it is happening! So, you will see this block at the beginning of any ActivityBot example program that is meant to make the robot move. A low-battery beep will help you troubleshoot your ActivityBot projects by ruling out low battery power as the culprit.
What is a brownout? - You may be familiar with the word blackout; a blackout is when power dies comepletely, like when the power goes out in your home. A brownout means that there is still power, just not enough to make everything work.
The Frequency out block's duration (ms) and frequency (Hz) fields can accept use variable blocks and even Operators > Numbers category blocks, as well as the default number value blocks. Sometimes it is fun or useful to have a tone vary in correlation to some sensor's input values, so you can know what the ActivityBot is sensing. For now let's just play with the idea using a variable that's counting loops in a repeat item block.
Links
[1] https://www.parallax.com/downloads/propeller-activity-board-wx-product-guide
[2] https://www.parallax.com/downloads/propeller-activity-board-guide