Está en la página 1de 132

Edition 4/2017 | July & August 2017

www.elektormagazine.com

LEARN DESIGN SHARE


nWatch
a Wearable
Development System
Audio DAC
for Raspberry Pi
A network audio player
with Volumio

PCBs — Printed, or how to build


not Etched your own smart watch
the Voltera V-One PCB printer
and reflow soldering station
2-Terminal Dimmer • Audio DAC for Raspberry Pi • BBC micro:bit for
Electronicists (2) • Components in Space • Data acquisition and oscilloscope
functions • Electronics in Orbit • Elektor Labs Pipeline • Err-lectronics •
FPGA-DSP Board for Narrowband SDR • Get 5 V from One Exhausted
Alkaline Cell • Homelab Helicopter • Keep Cool with an ATtiny • Making
Lights Meaningful • May I have the menu, please? • Mercury Coulometers
• MicroPython and the pyboard • nWatch, a Wearable Development System
• PCB Design is Not Easy • PCBs — Printed, not Etched • RF Step Attenuator
• Sea Murmur Simulator • Sensors Make Sense (4) • Smart Devices • Sniffer
FPGA-DSP Board for
using RFM12 Radio Module • Test Pattern Generator using a Digital Camera •
Narrowband SDR
A fully programmable
Tektronix 556 and 565 Dual-beam Oscilloscopes • The ESP8266’s Big Brother •
receiver/transmitter baseboard The I2C Bus • Ukele-LED • Zenerdoku (an extraordinary Hexadoku) • And more
Appliance Design Jet ad 020817.qxp_Layout 1 2/8/17 4:16 PM Page 1
Elektor Magazine
Edition 4/2017
Volume 43, No. 484
July & August 2017

ISSN 1757-0875 (UK / US / ROW distribution)

www.elektor.com
www.elektormagazine.com

You can leave your hat on


Elektor Magazine, English edition
is published 6 times a year by

Elektor International Media


78 York Street Today, if you see a board with a pinheader along the sides, or its female counterpart the
London W1H 1DP pinheader socket, in single- or double-row guise, most likely you are looking at an exten-
United Kingdom
sion board for one of the popular DIY embedded platforms like Raspberry Pi, Arduino,
Phone: (+44) (0)20 7692 8344
BeagleBone and many others. These stack-on boards go by trendy names like hat (RPi),
Head Office: shield (Arduino), or cape (BB). The name ‘hat’ is a good find as besides being an acro-
Elektor International Media b.v. nym for Hardware Added on Top; it doubles nicely as the device you put on top of your
PO Box 11
RPi board. The ‘shield’ I find a little puzzling as I was taught at school this is a protective
NL-6114-ZG Susteren
device designed to keep the bearer from being hurt by sharp or heavy objects hurled or
The Netherlands
Phone: (+31) 46 4389444 poked at him in battle situations. Defensive in essence, not aggressive. One wonders what
Fax: (+31) 46 4370161 Arduino has to ward off as it is doing the opposite, I mean attracting, like a magnet, all
sorts of external hardware, I/O, and sensor activity in general? The cape, too, is a weird

Memberships: designation as I am challenged to associate any dog let alone its bone with a cape, be it
Please use London address referring to a sleeveless cloak or a promontory. And neither is that friendly looking doggie
E-mail: service@elektor.com in beaglebone.org’s logo ever seen wearing the garment, or high on a windswept rock
www.elektor.com/memberships
peering over the ‘vast waters — of the petrel and the porpoise’. Puzzling.
Shields, capes or hats come in a bewildering variety covering just about anything you’d
Advertising & Sponsoring:
want to do learn from, or inflict on, the real world (your I and O respectively). Check out
Johan Dijk
Phone: +31 6 15894245 the .org websites associated with each of The Three Platforms, and the .com sites of a
E-mail: johan.dijk@eimworld.com flood of board retailers and you’ll find that most, if not all, plug-on boards cost more than

www.elektor.com/advertising the computerette they sit on. Users seem to be happy with that simply because the hat/
Advertising rates and terms available on cape/shield is a fit-and-forget device that allows people to concentrate on what the sys-
request.
tem, rather than the MCU alone, is actually doing. Hats off to the meticulously designed
RPi Audio DAC on page 22.

Jan Buiting, Editor-in-Chief


Copyright Notice
The circuits described in this magazine are for domes-
tic and educational use only. All drawings, photographs,
printed circuit board layouts, programmed integrated
circuits, disks, CD-ROMs, DVDs, software carriers, and
article texts published in our books and magazines
(other than third-party advertisements) are copyright
Elektor International Media b.v. and may not be repro-
duced or transmitted in any form or by any means,
including photocopying, scanning and recording, in
The Circuit
whole or in part without prior written permission from Editor-in-Chief: Jan Buiting
the Publisher. Such written permission must also be
Deputy Editors: Thijs Beckers, Clemens Valens
obtained before any part of this publication is stored
Translators: David Ashton, Jan Buiting, Martin Cooke,
in a retrieval system of any nature. Patent protection
may exist in respect of circuits, devices, components Ken Cox, Arthur deBeun, Andrew Emmerson,
etc. described in this magazine. The Publisher does Tony Marsden, Mark Owen, Julian Rivers
not accept responsibility for failing to identify such Membership Manager: Raoul Morreau
patent(s) or other protection. The Publisher disclaims
International Editorial Staff: Thijs Beckers, Mariline Thiebaut-Brodier
any responsibility for the safe and proper function
of reader-assembled projects based upon or from Denis Meyer, Jens Nickel
schematics, descriptions or information published in or Laboratory Staff: Ton Giesberts, Luc Lemmens,
in relation with Elektor magazine. Clemens Valens, Jan Visser
Graphic Design & Prepress: Giel Dols
© Elektor International Media b.v. 2017
Publisher: Don Akkermans
www.eimworld.com
Printed in the Netherlands

www.elektormagazine.com July & August 2017 3


This Edition
Volume 43 – Edition 4/2017
No. 484 July & August 2017

Regulars
13 Elektor Connexions
59 Homelab Helicopter

22
68 Err-lectronics
Corrections, Updates and Feedback to
published articles

79 Elektor Labs Pipeline


85 Q & A

70
Components in Space

100 Retronics: Tektronix 556 and 565 Dual-


beam Oscilloscopes
FPGA-DSP Board for
The Triple-L beasts: large, loud, lumpy Narrowband SDR
107 Tips & Tricks A fully programmable receiver/
Test Pattern Generator using a Digital
Camera
transmitter baseboard
Presented here is an FPGA-based digital signal processing board
117 Peculiar Parts, the series
featuring everything necessary to do baseband processing of
Mercury Coulometers
traditional narrowband modes like SSB/CW and AM. It solves many of
126 Elektor Ethics the issues and limitations seen in simpler SDR platforms. Capable of
Smart Devices transmitting as well as receiving, it provides a perfect foundation for a
shortwave and/or VHF/UHF/SHF/microwave
128 Elektor Store transceiver, ideal for scientific,
130 Zenerdoku (an extraordinary Hexadoku) ham, and other serious radio
applications.

Features
6 PCB Design is Not Easy
The art of laying traces

44 PCBs — Printed, not Etched


Presenting the Voltera V-One PCB printer
and reflow soldering station

44
94 Electronics in Orbit 18 RF Step Attenuator
Space science for all of us Adjustable attenuation gives precise signal
levels
99 “May I have the menu, please?”
22 Audio DAC for Raspberry Pi
A network audio player with Volumio

30 BBC micro:bit for Electronicists (2)

Projects
Data acquisition and oscilloscope functions

35 Sea Murmur Simulator


Gentle noise to help you go to sleep

14 2-Terminal Dimmer 38 The I2C Bus


controls LEDs, lamps and heaters Part 2: using the bus with a microcontroller

4 July & August 2017 www.elektormagazine.com


Audio DAC
magazine

88 The ESP8266’s Big Brother

for Raspberry Pi
Getting started with ESP32 and the Arduino
IDE

104 Sniffer using RFM12 Radio Module


spy on the ether

A network audio player 108 Sensors Make Sense (4)


For Arduino and more

with Volumio 114 Keep Cool with an ATtiny


Temperature-dependent fan control

118 Ukele-LED
Serially addressable LEDs as ukulele

88
learning tool

The ESP8266’s 122 Making Lights Meaningful


For all model aircraft
Big Brother
Getting started with ESP32 and the
Arduino IDE
The ESP8266 from Espressif has made waves in

Next Editions
the maker community with its low price: you can
get one from AliExpress for just two or three
euros/dollars/pounds. Its big brother, the
ESP32, is the result of Espressif’s efforts to
make their WLAN SoCs fit for the future. Elektor Magazine 5 / 2017
Along with a dual-core processor, it Tangible Prototypes for Tabula • LoRa with ST Boards •
has onboard Bluetooth, more RAM, CPLD Board as DIL Component • FFT Scopes in Practice
and IO extensions. In this article
• ESP32 with IDF • Datalogger for Heating Systems •RPi
we talk about programming the
Zero W Review • Function Generators • Flexible IoT sen-
ESP32 with the Arduino IDE. In
sor interface with GoNotify • Scoreboard with 7-segment
the next issue of Elektor we will
turn our attention to the native Displays • 12-V LED Driver • Ultrasonic Sound Generator
development tool IDF. • Universal I2C Bus Isolator and Level Adapter • Temi
Temperature & Humidity Sensor • Spy Camera Detector
• and much more.
Elektor Magazine edition 5 / 2017 covering September & October is
published on 15 August 2017. Delivery of printed copies to Elektor
Gold Members is subject to transport.
Contents and article titles subject to change.

Presenting the
Voltera V-One 48 nWatch, a Wearable Development
System Elektor Business Magazine 4 / 2017
PCB printer
or how to build your own smart watch Focus on: LEDs, Displays & Drivers
and reflow
soldering station AS7221 Spectral Tuning IoT Smart Lighting Manager
62 Get 5 V from One Exhausted Alkaline Cell (ams) • Smart City Transformation (Schréder) • GP-
Juice it to the Max! LV-32D Driver Series (GlacialPower) • Lighting Audit,
70 FPGA-DSP Board for Narrowband SDR Spectrum Mixer (GL Spectrosoft) •MiP-Displays in Me-
A fully programmable receiver/transmitter dical Applications (Sharp Devices Europe) • High-power
baseboard Colour and White LED Emitters (LED Engin) •Lights for
the ‘Oasis’ Rinspeed concept car (OSRAM) • and more.
80 MicroPython and the pyboard
From blinking LED to … webserver blinking Elektor Business Magazine edition 4/2017 is published on 15 July
an LED 2017. Contents and article titles subject to change.

www.elektormagazine.com July & August 2017 5


PCB Design is Not Easy
The art of laying traces
By Clemens Valens (Elektor Labs) Glossary further on in this article to better understand the
text. Also, even though this article is quite long, it is far from
complete. PCB design is simply too vast a subject to be treated
Even if such a naive approach may work for simple, low-power comprehensively in one article.
and low-frequency circuits, it is wrong. Simple circuits need
good PCBs too. Good PCBs not only make a circuit work reliably System integration
and as intended, they also limit EMC problems as much as pos- The first step — skipped by most people — involves studying
sible, they provide test points for system assembly and repair, how the board is supposed to be integrated into the system.
and they are easy to fit in the final application. Because that is What shape should the board have? Where should the mount-
what a circuit board really is, a component in a system, and as ing holes be? How many? And the cables and wires to and from
such it has to be as good as any other component used in that the board? Where do they come from, where do they go? Are
system. A PCB design isn’t intended to please its designer; it there any height limitations? Possible heating issues? How is
must please the end user, whoever that may be (Figure 1). the user going to interact with the board? Will there be plug-
In what follows, acronyms and jargon are used. Refer to the gable cables? On the rear or on the front, on the side maybe?

6 July & August 2017 www.elektormagazine.com


To many people, designing a printed circuit board (PCB) is a mere detail or
afterthought. The circuit has been tested thoroughly and then, without thinking
about it too much, they plunk it onto a board to make it easier to move around
without wires coming loose or components dropping off. How wrong they are…

Rotary encoder or pushbuttons? Display? LEDs? Are there pos-


sible issues with the material the enclosure is made of? Oh
yes — another afterthought — what about the power supply?
Even if the system consists merely of your circuit mounted
in an enclosure, then, before you set out designing a PCB for
the circuit, choose a suitable enclosure and adapt the PCB’s
size and shape to it.
Unless you have excellent metal, wood and plastic working
skills, or have access to CNC and laser cutting equipment, try
to limit the mechanical work to a minimum.
Figure 1. Your board may be built in a factory like this, somewhere far
Board manufacturing away in your perception. Therefore, for the best chances of success,
Another important question is: how is the board going to be design it in such a way that it can be done with as little explaining as
made? Are you planning on etching it yourself at home? Are you possible.

www.elektormagazine.com July & August 2017 7


any good at it? If not, you may want to avoid vias, and stick to
one layer. Double-sided boards require excellent alignment of
the top and bottom films, and metalizing vias can be a lot of
work, especially when there are a lot. Having said that, many
home etchers achieve great results with double-sided boards;
it is mostly a matter of skill and experience.
You may want to stay away from ground and other copper
pours (planes) since you don’t have a solder mask to avoid
solder bridges. Finding and cutting almost invisible shorts is
an unpleasant job as well. Maybe use thicker traces to prevent
them from getting eaten away by the etching fluid? To avoid
copper bridges, don’t place traces too close to each other. Use
larger pads because you’re not so good at drilling (Figure 2)?
A PCB engraving machine has similar requirements but, unless
Figure 2. A home etched panel with many holes left to drill, and panel you are a very good home etcher, it has higher precision. The
cutting still to be done. Is it really worth it to do this yourself? trace density can be higher, but not too high either. If the mill-

A Small Glossary of PCB Design

Auto-router: Holy Grail of PCB design software Millimeter: one thousandth of a meter solder migrating away from the pad which
developers Net: a desired connection between two or more may result in bad solder joints or pulling an
Bottom: the lowest layer of the board stack, pins SMD device out of alignment.
also still commonly known as solder side OAR: outer annular ring SMD: surface-mount device, a device using SMT
Class: resolution or density of a PCB; the higher Pad: PCB element for connecting a pin SMT: surface-mount technology, for parts with
the class, the smaller PCB elements and PCB: printed circuit board terminals that are not to be inserted in holes
clearances are allowed to be PCB element: object printed on a layer, includes Stack: neat pile of layers
Clearance: distance between two or more PCB the board outline Stencil: mask to apply solder paste on a PCB
elements Pin: connection point of a component like a Terminal: see Pin
DRC: design rule check, to verify that PCB pad, pin, lead, etc. THT: through-hole technology, for parts with
elements respect a set of required design Plane: large copper area; called power plane terminals that are to be inserted in holes
parameters like minimal trace width, when connected to ground or a supply Tombstoning: the partial or complete lifting of
minimal drill size, minimum clearance voltage two-terminal SMT components during reflow
between pads, etc. Plated: covered with a conducting material Top: the highest layer of the board stack, also
ERC: electrical rule check, to verify that nets are Pour (copper): see Plane known as component side
connected, not overlapping, no shorts exist Push and shove: routing a trace by pushing Trace: a connection between two or more pins
due to copper pours, etc. and shoving PCB elements surrounding the on a PCB
Excellon: data format for CNC drill and route trace to create enough clearance for the Track: see Trace
machines new trace Via: metalized hole connecting traces on two or
Fiducial: special mark on a film, mask, board, Ratsnest, rat’s nest: a visual representation of more different layers
panel, etc., to help aligning them with all unconnected nets Via stitching: the use of many vias to connect
cameras, stencils, machines, each other, etc. Resist: protected against solder(ing), see Solder a copper element on one layer to another
Gerber: ASCII vector data format for two- mask element on another layer; often used for
dimensional, two-color images Routing: transforming nets into traces. conducting heat or on high-frequency
Heat relief: pad-copper (plane or trace) Silk screen: a non-conducting layer of graphic boards
connection preventing solder heat from symbols and text, usually white, also known
being absorbed by the copper as component print
IAR: inner annular ring Short: an undesired connection between two or
Layer: surface carrying PCB elements like more pins
traces, pours and components Solder mask: mask with openings where
Metalized: see Plated solder(ing) is allowed. A solder mask not
Mil: one thousandth of an inch only prevents short circuits, it also avoids

8 July & August 2017 www.elektormagazine.com


ing is too deep, traces may disappear. If on the other hand the
milling is not deep enough, shortcuts may appear. If the board
is not flat, both problems may occur simultaneously. Another
thing to keep in mind is that contrary to etching, milling leaves
the unused copper on the board. This makes soldering harder
(again, no solder mask) but can also create dangerous situ-
ations with circuits that connect to high voltages like the AC
line grid because the clearances between traces are no longer
respected. This can also pose problems in circuits with high-im-
pedance inputs. It is possible to mill away the unused copper,
but it will take much longer to fabricate the board.
You can manually mill a board with a Dremel-ish tool or suitable
milling bits like those ball-shaped drill bits you may have seen
your dentist use. Like him/her, practice and skill are required
to obtain painless results. Figure 3. To provide proper decoupling for ICs with many pins, the
Then there is, of course, the professional route. Pooling ser- decoupling capacitors can be placed on the other side of the board. Note
vices that combine your design together with designs from how the component designators are placed outside the densely populated
other customers on one supersize board are widely available area in an intuitive way.
on the Internet. Prices and delivery terms vary wildly so it’s
wise to compare several providers. The costs depend mainly
on board surface, number of layers, board class and produc- Humidity and/or dust may pollute the board, requiring larger
tion delay, and adding options will make it more expensive. clearances around traces and components to avoid shortcuts
Some services allow you to take options away, others don’t and leaks. This all is closely related to any norms and stan-
and you may end up with features that you don’t need. Pool- dards your board may be required to meet. Even though this
ing services in places remote to you may seem attractive but may seem a non-issue for most DIY boards, there are good
shipping delays are not always respected and packages may reasons why these standards exist, and reading up on them
get lost. Some services offer a price per board including ship- might actually teach you a thing or two.
ping, others charge setup and/or tooling costs. Place THT components on the top side, also called the compo-
Usually there is no reason to try to make the PCB as small nent side. Place SMT parts all on the same side, top or bottom;
as possible. It may be cheaper to manufacture, but doing so avoid placing them on both board sides as it makes manufac-
makes the board more difficult to route, and more complicated turing more expensive. Again, even though this may not be
to integrate let alone repair. an issue for one-offs and small series, it is good practice to
A word on milling: sometimes non-circular milling is required to try to avoid SMDs on both sides where possible (Figure 3).
fit a part or to allow access to something. Unfortunately, mill- Boards that have SMT components on them need at least three
ing requires yet another tool, meaning that it usually increases fiducials as reference points for pick and place machines. Large
board costs. Some manufacturers do not add costs if the mill- ICs with many fine-pitched leads may require fiducials too to
ing tool bit is the same as the one used for the board outline. ensure correct alignment. DIY boards can, of course, do with-
Also, milling may not be possible as detailed and accurately as out fiducials, but why not try to make a habit of doing things
you would like, so, before milling away shapes, check with the the professional way? It doesn’t cost anything.
manufacturer to see what is possible and what is not. Orient all polarized components such as capacitors and diodes
in the same direction (unless signal integrity or other good
Component placement reasons forbid you to do so). It is a great time-saver during
Components should not be placed anywhere or anyway you board assembly, inspection and faultfinding. Always indicate
like, not even when the circuit allows you this virtual luxury. the polarity on the silkscreen.
For ease of installation, inspection and repair, components Beware of mirrored footprints.
should be arranged in rows and columns, and oriented uni-
formly. Although for one-offs to be assembled by you this Stay on the grid
seems unnecessary, by doing so your life may become a little Work on a grid for as long as possible. I like to place the com-
bit easier, as well as those of the people that assemble and ponents and do the initial routing on a 50 mil grid. When things
repair boards for a living. get too dense, I will switch to a 25 mil grid. When a dense
For electrical reasons components should — in general — be board is almost done I may switch to a 5-mil grid to squeeze
placed as close to each other as possible. Of course, there the last trace segments in. Occasionally a 1-mil grid may be
are many more criteria to take into account here, like current required to precisely position an element while respecting the
return paths, avoiding crosstalk and other unwanted induc- design rules (DRC). Mils, mmm, it doesn’t really matter which
tive or capacitive couplings, etc. In short, it is important to unit you choose, as long as you stick to it.
carefully plan component placement. A power amplifier sim-
ply does not have the same requirements as a high-precision Pads
measurement device. Component leads and terminals are soldered to pads on the
However, the soldering technique used to mount the compo- PCB. For many parts the pads not only provide the electrical
nents may impose yet another set of constraints. The envi- connection, they double as the mechanical mounting points for
ronment too can have an impact on component placement. the part. It is therefore important that the pad is large enough

www.elektormagazine.com July & August 2017 9


Figure 4. A selection of THT pads available in the popular Eagle PCB Figure 5. Tapered pads in Eagle, created with the teardrop script (ULP).
design tool.

for this. Especially high or heavy parts with few terminals (e.g. space required to meet clearance rules.
large capacitors) need big pads to prevent them from acciden- Teardrop-shaped and tapered pads — where the pad gradu-
tally being ripped off . The copper is glued to the board, and, ally merges into the connecting trace — exist too (Figure 5).
especially when heated up (by soldering or current) delami- Besides giving a slight retro touch to the board, they do provide
nation is a possible risk. stronger pad-trace connections. This is important for boards
SMD parts usually have oblong shaped pads. Lead-free sol- that have to be able to bend, like flexible PCBs. Not all PCB
der doesn’t flow as well as traditional 60/40 solder, especially design tools can do this.
in the corners, which is why people have started to use pads Then there is heat relief (Figure 6). When a component lead
with rounded corners. SMD pads must be large enough to hold must be soldered to a very thick trace or a copper pour, the
enough solder paste to correctly solder a terminal. Refer to copper surrounding the pad may absorb the heat, making sol-
the component’s datasheet for the footprint or landing pat- dering difficult. To avoid the heat flowing away, pads can be
tern to use. connected with thin traces — so-called spokes or thermals,
THT pads can have all sorts of shapes (Figure 4). Square pads usually four — to the surrounding copper (this is where the
are often used to indicate pin 1 of a part, say, a connector. inner annular ring makes its appearance). When doing reflow
Octagonal pads are popular, but round is the best shape as it soldering (i.e. in an oven) this is less of a problem because the
maximizes the copper area (good for mechanical strength as whole board is heated up to the same temperature. Therefore,
well as heat dissipation) while simultaneously minimizing the there is usually no real reason to use heat-relief techniques

Automatic or manual routing?


CAD tool manufacturers and scientists spend and have spent
many, many, many hours on developing and improving automatic
routers and yet I have never been satisfied with the results of
a single one of them. I also have never met anyone who was.
One reason is probably that I have never had access to the
best tools available, but the ones that I did try either crashed
or gave up five minutes after I had left the office, never man-
aged to route 100% of the board, if they achieved 100% then
made me spend hours on cleaning it up, or were simply too
complicated to set up. Because of all these reasons I prefer to
route manually. (Also, I find routing a very relaxing activity.)
The automatic router often manages to route up to 90% of the
board or better, but hardly ever achieves 100% unless the cir-
cuit is very simple. When it gets stuck before reaching 100%
this usually means that there really is no solution left to finish
the board. That doesn’t imply that the board can’t be routed,
it just means that the autorouter has blocked all possible solu-
tions. To get out of this hole you have to undo so much that in
the end it would have been quicker to have routed the board
manually from the start.
As a kind of compromise, some people use the autorouter to see The Eremex TopoR ‘topological router’ lacks preferred routing
where routing problems may pop up, then move some compo- directions to optimize space usage. (Source: Eremex)
nents to hopefully solve these potential bottlenecks and finally
route manually. Others use the auto-router only on (trivial)
parts of the board and then clean up afterwards.

10 July & August 2017 www.elektormagazine.com


on pads for SMT parts that are to be soldered in an oven.
However, tombstoning — the partial or complete lifting of an
SMT component during reflow — may occur when the thermal
mass is very different on both sides of a small two-terminal
device like a resistor or capacitor. Heat-relief can bypass this
problem. Vias hardly ever need heat relief because, in general,
they are not soldered.

Holes
Pads often have holes in them — vias have holes too. Mount-
ing holes can be non-plated; holes in pads and vias are plated.
You specify the plated-hole diameter for your vias and pads; it
is the job of the PCB manufacturer to ensure that the finished
hole matches this diameter. For a plated hole the actual drill
size must be larger than specified because the plating material
needs space. Drilling has limited accuracy and a hole may be
drilled off-center (Figure 7). Therefore, to ensure that enough
copper remains around a plated hole after drilling and etch-
ing the board, the ‘outer annular ring’ (OAR) should be wide
enough. Inner annular rings (IAR) exist too. According to my
Figure 6. Heat relief prevents too much heat flowing away into the large
dictionary, ‘annular’ means ‘shaped like a ring’, so, technically
copper pour during soldering. Here the minimum inner annular ring (IAR)
speaking, annular rings are “ring rings” (which reminds me may be specified even though it is much the same as the OAR. The red
of this great Abba song from 1973 of which I highly recom- ring represents the plating of the hole.
mend the video on YouTube. They don’t make music like that
anymore…, nor apparel, Swenglish, guitars, hairdos, etc., but
I digress.) parallel” are often used to improve current conduction, while
A common mistake is to specify the wrong drill size for a com- limiting the risk of open circuits due to a broken via. However,
ponent lead — either too large or too small. one large via can be used too.
There is an issue related to vias and wave soldering: if a via is Naming nets is helpful during routing as they remind you of
unmasked, solder may flow up through it and potentially dam- the signal you are working with.
age a component mounted over it. Closing the solder mask for Then, corners! Rounded traces are best because, contrary to
vias will usually prevent this. angled traces, they have constant width. Changes in trace
width cause impedance mismatches and reflections, but only
Traces and planes at very high frequencies so most circuits are not affected by
Keep traces as short as possible; you knew that, of course. This
is especially true for high-frequency signals, but low-frequency
and even DC signals benefit from short traces too. Not only
are short traces good for signals, they also save board space.
Some fast signals may require traces (or a pair of traces) of an
exact length (and impedance) which is not always the shortest
connection possible.
Do not use the thinnest pen from your PCB design tools. Thin
traces may cost more and are fragile. The finest detail on the
board determines the board’s manufacturing class; the higher
the class, the more expensive the board. Vibrations can cause
micro cracks in thin traces resulting in bad or even broken con-
nections. If the board has to be soldered by hand, or if rework
is to be expected, thin traces may easily delaminate when too
much heat is applied for too long. Home etching usually is not
well-controlled and thin traces may get eaten away. Further-
more, a thin trace may not be capable of carrying the current
that you had in mind for it. Adapt the trace width to the current
that has to flow through the trace, the extra width is needed
to keep the trace cool. Many online calculators are available to
help you determine the best width for your trace. A thin trace
carrying too much current will heat up and may eventually
Figure 7. Due to manufacturing tolerances a hole may be drilled off-
melt or crack; it is the heat that limits the current. Vias also center. To allow for plating (the red ring) the hole must be drilled larger
must support the current. Covering traces with a thick layer than specified. The finished hole (with plating) will have the diameter you
of solder will increase the maximum current a trace can carry. specified. The ring that remains after drilling is the annular ring (AR). The
Similarly, filling a via with solder or copper helps too. Providing minimum acceptable outer annular ring (OAR) shown here is specified by
openings in the solder mask will be useful here. Multiple vias “in the design rules (DR).

www.elektormagazine.com July & August 2017 11


when you have another look at it six months later — may get
confused by them. If you must accept a warning, document
the reason why. If possible change the design rule that gives
you trouble to make it go away, but make sure the new rule
is acceptable for your application as well as for your board
manufacturer.

Markings and component print


Try to provide designators for all component outlines and make
sure they remain visible after the components are mounted.
I like to orient designators the same way as the components,
in rows and columns (see also Figure 3). Do indicate pin 1 on
all connectors, headers, and any other component where pin 1
is not readily identifiable. Also clearly mark the polarity of all
polarized components such as capacitors and diodes (Figure 8).
Figure 8. No component designators, only one pin-1 marking, traces with Avoid print under SMT parts, especially two-terminal ones, as
all kind of angles and teardrop vias. Once you know what you are doing it this makes their “seat” wobbly and may result in tombstoning.
is common practice to be liberal about good practice. Keep text legible and use labels where useful to guide the user.
Note that the openings in the solder mask are usually slightly
larger than the pads, and any silkscreen print crossing these
these problems. Right angles are considered ugly, yet you will openings is cut away so make sure text does not overlap them.
find many when you look closely at the vias on a board. Often Put legible text on all layers to prevent accidental mirroring
a trace on one layer continues at a 90° angle on another layer, of a layer. Label or number layers to ensure that they will be
and even if it doesn’t, the via itself introduces two 90° angles. stacked in the right order.
Traces with 90° angles tend to be longer than those that use Give the board a unique name or number and don’t forget to
45° angles. Sharp corners may also introduce delamination mark its revision.
problems, acid pockets, or on the other hand, under etching. If the board’s bottom side can have print too, use it.
Sometimes it is impossible to avoid a sharp edge and in most DIY boards in general do not have a silkscreen, but that doesn’t
cases that is fine. Personally I tend to stick to 45° angles mean that you should forget about text and polarity markings;
whenever I can. you can write on the copper layers too. So, where possible place
Using a power plane or copper pours (usual for GND) can save marks and text while keeping an eye on their size to avoid that
a lot of work and is good from an EMC perspective. However, they will be lost during etching.
be careful when using multiple supply planes, especially close
to board edges and mounting holes where metal objects and Testing
fixing screws may create unintended short-circuits between Provide easily accessible test points. If possible make the cir-
planes. Always run an electrical rules check (ERC) when done cuit produce useful test signals. Component terminals should
to ensure that all short and open circuits have been corrected. not be used as test pads as a test probe pushed against a ter-
When you use a plane or pour for a net, do not route that net minal may temporarily “repair” a bad solder joint, feigning a
but let the copper pour take care of it. Beware of very thin, “good” connection that’s bad most times. Vias can be useful for
sort of accidental, connections between plane segments that testing, but only when they were left open in the solder mask.
may get etched away and break the continuity of the plane.
Such planes are unsuited for home etching. To prevent this Is that all?
from happening, start with a high copper pour clearance and After reading this long article you may think that you know
see if the copper flows everywhere. Move traces and vias to a lot about designing PCBs, but in reality we only scratched
improve copper flow. When you are satisfied with the pour you the surface. We did not discuss, to name a few, current return
may decrease the clearance. paths, multiple ground planes, heat management during sol-
Note that planes have an influence on the copper distribution dering and heat management when operating, EMC compli-
of the board. When the copper is unevenly distributed etching ance, handling high-speed signals, designing footprints, etc.
may become uneven, and can result in uneven copper thick- PCB design is a vast theme combining chemistry, physics,
ness distribution making the PCB bend at extreme tempera- electronics, mechanics and automation. It is rather amazing
tures (as in automotive applications). to discover that many aspects of PCB design never really have
been studied in detail and are simply based on common sense
Use design rules and assumptions. On the Internet you can find many discus-
Use the design rules checks (DRCs) and electrical rules checks sions on PCB design details, so, when in doubt, ask around.
(ERC) to make sure all PCB elements respect them. Good design
rules will help avoid traces from overlapping or coming too close Thanks to Malte Fischer for his useful suggestions.
to the board’s edge, help you find illegal drill sizes and clear- (160397)
ances and much more. Use them! Also make sure that when
Web Link
you think the board is ready, all nets are connected indeed. Do
not leave warnings and errors even if they are acceptable for [1] www.elektormagazine.com/160397
you because the person that inherits the design — or yourself

12 July & August 2017 www.elektormagazine.com


LABS PROJECT

2-Terminal Dimmer
controls LEDs, lamps and heaters

Features
• Two flavors: AC or DC
By Michael A. Shustov (Russia) • Does not require extra wire
and Andrey M. Shustov (Germany) • Does not require Arduino

In the past, rheostats (today also called potentiometers) were connected in series with a load to control the
current flowing through the load. Although simple, this technique has some disadvantages.

First of all, the current can only be con- lamps and LEDs), or to control the speed
R
trolled when the load is active. Secondly, of a motor.
the heating of the rheostat results in sig- Dimmers controlling the intensity of LED LED

nificant losses. Furthermore, controlling light sources are usually connected in


the intensity of a light flux emitted by parallel with the power supply; they are
E DIMMER
light-emitting diodes (LEDs) with a rheo- three-terminal devices. Two terminals
stat is almost impossible owing to the connect to the power supply while the
nonlinear current-voltage characteristics third connects to the load. Such dimmers
of LEDs. Pulsewidth modulation (PWM) is
a better and much more efficient way to
smoothly change the intensity of heat- Figure 1. The dimmer is in series with the
copyright
ing and lighting devices (incandescent LED(s) and requires only two wires.

14 July & August 2017 www.elektormagazine.com


MAX MIN
LED1
project information
P1 R2 R4
LED
330R 560R K1
47k 2 lighting PWM dimmer
R1 lin. S–
D3 Danger! 555
1
1k8
C2
S+

D1 D2 4u7 SWITCH entry level


BZXC79C3V6

K2
Æ intermediate level
1N4148 1N4148
2
expert level
L–
4 8
RES VCC 1
6 T1 L+
THR

7
IC1
3
R3
LED
2 hours approx.
DIS OUT 2k2
2 LMC555
TRIG RFP12N10L K3
CV GND 2 V+

C1
5
C3
1 Soldering iron,
1
V– common sense
2n2 1n
VDC
160380 - 11

copyright
£12 / €15 / $17 approx.

Figure 2. The DC version of the series dimmer.

cannot be used in place of conventional imately 6 kHz, i.e. way too fast for the AC Line-powered dimmer
double-pole switches, since they require human eye to notice. The pulse/pause It is, of course, possible to adapt the
an additional third power wire for proper ratio or duty cycle is adjusted with poten- dimmer for use with an AC power supply
connection. To overcome this problem tiometer P1; the minimum and maximum like the 230 VAC line voltage available in
we propose a two-terminal dimmer con- values for the pulse width are determined households in many countries all over the
nected in series with the load (LED, lamp by resistors R1 and R2. world (115 VAC will work too.) To achieve
or a heating element) instead of a switch, this feat two hurdles have to be taken:
see Figure 1. Contrary to a switch, the Up to here the dimmer is a standard
dimmer allows adjusting the load cur- three-terminal shunt regulator. The trick • Finding a suitable power transis-
rent from almost 0 to about 97% of its to get rid of one terminal is to use the tor capable of handling such high
maximum value. The dimmer is powered load’s supply to power the circuit. This is voltages;
through the load when its switching ele- achieved by charging C2 through R4 and • converting the AC voltage to a DC
ment is disconnected and the current LED1 when T1 is not conducting. Zener voltage.
through the load is minimal. diode D3 limits the voltage to 3.6 volts.
An inconvenience of both two-termi- LED1 serves as a power-on indicator and The second point requires some atten-
nal and three-terminal dimmers is their also makes it easier to find the dimmer tion. Simply rectifying the AC line volt-
residual current consumption, but it is in the dark. age is not good enough, as heavy loads
insignificant compared to the current Transistor T1 can withstand up to 100 V like incandescent light bulbs will flicker,
when the load is powered. and conduct 12 A, but not at the same making filtering mandatory. Furthermore,
The dimmers described below can be time (the PCB only handles up to about the rectified line voltage is about 325 V
used with household lighting devices, 2.5 A anyway). According to its data- (163 V for 115 VAC line voltage), which
thermostats, and for instance back-up sheet it can dissipate up to 60 watts, is too high for standard household light
or secondary lighting. and it should be mounted on a suitable bulbs (several identical lower-voltage
heatsink when it has to handle more than light bulbs connected in series can be
Two-terminal DC-powered 1 watt. R4 determines the maximum sup- used, however). Because of these prac-
dimmer ply voltage, 20 V here. tical limitations, what follows is mainly
At the heart of the dimmer (see Fig- With the values given in the schematic to illustrate our point and is not recom-
ure 2) is the good old 555 timer IC in its we measured a quiescent current of mended for use in real life.
low-power CMOS guise called LMC555CN. 3.5 mA (i.e. when the duty cycle is 0%). Figure 3 shows the 230-VAC version of
It is wired as a pulse generator with vari- That’s enough current to make certain the dimmer. The most noticeable change
able duty cycle, a well-known circuit, LEDs light up noticeably. Reducing the is the addition of the rectifier (D4-D7)
nothing new under the sun. The output value of R2 to 75-100 ohms may improve and the supply filter made up with C4, C5
of IC1 drives power MOSFET T1 which the situation. In addition, increasing the and C6. We also added a skull & bones
in turn switches on and off the load (the value of R5 will reduce the minimal cur- symbol to make clear that potentially
LED) as dictated by the PWM signal. The rent too. A switch can be connected to lethal things are going on here.
PWM signal has a frequency of approx- K1 to completely turn off the dimmer. The filter capacitor is made with three

www.elektormagazine.com July & August 2017 15


MAX MIN
LED1
K1
P1 R2 R4 R5
2
330R 15k 15k L–
47k 2W 2W
R1 lin. 1
L+
D3
1k8
C2
LOAD
D1 D2 4u7
BZXC79C3V6

1N4148 1N4148 D4 D5
230VAC
4 8
VCC
1N4007 1N4007
RES
6 K2
THR T1
IC1 R3 1
7 3 C4 C5 C6 V
DIS OUT 100R
2 LMC555 2
TRIG 100u 100u 100u V
BU323Z 350V 350V 350V
CV GND
D6 D7
LINE
5 1
C1 C3

2n2 1n 1N4007 1N4007

160380 - 12
copyright

Figure 3. This dimmer circuit is dangerous and may kill you. Do not look at it too long.

separate devices because one big one capacitors is not critical when a heating up to 150 W (with a suitable heatsink!).
is difficult to find and rather expensive. element is used as a load. If you are tempted to replace this tran-
With three times 100 µF (350-V types Besides the clearly visible schematic sistor by something “sturdier”, keep in
minimum) and a 100-W light bulb the changes there are also a few more sub- mind that the rectifier diodes D4-D7 are
voltage ripple at the output will not tle changes. Transistor T1 for once is specified up to 1 A and 3 W.
exceed 3% (approx.). This is invisible now a BU323Z Darlington power tran-
to the human eye. For heavier loads sistor instead of a MOSFET. This tran- Let’s do some math
the values of C4-C6 must be increased; sistor is designed for 230-VAC inductive When using LEDs (just one or
for light loads they can be decreased. switching applications and has built-in a few in series) for
The capacity of these over-voltage protection. It can handle illumination

purposes, the resis-


tance of a current limiting
resistor R has to be calculated (Fig-
ure 1), and its power rating must be
determined.
The forward voltage U LED of an LED
depends on its color, see Table 1. We
can now estimate the resistor value with
the following equation:

USUP − n ×ULED −UT1


R= [Ω]
0.9 × ILED

Where USUP is the supply voltage, n is the


number of LEDs, UT1 the voltage dropped
by transistor T1, and ILED the maximum
current through the LED(s). Consult the
LED’s datasheet for the exact values of
ULED and ILED. The power rating for the
resistor can be calculated with

16 July & August 2017 www.elektormagazine.com


Table 1. Forward voltages
PR = (ILED )2 × R [W] related to the color of the light emitted by an LED.
Color Wavelength [nm] ULED [V]
Infrared ≥ 760 ≤ 1.6
Examples
Red 610 – 760 1.6 – 2.0
1. (Figure 2) Assume n = 1, ULED = 3 V,
ILED = 0.05 А, UT = 0.04 V, Orange 590 – 610 2.0 – 2.1
USUP = 20 V. Then R = 377 Ω, or, Yellow 570 – 590 2.1 – 2.2
rounded off to the nearest higher Green 500 – 570 2.2 – 2.5
standard value, 390 Ω. The resistor Blue 450 – 500 2.5 – 2.7
should be able to absorb (0.05)2 ×
Violet 400 – 450 2.7 – 3.1
390 = 0.975 W, or, rounded off to a
Ultraviolet ≤ 400 ≥ 3.1
common value, 1 W.
White – 3 – 3.7

2. (Figure 2) Assume ULED = 2 V,


ILED = 0.02 А, UT = 0.04 V,
USUP = 16 V. If we limit n × ULED to these numbers the current through by the use of the circuits presented in
80% of USUP, then n = 6. In this the LEDs becomes (USUP – n × ULED this article.
case R becomes 220 Ω, and its – UT) / 1500 = 0.041 A, mean- (160380)
power rating should be better than ing that T1 has to dissipate UT ×
88 mW (0.125 W would be a good ILED = 0.125 W. It should be able to Web Link
standard value). do this without a heatsink. [1] www.elektormagazine.com/160380

3. (Figure 3) Assume ULED = 2.5 V, Final words


ILED = 0.05 А, UT = 3 V, We can’t repeat it enough times: the cir-
USUP = 325 V. If we limit n × ULED cuit from Figure 3 is dangerous; it carries
to 80% of USUP, then n = 104 and lethal voltages and may kill you or some-
R = 1,378 Ω. The nearest stan- one else when used without having taken
dard value would be 1.5 kΩ. Its proper precautions first. Do not build this
from the store
power rating should be better than circuit. Do not use it either, even if you
ª160380-1
3.75 W. The required resistor can didn’t build it. The authors and Elektor
PCB for DC-version
be realized by connecting two 2 W, take no responsibility or liability, so far as
3 kΩ resistors in parallel. With legally possible, for any damages caused

component list

www.elektormagazine.com July & August 2017 17


HOMELAB PROJECT

RF Step Attenuator
Adjustable attenuation
gives precise signal levels
By Alfred Rosenkränzer (Germany)

When dealing with radio-frequency signals it often comes in handy to have an easy way to attenuate a signal
level in discrete steps. For example, you might want to reduce the output of an RF generator to a lower level
than the output control on the generator allows, and there are many other applications of attenuators in
the adjustment and repair of receivers and other radio equipment. Unfortunately professional attenuators
are rather pricey, but they do not contain any expensive electronics and so a DIY approach is an eminently
practical alternative.

Sometimes it is necessary to attenuate there is no real alternative to an exter- example, when testing the sensitivity or
an RF signal by a known amount. If the nal attenuator, which is normally sim- small-signal behavior of a receiver: just
signal comes from an RF source whose ply inserted into the RF output connec- insert the attenuator in the antenna lead
level cannot easily be adjusted, then tion. Such an arrangement is useful, for and increase the degree of attenuation

18 July & August 2017 www.elektormagazine.com


impedances of the circuit are the same, layout more convenient. When working
Features but the signal level is not). These are with RF a printed circuit board is prefer-
• Switched RF attenuator with six called a T-type attenuator and a pi-type able to hand wiring, as it ensures that all
stages, 0 dB to 31 dB attenuation attenuator. Each configuration consists stages can be made geometrically identi-
in 1 dB steps of three resistors (see Figure 2). For this cal and helps keep parasitic inductances
project I selected the pi-type attenua- and capacitances under control.
tor as it makes the printed circuit board Figure 3 shows the resulting circuit of a
to the point where reception starts to
fail or where whatever phenomenon is
being investigated, perhaps noise or AFC
artifacts, starts to raise its head. Many
other applications of attenuators will be
immediately obvious to any RF engineer.
The familiar names in test equipment
manufacture produce good-quality atten-
uators (see Figure 1) but unfortunately
at a price that not all experimenters
will be comfortable shelling out. But an
attenuator basically consists only of an
enclosure, connectors, switches and a
few resistors. With a little care it is per-
fectly possible to build a good attenuator
for the common frequency bands your-
self for a much more reasonable price.

Attenuator circuit
There are two different but equivalent cir-
cuit configurations used to attenuate sig-
nals while maintaining impedance match-
ing (in other words, the input and output Figure 1. Example of a VHF attenuator by HP, long since out of production.

www.elektormagazine.com July & August 2017 19


realized; however in practice the max-
imum attenuation is limited to about
10 dB, as beyond that parasitic effects
in the components, printed circuit board
copyright and switches (which are not specially
designed for RF applications) come into
play. The smallest degree of attenua-
tion used in the circuit is 1 dB, although
fractions of a decibel could of course be
Figure 2. T-type and pi-type attenuator networks. implemented.
If a switch is in its upper position, its
stage is bypassed and the signal is not
attenuated. In the lower position, the sig-
S1.A S1.B S2.A S2.B S3.A S3.B
nal passes through the attenuator stage.
TP1 R1 R7 R13
TP2 13R7 316R 261R The attenuation levels of the individual
R2 R8 R14 stages can be chosen independently, as
10R 12R1 26R1
R3 R4 R5 R6 R9 R10 R11 R12 R15 R16 R17 R18 the input and output impedances of all
the stages are the same. In my prototype
6810R

1000R

1000R

6810R

8250R

8250R

1470R

1470R
464R

464R

261R

261R
I built attenuators of 1 dB, 2 dB, 4 dB,
1 dB copyright 2 dB 4 dB 8 dB, 8 dB and 8 dB. Together these allow
RF attenuation in steps of 1 dB (about a
10 % reduction in amplitude) from 0 dB
S4.A S4.B S5.A S5.B S6.A S6.B
to 31 dB, which makes sense for the
R19 R25 R31 TP3
typical uses to which I put the device.
825R 825R 825R TP4 Other combinations are of course possi-
R20 R26 R32
56R2 56R2 56R2 ble: for example six 10 dB stages would
R21 R22 R23 R24 R27 R28 R29 R30 R33 R34 R35 R36 allow attenuation from 0 dB to 60 dB
3160R

3160R

3160R

3160R

3160R

3160R

in steps of 10 dB, or stages of 0.5 dB,


121R

121R

121R

121R

121R

121R

1 dB, 2 dB, 4 dB, 8 dB and 8 dB would


8 dB 8 dB 8 dB 160323 - 11 give attenuation from 0 dB to 23.5 dB
in steps of 0.5 dB.

Figure 3. Complete circuit of the six-stage attenuator.


Calculations
In order to calculate the required resis-
six-stage attenuator. It simply consists be realized accurately despite only using tances I used the AADE software, which
of six cascaded pi-type attenuator stages standard E-series values. In total, then, can be downloaded at [1]. The main
each of which can be optionally bypassed the circuit comprises six switches and (up use of this program is in creating more
using a double-pole switch. A point to note to) 6 × 3 × 2 = 36 resistors. complex designs such as filters, but it
is that each resistor in each pi network The desired attenuation of each stage is is perfectly capable of helping to design
has been replaced by a parallel combi- achieved by choosing appropriate values attenuators and saves a lot of tedious
nation of two resistors. This allows the for the resistors. In theory any attenu- calculation.
calculated ideal value of each resistor to ation between 0 dB and ∞ dB can be In the menu Design -> Attenuator Pad
first select the ‘pi’ topology and in the
next menu select the source impedance.
In principle any value might be used
component list here, but these days the conventional
values are 50 Ω for test equipment and
75 Ω for antennas and analog video sig-
nals. The printed circuit board is designed
for an impedance of 50 Ω. If required, the
S1 S2 S3 S4 S5 S6
trace widths and board thickness can be
E

R1 R7 R13 R19 R25 R31 modified for use in a 75 Ω environment.


T

R2 R8 R14 R20 R26 R32 Programs to help with this design can be
found on the Internet: if you are thinking
R10

R12
R15
R16
R17
R18
R21
R22
R23
R24
R27
R28
R29
R30
R33
R34
R35
R36
R11
R3
R4
R5
R6
R9

of making such modifications and under-


stand the issues involved, you may find
Figure 4. RF layout techniques are used on the attenuator the tool linked to at [2] worth a look.
circuit board. The desired attenuation value is entered
in the next menu and then the program
shows the circuit with the required resis-
tor values. Unfortunately the values

20 July & August 2017 www.elektormagazine.com


almost never coincide with E-series pre-
ferred values, and even if we allow our-
selves to use E96 values it is not always
possible to find a good solution. Instead
it is possible to come up with pairs of
resistors from the readily-available E24
series whose parallel combination hits
the computed ideal value sufficiently
closely, using either mental arithmetic,
a pocket calculator, an Excel spread-
sheet or a short program. An even eas-
ier approach is to use one of the online
Figure 5. The circuit board fitted in the Hammond enclosure.
tools that are available: these do all the
hard work and show possible combina-
tions along with the percentage error
in the result. A good choice is the tool
found at [3]. For this application errors
of up to 1 % are acceptable.
You might wonder why the circuit uses
parallel resistor combinations rather than
series combinations: the reason is that it
simplifies the design of the circuit board
and improves its RF performance.

It’s all down to the board


The board I laid out for this circuit is
Figure 6. The completed prototype. Figure 7. Screenshot showing the frequency
shown in Figure 4, and the design
response at minimum (0 dB) and maximum
files (in Eagle format) are available for (31 dB) attenuation.
free download from the Elektor web
page accompanying this article [4].
The switches are in the middle, and ing the circuit board should not pres- the Hammond enclosure and Figure 6
immediately below each are the six ent any special difficulties, although the rather handsome (even if I say
resistors corresponding to it. There are soldering 0603 SMD resistors calls so myself) completed prototype. And
three vias connecting the network to for good tweezers and a steady hand. it’s not just a pretty face: considering
the ground plane on the other side of After assembling the board it should the simplicity of the design its perfor-
the board. The trace widths, when used be thoroughly tested by enabling each mance is more than acceptable. Fig-
with an FR4 substrate 1.0 mm thick attenuation stage individually in turn ure 7 shows the frequency response
(this dimension is important!), are cho- (with the other five switches set bypass at attenuations of 0 dB and 31 dB: as
sen to yield a characteristic impedance their stages) and then measuring the can be seen, the attenuator performs
of 50 Ω. The resistors are intended to input and output impedances of the well up to around 200 MHz.
be 0603 SMD types, but their pads are unit as a whole. When measuring the (160323)
sufficiently large that it is easy to fit impedance at one port it is of course
Internet Links
0805 components instead. The power necessary to terminate the other port
handling capability of the attenuator in 50 Ω (for example, using two 100 Ω [1] http://w1hue.org/filter.html
depends directly on the power rating resistors in parallel). If the measured [2] www.eeweb.com/toolbox/
of the resistors used: the design is not impedance is within 1 % of 50 Ω, then microstrip-impedance
intended for use in high-power appli- you can be fairly sure that you have [3] www.qsl.net/in3otd/parallr.html
cations, and it is best to keep power not accidentally got two resistors the
[4] www.elektormagazine.com/160323
levels to below 100 mW. The layout wrong way around. The final test is to
also includes, above the main circuitry, make sure that the attenuation intro-
a test structure and provision for two duced by each stage is correct. This
SMA connectors to allow measurement can be done at DC: use a power sup-
of the characteristic impedance of a ply (at no more than 5 V) and a 50 Ω About the Author
trace. The connectors are optional and series resistor to feed the input of the
Alfred Rosenkränzer has worked for
only required for this measurement. device and terminate the output with
over 30 years as a design engineer,
The board is designed to fit neatly into 50 Ω. Measuring the ratio between the
initially in the field of professional
a Hammond cast aluminum enclosure voltage at the input terminals of the
television equipment. Since the end
(see the component list). Input and device and the voltage at the output
of the 1990s he has worked on high-
output are on RF sockets: BNC con- terminals of the device will give the
speed digital and analog circuits for
nectors are conventionally used in actual attenuation.
IC testing.
test equipment applications. Populat- Figure 5 shows the board fitted in

www.elektormagazine.com July & August 2017 21


LABS PROJECT

Audio DAC for Raspberry Pi


A network audio player with Volumio

By Ton Giesberts Small single-board computers like the


(Elektor Labs) Raspberry Pi are ideal for use as small
stand-alone network audio
players.

With Volumio and


other specialized Linux
distributions, putting together
an audio player is remarkably
easy. And as Elektor staff member Ton
Giesberts shows in this article, you can also us
this approach to build a high-end audio player.

If you are looking for a small stand-alone project for this, we might as well design package, and it has outstanding specs in
network audio player, preferably with a a good high-end DAC for the RPi using all respects, including a dynamic range
touchscreen user interface, you don’t components with top-notch specs. of 127 dB (2 V RMS, stereo) to 132 dB
have a lot of options. Usually you end up (9 VRMS, mono), a THD of 0.0004%, and
with a largish amplifier from one of the The project at a glance differential current outputs (7.8 mApp).
big brand names, with a corresponding Digital to analog converter (DAC) ICs The PCM1794A accepts all known data
price tag. And most of them do not from Burr Brown (now part of Texas formats: standard, left justified, and I2S
have a touchscreen. If what you want is Instruments) have always been (and (which is important for our project). The
something compact and portable, these still are) about the best you can buy, digital portion of the IC operates at 3.3 V,
devices do not fit the profile. and we have used them previously in but the digital inputs are also compatible
That means your only real option is various high-end DAC projects. For this with 5 V signals. For a complete overview
to make your own. Apps based on the project we opted for one of the top of of the specifications, see the device data
Raspberry Pi are a good starting point, the line devices from Burr Brown: the sheet [1].
and DACs with fairly good specs are now PCM1794A. This is a 24-bit DAC which In order to convert the differential current
available for the RPi platform. However, can handle sampling rates up to 200 kHz outputs into single-ended voltages, we
at Elektor we are not satisfied with “fairly and has an integrated 8× oversampling need a current to voltage converter for
good” – if we are going to develop a filter. This IC comes in a 28-pin SSOP each channel, followed by a combined

22 July & August 2017 www.elektormagazine.com


filter and gain stage that converts the converters and analog output filters,
differential voltage output into a single- we use an on-board inverting voltage project information
ended voltage output. regulator to derive it from the +5 V rail. audio
Based on this knowledge, we can draw If you take a closer look at the circuit
network player DAC
the block diagram shown in Figure 1. diagram, you can see that the analog
Raspberry Pi touchscreen
From that we can derive the following supply voltage is actually +5.2 V
shopping list: on the hardware side a instead of +5 V. We intentionally chose entry level
Raspberry Pi 3 (version 2 is also usable) this somewhat higher voltage, which is
Æ intermediate level
and the previously mentioned audio DAC, still within the safe range for the DAC
expert level
along with a Waveshare 3.5” touchscreen IC, to ensure a maximum undistorted
display for the Raspberry Pi to provide signal level of 1 V from the output filter.
the user interface, and on the software You often see an output voltage of 2 V,
5 hours approx.
side Raspbian for the RPi, Volumio or but for that you have to use rail-to-rail
something similar (such as Mood Player), opamps or a higher supply voltage, and
and the driver for the Waveshare display. most rail-to-rail opamps cannot match
Raspberry Pi 2 or 3, com-
the outstanding specifications of special
puter with Putty (Windows)
Power supply considerations high-end audio opamps.
or Linux, two AC adapters
The digital to analog converter IC1 We chose a TPS7A4700 ultra low-noise,
(see the detailed schematic diagram low-dropout voltage regulator to provide
in Figure 2) needs two different the +5.2 V main supply voltage. It can
€110 / £95 / $120 approx.
supply voltages: +3.3 V for the digital supply a maximum current of 1 A with a
por tion and +5 V for the analog voltage drop of just 307 mV. The output

derived from the +5.2 V supply voltage


by a TPS7A4901 ultra low-noise linear
I/V Stage
DATA
L voltage regulator (IC7). The exact value
Analog Out
LRCK Differential to of the output voltage is set by the voltage
RPi3 PCM1794A Single Ended
BCK
/Filter divider R28/R29:
SCK R
Analog Out
I/V Stage ⎛ R28 ⎞
Vout = ⎜ +1⎟ ×1.185V
⎝ R29 ⎠
PLL
fx6
+5V2
DAC For the +3.3 V supply voltage we use
+3V3
+7...12VDC Power the same type of linear voltage regulator
Supply (IC9), with the output voltage set by the
+4V74 I/V Stage
& voltage divider R32/R33.
- 4V81 Output Filter
copyright The negative supply voltage is provided
by an LM27761 low-noise inverting
voltage regulator (IC8). It uses switched
Figure 1. Block diagram of the audio DAC. capacitors to invert the input voltage,
followed by a low-noise linear regulator
which generates a stable output voltage
portion. In theory we could use the voltage can be set by grounding specific from the inverted input voltage. This
supply voltages available on the GPIO pins which are connected to internal output voltage is set to –4.81 V by the
expansion connector of the Raspberry resistors. Each pin has an associated voltage divider R30/R31:
Pi board, but they are so noisy that voltage, and the output voltage is
there would be nothing left of our high- equal to the sum of the voltages of the ⎛ R30 ⎞
Vout = − ⎜ +1⎟ ×1.22V
end aspirations. That means we have individual pins. The minimum output ⎝ R31 ⎠
to provide an independent source of voltage is the same as the reference
+3.3 V and +5 V. Of course, it would voltage of 1.4 V. To obtain an output
also be possible to power the Raspberry voltage of +5.2 V, we tie pins 6, 10 and We intentionally chose these “odd”
Pi from the DAC board, but that would 11 to ground, so the output voltage is voltages for the output portion (instead
have the same detrimental effect on the given by the formula: of the more common ±4.5 V) to ensure
ultimate signal quality. A drawback of an undistorted maximum output signal
this totally separated approach is that we Vout = 1.4V + 3.2V + 0.4V + 0.2V = 5.2V level of 1 V (0 dB).
will need two AC adapters to power the The power connector (K7) is protected
overall device. To avoid the need for yet a Other voltages against reverse polarity by the Schottky
third AC adapter to provide the negative The positive supply voltage for the analog diode D1. The voltage drop over
supply voltage for the current to voltage output portion is set to +4.74 V, which is this diode is just 0.3 V. The current

www.elektormagazine.com July & August 2017 23


+3V3 +3V3 +5V2
L6 IC2, IC3 = LME49720 IC4, IC5 = LME49710

C28 C29 C27 C26 C25 C24 C22 C23


3
IC2A
10n 100n 10u 47n 10u 47n 47n 10u 1 R6
2 IC2.A 560R
VDD 2
SCK = 6 x BCK 9 28 15 R1 R5 R7 C10
JP1 JP2 6
IC6 8
SCK
VDD 360R 1k 360R

VCC2L
VCC2R
S0 CLK/2
7 5 SCK R22 7 26 7.8mA p-p C1 C9 2n2
CLK FBIN 22R SCK IOUTL-
1 4 BCK R23 6 6n8
S1 ICLK 22R BCK 2
DATA R24 5 25 7.8mA p-p C2 6n8 R17
ICS570BILF 22R DATA IOUTL+
6n8 IC4 6
LRCK R25 4 R8 R10 47R K3
GND 22R LRCK 3
3
360R 1k 360R K1 L
+3V3 1 VCOML
22
6 R2 R9 1
C11
IC1 C21 7

560R
R21 IC2.B 2
5 IC2B 2n2
7x 47k
10uF +5V2
23
1 VCC1

2
3
4
5
6
7
8
MONO
+3V3_RPi +5V_RPi 2 C20 C19 3
CHSL PCM1794A IC3A
3 1 R12
DEM
10u 10u IC3.A 560R
10 2
K5 MUTE 21
1 2 11 VCOMR R3 R11 R13 C15
FMT0
3 4 12 360R 1k 360R
FMT1
5 6 14 18 7.8mA p-p C5 C14 2n2
*RST IOUTR-
7 8 13 6n8

AGND3R
AGND3L
ZERO 2

AGND2

AGND1
9 10 17 7.8mA p-p C6 6n8 R18
1
2
3
4
5
6
7
S1 R19 IOUTR+ 6
11 12 BCK DGND IREF 6n8 R14 R16 IC5 47R K4
BCK H 3
K2 R

270R
13 14 8 20 24 27 19 16 360R 1k 360R
L R20
15 16 6 R4 R15 1
LED1 C16

10k
17 18 7
14
13
12
11
10
9
8

560R
IC3.B 2
19 20 no data 5 IC3B 2n2
21 22
23 24
+5V2 +3V3 +3V3
25 26
27 28 8 1
IN OUT
29 30 C53 C52 5 IC9 R32
31 32
EN C50 copyright

180k
33 34 4u7 4u7 7
TPS7A4901
DNC 10n C49 C48
LRCK 35 36 TEST POINT 2
LRCK FB
37 38 6
NR/SS 1.185V R33
4u7 4u7 +4V74L
39 40 DATA C51 L1

100k
DATA NC GND EPAD +4V74L +4V74L
3 4 9 C30
10n

4u7 C3 C12
K7 >5V7 +5V2 +4V74
8 7
3 PMEG6030EP 100n 100n
R26
1 15 1 8 1 IC2 IC4
IN OUT IN OUT 0R +4V74R C4 C13
2 C58 C57 C56 16 20 C54 C41 C40 5 IC7 R28
L2 4 4
D1 IN OUT EN C38
300k

13 3 TPS7A4901 100n 100n


47u 10u 10u EN SENSE 47u 4u7 4u7 7 C31
16V 25V 25V 16V DNC 10n C37 C36
IC10 2 K6
14 FB L5
NR 6 1.185V R29 C35 C34 4u7 -4V81L -4V81L
C55 NR/SS 4u7 4u7
17 C39 0
100k

NC NC GND EPAD
R34 18 100n 100n
1u NC
10n
3 4 9 -4V81L
19 L7 L3
NC
1k

+4V74R +4V74R
TPS7A4700
12 4 -4V81 ACM4520-231-2P-T C32
LED2 0P1V 6P4V2
11 5 R27
0P2V 6P4V1 1 4 C7 C17
10 6 VIN VOUT 0R 4u7
Power 0P4V 3P2V C47 C46 R30
9 8 8 7
0P8V 1P6V 6 IC8 100n 100n
-4V81R IC3 IC5
150k

GND PAD EN
4u7 4u7 7 C8 C18
7 21 C1- C42 L4 4 4
C45 5 –1.22V
VFB
C33 100n 100n
1u 8 LM27761 R31 2u2
3
C1+ CPOUT
4u7
51k

C44 C43
PAD GND -4V81R -4V81R
9 2
4u7 4u7
160198 - 11

Figure 2. Detailed schematic diagram of the high-end DAC for the Raspberry Pi.

consumption of the audio DAC is listed we added a frequency multiplier with A problem
in Table 2. an integrated PLL in the form of an We ran into a different problem when
ICS570BILF (IC6). This IC has a zero testing our prototype DAC. First we tried
Master clock delay buffer to ensure that the rising all sorts of 32-bit and 24-bit audio data
In order to utilize the audio DAC, the edges of the input and output signals with sampling frequencies from 32 to
operating system of the Raspberry Pi are perfectly aligned. 192 kHz, all without any difficulties.
(Raspbian) has to be configured for a The multiplication factor can be set However, when we tested the circuit with
HiFiBerry DAC. Once that is done, the between 0.5 and 32 by two tri-state 16-bit audio data we did not see any
Inter-IC Sound (I2S) signals are available inputs (S0/S1). According to the date output signal. To make a long story short,
on the GPIO expansion connector. The sheet, the output frequency range is 10 after a lot of sleuthing we discovered that
official names of these signals are to 170 MHz. We chose a multiplication although the PCM1794A supports 16-bit
Continuous Serial Clock (SCK) or Bit factor of 6 by leaving both S0 and S1 and 24-bit audio, that is not entirely
Clock (BCLK/BCK), Word Select (WS) open, and we use the CLK/2 output, true in I2S mode. The data sheet is not
or Left/Right Clock (LRCLK/LRCK), and which is also connected to the feedback especially clear about this.
Serial Data (SD/SDATA). input. This configuration provides the Does this mean that our player does not
For proper synchronization we also need best input range (2.5 to 12.5 MHz) with support 16-bit audio? That depends.
a master clock, but that is not included an output range of 15 to 75 MHz. You Direct playback is not possible, but the
in the original I 2S specification. This might think that with this arrangement Volumio version we use here (version
signal is therefore not available on the it is not possible to handle signals with a 1.55) includes sampling frequency
expansion connector, so the DAC circuit sampling frequency of 32 kHz, but that conversion capability with three different
has to generate it on its own. For this is not true; it works perfectly. quality levels. With a bit of luck, this

24 July & August 2017 www.elektormagazine.com


capability will also be implemented in the master clock runs at nearly 74 MHz For supply voltage decoupling we use
the planned update to Volumio 2. with a sampling frequency of 192 kHz. aluminum-polymer capacitors (C19, C23,
The various hardware select lines C25, C27) due to their low equivalent
The D/A converter (MONO, CHSL, DEM, MUTE, FMT0, FMT1 series resistance (ESR) of 40 mΩ at
The DAC device (IC1) has an integrated and RESET) are routed to a 7-pole DIP 100 kHz. However, they have the
8x digital oversampling filter and can switch and a set of seven 47-kΩ pull-up disadvantage of a relatively high leakage
handle sampling frequencies from resistors. This makes changing the current of 100 µA (max.). Since it is not
10 kHz to 200 kHz. The I2S signals are settings very easy. The ZERO output on clear whether this leakage current affects
connected through four 22 Ω resistors pin 13 drives LED1, which indicates that the internal input current, we added a
(R22 to R25) to block RF noise, since no audio data is present. pair of normal electrolytic capacitors

component list

Figure 3. The component side of the PCB. Figure 4. The bottom side of the PCB.
Jumpers JP1 and JP2 can normally be
omitted.

www.elektormagazine.com July & August 2017 25


(ESR 1.06 Ω at 100 kHz, leakage current
4 µA). If you want to experiment with
different capacitor types, there is plenty
of room on the PCB.

Output filter
Although the sampling artifacts are
largely suppressed by the 8x digital
oversampling filter, there are still
undesirable high frequency components
present in the output signal of the DAC.
We use a reconstruction filter to suppress
these components. The filter in question
is a third-order Butterworth filter, and
the current to voltage converters (IC2/
IC3) are part of this filter. The corner
frequency is 64.5 kHz. With a sampling
frequency of 44.1 kHz, the 8x frequency
component at 352.8 kHz is attenuated by
more than 40 dB, and with a sampling
frequency of 192 kHz the attenuation
Figure 5. The GPIO connector is mounted on the bottom side.
is more than 80 dB. The chosen corner
frequency is a compromise between
adequate attenuation at low sampling
frequencies and the audio bandwidth
of the output signal at higher sampling
Table 1: S1 settings
frequencies. Here the filter bandwidth is
S1-1 L De-emphasis disabled for 44.1 kHz
more than three times the normal audible
S1-2 L Digital filter with steep falling edge range.
S1-3 L Mono off The DAC IC has differential current
S1-4 L Mono off outputs, which allows an external filter
S1-5, S1-6 L I2S mode to be used. To convert the output current
into a single-ended voltage, we need a
S1-7 H Reset off
current to voltage converter, which in
this case is built around the dual opamps
of IC2 and IC3. The differential output
voltages of IC2A/IC2B or IC3A/IC3B are
Table 2: Current consumption at different sampling frequencies fed to IC4 or IC5, respectively, which
Sampling frequency Current consumption (K7) convert them into single-ended voltages.
No data 120 mA They are also configured as second-
32 kHz 127.5 mA order filter stages. In combination with
the current to voltage converters, the
44.1 kHz 131.7 mA
overall filter characteristic is equivalent
48 kHz 133 mA
to a third-order Butterworth filter.
96 kHz 149.5 mA On the PCB the single-ended output
192 kHz 182.1 mA signals are available on connectors
(Measured with 8 V lab power supply; both outputs terminated with 10 kΩ) K1 and K2 via headers K3 and K4.
Jumpers allow the signals from K3 and
K4 to be fed directly to K1 and K2. It
is also possible to connect a stereo
potentiometer to the headers to provide
Table 3: Distortion
a simple volume control.
THD+N
The DAC IC does not have integrated
Sampling frequency 48 kHz 96 kHz 192 kHz volume control capability. Although it
1 kHz BW = 22 kHz 0.0008% 0.0009% 0.0013% is possible to use Volumio for software
BW = 80 kHz 0.0028% 0.0012% 0.0014% volume control, that comes at the
7 kHz BW = 22 kHz 0.00095% 0.0011% 0.0013% expense of the resolution and therefore
affects the sound quality. For us that is
BW = 80 kHz 0.003% 0.0014% 0.0016%
out of the question. We therefore decided
IMD
to add hardware volume control in the
50 Hz:7 kHz = 4:1 0.0014% 0.002% 0.0036%
form of a separate board, which also

26 July & August 2017 www.elektormagazine.com


allows the volume to be adjusted under are hidden on the board. If you assemble have been soldered in place. The latter
remote control. The volume control board the board manually using a hot-air should therefore be kept for last.
will be described in the next issue of soldering iron or a reflow oven, it’s a Jumpers JP1 and JP2 are located on the
Elektor. good idea to use an enlarged copy of the bottom of the PCB. They can normally
component layout to help you put all the be left open (SCK = 6 × BCK). The
As a final detail, the balanced analog components in the right place. With many audio output connectors (Cinch/RCA
supply voltages for the filter and current of the 0805 components, replacement is connectors) are Switchcraft components
to voltage stages are decoupled from difficult or virtually impossible after the with two terminals closer together than in
the digital supply voltage by a common- conventional through-hole components the standard 10 mm version. This means
mode choke and four RF chokes (for each
channel individually).

The board
For the DAC board we only need a single
external supply voltage in the range of 7
to 8 V, since the Raspberry Pi board has
its own 5 V supply. An external supply
voltage of 9 to 12 V is possible, but not
recommended due to the higher power
dissipation in IC10.
The top and bottom PCB layouts for
the DAC board are shown in Figure 3
and Figure 4. The board has the same
dimensions as the Raspberry Pi. The
power connector and the two signal
outputs are on the same end of the
board, with the seven-pole DIP switch S1
on the opposite end (adjacent to the WiFi
antenna on the RPi 3 board). The 40-pin
GPIO stacking header K5 is mounted on
the bottom of the board, as can be seen
from the photos of the assembled board.
The pins of connectors K1–K4, K6 and K7
protruding on the bottom of the board
must be trimmed as short as possible
to avoid shorting on the metal shells of
the Ethernet and USB connectors on the
Raspberry Pi board. It is probably a good
idea to place a bit of insulation between
the two boards. In our prototype we
used M2.5 metal male/female threaded
standoffs with a length of 17 mm
(0.675”) to attach the DAC board to
the Raspberry Pi. The solder pads for
the capacitors in the filter stages are
laid out to allow three different types of
capacitor to be mounted for C1, C2, C5,
C6, C9–C11, and C14–C16. SMD 0805
components can be used here, but it
is also possible to mount conventional
through-hole capacitors with a lead pitch
of 5 mm. For best results, we recommend
using 1% polystyrene capacitors.
Pin 1 of each IC is marked with a small
white dot, but with IC7 this is difficult
to see due to capacitor C38. There was
not enough room to put the numbers
of the 0805 resistors and the 0805 and
1206 capacitors next to the components
concerned, so we put them inside the
component outlines. That means they Figure 6: The complete network audio player.

www.elektormagazine.com July & August 2017 27


Volumio
from the store
Volumio is a free open source Linux distribution specifically tailored to music
ª160198-1:
playback. Volumio runs on a wide variety of devices, including small inexpensive Bare PCB
computers such as the Raspberry Pi. After you install Volumio, the device turns
ª160198-91:
onto a headless audiophile music player. Here “headless” means that you have Assembled module with touchscreen;
to use another device, such as a smartphone, computer or tablet, to operate the headers included separately (to be
audio player. soldered by user))
For that you can use the Volumio user interface, which is a web app that runs on ªSKU 17631:
any device with a browser and makes playing music files easy and intuitive. The Raspberry Pi 3 (model B)
web app and Volumio communicate with each other over the local area network.
On the Elektor Labs page for this project [2] we provide detailed instructions for
installing Volumio on your Raspberry Pi (please note that we used version 1.55) so
that you can also use the touch screen for this purpose. ×
Figure 7 shows the Volumio user interface on the display (left) and on a PC
monitor (right). that if you want to use a different type,
it probably will not fit.
The Waveshare 3.5 inch touchscreen
display for the Raspberry Pi must be
mounted 16 mm (0.625”) above the
DAC board. For this we used four metal
male/female threaded standoffs with
a length of 14 mm (0.55”) together
with an M2.5 nut under each standoff
for the extra distance. This means you
should not press the connector down as
far as possible. In case of doubt, it is
better to use a second stacking header
Figure 7. Volumio can be operated using the touchscreen (left) or a PC (right). and mount the display a bit higher. The
distance between the 26-pin connector
of the display and the DAC board is about
2 mm.
Figures 5 and 6 show what the
complete network audio player looks like.

Measurements
It goes without saying that we subjected
our audio DAC to extensive testing. The
key results are summarized in Tables 2
and 3. All measurements were made
with the S1 settings listed in Table 1.
The current consumption increases at
higher sampling frequencies, as can be
seen from Table 2.
The measured figures for total harmonic
distortion plus noise (THD+N) and inter-
modulation distortion (IMD) are listed
in Table 3.
Several plots made with our Audio
Precision analyzer are also available
on the Elektor Labs page for this
project [2].
(160198-I)

Web links
[1] PCM1794A data sheet:
www.ti.com/general/docs/lit/getliterature.
tsp?genericPartNumber=pcm1794a&fileType=pdf
[2] Elektor Labs project page: www.elektormagazine.com/labs/
audio-dac-for-rpi-networked-audio-player-using-volumio

28 July & August 2017 www.elektormagazine.com


More than 45 years of experience
24-hour shipping
More than 75,000 products

W E R S U P P LY
INDEP I N G ENDENT PO
R T R AV E L L
IDEAL F O
Intenso slim 10,000 mAh power bank
Our price tip – ideal for
smartphones & tablets!
Cell capacity: 10,000 mAh, lithium-ion
Output connection: USB A and integrated
micro USB cable
Output: 5 V DC, max. 2.1 A
Protective features: surge voltage protection,
discharge protection, overcharge protection,
short-circuit protection
Dimensions: 130 x 70 x 16 mm
Order no.:

9.68
instead of 16.40 INTENSO 7332530

SAVE
41%
TO HELP YOU CHOOSE
Smartphone Tablet PCs
suitable for power banks suitable for power banks
with 1 – 1.5 A and  with more than 1.5 A and
2,200 – 6,000 mAh 6,000 – 20,000 mAh Logilink slim 20,000 mAh power bank
The power bank with
huge power reserves
Stabilised universal adapter, 12 – 24 V DC Output: 5 V DC, max. 2.1 A
Supplies netbooks and notebooks with LED charge state display (4 segments)
reliable power while travelling by car! Protective functions: overcharge protection,
deep discharge protection, short-circuit protection
Input voltage: 12 – 24 V DC
2 USB ports
Output: 15 – 20 V DC / max. 4,730 mA
Dimensions (L x W x H): 160 x 82 x 23 mm
10 DC connector plugs included for different devices
Short-circuit, overload, surge current and overheating protection
T
Integrated USB charging port, 5 V DC HOW ABOU
G EXTRA?!
SOMETHIN

Order no.:

22.38
LOGILINK PA0086B

E NOW
Order no.: OUR HOTLIN
E
UR LANGUAG

25.86
NTS 90 USB
ALSO IN YO
We look forward to your call:
+44 203 808 95 25
Daily prices! Price as of: 29. 5. 2017 Prices in £ plus statutory VAT, plus shipping costs · reichelt elektronik, Elektronikring 1, 26452 Sande (Germany) Onlineshop languages:

www.reichelt.co.uk
PAYMENT METHODS:

SHOP CONVENIENTLY ONLINE! ORDER HOTLINE: +44 203 808 95 25


HOMELAB PROJECT

BBC micro:bit for
Electronicists (2)
Data acquisition and oscilloscope functions

By Burkhard Kainka (Germany)

Every microcontroller that features an


A-to-D converter and a PC interface can be
used as a logging device for data acquisition
systems. But with the BBC micro:bit you
get the bonus of a small LED display and a
wirefree interface into the bargain. Just the
job for special applications in
your electronics lab!

The small footprint of the


BBC micro:bit would alone make
it a go-to choice for measurement
tasks. Regardless of whether pow-
ered over a USB cable or by batter-
ies, and whether it used Bluetooth or
some simplified wireless protocol to
communicate with the outside world,
it can always be installed close to the
object under examination.

A USB oscilloscope
For programming the BBC micro:bit the
mbed platform has proven its worth. The

GND

3V

Input

micro:bit P2

P1 10k

P0

Figure 1. Measurement input and signal output. Figure 2. A squarewave signal with 10 Hz Figure 3. The filtered signal.
repetition rate.

30 July & August 2017 www.elektormagazine.com


basics are explained in reference [1]. All
Listing 1. Rapid measurement with direct data transfer.
the programs mentioned in this article
are available to download as text files //Voltage Logger/Scope
on the Elektor website [2] and need to #include "MicroBit.h"
be copied into an existing mbed project. MicroBit uBit;
When deploying the BBC micro:bit for
general-purpose measurements you int main()
must ensure that the voltage range {
under examination cannot overstep the
uBit.init();
range between GND and VCC. A protec-
MicroBitSerial serial(USBTX, USBRX);
tive resistor of 10 kΩ in series with the
uBit.io.P1.setAnalogValue(512);
input will restrict the current flow in all
uBit.io.P1.setAnalogPeriodUs(100000);
situations, necessary if you accidentally
exceed safe limits (Figure 1). As well as while (1) {
the analog input there’s also a square- if(uBit.buttonA.isPressed()){
wave output, with which you can produce int u = 1000+3300 * uBit.io.P0.getAnalogValue()/ 1023;
a handy test signal. uBit.serial.printf("%d\r\n", u);
For maximum speed the program in // uBit.sleep(100);
Listing 1 captures data without buff- }
ering for immediate transfer of each }
measured value. A significant element }
of the cycle time arises from the serial
transfer at 115,200 baud. If the mea-
surements captured are a mixture of, ment and a scrolling display is shown. As ated from the squarewave, as would be
say, single-digit (3 mV) and four-digit soon as you release the button, the last expected (Figure 3). The measurement
(3000 mV) amounts, these variable display is frozen, so you can examine it range of the Arduino plotter adapts auto-
figures will result in uneven data flow. more closely or save a copy of it. matically to smaller voltages.
Consequently we raise the voltage by The additional signal output can be use-
1000 mV, making the possible values ful for investigating circuits or compo- Faster sampling by buffering
from 1000 mV to 4300 mV and always nents. Using a low-pass filter with 4.7 kΩ If you are minded to reduce the time
taking the same time to process. The and 22 μF a sawtooth signal is gener- taken by serial data, it is only the acqui-
program also provides its own signal
source so that you can measure some-
thing without additional overheads. P1 Listing 2. Rapid saving and subsequent transfer.
becomes a PWM output with a PWM fre-
//Fast Scope
quency of 10 Hz and a period of 100 ms.
For evaluating the data there are plenty #include "MicroBit.h"
of options. You could take in the data MicroBit uBit;
using a terminal program and then pres-
ent it as a spreadsheet. A convenient int main(){
alternative is the serial plotter in the char d[400];
Arduino IDE (version 1.6.8 onwards). uBit.init();
This software provides a scrolling screen MicroBitSerial serial(USBTX, USBRX);
display, adjusted automatically to the uBit.io.P1.setAnalogValue(512);
display range, making range switching uBit.io.P1.setAnalogPeriodUs(2000);
or reformatting unnecessary. With the
while (1) {
settings shown we can measure a sym-
if(uBit.buttonA.isPressed()){
metrical squarewave signal with 10-Hz
for(int i = 0; i < 400; i++){
repetition rate (Figure 2). At the same
time we now have a known time axis. The d[i] = uBit.io.P0.getAnalogValue()/ 4;
entire oscillogram clearly depicts a data }
acquisition duration of 300 ms. for(int i = 0; i < 50; i++) uBit.serial.printf("%d\r\n", 0);
The serial plotter of the Arduino IDE for(int i = 0; i < 400; i++){
always plots first from left to right until uBit.serial.printf("%d\r\n", d[i]);
the screen is completely filled. After this, }
the picture scrolls to the left to make for(int i = 0; i < 50; i++) uBit.serial.printf("%d\r\n", 255);
old data disappear. The choice between }
a continuous or static display is made uBit.sleep(500);
with the button A (if(uBit.buttonA.
}
isPressed()in Listing 1). Just press but-
}
ton A for the duration of the measure-

www.elektormagazine.com July & August 2017 31


shown, the measurement lasts around
30 ms, which means that with 400 data
points a sampling rate of approximately
13 kHz can be deduced. Because the
PWM frequency in this program was
raised by 500 Hz, you can easily verify
this with a signal of your own. Figure
5 shows the PWM signal at the output a
low-pass filter with 4.7 kΩ and 100 nF.

Wireless transfer
of captured data
Figure 4. Measuring with a higher sampling Figure 5. A 500-Hz sawtooth signal The BBC micro:bit is equipped with
rate. Bluetooth Low Energy (BLE). You will look
in vain on the board for a dedicated chip
for this, as the RF circuitry is already built
sition time of the A-to-D converter that use a Byte Array with 400 bytes using into the microcontroller. The nRF51822
limits the achievable sampling rate. So char d[400]. By dividing by 4, the 10-bit from Nordic Semiconductor was originally
you create a Data Array, fill it with data data of the A-to-D converter becomes an developed for applications such as
measurements and send these off to the economical 8 bits. wireless keyboards and mice, which did
PC. But it’s exactly here that problems We now store and transfer 400 bytes not call for extensive range but did have
arise that you had not reckoned with. (Listing 2). We are still 100 bytes short to use battery power economically. The
Although the controller is well endowed for filling the plotter. But we can make a BBC micro:bit takes advantage of these
with RAM, an Array of the type int virtue out of necessity and prefix a zero- capabilities. You can power the board
d[100] is pushing the limits, because bytes header and suffix a trailer having using a 3-V battery and then dispense
the Microbit Runtime does not have much 255-bytes. This causes the serial plotter with even the USB cable. This makes
spare capacity. But if you want to use to always display the full measurement the system viable even for long-term
the serial plotter, there should already range and provides the viewer with clear applications powered by batteries. The
be 500 measured values. visibility of the range limits. The reading shortform lineup of its main features
You definitely need to be aware that the in Figure 4 depicts a 50-Hz signal with speaks for itself:
type of int in a 32-bit system has a typical interference pulses, which you
size of four bytes. Accordingly we have pick up with an exposed measurement • 2.4-GHz transceiver
400 bytes at our disposal. Therefore we lead. Because around 1.5 oscillations are • –93 dBm sensitivity in Bluetooth®
low energy mode
• 250 kbps, 1 Mbps, 2 Mbps supported
data rates
• Tx Power –20 to +4 dBm in 4-dB
steps
• Tx Power –30 dBm whisper mode
• 13 mA peak Rx, 10.5 mA peak Tx
(0 dBm)
• 9.7 mA peak Rx, 8 mA peak Tx
(0 dBm) with DC/DC
• RSSI (1-dB resolution)
• ARM® Cortex™-M0 32-bit processor
• 275 μA/MHz running from flash
memory
• 150 μA/MHz running from RAM
• Serial Wire Debug (SWD)

Programming with mbed enables the use


of Bluetooth, allowing you to transmit
data direct to a smartphone or tablet.
Admittedly this calls for a pretty sizeable
software stack and worse, it leaves you
to develop the custom apps.
But there’s a far simpler way. You see,
you can address the 2.4-GHz transceiver
at a lower level, dispensing altogether
with the complicated Bluetooth protocol.
Figure 6. Deactivating BLE. Making this possible is the MicroBitRadio

32 July & August 2017 www.elektormagazine.com


support platform [6] with simple
datagrams (text messages) that the
transceiver can handle unaltered. One
BBC micro:bit module sends a text
message and all other modules in range
can receive it. To make this work a default
channel and a default transmit power
have been defined, so you really don’t
need to concern yourself with anything.
That makes this one of the simplest
methods of transferring data without
wires. At the same time it gives you the
ability to make isolated (potential-free) Figure 7. Data measurements sent by wireless Figure 8. Measuring the internal test signal.
measurements. A typical application link.
might be an electrocardiogram device,
as the electrical (galvanic) separation
eliminates any troublesome electrical MicroBitRadio component and Bluetooth file is an entry MICROBIT_BLE_ENABLED 1,
hum interference. Low Energy (BLE) at the same time. in which you need to replace the 1 with a
All you need is two BBC micro:bit If you want to use the MicroBitRadio 0. In the next compilation that you make
modules. One is employed as the functionality, you need to disable the BLE BLE is then deactivated, enabling you to
measuring instrument for transmitting stack on your micro:bit by compiling the use the simplified MicroBitRadio.
the data, the second one is programmed runtime with #define MICROBIT_BLE_ The program in Listing 3 sends and
as the receiver, for displaying the data ENABLED 0 in your inc/MicroBitConfig.h receives datagrams of measurement
or transferring it to a PC over a USB file. data. The sender and receiver can
cable. To use MicroBitRadio in mbed you It is not entirely simple to locate the therefore use the same program and also
do need to deactivate Bluetooth Low correct point in the numerous files of exchange data reciprocally. The sender
Energy. There’s a note about this in the the runtime system. The exact path executes a measurement at P1 and
BBC micro:bit documentation: is: microbit\microbit-dal\inc\core\ transmits the reading in mV. The receiver
It is not currently possible to run the MicroBitConfig.h (see Figure 6). In this passes the received data forward via the

Advertisement

Join the Elektor Community GOLD


MEMBERSH
Take out a GOLD Membership now! ✔ 6x Elektor M
IP
agazine (Print)
✔ 6x Elektor M
agazine (PDF)
✔ Access to Ele
ktor Archive
(Thousands of
Articles)
✔ Access to ov
er 1,000 Gerber
files
✔ Elektor Annu
al DVD
✔ 10% Discount
in Elektor Store
✔ Exclusive Off
ers

GREEN
MEMBERSHIP
✔ 6x Elektor M
agazine (PDF)
✔ Access to Ele
ktor Archive
(Thousands of
Articles)

Also available: ✔ Access to ov


files
er 1,000 Gerber

The all-paperless GREEN Membership! ✔ 10% Discount


✔ Exclusive Off
in Elektor Store

www.elektor.com/member
ers

www.elektormagazine.com July & August 2017 33


USB connection. Nothing changes on the
Listing 3. Sending and receiving datagrams.
PC side. Here we can again make use of
the serial plotter. Figure 7 illustrates a //Radio Data
measurement reading. The transmitter #include "MicroBit.h"
is battery-driven and is located three MicroBit uBit;
meters (10 feet) away from the receiver.
The link works for up to approx. 10 m
(30 ft.). A 10-µF electrolytic was attached void onData(MicroBitEvent e)
to analog input P1. This was charged up {
slowly using the 10-MΩ pull-up resistor ManagedString s = uBit.radio.datagram.recv();
provided on the PCB. You may notice uBit.serial.send (s);
some deviation from the normal charging uBit.serial.send (" \r\n");
curve, because this capacitor had not }
been used for a long time. In a case
like this just a low leakage current flows int main()
initially that increases only gradually. On {
the right-hand side of the diagram the uBit.init();
measured voltage lies clearly below 1 V uBit.messageBus.listen(MICROBIT_ID_RADIO, MICROBIT_RADIO_EVT_
and rises only slowly. DATAGRAM, onData);
uBit.radio.enable();
Mini-oscilloscope with LED char output[16];
display while (1) {
An extremely basic oscilloscope is better int u = 3300 * uBit.io.P1.getAnalogValue()/ 1023;
than none at all and sometimes it’s more itoa (u, output);
important that the device is very small, uBit.radio.datagram.send(output);
standalone and easy to handle. Here uBit.sleep(100);
we see measurement data displayed }
graphically on the LED display using }
5×5 LEDs (Listing 4). Even if you are
accustomed to a far more sophisticated [5] B. Kainka, BBC micro:bit Tests
instrument, you can definitely get results Tricks Secrets Code, CreateSpace
with this little alternative. It is quite 2016
remarkable, what is still discernible with
[6] https://lancaster-university.github.
such a simple ‘scope.
io/microbit-docs/ubit/radio/
Once again the mini-oscilloscope uses
Port 1 as an analog input and additionally
employs Port 0 as a PWM output. With a
Listing 4. Using the LED display.
repetition rate of 500 μs, an output signal
with a frequency of 2 kHz is generated. //LED-Scope
A direct connection to the measurement #include "MicroBit.h"
input shows the limits of the A-to-D MicroBit uBit;
converter (Figure 8). The sampling time int main()
is obviously too long to display sharp {
edges of the PWM signal. The limiting int y;
frequency of this simple oscilloscope is uBit.init();
therefore somewhere below 10 kHz. This
uBit.io.P0.setAnalogValue(512);
is not enough for an RF lab but probably
uBit.io.P0.setAnalogPeriodUs(500);
adequate for many simple measurements
uBit.display.enable();
and experiments.
(160384)
MicroBitImage image(5,5);
while (1) {
for(int x = 0; x < 5; x++){
y = 4- (uBit.io.P1.getAnalogValue()/205);
image.setPixelValue(x,y,255);
Web Links
}
[1] www.elektormagazine.com/160273
uBit.display.print(image);
[2] www.elektormagazine.com/160384 uBit.sleep(500);
[3] https://developer.mbed.org/ image.clear();
[4] https://lancaster-university.github. }
io/microbit-docs/ubit }

34 July & August 2017 www.elektormagazine.com


LABS PROJECT

Sea Murmur Simulator


Gentle noise to help you go to sleep

By Sunil Malekar and Clemens Valens (Elektor Labs)

When Morpheus’ arms keep


eluding you, listening to the sound
of surf and waves breaking on a
beach may help you to relax. With
the circuit presented here switched
on at your bedside Mr Sandman is
sure to stop by.

project information
Noise
Simulator
Relaxation

Æ entry level
intermediate level
expert level

1 hour approx.

You may think that for producing a mag- weeks is because of our Multifunctional Soldering iron,
azine like Elektor all that is required Power Planner and unsung hero Hedwig. small screwdriver,
are some editors to write articles and Although electronics is not her specialty bed
one or two graphics designers to cre- (“is this capacitor thing or whatever it
ate nice illustrations. That is only partly is supposed to be this kind of blue?”),
true. One of the main reasons — possi- Hedwig does have a pet circuit: the sea £12 / €15 / $17 approx.
bly the only one — for you to be able to sound generator. So Hedwig, this one
read your favorite magazine every eight is for you.

www.elektormagazine.com July & August 2017 35


R4 +5V
C9
68k 10u

R3 P1
50V
100k C4 R8 R13
R5 P4
D1 D2 500k 2M2

1k2
47u

10k
10 50V
8 6 1M C10 1 IC3
IC2.C R11 2 3 6
9 R6 7 C8 R12 C11
D3 IC2.B 8
1 5
3x 5 R9 1u IC2.A 100k LM386

1M
1N4148 50V
10k

3 10u 2 C13 K2
220u
50V

100k
P2 4 50V
T3 7 47n
R10
R7 R14
500k 100k IC2 = LM324 C12
Speaker

10R
Volume

2k2
P3 P5
OUT
500k BC547C 10k 10u
50V

+5V +5V

+5V
copyright R2 +5V

10k
8
K1
R1 C2 2 +V 7
1 C+ OSC
+5V 68k 4 C5
2 C7 C3 1 IC1 5
D– T1 * T2 10n IC2 FC OUT –5V
3 C1
D+ 11 100u
4 MAX660 6 C6
220u 100n 50V C– LV
4 50V
GND GND
1u
50V 100u
2N3904 3
50V
USB
–5V
140097 - 11
–5V

Figure 1. The internals of the sea murmur simulator.

cates matters a bit, especially because


Features of the asymmetrical aspect, i.e. the
• Independent control of swell or attack of the sound should
wave attack and decay shape not have the same duration as its
• Powered from a phone charger decay. An asymmetric triangle gener-
• No (0) Arduino inside ator is much easier to build, see the
circuitry around IC2.C and IC2.B,
and the result is more than sat-
The sound of waves breaking on the isfying. Normally such an oscillator
beach is considered relaxing by many produces a triangular wave that’s sym-
people. As relaxing and even roman- metrical around zero, but we don’t want
tic as it may appear, when analyzed by + 5   V, i .e. that here as the negative halves would
the impartial and objective scientist the 10 V in total. Such block our modulator T3, resulting in dis-
sound turns out to be modulated noise in a ‘high’ voltage is nec- continuous breakers. To prevent this hap-
essence. Perhaps slightly pink noise, as essary for producing good noise. T1 and pening, D1 was added. Now the output
a vague reminiscence of the setting sun, T2 are specified as 2N3904 because it of IC2.B sweeps nicely between 0 V and
but noise it is. Noise is easy to produce was found that these transistors produce about 3 V.
with an electronic circuit — as a matter more noise than the more Elektor-savvy
of fact, it is much more difficult to not BC547 a.k.a. TUN in the old days. We Pots P1 and P2 control the slopes of the
produce noise with electronics. Basically, tried that one too, and it worked, but modulating signal; P1 adjusts the rising
all you need to do is reverse-bias a diode. you may obtain better results with the slope, P2 the falling slope. Together they
given types. If you want to experiment determine the frequency of the signal,
The circuit with these transistors, keep in mind that the speed of the waves so to speak. The
Even though generating noise is easy, the 2N3904 for which we designed the smaller their total value, the higher the
making usable noise requires some effort. printed circuit board does not have the frequency. Their ratio determines the
Figure 1 shows the schematic of the same pinout as the BC547. symmetry of the signal.
contraption we came up with. Here the
noise source is T1 wired as a reversed-bi- Now that we have noise, we have to Transistor T3 acts as a current-controlled
ased diode with its emitter mimicking modulate it to simulate the sound of the resistance controlling the amplification
a cathode and its base, an anode. The waves and the surf. Modulation requires of IC2.A; the smaller the resistance, the
noise it produces is buffered by T2. Look- an oscillator. Some sort of asymmetric stronger the output signals. Pots P3 and
ing closely you will notice that this tran- sine-like wave is likely to result in the P4 then, provide a means of fine tuning
sistor is connected between –5 V and most realistic effect, but this compli- the amplification.

36 July & August 2017 www.elektormagazine.com


The output of IC2.A is fed through P5, Calibration
the overall volume control, to a power Like every high-precision instrument, our from the store
amplifier built around IC3. This is a clas- sea murmur simulator has several trim-
ª140097-1
sic LM386 circuit capable of driving a pots that require adjustment in order to PCB
loudspeaker or headphones. The gain get the best result. Luckily, the proce-
of the amplifier can be set to anywhere dure is simple. It starts by turning P3 to
from 20 to 200 by using the right com- its minimum position (i.e. wiper to 0 V).
binations of parts R13 and C9. P4 controls the background noise of the
virtual sea when there are no waves at studies and simulations in the lab have
Without these parts the gain is 20, all. Adjust P4 for a nice, soft whisper in shown that the rise of a wave (P1) is usu-
with only C9 between pins 1 and 8 (i.e. the loudspeaker. ally 5 to 10 times shorter than its decay
R13 = 0 Ω) the gain is maximum (200). (P2); the required wave shape is there-
The values shown in the schematic set Now adjust P3 to add waves. It effectively fore more like a sawtooth than a trian-
the gain to 50 or so. controls the amplitude of the waves — gle. The wave period should be several
simply set it to a realistic level. If the seconds — adjust to taste.
Although a large part of the circuit is sound appears to start clipping, lessen (140097)
powered from a symmetric ±5 V sup- off on P4 a little. Remember that P3 and
ply, a standard 5-V USB phone charger P4 affect each other so that further fine
Web Link
is sufficient to make it all work. This is tuning may be necessary.
made possible by IC1, a MAX660 chip [1] www.elektormagazine.com/140097
wired as a switched-capacitor voltage Finally the ‘shape’ of the waves has to
inverter, and USB connector K1. be adjusted with P1 and P2. Extensive

component list

www.elektormagazine.com July & August 2017 37


The I2C Bus
Part 2: using the bus with a microcontroller
The familiar two-wire bus is ideal for experiments
and applications using a Raspberry Pi
or on an Arduino.

By Josef Möllers (Germany)

SDA

SCL

S B1 B2 BN P

Raspberry Pi, BeagleBone, Arduino, Genuino, ATmega, PIC, The Raspberry Pi provides a convenient environment for learn-
practically any PC: pretty much anything you can find sitting ing how to use new and unfamiliar I2C slave devices. Figure 1
on a maker’s work bench that can compute will have one or shows how a breadboard can be used to connect an LM75 to
more I2C interfaces. Using the example of the LM75 tempera- a Raspberry Pi.
ture sensor we will look in this article at how the I2C interfaces
of the Raspberry Pi, ATmega and Arduino can be used as bus Operation as bus master
masters, and, where possible, as bus slaves. Before the I2C bus on the Raspberry Pi can be used under
Raspbian, it is necessary to install two extra drivers. To do
Raspberry Pi this, launch raspi-config and select the I2C option under the
The Raspberry Pi has two physical I2C buses, of which only Advanced Options menu item. This will enable the interface
one can normally be used directly. The Raspberry Pi board and load the necessary kernel module. Alternatively add the
comes with pull-up resistors to the 3.3 V supply already fit- following lines to the file /etc/modules using a text editor:
ted and permanently enabled. SDA and SCL are available on
pin 3 (SDA) and pin 5 (SCL) of the expansion header, conve- i2c-dev
niently right next to the 3.3 V supply on pin 1, the 5 V supply i2c-bcm2708
on pins 2 and 4, and ground on pin 6. These pins belong to I2C
bus number 1. It is therefore possible to make a very compact After restarting the system the two drivers (as well as any other
plug-in expansion board offering temperature sensing, real- extra drivers that are required) will be loaded and the device
time clock or position sensing functions. nodes /dev/i2c-<n> will be created. This can be confirmed
Caution: the ports of the Raspberry Pi must only be oper- using the following commands at the ‘$ ...’ prompt.
ated at 3.3 V and connection to 5 V signals can damage the
device. It is important, therefore, to check your circuit carefully $ lsmod | i2c_
before connecting it to the ports on the Raspberry Pi. In par- i2c_dev XXXX 0
ticular take care that no I2C slave contains pull-up resistors to i2c_bcm2708 YYYY 0
the 5 V rail. If present, any such resistors should be removed: $ ls /dev/i2c-*
the slave will still work without them. dev/i2c-1

38 July & August 2017 www.elektormagazine.com


In the above XXXX and YYYY stand for the size of the modules,
while the two zeros indicate that no programs are currently
using the modules. The commands will, incidentally, work even
without root privileges.
Next install the i2c-tools package, which includes among
other things code to detect I2C devices and buses:

sudo apt-get install i2c-tools

Raspbian already includes drivers from some I2C peripheral


devices, including for the RV-8523 real-time clock (RTC). Unless
configured otherwise, the Raspberry Pi drives the I2C bus in
standard mode at 100 kbps.

For a first test you can use the i2cdetect tool from a terminal
window to obtain an overview of the slave devices that the
system recognizes on I2C bus number 1. The results might
appear as shown in Figure 2, where the LM75 is responding
to address 0x48.

The commands i2cget, i2cset, and i2cdump can be used to Figure 1. Connecting an LM75 to a Raspberry Pi using a breadboard.
communicate with the LM75 without having to get involved
in programming. In the example below 0x00 is the register
number, which must always be specified.
ioctl(fd, I2C_SLAVE, 0x48);

pi@raspberrypi ~ $ i2cget -y 1 0x48 0x00 w


0xa010
And now we can write to and read from the device.
The two bytes of the reply must be swapped over, giving
0x10a0. Of this result only the upper nine bits are valid: they
unsigned char buf[2];
are 0x021. The LM75 reports temperature in steps of 0.5 K,
float T;
and so the temperature reading in this example is 16.5 °C.
The hardware of the Raspberry Pi in principle also supports buf[0] = 0;
operation as an I2C slave, but this is not supported by the write(fd, buf, 1); /* write register number 0 */
Linux driver. read(fd, buf, 2); /* read temperature register */
T = ((buf[0]<< 8) | buf[1]) / 256.0;
Programming in C and Python
Five functions are required to program the I2C bus in C.
Finally we close the device node: Geräteknoten wieder:
• open() to access the I2C device node;
• ioctl() to set the I2C slave parameters; close(fd);
• read() and write() for the actual communication with
the slave; and
• close() to indicate when access to the I2C device node is Of course it is a good idea to check the return values from the
no longer required. function calls properly in order to detect possible errors, such

For the following code, in addition to the other include files,


the include file linux/i2c-dev.h is required for the definition pi@raspberrypi ~ $ i2cdetect -y 1
of I2C_SLAVE. 0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
# include <linux/i2c-dev.h> 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
The device node is accessed using the open() function. 40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
fd = open("/dev/i2c-1", O_RDWR); 70: -- -- -- -- -- -- -- --

Next we set the slave address with an ioctl() call. Figure 2. The i2cdetect tool has found an LM75 at address 0x48.

www.elektormagazine.com July & August 2017 39


bus = smbus.SMBus(1)

address = 0x48

w = bus.read_word_data(address, 0)

print format(w, '04x')

The “0” in the call to the read_word_data method supplies


the register number, which here is the index of the tempera-
ture register. In the SMBus protocol, which sits on top of the
I2C protocol, a register number must always be set at the
Figure 3. The ATmega88 and the sensor on a breadboard.
start of a communication. This causes problems in the case
of the PCF8574 port expansion chip, for example, which has
no address register.
as whether the user running the code has permission to open The returned value has the same problem as with the i2cget
the device node /dev/i2c-1, whether a slave exists at address command: the two bytes in the word w must be swapped over.
0x48, and whether the data transfers were successful.
ATmega
Before programming the I2C bus in Python, it is necessary to The Atmel ATmega microcontroller series have an integrated
install (or to have already installed) the python-smbus Rasp- I2C controller which supports both standard mode (at 100 kHz)
bian package. and fast mode (at 400 kHz). It can be operated as a master,
as a slave or as a combination of the two. The ATmega324PB
sudo apt-get install python-smbus and the ATmega328PB devices include two I2C buses. In the
following examples we will be using the ATmega88, which can
Then the temperature can be read from the LM75 as follows. be plugged into a breadboard along with the sensor as shown
in Figure 3.
#! /usr/bin/python Here the best approach is to use the i2cmaster library by Peter
Fleury [1]. Note, however, that this library does not auto-
import smbus
matically enable the internal pull-up resistors! It is therefore
import time necessary to take care of this ourselves: Figure 3 shows the
resistors towards the top of the breadboard, running to the 5 V
rail. The library configures the I2C bus controller in the ATmega
to run in standard mode (100 kHz). The LM75 sensor can be
Listing 1. Main loop for reading from the LM75. accessed using code like that shown in Listing 1.
Using lcdlibrary, by the same author, we can construct a
# include <i2cmaster.h>
digital thermometer with an external liquid crystal display.
This can be connected using an I2C interface board (which will
# define LM75 (0x48 << 1)
usually be based on a PCF8574), or alternatively an LCD with
// see datasheet
built-in I2C interface can be used.
int
The I2C bus controller in the ATmega devices does not have to
main(void)
be operated in master mode, controlling a slave. It can also be
{
run in slave mode, controlled by an external master. A com-
unsigned char val[2];
posite mode of operation is also available, where, for example,
the ATmega might at one moment be communicating with the
i2c_init();
LM75 as a bus master, and then at the next moment be acting
// initialisation I2C
as a slave to a Raspberry Pi master. One situation where an
ATmega might be used as a slave is where the ATmega is read-
i2c_start(LM75 | I2C_WRITE);
ing data in real time over its port pins, doing some processing,
// addressing to write
and then supplying the results upon request to a Raspberry Pi.
i2c_write(0x00);
This kind of set-up is more complex, and entails tight coupling
// temperature register
with the rest of the code running on the ATmega. There do
i2c_rep_start(LM75 | I2C_READ);
exist, however, the rudiments of a library implementing oper-
// addressing to read
ation in slave mode [2].
val[0] = i2c_read();
The description below follows that given in Atmel’s datasheets,
// degrees Celsius
which contain tables of the various states of the I2C controller.
val[1] = i2c_read();
For example, in the datasheet for the ATmega48/88/168, the
// tenth part bit
relevant information can be found in section 22.7.
i2c_stop();
// ready
It is sensible to make the software implementing I2C slave
for(;;);
mode run under interrupts. The bus controller hardware can
}
trigger an interrupt under the following conditions.

40 July & August 2017 www.elektormagazine.com


• after transmitting a ‘start condition’ or ‘repeated start Working with the Arduino is just as straightforward as working
condition’; with the Raspberry Pi (see Figure 4). Depending on the exact
• after transmitting the address and read/write bit; model of Arduino (or clone), you may find that the processor
• after transmitting a data byte;
• when the ATmega has lost an
address arbitration (when a colli- Listing 2. Interrupt service routine to deal with address matching and
sion occurs while transmitting the detection of ‘stop condition’. The complete and extensively commented
‘start condition’, the address byte code is available on the project web page [5].
or the read/write bit); ISR(TWI_vect)
• when the ATmega has detected {
a ‘start condition’ and has been /*
addressed as a slave; * These variables need to be preserved across interrupts
• when the ATmega has received a */
data byte; static unsigned char i2c_idx, /* Index into twi_msg[] */
• when the ATmega has detected i2c_tosend; /* Number of bytes to send */
a ‘stop condition’, or a ‘repeated
start condition’ where it has switch (TWSR & 0xf8)
(again) been addressed as a {
slave; or ...
• when an invalid bus transaction /*
has been detected. * RECEIVE Code
* See Table 19-4. Status Codes for Slave Receiver Mode
The first four of these situations are * [Page 229]
only relevant to master mode, and so */
we are only interested in the last four. case 0x60:
The I2C peripheral unit must be initial- /*
ized with the desired slave address. It * Own SLA+W has been received; ACK has been returned
can then be enabled and it will start * TWDR: No TWDR action
to run. * STA=X STO=0 TWINT=1 TWEA=1
* Data byte will be received and ACK will be returned
TWAR = (I2C_Slave_Addr << 1); */
TWCR = _BM(TWEA) | _BM(TWEN) | TWCR = (TWCR & ~_BM(TWSTO)) | (_BM(TWINT) | _BM(TWEA));
_BM(TWIE); i2c_idx = 0;
break;
There is no need to set the bit rate …
for slave mode, as the communication case 0xA0:
speed is determined by the master. /*
When an interrupt occurs, the first * A STOP condition or repeated START condition has been
step is to determine its cause. To do * received while still addressed as slave
this it is necessary to read the TWSR * TWDR: No action
status register and examine its top * TWA=0 STO=0 TWINT=1 TWEA=1
five bits. * Switched to the not addressed Slave mode;
Listing 2 shows a fragment of the * own SLA will be recognized;
interrupt service routine (ISR) for * GCA will be recognized if TWGCE = "1"
receiving and transmitting data as */
a slave, and for detecting a ‘stop TWCR = (TWCR & ~(_BM(TWSTA) | _BM(TWSTO))) | (_BM(TWINT) | _BM(TWEA));
condition’. break;
The descriptions and tables in the …
ATmega datasheets are very com- case 0xA8:
prehensive, including explanations of /* Own SLA+R has been received; ACK has been returned
the status codes, actions required in * TWDR: Load data byte
software, and the resulting behavior */
of the hardware. /*
* The address (register number) has been received,
Arduino * Start sending payload
Many Arduinos are based on Atmel */
ATmega-series microcontrollers, and TWDR = 0x42;
so the above discussion applies equally break;
to them. However, a popular and very }
convenient library called Wire.h is also }
available for the Arduino.

www.elektormagazine.com July & August 2017 41


runs on 3.3 V and that its ports cannot tolerate 5 V signals.
So check and measure before connecting your circuit and if
necessary remove any pull-up resistors on the slave.

The Wire library can be found directly within the Arduino IDE.
As in the case of Peter Fleury’s i2cmaster library the library
and I2C interface must be initialized at the start of your code.

#include <Wire.h>
void setup() {
Wire.begin();
}

The call to Wire.begin() enables the internal pull-up resis-


tors. The value of these resistors is relatively high, which can
cause problems: if so, add two external resistors with a value
of 10 kΩ to 20 kΩ in parallel. Alternatively, disable the internal
resistors altogether and just rely on external pull-ups (which
should then be in the region of 4.7 kΩ). This can be done with
the following two lines of code after the call to Wire.begin().

Figure 4. Connecting to an Arduino is practically the same as connecting digitalWrite(SDA, 0);


to a Raspberry Pi. digitalWrite(SCL, 0);

The I2C bus on a PC


Practically every PC has its own I2C interface, and most have 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
several such interfaces. There are I2C slaves in displays (DDC [3]) 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
and DRAM DIMMs (SPD [4]). Internal temperature sensors are 30: -- -- -- -- -- -- -- 37 -- -- 3a -- -- -- -- --
also often connected over I2C. Unfortunately there is scant to 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
non-existent manufacturer information on the devices used and 50: 50 -- -- -- -- -- -- -- 58 -- -- -- -- -- -- --
on whether and how the buses can be accessed externally: 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
sometimes a bus will be used only within a particular module. 70: -- -- -- -- -- -- -- --
If the PC is running Linux, it is easy to run some experiments
by loading the i2c-dev module as follows. It is not always clear what peripheral devices are present. In
the example below the monitor’s EDID PROM is at address
$ sudo modprobe i2c-dev 0x50.

You can then look at what device nodes are root@bounty:~# i2cdump -y 5 0x50
present in /dev. No size specified (using byte-data access)
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
$ ls /dev/i2c* 00: 00 ff ff ff ff ff ff 00 1a b3 d4 07 ec 22 02 00 ........?????"?.
/dev/i2c-0 /dev/i2c-1 /dev/i2c-2 /
10: 0a 16 01 03 80 34 20 78 2a ef 95 a3 54 4c 9b 26 ?????4 x*???TL?&
dev/i2c-3 /dev/i2c-4 /dev/i2c-5
20: 0f 50 54 a5 4b 00 81 80 81 00 81 0f 95 00 95 0f ?PT?K.???.???.??
30: a9 40 b3 00 01 01 28 3c 80 a0 70 b0 23 40 30 20 ?@?.??(<??p?#@0
40: 36 00 06 44 21 00 00 1a 00 00 00 fd 00 38 4c 1e 6.?D!..?...?.8L?
Up to this point you do not need root privi- 50: 52 10 00 0a 20 20 20 20 20 20 00 00 00 fc 00 42 R?.? ...?.B
leges. Under Debian and its derivatives (which 60: 32 34 57 2d 35 20 45 43 4f 0a 20 20 00 00 00 ff 24W-5 ECO? ....
includes Raspbian and Ubuntu) you can install 70: 00 59 56 32 45 31 34 30 30 31 32 0a 20 20 00 8e .YV2E140012? .?
i2c-tools.

apt-get install i2c-tools If your PC has a VGA connector, you can try connecting an
I2C slave to pin 12 (SDA) and pin 15 (SCL). Pins 6 (SCL)
Sometimes there are slaves on only one of the buses, as in the and 7 (SDA) of a DVI connector and pins 15 (SCL) and 16
following example. (SDA) of an HDMI connector are also good candidates for
experimentation. Unfortunately in some cases these buses
root@bounty:~# i2cdetect -y 5 are under the sole control of the graphics card and its
0 1 2 3 4 5 6 7 8 9 a b c d e f firmware.
00: -- -- -- -- -- -- -- -- -- -- -- -- --

42 July & August 2017 www.elektormagazine.com


Note that this is not an official solution and that things may void receive(int n) {
change in the future. In any case it is a good idea to measure while (n--) {
the effective pull-up resistance with a multimeter after initial- uint8_t c = Wire.read();
ization is complete. // Verarbeite c
}
Caution: when the internal pull-up resistors are disabled in this }
way there will be a brief period during which they are enabled. If you wish to transfer data to the master then you should call
This can cause problems if a 3.3 V slave with two external pull- the method onRequest() instead of onReceive(). Again, the
ups to 3.3 V is connected to a 5 V Arduino. In this case it is name of the event handler function that will produce the data
essential to use a level-shifting circuit. to be sent is passed as a parameter. Since at the moment of
After initialization, data can be sent to the I2C slave in the calling the handler function the number of bytes to be sent is
loop() function. The following example sets the address pointer not known, no parameter is passed to it. The data bytes are
in the LM75 to point to the temperature register. sent using a single call to Wire.write().

void loop() { #include <Wire.h>


Wire.beginTransmission(0x48); void setup() {
Wire.write(byte(0x00)); Wire.begin(0x48);
Wire.endTransmission(); Wire.onRequest(transmit);
}
The following fragment reads from the LM75. void loop() {
while (1) delay(1000);
Wire.requestFrom(0x48, 2); }
c1 = Wire.read(); void transmit() {
c2 = Wire.read(); uint8_t msg[N];
} // Erzeuge msg[] Inhalt
Wire.write(msg, N);
As you can see, the Wire library requires that you first specify }
the number of bytes expected from the slave (in this case, 2).
The first call reads in the two bytes, and then the subsequent The two event handler set-up methods can be called together
calls allow you to access the received data. in the same sketch.
The Arduino Wire library can also be configured for operation
in slave mode. Again, the library must first be initialized. In #include <Wire.h>
this case the call to Wire.begin() must be given a parameter void setup() {
which is the desired slave address: it is the presence of this Wire.begin(0x48);
parameter that selects slave mode. It is also necessary to set Wire.onReceive(receive);
up an event handler which will be called whenever the Arduino Wire.onRequest(transmit);
is addressed as a slave. In the example below the event han- }
dler is called when the Arduino is to receive data.
Such a configuration would allow you to emulate an LM75
#include <Wire.h> accurately, using a 1-wire temperature sensor such as the
void setup() { DS18B20 instead of the LM75, or to emulate a real-time clock
Wire.begin(0x48); peripheral receiving time over DCF77 or GPS.
Wire.onReceive(receive);
} Coming up in part three
The next installment in this short series will look at some pop-
Although not normally necessary for a slave device, the call ular I2C peripheral devices: besides the LM75 temperature
to the Wire.begin() method again enables the built-in pull-up sensor we will also examine the PCF8574 port expander and
resistors. They can be disabled if necessary as described above. the RV-8523 real-time clock. Finally we will close with some
thoughts on troubleshooting using tools within the means of
Caution: note again that although a 5 V Arduino can be con- the average hobbyist.
figured as a slave to a 3.3 V master, there will be a brief pulse (160418)
to 5 V on the signal lines which may damage the 3.3 V master.
So, for example, if you want to operate an Arduino as a slave
Web Links
to a Raspberry Pi, you must make certain that the Arduino
is only electrically connected to the Raspberry Pi after it has [1]  http://homepage.hispeed.ch/peterfleury/avr-software.html
completed initialization. [2]  www.jtronics.de/avr-projekte/library-i2c-twi-slave.html (in
When a data byte is received, the event handler (which was German, English machine translation available)
configured to be receive in the above example code) will be [3]  https://en.wikipedia.org/wiki/Display_Data_Channel
called. Again the data bytes have already been read in, and
[4]  https://en.wikipedia.org/wiki/Serial_presence_detect
the number of bytes received is passed as a parameter to the
handler. [5]  www.elektormagazine.com/160148

www.elektormagazine.com July & August 2017 43


PCBs — Printed, not Etched
Presenting the Voltera V-One PCB printer
and reflow soldering station

By Karl-Ludwig Butte (Germany)

Figure 1. Side view of the Voltera V-One.

Etching your own PCBs used to be a real chem lab exercise. First you had to copy the PCB layout from film
to the PCB material by exposing, developing and fixing the photoresist. That involved a lot of chemicals, with
unpleasant odors and a good chance of splashes or spills. Now there’s an entirely new option: the Voltera
V-One can print circuit tracks, apply solder paste, and even solder the components in a reflow process.

The hassle of working with chemicals convinced many develop- PCB production with their V-One PCB printer, which could inspire
ers to stop making their own prototype PCBs. The trouble starts many electronics enthusiasts to start making their own PCBs.
already with the layout film, where you have to determine the That’s true twenty-first century technology — with the V-One
exposure and development times by trial and error. The goal is you print PCBs, apply solder paste to the board, and even
to find the best compromise between the darkness of the black solder manually placed components using a reflow process.
tracks and the lightness of the surrounding areas. Making the
tracks darker causes the surrounding areas to become gray, Hardware
with the result that the copper will not be fully etched away The V-One is a flatbed printer with three-axis control, and it
where it shouldn’t be left. If instead the surrounding areas fits easily on a benchtop (Figure 1). The mechanical structure
are nicely clear, the track density is not high enough and thin is illustrated in Figure 2. There is a base on which a movable
tracks in particular are sometimes etched away. bridge is mounted for the Y axis. A carriage with a tool holder for
Once you get the film prepared reasonably well, it is time for three different tool modules and a drive gear (carriage gear) is
the real work: exposing, developing and etching the PCB. If mounted on this bridge. This carriage travels along the X axis.
everything goes well, after removing the photoresist layer you The tool modules can also be moved vertically along the Z axis.
are rewarded with shiny copper tracks. We call this a printed The three tool modules shown in Figure 3 are a probe head, a
circuit board (PCB), but actually it should be called an etched print head for electrically conductive ink, and a print head for
circuit board (ECB). solder paste. The tool modules are simply attached to the tool
Now the Canadian start-up Voltera is poised to revolutionize holder by four strong magnets, making them easy to exchange.

44 July & August 2017 www.elektormagazine.com


Figure 2. Mechanical structure of the V-One. Figure 3. Tool modules of the Voltera V-One.

The PCB substrate material for printing (FR4) is secured to the


work surface by two clamp strips. A heating system is mounted
beneath the work surface. In addition to heat-setting the printed
tracks, it allows SMD components mounted on the PCB to be
reflow soldered in a subsequent operation. This means that
with the V-One you can not only make your own PCBs, but
also solder components on your boards, eliminating the need
for separate reflow oven. And because the V-One also applies
solder paste precisely on the pads, you do not need a stencil.
With the V-One, every electronics enthusiast can work with
SMD components easily and professionally.
The slots which guide the bridge along the Y axis are illumi-
nated by recessed strips of RGB LEDs (Figure 4). In addition
to being a visual attraction, they signal the temperature of the
work surface: red means “Hot! Don’t touch!” In that state the
work surface temperature can be as high as 250°C. When the
LEDs are blue, the thermal phase of baking or reflow soldering
has been completed and the board can be removed.
The printer has a USB interface, and at least for operation with
Windows a specific driver must be downloaded and installed
from the Voltera website.

Software
The associated software is a package comprising calibration, Figure 4. Operating mode indication: when the LEDs in the Y axis slots
control and printing software and a video user guide. The video are red, the work surface is very hot.
user guide in particular deserve praise: each step of the pro-
cedure is illustrated by one or more short videos on the right
side of the screen, and each action is shown in practice (Fig-
ure 5). The videos run continuously and help you understand
the illustrated actions on your own machine. It could hardly
be simpler or clearer.
Software is available for Microsoft Windows 7 (64-bit) or later
and for OS X version 10.11 or later. Unfortunately, a Linux ver-
sion is not yet available. The software can be updated at any
time, with no need for antiquated optical storage media. In
addition, the software checks for updates each time the pro-
gram is launched. If an update is available for the software or
the printer firmware, it is installed automatically.

Working with the V-One


The Voltera V-One processes exclusively Gerber files, which
can be generated by most modern PCB layout programs. Volt- Figure 5. The software package for the V-One includes video tutorials.

www.elektormagazine.com July & August 2017 45


Figure 6. The V-One at work: printed PCB tracks. Figure 7. Target and actual temperature curves for PCB track baking.

era has tested the Gerber dialects of Eagle, Altium, Upverter the previous one). According to the manufacturer, the con-
and KiCad. Gerber files are also available as downloads for ductive ink and the solder past should normally be kept in the
many Elektor projects. To make it easy to try out the printer refrigerator, and they should be taken out 30 minutes before
right away, Voltera kindly includes all necessary components the start of printing to allow them to adjust to room tempera-
for a small “Hello World” project. That consists of a simple ture. However, in my experience a considerably longer time
blinking light board with the well-known NE555 timer IC in of about two hours is advisable, because then the printing is
an SMD package. The PCB layout is already incorporated in much more uniform and above all free from gaps. If the test
the software and can be accessed by a special link in the pattern is okay, you can wipe it away with a paper towel and
Open File dialog. clean the board again with alcohol.
It is always fascinating to watch the printer at work (Fig-
Printing ure 6). Unlike ink jet printers, the print head does not scan
Standard FR4 glass fiber reinforced epoxy circuit board material back and forth over the surface of the board. Instead, it prints
is a suitable choice for the substrate. Along with a ten-pack of the tracks one after the other, just like a plotter, and finishes
blank circuit boards with dimensions of 2 × 3 inches and 3 × 4 them with solder pads.
inches, my V-One came with a shield for the Arduino Uno and
Mega. The maximum printing area is 138 × 102 mm (5.5 × 4
inch). In my experience it is a good idea to clean the board
with alcohol before printing, since traces of skin oil can lead Automatic PCB printing and
to broken PCB tracks. reflow soldering
The first step is to secure the blank circuit board in the middle
of the working area with the two metal clamp strips. In the
next step, the probe head outlines a rectangle on the board If the printing is not satisfactory in some places, which can hap-
within which the circuit will be printed. If the rectangle is not pen for a wide variety of reasons, you can select the affected
in the middle of the board or extends beyond the edge of the area on the screen and repeat the printing in that areas. For
board, you can adjust the position on the screen until every- this you can also adjust the ink supply if necessary.
thing is okay. You can also use this approach to print several
small layouts on the same board, for later separation into Baking
individual boards. Once the printing is completed, you can start the baking pro-
Once the position on the board is correct, the probe head scans cess in order to cure (harden) the freshly applied ink tracks.
the board to generate a height profile. The print nozzles for Until they are cured, you must be careful to avoid accidentally
the electrically conductive ink and the solder paste are very smearing the ink. For baking, the clamp strips are exchanged
thin and fragile. They must never be allowed to collide with the and the board is placed in the recesses of the clamp strips with
board surface, but they also should not float too high above the printed side facing down, so that the surface of the board
the surface, as otherwise the print quality will suffer. is held slightly above the working surface.
After the height profile has been generated, the probe head The baking process is initiated by the software and takes about
is replaced by the print head with the electrically conductive 40 to 50 minutes. During this time the target and actual tem-
ink. First a test pattern is printed with this head. It consists of peratures of the heating system are continuously plotted on
two serpentine lines and several parallel horizontal lines with the screen (Figure 7). The bridge guide slots also light up
a minimum separation of 0.8 mm. The minimum track width is bright red as a warning signal. Touching the printer during the
8 mil (about 0.2 mm). If the test pattern is not printed prop- baking process is not a good idea, because a temperature of
erly, you can adjust the ink flow in the software and then check 250°C can cause painful burns. To on the safe side, I placed
the new setting by printing the pattern again (after wiping off my V-One on top of a double layer of ceramic tiles.

46 July & August 2017 www.elektormagazine.com


Figure 8. The fully printed and polished PCB after track baking. Figure 9. After soldering by the V-One, the finished board is ready for
testing.

When the LEDs change back to blue, the heating system has temperatures in the range of 190 to 210 °C. The solder rec-
cooled down and the baking process is finished. Now you can ommended by Voltera (Sn62, or even better SnBiAg1) is well
safely remove the board. suited to this temperature range. The solder wire is so thin
A special plastic sponge is include with the V-One, and it must that there is no room for a flux core. The flux (for example,
be used now to polish the PCB in order to ensure reliable sol- ChipQuick SMD 291) must be applied separately before solder-
der joints later on. Figure 8 shows the fully printed and pol- ing. As I found out the hard way, that takes a bit of practice.
ished PCB.

Applying solder paste Summary


Before starting with the application of solder paste, you have The Voltera V-One definitively makes PCB etching a thing of
to mount the PCB back on the working surface, and then you the past. Once you have tried it, you can hardly imagine life
must tell the printer the precise locations of two reference without it as an electronics enthusiast. Particularly for hard-
points. That is easily done with the probe head in combination ware development, it is a major advantage to not have to wait
with the appropriate software functions. Then you replace the days or weeks for prototype PCBs from a service provider. The
probe head by the print head for solder paste and start the integrated reflow soldering capability is the icing on the cake
printing process. and makes SMD soldering a routine task. Although the PCB
printer is not exactly cheap (the Voltera list price is $2179),
Component placement and reflow soldering and neither are the associated consumables, in my opinion
Placing the components on the board is a manual task. Good they are all worth every penny.
tweezers are essential for this. Even so, you must be very (160384-I)
careful to avoid smearing any of the solder paste, and you
must ensure that polarized components such as electrolytic
Web Link
capacitors, diodes, ICs and so on are placed with the right
orientation. When all the components are mounted, you can [1] www.voltera.io
place the board in the middle of the working area and start
the reflow process (Figure 4). When the LEDs change back to
blue, the board is finished and ready for testing (Figure 9).
The connecting wires for the 9 V battery clip (on the left in
Figure 9) are soldered on afterwards, which brings us to the
next topic in this article.

Processing leaded components


In response to the question of whether the V-One can only
process SMD components, there is a clear answer: it can also
be used with leaded components. For this you must use the About the Author
corresponding solder pads (with a hole in the middle) in the Karl-Ludwig Butte studied Computer Science with
layout. After the board is baked and polished, the next step is specialization in economics at the Fulda University of
old-fashioned manual hole drilling and component placement, Applied Sciences in Germany and is presently active in IT
instead of solder paste application. However, electrically con- and process control in the automotive industry. In his free
ductive ink does not behave the same way as copper, so you time he enjoys working on electronics projects, as well as
have to get used to soldering on it. It is essential to use a computers of all types and the history of computers.
temperature-controlled soldering station which can be set to

www.elektormagazine.com July & August 2017 47


HOMELAB PROJECT

nWatch,
a Wearable Development System
or how to build your own smart watch

48 July & August 2017 www.elektormagazine.com


By Piotrek Wasilewski (Poland) Features
• ARM Cortex-M4
• Bluetooth Low Energy (BLE)
• Gyro, accelerometer and
Originally designed as a simple school-quiz-electronic-cheat-sheet, this
magnetometer
watch became pretty smart over time. And by evolving it into a more • MP3 player
useful device the author accidentally learned a few things along the way. • 3D printed enclosure
• Great learn project
So, cool gadget or fun educational tool? Build one yourself and find out.

The nWatch presented in this article is finally realized what I was doing wrong: is a member of the high-performance
a smart watch that doubles as a micro- I wanted to make a quite complex device foundation line from STMicroelectron-
controller development board. At the in a very short time. This really was a ics. It has an ARM Cortex-M4 core run-
start this project wasn’t really about a bad idea and so I decided to spend some ning at 168 MHz with a DSP and an FPU,
development board, but more for a sim- time to rethink the schematic, and redo there is 1 MB of flash memory, and a
ple watch to cheat at my school quizzes the PCB while aiming for as few bugs as galaxy of peripherals. The reasons for
about subjects that were — in my humble possible. After about two weeks of fixing selecting this device are several. First, it
opinion — not relevant. The first proto- issues, I came up with the final version. I has enough general purpose I/O (GPIO)
type was not very advanced, but it did had learned to think about a project first ports and buses to connect all the other
what it was designed for. Then I started before trying to draw the schematic or ICs to it. A special hardware memory
thinking about the possibilities of devel- design a PCB. This project also taught management unit (MMU) is present,
oping a device that would be useful and me to be patient. which is used to control the LCD and
allow me to learn something in the pro-
cess, and so I came up with the idea to
build a smart watch that doubles as a
microcontroller development board. This
turned out to be not so easy though. wake up Accellerometer
button RTC clock Gyroscope Bluetooth
When I started out I had limited knowl-
edge of electronics and only some basic
programming skills, the idea being that SRAM memory

I would acquire the necessary knowl-


edge along the way. The goal was to LCD panel
make the watch from parts accessible to DC-DC
backlight Main CPU Lipo
enthusiasts like me, available in shops STM32f407 converter
or through the Internet. In this article
Touch screen voltage
I will show you how I approached this divider
project and prove that anyone can build
Touch
a similar device at home. controller

Always start @ the beginning MP3 decoder Magnetometer microSD card


One day I woke up with the idea of build-
ing a tactile smart watch with a big LCD
and some other features like an MP3
Figure 1. Overview of the nWatch internals. It was not easy to cram all this into a wristwatch.
player, SD card, etc. But what to do with
such an idea? It is generally good prac-
tice to write down the things you want The nWatch hardware the external SRAM memory (IC10). The
to do, the pros and cons of the solutions Figure 1 shows the block diagram of MMU makes controlling things much eas-
you plan to adopt, the functions of the the nWatch, the schematic that closely ier than would be possible with inde-
device, and so on. In short, it all starts by follows the block diagram is shown in pendent GPIOs pins. The micro has fast
defining the specifications of the device. Figure 2. As you can see there are quite built-in RAM, and enough flash mem-
At first I thought I could skip this step a few blocks and I will discuss them one ory for my purposes. Using this micro
and just draw up a schematic and design by one in no particular order. also has one major drawback: its case,
a PCB for it. However, as it turned out which is pretty huge (relatively speak-
this first, naive version was so riddled The CPU ing, of course). Unfortunately there was
with mistakes that I was forced to make The heart of the nWatch is IC1, an STM- no other solution, because I didn’t want
a second one and then a third. Then I 32f407ZGT6 microcontroller. This micro to use a ball-grid array (BGA) package.

www.elektormagazine.com July & August 2017 49


S1 S1 +3V3 +3V3 +3V3 +3V3 +3V3 +3V3
SW3 SW3
MAIN CPU MAIN CPU
EXTERNALEXTERNAL
SRAM SRAM NOKIA DISPLAY
NOKIA DISPLAY
S2 S2 C7 C16 C7 C16 C19 C20 C19 C20 R19 L3 R19 L3 MEMORY MEMORY
SW1 SW1 11 33 11 33 3 22 3 22
VDD VDD VDD VDD

1k

1k
D0 6 D0 6

VAUX

VAUX
VIO

VIO
100n 100n 100n 100n100n 100n 100n 100n 10uH 10uH D0 D0
A0 1A0 1 7 D0
7 D0
C21 C21 A0 A0 IO0 IO0 D1 18 D1 18
A1 2A1 2 8 D1
8 D1 D1 D1
SWDIO SWDIO A1 A1 IO1 IO1 D2 8 D2 8 12 RST 12 RST
TP7 TP7 A2 3A2 3 9 D2
9 D2 D2 D2 !RESB !RESB

143

143
108
121
131
144
108
121
131
144
100n 100n A2 A2 IO2 IO2
32

30
39
52
62
72
84
95

25

33
32

30
39
52
62
72
84
95

25

33
SDWCLK SDWCLK D3 17 D3 17
17

17
TP6 TP6 A3 4A3 4 10 D3
10 D3 D3 D3
A3 A3 IO3 IO3

PDRON

VDDA
PDRON

VDDA
D4 9 D4
VDD
VDD
VDD

VDD
VDD

NRST
9
VDD
VDD
VDD

VDD
VDD
VDD
VDD
VDD
VDD
VDD

NRST
VREF+

VREF+

TP5 TP5 A4 5A4 5


IC10 IC10 13 D4
13 D4 D4 D4 K4 K4
37 37 6 BATT
6 BATT A4 A4 IO4 IO4 D5 15 D5 15
PA3 PA3 VBAT VBAT A5 18A5 18 14 D5
14 D5 D5 D5
128 128 21 FPC5
21 FPC5 A5 A5 IO5 IO5 D6 10 D6 10 1 1
PG13 PG13 PF9 PF9 A6 19A6 19 15 D6
15 D6 D6 D6 VLED1– VLED1–
129 129 22 FPC6
22 FPC6 A6 A6 IO6 IO6 D7 14 D7 14 23 23
PG14 PG14 PF10 PF10 A7 20A7 20 16 D7
16 D7 D7 D7 VLED2+ VLED2+
SWI SWI 35 35 26 26 A7 A7 IO7 IO7
PA1 PA1 PC0 PC0 A8 21A8 21 29 D8
29 D8 NOKIA LCD6300 NOKIA LCD6300
126 126 28 FPC1
28 FPC1 A8 A8 IO8 IO8 A16 19 A16 19 24 LED+ 24 LED+
PG11 PG11 PC2 PC2 A9 22A9 22 30 D9
30 D9 D/!C D/!C VLED1+ VLED1+
RST RST 36 36 46 BAT_ADC
46 BAT_ADC A9 A9 IO9 IO9 2 LED– 2 LED–
PA2 PA2 PB0 PB0 A10 23A10 23 31 D10
31 D10 VLED2– VLED2–
27 27 47 BACKLIGHT
47 BACKLIGHT A10 A10 IO10 IO10 CSB 11 CSB 11
PC1 PC1 PB1 PB1 A11 24A11 24 32 D11
32 D11 !CSB !CSB
A11 A11 IO11 IO11

GND_UNK0
GND_UNK1

GND_UNK0
GND_UNK1
45
TOUCH_INT TOUCH_INT 45 48 48 WRB 5 WRB 5
PC5 PC5 PB2 PB2 A12 25A12 25 35 D12
35 D12 WRB WRB
44 44 50 50A6 A6 A12 A12 IO12 IO12 RDB 20 RDB 20
R17 PC4
R17 PC4 PF12 PF12 A13 26A13 26 36 D13
36 D13 RDB RDB

GND
GND

GND
GND
MP3-MOSI 43
MP3-MOSI 43 53 53A7 A7 A13 A13 IO13 IO13
0R PA7
0R PA7 PF13 PF13 A14 27A14 27 37 D14
37 D14
SDIO_D0 SDIO_D098 98 54 54A8 A8 A14 A14 IO14 IO14 4 21 7 16 4 21 7 16
PC8 PC8 PF14 PF14 A15 42A15 42 38 D15
38 D15
SDIO_D1 SDIO_D199
PC9
99
PC9
IC1 IC1 PF15
55
PF15
55A9 A9 A15 A15 IO15 IO15
A16 43A16 43
SDIO_D2 111
SDIO_D2 111 56 56A10 A10 A16 A16
PC10 PC10 PG0 PG0 A17 44A17 CY7C1041DV33
44 CY7C1041DV33 17 WRB17 WRB +3V3 +3V3
SDIO_D3 112
SDIO_D3 112 57 57A11 A11 A17 -10ZSXI
A17 -10ZSXI
WE WE
PC11 PC11 PG1 PG1 A18 28A18 28 41 RDB
41 RDB
SDIO_CMD SDIO_CMD116 116 58 58D4 D4 A18 A18 OE OE
PD2 PD2 PE7 PE7 40 UB
40 UB
SDIO_CLK SDIO_CLK113 113 59 59D5 D5 UB UB 6 8 14 6 8 14
PC12 PC12 PE8 PE8 NE3 6NE3 6 39 LB
39 LB
DRDY- DRDY- 76 60 60D6 CE CE LB LB

VCC
76 D6

VCC
VIO

VIO
IN0

IN0
PB15 PB15 PE9 PE9
MP3_ON MP3_ON75 75 70 SDA
70 SDA GND GND GND GND TOUCH_INT 2TOUCH_INT 2 13 13
PB14 PB14 PB11 PB11 INT INT X+ X+ TP8 TP8
IR_LED IR_LED 74 74 79 79D15 D15 12 34 12 34 SCL 4 SCL
IC11
4
IC11 15 15
PB13 PB13 PD10 PD10 SCLK SCLK Y+ Y+ TP9 TP9
MP3-DREQ MP3-DREQ100 100 80 80A16 A16 SDA 5 SDA STMPE811
5 STMPE81116 16
PA8 PA8 PD11 PD11 SDAT SDAT X– X– TP10 TP10
49
DIVIDE_ON DIVIDE_ON 49 81 81A17 A17 3 3QTR QTR 1 1
PF11 PF11 PD12 PD12
LCD +4V1
LCD +4V1 A0/D0 A0/D0 Y– Y– TP11 TP11
SW2 SW2 73 73 82 82A18 A18

DATAIN

DATAIN
D1 D1
PB12 PB12 PD13 PD13 BACKLIGHT BACKLIGHT
STM32f407
STM32f407 SBR1A40S1 SBR1A40S1

GND

GND
SCL2 SCL2 136 136 87 87A12 A12
CONVERTER CONVERTER L2 L2

IN1
IN2

IN3
IN1
IN2

IN3
PB6 PB6 PG2 PG2
137 137 88 88A13 A13 9 11 10 12 9 711 10 12 7
PB7 PB7 PG3 PG3 C17 C1722uH 22uH
LCD_ON LCD_ON34 34 89 89A14 A14 R4 R14
R4 R14 R16 R16
PA0 PA0 PG4 PG4 2 12 1
D7 D7 63 63 90 90A15 A15
PE10 PE10 PG5 PG5 1u VIN1u SW
VIN SW
TOUCH TOUCH

1k

1k

1k
1k

1k

1k
D8 D8 64 64 91 BRTS
91 BRTS 3 3 LED+ LED+
PE11 PE11 PG6 PG6 OVP OVP CONTROLLER CONTROLLER
D9 D9 65 65 93 BLE_EN
93 BLE_EN 4 IC12
4 IC12
PE12 PE12 PG8 PG8 EN EN
D10 D10 66 66 96 BLE_TX
96 BLE_TX AP5724 AP5724 5 5 LED– LED–
PE13 PE13 PC6 PC6 R2 R2 FB FB
D11 D11 67 67 97 BLE_RX
97 BLE_RX R5 R5 +3V3 +3V3
PE14 PE14 PC7 PC7 GND GND C18 C18
10R

10R

D12 D12 68 68 101 VBUS


101 VBUS

10R

10R
PE15 PE15 PA9 PA9 6 6

R27
R28
R29
R30
R35
R36
R27
R28
R29
R30
R35
R36
D0 D0 85 85 102 SD_ON
102 SD_ON 100n
PD14 PD14 PA10 PA10 100n
D1 D1 86 86 103 DM
103 DM
PD15 PD15 PA11 PA11

1k
1k
1k

1k
1k

1k
1k
1k
1k
D14 D14 78 78 104 104DP BACKLIGHT
DP BACKLIGHT
PD9 PD9 PA12 PA12
D13 D13 77 77 105 SWDIO
105 SWDIO
PD8 PD8 PA13 PA13

R9

R9
SDA2 SDA2 140 140 109 SWCLK
109 SWCLK SD CARD SD CARD
PB9 PB9 PA14 PA14 BATT_BLE BATT_BLE
SCL SCL 69 69 110 MP3-DCS
110 MP3-DCS

0R

0R
PB10 PB10 PA15 PA15 Card SocketCard 4 K1Socket 4 K1
FPC2 FPC2 29 29 114 114D2 D2 2 2
PC3 PC3 PD0 PD0 VDD VDD
MP3-SCK MP3-SCK41 41 115 115D3 D3 VCC VCC SDIO_DO SDIO_DO 7 7
PA5 PA5 PD1 PD1 3 3 18 18 DATA_OUT DATA_OUT
1 1 117 CPU_ON
117 CPU_ON P2.2 IC2P2.2 P0.1IC2 P0.1 SDIO_CMD SDIO_CMD 3 3
PE2 PE2 PD3 PD3 4 4 17 BLE_TX17 BLE_TX DATA_IN DATA_IN
2 2 118 RDB
118 RDB P2.1 P0.2(RX)
P2.1 P0.2(RX) SDIO_CLK SDIO_CLK 5 5
PE3 PE3 PD4 PD4 BLE_RST 5
BLE_RST 5 16 BLE_RX 16 BLE_RX SCLK SCLK
3 3 119 WRB
119 WRB RST RSTP0.3(TX) P0.3(TX) SDIO_D3 SDIO_D3 2 2
PE4 PE4 PD5 PD5 6 6 15 BLE_INT15 BLE_INT CS CS
4 4 123 123 P2.0(EN) P0.4(BCTS)
P2.0(EN) P0.4(BCTS) SDIO_D1 SDIO_D1 8 8
PE5 PE5 PD7 PD7 DAT1 DAT1
SW3 SW3 5 5 124 CSB
124 CSB CC2540-BLE CC2540-BLE SDIO_D2 SDIO_D2 1 1
PE6 PE6 PG9 PG9 7 7 14 BRTS14 BRTS DAT2 DAT2
7 7 125 NE3
125 NE3 P1.7 P0.5(BRTS)
P1.7 P0.5(BRTS)
PC13 PC13 PG10 PG10 8 8 13 13 SD & MMC SD & MMC
8 8 127 127 USB+ USB+ P0.6 P0.6 CARD_DETECT CARD_DETECT CD1 CD1
TP14 TP14 PC14 PC14 PG12 PG12 9 9 12 12 CARD_DETECT CARD_DETECT
9 9 132 132 USB– USB– P0.7 P0.7 CD2 CD2
TP15 TP15 PC15 PC15 PG15 PG15 R18 10 R18 10 11 11 CARD_DETECT CARD_DETECT
A0 A0 10 10 133 133 P1.2 P1.2 P1.1 P1.1
PF0 PF0 PB3 PB3 GND VSS GND GND VSS GND
A1 A1 11 11 134 134 GND GND +3V3 +3V3
1k

1k

PF1 PF1 PB4 PB4 MT 6 MT1


MT 6 MT1
A2 A2 12 12 139 139 1 1
PF2 PF2 PB8 PB8
A3 A3 13 13 141 141LB LB
PF3 PF3 PE0 PE0
A4 A4 14 14 142 142UB UB
PF4 PF4 PE1 PE1 2 13 2 13
A5 A5 15
PF5
15
PF5 PA4
40
PA4
MP3-CS
40 BLE_INT_OUTBLE_INT_OUT
MP3-CS BLUETOOTH 4.0
BLUETOOTH 4.0 VDD VDD_IO VDD VDD_IO
18 18 42 MP3-MISO
42 MP3-MISO WITH WITH 4 4 12 12
PF6 PF6 PA6 PA6 T3 T3 S1 S1 SETC SETC
FPC3 FPC3 19 19 135 MP3-RST
135 MP3-RST
INTERRUPTINTERRUPT
TRANSISTOR TRANSISTOR SCL SCL 1 IC7
1 IC7
PF7 PF7 PB5 PB5 R11 R11 SCL SCL C24 C24
FPC4 FPC4 20 20 122 122 BLE_INT DRDY–
BLE_INT 15
DRDY– 15
PF8 PF8 PD6 PD6 4k7 4k7 DRDY– DRDY–
138 138 92 92 R21 R21 SDA SDA16 16 1u
BOOT0 BOOT0 PG7 PG7 LED1 LED1 SDA HMC5883L SDA HMC5883L 1u
BSS84 BSS84
VCAP1

VCAP2
VCAP1

VCAP2

10 10 8 8
VSSA

VSSA

C1 C1 SETP SETP
1k

1k
VSS
VSS
VSS

VSS
VSS
VSS
VSS
VSS

VSS
VSS
VSS
VSS
PH0

PH1
PH0

PH1

TP3 TP3 GND GND GND GND


R20 R20
BATT_BLE BATT_BLE
38
51
61
83
94

23

24

71

31
38
51
61
83
94

23

24

71

31
107
120
130

106
107
120
130

106
16

16

C6 C1 C6 C1 C22 9
C22 11 9 11
TP4 TP4
1k

1k

1u 1u 1u 1u 4u7 4u7 MAGNETOMETER


MAGNETOMETER
OSC2

OSC1
OSC2

OSC1

R24 R24 MCP1703T MCP1703T


1M 1M CHARGINGCHARGING
CIRCUIT CIRCUIT IC4 IC4
3 3 2 BATT_BLE
2 BATT_BLE
3 X2 3 X2 IC3 IC3
USB CONNECTOR
USB CONNECTOR +4V1 +4V1
VBUS VBUS C10 C10 OUT OUTC11 C11 VBUS 4 VBUS 4 3 3
K2 K2 VIN VBAT
VIN VBAT
1 TRI 1 TRI +4V1 +4V1 1 1
1 1
L4 L4 22p 22p 22p 22p
MCP73831 MCP73831
VBUS VBUS DM DM STAT 1 STAT 1 5 5
2 2 STAT PROG
STAT PROG
D– D– 10uH 10uH VSS VSS MCP1703T MCP1703T
3 3 R38 R38 R23 R23
D+ D+ L5 L5DP DP 2 2 C9 C3 C9 C3 IC5 IC5
4 4 CPU CRYSTAL
CPU CRYSTAL 3 3 2 BATT
2 BATT
ID ID
5k6

VDD GND VDD 16 MHz


5k6

GND
1k

1k

10uH 10uH 16 MHz


5 5 1u 10u 1u 10u
GND GND 4 2 4 2 VOLTAGE REGULATORS
VOLTAGE REGULATORS
FOR SLEEPFOR
MODE
SLEEP MODE 1 1
USBAB USBAB

Figure 2. Besides some resistors and capacitors, the schematic does not add much to the block diagram.

50 July & August 2017 www.elektormagazine.com


External SRAM and microSD card
V+ V+ There are two external memories in the
MCP1703T-1V8
MCP1703T-1V8
IC13 IC13 nWatch, an SRAM chip and an SD card.
SUPPLY 3
SUPPLY 3 2 2

5 7 24 31
5 7 24 31
The SRAM IC10 was not originally
1 1
CRYSTAL, CRYSTAL, planned, but it eventually proved nec-

CVCCO
CVCCO
CVCCO
CVCCO
CVCCO
CVCCO
CVCCO
32 32 15 15 TURN ON TRANSISTOR
TURN ON TRANSISTOR
TEST TEST VCO VCO
AND VOLTAGE
ANDREGULATOR
VOLTAGE REGULATOR essary to handle the display in a com-
FOR MP3 DECODER
FOR MP3 DECODER
6 6 33 33
14
IOVCC0
14
IOVCC0 GPIO0
34
GPIO0
34
fortable way because the CPU’s internal
IOVCC1 IOVCC1 GPIO1 GPIO1
SUPPLY SUPPLY
19
IOVCC2
19
IOVCC2 GPIO2
9
GPIO2
9 RAM is not large enough to handle the
38 38 10 10
43
AVCC0
43
AVCC0 GPIO3
36
GPIO3
36 memory requirements of the STemWin
AVCC1 AVCC1 GPIO4 GPIO4
45
AVCC2
45
AVCC2 GPIO5
25
GPIO5
25
graphics library (see below). IC10 is used
11 11
GPIO6 GPIO6
MP3-RST MP3-RST 3
RESET
3
RESET GPIO7
12
GPIO7
12 as a screen buffer for the LCD. All screen
MP3-CS MP3-CS 23
CS
23 IC14
CS IC14 4 modifications are applied to the buffer
4
MP3-DCS MP3-DCS 13 13 GND0 GND0
DCS DCS 16 16
MP3-SCK MP3-SCK 28
SCLK
28
SCLK
GND1
20
GND1
20
held in this memory before it is trans-
MP3-MOSI MP3-MOSI 29 29 GND2 GND2
MP3-MISO MP3-MISO 30
SI
30
SI
GND3
21
GND3
21 ferred to the display’s buffer. Notice that
SO SO 22 22
MP3-DREQ MP3-DREQ 8
DREQ
8
DREQ
GND4
35
GND4
35
this memory is not as fast as the micro’s
GND5 GND5
K3 K3
46 46 37 37 built-in RAM, and it is good practice to
LEFT LEFT AGND0 AGND0
39
RIGHT
39
RIGHT AGND1
40
AGND1
40
keep all the allocated stacks (FreeRTOS
41 41
VS1053 VS1053
AGND2 AGND2
42
GBUF
42
GBUF AGND3
47
AGND3
47 memory, etc.) in internal memory to
R33 R41 R33 R42 R41
1 1
R42 26
RX
26
RX
make the CPU work as fast as possible.
MIC+/LINE1 MIC+/LINE1 27 27
TX TX The external SRAM is connected to the
1M

1M

1M
1M

1M

1M

2 2
MIC– MIC– C12 C12
48 48 44 44
C15 C13 C15 C14 C13 LINE2
C14 LINE2 RCAP RCAP
same bus as the LCD and is controlled
XTALO XTALI
XTALO XTALI 100n 100n
47n 10n 47n 10n 10n 10n 17 18
17 18 by the CPU’s flexible static memory con-
R15 R15
SUPPLY SUPPLY
1M 1M troller (FSMC).
T1 T1 +4V1 +4V1 +4V1 +4V1
C5 X1 C5 3 X1 3 C4 C4
R6
0R
R6
0R
The second external memory is the
OUT OUT
22p 22p TRI 1 TRI 22p
1 22p
non-volatile SD card (K1). I opted for
R26 R26 +3V3 +3V3
R3 +3V3
R3 +3V3
BSS84 BSS84
0R 0R
an SD card because you can remove it
4k7

4k7

+3V3 +3V3 R1 R1
easily and connect it to a computer or
16.288 MHz 16.288 MHz
MP3_ON MP3_ON VDD GND VDD GND 0R 0R
smartphone to upload a new image or
4 2 4 2
text file. This part is a leftover from the
+3V3 +3V3
first versions of the cheat watches. At the
BATT BATT time I didn’t know how to upload cheat
VCC VCC
BATT_BLE BATT_BLE
VBAT VBAT XI XI
R31 R32 R31 R32 sheets to my watch other than by using
R12 R13 R12 R13 IC9 IC9 X3 X3
an SD card. It is connected through a
4k7

4k7

WDI
4k7

4k7

WDI
13 8 13
8
C23 C23
4k7

4k7

AF
4k7

4k7

AF
EXTI EXTI XO 32.768 kHz
XO 32.768 kHz
SDA2 24
SDA2
VDD
24
VLOGIC
VDD
20
2n2
VLOGIC
20
2n2 fast SDIO bus which allows reading and
SDA SDA SDA SDACPOUT CPOUT
SDA SDA R7 R7 SCL2 23
SCL2 23IC8 IC8 writing files much faster than over SPI.
SCL SCL BATT_BLE BATT_BLE SCL SCL
SCL AB0805 AB0805
SCL NTIRQ 1k
NTIRQ 1k MPU_INT 12
MPU_INT 12 10 10
INT INTREGOUT REGOUT
CLKOUT CLKOUT
R8 R8 1 1
RTC_INT RTC_INT CLKIN CLKOUT
CLKIN C2
CLKOUT C2
FOUT NIRQ2
FOUT 1k
NIRQ2 1k 100n 100n
GND GND MPU-6050 MPU-6050
6 6 7 7
AUX_DA AUX_CL
AUX_DA AUX_CL
R34 R34
11 11 9 9
RTC_INT_OUTRTC_INT_OUT FSYNC FSYNCAD0 1kAD0 1k

T2 T2 GND GND
18 18
R10 R10
RTC_INT RTC_INT
4k7 4k7
RTC CLOCKRTC CLOCK
BATT_BLE BATT_BLE BSS84 BSS84 WITH WITH GYROSCOPE AND ACCELEROMETER
GYROSCOPE AND ACCELEROMETER
INTERRUPTINTERRUPT
TRANSISTOR
TRANSISTOR

TP12 TP12 copyright


BT BT +4V1 +4V1
SMD PAD SMD PAD

+4V1 +4V1
VOLTAGE DIVIDER
VOLTAGE DIVIDER Figure 3. The Nokia 6300 display is still
TP13 TP13 R39 R39 available on the Internet.
Li-Ion Li-Ion
1k

1k

SMD PAD SMD PAD DOWN CONVERTER


DOWN CONVERTER
+3V3 +3V3 T4 BSS84T4 BSS84
AND CPU ON LINES
AND CPU ON LINES
S3 S3
T5 T5
SW2 SW2 4 4 5 5
VIN VFB/VOUT
VIN VFB/VOUT
IC6 IC6
L1 L1 R40 R40
R22 R22
The display
DIVIDE_ON DIVIDE_ON
D5 D5 1k 1k
MPU_INT
D2
MPU_INT
D2
1
MCP1603T MCP1603T
1 3 3
Actually the display is the reason for the
3k3

3k3

SHDN LX
SHDN LX
4uH7 4uH7 BSS123 BSS123
D3 D3
GND GND
C8 BAT_ADC
C8 BAT_ADC
letter ’n’ in ‘nWatch’, as it was scavenged
RTC_INT_OUTRTC_INT_OUT 4x 4x 2 2
SBR1A40S1SBR1A40S1
R25 R25 from an old Nokia 6300 mobile phone
D4 D4 1u 1u
BLE_INT_OUTBLE_INT_OUT (Figure 3). Having picked this display
4k7

4k7

CPU_ON
R37
CPU_ON
1k
R37
was no accident. It is quite easy to con-
1k
160326 - 11 160326 - 11
trol as it uses an 8-bit parallel bus; it is
cheap (less than $5); and it has a con-
nector that is not unthinkable for use
by an amateur. Furthermore, it has the
right size. It is small enough for a watch

www.elektormagazine.com July & August 2017 51


and large enough to allow finger move- Touch panel controller
ments (and a touch panel) to control the To interface with the resistive touch panel
watch. Reverse engineering the display I opted for the distinguished STMPE811
seemed not too hard — on the Internet from STMicroelectronics (IC11). It can
I found articles describing how to com- talk to the MCU over SPI or I2C (used in
municate with the display, and even the this case), and has many registers allow-
datasheet of the LCD controller ended up ing in-depth control of the touch panel.
on my hard drive. Although these prop- Different parameters can be adjusted to
erties had convinced me to use the Nokia adapt the touch screen to the display you
display for my watch, I did do a proto- are using. It also has some interesting
type with one of those popular ILI9320- hardware features like window tracking
based TFT LCDs. At the time I thought or temperature measurement. It can
that the display would be much faster if generate an interrupt on touch, informing
I used a 16-bit bus instead of 8-bit, and the CPU that it can read the coordinates
also the ILI9320 controller chip has more instead of doing periodic register reads. Figure 4. Thanks to a dedicated decoder IC the
built-in features. However, this experi- nWatch can be used as MP3 player.
ment, albeit interesting, didn’t satisfy Backlight
me. It turned out that the LCD had poor The AP5724 from Diodes Inc., IC12, is
viewing angles and I found the colors a small white LED step-up converter in Transistor (T1) is used to switch the
on the pale side. Maybe my TFT was a 6-pad DFN package that controls the decoder on and off to save power.
not of the best quality, I don’t know, brightness of the LCD. Being a step-up Figure 4 shows the nWatch MP3 player
but this experiment made me decide to converter it needs a few external com- application.
stick to the Nokia display. OK, I know it ponents like a power inductor (L2), a
is not the fastest gun in town, but it is Schottky diode (D1), and capacitors (C17 Bluetooth Low Energy (BLE)
good enough for simple user interfaces. & C18). It is controlled by a PWM signal The Bluetooth module (IC2) used in the
Remember that the way the display is from the CPU. It is able to drive up to nWatch is based on Texas Instruments’s
drawn also highly influences the speed. six LEDs, and since the Nokia display has Bluetooth LE CC2540 chip, and can be
Drawing it pixel by pixel will be much only two, it is perfect for the job. Resis- used to send and receive data from a
slower than transferring big chunks of tor R5 determines the maximum current smartphone. This allows you to display
data using Direct Memory Access (DMA). through the LEDs. notifications, or to update the time and
The LCD connects to connector K4. date from the phone. I chose this mod-
MP3 player ule mostly because it was a great com-
Adding a touch panel In the first two prototypes the main CPU promise between price and size. The
Having a touch panel was one of the was responsible for playing music files. range depends on many factors, and
main objectives of the project. However, An external digital-to-analog converter can also be changed by setting the reg-
finding a touch panel that fitted my spec- (DAC) was used to drive the earphones. isters responsible for the transmitting
ifications was pretty difficult and, even Only WAV files were supported, and power. The range is actually quite good
though I succeeded, now, in hindsight, everything — like file reading, header for a small PCB antenna. The module can
I even consider this a big drawback as it parsing, etc. — was done in software. wake up the micro when data is being
seriously compromises reproducing the MP3 support would be nice, but since I received; data is transferred between the
nWatch. didn’t like too much the idea of decoding micro and the BLE module over a simple
MP3 files myself in software, I looked for serial connection.
The first panel I tried was from a 2010 another solution. This search led me to An inconvenience of this module is that it
Nokia C3 phone. This is a perfect match the exquisite VS1053 from VLSI Solu- draws significantly more current when it
for a 2.2” N82 LCD, which is a larger and tion (IC14), which can decode and play remains connected. It is therefore better
almost fully compatible brother of the different file formats (Ogg Vorbis, MP3, to disconnect after every data exchange
Nokia 6300. Although it was resistive, AAC, WMA, FLAC, it even plays MIDI files) and only reconnect when needed.
its sensitivity was rather good. Unfortu- — all you have to do is send them to the
nately, it was too large for a wristwatch chip over SPI. This chip not only does the Sensors
and it didn’t fit the 2” Nokia 6300 dis- hard work, it also provides functions to The nWatch is equipped with three posi-
play. After many hours of surfing and control the sound (volume and tone con- tion sensors which I chose for being
searching the Internet, I finally found a trol, etc.), and it has an on-chip head- really popular among e-enthusiasts and
suitable touch screen on Aliexpress. Its phones amplifier. In short: the perfect so there are a lot of open-source libraries
size was perfect for my display, but its solution. Thanks to IC14, all the CPU has for them on the Internet. It’s a “tradi-
sensitivity was not impressive, requiring to do is periodically send chunks of data tional” set of a gyro, accelerometer and
strong finger presses and taps. Although to the decoder chip. magnetometer.
I use this panel in the current nWatch, The VS1053 is quite small, and only The first two sensors are combined in
I’m not happy with it, and I would like needs a few capacitors, a few resistors IC8, the MPU6050, a six-axis motion
to replace it by a capacitive touch panel. and a quartz crystal. It requires 1.8 V for tracking device from InvenSense. It com-
The four touch panel wires go to TP8 the core (CVDD), which led to the addition municates with the CPU over an I2C bus,
to TP11. of voltage regulator IC13 to the board. and has a separate LDO voltage regula-

52 July & August 2017 www.elektormagazine.com


tor to power it even when the main DC/ combined gyro and accelerometer (IC8), a micro USB connector (K2) and a 3-pin
DC converter is off. The interesting thing the RTC (IC9) and the BLE module (IC2) pinheader (TP5, TP6 & TP7) used to pro-
of this chip is that it has an on-board respectively. gram the microcontroller with an ST-Link
programmable digital motion processor IC6, an MCP1603 from Microchip, is a programmer and/or debug the running
(DMP). Consequently we can change its high efficiency 500-mA, 2.0-MHz syn- program. This is the best and fastest way
firmware, and let it do some calculations, chronous buck regulator intended for bat- of programming the watch.
freeing up some processing power of the tery-powered applications, exactly what The micro USB connector is used to
main CPU. The firmware is uploaded to was needed here. An inductor (L1) and charge the Li Po battery and allows
the sensor just before the initialization. a capacitor (C8) is all that is needed to exchanging some data over USB. When
Doing so gives the sensor more functions make it fly. connected to a computer (Windows,
like tap and free-fall detection. Interrupts IC4 and IC5, two LDO voltage regula- Linux or Mac OS) the nWatch is detected
can be generated for such events and can tors provide power to the parts that are as a mass storage device (MSD), and
be used to wake up the CPU. always on (unless the battery dies): IC2, the contents of the SD card are dis-
The 3-axis magnetometer is the popular IC8 and IC9. IC5 also provides power played. The USB port also provides a
Honeywell HMC5883 (IC7), a small chip to the CPU to prevent that it will lose its way of uploading programs to the watch
in a QFN package that also communicates battery-backed memory registers when thanks to its built-in bootloader. This is,
over an I2C bus, but not the same as IC8. the 3.3-V rail is switched off. These reg- however, much slower compared to using
The reason for this is that I wanted to isters are a special protected area of CPU the external programmer. For USB pro-
keep traces as short as possible to avoid memory where data is held as long as gramming the executable (HEX or BIN)
placing unnecessary space-hungry and there is a high-enough voltage on sup- file must first be converted into a special
hard-to-solder vias. Since the CPU has plied to its VBAT pin. DFU (device firmware update) format. It
two I2C ports, I simply wired the sensors IC4 powers the BLE module so that it is not possible to do any debugging over
to the I2C bus nearest to them. will not interfere too much with the rest USB, so treat USB programming more
of the circuit. like an additional feature instead of your
Real-time clock As mentioned before, LDO voltage regu- preferred software development port.
Imagine you want to set an alarm to lator (IC13) provides 1.8 V for the core
remind you of some upcoming event. If of the MP3 decoder (IC14). The PCB
this event is too far away in the future R22 and R25 form a voltage divider The shape of the PCB is adapted to the
and the watch is left on, it will run out of allowing the CPU to measure the bat- 3D-printed case and to the 3.5-mm jack
power before reaching the event. This sit- tery level. This divider can be switched connector. To make the watch as thin as
uation can be greatly improved by using off by T4 and T5 in order to save power. possible I mounted the jack connector
a low-power real-time clock (RTC) with “in” the PCB instead of on it. Doing so
alarm functions. Now all you have to do Li Po battery with charger saves a lot of space, allowing the watch
is setup the RTC’s alarm before switching The nWatch is powered from a 150 mAh case to be less thick.
the watch off. Once the RTC reaches the Li Po battery. Although it is small, it Even though the PCB is routed with
alarm date and time, it will switch on the allows the watch to sleep on it for more rather thin traces (≥6 mil) it is possible
voltage regulator IC6 (by means of tran- than a week. In case you actually use the to make it at home using the standard
sistor T2) and the watch will come alive. watch for checking the time every once photo-resist method. Doing this, how-
A good RTC that I found is the AB0805 in a while, one battery charge will keep ever, is something for the do-every-
from Abracom (IC9). It has an I2C inter- the watch running for at least five days. thing-yourself (DEY) die-hard because
face and consumes around 50 nA, much The battery is equipped with a PCM (pro- soldering the 200 or so vias by hand is
less than the CPU in deep sleep mode tection circuit module), which protects it not for the fainthearted.
would ever attain. against short circuits and deep discharge. The microcontroller in its large, 144-pin
When the battery is fully discharged the LQFP takes up a lot of PCB real estate,
Power supply PCM disconnects the battery from the making the board quite dense and I don’t
The nWatch being a wearable wristwatch, rest of the circuit until a charger is con- believe that I could have made it any
it had to be as low power as possible. A nected. When this happens all memory smaller. At some point I thought about
step in the right direction was to allow is cleared, including the one of the RTC switching to a 4- or even 6-layer PCB
the 3.3-volts supply to be switched off that holds the date and time. To make with the main chips in BGA packages, but
altogether. To make this happen I used restoring data easy I wrote a simple app I did not pursue this idea as the nWatch
a voltage regulator (IC6) with an enable for my smartphone (see below). was supposed to become a low-cost
pin (SHDN) that controls the output of Battery charging is controlled by a development board for hobbyists, not just
the device. There are four ways of switch- single-cell charger IC, the Microchip an expensive prototype. Smaller parts
ing the watch on (again). The most obvi- MCP73831 (IC3), which handles the would also make board assembly much
ous and easiest-to-implement technique charging process automatically. It harder, while using BGA packages would
is by pressing pushbutton S3. When the only needs a resistor to set the charge require special equipment. I therefore
button is pressed a positive voltage is current. decided that a two-layer board had to do.
applied to the SHDN pin through D5 and The position of the components on the
the regulator turns on, powering on the Connectors PCB is essential when you design a
rest of the circuit too. D2, D3 and D4 ful- The nWatch has three main connectors: watch, because space is at a premium.
fill the same functions as D5 but for the a microSD card slot (K1) on the bottom, Try to put all the components with simi-

www.elektormagazine.com July & August 2017 53


Figure 5. For a thin assembly the Li Po battery Figure 6. 3D renderings of the watch case.
is placed on top of the SRAM chip.

lar heights on the same side of the PCB. version and see where you went wrong The watch looks best when printed with a
If you mix them on bottom and top, the when you try to assemble everything. low layer height, meaning that the verti-
tallest part on each side determine the You are probably going to need at least cal step size should be really small. With
overall PCB height. A Li Po battery is three or four iterations to get it right. a 0.2 mm z-axis step size I obtained sat-
also a problematic part. If you can, it is Deciding to build a watch does not isfying results. My Prusa Mendel Itera-
the best to put it in a milled slot in the make things any easier as they tend to tion 2 (I2) 3D printer proved to have a
PCB. When this is not possible due to be rather small and thin. It starts by good-enough resolution and stability to
the small board surface a possible solu- drawing a rough, overall shape for the print a pretty nice case, showing that
tion is to make an area with only really watch, while keeping in mind the sizes most 3D printers will be suitable for the
flat components like resistors, etc. In my of the PCB, the Li Po battery and the LCD job as the parts are rather easy to print.
case I had no choice but to put the SRAM with touch panel. Then you measure, try,
memory under the battery (Figure 5). curse and iterate until it all fits. Building your own nWatch
It was the best compromise because it The parts that make up the nWatch case 1. Get all the parts
is only 1 mm thick. Other elements, like were designed in Solid Edge (Figure 6). Start by collecting the components, and
the 3.5 mm jack connector or the USB Initially, the idea was to make the case preferably with the hard-to-get compo-
socket, may be “mid” mounted, mean- at least splash-proof, but it turned out to nents. That way you quickly know where
ing that they are hanging in a cut-out in be too hard to make all the connectors you stand. Apart from the touch panel,
the PCB. Doing so keeps the height of waterproof (especially the SD card slot). which is probably the trickiest part of
the board within bounds. I had a few other ideas but eventually the nWatch, there are a few other com-
decided to make a two-part enclosure, ponents that may give you a hard time
3D printed parts held together by four tiny screws. This is finding them. The “mid-mount” 3.5-mm
3D printing is easy, the hard part is cre- a good solution, because after removing audio jack connector is such a part. I
ating the 3D models of your design. Not the screws we have an easy access to recovered it from an old tablet or smart-
only does it have to look nice, especially the main board, the Li Po battery, and phone of which the exact model and ref-
when you are designing a wristwatch, the LCD with its touch panel. erence elude me, used it in my prototype,
but the circuit board with all its parts The watch case has two rectangle slots and then wasn’t able to find a drop-in
has to fit in it too. Unfortunately, I have for the buttons. The wake-up button is replacement on the Internet. Those you
not discovered a magical solution to this the biggest, so it is easy to press it and can find either have a slightly different
problem, it still boils down to precisely is placed above the watch band mount. footprint, an incompatible plastic cover
measuring everything, 3D print a first The buttons are 3D printed as well. or both. However, it is possible to adjust

Figure 7. Several board iterations were needed before arriving at the final design of the nWatch.

54 July & August 2017 www.elektormagazine.com


the cut-out in the PCB with a tiny file, or
connect the pads with bits of wire.
The pushbuttons are less problematic,
but may also be hard to find. I don’t
have an exact reference for them, just
the dimensions. The best way to proceed
is by comparing the dimensions and the
way they look.

2. Assemble the PCB


Once all the parts collected and the naked
PCB ready on your desk, you can start
the board assembly (Figure 7). Solder-
ing most parts on the PCB shouldn’t be
very hard as long as you use a small
soldering iron. The tiniest parts are the
0402 resistors and capacitors, which
need a bit of practice to solder. A hot-
air station is more or less required for
mounting the SMD quartz crystals and
Figure 8. Assembled prototype with display and touch screen attached.
chips in QFN packages with their pads
on the bottom of the package. There is
nothing to be afraid of when you first deal
with QFNs. If you prepare things well, Case assembly is really simple (Fig- strap you like, but don’t forget that you
all you have to do is to position the chip ure 9). With a piece of sandpaper grind also need two of those watch strap spring
roughly and apply heat to it; it will align the surfaces where the two main body bars.
all by itself. Remember not to keep the parts will meet. This is essential for
heat on for too long to prevent the part obtaining a perfect fit. Also it is a good Software
from burning. The rest is nothing more idea to drill out the holes in the bottom Software is a very essential part of every
than normal SMD soldering. Make sure part and in the band holder, because development board, and, of course, of
to check that all the pins of the larger after printing they are usually a bit a smart watch also. While I was devel-
ICs (micro, VS1053, etc.) are soldered obstructed with printing filament. Then oping and building different versions of
correctly. Sometimes they look soldered, insert the side button followed by the the hardware, I also wrote some code
but in reality they hang a little above the PCB (remember to remove the microSD to control the watch and adapted many
PCB surface without touching the pad. card first). Place the wake-up button in libraries to work on the watch.
its slot, and cover everything with the
3. Put it all together top part of the case. Insert and fix the User interface with STemWin
After assembling the PCB you should four screws, and there you are. One of the most important libraries
check if there aren’t any short circuits. For the watch strap or bracelet it should for the nWatch is STemWin. This is a
Once you are sure about your soldering be possible to use any standard-sized graphics library that controls the LCD,
work, connect the battery and stick it to
the PCB on top of IC10, the SRAM chip.
My touch panel came with adhesive
tape on the panel edges, so I just had
to remove the protecting film and stick
it on the LCD. What may cause some
problems, however, is the connection to
the PCB. Different pin-outs on different
touch panels may require guessing the
order of the four pins. In my case I had
to cross two wires to make it work prop-
erly. Luckily, wiring it up the wrong way
doesn’t do any harm, so take as many
guesses as you needed to get it right. If
the coordinates are reversed, or touches
are not detected, simply swap wires until
it works as expected (Figure 8).
After soldering it to the main board, just
put the LCD connector in place and put
the display on the other side of the PCB,
covering the battery. Figure 9. Stack the parts like this for the final assembly.

www.elektormagazine.com July & August 2017 55


component list

PCB pictured at 150% of actual size

56 July & August 2017 www.elektormagazine.com


and draws all the elements of the user nese developer well-
interface. Based on Segger’s emWin, it known for his popular
is supported by STM (the manufacturer FatFS and petit FatFs
of the MCU) making it is easy to adapt to libraries that are so
any STM32-based device. On the Internet very useful when
you can find a lot of different examples using SD cards in
and full documentation. embedded systems.
Looking at the sample programs, the Since TJpegDec was
screen elements such as buttons and designed for small
text boxes will remind you of the old microcontroller sys-
Windows look. However, and fortunately, tems, it does not
these parts of the interface are fully cus- require as much
tomizable, the reason why this library is memory as libjpeg.
so interesting. Together with the library It is fast enough to
you get several utilities that help you to render for instance
create the interface look and feel you a photo gallery,
want. GUIBuilder is, in my opinion, the but playing a video is pushing things
most useful tool of all. It allows you to too far. ate HAL functions but I have no
design a screen, and generate the code experience with it, so you are on your
for it to add to your project. For sure, this The hardware configuration & ST own here.
intuitive tool is a real time saver. libraries
The STM low-level libraries, although Integrated development
Multitasking with FreeRTOS very complete, do not have a good rep- environment
This free, real-time operating system utation. Some users feel that they are The integrated development environment
(RTOS), well-known to hobbyists and inefficient and think that bare-metal pro- (IDE) that I initially used for writing the
professionals alike, controls the watch. gramming is the only way to go, oth- nWatch software was CoIDE from Coo-
Thanks to its multitasking capabilities ers only use the standard peripheral Cox. I chose this IDE because I wanted
several applications can run simultane- library. A general consensus has never unlimited code size and an Eclipse-like
ously. It allows you to set task priorities, been reached. Personally I had no diffi- interface. I have no complains about the
put tasks to sleep, give them a certain culties in using these libraries, although IDE itself, but it seems to be a bit for-
time to work and much more. I will not I sometimes had to configure a hardware gotten by its creators. The last version
go into detail here because it is really register myself, for instance in the case that was released is buggy and I was
well-documented software, please con- of periodically called function that has to obliged to stick to the previous version.
sult the Internet if you want to find out execute fast (like a DMA transfer). If you In the end I switched to Attolic’s True-
more about it. are using the latest hardware abstrac- STUDIO which seems to be continuously
tion layer (HAL) library from STM, you improved and supported. There are some
Play animations with libjpeg will have to adapt my code to add all the other programming environments that
Another classic library I used is libjpeg, a needed header files, etc. Some people you can use, including a bare Eclipse
library to decode JPEG files. I used it for have started using the STM32CubeMX with toolchain, but they sometimes have
playing simple movies on the watch. Its initialization code generator tool to cre- code size limitations or are only available
main advantage is its speed; it allowed
me to achieve up to 21 frames per sec-
ond (FPS) with 240x320-pixel frames. About the Author
However, it also has an important draw- Peter (Piotrek in his homeland) is a 19-year-old highschool student living in
back: it needs a lot of stack memory Poland. He is an embedded systems enthusiast and enjoys microcontroller
as it was originally a library developed programming, especially AVR and STM32 types. He started his electronics
to promote the JPEG standard. In cases career with building sumo robots for competitions, and recently got interested in
where you need really fast JPEG decod- wearable technology. Time permitting he also likes to build RC planes.
ing and you do not have to care about
memory usage, this is the right library Fast Forward Award 2016
to use. In situations where memory is
The nWatch was one of the entries for the Elektor Fast Forward Award organized
an issue it is better to use for instance
by Elektor in collaboration with the governors of the 2016 electronica tradeshow in
the TJpgDec library.
Munich. It was a great opportunity for hobbyists and professionals alike to share
and present projects, products and startups.
Low memory-footprint graphics
The author of this article presented the nWatch project to an international
library
professional audience and jury. This gave him the opportunity to meet several
In situations where the libjpeg library is
manufacturers to discuss the components used in the watch. Many opinions and
not suitable, you can use the Tiny JPEG
suggestions from other participants and visitors made Peter leave as a happy
Decompressor library TJpegDec. This tiny
man with a head full of new ideas. The fact that he won third place in the FFA’s
library, optimized for small, embedded
Prototyping category only made his smile bigger.
systems was created by ChaN, a Japa-

www.elektormagazine.com July & August 2017 57


Figure 10. Android Studio 2.2.3 was used to create a simple Android app to communicate with the watch.

as trial versions. Configuring Eclipse for cable with a 3-pin, 2 mm female connec- watch rather complicated). Solving all
the nWatch all by yourself might cause tor and you are ready to go. the problems encountered during devel-
headaches and may discourage you. opment of the watch taught me many
Android app things. Now I appreciate how much time
In-circuit programming Even though I’m not much of a Java pro- and effort is needed to build a device
I highly recommend investing in a cheap grammer, I decided to write a simple like this. I also learned that teamwork
ST-Link programmer. You will see that app to send data to the watch from a is a really good thing as I wasn’t able to
not only is it much more comfortable to smartphone. I found an example of a make every part of this project perfect
use compared to the USB bootloader, it Bluetooth low energy app and modified myself. However, I think the outcome is
also allows you to debug the code you it so that I could read the time and date quite interesting.
wrote. Being part of STM Discovery and from the phone and wirelessly send it to With this article I wanted to show that
Nucleo boards (that are often handed out the watch (Figure 10 & Figure 11). It everyone can build a device like this
for free at trade shows), make it the best is really comfortable, because there is no watch. It is not that hard after all and,
candidate. All you have to do is make a need to write a special app for the watch. in my opinion, it is the easiest way of
When you launch the app on the smart- learning something new. I hope you
phone it will look for an nWatch nearby, enjoyed reading the article as much as
and when it finds one just tap the send I did building the nWatch.
button to set the time and date. The (160326)
next version of the app should update
the watch without any user intervention. Web Link
[1] www.elektormagazine.com/160326
Conclusion
I think I managed to achieve my initial
objectives. The device I built was a great
learning experience that connected of
many skills like programming, electron-
from the store
ª160326-1
Figure 11. The Android app does not (yet) have ics, mechanics, and 3D design and print-
Unpopulated nWatch PCB
fancy graphics, but it allows you to set the ing. It was made of low-cost parts, some
nWatch time and date by a tap on the ‘Send of them scavenged from old cellphones
Data’ button. (unfortunately making reproducing the

58 July & August 2017 www.elektormagazine.com


HomeLab Helicopter
Compiled by Clemens Valens (Elektor Labs)

Arduino Create
Although it has not stirred up
a lot of dust yet, the popular
Arduino platform is evolving in knows only one board). The diffe
a rather spectacular way. Ove rence with those platforms
the past months the people r is that Arduino Create can, like
at Arduino have been quietly Codebender could, program
running a background task with the board itself without the user
the objective to develop a having to manually copy a
full-fledged cloud-based onlin file to a disk. To make this wor
e development platform calle k, a piece of software giving
Arduino Create. It is an ambitiou d the browser access to the boar
s project, taking the concept d has to be installed first, so it
of the now defunct Codebender is not completely hassle-free,
a step further, up to the prefab but once that part properly in
BBC micro:bit level. Regular visit place the rest is automatic.
ors of the Arduino.cc website
have had access to this platform The second objective is to mak
almost from the beginning, e the development of IoT appli-
but its presence was not adve cations as easy as possible by
rtised too much. providing low-threshold cloud
services for free. Again, this
Arduino Create currently has is very much like mbed, but
two accessible to non-specialists.
Traditional Arduino aficionados
can continue
using the off-line IDE they got
to know so well.
However, when downloading a
new version from
the website they will notice that
Arduino Create
is being ‘pushed’ as the preferre
d way to go.
We look forward to what the
future will bring.
Arduino OS maybe?
(160404-a)

main
goa ls. The first is to com -
pletely remove the hassle of
inst allin g boa rds, tool s and
libraries. The Arduino Create
user logs into his/her account,
connects a compatible board
to
the computer and starts coding
— it should be that simple. The
board is recognized by the onlin
e
IDE, all the libraries published
in
the Arduino repository are avai
l-
able without inst alling, the
IDE
is always up to date, etc. This
is
very much like ARM’s mbed (wit
h-
out the programmer’s jargon) or
the
BBC micro:bit environment (wh
ich

8,400,000,000 c t e d o bjects will


b e i n u s e in 2017
con n e
8.4 billion
www.elektormagazine.com July & August 2017 59
Electronics in literature
As far as I know — but what do I know? — literature and electronics do not mingle well.
There is, of course, the Darlington substitution scandal situated in 1886, and involv-
ing Sherlock Holmes, but it was written many years before someone came up with
the idea of the Darlington transistor (this feat from 1953 is, by the way, attributed to
Sydney Darlington), and is therefore also much
older than the admittedly bad idea of substituting
one incorrectly, and although many stories feature
electronics and technology in spectacular ways, they
merely tend to show off the ignorance of the writ-
ers on the subject. Imagine then my surprise when
recently reading a crime novel (Fuzz by Ed McBain,
an 87th Precinct novel from 1968) I suddenly found
myself gazing at circuit diagrams and a detailed and
plausible explanation of how it was supposed to work.
Pictures in novels are rare, what are the chances of it
being a schematic?
(160404-b)

Fuzz by Ed McBain (1968)

The LM0901A1411090451C degraded


circuit operational amplifier.

Weird components
The LM0901A1411090451C Polish operational amplifier is a macro-power, low performance, degraded cir-
cuit operational amplifier designed to have a no-load power dissipation of less than 0.553 W at Vs = ±1 pV and less than 200 W
at Vs = ±2 pV. Open loop gain is greater than 0.001k and input bias current is typically 200 A.
© March 1878, Nominal Semidestructor Corporation
https://goo.gl/jFf75N
(160404-c)

60 July & August 2017 www.elektormagazine.com


Must-have homelab tool
Improve your reflow skills
If you have ever found yourself in a situation
where you needed a den-
You may not have noticed it, but the main theme of this edition
tist’s mirror-on-a-stick
is printed circuit board (PCB) design. Since PCBs are closely
to troubleshoot some
related to soldering, the art of soldering is an important skill
inaccessible device,
to master, even for a PCB designer as the technique used for
these glasses may
soldering has an impact on the PCB design.
be exactly what you
need. With its prisms
instead of normal lenses
they allow you to look down while
looking forward, hence see things in spots
where your head can’t go. Intended for reading on the beach
without having to lift your weighty head, or for discretely
spying on other people, prism glasses are great fun. How
about rotating one of the prisms 180°? Now you can look
up and down at the same time! Or rotate one 90° to the
left and the other to the right and experience horse vision.
Available all over the Internet, search for Prism Glasses or
Bed Prism Spectacles.
(160404-d)

When surface-mount devices are soldered in a reflow


oven, the temperature has to follow a precise path —
Source: Jannis Hermanns, https://jann.is/
the thermal or temperature profile — to ensure proper
solder joints. Temperature profiles for components
can be found in their datasheets, and not all compo-
nents require the same profile. However, all parts, Brick your computer
irrespective of their size and mass, must, within a
When you don’t have access to
defined time period, achieve the minimum tempera-
CNC machines and laser cutters,
ture to start the reflow process without exceeding the
and if you lack good drilling & cut-
maximum temperature the part (and others) can han-
ting skills you can always turn to
dle. It is easy to see that this is a complicated process.
Lego to build an enclosure for your cir-
A standard for thermal profiling called IPC-7530 has existed
cuit. Many people do this for their Arduino
since 2001. Sadly it is now obsolete; revision A is supposed to
or Raspberry Pi for instance, and I have even
see the light soon. Even though its name suggests an update, it
seen etching tools made with the little colorful bricks.
is actually more of a complete rewrite. The new document pro-
Jannis Hermanns from Berlin (Germany) built a tiny Mac-
vides a myriad of information, from definitions to comparisons
intosh Classic “clone” out of Lego, a Raspberry Pi and an
of solder, from techniques for measuring thermal profiles or for
e-paper display. He used Lego Digital Designer (LDD) to
choosing a reflow oven to understanding solder reflow defects.
design his bricked enclosure.
The purpose of this standard is to provide useful and practical
LDD can be downloaded for free from
information to those responsible for developing thermal pro-
http://ldd.lego.com
files to produce acceptable tin-lead and lead-free electronics (160404-f)
assemblies. Officially the standard is targeted at managers,
design and process engineers, and technicians who deal with
mass soldering processes, but the homelab worker and other
occasional reflow soldiers can use this document to greatly
improve his/her reflowing skills. People who open the oven
during the cooling phase to make a board cool down much
faster may want to read this document to find out why they
should exert more patience.
At the time of writing this item, the August 2016 draft of the
document was available for free downloading from
https://goo.gl/l88pjX
(160404-e)

Want to participate? Please send your comments, suggestions, tips and tricks to labs@elektor.com

www.elektormagazine.com July & August 2017 61


HOMELAB PROJECT

Get 5 V from
One Exhausted Alkaline Cell
Juice it to the max
Every day we throw away tons of supposedly empty 1.5-volt alkaline (“dry”) cells. Triggered by the waste
caused by my battery-powered equipment failing to work with partially discharged cells, I designed a circuit
to step up the voltage of one exhausted cell to around 5 V for use in another application. Say, to make an
LED light, keep a lightweight microcontroller buzzing, or power remote sensors that do not demand much
energy… Until that battery, like The Parrot, is dead.

By Juan Canton (México) BC560 and BC550-ish devices at the


drop of a hat. No cigar, at least that’s
what Elektor Labs users reported. The
This self-oscillating voltage step-up con- stray capacitance and other device
verter supplies an output voltage just parameters will play tricks on you.
under 5 volts from a battery voltage In essence you are looking at an oscil-
down to about 0.8 volts. At about 60% lator T1-T2-L1-C1 controlled to some
efficiency and just 5 mA of output current extent by T4 in terms of the out-
it’s is not a wonder of efficiency but that put voltage appearing on K1. Coil
was not the intention. Really, the author (not: choke) L1 is the energy storage
was after juicing exhausted 1.5-V batter- device, helped by C2 as a reservoir
ies to the maximum using components and smoothing device.
readily available to him at low or even no Of the “interesting” parts, the
cost, as part of an experiment. 1N4732A is a ‘voltage regulator
The critical factors in the circuit are diode’ specified by NXP for nomi-
inductor L1 and the transistors. On the nally 4.7 V, 53 mA Ifwd, and 10 µA
latter, you might think the 2N3906 and Irev at 1 V Vrev. L1 then is a true
2N3904 are the TUP and TUN of the inductor, not a choke. Our labs
Americas and can be substituted by trainee’s selection of the part
worked sat-
isfactorily with a promise of better
L1 D1 results by using a slightly higher value.
2N3906
330uH Do experiment and give it a try. The
1N5817
T3 PE52627NL from Pulse Engineering
(#1209550 at Farnell) is specified for
E C
C1
R3 D2
0.78 ohms max. DC resistance. It’s a
T1 B
BATT1 2N3906 low-profile and compact device.
270k

150p K1
C4 C2 1 The 1N5817 is a 1-amp Schottky (i.e.
1N4732A 2 5V
33u 2N3906 T2 220u low-dropout) rectifier diode. Do not use
25V T4 25V
1V5 R1 a regular silicon 1N400x in this position
10R
as it will waste output voltage.
R4 2x R2
2N3904
2N3904 C3 Interestingly, you can power the circuit
copyright
with a higher voltage without exceeding
1k
6k8

100n
the output voltage and the load coming
E C
to grief — the network that regulates the
150724 - 11 B
output voltage will stop the oscillation.
All within limits of course.
Figure 1. An experimental 5-V step-up converter for exhausted 1.5-volt batteries. (150724)

62 July & August 2017 www.elektormagazine.com


HOMELAB PROJECT

Vacuum Tube Curve Tracer


‘Remake’ of the Tektronix 570

In order to test salvaged vacuum tubes, the author required a tube tester. Because a ‘real’ tester
like the Tek 570 was an unattainable ideal, he decided to build one himself — based on a modern
microcontroller. The version presented here can measure the cathode current as a function of either
anode voltage or grid voltage.

By Charles van den Ouweland a large collection of vacuum tubes in the


(Netherlands) attic, which looked visually intact and
that were really only collecting dust.
What do you do with a chest full of
parts salvaged from old equipment?
Do you suffer from this too? That you You use them, of course – for quick &
can’t actually throw anything away, and dirty experiments they are often per-
therefore from of all those hopelessly fectly usable. Things like resistors, capac-
defective ‘Retronics’ devices, donations itors, inductors, etcetera are measured
from family, friends or neighbors (three easily enough, and also for transistors
categories that do not necessarily over-
lap) who thought that they were doing
you a favor, you occasionally try to sal- Figure 1. This is what the characteristics
vage some useful part? The author too, produced by the vacuum tube tester a.k.a.
and after a number of years there was “tracer” look like.

www.elektormagazine.com July & August 2017 63


naked eye, and a potential short circuit hundred volts. Then, on the screen of
between electrodes could be detected the cathode ray tube the cathode current
using an ohmmeter, but that is about all. is displayed as a function of anode volt-
On the other hand, there is little point age at different grid potentials. These
in building a circuit and using a tube of characteristics make it clearly visible
which it is unknown whether it is “good” whether the tube is suitable for a cer-
or not, because when the circuit then tain application.
doesn’t work, where is the problem likely The first thing that came to the author’s
to be? The design, the defective tube, mind was “I want that too”. The only
or both? problem is that the Tektronix 570 (Fig-
ure 2) has now become a collector’s
The Tektronix 570 item; if there is even one to be found,
Even if you have no intention of doing then you will certainly need a well-filled
something yourself with these tubes, you wallet. Apart from that, the ‘570 is a
can always try to sell them. Browsing real monster with dimensions of 42 x
through eBay, the author came across a 33 x 62 centimeters and weighs around
French vendor who accompanied every 80 pounds.
Figure 2. The original Tektronix 570 is a tube for sale with a photo of its char- As with any right-minded electron-
monster in the truest sense of the word. acteristic, made with the aid of an old ics engineer this was immediately fol-
Tektronix 570 curve tracer. lowed by a second thought “I can do this
To generate these characteristics (Fig- myself”. With modern semiconductor and
and diodes their usefulness can be ascer- ure 1) the tester applies different grid microcontroller technology and using an
tained quickly. With vacuum tubes this is voltages to the tube under test (0 V, existing oscilloscope, this should be pos-
not that simple, however. Okay, severe –1 V, –2 V, etcetera) and then varies sible at a fraction of the cost (and also
damage may be recognizable with the the anode voltage from zero to a few much lighter). The idea of the ‘Neptronix

+5V
IC2 LCD1
+18V 7805T L1

10uH
C5 C6 GR-LCD-100x48 C7 C8 R12
C2 C1
DATA/CMD

10k
ENABLE

100n 100n 10n 47n R11 R6


10u 10u +300V
VCC
GND

LED

R/W

D7
D6
D5
D4
D3
D2
D1
D0

1M

47k
10 30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 R16
VCC AVCC +5V +18V
38 40

2k7
PA2(ADC2) PA0(ADC0) R4
37 39
PA3(ADC3) PA1(ADC1)
56k

36 2W
PA4(ADC4) 8 T2
copyright 35
PA5(ADC5)
IC1 PD7(OC2)
21
IC4
34 20
PC7
PC6
PC5
PC4
PC3
PC2
PC1
PC0

PA6(ADC6) PD6(ICP1) 4
33
+5V PA7(ADC7) TIP50
29 PC7
PC7(TOSC2)
ICP 5 28 PC6 +5V 3 DUT
PB4(SS) PC6(TOSC1) 3 –18V T1
1 MOSI 6 27 PC5
PB5(MOSI) PC5(TDI) C3 C4 1
2 MISO 7 26 PC4 IC4.A 5
PB6(MISO) PC4(TDO) 2
3 SCK 8 25 PC3
PB7(SCK) PC3(TMS) 10u 100n MPSA42
4 24 PC2 8
PC2(TCK) R13 R2
5 RST 9 ATMEGA32-P 23 PC1 15 7 6 R7
RST PC1(SDA) 10k 15k
6 19 22 PC0 PC7 1 VDD 16 R3 R1
REFIN
1k

PD5(OC1A) PC0(SCL) DB7


18 PC6 2 14
CLR IC4 = NE5532N
10k

3k3

PD4(OC1B) DB6
17 1 PC5 3 IC3 12 R15
PD3(INT1) PB0(XCK/T0) DB5 PD
16 2 PC4 4 19
39k

PD2(INT0) PB1(T1) DB4 VOUTA


15 3 PC3 5
PD1(TXD) PB2(INT2/AIN0) DB3
14 4 PC2 6 18
PD0(RXD) PB3(OC0/AIN1) DB2 VOUTB
PC1 7 R10
GND XTAL1 XTAL2 GND AREF DB1 AD7302
PC0 8 SMD 5
11 13 12 31 32 DB0
10k

10 13 7
X1 WR LDAC IC4.B
C9 11 9 6 D1
A/B CS R8 R5
DGND AGND
2x
100R

100n
10k

20 17 R9 R14 D2
RESET 16MHz 1N4007
39k 1k

160356 - 11

Figure 3. The schematic of the vacuum tube tester.

64 July & August 2017 www.elektormagazine.com


570’ (where, ‘nep’ is Dutch for ‘fake’ or
‘bogus’) was born.

Design D1 adjustable
+32V R6 L1 BYV27-600 55 – 400V
The circuit has been designed such that 0R22
47uH
two types of measurement are possible: 0W5 R3 R5
C1
- varying the grid voltage with several

100k

1M8
6 7 8
different fixed values of anode voltage; 220u
VCC IS DC 2W
- varying the anode voltage with several T1
1
SWC D2
different fixed values of grid voltage. C5 C2 IC1 2
SWE
This is seamlessly controlled using a 100u MC34063AP
100n 1N4148
IRF740
microcontroller and for the user inter- 5
FB TC
3 T2
C6
face serves a small LC Display with a
GND 47u
set of four pushbuttons. The software 4 C3
R1
BC
R2
400V
has been designed in such a way that it 557B

6k2
10k
470p
is also possible to display the measured
characteristics on the display instead of
on the display of an external oscilloscope. R4 P1 P2
6k2
The Neptronix 570 is and remains built
C4 100k 10k 160356 - 12
on a breadboard; no circuit board has
been designed for it. 100n
copyright
Birds-eye view of the schematic
The schematic for the tracer is drawn in
Figure 3. On the left is drawn the outline
Figure 4. The high-voltage power supply; the input voltage of 32 V is supplied from an old printer
of IC1, the microcontroller — an ATMe-
power supply.
ga32-P. This µC was selected because
it has a large number of I/O lines, is
available in a DIP package for not much
money, and because the author had a
couple on hand.
To the left of IC1 we see the ICP pro-
gramming connection and the four push-
buttons for the user interface (and also
the reset button). The 8-bit wide data
bus from the µC goes in one direction to
the LC Display (LCD1) and in the other
direction to a dual-channel D/A-converter
(IC3). This provides the control voltages
for the different drive voltages for the
tube that is to be tested.

Finally, on the right, two opamps are


drawn; the top one (IC4.A) supplies, via
two high-voltage transistors, the anode
voltage for the tube (DUT = Device Under
Test), while the bottom one (IC4.B), gen-
erates the grid voltage.
Figure 5. The vacuum tube tester as described in this article.
Power supply
As is known, tubes generally operate at
(very) high voltages. In the schematic adequate cooling! The same lab power on hand (in any case, the author didn’t),
several different power supply voltages supply also generates the negative volt- so a solution has to be found for that. A
are indicated – first let’s take a look age of –18 V; this ±18 V is used to power very big problem this fortunately is not
where these come from. both opamps. Since everyone is likely to – see the schematic of Figure 4. This
The power supply voltage for the digi- have a (dual) lab power supply on the is a standard application of the step-up
tal electronics and the display (5 V) is workbench there is no need to go into converter MC34063AP.
supplied through a simple 7805T (IC2 any further details. The author used a power supply, sal-
in Figure 3), which in turn is powered The high-voltage supply is a bit more vaged from a worn-out Canon Pixma
from +18 V that comes from a lab power complicated. Not everyone will have an printer, that generates the input voltage
supply. Note: this 7805 needs to have adjustable DC high-voltage power supply of 32 V. However, if the available input

www.elektormagazine.com July & August 2017 65


Figure 6. The Start tab. Figure 7. The Anode tab. Figure 8. The Grid tab.

voltage is (much) lower, then it can be ler. To compensate for the voltage drop
difficult to obtain a sufficiently high out- across R5, voltage divider R7/R15/R8
put voltage. In that case a voltage-dou- applies one-fifth part of the cathode volt-
bler could offer a solution. age to the non-inverting input of IC4.B.
Figure 5 gives an impression of the vac-
A few details uum tube tracer/tester during the devel-
The (dual-channel) D/A-converter IC2 opment phase.
(an AD7302) is unfortunately not (at
an acceptable price, at least) available User interface
Figure 9. The Output tab.
in a DIP package. The author therefore The LC Display, together with four push-
mounted the SMD version of this IC on buttons (up, down, left, right), are used
an adapter board, so that it would still for operating the vacuum tube tester. The
be possible to built the tube tester on a display shows a series of tabs in which
breadboard without any difficulties. different settings can be made. Navigat-
The anode voltage of the tube to be ing between the different tabs is accom-
tested amounts to maximum of around plished with the left and right pushbut-
320 V. For this purpose, opamp IC4.A tons; the corresponding tab is opened
multiplies the voltage at the output A of using the down pushbutton. Now the left
the DAC (0 to 5 V) by 3.5. Subsequently, and right buttons can be used to change
T1 multiplies this voltage again with a the settings within that tab. Below is a
ratio of 17. Transistor T2 ensures that brief description of the implemented tabs.
sufficient current is also available.
Figure 10. The Run tab.
When we only want to vary the anode Start (N)
voltage (‘sweeping’), then it is not nec- On the start screen (Figure 6) the selec-
essary to know the exact amount of gain tion can be made between the two oper-
from IC4.A and T1. There is, however, ating modes:
also a ‘reversed’ operating mode imple- varying the grid voltage with different
mented (variation of the grid voltage for values of anode voltage (step plate/
different fixed values of anode voltage) anode, sweep grid) or
and for this the anode voltage needs to varying the anode voltage with different
be exactly regulated to known voltages. values of grid voltage (step grid, sweep
For this reason, the voltage divider built plate/anode).
from R11, R12 and R16 is used to feed The right button advances to the next
back one-eightieth part of the anode volt- tab.
age to A/D-input ADC0 of the microcon-
Figure 11. The calibration screen. troller. In this way the controller can cal- Anode (A)
ibrate the anode voltage. In this tab (Figure 7) the minimum and
The other output of the DAC goes to maximum anode voltage and the step
opamp IC4.B. Because the grid voltage size of anode voltage are set. Up/down
needs to be negative, this opamp con- are used to navigate to a particular value,
verts the 0 to 5 V from output B of the after which it can be changed using left/
DAC into a range of 0 to -18 V. Diodes right. The step voltage is used when in
D1 and D2 protect the circuit from volt- the Start tab the selected mode is step
ages that are too high. plate, sweep grid. This value deter-
To measure the cathode current, a resis- mines the amount that the minimum
tor R5 (100 Ω) is inserted between the and maximum voltages are increased
cathode and ground. The voltage drop or decreased.
across R5 goes via R6 to the second
Figure 12. Calculation of the transconductance. A/D-input (ADC1) of the microcontrol- Grid (G)

66 July & August 2017 www.elektormagazine.com


Here the minimum and maximum grid voltages are set, as well
About the Author
as the grid step voltage (Figure 8). The latter is used when
the operating mode step grid, sweep plate/anode has been Charles van den Ouweland (Breda, 1963) studied
selected. This value also determines the amount that the min- Electrical Engineering at the Eindhoven Technical
imum and maximum are increased or decreased. University, Holland. He currently works as a software
architect for ProRail, but in his spare time he keeps busy
Output (O) with electronics — in particular the fusion of modern
Here the selection is made for output to an oscilloscope or to microcontrollers with ‘old fashioned’ tubes.
the LC Display (Figure 9).

Run (R)
Push the down button on the tab (Figure 10) to start the mea-
surement process. When the output is selected to go to the LC
Display, the results will appear here. The sweep-parameter is
displayed on the horizontal axis.

In this context a few remarks. If an oscilloscope is used to dis-


play the characteristics, then it has to be connected as follows.
In the mode sweep grid, step anode: x-axis is grid, y-axis is
cathode; in the mode sweep anode, step grid: x-axis is anode,
y-axis is cathode.
In the LCD mode the measurements are performed relatively
slowly, and the firmware calculates the average of a number
of measurements before sending this to the display. On the
other hand, in the oscilloscope mode the measurements are
made quickly, to prevent flickering of the display.
Calibrate (C)
After a press on the down button this tab appears (Figure 11),
showing a graph of the anode voltage (0 to 230 V) versus the
DAC value (0 to 255). The numeric values in the example of
Figure 11 from top to bottom: maximum voltage at a DAC Advertisement

value of 0; minimum voltage at a DAC value of 255; gradient;


intercept of the straight line with the y-axis.
After a press on the up button, this graph disappears and the
theoretical curve appears (same axis).

Transconductance (T)
In this tab (Figure 12) the transconductance S can be mea-
sured. This works as follows: first the anode voltage is set to
the maximum value (anode tab). The grid voltage is also set
to the maximum value (grid tab). Now the current I1 is mea-
sured. Subsequently, the grid voltage is lowered by one step
value and the current I2 is measured. The transconductance
then follows from:

S = (I1 – I2) / grid step voltage [A / V]

In the example of Figure 12 the anode voltage is 200 V and


the grid voltages are 0 V and –1 V. The measured values are
I1 = 600 µA and I2 = 11000 µA. This results in a transconduc-
tance of –10.4 mA/V.
The tabs H (filament voltage/current) and S (screen grid) were
not yet implemented at the time of writing.
The firmware for the vacuum tube tester (which can be pro-
grammed into the microcontroller via the ICP interface using
any regular AVR programmer) can (‘as is’) be downloaded
from the Elektor Labs page for this project (‘vacuum tube
curve tracer’). There you will also be kept informed about
future developments and updates, and you can add your own
contributions and comments.
(160356)

www.elektormagazine.com July & August 2017 67


Err-lectronics
Corrections, Updates and Feedback
to published articles
BL600-eBoB (1)
Elektor 2/2015, p. 42 (140270)
UPDATE. The manufacturer of the Laird BL600 Bluetooth Low Energy
Module which was featured in the original March & April 2015 article
has since updated its software (firmware and libraries). Unfortu-
nately the earlier version seems to be no longer available. The
example given in the 2015 article was based on version 1.5.7.0
revision 5 of the firmware and its associated libraries.
It could be that this example is not compatible with
the latest version of the firmware and its libraries.
In any case, it is important to use only the library that
matches the BL600 firmware and revision version. If you
see a ‘BL600: Cross Compiler not found’ error message, your
module firmware and downloaded library are not compatible.
The AT commands for identifying the firmware and revision of the BL600 (first connect the module via the serial inter-
face to the PC) are:

• firmware: AT I 3<Enter>
• revision: AT I 0<Enter>

See the ‘eBoB BL600 (2)’ (www.elektormagazine.com/150014) article for further information on the firmware.

Welcome to the Share section


Elektor 1/2017, p. 114 (160252)
In this piece Elektor Netherlands editor Thijs Beckers wondered why the “polarity” of the AC line connec-
tion to a hot water boiler should be important. This generated lots of feedback for which we are grateful!
Below is a selection.
Readers should be aware that 230 VAC line outlets in Holland are earthed in wet rooms, or non-earthed in dry
rooms. Neither type is polarized, i.e. the connection of the Live (L) and Neutral (N) pins in the outlet is not regulated.
The Protective Earth (PE) pins are connected to a local earthing pin and to central earth at the power station and/or
the substation.

FEEDBACK. The Live and Neutral connections are important when a single-pole switch is used to switch equipment on and off.
One example I have noticed, with fluorescent tubes. The ballast is a sort of auto-transformer wired in series with the
filaments at either end of the tube. When the on/off switch is in the Neutral wire the filament is at AC mains potential
even when switched off and this voltage is sometimes sufficient to cause a low-level glow discharge in the gas around
the filament to the earthed fitting. With the switch in the Live wire, the filament will be at AC neutral potential which is
much closer to earth and no discharge or glow is visible.
Lothar Freißmann, Germany

FEEDBACK. The problem is probably caused by electrolysis. There is always some DC component on the (AC) power
line and this causes deposits to form on electrodes which can be remedied to a certain extent by grounding the device.
Reversing the plug reverses this effect; but deposits will then be formed on the other electrode in the heater.
I have a similar problem here in Canada, namely a buildup of lime scale in my instantaneous water heater. Running
a solution of vinegar through the pipe work for a couple of hours is effective in removing the lime scale. To make the

68 July & August 2017 www.elektormagazine.com


descaling process easier I have added a bypass and pump to the pipe work so that I can flush through with vinegar for
as long as necessary.
Clinton Millet, Canada

FEEDBACK. Looking through the handbook for my old gas hot water boiler ‘Calenta’ made by the company Remeha
‘mains phase reversal detection’ is an option that can be enabled in the setup menu (parameter #43). In some
countries the mains plug design allows it to be inserted in one of two ways only so that the Live and Neutral con-
nection become swapped when the plug is inserted ‘upside down’. Well naturally I had to try this menu option
out. The default factory setting is with this phase detection disabled. With this option enabled I swapped the Live
and Neutral wires and sure enough, on switch on it produced the error code SU9 ‘mains plug incorrectly wired’.
In the boiler combustion chamber the igniter electrode produces a spark to start the gas burning and after ignition it is
fed with a high voltage producing ionizing current which is measured to check the combustion conditions are within safe
limits. The handbook states that this ionization current should be less than 3 µA. Replacement electrodes are included
in many of the standard service kits for the boiler. The high voltage is produced by a step-up switching regulator which
could possibly generate faults if the Live and Neutral wires are swapped. Measuring such low levels of current with a
worn and dirty electrode will also eventually lead to unreliable operation.
Peter van de Meerendonk, The Netherlands

Opamp Power Supply Connections...


Elektor 1/2017, p. 118 (160257)
FEEDBACK. I work in IC design and development, and the problem of the IC variant marked with an ‘R’
indicating reversed supply rail pins is probably a result of an important customer of the chip requesting
this specific pin assignment to simplify their own board layout. It’s a simple job for the chip manufacturer to
change the bonding pattern and chip labeling. As PCB component density increases alternative pinouts can be
useful to solve a tricky layout problem.
Lothar Freißmann

Minuscule MEMS microphone — for the Bat DetectorPLUS


Elektor 6/2016, p. 115 (160083)
FEEDBACK. In the article it states that special ultrasonic microphones are very difficult to find. That’s not strictly true :-).
As an old ‘night owl’ I am also a bit of a bat fan (the creatures, not the superhero) and have built several
bat signal detectors over the years. First purely digital (using a 7493 divider), later an analog down-converter
design (using an SO42P). I needed microphones suitable for the application and found the ultrasonic module a
good (and cheap) source. Try searching for ‘HC-SR04’ at an online auction site like eBay.
This module, otherwise known as a ‘ping sensor’ contains an ultrasonic microphone along with some other chips in
SMD-outline that could be salvaged for use in other projects. It also has an ultrasonic transmitter or loudspeaker module
which can be used for sending ultrasonic signals (as used with early TV remotes). These HC-SR04 modules are a popular
choice for obstacle avoidance and distance sensing applications for robotics with Arduino systems. Some suppliers offer
discounts on packs of 5. The transducers are bigger than the original unit and much easier to handle. They use stan-
dard electret transducers making them compatible with
many different types of bat detector circuits.
Another advantage of their size is
they can be easily fitted with a para-
bolic reflector (made from stiff paper)
with the transducer positioned at the
focal point. This makes the microphone directional
and helps pinpoint the creature at a greater range.
The microphones can detect signals beyond 100 kHz, but most
native bats don’t squawk at such high frequencies.
Peter Krengel

www.elektormagazine.com July & August 2017 69


LABS PROJECT

70 July & August 2017 www.elektormagazine.com


FPGA-DSP Board
for Narrowband SDR
A fully programmable
receiver/transmitter baseboard

By Daniel Uppström (SM6VFZ, Sweden)

and Ton Giesberts (Elektor Labs)

www.elektormagazine.com July & August 2017 71


Presented here is an FPGA-based digital signal processing board Let’s build one ourselves
This project started in 2013 when the
featuring everything necessary to do baseband processing of traditional
author built a first prototype and started
narrowband modes like SSB/CW and AM. It solves many of the issues writing VHDL-code for DSP blocks. Com-
and limitations seen in simpler SDR platforms. Capable of transmitting pared to a DSP executing code from
scratch to glory, it is in general easier
as well as receiving, it provides a perfect foundation for a shortwave
to implement a complex signal processing
and/or VHF/UHF/SHF/microwave transceiver, ideal for scientific, ham, chain in programmable logic since every
and other serious radio applications. step can be designed independently of
the others. When done, all that remains
to do is connect the signals between the
different blocks. Explaining this devel-
From the good old days… were accepted in a bid to make radios opment process is beyond the scope of
There once was a time when radio tech- smaller and cheaper while covering many this article, but all the code written and
nology was the focus for the bulk of elec- frequency bands. The reduced perfor- all other necessary information is freely
tronic hobbyists and electronic engineers. mance with regard to essential radio available for anyone to study [1].
Many people built their own equipment properties like receiver selectivity and Though a useful and powerful combina-
and having a radio amateur license was clean transmitted signals was to some tion, programmable logic and ADCs alone
synonymous with being interested in extent compensated for by fancy digi- do not add up to a radio. The FPGA-DSP
electronics. But when the technologies tal features, color displays, and so on. board needs to be complemented with
evolved it became harder for hobbyists However, for those who are not easily a radio board to do the frequency con-
to keep up and eventually most radio impressed by looks and gadgets and pre- version, as well as with analog filtering
amateurs bought their equipment ready- fer a high-performance radio instead, it and amplification. Such a board will be
made. The state-of-the-art transceivers now again makes sense to try to build presented in a future installment of this
of the 80’s and 90’s made use of a very something at home. series. A control board for tuning the
large number of complex analog building radio, adjusting the volume, etc. will be
blocks and it became almost impossible … to software-defined radio the subject of yet another article. With
for hobbyists to build something simi- Still, reverting to state-of-the-art analog the three boards it is possible to build a
lar, not only because of the amount of technology may not be the best solu- complete radio with a front panel and in
knowledge needed, but also with regard tion and it may be more interesting to a suitable enclosure.
to size and costs. look at what is happening in the field of It should be noted that the system may
With the evolution of the Internet new Software Defined Radio (SDR) where a also be controlled by a PC connected with
ways of communication arose and the large part of the radio signal processing a USB-to-serial adapter, or a Raspberry
number of commercially-built radio trans- is implemented in the digital domain and Pi communicating over its I2C or serial
ceivers for amateurs started to decrease. executed by software. With the comput- port. A graphical user interface written
At the same time many compromises ing power and the good analog-to-digital in Python is available to demonstrate the
converters (ADCs) available today SDR functionality.
technology really makes sense.
Many hobbyist and amateur radio appli- Circuit description
project information cations process digitized signals entirely The FPGA-DSP board features a 24-bit
in software by a PC or a Digital Signal ADC for sampling at an intermediate fre-
FPGA DSP SDR
Processor (DSP). Although this approach quency in receive mode, a Cyclone IV
Radio Transmitter is flexible, it is rather inefficient since sig- FPGA for signal processing, a high-speed
Receiver Ham Radio nal processing is still relatively costly in DAC for local oscillator and transmit sig-
terms of processor operations when done nal generation, an audio interface for
entry level without hard-coded multipliers and simi- microphone and loudspeaker, a very sta-
intermediate level lar peripherals. Many of the popular SDR ble high-precision oscillator and an I2C
Æ expert level platforms also have poor or non-existent or UART interface for a host controller
analog filtering before digitizing, as well (Figure 1).
as low-resolution in terms of the ADC, The heart (or brain) of the FPGA-DSP
8 hours approx. resulting in poor performance especially board is the EP4CE10 Cyclone IV FPGA
with strong interfering signals around. from Intel, formerly Altera (IC4). This
A better way would be to build a good chip can be configured for virtually any
SMD soldering tools, analog radio front-end and do the sig- digital function. Governed by the firm-
JTAG programmer (USB nal processing with programmable logic. ware, at start-up its gates are configured
Blaster), Quartus Lite Today’s Field-Programmable Gate Arrays by an external memory (IC5) known as
(FPGAs) available at affordable prices the configuration memory.
sport an impressive number of gates, For audio input and output there is a
£190 / €200 / $210 approx. memory bits and hard-coded multiplier so-called CODEC (coder-decoder) — a
blocks. They are excellent for complex TLV320AIC20K (IC3) — comprising two
signal processing tasks. ADC/DAC channels with 16-bit reso-

72 July & August 2017 www.elektormagazine.com


lution and a maximum sample rate of
25,000 samples per second (SPS). It Features
has a built-in digital 8-kHz lowpass fil- • FPGA + DSP + Audio CODEC
ter, besides a microphone amplifier and • Narrowband software defined radio platform
a speaker driver that can deliver up to • Can be used for radio operation at virtually any frequency between zero and
250 mW into 8 Ω. All audio inputs and many GHz
outputs sport programmable gain/atten- • Uses superheterodyne principle
uation. The speaker gets connected to • Low second IF higher than 0 Hz
K2, the microphone to K3; all other chan- • Receive (RX) and Transmit (TX) compatible
nels available in IC3 are connected to • Weaver SSB modulator/demodulator
K4, making them available for auxiliary
equipment.
EXT REF
The main input of the board is through TCXO

K1; it expects a differential signal, typi- 20MHz < 50MHz

cally in the hundreds of kHz range. The A

signal passes a differential amplifier AD7760 2x 14 bit


Signal
(IC1) and a discrete lowpass filter, to in
A 24 bit EP4CE10 D
be digitized finally by 24-bit ADC IC2, a Cyclone IV
D FPGA A
type AD7760. This chip has many power
1,25 MSPS DAC5672 B
supply connections separated by supply 120 MSPS

voltage and/or passive filters. Its mas- I2 C or UART


Control Interface
ter clock is provided by the FPGA, lev- GPIO’s
PTT,Key
el-shifted to 5 V by IC8.
There is also a fast two-channel digi-
Audio
tal-to-analog converter (DAC) on the copyright Codec

board, a DAC5672 (IC6). Its two differ- 150177 - 11


TLV320AIC20K
ential outputs A and B are converted with
transformers to single-ended outputs;
Figure 1. Block diagram of the FPGA-DSP board.
low-pass filtering is provided, allowing
signals up to 50 MHz to be produced.
The two DAC outputs are available at sists of two pins intended for I2C or UART tion at virtually any frequency between
SMA-type coaxial connectors K8 and K9. communication, selectable by solder zero and many GHz. The typical applica-
The board’s main clock is generated by jumper (JP1). They are available on K7, tions, however, are for shortwave (under
IC7, a 20-MHz Temperature-Compen- together with seven additional I/O lines 30 MHz) and/or the 2-m amateur band
sated Crystal Oscillator (TCXO). The intended typically for PTT (push-to-talk) (144-146/148 MHz).
clock signal is fed to the FPGA which and Morse key signals. These pins might For shortwave reception, a simple radio
distributes it to the peripheral ICs. The also be used for I2S audio I/O. board could be constructed as shown in
frequency can be fine-tuned with poten- Solder jumpers JP2 and JP3 do not have Figure 3. The antenna signal is lowpass
tiometer P1. Connector K5 provides an a function in the current FPGA firmware. filtered and amplified. By mixing it with
input for an external reference source K6 provides a JTAG interface for pro- a local oscillator (LO) signal from DAC A,
— if one happens to be available. If so, gramming the FPGA and its configura- the frequency of interest is converted
the TCXO can be switched off by means tion memory. to 45 MHz before it is passed through a
of T1. The TCXO and the external refer- crystal filter. This intermediate frequency
ence signals are both guided to the FPGA Radio topology (IF) signal is amplified before entering
through unbuffered inverters wired as With a suitable radio board, the FPGA- a second mixer where it is converted
analog amplifiers (IC9, IC10) and con- DSP board can be used for radio opera- down to a second IF signal centered at
sequently may be of moderate voltage
swing.
The clock is divided down in the FPGA
to generate a low frequency signal for < 30 MHz 45 MHz
LED1 indicating that the clock is run- Antenna
in
312.5 kHz
ning and the FPGA is configured. The to ADC
function of LED2 is reserved for future
Crystal filter
needs. The board’s 5-volt supply volt- 44.6875 MHz
from DAC B
age is connected to K10 from where it
is distributed to four different Low Drop-
15 - 45 MHz
Out (LDO) voltage regulators (IC11-14) copyright from DAC A
to create the supply voltages — 1.2 V, 150177 - 12

1.8 V, 2.5 V and 3.3 V — required for


various components on the board.
The interface to the host controller con- Figure 3. Block diagram of a radio add-on board.

www.elektormagazine.com July & August 2017 73


74
IRF9321PBF +5V
R19
C34

1k
L14 NM C37 IC14 IC13 IC12 IC11
R21
1k T2 TPS79633DCQ +3V3 TPS79625DCQG4 +2V5D TPS73018DBVT +1V8 LP3891EMR-1.2/NOPB +1V2
K3 R23 K10
MIC C33 C36 22n 2 4 2 4 1 5 7 1
+3V3 +1V8 +3V3 IN OUT IN OUT IN OUT VIN VOUT

47k
5V DC C105 C104 6 2
L15 S/D VOUT
NM R22 1n C38 3
C99 C97 C96 C94 C93 C91 C90 VBIAS C89

EN
GND
GND
NR/FB
EN
GND
GND
NR/FB
EN
GND
NR
100n 47u

chip schematic!
copyright
1k C39 C40 C41 C42 C106 C43 R53
R20 0 16V GND GND PAD

1
3
6
5
1
3
6
5
3
2
4
C35 22n

4
5
9
1u 2u2 1u 2u2 1u 2u2 47u 47u

10k
C98 C95 C92

1k
1u 1u 1u 100n 100n 47u 16V 16V
16V
NM
100n 100n 100n

42
33
5
15
12
C31

July & August 2017


36 31
MICBIAS CIDI+

AVDD
DVDD
L12 10p 35 30 C100 C101 C108 C109 C110

IOVDD

AVDD1
AVDD2
DRVDD 27
LSP K2 MICI+ CIDI-
C30 34 14
MICI- FSD
28 2u2 2u2 47u 47u 47u
SPKO- 16V 16V 16V
L13 10p 26
SPKO+ 48 +1V2
C32 37 NC +3V3 +2V5D +3V3 +2V5D
LCDAC 8
38 NC
HNSO-
10p 39 23 C65 C66 C67 C68 C69 C70 C71 C72 C102 C107
HNSO+ RESET C53 C54 C55 C56 C57 C58 C59 C60 C61 C62 C63 C64 +5V
40 22
K4 HNSI- MCLK
L31 41 IC3 21 2u2 100n 2u2 100n 2u2 100n 2u2 100n 47u 47u
HNSI+ M/S +3V3 100n 100n 100n 100n 100n 100n 100n 100n 100n 100n 100n 100n 16V 16V R41
1 2 L32 44 TLV320AIC20KIPFB 20 +3V3
LINEI+ SCLK
1k

3 4 L33 45 19 +2V5D +3V3 +2V5D


LINEI- FS
5 6 L34 46 18 IC5 C44 L30
LINEO- DIN C80 C81

3
7
8
7 8 L35 47 17
LINEO+ DOUT LED3

17
26
40
47
56
62
81
93
117
122
130
139
5
29
45
61
78
102
116
134
9 10 L36 1 11 100n
HDSI- SCL 100n 100n C82

VCC
VCC
VCC
L37 2 10 5 100n
HDSI+ SDA ASDI Power
L38 3 9 1 1

16
22
42
47

VCCIO1
VCCIO2
VCCIO3
VCCIO3
VCCIO4
VCCIO4
VCCIO5
VCCIO6
VCCIO7
VCCIO7
VCCIO8
VCCIO8
VCCINT
VCCINT
VCCINT
VCCINT
VCCINT
VCCINT
VCCINT
VCCINT
HDSO- PWRDN nCS IO
L39 4 6 2 144 48

www.elektormagazine.com
HDSO+ DCLK IO IO, DIFFIO_T1p, (DM1T) MODE AVDD
2 3 143 1 23
GSET

DVDD
DVDD
DATA IO IO, DIFFIO_T1n, (DQ1T) DA13 DB13

VSS
AVSS
AVSS1
AVSS2
IOVSS
TESTP
DVSS
DRVSS2
DRVSS1
R24 6 142 2 24
GND IO, DIFFIO_L1n, (DATA1,ASDO) IO, DIFFIO_T2p, (DQS1T/CQ1T#,DPCLK7) DA12 DB12

6
7

24
43
32
13
16
29
25
7 141 3 25

4
IO, VREFB1N0 IO, DIFFIO_T5p DA11 DB11

27R
+5V +2V5D 8 138 4 26
IO, DIFFIO_L2p, (FLASH_nCE,nCSO) IO, (DATA6) DA10 DB10
L6 R18 10 137 5 27
IO, DIFFIO_L4p, (DQS0L/CQ1L,DPCLK0) IO, (DATA5), (DQ1T) DA9 DB9
10R 11 136 6 IC6 28
C22 IO, DIFFIO_L4n IO, VREFB8N0 DA8 DB8
L1 L2 L3 L4 R17 L7 L8 L9 L10 L11 12 135 7 29
M25P40-VMN6PB DCLK IO, DIFFIO_T8n, (DQ1T) DA7 DB7
C103 C16 100n 13 133 8 30
IO, (DATA0) IO, DIFFIO_T10p, (DATA3), (DQ1T) DA6 DB6

10R
28 132 9 31
IO, DIFFIO_L6n IO, DIFFIO_T10n, (DATA2), (DQ1T) DA5 DB5
47u 100n 30 129 10 32
16V C21 IO, DIFFIO_L8p, (DQS1L/CQ1L#,DPCLK1) IO, DIFFIO_T11p DA4 DB4
C17 C18 C19 C20 L5 C23 C24 C25 C26 C27 C28 C29 31 128 11 33
IO, VREFB2N0 IO, DIFFIO_T11n DA3 DB3
32 127 12 34 R49
10n IO, RUP1 IO, DIFFIO_T12p DA2 DB2
100n 100n 100n 100n 100n 10u 100n 10u 100n 100n 100n 33 126 13 35 L26..L29 = 0805CS-181XGLB
15nH IO, RDN1 IO, DIFFIO_T12n DA1 DB1
100R

pin9 34 125 14 36 TC4-1WG2+ K8


IO IO DA0 DB0 L26 L27

27
12
33
6
41
44
38 124 46 1 TR1 4 C83 C84 C85 1
IO, DIFFIO_B1p IO, DIFFIO_T13p IOUTA1
14 39 121 19 R42 2 180nH 180nH
2

AVDD2 IO, DIFFIO_B1n IO, DIFFIO_T16p CLKB/RESETIQ


NM

DVDD
15 42 120 20 3 6 DAC A

AVDD2
AVDD4
AVDD1
AVDD1
VDRIVE
AVDD2 IO, (DQS1B/CQ1B#,DPCLK2) IO, DIFFIO_T16n, (DQ1T) WRTB/SELECTIQ
IC1 = OPA2374AIDG4 4 63 43 119 18 45 R50 120p 180p 120p
AVDD2 VDRIVE IO, PLL1_CLKOUTp IO, VREFB7N0 CLKA/CLKIQ IOUTA2 100R
24 61 44 115 17 39 K9
5 AVDD3 DB0 IO, PLL1_CLKOUTn IO, RDN4, (DQ1T) WRTA/WRTIQ IOUTB1 100R L28 L29
+2V5A 60 46 114 R51 6 C86 C87 C88 1
7 R12 DB1 IO, VREFB3N0 IO, RUP4, (DQ1T)
3
NM

IC1B 25 59 49 113 DAC5672IPFB 180nH 180nH


2

6 18R VIN+ DB2 IO, DIFFIO_B9p, (DQ1B) IO, PLL2_CLKOUTp R43


22 58 50 112 40 2 4 DAC B
VOUTA+ DB3 IO, DIFFIO_B9n, (DQ1B) IC4 IO, PLL2_CLKOUTn IOUTB2
C3 R10 C10 57 51 111 37 43 1 TR2 120p 180p 120p
DB4 IO, DIFFIO_B10p, (DQ1B) EP4CE10E22C8N IO, DIFFIO_T19p SLEEP EXTIO
56 52 44 TC4-1WG2+

1k
NM DB5 IO, DIFFIO_B11p BIASJ_A
C1 R1 R3 C7 R8 27p 55 53 110 41 R52 R40 C79
20 DB6 IO, DIFFIO_B11n IO, DIFFIO_T20p, (DQS0T/CQ1T,DPCLK6) BIASJ_B
DGND
DGND
AGND

K1 560R 560R 1k VINA- 54 54 106


DB7 IO, DIFFIO_B12p IO, DIFFIO_R1n
2k0

C9
100R

100n
15
21
38

100n 100n 52 55 105


DB8 IO, DIFFIO_B12n IO, VREFB6N0
C2 R2 R4 C8 R9 51 58 104
5p6 19 DB9 IO, DIFFIO_B15p, (DQ1B) IO, (DQS0R/CQ1R,DPCLK5) K7
560R 560R 1k VINA+ IC2 50 59 103 R54
R11 C11 DB10 IO, DIFFIO_B16p, (DQ1B) IO, DIFFIO_R3p, (CLKUSR) 100R GPIO6
100n C4 100n AD7760BSVZ 49 60 101 R55
DB11 IO, DIFFIO_B16n, (DQ1B) IO, DIFFIO_R3n, (nCEO) 100R GPIO5

1k
NM 27p 48 64 100 R56 GPIO4
DB12 IO IO 100R
21 47 65 99 R57 GPIO3
2 VOUTA- DB13 IO, VREFB4N0 IO, DIFFIO_R4p, (CRC_ERROR) 100R
26 46 66 98 R58 GPIO2
+5V 1 18R VIN- DB14 IO, RUP2, (DQ1B) IO, DIFFIO_R4n, (INIT_DONE) 100R
IC1A R13 45 67 15 L22 PTT/GPIO1
3 DB15 IO, RDN2, (DQ1B) TDI
R7 +2V5A 40 68 20 L23
R15 R14 CS IO, DIFFIO_B20n, (DQS0B/CQ1B,DPCLK3) TDO KEY/GPIO0
10 39 69 16 L24 SCL/RxD
+2V5D 100R 10R VREF+ RD/WR IO TCK

330R
C12 38 70 18 L25 SDA/TxD
C13 DRDY IO, DIFFIO_B21p TMS +3V3
47u 37 71 94
16V RESET IO, DIFFIO_B21n MSEL0
R5 10n 9 36 72 96
REFGND SYNC IO, DIFFIO_B22p MSEL1
8 3 73 97 R34 R35 R36 R37 R38 R39
DECAPA MCLK C45 IO MSEL2

10k
+2V5A R25
30 2 74 21 +3V3
1k
1k
1k

8 DECAPB MCLKGND 10k IO nCE


10k
10k
10k

C6 K6
17 65 +3V3 75
IC1 RBIAS EP 100p IO

3
100n R6 C14 C15 R16 76 92 1 2
4 4 2 IO, RUP3 CONF_DONE
C5 +5V 77 14 3 4

5
IO, RDN3 nCONFIG

160k
DGND
DGND
DGND
DGND
DGND
DGND
DGND
AGND1
AGND1
AGND2
AGND2
AGND2
AGND2
AGND2
AGND3
AGND3
AGND3
AGND3
AGND4
100n 33p

10k
IC8 L16 80 9 5 6
IO, VREFB5N0 nSTATUS

1
7
5
100n

35
42
43
53
62
64
34
13
16
18
28
23
29
31
32
11
100k 83 7 8
C46 IO 88 R44
R26 84 CLK7, DIFFCLK_3n 10k 9 10
100n IO, DIFFIO_R8n 89 R45
85 CLK6, DIFFCLK_3p 10k
IC8, IC9, IC10 = 74AHC1GU04W5-7 PMV65XP IO, DIFFIO_R8p, (DQS1R/CQ1R#,DPCLK4) 90 R46
T1 86 CLK5, DIFFCLK_2n 10k
IO, DIFFIO_R7n, (DEV_OE) 91 R47 +2V5D JTAG
R28 87 CLK4, DIFFCLK_2p 10k
R27 L17 IO, DIFFIO_R7p, (DEV_CLRn)
10k 35 L18
VCCA1

NM
23 107 L19

4
IC7 CLK1, DIFFCLK_0n VCCA2
5
+1V2
C49 R29 24 37 L20
P1 1 Vdd 3 2 4 CLK2, DIFFCLK_1p VCCD_PLL1
Vc 27R 25 109 L21
GND
GND
GND
GND
GND
GND
GND
GND
GND
GND
GND
GND
GND
GND
GND
PAD
GNDA2
GNDA1

C47 C50 CLK3, DIFFCLK_1n VCCD_PLL2


3

100p
4

C73 C74 C75 C76 C77 C78


19
22
27
41
48
57
63
79
82
95
36

GND C48 IC9


118
123
131
140
145
108

2
10k 100n 100n 100n
100n 100n 100n 100n 100n 100n
ASVTX-09-20.000MHZ-T 150177 - 18
R30 +3V3
L40
10k R32 R33 R48
JP1 JP2 JP3
Ext. clock
10k

5
330R
330R

K5 C51 R31
1 2 4
27R
C52 LED1 LED2
2
3

100p
IC10
100n

Figure 2. If you manage to look through the mist of passive filters, decoupling capacitors, data buses and supply lines, what remains is basically a four-
312.5 kHz (see below) with the help of
a second LO signal provided by DAC B.
The second IF signal is digitized by the LPF 32 LPF

ADC and fed into the FPGA where it is


cos 2x 10 bit
24 bit
processed and ultimately demodulated @ 1.25 MSPS
to audio. from ADC Audio out
1.25 MHz
OSC Bandwith setting AGC Demod
Compared to many other SDR-solutions 4
16 bit
@ 25 KSPS
this topology is advantageous for two to Codec
sin
reasons:
Q RSSI
LPF 32 LPF
1. Double conversion superhetero-
dyne principle. 39 KSPS 150177 - 13

The signal is mixed to a high-frequency


first IF where it is filtered. Then it gets
Figure 4. The signal processing chain implemented in the FPGA.
converted down to a low-frequency sec-
ond IF and subsequently, sampled. This
is advantageous since strong signals on need for gain control in the analog blocks, but shifted one position or 90°) the sig-
frequencies other than the one of inter- which, in turn, simplifies the receiver cir- nal at 312.5 kHz is down-converted to a
est are filtered out by the narrow filter cuitry a lot. quadrature signal centered at 0 Hz. These
positioned early in the chain. This implies signals are then fed to down-sampling
high selectivity, or high dynamic range, Digital signal processing low-pass filters that reduce the sample
allowing the receiver to receive weak — reception rates by 32 — simply by throwing away
signals in the presence of strong ones. It is the FPGA’s job to process the sampled 31 out of 32 samples —, to provide out-
The simpler SDR projects often use the input signal. Figure 4 shows a simplified puts at sample rates of around 39 KSPS.
‘zero-IF’ principle instead, with only one diagram of the implemented blocks. These two down-sampled signals now
mixer, no filter, and simple digitizing at The ADC digitizes the input signal cen- each contain information from zero to
audio frequencies around the carrier. The tered at 312.5 kHz at a rate of 1.25 mil- about 10 kHz; combined, they represent
approach is limited in its ability to handle lion samples per second (MSPS). With the information that was within ±10 kHz
strong interferers, since mixing products 24 bits per sample at 1.25 MSPS there of 312.5 kHz in the sampled input signal.
of unwanted signals are likely to fall in are 30 Mbits/s to process. This is a lot In case you didn’t guess it, the second
the audio band where they will distort more than necessary and so the first IF of 312.5 kHz was chosen because it is
the signal you want to hear. digital processing steps are to down a quarter of the 1.25-MHz sample rate.
Fancier SDR solutions simply sample a convert and down sample the input This allowed the implementation of the
large portion of the frequency spectrum stream. By multiplying the signal with down converter in VHDL to be kept sim-
(‘direct sampling’) and do the tuning in two sequences [0,1,0,−1,0,…], a “sine ple because multiplying by 1, 0, and −1
the digital domain. This method creates wave” at exactly a fourth of the sample is easy (Listing 1). Other IF frequencies
interesting opportunities for monitoring rate, and [1,0,−1,0,1,…], a cosine (the would have required a sine table and
large chunks of the spectrum, but, when second sequence is identical to the first, 24-bit multipliers.
combined with a desire for good selectiv-
ity and/or dynamics, it places very strict
requirements on the linearity of the input Listing 1.
amplifier and resolution of the ADC in VHDL implementation of a down converter at ¼ of the sample rate.
terms of effective bits. Fast sample rates if ns = 0 then
and high resolutions usually imply high Ia(write_pointer) <= signed(Data_in); -- 1
costs and power demands, often result- Qa(write_pointer) <= to_signed(0,24); -- 0
ing in poor compromises.
ns := 1;
elsif ns = 1 then
2. The second IF is low but not zero.
Ia(write_pointer) <= to_signed(0,24); -- 0
This means that an interferer within the
filter bandwidth (typically 15 kHz) cannot Qa(write_pointer) <= signed(Data_in); -- 1
mix to produce a frequency interfering ns := 2;
with the received signal. These kinds of elsif ns = 2 then
mixing products will be sampled but digi- Ia(write_pointer) <= (not signed(Data_in)) + 1; -- -1
tally filtered out afterwards because they Qa(write_pointer) <= to_signed(0,24); -- 0
end up below the desired signal centered ns := 3;
at 312.5 kHz. Since this frequency is not elsif ns = 3 then
too high, it requires only a sample rate Ia(write_pointer) <= to_signed(0,24); -- 0
in the range of 1-2 MSPS for which one Qa(write_pointer) <= (not signed(Data_in)) + 1; -- -1
can find affordable 24-bit ADCs. These
ns := 0;
24 bits result in a digital dynamic range
end if;
of more than 100 dB and eliminate the

www.elektormagazine.com July & August 2017 75


freq. word

signals bandlimited
cos
to 1.6 kHz
Audio Audio
OSC
address ROM data
sinetable
1.7 kHz
sin
Q
Q 150177 - 16
150177 - 14
150177 - 15

Figure 5. AM signal demodulation. Figure 6. SSB and CW signal demodulation. Figure 7. The basic operating principle of DDS.
The block with the sigma symbol in it is the
phase accumulator.

The next step is to lowpass-filter the two using the Pythagorean theorem for two interface. The audio CODEC provides pro-
signals once more. This time the cutoff orthogonal vectors: √(I2+Q2), see Fig- grammable gain and can drive a speaker
frequencies are adjustable in order to ure 5. For SSB (and CW) demodulation or headphone directly.
match the selected mode of operation. is unfortunately a bit more complicated. The local oscillator (LO) signals at the
For AM, their cutoff frequencies are at In this design Weaver’s method was used outputs of the two DACs are produced
5 kHz for 10 kHz of information band- [2][3]. The main idea (Figure 6) is to by two Direct Digital Synthesis (DDS)
width. For SSB (Single-Side Band) tele- split the signal bandwidth in two and mix blocks inside the FPGA. Such a synthe-
phony, they are set to around 1.6 kHz again with a locally generated low fre- sizer consists of a so-called phase accu-
(3.2 kHz bandwidth), and for narrow quency quadrature signal in the middle of mulator register whose value is increased
band CW (Continuous Wave; Morse code) the band. Choosing between Upper Side by a fixed amount at every clock cycle of
they filter at only a few hundred hertz. Band (USB) or Lower Side Band (LSB) is the 120-MHz DAC clock (which is derived
Two times 24-bit resolution still yields then just a matter of sign manipulation from the internal PLL of the FPGA), thus
a lot of data to process. To extract the in the final adder. the increase determines the frequency.
information of interest, i.e. to demodu- The demodulated audio finally passes a The accumulated value is used as an
late, we do not need all these bits. The lowpass filter to remove any high-fre- address into a sine table; the value found
task of the next block, the Automatic quency components caused by distortion at that address is sent to the DAC (Fig-
Gain Control (AGC), therefore is to con- in the AGC or demodulator. It is then res- ure 7). The frequency word for DAC A,
tinuously monitor the signal strength and ampled to match the sampling rate of the which forms the tunable LO, is 25-bits
scale the signal so as to output only two audio CODEC and wide. This corresponds to a frequency
10-bit streams that can be demodulated. sent to the latter step of 120 × 106 / 225 = 3.57 Hz. In
The AGC block also outputs the Received over a standard addition, there is a fine-tune mechanism,
Signal Strength Indication (RSSI). serial implemented with fractional values, giv-
Next is the demodulator. For PCM ing a final resolution of 0.44 Hz.
AM signal demodulation For the second LO, which is a fixed fre-
this amounts to the quency for conversion between the first
extraction of the IF and the second, the corresponding
amplitude by DDS is implemented with a lower reso-
lution to save FPGA resources — it has
a precision of about 38 Hz.

FPGA programming
The compiled firmware for this project
is available as a ‘JTAG indirect configu-
ration’ file (trx.jic) that first configures
the FPGA as a bridge and then programs
the configuration memory through the
FPGA. This is done with the aid of a USB
Blaster adapter that connects to a PC
over USB to form a JTAG interface to the
board. Such adapters can be found for lit-
tle money on popular shopping websites.
The software to use at the PC side is
known as Quartus Lite and can be freely
downloaded from the Intel/Altera web-
site. If the complete development envi-

76 July & August 2017 www.elektormagazine.com


component list

www.elektormagazine.com July & August 2017 77


shortwave listeners.
It should also be possible to route the
audio from the FPGA directly to the PCM/
I2S ports of the Raspberry Pi in order to
avoid the detour over analog audio when
doing remote operation. This is yet to
be tested.
How to download the applet, install nec-
essary packages and connect the Rasp-
berry Pi to the FPGA board is described
in a document available with the source
code.

Conclusion
The project presented in this article is a
powerful building block for radio ama-
teurs and experimenters who want to
Figure 8. The prototype built by the author doing USB at 144 MHz. build their own radios without compro-
mising on performance. At the same time
it is hoped that this project will inspire
the more digitally oriented readers to
Web Links dive into the world of radio and signal
[1] www.elektormagazine.com/150177 processing.
[2] Donald K. Weaver Jr., “A Third Method of Generation and Detection of The project has a lot of room for improve-
Single-Sideband Signals”, www.h4.dion.ne.jp/~ja5fp/weaver.pdf ments and additions. A future install-
ment (hopefully in the next edition) will
[3] Daniel Uppström, “Weavers metod för SSB”, ESR Resonans 2/2014,
present a radio board and discuss the
http://resonans.esr.se/ESR_Resonans_2014_2.pdf (in Swedish)
transmission side of things; if enough
[4] www.elektormagazine.com/labs/ resonance is observed, we may present
fpga-dsp-radio-for-narrow-band-communications-150177-i more advanced radio boards.
[5] https://github.com/ast/dspsdr The VHDL code for the FPGA is available
as open-source on [5] and additions and
improvements are welcome.
ronment is not of interest there’s always ble through the project web pages [1], Finally, it should also be noted that the
the option to download the applications [4], and [5]. board is generic enough to be used as a
needed for programming only. The Quar- In a standalone radio the controller is development board for other FPGA-DSP
tus suite is available for both Windows likely to be a small microcontroller board applications.
and Linux. with a display and buttons (like the Elek- Please visit the project web page for
tor Platino). A suitable board will be updates and additions.
Control interface described in a subsequent installment. (150177)
At power on, the firmware gets loaded For experiments, or when the need for
from the configuration memory, and pro- a monitor and mouse/keyboard is not
grammed into the FPGA. Then the FPGA an obstacle, a Raspberry Pi should also
has to be initialized and controlled over make a flexible control interface. For the
I2C or the serial port. The FPGA is much RPi (or any other Linux computer), an
like a typical IC with a few registers that applet was written in Python using the
need to be set. Every data transmission GTK graphical framework, which makes
involves five bytes being sent to the the controls easily accessible. By default
FPGA. The first two bits set the regis- this applet connects to the FPGA board
ter address while the remaining 38 bits over the serial port. It also has an exper-
contain configuration data. imental socket mode to enable remote
A few status signals can be read as operation. The idea is to run a server
well as the value of the received sig- on a Raspberry Pi at the location of the
nal strength indication (RSSI). The con- radio and connect to the Pi with the
troller typically polls this information a applet from a remote computer. With
few times per second to update signal the large amount of man-made noise
from the store
strength indication to the user. in urban areas, and with the limitations ª150177-1:
Bare PCB for FPGA-DSP board
A detailed description of the control and regulations against installing large
interface, with full register map, is avail- antennas in these locations, the option ª150177-91:
able together with the firmware and its of remote operation becomes increas- Ready-built FPGA-DSP board
source files in a GIT repository, accessi- ingly interesting for radio amateurs and

78 July & August 2017 www.elektormagazine.com


Elektor Labs
Pipeline
A large part of electronics is all about measuring something. This time we present a few projects you can
build yourself to measure heat, waste, time and I2C addresses.

I2C bus scanner has OLED display


The Inter Integrated Circuits bus, better known as I²C bus, was devel-
oped by Philips in the 1980s to connect a microprocessor or microcon-
troller in an easy manner to other integrated circuits in — at the time of
invention — mostly television sets made by the brand and its sub-brands.
Little by little the bus became popular and today components with I²C
interface are all over the place. Because the bus pops up everywhere,
tools are needed to check if it is working correctly. The scanner proposed https://goo.gl/4ZUy79
here helps you to quickly see if the connected devices are actually alive.

Candle2light — a luminous efficacy booster


Before electric lighting became common in the early 20th century, can-
dles and oil lamps were commonly used for illumination. Even a modern
candle producing approximately 80 W of heat energy has a luminous
efficacy almost a hundred times lower than an incandescent light bulb.
Tea lights are even worse. With a Peltier element it is possible to con-
vert the heat released by a tea light into electricity and drive a highly
efficient LED reading light, allowing you to read your favorite book by https://goo.gl/CIyKwl
electric candle light.

Zero liquid discharge monitoring with LoRaWAN


Zero liquid discharge (ZLD) is one major step towards making an indus-
trial plant non-polluting. It means that a plant can take in water but it
should not discharge any wastewater. ZLD plants produce solid waste.
This project provides a cheap, solar-powered wireless liquid level monitor
for plants that cover a large surface and that may have multiple drains.
An ultrasonic transceiver, together with an Arduino and a LoRaWAN mod-
ule is about all that is needed at the drains, plus a laptop running Google
https://goo.gl/KyU7G1
maps at the office side of things.

So retro, but oh so stylish: the wooden Nixie watch


For many years now I am in the possession of a stylish, shiny wooden
attaché case, brought home from a trip to Tanzania. I never use it though,
because unfortunately I totally lack style. Maybe building and wearing
this beautiful wooden watch with its retro Nixie tube display improves
matters a bit? Maybe start wearing wooden glasses too? Or maybe I just
should stop wearing wooden shoes?
(160401)
https://goo.gl/lUMZRU

www.elektormagazine.com July & August 2017 79


LABS PROJECT

MicroPython and the pyboard


From blinking LED to …
webserver blinking an LED

By Clemens Valens (Elektor Labs)

Since its first release in 1991, the Python programming language got widely adopted, and today it has
become the preferred language of many programmers. Although intended for PC applications, a few years
ago Python got ported to embedded systems too. Called MicroPython (uPy), it was is a subset of Python
running on platforms like the BBC micro:bit and the ESP8266. And hey, it also runs on the pyboard, the
official uPy demonstrator board.

The Micro Python project (written as than six times the initial funding goal Ethernet module, and the NRF24L01+
two words at the time), including the of £15,000. This success implied that low-power wireless module. Now, almost
pyboard, was on Kickstarter by the the team had to throw in support for four years later, it’s time to see what
end of 2013 where it scooped up more the CC3000 Wi-Fi module, the WIZ820io has come of it all. Let’s have a play with
the pyboard and uPy.

Getting started with the


pyboard
In front of you, you should have a
pyboard v1.1 (PYBv1.1, nicely pack-
aged), a micro USB cable and a computer
(I used a Windows 10 laptop). Connect-
ing the board to the computer immedi-
ately brings up a window showing the
contents of drive E, labeled PYBFLASH.
Figure 1. The REPL. If you happened to have an SD card

80 July & August 2017 www.elektormagazine.com


plugged in, its contents will be shown >>> pyb.LED(1).on()
instead. The operating system should Features
also find a serial port. After launching a Notice how a red LED, next to the ‘USR’ • Programming in MicroPython
serial port terminal program (like Tera pushbutton, lights up. Repeating the • Simple webserver
Term), connecting it to the pyboard’s port command but with the ‘1’ replaced by • 100% Arduino-free
and pressing a key, you should see the a ‘2’ (use the arrow keys to go back to
Python prompt (Figure 1): the previous command and edit it) lights
up a green LED next to the red one. LED
MicroPython v1.8.2 on 2016-07-13; number 3 is yellow, number 4 is blue.
PYBv1.1 with STM32F405RG Except for the yellow one, the LEDs are
Type "help()" for more information. incredibly bright and you better not look project information
>>>  right into them. Let’s continue therefore
Python MicroPython
>>>  with LED(3), leaving you with the exer-
cise to switch off the other three LEDs. pyboard
That was fast, wasn’t it? Less than a min- To blink an LED forever a loop is needed, webserver
ute after plugging in the board you are for instance the while loop. To make it
in business — a minute mostly spent on loop forever use a condition that will Æ entry level
moving the mouse around to open and always be true, like the Boolean con- intermediate level
navigate the operating system’s menus. stant True. Enter the command (don’t expert level
forget the colon ‘:’ at the end)
REPL
What you are now looking at is a simple, >>> while True: 2 hours approx.
interactive programming environment
that takes single expressions, evaluates Next, enter a toggle LED command. The
them, and returns the result. Such an terminal will start indenting the code pyboard v1.1,
environment is known as a Read–Evalu- as is mandatory in Python, shown by PC,
ate–Print Loop or REPL. It is important to three dots. Enter a delay command to serial terminal
know this acronym, because, when doing set the blink rate, 250 ms for instance.
Python, you will encounter it a lot. People You should now have something like this:
that have worked with BASIC will under- £30 / €35 / $40 approx.
stand this kind of interface, although it >>> while True:
wasn’t probably called REPL when they ...     pyb.LED(3).toggle()
used BASIC. Python is, like BASIC, an
interpreted programming language, and,
like BASIC, Python can be compiled to
make it run faster. As a matter of fact,
Python is a lot like BASIC.

Next step: blink an LED


As the Python prompt suggests, type
‘help()’ and press the enter key. This
brings up a list of possible commands
to get you started (Figure 2). Having a
close look at this list is interesting as it
reveals what is possible with the board.
Built around an STM32F405RG ARM
Cortex-M4F microcontroller, the board
apparently has a real-time clock (RTC),
an analog-to-digital converter (ADC), a
digital-to-analog converter (DAC), four
LEDs, switches, an accelerometer, a ran-
dom number generator (RNG), I²C, SPI,
UART, I/O pins and it supports servos.
Some functions that control these periph-
erals are listed too, making for a pretty
comprehensive help indeed. Simply look-
ing at the board also reveals an SD card
connector.

At the prompt, type the command below


and press <Enter>. Figure 2. MicroPython also contains a comprehensive help.

www.elektormagazine.com July & August 2017 81


The pyboard is accessible as a flash drive
and when you open it in a file viewer,
you will see the file main.py . This is
the Python file that is executed after a
pyboard reset (hard with the ‘RST’ push-
button, or soft with the Ctrl-D command).
Open this file in the text editor and add
your commands to it. When done, save
the file and reset the board to launch
your program.

Getting out of a (deep) hole


Don’t be afraid to get creative, trial and
error is the way to go. If you manage
to mess things up in such a way that
nothing seems to be working anymore,
know that there are two rescue proto-
cols that may help you out: safe mode
and factory reset. In safe mode the files
boot.py and main.py are not executed,
giving you access to the file system (the
USB drive should appear). Now you can
edit them to fix any problems. Entering
safe mode starts by pressing the ‘USR’
button. Hold it down while you briefly
press the ‘RST’ button. Now watch the
LEDs. When only the yellow LED is on,
Figure 3. DfuSe busy writing new firmware to the pyboard.
release the ‘USR’ button. The board is
now in safe mode.
Factory reset goes a step further than
...     pyb.delay(250) -1 -2 21 safe mode. It deletes all the files on the
... -1 -2 20 internal pyboard storage (not those on
-2 -1 20 the SD card), and restores the files boot.
To get this loop going you have to leave … py, main.py, README.txt and pybcdc.inf
indentation mode first by pressing the back to their original state. To do a fac-
backspace key, then press enter. LED3 As before, press Ctrl-C to return to tory reset, proceed in the same way as
should now blink at the rate you entered. the prompt. This is a revealing test as for entering safe mode. However, this
As you may have noticed, the terminal it shows the speed of execution of an time, when the LEDs are doing their lit-
does not accept commands while the loop apparently simple loop. All it does is read tle dance, release the ‘USR’ button when
runs. To break out of the loop and return a sensor and print three integer values. I both the yellow and the green LEDs are
to the command prompt, press Ctrl-C measured about three lines per second, on. The yellow LED flashes quickly three
(‘interrupt a running program’). Now all which is not very fast indeed. times and you are back to where you
the commands that were (accidentally) The reason for this slowness is that the started: the beginning of this article.
entered while the loop was running will program is interpreted on-the-fly instead If the above methods did not help you
be executed, so better be careful what of being transformed (compiled) into solve your problems, you have one
you do during program execution! machine instructions first, and even last resort: reprogram the firmware.
though there is only one line of code For this you must put the board into
(ignoring the while statement), this is in Device Firmware Update (DFU) mode.
pyboard accelerometer reality a quite complex instruction. It is This is achieved by shorting pin P1 to
Here is a quick experiment to see if possible to speed things up by creating 3V3 (with a paperclip) before resetting
the board’s accelerometer is working so-called frozen modules, but doing this the board by pressing the ‘RST’ button.
correctly.  implies recompiling the complete firm- The first time you do this you may have
ware for the pyboard, which sadly is out- to install a DFU driver first. If Windows
>>> while True: side the scope of this article. does not manage to do this all by itself,
...     print(pyb.Accel().x(),pyb. as was the case on my computer, you
Accel().y(),pyb.Accel().z()) My first program will have to help it a bit. Download the
After playing a while in the REPL you may package STSW-STM32080 (or DfuSe
The output should be an endless list of be wondering how to transform your vol- Demo) from the STMicroelectronics
the three values x, y and z. Rotate, spin, atile experiments into something more, website and install it. Point Windows to
flip, roll, jaw, and shake the board to let’s say, persistent. This is easy enough; <installation path>\STMicroelectron-
make the numbers change. all you need is a good text editor. ics\Software\DfuSe v3.0.5\Bin\Driver\

82 July & August 2017 www.elektormagazine.com


to make it install the driver. If all went shouting and making signs to attract my other standard sockets methods that
well, DfuSe Demo should now list the attention, yes, I did reprogram the board work in MicroPython either and some
board (Figure 3). with a special firmware that includes net- of which even must be used. Go figure.
Precompiled firmwares can be found on work drivers (pybv11-network-20170322- Somebody didn’t test things all the way
the uPy website. Make sure to pick one v1.8.7-461-g58f23de.dfu). through at MicroPython Corp. Inc. Ltd.
that corresponds to your board. In the I had pasted the simple-enough web- OK, the W5200-based WIZ810io module
‘Upgrade or Verify Action’ area (not the server code in main.py but it didn’t work. is not the most recent one.
‘Upload Action’ area) click ‘Choose’, navi- How to go about to debug it? Actually, Anyway, even though replacing sendall
gate to the DFU file that you want to pro- I don’t know what the preferred Python by send was easy enough, it did not make
gram and click ‘Upgrade’ (not ‘Upload’). way is. I guess, either you add debug my webserver work. It took another good
Close DfuSe, remove the boot jumper statements to the program or you can deal of head scratching to find the cul-
and press ‘RST’. You may now have to paste the program line-by-line into the prit: a missing content-length field in
do a factory reset to restore the flash REPL, which is what I ended up doing. the HTTP page header sent by my web-
file system. In my case it was necessary Albeit somewhat tedious, this technique server. After adding it, my MicroPython
to let Windows repair the pyboard drive quickly showed me that the call of the webpage finally showed up in my browser
after a firmware update. sendall method of my socket object was (Listing 1).
DFU is, of course, also possible on Linux invalid (read the code [4] to understand Putting the working code in the file
and Mac OS by using dfu-util or pydfu. what I am on about). There is no such main.py lead to new surprises. Ini-
method! Now this is strange, because tially it worked fine, but when I started
Not all mistakes are yours the MicroPython socket documentation improving it a bit, something went hor-
When you start to learn writing uPy pro- clearly mentions it on its website. This ribly wrong and it all fell over. To cut
grams you will, of course, encounter your took me to the MicroPython source code a long story short, the file system on
share of errors and mistakes. One of the repository on GitHub to have a closer my pyboard had somehow become cor-
most common — and frustrating — errors look at the network driver where I dis- rupted and the webpage’s contents had
is forgetting to use the tab key. Or think- covered, after a lot browsing, that the been transformed into garbage. Also,
ing that you were using tabs, when in WIZnet driver does not export a sendall the file main.py had become inaccessi-
reality you were not. Or using it when method at all. It doesn’t export some ble and its size was reduced to 0. After
in fact you shouldn’t. Remember that
Python requires indentation and for this
it only accepts tab characters. There-
fore, make sure that your text editor
preserves tabs as there are many that
silently replace them by spaces. The free-
ware editor Notepad++ is a good editor
that does Python syntax highlighting and
preserves tabs.
Besides indentation problems you may
also run into Python compatibility issues.
MicroPython is a port of Python, but it is
not a perfect port. On the uPy website
you can find a list of differences between
CPython (the Python reference imple-
mentation) and uPy. So, if one day you
run into a strange error where code that
is supposed to work, doesn’t, maybe you
should check this list.

Setting up a simple webserver


Since the Kickstarter campaign had
promised WIZ810io network support
and since I happened to have a few of
these modules lying around, I decided
to try to set up a simple webserver (Fig-
ure 4). This was the point where things
became complicated and clouds started
to gather. The first step was, of course,
Google in the hope to find an all-singing,
all-dancing example, but I came up emp-
ty-handed. I did find some MicroPython
webserver code [4], but it didn’t work Figure 4. MicroPython webserver built with a PYBv1.1 pyboard and a WIZ810io Ethernet module
on my pyboard. Now, before you start from WIZnet.

www.elektormagazine.com July & August 2017 83


restoring the pyboard using the methods
Listing 1. Simple webserver for the pyboard.
described above, I could reinstall my lit-
tle program to get the webserver up and import os
running again. import network
This experience taught me to do the import socket
experimentation in the REPL instead of
saving a file too often on the pyboard. Its # Adapt these for your network.
filesystem seems to be a tad fragile. For my_ip = '192.168.2.33'
comfortable REPL copy-pasting it is useful subnet_mask = '255.255.255.0'
to have a serial terminal that supports gateway = '192.168.2.1'
multi-line pasting. Tera Term does this.
dns = '8.8.8.8' # dunno what to put here, 8.8.8.8 is WIZnet example.
Such a tool allows you to paste blocks
# The one and only page we serve.
of code up to points of where a man-
page_name = 'page1.htm'
ual backspace is required to decrease
the indent level (for instance at the end
# Initialize network interface.
of a while loop or if-else statement),
speeding things up a bit. nic = network.WIZNET5K(pyb.SPI(1),pyb.Pin.board.X5,pyb.Pin.board.X4)
nic.ifconfig((my_ip,subnet_mask,gateway,dns))
I want more! print(nic.ifconfig())
The MicroPython website has nice tuto- # Launch server (2x Ctrl-C gets you back into REPL mode).
rials that show how to use the pyboard’s s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
peripherals. Reading them is highly rec- s.bind(('',80))
ommended and will save you a lot of s.listen(0)
time. They also present some advanced while True:
techniques like combining assembler with conn, addr = s.accept() # addr is not used but required.
uPy. Keep in mind that these tutorials request = conn.recv(1024) # receive HTTP request.
concern the pyboard and presented tech-
# Look for the string "Val=".
niques may not work (in the same way)
val_begin = str(request).find('Val=')
on another board.
if val_begin>0:
# Found string "Val=", now extract value.
Conclusion
MicroPython and the pyboard present pyb.LED(1).on()
a fun and low-cost way of getting into val_end = str(request).find(' ',val_begin)
embedded programming and learning v = str(request)[val_begin+4:val_end]
Python along the way. All of the goods print("Val =",v)
promised during the Kickstarter cam- conn.send(v)
paign have been delivered, even the # LED3 off if v<50, on otherwise.
stretch goals. The uPy website with its if int(v)<50:
nice tutorials may not always be up to pyb.LED(3).off()
date, so, when in doubt, consult the proj- else:
ect pages at GitHub. pyb.LED(3).on()
(160428)
else:
Web Links # String "Val=" not found, serve web page.
pyb.LED(2).on()
[1] www.elektormagazine.com/160428
# Send HTTP header.
[2] http://micropython.org/
conn.send('HTTP/1.1 200 OK\nConnection: close\nServer: pyboard\
[3] https://github.com/micropython
nContent-Type: text/html\n')
[4] https://github.com/RinusW/WiPy/ conn.send('Content-Length: ')
tree/master/AiCWebserver # We have to insert the size of the data we are going to send.
conn.send(str(os.stat(page_name)[6]))
# Unreadable way of getting file size.
# Close HTTP header.
from the store conn.send('\n\n')

ªSKU17931: # Send web page.


MicroPython pyboard v1.1 f = open(page_name,'r')
ªSKU18023: conn.send(f.read())
Python for microcontrollers: conn.close()
getting started with MicroPython pyb.LED(1).off()
pyb.LED(2).off()

84 July & August 2017 www.elektormagazine.com


(almost) everything
Q you wanted to know about...
Components in Space
Interview with Jaime Estela, Spectrum Aerospace Group

Now that small companies and even start-ups can afford their own satellites, it’s good to know more about
components in space.

age currents of the components, causing higher power dis-


sipation which ultimately causes failure of the components.

Single event effect: Highly ionized particles induce strong


transient discharges (noise pulses) in semiconductor devices,
which interfere with device behavior and cause data corruption.

Q How are components tested for radiation resistance?

A There are two main types of radiation test in practice:

Total ionizing dose (TID) test: For this test a cobalt-60


cell is used as a gamma source. Similar sources are used
in medical equipment, but there they are much weaker. The
radiation exposure simulates several years of deployment in
space in a very short time. The radiation-induced charges
affect the properties of semiconductor devices in various ways.

Figure 1. ISS astronauts practicing repair tasks for electronic components Single event effect (SEE) test: In this test a particle accel-
(photo: NASA).