Академический Документы
Профессиональный Документы
Культура Документы
Subscription Information
January 2017
08 TechKnowledgey 2017 48 The Spin Zone
Nuts & Volts — PO Box 15277
North Hollywood, CA 91615-9218
Call 877-525-2539 or go to www.nutsvolts.com
Subscribe • Gift • Renewal • Change of Info
06 DEVELOPING
Departments 54 NV WEBSTORE
PERSPECTIVES 62 TECH FORUM
The Zombie Apocalypse 64 CLASSIFIEDS
— Are You Ready? 65 ELECTRO-NET
07 READER FEEDBACK
65 AD INDEX
07 SHOWCASE
4 January 2017
Bergeron - Developing Perspectives - Jan 17_Dev Perspectives - ReadFeed Feb15.qxd 12/5/2016 10:04 PM Page 6
DEVELOPING
PERSPECTIVES
by
Bryan
Bergeron,
Editor Published Monthly By
T & L Publications, Inc.
430 Princeland Ct.
Corona, CA 92879-1300
(951) 371-8497
FAX (951) 371-3052
In this column, Kristen answers questions • Phantom Power and Stopping a Cough
about all aspects of electronics, including
hardware, software, circuits, theory, radio • Extending Wi-Fi Range on the Cheap
troubleshooting, and anything else of interest • PBX and Auto Dialer
to the hobbyist. Send all questions and
comments to: Q&A@nutsvolts.com. shield/ground wire. There’s a whole article that could be
written on whether the shield is the same as the ground,
or even if they should be connected to each other. Ward
Phantom Power and Stopping a Cough Silver’s article from the November 2016 Nuts & Volts tells
the story well. An example of a simple circuit to implement
Q
I am interested in creating a mute (a.k.a., phantom power on a balanced three-wire system is shown
“cough”) button for the microphones used in Figure 1. n
by the hosts in our podcasting studio. The As a side note, loop-start telephone systems like POTS c
microphones are Audio Technica AT831B (Plain Old Telephone Service) lines are an example of a
Lavalier phantom powered from our mixer. I would like to phantom power that isn’t balanced. The phone company
build the circuit in a small desktop box with a button on supplies roughly 48 volts open-circuit to the telephone E
top and XLR IN and XLR OUT on the back to insert the instrument. That becomes a power supply that’s used to
Q
box between the mixing board and the microphone. I have pass current through a carbon microphone where the
seen a few “mute” schematics that suggest shorting pins 2 resistance varies with sound pressure. A certain impedance
and 3, but I think this might short out the phantom power. across the incoming pair causes the phone switch to sense
Do you have a schematic that might work for me? that the phone is off-hook, and the audio is impressed
Lance Harvey as small AC variations on the line. There are many more a
Midland, TX things (ring voltage, hook flash, DTMF, etc.) that can be lo
signaled in a loop-start system. It’s a really clever design. re
A
I think that the schematics you’ve found are Of course, when we build equipment, we are never M
on the right track. I have a collection of Nagra sure what will be connected to any terminals that we
audio tape recorders (beautiful machines with expose, so we have to plan for wires to be shorted and
superb audio quality, by the way), and that’s other bad situations. Phantom power is no exception, so
A
where my experience with this comes from. Let’s first take that is why there are resistors shown in the figure to limit
a look at how phantom power works. the worst case current supplied by the phantom power
Since some types of microphones and accessories supply. Even if you were to short all of the wires from the
require voltage and a little bit of power to operate, XLR connector together, a properly designed device should
engineers came up with the idea of impressing a little be fine. We never know for sure if things are properly
power supply voltage on the signal wires. Since the audio designed, though. Let’s just assume that for the moment. d
signal is changing with time, it can be separately extracted The audio signal coming from a microphone in a in
or injected with either inductors or capacitors, depending balanced or differential audio system is derived from p
on the implementation. In the case of balanced audio such subtracting the voltages from the two differential audio c
as we see in three-wire systems using XLR connectors, pins. In the case of XLR connectors, that’s pins 2 and 3. If th
we can take advantage of the three conductors to further there is a voltage between the shield/ground (pin 1) and
separate the AC component from the DC component. the other two, it is not considered to be part of the audio w
The convention for these balanced systems is to raise signal. What this implies is that pins 2 and 3 will generally o
the two differential audio signals roughly equally above the be close to each other in voltage. im
In order to build our cough button, we don’t need in
to short the entire phantom power system. All we need e
to do is bring the voltage difference between pins 2 and th
3 to zero. That means we can indeed simply short them d
together with a switch (Figure 2). To be a little paranoid, th
you might use a very low impedance — but not zero — to th
connect them together.
An important consideration, though, is making sure a
that noise can’t leak into the system from the switch. so
It is probably a good idea to use a metal box to shield th
the switch from stray electromagnetic fields, and to c
n FIGURE 1. One way to supply Phantom Power connect that box to the shield/ground on pin 1 of the XLR w
12 January 2017
Q
My (step) granddaughter wants to make a significantly less expensive, though. So, building the dipole
e Wi-Fi signal extender for a science fair. I was out of copper wire is recommended.
e wondering if a purely passive circuit might work.
Could we put a dipole at one end of some coax
and then at the far end just have the thing loop back? If the n FIGURE 3. Dipole length rule of thumb.
loop was big and part of it passed near a laptop, would it Supporting structures should be made with something
rebroadcast? Would it help if the circuit was tuned to 2.4 that exhibits a low relative dielectric constant so that the
MHz or 5.whateveritis MHz? Am I being crazy? pattern and impedance aren’t distorted much. While the
Randy Smith dimensions are important, they aren’t critical. A dipole
Palo Alto, CA has a fairly low Q (quality factor — a measure of how
narrow its operational bandwidth is) given its high radiation
A
No Randy, you’re not being crazy at all! What resistance, so it works without too much impedance shift
you propose is close to what you want. It’s over a fairly wide range. Even if it’s off, it’s not fatal. There
called a passive repeater. I’ve done it myself on is just a slightly higher loss in the coax and changes to
d the two-meter amateur band. the antenna’s field strength pattern. Careful construction
Instead of a loop at the far end, you’d want another is warranted because of the skin effect, though. Figure 4
dipole. The idea is to construct a dipole that is resonant gives you a basic idea of what the passive repeater looks
in the middle of the Wi-Fi channel spectrum (or on a like electrically.
particular channel that she’s using), pass it through some With this arrangement, place one dipole near the Wi-Fi
coax, and then build a dipole of the same dimensions at base station’s antenna — preferably polarized the same
the other end of the coax. way as its antenna for maximum coupling — then place
If the dipole is resonant, in other words 1/2l (or the other one in another room and take signal strength
wavelength), then the feed point impedance would be 72 measurements both with and without the apparatus.
ohms resistive, which is very close to the characteristic Almost all Wi-Fi transceivers have a way to measure relative
impedance of RG-6 75 ohm low loss coax — what’s used field strength, often called RSSI. It is usually displayed in
in cable television everywhere. One dipole would couple dBm (decibels against 1 mW).
energy from the propagating electromagnetic energy from A similar measurement of noise is usually available
the Wi-Fi base station into the coax. The energy would flow from the transceiver. Measurements of the RSSI and
down the coax, shielded from radiating externally. Then, noise can be combined to produce a signal-to-noise ratio.
the dipole at the far end would reradiate that energy into Another study for the science fair might be how critical
the destination area. the dipole dimensions are to performance; both the dipole
Calculating the dipole length requires a slight length and the separation of the wires at the feed point.
adjustment to the speed of light in a vacuum. This is a To refine the passive repeater a bit, you’d want to
somewhat complicated calculation that is dependent on put around two or three ferrite beads (little toroids) on
the thickness of the wire relative to the wavelength. We the coax near the feed point, or even just loop the coax
call this unit-less number the velocity factor, and for this we tightly two or three turns near the feed point to decouple
will just guess that it will be around 0.95. A simple rule- the outer side of the coax shield from the dipole and
January 2017 13
Q
I love my small PBX system and want to add an running Linux. Asterisk is designed to work with VoIP
auto dialer between the CO line and the PBX. phones, but there are also POTS interface cards available.
I want to detect outgoing digits (if more than The website has a section under “Products” that can
two digits, no action). If they are 1, 1, then the direct you to manufacturers of hardware POTS interfaces
dialer should add prefix 9 and dial 911 (or disconnect compatible with Asterisk. Being open source, if you aren’t
and dial 911) as is required by new laws. Are there simple happy with how it works, you can change it in software.
commercially available devices or can you suggest some While you’re on the Web, if you are plagued by
simple circuit to achieve such a thing? unwanted marketing calls, be sure to search for “PBX” and
Ankur Bhakta “Lenny” ... NV
14 January 2017
e’ve all experienced the feeling of visiting a group dB is just a number that describes how much bigger or
W outside of our own background and being
completely flummoxed by the rapid-fire jargon being
smaller one quantity is compared to the other. Both
quantities themselves must have the same base units,
thrown around. Just as confusing are the measurements in though — watts, for example. If P2 is larger than P1, the dB
this alternate universe. Wireless communication seems to value is positive, such as for amplifier gain. If P2 is less, the
involve many such terms, but many seem to be calculated value is negative and represents attenuation or loss.
or expressed in terms of the decibel. This column covers a (Somewhat confusingly, it’s common to specify an amount
number of these measurements and values, and shows of attenuation as a positive value of dB. For example, “This
you how to use decibels for them. filter attenuates the signal by 20 dB.”)
If you want to compare voltage (or current) levels, you
The Decibel have to account for the relationship between voltage (or
current) and power not being linear — doubling voltage
The “dee-bee” is everywhere in ham radio, and is (or current) is a quadrupling of power:
used for characterizing everything from antenna
performance to nano-sized signals. Learn the decibel P = V2/R = I2R so dB = 20 log10 (V2/V1)
(abbreviated as lower-case ‘d’ followed by an upper-case
‘B’ or ‘dB’) and you and your signal will go a long way! You don’t necessarily have to have a calculator at the
From the ARRL Ham Radio License Manual’s online ready. Just memorizing the few power dB relationships in
math tutorials for beginning hams (arrl.org/chpt-2-radio- Table 1 is easy. Remembering a simple rule for factors of
signal-fundamentals), we introduce the decibel. “You 10 will come in quite handy, too. Speaking in terms of
have probably recognized deci as the metric prefix that power, any change by an exponent of 10 is a change in
means one-tenth. The unit we are really talking about here dB of 10 times the exponent. A change of 100 (102) is a
is the bel (a ratio of sound levels named for Alexander change of 20 (2 x 10) dB; a change of 1000 (103) is a
Graham Bell), so a decibel is just 1/10th of a bel. We use change of 30 (3 x 10) dB; and so forth.
a decibel instead of a whole bel because the bel Another handy thing to remember is that multiplying
represents a rather large change in levels. The dB is a just- the ratio by a factor allows you to add the dB equivalent
perceptible change and more useful as a unit of of that factor. For example, from Table 1, a change of 20
measurement.” As used in wireless, the decibel is the ratio is the same as a change of 5 x 4, so a change of 20 in dB
of two power levels: is equal to 7 + 6 = 13 dB. You could also figure that out
from 20 = 10 x 2, so the dB equivalent is 10 + 3 = 13 dB.
dB = 10 log10 (P2/P1) Doubling power — another common situation — is a
change of 3 dB. By memorizing a few values and rules,
Note that the dB has no units because it is a ratio. The you can navigate dB quite easily!
yet need to work with gain and attenuation in dB. The Noise in Analog-to-Digital Converters (ADCs)
solution is to use a single fixed reference level for all It’s the norm these days to digitize analog signals and
measurements. The value for P1 in the equation shown manipulate them in software. As such, it’s important to understand
(the one in the denominator) is the ratio’s reference level. the noise performance of ADCs. The Analog Devices’ tutorial —
By using the same absolute reference value for all of your “Understand SINAD, ENOB, SNR, THD, THD + N, and SFDR So You
calculations, you also know the absolute power of the Don't Get Lost in the Noise Floor” (AD MT-003) — is an excellent
measurement. tutorial on different noise metrics of ADCs.
For example, if you use one milliwatt (1 mW) as your You can download it for free at www.analog.com/media/en/
training-seminars/tutorials/MT-003.pdf.
reference level, all of your dB values will be calculated
“with respect to one milliwatt.” This is so common in
wireless that the abbreviation dBm was created. A power Gain: Power or Pattern
level of 10 dBm is 10 times 1 mW or 10 mW; 3 dBm is 2 I have mentioned “gain” several times so far in this
mW; -20 dBm is 0.01 mW; and so forth. Because values in column and it’s time to explain there are two common
dB are added or subtracted when the quantities are definitions, both specified in dB. The most used definition
multiplied or divided, you can easily use dBm values and probably the one you imagine when you see the
throughout your radio system. word is power gain. This is what happens when an active
For example, when a 1W transmitter signal (30 dBm) device such as an op-amp or transistor or vacuum tube
is amplified with a gain of 15 dB, it becomes a 30 + 15 = uses a low level input signal to control a more powerful
45 dBm signal. A received signal of -47 dBm experiencing output signal. The output signal has more power than the
a cable loss of 6.2 dB is reduced to -47 – 6.2 = -53.2 dBm. input signal. That input-to-output power ratio is the gain of
Other common abbreviations you’ll encounter in the the circuit or device — pretty straightforward.
wireless world are the dBW (reference level of one watt), The other type of gain is created by antenna
dBV (reference level of one volt), and dBuV (reference designers. You’ll frequently see antennas specified to have
level of 1 µV). When you see a letter appended to “dB,” it some value of gain in dB. The antennas themselves do not
is specifying a common reference value. add any power to the signal applied to their feed point. In
fact, due to resistance, the antenna has a slight loss. The
Signal-to-Noise Ration gain being referred to — pattern gain — comes from
focusing the signal in a certain direction so that it appears
Another common measurement expressed in dB is the stronger in the favored direction. This is equivalent to
signal-to-noise ratio, or SNR or S/N. SNR compares the having amplified the signal by the same amount.
signal power to the power of the background noise: SNR An antenna’s pattern gain, however, is always
= 10 log10 (PSIGNAL / PNOISE). Often left out of the measured or specified with respect to some standard
discussion is the bandwidth of the channel over which reference antenna. The two most common references are
noise is measured. the isotropic antenna which radiates equally in all three-
For example, a telephony circuit (mobile or landline) dimensional directions, and the dipole which radiates best
may be assumed to have a communications-quality broadside to the antenna and very weakly off the ends.
bandwidth of 3 kHz. It’s usually assumed to be the (Dipoles and their radiation patterns were discussed in the
receiver or amplifier bandwidth, but don’t assume that’s September 2016 column.)
always the case. If you really need to know SNR with full If you imagine the isotropic antenna’s radiation
accuracy, specify the bandwidth of the measurement. pattern as a spherical balloon filled with radiated power, a
In the case where interfering signals are also present directional antenna like a beam or dish creates pattern
— such as for a data link in a shared unlicensed frequency gain by “squeezing” the sphere. Where the signal is
band like 900 MHz or 2.4 GHz — a better measurement focused, the sphere extends farther from the center than
might be signal-to-noise plus interference ratio or SNIR. without focusing. The ratio between the focused direction
(This measurement is also written as signal-to-interference and the original equal-in-all-directions is the antenna’s gain
plus noise ratio, or SINR.) If your data link will be in that direction.
operating in a crowded band, this might be a better way Since the ratio depends on the reference antenna’s
to measure and plan your communications link. pattern, antenna gain must always be specified with
Finally, each step in the modulation/demodulation and respect to the reference antenna. If the reference was an
signal amplification chain adds some distortion products isotropic antenna, the abbreviation dBi is used; dB with
to the desired signal. The measurement signal-to-noise plus respect to an isotropic antenna. If a dipole was used, the
interference and distortion, or SINAD accounts for these abbreviation dBd is used with the understanding that the
effects: SINAD = 10 log10 [(PSIGNAL + PNOISE + PDIST) / dipole’s pattern is used where the dipole’s radiation is
(PNOISE + PDIST)]. strongest: broadside to the dipole. In fact, a dipole has a
January 2017 17
Silver - Ham's Wireless Workbench - Jan 17_Hams Wireless Workbench - Sep 15.qxd 12/5/2016 10:09 PM Page 18
BUILD IT YOURSELF
By Theron Wierenga
An Electronic Chessboard
Using RGB LED Strips and
HALL
EFFECT
SENSORS
King moves. Queen moves.
The game of chess is considered by
many to be very complicated and
played by people who enjoy a
challenge. Actually, the rules of how
the chess pieces can move are fairly
simple and easily learned. What makes
things complicated is the total number
of different ways a game can progress.
After each side has played three Bishop moves. Rook moves.
moves, the pieces could form any one
of over nine million possible positions
on the board. The number of distinct
40 move games is far greater than the
number of electrons in the observable
universe. If you are not familiar with
chess, Wikipedia has an excellent
introduction to the game at
https://en.wikipedia.org/wiki/Chess.
The chessboard layouts shown here Knight moves. Pawn moves.
illustrate the various allowable moves
for each chess piece. The more
esoteric castling, en passant, and
promotion moves are not included in
this project, although they could be
added to the software.
20 January 2017
Wierenga - LED Chess - Jan 17 - part 1_Blank Project NV.qxd 12/5/2016 10:18 PM Page 21
Post comments on this article and find any associated files and/or downloads at www.nutsvolts.com
/magazine/article/January2017_Electronic-Chessboard-LEDs-Hall-Effect-Sensors.
T he black circles
represent the squares
where each piece can
move. The knight is the
only piece that can jump
over other pieces. The
pawn’s first move can be
either one or two squares
forward if those squares are
empty. After the pawn’s
first move, it can only move
forward one square if
empty. The X positions
mark where the pawn can
capture an opponent’s
piece, which is limited to a
diagonal move forward of
one square.
My Path to
Building
This
Some time back, my
grandson mentioned a
■ FIGURE 1.
circuit board for gaming he Schematic of the
was working on in his complete
college program. Our chessboard circuit.
discussion led me to
thinking about building a
chessboard using an array
of RGB LEDs and some
sort of detector to monitor (Full size schematic
the position of the chess available at article link.)
pieces. I experimented with
an array of 256 individual
RGB LEDs placed in a 16 x 16 array, using a block of 2 x turned on, it does not need to be continually refreshed.
2 LEDs for each board square. For the detector, I tried My previous experience had me deciding against using IR
using reflective IR sensors. After many attempts, I got a detectors, so I went instead with Hall effect sensors.The
prototype to barely work. Scanning 256 LEDs is not chess pieces have a small magnet in their base to trigger
simple, but worked fairly well. The problem was the IR the Hall effect sensors. I also moved from using an
detectors. Their output was read with an Arduino Mega Arduino Mega 2560 to a Teensy 3.1, which has more
2560 analogRead() which gave differing values for each IR RAM and a 72 MHz clock, as opposed to 16 MHz for the
detector. This coupled with the fact that as the ambient Arduino. It can also be easily programmed with the
light in the room changed, the IR detector’s values Arduino GUI. You will need to download and install the
changed as well, it was just a matter of a few chess moves Teensyduino software package to program the Teensy 3.1
before the IR detectors gave an error. with the Arduino GUI. Download information and
After some experience using RGB LED strips, it instructions can be found at https://www.pjrc.com/
occurred to me that this might be an easier way of driving teensy/teensyduino.html.
the LEDs on an electronic chessboard. Once an LED is This chessboard does not play a chess game against
you. The chessboard is used by two players, and the basic
Arduino Mega 2560 Teensy 3.1 objective is to keep track of the board and the rules of the
RAM 8K 64K game for both players. This makes it a nice learning device
Program Space 256K 256K for the beginning chess player. The LEDs light up to show
Clock Speed 16 MHz 72 MHz a player where a piece can be moved, and whether there
January 2017 21
Wierenga - LED Chess - Jan 17 - part 1_Blank Project NV.qxd 12/5/2016 10:18 PM Page 22
and because one will invert the signal, the two NAND
gates were used is series. With this in place, the strip is
driven by a five volt line.
The Teensy 3.1 is essentially a faster replacement for
the Arduino line of microcontrollers with added features. It
was chosen because of its higher speed, adequate
program space, and additional RAM, which is needed for
the software that drives the chessboard. I elected to use
an IC socket for the 28-pin Teensy 3.1, with the thought of
ease of removal if the Teensy is damaged. Unsoldering a
bad 28-pin IC is inviting damage to the PCB. The Teensy
3.1 can be powered by a 3.7 to 5.5 volt source, but its
I/O is at the 3.3 volt level. While this will interface directly
with five volt ICs like the 7400 TTL and HTC series, it
should be noted that its output will not directly drive a
PNP transistor powered with five volts. This is because the
3.3 volt high output does not come close enough to the
five volts to turn off a PNP transistor. The chessboard
circuit has a five volt powered 74HCT138 three- to eight-
bit decoder between the Teensy and the PNP transistors
that power the rows of Hall effect sensors, which takes
care of this problem. The 74HCT138 also reduces the
number of I/O lines needed on the Teensy 3.1.
■ FIGURE 4. Prototype printed circuit board before installing
Allegro 3144 Hall effect sensors were chosen because the 64 Hall effect sensors.
they are inexpensive and readily available. They have a
Schmidt trigger open collector output with a little representing the chessboard squares.
hysteresis which gives noise-free switching when the After mounting the single 3144, I cut a small strip of
magnet moves into or out of the field of the sensor. Small wood that just fit snugly under a row of the 3144s and
neodymium disk magnets — 10 x 3 mm graded N50 — taped it down with blue masking tape. This served as a jig
were glued into the bottom of a set of plastic chess when soldering in a row of 3144s such that they would all
pieces, with the correct magnet face placed at the bottom be the same height above the PCB and is shown in Figure
of the piece. I put together a single 3144 on a breadboard 6. The 3144 has an open collector output and all the
with an LED for output to determine the correct magnet outputs of a column of eight are connected together. A
face to place toward the 3144 to switch it on (see Figure row of 3144s is then powered by the PNP transistor and
5). The pins on the 3144 are bent at a right angle so that each column read one at a time by the Teensy 3.1.
the face of the 3144 with the part number on it points The chess piece set I used was purchased from
upward when mounted on the PCB. Care needs to be https://www.wholesalechess.com and is their Analysis
taken to insure that the 3144 stands high enough off the Chess Pieces set. They are inexpensive and small; the king
circuit board to allow the magnet to switch this sensor; is 2-1/2 inches tall and the pawns are 1-1/4 inches, but are
therefore, I used the full length of the 3144 leads. just the right size for the chessboard. The bottom has a 10
I mounted a piece of 1/4 inch Plexiglas to the top of mm hole which perfectly fits a 10 mm diameter by 3 mm
the circuit board using 5/8 inch spacers and 4-40 machine thick neodymium disk magnet. The magnets press-fit into
screws. I soldered in one 3144 to a height where I was the base of the chess pieces very easily. However, there is
confident the magnets in the bottom of the pieces would a problem — especially with the lightweight pawns.
activate the 3144 through the Plexigas surface. The chess When another piece gets near a pawn or you place a
pieces sit on the Plexiglas with the LEDs underneath, piece slightly off center, the magnets repel each other and
speed since the chessboard is not going to look at all can jump two spaces over. So, for example, in code we
possible plays several moves ahead. Due to the different could use:
sizes of the two different types of arrays, the program
code does contain a large number of array indices that if (piecesValCur[y][x]) == BORDER)
// We are off the board in one comparison
add a -2 or +2 to the index. Some of the worst bugs in my
program code were simply due to forgetting this point. instead of:
There are two key arrays that represent the board. The
first — which I label piecesVal[12][12] — identifies each if ((y < 0) || (y > 7) || (x < 0) || (x > 7))
// We are off the board in possibly four comparisons
piece and their placement on the board at startup. A
second array — piecesValCur[12][12] — maintains the Instead of using numbers like 255 and 16 in the
piece’s current positions and identifies each piece as they software, it is much more understandable to use the
are moved. Various 8 x 8 arrays are used when reading defines like BORDER and BLACK_KING. This has been
the Hall effect sensors to determine where pieces are done wherever possible in the software.
located. Just about any set of numbers could be used to The piecesValCur[y][x] array contains not only the
represent the different pieces. The 1 through 16 numbers I position using the indices, but the number values that
chose supposedly represent the relative values of the identify the exact piece as well. However, when we read
pieces. The number 128 was added to the byte value (bit the Hall effect sensors, we will only get a reading that tells
7 set) to indicate the white pieces. These values are us where pieces are located — not their values. So, when
placed in #define statements so the piece names can be reading the Hall effect sensors, we can find that position
used in place of the numbers: 3,4 has changed and there is not a piece there compared
to a previous reading. We then use the 3,4 indices in the
// White = 128, white at bottom, starting positions piecesValCur[y][x] array to find which exact piece was
// Black = 0, add color to piece value
//
removed. Reading the Hall effect sensors gives us this
// Black White array on startup:
// Pawn = 1 and 129
// Knight = 3 131 byte piecesCurrent[8][8] = {{1, 1, 1, 1, 1, 1, 1, 1},
// Bishop = 4 132 // [y][x] Where current piece are located
// Rook = 5 133 {1, 1, 1, 1, 1, 1, 1, 1},
// Queen = 9 137 {0, 0, 0, 0, 0, 0, 0, 0},
// King = 16 144 {0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
// Defines for chess pieces and spaces {0, 0, 0, 0, 0, 0, 0, 0},
#define BORDER 255 {1, 1, 1, 1, 1, 1, 1, 1},
#define EMPTY 0 {1, 1, 1, 1, 1, 1, 1, 1}};
#define BLACK_PAWN 1
#define BLACK_KNIGHT 3 In addition to the piecesCurrent[y][x] array, similar
#define BLACK_BISHOP 4 arrays are maintained that are used when doing the actual
#define BLACK_ROOK 5
#define BLACK_QUEEN 9 reading of the Hall effect sensors. The two arrays are then
#define BLACK_KING 16 compared to determine what piece has been moved.
#define WHITE_PAWN 129 Notice that these arrays do not need the two rows and
#define WHITE_KNIGHT 131 columns of additional values to denote positions off the
#define WHITE_BISHOP 132
#define WHITE_ROOK 133
board:
#define WHITE_QUEEN 137
#define WHITE_KING 144 // Read a row of 8 Hall Effect sensors
int readLine(int row, byte piecesTemp[][8])
byte piecesVal[12][12] = {
{{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, // Read each sensor in a row looking for a zero,
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, // which means a piece is there.
{255, 255, 5, 3, 4, 9, 16, 4, 3, 5, 255, 255}, // The 3144 Hall Effect sensors are open collector
{255, 255, 1, 1, 1, 1, 1, 1, 1, 1, 255, 255}, // output and pull to ground when activated.
{255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255}, // We invert the zero to place a one in our array if
{255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255}, // a piece is on a square.
{255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255}, // After each read we add to count to keep a running
{255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255}, // total.
{255, 255, 129, 129, 129, 129, 129, 129, 129, 129, 255, 255}, int count = 0;
{255, 255, 133, 131, 132, 137, 144, 132, 131, 133, 255, 255}, piecesTemp[row][0] = !digitalRead(2);
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, count += piecesTemp[row][0];
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}}; piecesTemp[row][1] = !digitalRead(3);
count += piecesTemp[row][1];
The 8 x 8 array is surrounded by two rows and piecesTemp[row][2] = !digitalRead(4);
count += piecesTemp[row][2];
columns of values set to 255 or 0xFF Hex. This boundary piecesTemp[row][3] = !digitalRead(5);
makes it a little easier to check for pieces moving off the count += piecesTemp[row][3];
board. The bank of two was necessary because a knight piecesTemp[row][4] = !digitalRead(6);
January 2017 25
Wierenga - LED Chess - Jan 17 - part 1_Blank Project NV.qxd 12/5/2016 10:18 PM Page 26
Vintage Computing
The Retro PIC Single-
Board Computer
By Dan Gravatt Post comments on this article and find any associated files and/or downloads at
www.nutsvolts.com/magazine/article/January2017_Retro-PIC-Single-Board-Computer.
Vintage Computing
Vintage Computing
Vintage Computing
programming languages simply automate the process of by pauses to let the chip complete its write cycle, which is
presenting data bytes to the display controller and toggling on the order of 5-10 milliseconds — an eternity in CPU
the RS and E inputs to complete the data transfer. For this time. This is an example of how better understanding the
project, the R/W input of the controller is hard-wired to hardware improves your code. If you don’t allow for these
ground (write-only) on the LCD module itself. pauses between write cycles, the writes will fail!
The EEPROM is internally broken up into 128-byte
I2C “pages” and supports a block-write mode where a single
I2CWRITE instruction can save up to 128 bytes. This mode
The I2C bus is a true bus like the CPU’s address and is faster than writing a byte at a time since there is only
data buses, in that multiple devices share the same one 5-10 ms pause required per block. It also saves wear
connections to the CPU but can be accessed individually. and tear on the EEPROM, which is guaranteed for a large
In contrast to the separate parallel address and data buses but not infinite number of write cycles.
discussed above, I2C provides data, address, chip select, If you use this mode, you must keep track of the
and read/write control to its devices over a single EEPROM addresses you are writing to so that the block
synchronous serial connection. This greatly cuts down on write does not cross a page boundary and garble your
the physical connections needed for the bus. Note that data in the process. This does not affect read operations
much of the schematic in Figure 1a is taken up by the from the EEPROM, which can start and end anywhere.
wires for the CPU’s address and data buses. The tradeoff The PCF8563 RTC can be hard to find in an eight-pin
is that the I2C’s serial data streams transfer data more DIP package. I’ve specified a surface-mount part in the
slowly than the parallel-mode buses. Parts List because it is readily available. You can use a
For this project, we’re moving relatively modest commercially-available adapter to attach the SO-8 package
amounts of data on the I2C bus a few bytes at a time to to the circuit board, or fabricate a “spider” adapter from
and from the PCF8563 real time clock chip, and up to some leftover resistor leads. The DS1307 RTC is available
64K bytes for the 24LC512 EEPROM. The entire EEPROM in a DIP package and is mostly pin-compatible with the
contents can be read in a few seconds — not unlike the PCF8563, so you could substitute that with some
performance of an early eight inch floppy drive. Much of modifications to the code and circuit board.
the time required for a write to the EEPROM is taken up
ITEM PART # (DIGI-KEY) DESCRIPTION Stack
U1 PIC16F887-I/P-ND PIC microcontroller, 40-DIP
U2 1450-1182-5-ND 32 Kb static RAM, 28-DIP CPUs and
U3, U6 (2) 296-1598-5-ND 74HC574 octal latch, 20-DIP microcontrollers have a
U4 32 Kb EPROM, 28-DIP (see text) small array of registers
U5 296-1577-5-ND 74HC14 hex inverter, 14-DIP
U7 296-1575-5-ND 74HC138 decoder, 16-DIP that are used to store the
U8 24LC512-I/P-ND 64 Kb EEPROM, 8-DIP address of a program
U9 568-6650-1-ND PCF8563 real time clock, SOIC-8 instruction that jumps to
U10 LM34DZ/NOPB-ND LM34 temperature sensor, TO-92
(optional) another instruction
LCD NHD-0224BZ-FL-GBW-ND 2x24 character display location but needs to be
D1, D2 1N4148FSTR-ND Signal diode able to find its way back
D3 754-1720-ND Green LED, T-1
D4 516-1769-ND Amber LED, T-1
to where it started, such
D5 1N5399-E3/54GICT-ND Reverse protection diode as CALL or GOSUB. This
C1, C2 Optional, see PIC datasheet array is called a stack, and
C3 399-1418-ND 10 μF tantalum
C4-C7 399-4151-ND 0.1 μF ceramic
it is limited in size. The
C8, C9 Optional, see text PIC16F887 has an eight-
C10 Frequency trim cap; see PCF8563 datasheet level stack that can
R1 10KEBK-ND 10K 1/6 watt support eight nested
R2, R3, R6, R7, R12 4.7KEBK-ND 4.7K 1/6 watt
R4, R8, R9, R10 1.0KEBK-ND 1K 1/6 watt CALLs (i.e., a CALL within
R5 22KEBK-ND 22K 1/6 watt a CALL within ...).
R11 1.0MEBK-ND 1M 1/6 watt (optional) PICBasic PRO uses four of
SP1 445-2525-1-ND Piezoelectric beeper
X1 631-1081-ND 4 MHz crystal these levels for its own
X2 300-3007-ND 32 kHz crystal internal purposes, leaving
X3 Optional, see text four nested levels for use
J1-J6 S1011EC-40-ND 0.1” straight header
J7 CP-1560-ND PS/2 Mini-DIN-6
in your code.
I learned the hard
PARTS
S1 ED3048-5-ND 40-pin DIP socket
S2, S4 (2) ED3052-5-ND 28-pin DIP socket way that neither the PIC
LIST
SW1 450-1665-ND SPST momentary switch nor PICBasic PRO will
BT1 BS-7-ND Battery holder for CR2032
(none) S1111EC-40-ND 0.1” right-angle header for warn you if you write
memory jumpers code that creates a stack
30 January 2017
Gravatt - Retro PIC SBC - Feb 17_Blank Rough NV.qxd 12/5/2016 11:00 PM Page 31
Vintage Computing
ESP8266 RSS
News Reader
I admit it. I am a self-proclaimed news nut. I don't know, but this might actually
be an undiagnosed illness since I look at the news on the web constantly during
the day and then watch the news in the evenings on TV. There is always
something going on in our world (for better or worse) that I don't seem to want
to miss. So, when I was thinking about other applications for the amazing
ESP8266, I thought why don't I write an RSS reader so I can monitor the
headlines from many different news sources from around the world. Then, if
something catches my attention, I can open up my laptop and read the full story.
or those of you who aren’t familiar with RSS, In this article, I’m going to describe an RSS news
By Craig A. Lindley Post comments on this article and find any associated files and/or downloads at
www.nutsvolts.com/magazine/article/January2017_ESP8266-RSS-News-Reader.
As mentioned, the RSS news reader uses the same RSS News Reader
hardware as described in my previous ESP8266 articles. To
save you from going back and (re)reading previous
Software Operation
articles, the hardware information is repeated here starting Before you can use the RSS reader, you must supply
with the Parts List. Figure 1 shows a Fritzing connection login information for your Wi-Fi network. You do this by
diagram/schematic for the RSS news reader. Figure 2 opening up the main sketch/program file
shows the design wired up on a breadboard. The news ESP8266RSSNewsReader.ino and finding the following user
reader is powered via a USB cable and a USB power configuration section:
supply module, although it could be powered by plugging
it into your computer. The wire by wire connections are // ******************************************
// Start of user configuration items
shown in Table 1 because they might not be clear from // ******************************************
the Fritzing diagram.
// Set your WiFi login credentials
The GPIO designations are shown as that is how const char * WIFI_SSID = “xxxxxxxx”;
these digital I/O lines are referred to in the Arduino code. const char * WIFI_PASS = “xxxxxxxxxxx”;
The Adafruit LCD display also has a micro-SD memory
// ******************************************
card interface which can be used with the ESP8266, but it // End of user configuration items
was not needed for this project. // ******************************************
January 2017 33
Lindley - RSS News Reader - Jan 17_Blank Rough NV.qxd 12/5/2016 11:07 PM Page 34
This information allows the ESP8266 to login to your This is the RSS feed list with the NPR feed as the first
Wi-Fi network as required to access the RSS feeds across entry. That is why the first feed displayed by default is
the Internet. The login screen shown in Figure 3 is displayedNPR. As you use the feed advance pushbutton, you move
on the LCD while the login process is occurring. It will be down the list one RSS feed at a time. When you
replaced with the RSS news reader screen shown in Figure increment past the last entry, you wrap around to the first
4 when the login process completes successfully. Check again. You can easily delete feeds from this list or
your Wi-Fi login credentials (WIFI_SSID and WIFI_PASS) if rearrange their order to suit your preferences. You can
the login screen doesn’t go away. You’ll also notice towards even add feeds to this list by Googling the news provider
the top of the sketch this array of character strings: you are interested in and looking for the URL they publish
for their RSS feed(s). Once you have that, insert it into the
// Array of feed URLs feeds list, recompile the code, and upload it to the
const char *rssFeedURLs [] = {
“www.npr.org/rss/rss.php?id=1001”, NodeMCU Amica module, and you will be all set.
“http://rss.cnn.com/rss/cnn_topstories.rss”, Most of the remaining code in the
“http://feeds.bbci.co.uk/news/rss.xml”,
“http://hosted.ap.org/lineups/SCIENCEHEADS- ESP8266RSSNewsReader.ino sketch file is concerned with
rss_2.0.xml?SITE=OHLIM&SECTION=HOME”, declaring instances of the LCD driver, the text scroller, and
“http://www.latimes.com/rss2.0.xml”, the RSS reader classes and initializing them. The loop()
“http://rss.cnn.com/rss/cnn_tech.rss”,
“http://feeds.reuters.com/reuters/topNews”, function in the sketch continually calls the read function of
“rssfeeds.usatoday.com/usatoday- the RSSReader class, passing the URL of the RSS feed to
NewsTopStories”,
display. The code for the RSSReader is the most complex
};
in this application. The complexity is a result of having to
request the headline information from a news
Table 1.
Adafruit 1.8” LCD Display News Feed Advance source and then to extract the information of
NodeMCU Amica Pin Connection Pushbutton SPST Switch interest from the XML returned from the source.
D1 (GPIO 5) SW1 For those not familiar with XML, it is a software
D3 (GPIO 0) LITE and hardware independent tool for storing and
D4 (GPIO 2) D/C transporting data in human readable format.
D5 SCK • XML stands for EXtensible Markup Language
D7 MOSI
• XML is a markup language much like HTML
D8 (GPIO 15) TFT_CS
• XML was designed to be self-descriptive
3V3 VCC
GND Gnd SW2 • XML is a W3C Recommendation
REVIEW
Post comments on this article and find any associated files and/or downloads at
By Dane Weston www.nutsvolts.com/magazine/article/January2017_Bench-Werx-PCB-Rax.
The
The E
Easiest
asiest W
Way
ay tto
o Design Custom
Front
Front Panels
Panels & Enclosures
parts-express.com
1-800-338-0531 FrontPanelExpress.com
January 2017 39
Ward - MyRIO - Part 2 - Jan 17_Blank Rough NV.qxd 12/5/2016 11:24 PM Page 40
Computer Control
and Interfacing with
the NI MyRIO
By David Ward
FIGURE 13.
FIGURE 12.
There are
two usernames
and two
passwords
FIGURE 16. configured on
the MyRIO
used in these
articles. The
username and
password to
FIGURE 14. access the
MyRIO itself to view files, reboot,
etc., is “admin” and “nimyrio.” The
username and password to access
will then need to be added to the block the Wi-Fi connection is “NIMYRIO”
diagram. and “nilabview.” The address that
The LED variable status or data (true or should appear on the iPad needs to
false) will be sent out from the MyRIO Wi-Fi to FIGURE 15. be 172.16.0.1 and be named
the iPad and turn an LED indicator on the iPad NIMYRIO. Be sure to click on the
on and off. A control on the iPad (acting as a Save button before exiting. When
switch) will send its data (true or false) from the MyRIO Wi-Fi is working, there is
the iPad back to the MyRIO to control LED0. Third, NI an orange or red LED located just above LED0 that will be
Data Dashboard will need to be installed and a Data on. There is also a Wi-Fi button on the bottom of the
Dashboard built to interact with the VI through the MyRIO unit next to BUTTON0 that can be pressed to turn
MyRIO wireless router. the Wi-Fi off and on. However, if the Wi-Fi LED is not on,
If you have not set up the MyRIO Wi-Fi yet, it will be the Wi-Fi connection will not work.
demonstrated here. Setting up this Wi-Fi can be done To set up your project so that it can transmit and
several ways, but the way shown here will be through the receive wireless data, open up the Project View window.
USB cable connected to the host PC. On the PC, open Click on NI-myRIO..., right-click, and from the pull-down
Windows Explorer and type in address 172.22.11.2; this is menus select New > Web Service as shown in Figures 14
the default address the MyRIO unit uses for the USB and 15. Now, click on NI-myRIO..., right-click, and from
connection. You should see the System Configuration the pull-down menu select New > Variable as shown in
window shown in Figure 12. Select the fourth icon down: Figure 16. For the next step, refer to Figure 17.
Network Configuration. Figure 13 shows how this From the Shared Variable Properties window, you can
particular MyRIO Wi-Fi was configured: Wireless Mode > rename the variable (renamed as LED), then click on
Create wireless network; Country > United States; SSID > Variable Type > Network-Published, Data Type > Boolean,
NIMYRIO; Security > WPA2 Personal; WPA Passphrase > then click on OK. In the Project View tree, you will now
nimyrio; and finally Configure IPv4 Address > DHCP Only. see an untitled library with your LED variable under it;
42 January 2017
Ward - MyRIO - Part 2 - Jan 17_Blank Rough NV.qxd 12/5/2016 11:24 PM Page 43
FIGURE 19.
FIGURE 17.
FIGURE 18.
refer to Figure 18. To add more variables to your
project, click on Untitled Library, right-click, and
from the pull-down menu, select New > Variable
and name another variable as before; in this
case, button and Data Type > Boolean; see
Figure 19. Now with both the Project View
window and the Block Diagram window placed
next to each other, drag the two variables (LED
and button) one at a time from the Project View
tree over into the while loop of the block
diagram as shown in Figure 20. The green data
arrow on the button variable is on its right side;
this will work as it will be a control coming from
the Wi-Fi. However, the arrow on the LED FIGURE 20.
variable needs to be on its
left side so that it can
transmit its status through
the Wi-Fi.
To make this change,
select the LED icon, right-
click, and from the pull-down
menu, select Properties.
From its Properties window,
change the Access Type
from Read to Write. Refer to FIGURE 22.
Figure 21. Now, wire these
two variables into the block FIGURE 21.
diagram as shown in Figure
22, adding another “Or” gate as shown. This means that data through its Wi-Fi. The last step in this process is to get
either the pushbutton on the front panel of the VI, the the iPad ready to interact with the MyRIO Wi-Fi. First,
BUTTON0 on the MyRIO unit, or the control on the iPad download and install NI Data Dashboard onto your iPad
can control LED0, and that the LED indicator will be on from the Apple ITunes store; it should be free. When it is
the Data Dashboard of the iPad. installed, you should see the Dashboard icon as shown in
Be sure to click on File > Save All on either the front Figure 23. Open Settings as in Figure 24. You should be
panel or the block
diagram after you make
all of these changes so
you don’t lose them. It
is also wise to click on
the File > Save All (this
project) from the
Project View window FIGURE 23.
from time to time.
Now, the VI can be run
on the MyRIO unit. It FIGURE
24.
should start publishing
January 2017 43
Ward - MyRIO - Part 2 - Jan 17_Blank Rough NV.qxd 12/5/2016 11:25 PM Page 44
FIGURE 26.
FIGURE 25.
FIGURE 27.
FIGURE 29.
FIGURE 28.
FIGURE 30.
FIGURE 31.
FIGURE 32.
FIGURE 34.
FIGURE 33.
FIGURE 35.
FIGURE 36.
46 January 2017
McPhalen - Spin Zone - Jan 17_Spin Zone - Aug 15.qxd 12/5/2016 11:31 PM Page 48
Making Menus
Today, I have Willie Nelson stuck in my head — well, one of his songs, anyway, because I
am, in fact, on the road again. As I bask in the solitude of a quiet condominium, my
colleagues and their families are enjoying the day at Disney World. We're in a bit of a
celebratory mood because we've just come off a very big trade show and it was a
success. My client introduced a new product that uses a custom board designed by EFX-
TEK, and coded by yours truly. What my client's customers enjoyed about the new
controller is the simplified menus. They're easier to navigate, more consistent, and just
make better sense (FTR, I did not design nor code the previous product!). Menus are
important — in restaurants and in consumer devices — and we should never take them
for granted.
This month, I’m going to explore some of the code I
J
ust over 20 years ago, I created the concept for an
irrigation controller that would be developed into the used in my customer’s laser tag product, though we’re not
Toro ECx. The requirements for the product were a going to build a working laser tag weapon, nor a sprinkler
challenge: It had to be price competitive, and it had to be timer for that matter — but we are going to enter data for
available for sale all over the world. As a product designer, what would be useful in a small irrigation control
user interface is always something that I put a lot of application. Just as my client limited me to a 2x8 LCD with
energy into; that paid off this week with the laser tag three buttons (well, two buttons and a trigger; see Figure
controller, just as it did 20 years ago at Toro. I am very 1), we’re going to stick with that to see if we can make it
happy that the ECx (with tech upgrades, of course) is still work. It would be easier to work with four buttons, or
available for sale in my local hardware store. I put a lot of even six as I have on another project (a road sign
effort into that product, and it helped me realize a life-long controller), but the real world doesn’t always bend to our
goal of earning a United States patent (in fact, I earned desires and wishes. Another singer/song writer that I quite
two from it). It also allowed me to contribute to an enjoy once said, “You can’t always get what you want, but
employer that treated me very well. When I hand a new if you try, sometimes you get what you need.”
design to a customer, I am intensely focused on their I like to start with a map before coding any menu
initial reaction. A vice president at Toro was first to try the based projects; this is particularly helpful when working
ECx; he looked at me and said, “It’s too good!” (Not what with a client. On the laser tag project, for example, my
I was expecting.). On the show floor a few days ago, a client made a fairly serious structural change when he was
nice lady who runs a lot of laser tag facilities in Canada able to see the entire system laid out on a page, and this
kissed me on the cheek for how I had cleaned up the change was greatly appreciated by his customers. Figure 2
menus and operations versus the previous product. Again: shows the layout of our bare-bones sprinkler timer data
User interface matters, so it behooves us to do it well. entry menus. Note the color coding; the colors indicate
Post comments on this article and find any associated files and/or downloads at
www.nutsvolts.com/magazine/article/January2017_SpinZone_Making-Menus-User-Interface.
entry elements that will use the same code or an identical In the sprinkler timer demo, the edit_settings()
coding strategy (i.e., copy, paste, modify as needed). The method is called when the green button is pressed. This
overall map also serves as a check-list for the methods that changes pgmstate to edit mode and gets us to the top
have to be developed. level menu. The program will stay in this menu until EXIT
Author’s Note: I found a freeware font that matches Setup is selected and the green button is pressed. The real
standard character LCDs so I used it in my maps. This work takes place in the select_from_list2() method:
allowed my customer to see exactly what his menus would
look like before I ever started coding. Small details like this pub select_from_list2(idx, lo, hi, p_list) {
} | last
can make a big difference in a project.
The next step in my process was to code some helper idx := 0 #> idx <# hi
routines that would work with my standard LCD object. repeat
For example, the top row of the map is the top level of last := -1
the menu. The arrows indicate buttons on the tagger: repeat
if (idx <> last)
black for up and forward, red for down and reverse; green display_2x8(p_list + (idx * 17))
(the trigger) is to enter or accept. last := idx
The top level menu is a simple list of screens. I lay out if (get_input(@idx, lo, hi))
the screens in a DAT section like this: clear_buttons(BTN_CLR)
return idx
dat else
time.pause(BTN_SPD)
s_MainMenu byte “SET W-Days “, 0
byte “SET W-Starts”, 0 At the top, we start by fixing idx (current index into
byte “SET Sta Run “, 0
byte “SET Clock “, 0 list) to the range defined by lo and hi. Defining the range
byte “EXIT Setup “, 0 allows us to use a small portion of a longer list. On first
entry or any time the red or black buttons are pressed, the
For each 2x8 display, I define a single 16-character screen is updated. Buttons are handled by the get_input()
string. Those strings are displayed with this method: method:
pub display_2x8(p_str) pub get_input(p_value, lo, hi) | btns
lcd.home repeat
lcd.substr(p_str, 8) btns := scan_buttons(BTN_MS)
lcd.line(1) until (btns <> %000)
lcd.substr(p_str+8, 8) case btns
M_FWD :
This routine expects a pointer to a string, and this if (++long[p_value] > hi)
string should be 16 characters long to cover both lines of long[p_value] := lo
the 2x8 display. Since we’re going to be overwriting the return 0
display, we don’t need to clear it — clearing the LCD takes M_REV :
more time than simply moving the cursor to the home if (—long[p_value] < lo)
long[p_value] := hi
position, anyway. The substr() method puts the first eight return 0
characters of the string on the first line of the display.
Next, we move to the bottom line and print the second M_SET :
return
eight characters from the string:
This method uses scan_button() to wait for user input.
pub edit_settings | idx Note that it requires a pointer to a [long] value to be
idx := 0 modified, as well as the low and high limits for that value.
If the black button is pressed, the value is incremented,
repeat
if (pgmstate <> PS_EDIT) rolling over to the low limit if the high limit is exceeded.
return Likewise, if the red button is pressed, the value is
decremented, rolling under to the high limit if we drop
idx := select_from_list2(idx, 0, 4,
@s_MainMenu) below the low limit. If black or red is pressed, zero is
case idx returned to indicate that we’re not done editing. If the
0 : set_watering_days
1 : set_irrigation_starts green Set/Enter button is pressed, one is returned as a flag
2 : set_station_run_times to terminate editing this value.
3 : set_clock The scan_button() method handles basic debouncing
4 : pgmstate := PS_RUN and manipulates the button pins so that we can share the
January 2017 49
McPhalen - Spin Zone - Jan 17_Spin Zone - Aug 15.qxd 12/5/2016 11:31 PM Page 50
now.byte[3] := select_from_list1 {
} (now.byte[3], 0, 6, 1,
@s_Sun, 4)
return now
if (clr)
clear_display(true)
if (p_str0 > 0)
line_out(0, p_str0)
LCD buss. This is not a new or original concept; my friend,
if (p_str1 > 0)
Scott Edwards showed us how to do it many years ago in line_out(1, p_str1)
Nuts & Volts. Almost every one of my LCD projects uses
the buss pins for buttons. Figure 3 shows the schematic This method gets the most use in my menu systems.
for the laser tag HMI which I am using in the sprinkler The first parameter determines whether the LCD will be
timer demo; you can easily modify this for your own cleared or not. Again, if we’re using two strings and both
projects, and even add a fourth button to DB7 if you need are eight characters, there is no need to clear the LCD.
it. The LCD is configured as write-only (W/R line is tied to The next two parameters are pointers to the strings to be
ground), so we don’t have to put series resistors in the displayed: the first on the top line; the second on the
buss. The 10K voltage dividers attached to the buttons bottom line. If we want to display a string on a particular
and LCD buss ensure that the button input voltage to the line, we pass the address of that string. If a line is to be left
Propeller is at a safe level: blank (i.e., after clearing) or unmodified, then we pass 0
(false). In set_day(), the call to display_screen() changes
pub scan_buttons(ms) | btns, t the top line to “Today is” and clears the bottom line. This
dira[BTN_F..BTN_S] := %000 sets up the screen for the work which is handled by
btns := ina[BTN_F..BTN_S] select_from_list().
if (btns) This behaves like select_from_list2(), but only
t := cnt modifies one line of the display. In this case, it will be the
repeat ms bottom line which will display the abbreviated name of
waitcnt(t += MS_001)
btns &= ina[BTN_F..BTN_S] the week. Those names come from a list which begins
return btns with the DAT element called s_Sun. Note that we’re using
@ to pass the address of s_Sun.
This method is simplified by using the LCD buss pins Author’s Note: I have made a small style change in my
which are connected to the Propeller in a contiguous own programs, vis-à-vis strings. When they’re pre-defined in
group (a requirement of the LCD object). The pins are a DAT section, I preface them with “s_” and use mixed-
made inputs and then checked to see if any are pressed. If case naming. This is consistent with my use of the “p_”
one or more inputs are active, the method drops into a prefix for pointer (address) variables, as we always have to
loop for the debounce period (ms), and then re-scans the pass the address of a string to a method. The laser tag
pins before returning a clean input. project has dozens of strings, and this style change made
On the other side of this, the output routine for the them far more manageable.
LCD object must ensure that the buss pins are set to The parameter passed to set_day() is actually a long
outputs before any write. That is already in place. that contains all four RTC elements: day, hours, minutes,
I know what you’re thinking: “That’s a lot of layers for and seconds. As you can see, we’re only modifying byte 3
a simple menu!” You’re right, it is, but you’ll also notice of this value as that’s what holds the current day (0..6).
that each of the routines is atomic which will allow us to Since we’ve jumped into setting/editing the clock,
employ them elsewhere. In the laser tag project and in our let’s back up one level. In the menu map, you see four
simple sprinkler timer demo, we have more than screen elements under SET Clock, and routines for those
selections. For example, when we select Edit Clock, the elements are called with this method:
50 January 2017
McPhalen - Spin Zone - Jan 17_Spin Zone - Aug 15.qxd 12/5/2016 11:31 PM Page 51
now.byte[2] := edit_value{ The active watering days for the program are stored as
} (now.byte[2], 0, 23, 0, 1,
2) a byte called Water_Days that is embedded in a DAT
section. Each bit is identified by day name using an array
return now of strings and an array of string addresses which is why
This is starting to look familiar, right? It should. After we’re using the @@ operator to display a day name. Each
setting up the initial display, we display now as a clock bit is extracted into check which is then edited using
using the show_clock() method: select_from_list1(). In this case, the choices are “No” (0)
January 2017 51
McPhalen - Spin Zone - Jan 17_Spin Zone - Aug 15.qxd 12/5/2016 11:32 PM Page 52
www.embeddedARM.com
Single Board Computer
TS-7680
Low Power Industrial SBC
454 MHz ARM CPU
WiFi & Bluetooth Enabled
4GB eMMC Flash Storage
-40°C /+85°C Temp
e Range
Computer-on-Module
TS-4900
High Per fo
ormance
Freescale i.MX6 ARM CPU
WiFi & Bluetooth Enabled
Quad Core Option
(480) 837-5200
52 January 2017
McPhalen - Spin Zone - Jan 17_Spin Zone - Aug 15.qxd 12/6/2016 12:30 AM Page 53
(716) 630-703
0
CHASS
IS
TRANS
FORME
RS
ENCLO
SURES
January 2017 53
THE DESIGN CYCLE n BY FRED EADY
h
l n SCREENSHOT 1. The Configuration Wizard allows us
to easily change the nRF52832 peripheral configuration.
A scripting language allows us to create our own custom n SCREENSHOT 2. As you can see, the contents of the
sdk_config.h entries, which can be accessed via the sdk_config.h file can be altered by our selections within
Configuration Wizard. the Configuration Wizard.
Recall that we have the ability to right-click on .use_easy_dma = CONCAT_3(SPI, id, _USE_EASY_ \
types and be directed to their original definitions. DMA) \
Here is what the nrf_drv_spi_t structure looks like: }
Note that we used the nrf_drv_spi_t type to create the The state of SPI0_USE_EASY_DMA is determined by
spi0 structure. We populated the new structure using the a setting within the Configuration Wizard. I’ve captured
macro NRF_DRV_SPI_INSTANCE(SPI_INSTANCE). Using the negative point of definition for DMA operation in
the magic of right-clicking again, we can reveal the macro’s Screenshot 2.
contents: At this point, we have defined the SPI portal GPIO
pins and the spi0 instance. The SPI portal is being built to
/** transfer data. So, we will need to allocate some storage to
* @brief Macro for creating an SPI master driver house the data that will be exchanged over our new SPI
* instance. portal. For this, we need not conjure up any nRF52832-
*/ specific code. Just plain old C will work here:
#define NRF_DRV_SPI_INSTANCE(id) \
{ \ #define txdata “NutsVolts”
.p_registers = NRF_DRV_SPI_PERIPHERAL(id), \ static uint8_t m_tx_buf[] = txdata;
.irq = CONCAT_3(SPI, id, _IRQ), \ //extra byte in rx_buf for NULL character
.drv_inst_idx = CONCAT_3(SPI, id, _INSTANCE_ \ static uint8_t m_rx_buf[sizeof(txdata) + 1];
INDEX), \ //number of bytes to transfer = m_length
January 2017 57
0
1
F
d
a
a
P
n SCREENSHOT 3. Our nRF52832 Master device is at work. Every SPI signal you see in this capture was generated by U
the nRF52832. Since there is no Slave device attached, the MISO line is seen as a logical high for the duration of the
data exchange.
60 January 2017
is attached to the nRF52832, to visually signal a nRF52832. In the meantime, check out the Nordic
completed data exchange. Semiconductor website, build up an nRF52832 jig,
The SPI operations can be seen in Screenshot 4. and write some Bluetooth Low Energy code of your
Note the SPI Master always clocks out an ASCII 1. It own. NV
doesn’t matter in this case what the SPI Master sends
as we’re only interested in the SPI Master supplying a
clock to retrieve the SPI Slave data. As you can see in Raytac MDBT40 BLE Module
Screenshot 4, the SPI Slave sends one byte of its txBuf Raytac
with each data exchange cycle. www.raytac.com
n SCREENSHOT 4. Each cycle of data exchange transfers two bytes: one from the SPI Master (ASCII 1) and one from the
SPI Slave (txBuf[i]).
Parallax Board of Education Full Kit BOE Full Kit $98.90 0603ZD98
48W Soldering Station
USB version with Stamp and USB Cable. Parallax 7.5V Power Supply $8.95 Temp. Controlled
$15.25
310oF~840oF
>>> QUESTIONS and tolerances of components? For practical use of a small ultra capacitor p
example, if my power source is 12 is to maintain a CMOS memory while th
Uno-Known Device volts, is an electrolytic capacitor with the set is unplugged.
I’ve used the Arduino IDE with a 24V rating “better” than one with a Chip Veres
a genuine Arduino Uno board 16V rating? What do good designers Miami, FL
for experiments for a few months use as a margin?
without trouble. Recently, I wanted to #1174 Enrico Gutiérrez [#9163 - September 2016] to
permanently put an Uno in a desktop Panama City, FL Cassette to MP3 ja
project, so I purchased some budget I have a box of cassette audio st
Arduino Uno compatible boards. The >>> ANSWERS tapes that I want to convert to MP3 V
budget boards seem fine, but the [#9162 - September 2016] format. What’s the simplest way to o
Arduino IDE doesn’t recognize any of What’s The Deal With Ultra Caps? do it? I have a Windows 10 PC and a A
them. When connected, the boards I am looking to experiment with Nakamichi CR-2A cassette deck. p
show up as an “Unknown Device.” “ultra capacitors” as a replacement
I am using Windows 7 32-bit. Does for AA batteries. Is this possible to #1 There is a very good little box (i
anyone have any pointers on how to do and, if so, what kind of capacitors made just for transferring LPs and a
make this board work? would be a good place to start? CDs to MP3 or wave format. It’s e
#1171 Michael Allison made by DAK and costs $69.90. a
Camden, NJ #1 The short answer is NO. The See the link: www.dak.com/ Fo
main function of ultra caps is for reviews/2021story.cfm. so
Trainsformer Needed TEMPORARY backup of memory The box accepts stereo input th
I found a bargain at a local thrift type devices (i.e., clocks in DVD from any source (including a A
store and now have a 1959 Marklin players) during brief (i.e., less than a microphone), provides for balance si
HO Scale train, cars, and track. The day) power outages. They are NOT and loudness adjustment, digitizes Fo
set didn’t come with a transformer, so suitable nor designed to replace it according to the resolution you si
I thought it would be a fun project to batteries simply because, as they are want, and prepares a file for a CD. to
build from scratch. Does anyone have electrolytic capacitors, they need You can name the flie and see the w
a schematic or suggestion for a DIY recharging when their stored energy audio as it is played. This is especially lik
train transformer they can share? is depleted. Also, they’re not really useful in that you can ensure that a
#1172 Alfred Thompson designed for current loads greater the signal is not being clipped. One
Kingsport,TN than a couple hundred microamps. can then run the file(s) through a
This subject has come up a few times hiss and click reduction program,
Turn Signal Signal in the past couple of years and I which is especially good as it is based [#
I have a newly restored 1971 believe N&V had an article comparing on an algorithm rather than just F
Honda CB350 motorcycle that I ultra caps to batteries (primary and clipping spikes. Thus, it works on low
ride for fun on the weekends. One rechargeable). amplitude as well as high amplitude sw
problem is forgetting to turn off the Ken Simmons signals. co
turn indicators. I have found a kit that Auburn, MI The latest software also has a a
“beeps” every time the indicator lights feature which will automatically take p
up, but it's very annoying as I sit at a #2 This is only practical when the out the large gap one may have
light. I would like a circuit that would current draw is very low. A coulomb between sides of tapes or LPs, leaving
alert me only if the turn indicator is one amp-second. By definition, a only, say three seconds. I have found u
stays on for more than two minutes. one-Farad capacitor charged to five the whole process very satisfactory
Schematic would be welcome! volts can deliver five coulombs. A though time-consuming, as one in
#1173 Leland Collins single AA battery can deliver at least must — of course — pay a certain n
Gulfport, MS 1,350 coulombs. This is because the amount of attention to whether the —
material of the battery is consumed tape or LP is finished when doing the d
How Much Tolerance Is Enough? when it is delivering current. The conversion. The ideal thing is to have c
When designing circuits, is there capacitor isn’t consumed; it’s just a two screens on your computer so you n
a rule of thumb for picking voltages tank for electricity. About the only can keep your eye on the conversion
62 January 2017
r process while doing other work on solution is readily available from them out. Today, there are power
e the other screen. Harbor Freight Tools. Item 43060 MOSFETS but they aren’t very fast. So
John Drake is a “Router Speed Control” and the existing MOSFETS tend to fall in
es Ann Arbor, MI works great with inductive AC or DC two families: Fast but fragile, or strong
L motors up to 15 amps (120 VAC). but slow. Kind of like people.
#2 Quite easy to do. You need I have several to vary the speed Chip Veres
to get a cable to go from the RCA of many tools, not just my router. Miami, FL
jacks on your cassette deck to a Costing about $15 a piece, I use this
stereo mini plug to go into your PC. controller with my five-speed wood [#10162 - October 2016]
Very common, but if you can’t find drill press (when drilling soft metals Fish Caller Circuit
one, then Amazon has them. Dynex that require slower speeds); with I found a partially assembled kit
A20420 and many others. For your Harbor Freight’s largest “hurricane” labeled “Fish Caller.” Does anyone
purposes, practically anything will do. fan (which also has a HI/MED/LOW/ have a schematic for one that I could
Then, download Audacity, which OFF switch); and other AC powered use to finish it? Also, what’s the theory
(in my humble opinion) is the best fixed speed tools. behind how it works ... or does it?
audio editing program out there — Equipped with a 15 amp
especially since it is free. Go to www. 3AG type fuse and a three-prong #1 Seriously, you can find all the
audacityteam.org for the details. receptacle, this lightweight controller circuits you want by Googling “Fish
For MP3 export, you’ll also need is hard to beat and much safer to use. Caller Circuit” and looking at the
something called LAME, available on BGoodWill KD2FZU images. Less than seriously, it emits
the Audacity site. Play your tapes into Rahway, NJ Fishy Language for “Neener, neener,
Audacity, then export them either as neener! You can’t catch me!”
single songs per file or entire sides. #2 Danger Danger! The typical Chip Veres
For that matter, you can capture both lamp dimmer is not compatible with Miami, FL
sides of the tape and use Audacity the typical cheap fan motor. There
to remove the dead areas that occur are good articles on the Web as to #2 I built one years ago. It was
while changing sides. Or, if you only why. Look up shaded pole speed designed to produce a high frequency
y like a couple of the songs, just copy control and see why. That said, I find noise that supposedly attracted fish.
and paste what you want. that box fan motors tend to be okay Maybe my fish were hard of hearing
Jerry McCarty with better (triac based) motor speed but it never worked in my field trials.
via email controllers, such as sold by Harbor I have never seen them promoted in
Freight and on eBay. On a shaded any fishing supply catalogs either.
d [#10161 - October 2016] pole motor of a typical cheap fan, M. Herman
Fan Conversion overheating the motor is possible. LaQuinta, CA
My desk fan has a three-position Jim Lacenski
switch: HI/OFF/LOW. I would like to Bellevue, WA #3 Theory: It makes a ticking
convert the fan to variable speed. Will sound that sounds like a dying fish
a simple lamp dimmer work for this [#9164 - September 2016] which attracts other fish.
purpose? Transistor Training You might try https://www.
I’m retired and re-learning electronickits.com/electronic-fish-
g #1 Please do not even think of electronics. I am confused about the caller-plan. On the other hand, if all
using a simple lamp dimmer for this! differences between MOSFET and it does is tick, you now know what
Lamp dimmers are for “regular” transistors. Is there a rule of the circuit is supposed to do and you
incandescent (filament) bulbs only — thumb as to when/where/why you might be able to complete it with just
not inductive motor (AC or DC) loads would use one over the other? that much information. The above link
— and will likely cause a fire! A lamp sells plans to build such a thing. There
e dimmer connected to a ceiling fan Traditionally, MOSFETS were used are others selling kits as well. I simply
caused such a fire, nearly burning my for small-signal amplifiers and mixers, did a web search to find the above.
u neighbor’s house down! Don’t do it. particularly at high frequencies. High Phil Karras
The easiest, cheapest, and safest currents or voltages would easily burn Mt Airy, MD
January 2017 63
READER FEEDBACK
Continued from page 7
meets or exceeds 60% of the investment I will have to incur, Defining Electronics
I will order from the OEM and take my chances on selling the
rest. I will keep you posted as to the status of this offer. Electronics: The study of the electrical properties of and
Robert Reed the use of electronic devices.
Electronic devices include resistors, capacitors, inductors,
Anode + Cathode = ? diodes, transistors, integrated circuits, antennas, waveguides,
electronic tubes, batteries, etc.
I would like to point out an error on the picture of an Electronics includes laying out circuit boards — signal
LED. The schematic symbol polarity is reversed. The device crosstalk, current limit for a given width of trace, impedance
matching, skew of parallel signals, etc.
should be: cathode + and anode -. If the device is hooked up A person experienced in electronics will know how to
as pictured, it will destruct. You might want to print a assemble a circuit and how to solder the connections.
correction in the magazine. Programming DSPs, FPGAs, CPLDs, SoCs,
Mike Jobe microcontrollers, computers, etc., is just that — programming.
Marion, IL Programmers do not need to know which end of a soldering
iron to grab. (There has been talk over the years that BSEE
graduates don’t know that either.)
Thanks for having a look at the article. The LED drawings I like the mix of articles and the mix within articles in
on page 24 of the October 2016 issue appear to be correct. Nuts & Volts Magazine. This includes programming articles
Have a look at "LED" on Google Images. An LED must be about microcontrollers that react to and affect real world
biased in the forward direction in order to emit light. Thus, + devices. I would not change anything — not the articles nor
to the anode and - to the cathode. This terminology of the name.
cathode and anode is from the days of vacuum tubes: In a If you were to change the magazine’s name to Keyboards
and Microcontrollers, please consider that this new name
vacuum tube, electrons flow from cathode to anode, so the would make the magazine sound like a purely programming
current direction (defined as the flow of positive charges) is magazine and you would probably not get any new readers
from anode to cathode. that are interested in electronics.
That said, if you were to connect a low impedance We need Nuts & Volts!!! I know of no other magazine
voltage source — say a battery — of sufficient voltage to the that fills the bill for me. I like to read the mid-level articles in
LED in the polarity pictured, the LED would indeed destruct N&V and the ideas I get from N&V. I like to find out about
after a brief flash. So, a current-limiting resistor is needed, the new devices used in your articles and mentioned in your
New Products department such as the DS1820 temperature
which is the purpose of R3, R4, and R16 in the circuit. sensor, the S.USV Pi, and the EXasPiB.
I did notice one small glitch: the upper-right paragraph on My background?
page 26 refers to Figure 7; the reference should be to Figure - Took the Cleveland Institute of Electronics first phone
10. course.
Randy Keenan - Got my first phone FCC license 48 years ago. (Yup. I’m
almost older than dirt.)
- Was trained in television electronics — receivers and
broadcast equipment — in the Army (MOS 26T).
- Graduated from the Univ of MN with a BA in Industrial
64 January 2017