Elektor En202405
Elektor En202405
95
*
1
*
IN
CE 196
Repairing
Electronic
Equipment
Tools, Techniques, and Tips
10 MHz Reference
Generator
Highly Accurate,
With Distributor and
Galvanic Isolation
membership!
www.elektormagazine.com/Member
COLOPHON EDITORIAL
Jens Nickel
Volume 50, No. 529 International Editor-in-Chief, Elektor Magazine
May & June 2024
ISSN 1757-0875
The Team
International Editor-in-Chief: Jens Nickel | Content Director: C. J. Abate | International Editorial
Staff: Asma Adhimi, Roberto Armani, Eric Bogers, Jan Buiting, Stuart Cording, Rolf Gerstendorf (RG),
Ton Giesberts, Ouafae Hassani, Hedwig Hennekens, Saad Imtiaz, Alina Neacsu, Dr. Thomas Scherer,
PEFC Certified
Jean-Francois Simon, Clemens Valens, Brian Tristam Williams | Regular Contributors: David Ashton,
This product is from
sustainably managed
forests and controlled
Tam Hanna, Ilse Joostens, Prof. Dr. Martin Ossmann, Alfred Rosenkränzer | Graphic Design &
Prepress: Harmen Heida, Sylvia Sopamena, Patrick Wielders | Publisher: Erik Jansen | Technical
sources
PEFC/30-31-151 www.pefc.org
questions: [email protected]
Repairing
Electronic
Equipment
Tools, Techniques, and Tips 26
Regulars Features
3 Colophon 23 embedded world 2024
New Products Presented at the Fair
6 STM32 Wireless Innovation Design Contest 2024
The Winners 26 Repairing Electronic Equipment
Tools, Techniques, and Tips
33 Starting Out in Electronics…
… Continues the Opamp Theory 40 Sparkplug at a Glance
A Specification for MQTT Data
48 Peculiar Parts
The CRTC 69 The Arduino-Inside Measurement Lab
An 8-in-1 Test-and-Measurement Instrument for the
86 From Life’s Experience
Electronics Workbench
Pangpong Butt Launcher
88 FNIRSI 1014D Digital Storage Oscilloscope
92 2024: An AI Odyssey
Good Performance for Tight Budgets
Getting Object Detection Up and Running
112 Raspberry Pi 5 and Beyond
106 Err-lectronics
An Interview with Eben Upton, CEO of Raspberry Pi
Corrections, Updates, and Readers’ Letters
Industry
62 Open Source and Its Significance for the
Electronics Industry (2)
66 M12 Circular Connector With A-coding
First Choice for Industrial Applications
FNIRSI 1014D
Digital Storage Oscilloscope
Good Performance for Tight Budgets 88
4 May & June 2024 www.elektormagazine.com
+3V3
Qwiic
I2C.
K3
1 Grove
2 3 I2C
4 K4
1 OLED
2 3 K11
-A
R2 4
1 OLE
2 3
R4 4 K9
6k7
1 2 3 4
Radar-Controlled
22k
1 2
Lighting RV1
100k
R1
The AmpVolt Modular
DC Power Meter (Part 1)
JP1
R3
100k
Automatic
K12
22k
BATT
50 18
1
2
INA16 1
9-IN
1
lab
O R IG IN A L
Ele
la b
or
kt
la b or
8 In-Circuit LC Meter • Elek t Elektor Magazine July & August 2024
A Prototype Study As usual, we’ll have an exciting mix of projects, circuits,
fundamentals, and tips and tricks for electronics engineers and
18 The AmpVolt Modular DC Power Meter (Part 1)
makers. We’ll focus on IoT & Sensors. Visit Elektor's IoT & Sensors
Measure DC Power and Energy Consumption up to
page for more content! www.elektormagazine.com/iot-sensors
50 V and 5 A
36 A Simple DDS Signal Generator
From the contents:
Direct Digital Synthesis in Its Purest Form
> DIY Thermal Imaging Camera
50 Radar-Controlled Lighting > Cloud Chamber for Radioactivity
Automatic Stairway Light With Human Presence Detection > Best Sensors for Weather Stations
54 Digital Bubble Level and Active Stroboscopic Disc for
> Airflow Detector With Arduino
Turntables
> GSM Alarm Interface
Fine-Tune Your Record Player With This All-in-One Tool
> Low-Cost I2C Tester
> Water Leak Detector
74 Sound Card Performs Gain/Phase and Impedance > AWS Cloud for Arduino and Co.
Analysis
and much more!
For Frequencies From 100 Hz to 90 kHz
80 Measuring pH Value With the Arduino UNO R4 Elektor Magazine July & August 2024 edition will be published
Check the Quality of Your Water around July 10th. Arrival of printed copies for Elektor Gold members
96 10 MHz Reference Generator is subject to transport.
Highly Accurate, With Distributor and Galvanic Isolation
102 Project Update #2: ESP32-Based Energy Meter
Some Enhancements
FOCUS ON
STM32 Wireless
Innovation Design Contest
After several exciting months of competition, the STMicroelectronics [2] booth (4A-148)
during which dozens of innovative projects during the embedded world 2024 trade fair.
were submitted, the 2024 STM32 Wireless The top three winners emerged from the pool
Innovation Design Contest [1] (presented by of exceptional entries, each bringing a unique
STMicroelectronics and Elektor) has crowned perspective to the realm of wireless technol-
its top three winners after an intense period ogy (see Figure 1).
of evaluation. Congratulations to the following
STM32 winners for their hard work: Cédric Jiminez Claiming the prestigious First Prize (€2,500)
Wireless Innovation (First Prize), Alain Romaszewski (Second was Cédric Jiminez, with his Open-Vario
Design Contest Prize), and Balthazar Deliers (Third Prize). project [3]: an open-source, multi-functional
Want to learn about the connected variometer for paragliding and
STM32 Wireless Innovation Winning STM32-Based Projects hang gliding, equipped with features like
Design Contest and all the After meticulous scrutiny, the judges GNSS positioning, accelerometer, tempera-
participating projects? Visit the announced the winners on April 10, 2024, at ture sensing, glide ratio computation, and flight
Contest webpage for all the
details.
elektormagazine.com/st-contest
data recording, all based on the STM32WB- the Matter over Thread protocol, enabling
5MM-DK discovery kit (Figure 2). The judges real-time monitoring of power consumption
were thoroughly impressed by the design, the via smartphone (Figure 4). The setup includes
features of the project, as well as the level custom hardware for data conversion and
of detail used by Cédric in the extensive connection to the STM32WB5MM-DK dev kit,
documentation he wrote. Congratulations, software development in C/C++ and Python, STM32 Solutions
Cédric for this well-deserved victory! and a smart home integration that visualizes Visit the STMicroelectronics
energy usage. All of this demonstrates an website (www.st.com) for
Alain Romaszewski wins the Second Prize innovative approach to home energy manage- more information about all the
(€1,500) with his ZigBee Environmental ment. Well done! company’s innovative STM32
Measurement Center [4] for indoor plants solutions, including the NUCLEO-
or greenhouses, using the STM32WB5MM-DK STM32 Wireless Innovation and WBA52CG, STM32WB5MM-DK, and
kit (Figure 3). It features sensors for monitor- Inspiration Nucleo-WL55JC.
ing soil humidity, temperature, ambient condi- The STM32 Wireless Innovation Design
tions, and CO2 levels, and includes automated Contest provided a platform for inventors
watering and lighting systems based on these and technology enthusiasts to unleash their
measurements, with data management via a creativity and explore many different paths in
server MQTT and Node-RED application. Well the realm of wireless applications [6]. From
done, Alain, for this very well documented and IoT [7] to home automation, the contest has
skillfully designed project, which uses numer- showcased the diverse ways in which wireless
ous external modules while sporting a neat technology can shape the future. Are you
3D-printed case. inspired? As you develop your own STM32-
based projects, we encourage you to share
The Third Prize (€1,000) went to Balthazar your innovations with the global electronics
Deliers for his Electric Meter that Matters community. You are welcome to post your
[5], which integrates a Linky smart electricity projects on the Elektor Labs online platform:
meter with a smart home ecosystem using www.elektormagazine.com/labs.
240241-01
WEB LINKS
[1] 2024 STM32 Wireless Innovation Design Contest: https://www.elektormagazine.com/st-contest
[2] STMicroelectronics: https://www.st.com/
[3] Open-Vario on Elektor labs: https://www.elektormagazine.com/labs/the-open-source-multifunction-variometer-for-paragliding
[4] ZigBee Environmental Measurement Center on Elektor labs:
https://www.elektormagazine.com/labs/zigbee-environmental-measurement-center-for-indoor-plants-or-greenhouse
[5] Electric Meter that Matters on Elektor labs: https://www.elektormagazine.com/labs/the-electric-meter-that-matters
[6] Wireless applications: https://www.elektormagazine.com/wireless-communication
[7] IoT: https://www.elektormagazine.com/iot-sensors
In-Circuit
LC Meter A Prototype Study
When troubleshooting a board, the ability to test provide estimates of the value of the paral-
passive components without desoldering them from lel resistor Rp, and also the assessment of
a potential series resistor in one run. And
the PCB is most useful but at the same time critical, further, if we exchange the capacitor C with
since interference from the rest of the circuit during an inductor L, the driving voltage U(t) with
testing must be minimized. This prototype circuit can a driving current I(t), and also exchange
the roles of parallel and series resistances,
measure in-circuit capacitance from 1 pF to 80 mF or a similar scheme can serve to measure
inductance from 1 mH to 40 H. It uses a low voltage inductors. The current measurement is
method that is robust against parasitic parallel or series exchanged with a voltage measurement
across the inductor (instead of the voltage
resistance. The signal processing is mainly analog; the over a current measurement shunt in capac-
computation to extract L, C, and “parasitic” resistance is itance mode).
performed by an Arduino UNO.
These features make it tempting to use
the method for in-circuit components as
well, without the need to desolder them. To
A while ago, I played with a function be proportional to the driving triangle make this viable, one may observe that — if
generator to assess a capacitor quickly by voltage U(t). If the driving voltage now runs not powered — basically all semiconduc-
measuring the current arising through it between negative and positive values, it will tor parts, in the worst-case, expose diode
from the applied voltage waveform with an be zero at some t0 times during the constant junctions, with the likelihood of creating
oscilloscope. The initial setup was primi- rising and falling slopes of the triangle. potential additional parasitic current paths.
tive, since I was using a small shunt resis- Then at these times the parasitic resis- If the driving voltage stays below some
tor in series with the capacitor to infer the tive current IR(t0) = 0 and the measured 100 mV, the diode currents are still negli-
current. There, a triangular voltage wave voltage at these times only represents C gible. In the case of inductors, the resulting
seems to offer the advantage that, during and is independent of Rp. In practice, the voltage must stay below that limit. Such low
the constant rising and falling slopes of measurement may be done by sampling voltages also allow for ignoring the polarity
the applied waveform (ideally), the current the current at times where U(t) = 0. In short, of electrolytic capacitors.
through the capacitor has a constant this was the initial idea to make a simple
(positive or negative) value, which is propor- C-metering circuit that supplies a voltage In the presented prototype circuit, the
tional to the capacitance, C (Refer to the that is proportional to C and independent shunt and inductor voltages stay below
Measurement Method text box). of leakage or other parallel resistors. 10 mV. Synchronous sampling and averag-
ing make the measurement robust against
An additional current IR(t) = U(t)/Rp due to A more in-depth analysis of the scheme the influences of internal and external noise
a parallel (leakage) resistor Rp would simply showed the possibility for its extensions, to sources.
x1 R-current-
feed
sampling pulse
generator feedback
x1/500+ Cx
amplifier
Uadc
x500
averaging
sampling Lx
oscilloscope R-shunt
Block Diagram > Triangle drive voltage generator current flows through the shunt resis-
The block diagram of the circuit is shown (U12A…D). tor, which is selected by SW2 respectively
in Figure 1. As functional elements, the > Sampling window generation (U2A, via the auto-ranging MOSFET bank Q2…
circuit contains a generator of a defined U2B, U3A, U3B, U13A, U13B). Q7. The resulting shunt voltage of a few
triangular voltage waveform, comparators, > Signal amplifier (U16A, U16B). millivolts is amplified (total factor ≈ 500)
and logic to generate the sampling inter- > Synchronous polarity reversal (Q8, by U16A and U16B. After the first ampli-
val pulses, the signal amplifier A and the U1B). fier stage, the positive feedback signal is
sampling stage(s) with buffer amplifiers > Sampling, averaging (U5B, U5C, U5D; extracted by R74 and fed into the drive
(not shown). The connection to the Arduino C2, C3, C4; U5A) and buffering (U1C, voltage attenuator (R3, R8) to raise the drive
includes a four-channel, 16-bit ADC ADS1115 U1D). voltage such that the shunt voltage drop is
by Texas Instruments. The analog inputs added. The amplified signal ICx(t) can be
Ax of the microcontroller itself are used to The triangle drive voltage is created by used for monitoring through an oscillo-
determine the positions of range switches, integration (U12A), i.e. by accumulat- scope. In the circuit, it is further processed
and digital outputs address a number ing into C1 a current set by the resistor by synchronous polarity switching, which
of MOS switches to support a partial connected by switch SW2 to the polari- is performed by (Q8, U1B).
auto-ranging. Thereby, the Arduino sketch ty-switched (Q1, U12C) reference voltage.
can evaluate the measurement and then U12B compares the triangle output to the For an ideal capacitor, the output of U1B
display C or L values and possible (effec- intended opamp’s voltage swing (±2.5 V) would then be a DC voltage proportional to
tive) parasitic resistances with some further to enact the polarity switching (Q1) of its capacitance value (see again Measure-
auxiliary information on a 4×20 LCD. the high-precision voltage reference that ment Method). Non-ideal components such
controls the value determining slope. as parallel resistance, etc., induce a slope
Schematic Diagram on the current through Rshunt and thus a
The circuit (analog part) is shown in U12D buffers the attenuated (R3, R8) trian- ripple in the output value of U1B. There-
Figure 2. It contains the following groups: gular voltage to drive the test item Cx with fore, the sawtooth-like ripple voltage has
> Reference voltages (U4, U11). low impedance. The induced capacitor to be sampled in proper time windows and
R9
100M 4 4 4
R7 C5 C6 C7
R19 R11 U1 U12 U17
100k
C1
10k
10M
11 1µ 11 1µ 11 1µ
R12
SW1B R20 1M SW1A 22n
2
–9V
10k
R14 R6 10
1 5
100k U12A 100k R17 8
3 7 Q1 U12C
R23 R21 R15 U12B 100k 9
1k
6
+9V
10k
10k
+2V5 R5
R16 J113
100k
R22 1k
R10 R13 8 8 8 8
R24
10k
C8 C9 C10 C11
100k
100k
U2 U3 U13 U16
1k
4 1µ 4 1µ 4 1µ 4 1µ
2
R29 1 –2V5
+5V U2A –9V
R48 3
U9B
10k
U7B
1k
5 U18A
4 1 6
6 =1 3 4
6 2 & 7 ≥1 +9V
R65 SW2A R59
R32 7
U2B
10k
1k
5
14 14 14 14
U7A
1k
C12 C13 C14 C15
R63 1
3 U5 U18 U7 U9
≥1
10k
2 2
7 1µ 7 1µ 7 1µ 7 1µ
R33 1
U3A
3
1k
U9A –9V
1
MOD1 SCL =1
3
R37 2
2k2 R38
ARDUINO UNO SDA R36
2k2 5
AREF R35
1k
2k2 7
GND R34 U3B U1, U12, U17 = TL084
2k2 6
RESERVED 13 1 16 9 8
R41
U2, U3, U13 = MC33172
IOREF 12 IN1 IN2 IN3 IN4
+5V R25 U5 = 4016
RESET 11 2 3 3
U7 = 4001
1k
1k
3.3V 10 D1 S1 1
R26 U13A U18B U7C U9 = 4070
5V 9 15 14 2 U9C 6 8
POWER
1M 5
VIN 7 D3 S3
1k
DG413xY R28 7
6 7 6 U13B
10k 6
A0 5 D4 S4
R43 +2V5
ANALOG IN
A1 4 V– GND V+ VL
ICSP Lx
A2 3 +5V
RESET
4 5 13 12 R1
1k
MISO
SCK
A3 2 4k7
3
3
U9D
A4 TX 1 1 12 U5A
U1A
1
A5 RX 0 –9V +9V =1
11
2 13
–2V5
R46
SW2B
2
100k
+5V MOD2
R55 R57
ADS1115 Module
10k
10k
R60 SW3B 9 1
ICx(t) R31 VDD
1k 5 8 2
R66 R30 U1C 10k GND
4 3 10 3
SW3A R71 100k 100k SCL
3 4
4k7 R73 C2 SDA
1 6 9 U5B 6 5
U16A 100k ADDR
2 7 8 8 9 6
U16B R72 U1B 1µ ALRT
5 10 13 7
+9V A0
100Ω
100k
R67 R74 R69 R75
10Ω
10k
100k
U5D
0Ω
R58
1k
+2V5
4k7
4k7
9V 2k5
U4 Q8 10k
1N4007 1N4007
Q7
J113 R62
C3 C4
TL431D
100k
R64
Q6 +2V5 10k
1µ 1µ
BT2 U11 R3
Q5
1k
R47 Cx
TL431D 12
9V –2V5 Q4
100Ω
14
R4 R56 U12D R8
100Ω
13
10Ω SW2C
2k2
Q3
R61
1Ω
–9V
Q2
230581-006
A B
Measurement Method
The charge Q that is stored in a
capacitor is proportional to the voltage
U, increasing the voltage U(t) over a
capacitor increases the stored charge.
That implies that current has to flow
(I(t)). Mathematically, this is expressed
by I(t) = C(dU/dt). If U increases with a
constant slope, the current is constant.
A change from rising to falling slope
implies a change in current direction.
This is illustrated in Example A. sampling interval starts at this point, voltage. Driving the test item (L) with
there will be no residual influence of Rs a linear increasing current I(t) yields a
For a resistor, the current is proportional on the inferred C value. In the circuit constant induced constant voltage U(t)
to U (Example B), the current through presented in Example C, the time ∆t ≃ ts over the inductor U = L(dI/dt). The similar
a resistor parallel to C simply adds the is determined by conversion of the time effect of the parallel resistor in the case
capacitor current. At any time t0 with delay between slope sign change and of capacitors is now the extra voltage
U(t0) = 0 only, the capacitive current the zero crossing of I(t) to a voltage. caused by the (series) resistance of the
prevails. Sampling at these times (and inductor, while any parallel resistance to
multiplying with the sign of the slope) Note that the shunt used for the the inductor corresponds to the effect
yields current values that solely depend measurement of I(t) also adds to of the series resistance of the capacitor
on C. If the current I(t) increases linearly the effective series resistance Rs. To (see Example D).
around t0, the sampling time interval may compensate for this, the feedback
have a finite symmetric extension prior correction to U(t) is added to the circuit While, for “good” capacitors, the
and after t0, which helps to average out (see Feedback). parallel resistance is typically so large
contributions from various noise sources. that its effect is virtually invisible, the
To apply the scheme to inductors series resistance of inductors is nearly
Now, if we also have a series resistance L instead of capacitors, one has to always clearly visible as the slope of the
Rs, its effect is that the transition from exchange the roles of current and detected voltage across the inductor.
positive to negative current values
when the U(t) slope changes is no
longer abrupt, but follows a transient C D
with a finite time constant. This time
constant is τs = RC, where R is the
value of Rs ∥ Rp = RsRp/(Rs+Rp), which
for large Rp is very close to the series
resistance Rs. After a few cycles of τs the
transient effects are done. If the central
averaged, in order to single-out the proper supplied for the main sampling that yields R30×C2 and R39×C3; however, these times
and stable C and Rp values. the value of C and is supplied to MOSFET contain an additional factor 1/f — about 4
switch U5B, which then samples the ampli- for the main sample and 8 for the off-center
The sampling time windows are extracted fier output around the central part of the sampling — with f being the fraction of the
by the logic (U7, U18) driven by signal from slope and averages it in C2. Further off-cen- sloping period during which the sampling
comparators (U2, U3, U13; in the proto- ter sampling windows are selected such that window is open. The relative sampling
type I used audio MC33172 opamps from only the “late” windows of rising or falling window widths (f) are controlled by the
STMicroelectronics) that detect transi- slopes are selected by ANDing them with voltage divider levels seen by the row of
tions of the (non-attenuated) drive voltage Sync1 or NOT Sync1. By feeding these to U5C comparators (U2, U3, U13).
at levels supplied by the voltage divider and U5D, respectively, the amplifier voltage
between R24 and R43. XORing subsequent signal in both (rising and falling edges) Finally, to get a coarse estimate of the series
transitions yields a logic signal that is high selected off-center windows is averaged resistance, the time of zero crossing (=
when the drive voltage is within the window in C3. half of the voltage jump at slope reversal
between the pertaining levels. if Rp = ∞) of the signal is detected by U1A
The sampling average of the main signal (as comparator) and XORed (U9D) with the
Thus, a central window, symmetric to as well as that of the two off-center periods Sync1 signal, which ideally is High during
the zero-crossing of the drive voltage, is have time constants that are determined by the delay between sign reversal (“zero”) and
Amplifier SW1A
Examples
As an illustration of the basic operation
of the circuit as capacitance meter, the
display with a 470 nF styroflex capacitor
is shown in Figure 4a and Figure 4b.
The two sides show the results obtained
with different slopes of drive voltage U(t). Figure 4: Readouts obtained with different slopes of drive voltage U(t), with the auto-range-determined
The slope is indicated by the value of the values of the shunt resistor R, a) with estimate of a series resistor Rs = 187 Ω (left), and b) without it
(right).
chosen integrator resistor RC in the last
display line, there also the (auto-range-de-
termined) actual value of the shunt resistor
R = Rshunt is shown. The primary result C is
displayed together with the raw voltage at
A0 of the ADS1115. The second line shows
the estimated value, Rp, of the parallel resis-
tor and the related voltage at A1 of ADS1115,
where it is too large to be detected and is
indicated by the display with “N.A”.
location of the sampling intervals. The large The second example simulates a large 1 s (RC = 10 MΩ). As visible in Figure 8,
gap in the center (around 25 ms) is the main 1,000 µF electrolytic in-circuit capacitor the raw voltage trace (blue) now shows the
sampling window, the marks around 38 ms parallel to two diodes in both directions and jump transient of finite time at slope rever-
indicate the sampling window where the a 1 kΩ resistor and a 10 Ω series resistor sal, as well as the sloped ICx(t) voltage at
voltage increase due to a parallel resistor (Figure 7). The large capacitance requires later times that indicate the presence of
is probed. the choice of a slope with a period of about the parallel resistor. The applied voltage
Arduino Sketch
The communication with the microcontroller comprises the use
of an ADS1115-based 4-channel 16 bit ADC shield and output on
a 4x20 LCD, both connected via I2C. Further auxiliary voltages
are read directly via the direct Arduino analog inputs A0…A2,
used to decode range switch positions and support for the respectively for inductors
(semi) auto-ranging function. Further digital GPIOs are used
to operate the MOSFET switches that select shunt or current
feed resistors. The actual values of the corresponding resistors
should be updated in the source code to obtain optimal
accuracy. The main function of the microcontroller is to interpret
the measured ADC voltages and convert them into the desired The analysis of the transient that contains information on the
information on C/L, Rp and Rs. series resistance of C or the parallel resistance of L (or other
losses) is more involved. In the first step, the time delay between
Uadc0 Rc ⋅ C1 slope change and zero crossing of the signal τESR must be
Cx = ⋅ − Coffset inferred from the voltage reading in the 3rd ADC channel Uadc2:
Uref R shunt ⋅ A
and similarly
with A being the factor that combines the attenuation applied to In the case where the parallel resistance of C can be neglected
the drive voltage ≃ 1/10 with the amplification α ≃ 500, i.e. A ≃ 50; (i.e. no slope in the current signal) the series resistance can
for the actual values see the Arduino sketch! easily be obtained by Rs = τESR/(ln(2)Cx) in case of a substantial
parallel resistance effect, the extra slope has to be accounted
The parallel resistance (series resistance for inductors) the for, and the expression becomes slightly more complex. If the
difference of voltages from the “late” off-center sampling Rp related slope dominates the zero crossing, a reliable estimate
window Uadc1 and the central window Uadc0 is used, Ureffp of Rs is not possible and the display will show N.A. The actual
is the drive voltage difference between the centers of the two expressions can be seen in the source of the Arduino program.
sampling windows
Miscellaneous
SW1 = rotary switch, 6×2
SW2 = rotary switch, 4×3
SW3 = toggle switch, 2×2 a) b)
WEB LINKS
[1] Files for download: https://elektormagazine.com/230581-01
[2] This project on YouTube: https://youtu.be/hfbUxPfHmeg
www.elektor.com/ezine/en
or
Ele
lab
ORIGINA
L
Ele
b
or
kt
or
la
la b
• Ele k t
SCL
Measurement
SDA
Microcontroller
Tx Rx
OLED
Display VIN + +
Rx Tx
ADS1015
VIN –
Module
Microcontroller Module
A0 Load
A1
Voltage Div. –
22k
5
ADDR
6
ALRT
7
A0
8
A1
9
R1 JP1 R3 A2
RV1 10
A3
100k
22k
100k
K12 NC_VIN+
1
BATT
K5
2 1
NC_VIN–
2
K6 1 2 3 4 1 2 3 4 1 2 3 4 5
1
LOAD
INA169-IN K7 K8 K1
2
RAW OUT AG INA169-OUT 240141-001
The Software
Figure 5: 3D Rendering of the PCB. We made a default firmware for an ESP32-C3 with the Arduino IDE. Our
sketch [5] measures voltage and current, displays these on an OLED
Display [6], and calculates power consumption and the state of charge
(SoC) of a battery connected. The firmware is designed to work with
various microcontrollers and includes setup for serial communication
and I2C for connecting the ADS1015 ADC module and OLED display.
Refer to Figure 6 to see the AmpVolt prototype in action.
Energy Consumed
State of Charge (SoC) = × 100%
%
Battery Capacity
In this, “Energy Consumed” is the accumulated energy usage over Overview of the Arduino Sketch
time, measured in watt-hours (Wh), and “Battery Capacity” is the total
energy capacity of the battery, also in Wh. This calculation provides Setup and Global Variables
a real-time snapshot of how much energy has been used from the > Initializes serial communication and I2C with specific
battery, relative to its total capacity, offering valuable insight into the SDA and SCL pins.
remaining battery life and when recharging may be necessary. > Sets up the ADS1015 ADC module for reading analog
inputs and the OLED display for output.
Sample Rate > Defines constants for resistor values in the voltage
The ADS1015 ADC, as specified in its datasheet, boasts a maximum and current dividers, allowing for accurate voltage and
Sample Rate of 3,300 samples/s. However, when operated within current measurements.
the Arduino Framework, this rate experiences a notable adjust- > Establishes variables for calculating energy consumed
ment. Specifically, in single-shot test mode, the sample rate reduces over time and tracking the start time for elapsed time
to 312 samples/s, and in continuous mode, it can reach up to 1500 calculations.
samples/s. This reduction is attributed to the Hardware Abstraction
Layer (HAL) of Arduino, which, while facilitating code abstraction and Main Functions
simplicity, imposes a significant speed constraint on the ESP32. > readVoltage(): Reads and calculates the voltage based
on ADC values and the voltage divider ratio, accounting
During testing phases, efforts to enhance the sample rate were under- for any zero error offset.
taken by adjusting the I2C speed from the standard 10 kHz to 90 kHz. > readCurrent(): Similar to readVoltage(), but
This adjustment yielded a modest increase of approximately 20 to 30 calculates current using ADC values and the current
samples/s in single-shot test mode and 100 samples/s in continuous divider ratio.
mode. This outcome highlights the limitations imposed by the Arduino > sendData(): Sends data (voltage, current, or power)
Framework’s HAL on the ESP32’s performance capabilities. over serial communication based on the command
received.
It’s worth noting that operating the ESP32 in its native environment, > calculateAndSendAdditionalData(): Calculates
specifically the ESP-IDF, presents an opportunity for substantial additional data like power and state of charge, then
improvements in sample rate efficiency. The ESP-IDF allows for more sends it in JSON format over serial.
direct control over the hardware, potentially unlocking the ADS1015’s > readCommand(): Reads commands from the serial
full sampling capabilities. port, returning a complete command when a newline
character is detected.
Nonetheless, to accommodate a broader audience and ensure acces-
sibility, our first firmware implementation detailed here remains within Display and Utility Functions
the Arduino Framework. This approach aims to strike a balance > updateDisplay(): Updates the OLED display with
between performance and simplicity. However, there is an option to voltage, current, power, and other relevant data.
have highest measurement performance and additionally an easy > elapsedTimeAsString(): Calculates elapsed time since
application programming with Arduino and all its libraries: using two the module started and formats it as a string
microcontrollers.
WEB LINKS
[1] INA169 Current Sense Amplifier | Datasheet: https://www.ti.com/product/INA169
[2] ADS1015 12-bit ADC | Datasheet: https://www.ti.com/product/ADS1015
[3] GY-169 - INA169 Current Module: https://s.click.aliexpress.com/e/_DFZSO21
[4] ADS1015 Module 12-bit ADC: https://s.click.aliexpress.com/e/_DnMmvRJ
[5] AmpVolt V1.0 | Source code and PCB files: https://github.com/ElektorLabs/AmpVolt
[6] 0.96” OLED Display (Blue, I2C, 4-Pin): https://elektor.com/products/0-96-oled-display-blue-i2c-4-pin
EDITORs’
Picks
embedded world 2024
embedded world 2024 took place from April 9 to 11 in Nuremberg, Germany.
It was a must for everyone dealing with microcontrollers and tools. This year, there were
32,000 visitors, and more than 1,100 exhibitors in seven halls. Elektor editors
Brian Tristam Williams and Jens Nickel, plus Elektor Lab engineers Jean-François
Simon and Saad Imtiaz, took the chance to go around and find a lot of interesting new
products. As always, their personal selection can only be a small sampling of all the
innovations seen at the fair. You’ll find even more on our YouTube channel,
www.youtube.com/ElektorIM.
PTC
Java is a powerful language for multi-platform
programming with a gigantic ecosystem. But,
when it comes to real-time applications, Java is
not suitable because of unpredictable garbage
collector processes. The Perc Real-Time Java
platform from PTC fills this gap, with a virtual
machine and a tool set for realtime behavior. IoT
gateways are just one possible application.
www.ptc.com/en/products/developer-tools/perc
Seeed and
well-known for easy
Grove modules are me s int o play.
d now AI co
quick prototyping, an for an aly sis
e can be us ed
Artificial intelligenc Grov e se ns ors
m differe nt
of combined data fro sic) sp ee ch and
ll as for (ba
(sensor fusion) as we the Grove
Already available is
image recognition. ined with
, which can be comb
Vision AI Module V2 as host
act XIAO ESP32-S3
a camera and a comp ssible
models are also acce
controller. Pretrained there are
raft AI platform, and
on the public SenseC
more to come. 2
m/grove_vision_ai_v
wiki.seeedstudio.co
Arduino
Arduino displayed some new Pro solutions, for example new expansi
on
blocks for the Opta model, to allow more inputs/outputs. The Opta
Digital
Expansion block integrates 16 programmable inputs (0–24 V digital
or 0–10 V
analog) and 8 outputs, with a choice of 8 electromechanical or solid-sta
te
relays depending on the model. The Opta Analog Expansion block offers
6
programmable 0–10 V or 4–20 mA inputs and 6× 0-10 V, 4-20 mA or
PWM
outputs. These modules are designed in collaboration with Finder and
will
enable professionals to scale up their automation projects while integrat
ing
nicely with the Arduino ecosystem or Arduino PLC IDE.
An Arduino partner, SOLO Motor Controllers, was also present ,
demonstrating its various motor control modules, driven either by an
Arduino R4 or an Arduino Pro. The demonstration test bench (see photo)
used CANOpen to drive motors and linear actuators.
www.arduino.cc/pro/hardware-arduino-opta-expansions
www.solomotorcontrollers.com
Lattice
At the show, Lattice was mostly focused on
Cologne Chip showing their high-end, low-power products, such
We had a very nice chat with Cologne Chip, as the Lattice Avant-E. They had a very nice demo,
known for being one of the few EU-based FPGA which aggregated data from several sensors: a
manufacturers. Even the silicon die is made in a camera for on-board image recognition, a LiDAR, a
German “fab!” One of the interesting features of the RADAR, and so on. The demo setup is shown here.
GateMate family is scalability. The GateMate A1 and www.latticesemi.com/en/Products/FPGAandCPLD/
A2 are available now, and the A4 will be available Avant-E
shortly. They are all pin-compatible, which means
you can prototype your project with a GateMate A1
or A2 and then move to the A4 when it becomes
available, with no modifications to your layout.
They offer a good price-performance ratio and the
software toolchain is open-source too. There are
a few development boards available, including an
affordable one available from Olimex.
www.colognechip.com
www.olimex.com/Products/FPGA/GateMate/
GateMateA1-EVB/open-source-hardware
m,
is s e d t h e Live Strea t
If you m atch the video a
you can w u.be/eYugqSVYgY0
t
https://you
M5Stack
M5Stack is set to release several new products,
each utilizing Espressif’s ESP32 chips for diverse
applications. The ultra-compact NANO C6, about
the size of a fingertip and featuring the ESP32-C6
chip, offers advanced connectivity features
suitable for space-constrained environments. The
CORE MP135 focuses on long-range connectivity
with LoRaWAN and LTE, ideal for remote IoT
applications. The Cardputer, a unique, card-sized
Raspberry Pi computer with an OLED display, keyboard, and
Raspberry Pi was teasing brand- powered by the ESP32-S3, offers extensive I/O
new, unannounced products, capabilities, merging portability with functionality.
including the M.2 HAT+ for M5Stack also previewed the StamPLC, a
SSD applications and the new programmable power supply, and a digital
Raspberry Pi monitor. An exciting multimeter (DMM), all based on the ESP32-S3.
new product is a brand-new These tools are aimed at enhancing automation,
Raspberry Pi AI Camera module, measurement, and control systems.
which looks just like any other www.m5stack.com
camera module from the company. But, this one
has all the AI power on the module itself, meaning
that it will work for you while connected to as little
as a Raspberry Pi from the Zero range. The proof
was on display for all to see, with two demos,
one doing live object detection at 30 frames per
second, while another was able to do human-frame
detection and overlay wireframes in real time.
raspberrypi.com
240239-01
ab • Elek
or l t
kt
or
Ele
lab
ORIGINAL
Repairing
Ele
b
or
kt
or
la
la b
• Ele k t
Electronic Equipment
Tools, Techniques and Tips
First, let’s take a look at the tools that will Let’s start with the essential tools useful at the same time, among other things
be useful for most electronic repairs. Of (Figure 1). You’ll need at least: a multime- for testing power supplies, by monitoring
course, everyone will have their list of ter, a soldering iron and solder, an oscillo- the output voltage while increasing output
favorite tools, according to personal prefer- scope, and an adjustable power supply. To current. As for the second soldering iron,
ence. Here’s my list. If you’re a beginner, check solder joints and inspect the PCB it will be almost irreplaceable as a comple-
it may give you a few pointers to get you for defects, a small magnifying glass with ment to the first, for desoldering all kinds
started. If you’ve only got one or two of a high enough magnification (10× in my of SMD components with one iron in each
these tools, and the list seems far too long case) will be a precious help. Even a very hand.
or far too expensive, don’t panic! On the inexpensive magnifier will be infinitely
one hand, it’s always possible to do without, better than no magnifier at all; personally, I Speaking of soldering, here are a few extra
until you’ve decided that it’s the right time use a €3 plastic model from RS (ref 136-8106) supplies. Desoldering braid (I recommend
to buy a new tool, and, on the other hand, which serves me well. the tinned variant) and gel flux. For cleaning
most of these things can be found either up after soldering, cotton swabs and 99% (or,
very cheaply in China, or at affordable It’s debatable, but, in my opinion, a second failing that, 90%) isopropyl alcohol work
prices on the second-hand market in any multimeter and a second soldering iron are well. I’d recommend putting the alcohol
country. also essential tools. Two multimeters are in small plastic bottles (50 or 100 ml,
Figure 4: The infamous bulging electrolytic Figure 5: Using the diode mode to test a power MOSFET.
capacitors. (Source: Wikipedia [3])
WEB LINKS
[1] A well-known SMD marking code catalog: https://smd.yooneed.one
[2] Another useful SMD marking code catalog: http://marsport.org.uk/smd/mainframe.htm
[3] Source of the bulging capacitor picture: https://commons.wikimedia.org/wiki/File:D865PERL_bulge_2.jpg
[4] The Signal Path YouTube channel: https://youtube.com/@Thesignalpath
[5] Feedback Loop YouTube channel: https://youtube.com/@feedback-loop
[6] DiodeGoneWild YouTube channel: https://youtube.com/@DiodeGoneWild
[7] Tony359 YouTube channel: https://youtube.com/@tony359
Starting Out in
Electronics…
...Continues the Opamp Theory
Open-Loop Gain and Transition Frequency the open-loop gain is significantly larger than the gain set using
The open-loop gain of an opamp is specified for DC voltages. For those two resistors.
alternating voltages, the gain decreases with frequency (Figure 1).
If we want to dimension a circuit “safely,” we must ensure that the
This figure shows the course of the open-loop gain as a function open-loop gain is at least a factor 10 larger than the externally set
of the frequency for an internally frequency-compensated opera- gain. If, for an opamp with a transition frequency of 1 MHz, we set
tional amplifier. (For the sake of simplicity, we restrict ourselves to the gain to 10×, we could operate the circuit up to about 10 kHz.
frequency-compensated opamps). The open-loop gain decreases Operational amplifiers for audio applications therefore excel not
by 20 dB per decade — that is equal to 6 dB per octave. Internally, only by low noise, but also by a high transition frequency — in the
therefore, a first-order low-pass filter is present. case of the NE5534, for example, it is at 10 MHz.
For the opamp in our example, the open-loop gain for DC voltage The Slew Rate
is 100,000, and the transition frequency — the frequency at which An operational amplifier such as the LM324 has a transition
the open-loop gain has decreased to 1 — is at 1 MHz. We see that frequency of 100 kHz; for a simple 1× amplified buffer stage, this
the open-loop gain remains at the DC level of 100,000 until about is just about sufficient for audio applications: As long as the output
10 kHz, before decreasing by 20 dB per decade. (For the record, voltage does not exceed much more than about 100 mV, such a
the transition frequency is also called the unity gain frequency). circuit will function without any problems.
Earlier, we saw that, for determining the gain of an opamp circuit, But, when the amplitude of the output voltage is increased to,
the open-loop gain is irrelevant, but is solely determined by the let’s say, 10 V (at a frequency of 20 kHz), we are rewarded with
ratio of two external resistors. However, this is true only as long as some nasty distortion. That is an issue of the so-called slew rate.
Offset Current To make a long story short: With cutoff frequencies of 20 Hz and
In operational amplifiers with bipolar transistors, the problem 20 kHz, we would “ruin” the frequency characteristics of the
arises that small currents (in the order of a few nanoamperes) flow circuit; therefore, it is better to put the cutoff frequencies of the
to the inputs. These currents cause a voltage drop across the exter- individual amplifier stages well outside the actual transmission
nal resistors, and these in turn are responsible for a corresponding range. The actual limiting of that range to 20 Hz at the lower
DC voltage offset. end and 20 kHz at the upper end then takes place at the input
stage (if possible, preferably with an LC filter even before the first
This offset voltage that appears on the output of the opamp can semiconductor, to avoid demodulating HF disturbances from
be reduced by making the external resistors as small as possible local transmitters).
(while taking care not to create issues due to a too low an input
resistance). Another possibility is to make the resistors on both Of course, everyone has to decide for themselves where they actually
inputs as equal as possible, as sketched in Figure 2. define these cut-off frequencies: it also depends, for example, on
the number of amplifier stages connected in series. In our example,
Resistor R3 would have to be chosen to be the same value in this we keep a factor 3 as a “safety margin” and therefore choose 6 Hz
circuit as the combined parallel circuit of R1 and R2; if these were and 60 kHz, respectively. Our amplifier stage needs to amplify
10 kΩ and 100 kΩ, respectively, we would select a resistor of 9.1 kΩ by a factor of 10, so we take values of 10 kΩ and 100 kΩ for the
from our box of components. external resistors.
An alternative solution — mainly used in audio engineering — is to Since there is a virtual zero point at the inverting input of the
leave the offset voltage as it is and fit coupling capacitors between opamp, the input resistance of the circuit is equal to the value
the individual stages. of R1, which thus forms a high-pass filter together with C1.
The nearest available value is 2.2 µF, which puts the cut-off
frequency at 7.2 Hz. Since this still keeps us far enough away from input resistance, R3 should have a value of 100 kΩ…1 MΩ in the
20 Hz, we don’t need to worry about it any further. case of bipolar opamps and a value of 1 MΩ…10 MΩ in the case of
opamps with FET inputs.
The value of capacitor C2 is chosen in a way that its impedance at
the upper cutoff frequency is the same as the resistance value of R2: That’s it for now; next time we’ll discuss (among other things)
symmetrical connections and the summing amplifier.
Translated by Hans Adams — 240031-01
Again, we can use the standard value of 22 pF without further ado. Editor’s Note: This series of articles, Starting Out in Electronics, is
based on the book, Basiskurs Elektronik, by Michael Ebner, which
Offset Issues With a Non-Inverting Amplifier was published in German and Dutch by Elektor.
Unlike the inverting amplifier, the non-inverting amplifier in
its basic configuration has an open input; that means its input
impedance is equal to the (high) input impedance of the opera- Questions or Comments?
tional amplifier. If you have any technical questions or comments about this article,
feel free to contact the Elektor editorial team at [email protected].
In metrology, such high-impedance inputs are often desirable,
but in other areas, they only cause us inconvenience: The offset
currents cause a correspondingly large DC voltage offset, and irradi-
ation into the inputs causes enormous interference. It is therefore
Related Products
absolutely necessary to apply a resistor from the open input to
ground, as outlined in Figure 4. > B. Kainka, Basic Electronics for Beginners
(Elektor, 2020)
To minimize the DC voltage offset, R3 should be equal to the parallel Book: www.elektor.com/19212
Ebook: www.elektor.com/19213
circuit of R1 and R2; however, if we are more interested in a high
POWERING INNOVATION
DISCOVER THE R24C2T25 –
THE NEXT GENERATION IN
12.83
DC/DC CONVERSION
mm
recom-power.com/gate-drivers
11th- 13th JUNE | BOOTH 6-452
A Simple
DDS Signal Generator
Direct Digital Synthesis in Its Purest Form
Figure 1:
Analog Devices offer a range of integrated The AD9851 module.
circuits containing complete DDS signal
generators. These ICs cannot operate by
themselves, but need a low-pass filter and a an adjustable DC voltage, thus produc- a digital-to-analog converter (DAC). The
controlling device for initialization and setting ing a square wave with an adjustable duty AD9851’s datasheet [2] provides more detailed
of the desired output frequency. At AliExpress cycle. The addition of a small microproces- information. Figure 1 shows the module with
[1], complete modules are offered carrying the sor, a rotary encoder and a display makes a the AD9851. To make it fit into the selected
AD chip together with the filter and some complete signal generator. enclosure, the LED was removed and a corner
other components for a very competitive of the module was cut off. The potentiome-
price. In the little signal generator described What’s Under the Hood ter for adjusting the comparator’s DC input
below, a module with the AD9851 is used. This Signal generation is accomplished by direct voltage was removed as well, as it was not
module can produce a sine wave signal with digital synthesis (DDS). It uses a numerically needed: That DC voltage will be generated
a frequency of between 1 Hz and 70 MHz. controlled oscillator (NCO) and a lookup by a DAC within the microcontroller used to
A comparator is present on the chip, which table (LUT) to produce a digital sine wave. control the module.
compares the sine wave output signal with The latter is converted into analog form with
The AD9851 can be controlled in either a
parallel or a serial mode. Since the serial mode
needs only four connections and the parallel
DATA W0 W1 W2 W3 W39
mode more than twice as many, we use the
serial mode for initialization and frequency
FQ_UD selection. The “serial load” signals, as they
are called in the datasheet, are shown in
Figure 2. The fourth signal resets the device
W_CLK
to initialize it. A microcontroller provides
these signals using the built-in SPI peripheral.
40 W_CLK Cycles
Since the frequency will be variable, a rotary
230695-010
Figure 2: Serial load signals. (Source: AD9851 datasheet [2]) encoder is used to allow the user to change it.
1
VCC
2
D–
C1 C2 C3 3
D+
4
10
9
8
7
6
5
4
3
2
1
GND
10n 100n 10µ
POWER 1 14
VDD Vss USB
LED 2 13
VCC
GND
D0
D1
D2
D3
D4
D5
D6
D7
RA5 U2 RA0
3 12
ADJ RA4 RA1
4 11 U3
U1 RA3 RA2
AD9851 5 10 4
RC5 RC0 SDA
6 9 3
RC4 RC1 SCL
7 8 2
W_CLK
RC3 RC2 VCC
FU_UD
RESET
Qout1
Qout2
Zout1
Zout2
DATA
1
GND
VCC
GND
PIC18F04Q41
OLED 128x32
11
12
13
14
15
16
17
18
19
20
SW1
J3 J2
Encoder
Square Sine
230695-009
A small display is added to show informa- with a PICkit 4, PICkit 5, ICD 4, ICD 5, or is easier to set up than with the older type
tion on the currently selected frequency. One MPLAB Snap. Earlier versions of these tools PICs. The current frequency of the generated
should be aware of the fact that a DDS signal are not compatible with this PIC. The proces- signal is shown on a small 0.91″ OLED display,
generator does not produce pure sine wave sor was programmed before mounting on the which is controlled via an I2C bus with a clock
signals — the output signal contains multiple PCB. It is possible, however, to program the frequency of 400 kHz.
harmonics of the sampling frequency. processor on board by soldering temporary
wires to the processor pins and then desol- How to Change Settings
A Look at the Circuit Diagram der them after programming. The 5 V supply Pressing the rotary encoder’s knob moves
Figure 3 depicts the schematic diagram. voltage is provided via a USB connector. an underline cursor from left to right, circling
Because only a limited number of IOs is back to the left when the far right is reached.
required, a Microchip PIC18F04Q41 14-pin The PIC18F04Q41 belongs to a new series of Turning the encoder will increase or decrease
microcontroller is used. It controls the DDS PICs. In particular, the serial IO modules for the number underneath and to the left of
module with four outputs, reads the rotary SPI and I2C have been improved compared to the decoder. This provides an easy way to
encoder with three inputs, and drives the older devices. This is very useful in this appli- quickly cover the total range from 1 Hz to
display via the I2C bus, which needs another cation. The SPI module now has a buffered 70 MHz. Any change of the displayed number
two outputs. The DC output voltage is gener- output register, giving us the opportunity to will cause an output signal to the DDS module
ated on pin 11. produce the required forty-bit serial output to adjust the output frequency accordingly.
signal in a single continuous stream. For this
The last pins remaining are 1 and 14 for serial signal, a clock of 16 MHz is used, so that As mentioned, the DC voltage that goes to
power supply and 12 and 13 for program- a change of the generator’s output frequency the input of the comparator on the module is
ming. The PIC18F04Q41 can be programmed takes less than 3 µs. Also, the I2C module produced by a DAC inside the microcontroller.
Figure 4a: The front of the PCB, with the display. Figure 4b: The back of the PCB, without the Figure 4c: The back of the PCB with the DDS
DDS module. module installed.
Modules
U1 = AD9851 module
U3 = 0.91” 128×32 OLED display
Microcontroller made pluggable. Here, we run into a space About the Author
U2 = PIC18F04Q41-I/SL problem: The enclosure is only 20 mm high. Willem den Hollander has been passion-
Using an ultra-low-profile socket connec- ate about electronics since the age of 12.
Capacitors tor and accompanying low-profile pins, the He has a Master’s degree in electronics
All capacitors are SMD, 0805 height could just be kept within this restric- engineering and worked for 37 years in
C1 = 10 nF tion. The microprocessor is only available in R&D in the field of consumer electronics.
C2 = 100 nF an SMD package. The three capacitors and His favorite subjects are power supplies,
C3 = 10 µF the USB connector are also SMDs, which digital circuits, programmable logic, and
made the layout very simple. microprocessors. Several of his projects
Miscellaneous have been published in Elektor.
SW1 = Rotary Encoder Firmware
J1 = Mini USB connector The firmware [3] has been written in assem-
J2, J3 = SMA connector, 90˚ bler and occupies only 13% of the proces-
Enclosure = Strapubox 1551RGY sor’s program memory. At first, the ports Questions or Comments?
Rotary Encoder Knob are set up and then two configurable logic Do you have technical questions
PCB cells (CLC’s) are set as flip-flops that detect or comments about this article?
any positive transient caused by turning the Feel free to contact the author at
rotary encoder. Hereafter, timer2 is configured [email protected] or the Elektor
to provide a 10 ms delay for debouncing the editorial team at [email protected].
This voltage can be changed by pressing the switch, and timer4 to set a delay of about
encoder’s switch for about two seconds until 100 ms. The latter is required after initializ-
the display shows a three-digit number. In this ing the OLED display. After setting up the
situation, the voltage may be adjusted in 256 DAC that produces the DC voltage for the
steps by turning the encoder until the square comparator, the I2C bus module is configured
wave’s duty cycle is as desired. Pressing the to communicate with the OLED display with
knob again for longer than two seconds makes a clock frequency of 400 kHz, and finally the
the display return to frequency display. The SPI module that controls the DDS module.
value of the selected DC voltage is stored in After this, the display, the DDS module, and
the PIC’s internal EEPROM. the interrupts are initialized.
WEB LINKS
[1] AliExpress online store: https://aliexpress.com
[2] AD9851 Datasheet: https://analog.com/media/en/technical-documentation/data-sheets/ad9851.pdf
[3] Firmware download on this article’s webpage: https://elektormagazine.com/230695-01
UPDATED
STORE
Sparkplug
at a Glance
By Tam Hanna (Hungary) In addition, MQTT only offered rudimentary authentication for a long
time, and managing the connected devices (beyond issuing a Last
The popular MQTT protocol is one Will message [2]) required developer involvement or the use of a
of the most straightforward ways second service. The lack of standardization also meant that this work
had to be done by each developer and, in the worst case, anew for
to connect distributed electronics, each project.
such as sensors, controllers, and
data storage devices. As long as the The new protocol, called Sparkplug, now forces the user data transmit-
ted via MQTT into a schema, which ultimately ensures an organized
transmitted messages follow the and manageable structure.
(lax) rules of the standard and the
broker can be addressed correctly, In this article, we will take a look at the basic concepts and also carry
out initial practical experiments with the technology, which is still at
the data exchange works. A new an early stage.
protocol called Sparkplug attempts
to formalize the user data with an
Please Also Read the Standard Document!
additional layer, which makes it For reasons of space alone, this technical article cannot provide
easier to offer auxiliary services and a complete description of Sparkplug. However, the specification
create a diverse ecosystem, among of the protocol in version 3.0 is well written. It is therefore advis-
able to have the 140-page PDF document at hand [3]. This article
other benefits. Here is a first look – repeatedly contains cross-references to sections of the document
including some practical examples, where background information can be found.
as always.
First Overview
Originally created by Cirrus Link, the Sparkplug specification [3] has
The MQTT protocol [1], which is based on TCP/IP, has become a kind been managed by the Eclipse Foundation for some time now, which
of standard on the Internet of Things; it is lightweight, flexible, and has been trying to position itself as a “jack of all trades” in the IoT
easy to understand. In addition, MQTT can also deal very well with sector for quite a while.
network participants that are only temporarily active or accessible.
However, MQTT only ensures reliable communication — the organi- The second version of the standard introduced the use of Google
zation of the user data is up to the developer. Protocol Buffers [4] as a container data format. Sparkplug version 3.0,
Figure 1: These components work together to create a Sparkplug system. (Source: [3])
It should be noted that the MQTT standard allows the creation of “filters” The Sparkplug specification relies on Protocol Buffers as a payload,
with various special characters — it is therefore possible, for example, probably also due to their immensely broad support, for which there
to register all messages belonging to a certain type as relevant. Further are now suitable libraries in almost every programming language. The
information on this can be found in [5], for example. Protocol Buffers website is well worth reading for developers seriously
interested in Sparkplug [4].
Analysis of the Message Structure
The second factor when working with the Sparkplug specification is It should be noted that Protocol Buffers represent a binary protocol. In
the role of the individual messages, as outlined in Figure 2. Since the practice, however, as well as in the specification document, you often
specification describes the data flow by means of (confusing) timing see JSON annotations structured according to the following scheme:
diagrams, we will try to group important message types by role and
payload. However, if you want to look at the diagrams yourself, section 5 {
of the specification is recommended. "timestamp": <timestamp>,
"metrics": [{
Let’s start with the DBIRTH and NBIRTH messages. As suggested by "name": <metric_name>,
“birth” in the names, these are messages that indicate new parts of "alias": <alias>,
the Sparkplug network becoming available. NBIRTH deals with the "timestamp": <timestamp>,
appearance of a new node, while DBIRTH indicates the appearance "dataType": <datatype>,
of a new device. "value": <value>
}],
It is important that the payload of the messages must deliver a struc- "seq": <sequence_number>
ture that enables the receiver to generate a complete digital image }
(often referred to as a Digital Twin) of everything that creeps and flies
in the newly added endpoint. It follows from the same logic that both This is a format rehydrated from the binary data, which has nothing
NDEATH and DDEATH are responsible for the disappearance of endpoints. in common with the information physically sent over the airwaves. In
The system is fully modular internally. For this reason, in the first step, tamhan@TAMHAN18:~/designerlauncher/app$
we opt for the Config → Systems → Modules option to activate module ./designerlauncher.sh
management. We then see a group of ready-to-use archives [9] with
modules from third-party providers — to use the Sparkplug platform, The next step is for the newly launched Designer application to estab-
we need the MQTT Transmission and MQTT Engine elements, which lish contact. To do this, we first choose the Add Designer option, then
we install one by one using the web interface. click the Localhost option to add a new “platform entry.” The Open
Designer button then allows us to edit the information.
In the next step, we switch to the configuration option Config →
Mqttengine → MQTT Engine Settings, where we are informed — as In the next step, we decide on the SampleQuickStart option and click
shown in Figure 3 — that the Mosquitto instance living in the Docker on Open to load the start example. Clicking on the View → Panels →
container has been successfully found. OPC Browser option then opens another panel in which various OPC
data sources are available. Expand the Expand Devices section there
There is also a further setting under Config → Mqtttransmission → to show the [Sample_Device] device. A drag and drop operation is
MQTT Transmission Settings, the correctness of which must also be then required, as shown in Figure 4.
checked. In the interests of keeping the server platform compact, the
system has a modular design here, too. The Get Designer button allows Next, we must ensure that we close the Designer and use the Save
you to download a separate component called Designer, which allows and Close option to save and “upload” all changes made in the local
you to parameterize the settings existing in the platform. Download the application. We can then return to the web interface, where we can
archive in the first step and unpack it — the actual start of the appli- set a new configuration using the MQTT TRANSMISSION Settings
cation then occurs as with any other command line utility: → Transmitters → Create new Settings option. It is then important
that the text default is entered in the Tag Provider field — saving the
changes updates the system status.
tamhan@TAMHAN18:~$ mosquitto_sub
-h localhost -t spBv1.0/#
The reward for our efforts is the appearance of binary files, as shown
in Figure 5.
public void messageArrived In the first step, open the Java file and adjust two of the dozens of
(String topic, MqttMessage message) throws Exception { member variables according to the following scheme:
System.out.println("Message Arrived on topic " + topic);
public class SparkplugExample
// Initialize the outbound payload if required. implements MqttCallbackExtended {
SparkplugBPayloadBuilder outboundPayloadBuilder =
new SparkplugBPayloadBuilder // HW/SW versions
(getNextSeqNum()).setTimestamp(new Date()); . . .
private String serverUrl =
String[] splitTopic = topic.split("/"); "tcp://192.168.1.68:1883";
if (splitTopic[0].equals(NAMESPACE) && private long PUBLISH_PERIOD = 1000;
splitTopic[1].equals(groupId) && // Publish period in milliseconds
splitTopic[2].equals("NCMD") &&
splitTopic[3].equals(edgeNode)) { As above, the value stored in the serverUrl variable must, of course, be
adapted to the situation existing in your network. Reducing PUBLISH_
SparkplugBPayload inboundPayload = PERIOD then ensures that the main application is supplied with data
new SparkplugBPayloadDecoder(). more quickly.
buildFromByteArray(message.getPayload());
... After saving the modified file, it is necessary to return to the project
root directory and run a compilation again using the package manage-
In this context, it is also interesting to note that the standard is capable ment tool, Maven:
of processing extensive payloads. A good example of this is the follow-
ing for loop, which enumerates the various command types supplied pi@raspberrypi:~/sparkspace/tahu/java/
on the Raspberry Pi: examples/simple $ mvn clean install
The reward for our efforts is the creation of a .jar file, which can be
found in the ~/sparkspace/tahu/java/examples/simple/target direc-
tory. Activation then takes place according to the following scheme:
pi@raspberrypi:~/sparkspace/tahu/java/
examples/simple/target $ java
-jar example_simple-1.0.1.jar
To harvest the results, you must switch back to the Designer applica-
tion, where the result is displayed as shown in Figure 6.
tamhan@TAMHAN18:/usr/local/bin/ignition$
./gwcmd.sh --passwd the case of many other systems, however, the true value of such a
Password has been reset. Gateway needs to be restarted. standard only becomes apparent when it is widely adopted. There is
tamhan@TAMHAN18:/usr/local/bin/ no way around the “network effect law.”
ignition$ ./ignition.sh stop Translated by Jörg Starkmuth — 230038-01
Stopping Ignition-Gateway...
tamhan@TAMHAN18:/usr/local/bin/
ignition$ ./ignition.sh start
Starting Ignition-Gateway with systemd... Questions or Comments?
Waiting for Ignition-Gateway... Do you have questions or comments about this article? Email
running: PID:382296 the author at [email protected], or contact Elektor at
[email protected].
After restarting the gateway, you can log in via the URL — the gateway
then presents the first user with a window in which a new username
and the corresponding password for the administrator account can About the Author
be specified. As an engineer, Tam Hanna has been working with electronics,
computers and software for more than 20 years. He is a self-employed
A Solid System designer, book author and journalist (@tam.hanna on Instagram). In
With Sparkplug, the Eclipse Foundation is entering the race with a his spare time, Tam designs and produces 3D-printed solutions and,
solid ecosystem that seems well suited to “taming” the uncontrolled amongst other things, has a passion to trade and enjoy high-end
proliferation that can undoubtedly be found in the MQTT area. As in cigars.
WEB LINKS
[1] MQTT basics: https://hivemq.com/mqtt
[2] MQTT: Last Will: https://hivemq.com/blog/mqtt-essentials-part-9-last-will-and-testament
[3] Standard document: https://sparkplug.eclipse.org/specification/version/3.0/documents/sparkplug-specification-3.0.0.pdf
[4] Google Protocol Buffers: https://developers.google.com/protocol-buffers
[5] MQTT: Topics: https://hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices
[6] Sparkplug software: https://sparkplug.eclipse.org/compatibility/compatible-software
[7] Eclipse Tahu: https://github.com/eclipse/tahu
[8] Inductive Automation Ignition download: https://inductiveautomation.com/downloads
[9] Third-party modules: https://inductiveautomation.com/downloads/third-party-modules/8.0.17
The CRTC
Peculiar Parts, the Series
These chips were used with a character generator (CG) ROM. These
had usually seven character address lines, which were driven by
Figure 2: Building up text from lines of pixels — here using a 5×7 character the ASCII code for the character to be generated, and, for each
matrix. (Source: Intel) ASCII code, they output the pixel pattern for that character, stored
as rows and columns. Common character formats were 5×7 dots I worked on terminal systems that used CRTCs, but never did any
high, and 7×9 for better resolution. The CRTC would select which programming for them. Although they made a system designer’s
line of a character it needed by means of more address lines (called life easier, there was still a lot of work to be done setting them up
Line Count). for the desired character and screen format, and programming
the DMA access.
Building Characters, Line by Line
The CRTC would address the CG ROM with the code for the first So, the next time you’re struggling to get a text or graphics LCD
character, line address 1, to get the top row of pixels for that charac- working, spare a thought for the designers of yore who had to work
ter. It would then change the address to that of the second charac- with CRTCs!
ter, and get the top row of pixels for that character. This would 240058-01
continue until the end of that line. Then the CRTC would change
the line count address to 2, and repeat the process for the second
line of row pixels. All the time, the CG pixels were being sent to
the monitor in serial form. In this way, a complete line of charac-
ters would be output to the monitor. Then a new row of characters
would be loaded into the CRTC memory, and it would repeat the
whole process for another line of characters. Up to 80 characters
× 64 rows could be programmed, and the CRTC also generated the
horizontal and vertical sync signals. About the Author
David Ashton was born in London, grew up in Rhodesia (now Zimba-
Most CRTCs only had enough memory to hold two lines of character bwe), lived and worked in Zimbabwe, and now lives in Australia.
codes. One would be processed while the other was loaded. Usually, He has been interested in electronics since he was “knee-high to
DMA (direct memory access) was used — in this way, the load on a grasshopper.” Rhodesia was not the center of the electronics
the microprocessor was much-reduced (Figure 3). universe, so adapting, substituting, and scrounging components
were skills he acquired early (and still prides himself on). He has run
They had ancillary functions such as light pen detection — a pen an electronics lab, but has worked mainly in telecommunications.
or (for games) or a gun with a light-sensitive resistor or transistor
could be used to load a register with the screen coordinates where
the pen was pointed. A cursor position could be programmed, and Questions or Comments?
a whole character block would be lit to show the cursor. The CRTCs If you have technical questions or comments about this
could also have attributes programmed so that a character could article, feel free to contact the Elektor editorial team by
be underlined or shown in reverse, bright, or blinking. email at [email protected].
Radar-Controlled
Lighting
Automatic Stairway Light With
Human Presence Detection
to
El
r lab
TES
By Gino de Cock (Belgium)
TED
Ele k
rl
PIR-controlled lights and presence detectors are
to
ab
ab rl
• E l e kt o
found everywhere. They work quite well, but only for
warm moving targets. Radar-based human presence
detectors offer better precision and can detect speed of the target. This is known as the
stationary human bodies. This makes them suitable Doppler effect. We all know it from the sound
of cars and trains passing by. The pitch of
for automatic lighting control in offices and small, the sound is higher when the vehicle comes
dark rooms. In this article, we use such a radar to towards you and lower when it moves away.
turn a dark staircase’s lights on and off.
Measuring the distance of a target with a
CW radar can be done by adding frequency
modulation (FM). When the signal frequency
is swept up (or down) linearly, the received
You surely know those automatic lights a.k.a. 24 GHz amateur, amateur satellite, reflected signal will not have the same instan-
controlled by PIR sensors. They switch on radio location, and Earth-exploration satellite taneous frequency as the transmitted signal
when you pass in front of them and switch service band far from the busy 2.4 GHz Wi-Fi because it is delayed. The two frequencies
off automatically when movement is no band. Developed by Hi-Link Electronics, the are slightly different, and this difference is
longer detected. Practical as they may be, module provides human body detection proportional to the distance between the
they do have a mind of their own, making for home automation systems. Its working transmitter and the target. However, since
them behave a bit quirkily sometimes. With principle is based on frequency-modulated there is also the Doppler effect, this method
the introduction of low-cost radar-based continuous wave (FMCW) radar to detect only works accurately for static or slow-mov-
human-presence detectors, it has become both moving and stationary human bodies. ing objects.
possible to solve some of the issues that a
PIR sensor has. Radar detectors provide FMCW Radar Theory in a All the complexity from the above explanation
real presence detection even when you’re Nutshell is reduced inside the HLK-LD2410 module to
not moving, keeping the light on when you’re The radar is based on two working princi- a single digital output indicating the detected
reading on the toilet. It’s radar, so it’s immune ples. First, it uses the Doppler effect to detect target state. The output is high when a person
to false positive detections due to changing objects. A continuous wave (CW) signal is is detected, moving or not. The application
light conditions, a bee, moving hot air, etc. transmitted, then reflected by conducting using the radar module can therefore remain
materials such as metal or water, and thus simple, as it only has to react to a binary state.
The HLK-LD2410 Radar Module also by human bodies. When the reflecting
The HLK-LD2410 sensor [1] is such a object (the target) is moving, the wavelength The Circuit
high-sensitivity human-presence sensing of the reflected signal (and therefore its The application described in this article is
module. It works in the 1.2 cm wavelength frequency) changes proportionally to the an automatic light for a staircase (Figure 1).
4k7
47k
S
T1 1
K1
as it is enough to change a resistor value to
R1 G
IRF9540
T2 D
2 obtain a 5 V output. Use the following equation
to calculate the resistor value:
3
1k
IC1 IC2
4
D 1 8 G
IN+ OUT+
2x 2 7 R5
TLP431LP IN+ MOD1 OUT+ IRF540 S
R2
MP1584
1k
3 6
IN– OUT– LED1
4 5
IN– OUT–
1k...75k
RED
RA had a value of 115 kΩ. To lower the output at least two different shapes (Figure 4): a Configuring the Radar
to 5 V, R A must have a value of 43 kΩ. On 16×22 mm board with a large 5-way 0.1″-pitch The HLK-LD2410 module works out of the box,
our prototype, this could be arranged for by pin header and as a 7×39 mm long and but it can be configured over a serial port with
soldering a 68 kΩ resistor in parallel to RA. narrow board with a small, 0.05″-pitch connec- a Windows program named LD2410 Tool [2].
Another way is to replace RA with a 39 kΩ tor. Even though either type can be used, their This explains the presence of connector K2,
resistor in series with a 3.9 kΩ resistor (when connectors are not wired the same way. The a serial port wired up for a 3.3 V FTDI-com-
RB = 8.2 kΩ). first type’s signals are ordered TX, RX, OUT, patible USB-to-serial cable.
GND, and VCC, while the second has OUT,
PCB TX, RX, GND, and VCC. The PCB is wired for The radar module must, of course, be powered
At the Elektor lab, we designed a small printed the first type, but has room for the second before you can configure it, and there are two
circuit board (PCB) for the project with test type. The long and narrow module we ordered ways to do this: from the USB-to-serial cable
points for checking some vital signals. The came with an adapter cable that can easily be (JP1 closed) or from the circuit’s power supply
board fits in a cheap, plastic (ABS) 1591XXA connected to the PCB. Therefore, both types (JP1 open). In the second case, ensure that the
enclosure from Hammond (Figure 3). The can be used without too much fiddling. LDR sees darkness; otherwise the circuit will
radar features good shell penetration and does not turn on. Use P1 to adjust the light intensity
not require holes in front of it. This allows for a Power connector K1 is intended to be mounted (the level of darkness) that turns on the circuit.
more aesthetic enclosure. Although the sensi- “looking down,” meaning that the power supply
tivity is focused in front of the antenna, if you and light wires run down over the PCB to the With the radar module powered, you can
want to avoid detection from the back, shield opposite, short side. The two holes on that side configure it. First, connect to the module. The
the rear with a piece of metal (film). can be used for strain relief with e.g. a cable tool has two main modes. To align the radar,
tie or so (see Figure 3), but if you want to do it’s best to enable Engineering Mode and click
The HLK-LD2410 radar module comes in things another way, feel free to. Start (Figure 5). This then shows live sensing
in two graphs. On the left, the moving target
and on the right, the motionless target. The
detection aperture is divided into eight gates
of 75 cm each. The sensitivity of each gate
can be set from 0 to 100, where 100 is the
least sensitive (meaning “disable this gate for
detection”). If the blue or red line reaches or
crosses the green line, the output pin switches
to a high level. When you’re satisfied with the
chosen sensitivity levels, click Config to save
the settings to the sensor persistently.
Miscellaneous
JP1 = 2-way pinheader, 2.54 mm pitch + jumper
K1 = 4-way screw terminal, 5 mm pitch
K2 = 6-way pinheader, 2.54 mm pitch
MOD1 = MP1584 DC-DC converter
Related Products MOD2 = HLK-LD2410 radar module + 5-way pin socket, 2.54 mm pitch
Enclosure Hammond 1591 XXA
> SunFounder Kepler Kit
(Ultimate Starter Kit for Raspberry
Pi Pico W)
www.elektor.com/20730 WEB LINKS
> Seeed Studio Grove Ultrasonic [1] HLK-LD2410 human-presence detector: https://hlktech.net/index.php?id=988
Distance Sensor [2] LD2410 configuration tool:
www.elektor.com/20027 https://h.hlktech.com/Mobile/download/fdetail/204.html
Digital Bubble
Level and Active
Stroboscopic Disc
for Turntables
Fine-Tune Your Record Player With
This All-In-One Tool
3k3
GP0 VBUS
2 39
100n 100µ GP1 VSYS
3 38
INT
VCC
GND
SCL
SDA
XDA
XCL
AD0
GND LED GND
4 37
GP2 3V3_EN
5 36
BOOTSEL
GP3 3V3_OUT
6 35
Q2 D GP4 ADC_VREF
7 34
GP5 GP28
8 33
G GND GND LCD
9 32 1
GP6 U3 GP27 VCC
FDS9435A 10 31 2
S GP7 GP26 GND
D 11 30 3
Q1 GP8 RUN DIN
12 29 4
GP9 GP22 CLK
G 13 28 5
GND GND CS
FDS9435A 14 27 6
GP10 GP21 DC
S C1 100n 15 26 7
D1...4 = BAT46W GP11 GP20 RST
16 25 8
R2
D1 D3
GP12 PICO GP19 BL
17 24
100k GP13 GP18 JP1
18 23
GND GND
U1 D D2 D4 19 22
Q3 GP14 GP17
SWCLK
TP4056 v2
SWDIO
20 21
GND
R4 GP15 GP16
IN+ BAT+ R5
G
330Ω
100Ω
Charge
Full
BAT1
USB S 2N7002
LiPo
3V7 BZ1
200mAh R3
IN– SW1 SW2
BAT–
470k
230358-008
▲
result can be obtained by leaving the number of refer- as we shall see in the description of the firmware. Note
Figure 4: Project ence lines fixed and varying the frequency of the illumi- that the other graphic elements on the display still remain
schematic diagram. nating source. Specifically, with sixty reference points, clearly visible, thanks to the persistence-of-vision effect.
it turns out that to see them stationary, the frequency of
the light pulses will have to be equal to the number of Schematic Diagram
revolutions per minute: As can be seen in Figure 4, the wiring diagram is not
particularly complex. The display and sensor module are
ω = (f × 60) / n = (f × 60) / 60 ω=f connected to the default pins of the SPI and I2C inter-
faces, respectively, on the Raspberry Pi Pico, as can be
In practice, in the digital version of the stroboscopic disk, verified from the pinout given in the datasheet. Connect
sixty equally spaced segments are drawn via software JP1 is connected to the LCD, and its leads are soldered
along the outer circumference of the LCD. Then, by directly to the board. Power for the display is taken from
feeding the LEDs responsible for the backlight (BL termi- the regulator on the microcontroller board, whose GPIO
nal of the display) with a square wave signal of appro- pins, it should be noted, do not support voltages greater
priate frequency (33.33 and 45.00 Hz), we will see the than 3.3 V.
“notches” still when the speed of rotation of the turntable
(and thus of the display) is equal to the frequency itself, This avoids any interfacing problems at the outset. The
considering that the LEDs light up only at a semi-period sensor module incorporates a dedicated LDO (low-drop-
(high level) of the square wave. out regulator), so signal level compatibility is assured.
Buttons SW1 and SW2 are monitored by pins GP13 and
In this way, instead of relying on an external light source, GP14 (configured as input with pull-up resistor) and allow
it is the segments themselves that light up and become the selection of available functions and to turn the device
visible at the desired cadence, hence the name “active” on and off by interacting with the power circuit. Module
disk. To achieve exactly the required frequencies, I used an U1, equipped with the TP4056 chip and Micro-USB input
unconventional approach, but it proved to work perfectly, provides charging for the compact rectangular lithium
polymer (LiPo) battery of 3.7 V nominal and 200 mAh a VBUS presence sensor. Finally, in the wiring diagram
capacity, necessarily of the type with built-in protection of this project, C1 prevents immediate startup when the
circuitry, which ensures at least one hour of runtime for battery is connected, C2 and C3 are the usual power
the project. bypasses, and the buzzer confirms with a short beep
when the device is turned on and off.
It is advisable to charge the battery (a common phone
charger will suffice) with the device switched off, to obtain Realization of the Prototype
the correct end-of-charge indication. MOSFET Q1 [6] is The design was made, as I usually do it, on a prototype
the real switch of the device, normally held in the OFF board. This time I used two 60 mm diameter circular
state by R2 (gate terminal at the same potential as the baseplates, which can be found easily on the market,
source). When either switch is pressed, the gate, via stacked with the insertion of four spacers, to make a
D1 or D2, takes a negative value relative to the source, sort of “layered” assembly. Looking at Figure 6, it can
causing Q1 to conduct and reach (through Q2) the VSYS be seen that on the upper face of the first board are the
terminal on the Raspberry Pi Pico board, activating the buttons with the diodes, the buzzer and the motion sensor
microcontroller. module. Above the latter, the circular display is attached,
with its own connector from which wires connect to
As soon as firmware execution begins, GP15 goes high, the lower face, which houses the Raspberry Pi Pico, as
turning Q3 on (and consequently Q1), the display turns shown in Figure 7. From this side, the connections begin
on, and the button can be released. MOSFET Q2 can — via a five-pin connector made with strip contacts —
normally be considered “transparent” to the current flow, to the second baseplate, which houses the components Figure 6: The prototype
until the USB cable is connected for programming; in responsible for the power supply (the TP4056 module, — both the power supply
fact, in this case, the presence of the VBUS voltage deter- battery, MOSFETs, etc.). and the display side.
mines the disabling of Q2, preventing the return of the
▼
same voltage to the battery through internal diode Q1.
Miscellaneous
Display = Waveshare 1.28” 240x240 Round LCD 19192
About the Author BUZZER = SMD Buzzer
Since childhood, Antonello Della SW1, SW2 = N.O. pushbutton, PCB type
Pia has been attracted to electric- BAT1 = 3.7 V LiPo battery, 200 mAh, with protection
ity and electronic devices. He holds M/F strip connectors
an Electrical Engineering Techni- Spacers
cian high school diploma. Anton- Solderable, round breadboard, PC-15, 60 mm
ello has always cultivated and developed his passion
for analog and digital electronics. Currently, he plays
around with microcontrollers and programming, trying
to improve his skills. Antonello likes to develop and
propose projects that are as original as possible and
— as he hopes — interesting, as well. Related Products
> Raspberry Pi Pico RP2040
www.elektor.com/19562
Question or Comments?
Do you have technical questions or comments about > Dogan Ibrahim, Hardware Projects for
this article? Please contact the Elektor editorial team Raspberry Pi, Elektor 2014 (E-book)
www.elektor.com/16969
at [email protected].
WEB LINKS
[1] Waveshare LCD display module webpage: http://tinyurl.com/5n87a8pt
[2] Raspberry Pi Family: https://en.wikipedia.org/wiki/Raspberry_Pi
[3] Raspberry Pi Pico webpage: https://raspberrypi.com/products/raspberry-pi-pico/
[4] MPU6050 tutorial on LastMinuteEngineers website: http://tinyurl.com/rxr8av6k
[5] MPU6050 datasheet: http://tinyurl.com/mwr5fwb6
[6] FDS9435A datasheet: https://onsemi.com/pdf/datasheet/fds9435a-d.pdf
[7] Unofficial list of 3rd party boards support URLs — Arduino IDE: http://tinyurl.com/5edvv332
[8] Raspberry Pi Pico Arduino core — Earle F. Philhower, III: http://tinyurl.com/489kwb3k
[9] SW package for this project: https://elektormagazine.com/230358-01
[10] MPU6050_light — Arduino library: https://github.com/rfetick/MPU6050_light
[11] RunningAverage — Arduino library: https://github.com/RobTillaart/RunningAverage
[12] C library function — sprintf() — tutorialspoint: http://tinyurl.com/58ymn9wz
[13] ArduinoWatch — moononournation: https://github.com/moononournation/ArduinoWatch
[14] Video demo — YouTube: https://youtu.be/tun6wH5gKDA
[15] Raspberry Pi Pico Datasheet: https://datasheets.raspberrypi.com/pico/pico-datasheet.pdf
Open
Source
and Its Significance for
the Electronics Industry (2) Arduino UNO and Raspberry Pi are two
long-standing open-source solutions.
(Source: Mouser Electronics)
In part one [1] of this two-part open- The Impact of Open-Source Software on the EU’s
source series, we explored the GDP
In 2021, the European Commission published the results of its
definition and certifications available study [2] on the financial benefits of open-source software and
for open-source electronic software hardware. It found that, in 2018, companies within Europe invested
and hardware, as well as some of the €1 billion in open-source software. This resulted in a significant
impact on the EU’s GDP, adding between €65 and €95 billion to the
successful development and education economy. The Commission went on to state that a 10% increase
hardware products. In this second in open-source contributions could result in a GDP increase of
article, we will analyze the value of around 0.4% to 0.6% (€100 billion).
open-source solutions to the electronics When open-source software is coupled with powerful repository
market, look at trends such as closed- sites such as GitHub, thousands of developers from across the world
source hardware in combination with can push the system forward and fix bugs together. With produc-
tivity and engagement far beyond what is seen in even the best
open-source solutions, and examine the community-backed proprietary solutions, users feel a sense of
viability of using open-source hardware ownership over the software.
(OSHW) in commercial products.
In some cases, the complexity and breadth of modern applica-
tions can make it hard for proprietary solutions to develop quickly
enough to meet market expectations. Equally, interoperability in
What Does Open-Source Mean to the Electronics the digital world is key, especially for the internet of things (IoT)
Industry? and web-based applications, and this can be enhanced through
The major strength of an open system is its accessibility, which open-source solutions.
comes with several related advantages. For software, open-source
design removes all entry barriers, allowing more developers to get The Challenges of OSHW
their hands on source code, thus increasing collaboration, innova- With household names such as Mozilla Firefox and Android,
tion, and the rate of development for the host solution. the value and success of open-source software is obvious.
But OSHW solutions have had a harder time. Even the aforemen-
In terms of hardware, although there is always an expense linked tioned 2021 EU report acknowledged the difficulty in assessing
to the physical device, many of these advantages remain. Addition- the market impact of OSHW.
ally, with open design files, OSHW can mitigate supply shortages
by allowing for localized manufacturing and facilitating the rapid So, how viable is an OSHW solution for going to market, and how
development of design variants. does it impact the electronics market?
Conclusion
While the importance of open-source solutions for software
cannot be argued, it can be harder to draw the same conclusion
Figure 2: NXP’s i.MX RT1050 MCU. (Source: Mouser Electronics) for hardware. Many engineers designing commercial products feel
that OSHW is too vulnerable to be copied or undermined, which
can lead to damage to reputation and loss of market position.
Bluetooth 5.2 (including Bluetooth Low Energy), 802.15.4/Thread, Equally, in most cases, selecting hardware for a project is primarily
ANT/ANT+, and proprietary 2.4 GHz applications as well as NFC. based on performance and costs, and if an open-source solution
misses these requirements, it is unlikely to be selected over a propri-
Alongside open-source Matter compatibility, the hybrid approach etary product. That said, market-ready hardware is benefiting from
of the nRF52840 DK also supports Arduino’s UNO shields designed open-source solutions. This might be through assisting develop-
to the open R3 standard, making it possible to mount open-source, ment and prototyping, or through the combination of proprietary
third-party hardware. Nordic’s solution allows engineers to lever- hardware solutions and open-source software, firmware, and third-
age open-source hardware and software with its closed hardware, party hardware add-ons.
streamlining the development of IoT devices as well as promot-
ing interoperability within the smart home to the benefit of the By using a hybrid approach, it is possible for engineers to leverage
end user. the strengths of open solutions without being susceptible to their
potential weaknesses — combining the best of both worlds and
Open-Source MCU Development reducing development time and adding value to designs. For the
This hybrid theme of bringing together proprietary hardware with end-user, this approach can help to create a product that is more
open-source software is seeing similar success with real-time attractive than a completely closed design, with greater interoper-
operating systems (RTOS) for MCUs. The rising complexity of code ability, lower costs, and enhanced operation familiarity, all possible
in current RTOS implementations has resulted in the prominence thanks to using open-source solutions.
of the open-source community-supported solution Zephyr [12]. Led 240184-01
by a consortium of industry-leading vendors, including Intel [13],
Google, Meta, and NXP Semiconductors, Zephyr has been devel-
oped to cater to the evolving requirements of MCU deployments,
such as edge solutions and IoT.
Zephyr’s modular design and simple code reuse shorten the initial
steps for developers and encourage collaboration within its expand-
ing community. It already boasts the highest number of unique
contributors and upstream commits per month out of all other
RTOSes [14], as well as a wide range of supported hardware, demon- About the Author
strating the platform’s popularity and continued ability to adapt. As Mouser Electronics’ Director of Technical Content for EMEA,
Mark Patrick is responsible for creating and circulating techni-
The i.MX RT Crossover MCU [15] family from NXP (Figure 2) is one cal content within the region – content that is key to Mouser’s
example of a closed-source hardware solution that is designed to strategy to support, inform, and inspire its engineering audience.
operate with open-source software such as Zephyr. Before leading Technical Content, Mark was part of Mouser’s EMEA
Supplier Marketing team and played a vital role in establishing
Further pushing a hybrid approach, NXP supplies the closed-source and developing relationships with key manufacturing partners.
but free MCUXpresso development suite with its hardware. This Mark’s previous experience encompasses hands-on engineering
comprehensive offering is deeply integrated with its developer roles, technical support, semiconductor technical sales, and various
community and encompasses IDE interfaces, evaluation kits, and marketing positions. A “hands-on” engineer at heart, Mark holds a
configuration tools that enable the seamless and efficient imple- first-class Honors Degree in Electronics Engineering from Coventry
mentation of open-source software, such as Zephyr and Matter, University. He is passionate about vintage synthesizers and British
with NXP’s MCUs powered by Arm Cortex-M cores. motorcycles and thinks nothing of servicing or repairing either.
ElektorLabs
• Free Project Sharing
• Expert Support
• Collaboration Opportunities
• Access to Exclusive Resources
• Get published in
Elektor Magazine
M12 Circular
Connector Dust and liquids cannot harm the M12-A circular connector from Würth
Elektronik eiSos: The connectors, which comply with protection classes
With A-coding
IP67 and IP68 are suitable for use in harsh environments. (Source: Würth
Elektronik eiSos)
Industrial Applications The A-coding mechanical shape is the origin of all M12 codings;
all other different codings (B, D, L, X, S) have branched out from it,
which is why there are different codings (A, D, L, X, S, etc.), each with
different numbers of contacts available. Although M12 interfaces
can have from 2 up to 17 contacts, in practice, the most commonly
By Baptiste Bouix and Caroline Poulard used are three, four, five, eight, or twelve pins. The number of pins
(Würth Elektronik France) depends on the various requirements. For example, sensors and
power supply applications require three and four pins, whereas
Automation requires networking, and in the Profinet and Ethernet applications require four and eight pins,
industrial environment there is a proven and fieldbus, CAN bus, and DeviceNet typically require four or
five pins. 12 pins are required for sophisticated signal transmis-
versatile solution for connecting modules sion. Table 1 shows an overview of the protocols and number of
such as sensors or actuators: M12 circular connector pins required at the physical level.
connectors with A-coding can be used to Data Line With Power Supply
transmit signals, data, or as electrical cables. Würth Elektronik eiSos offers the M12 circular connectors as male
What needs to be considered is explained and female connectors with A-coding (DIN EN 61076-2-101). M12-A
below. offers the option to mix signals and DC power delivery, which are
particularly suitable for fieldbus applications in industrial automa-
tion. The WR-CIRC M12 family is available in panel-mounted
connectors, field attachables and cable assemblies with four, five
When connectors from different manufacturers can be combined, or eight pins. The current Würth Elektronik eiSos portfolio includes
a standard has been established. This is the case with M12 circu- plugs and sockets panel- and PCB-mounted in THT version, and
lar connectors. The industrial connectors represent a compact, pre-wired and solder buckets for cables (see “Comprehensive
standardized interface that is suitable for many applications: from Portfolio” text box). Areas of application can be found in industrial
the transmission of signals and data to power transmission. Pretty environments, particularly in automation and robotics, as well as
much anything is now possible using this robust, mechanically and in the field of renewable energies, communication technology, and
environmentally resistant long-serving connector. The term “M12” mechanical engineering. In addition, the panel and Field-Attach-
refers to the 12 mm nominal diameter of the locking thread. The able models of the M12 connectors are cULus-certified (UL2238).
wide range of applications for M12 connectors is also reflected in the All M12 connectors provide minimum protection to IP67 or IP68
number of mechanical codings (unique mechanical profiles of the against the ingress of dust, dirt, and water.
to ANSI/TIA-568. Each of the plug/socket pairs and the cable itself Figure 3: Pin assignment of a five-pin M12-A coded socket for the RS-485
have a budget for loss and crosstalk that must not be exceeded. It is interface. (Source: Würth Elektronik eiSos)
recommended to test the S-parameters of such an interface, which
mainly depends on the cable category and the cable length. Even
at significantly higher data rates of up to 10 Gbit/s, it is possible to
create an interface with an M12 circular connector with A-coding
by implementing the same pin assignment as for 10-BASE-T and
100-BASE-T and applying the same signal integrity considerations.
Such an interface will generally have a much shorter cable length.
Other Applications Figure 4: Pin assignment of a five-pin M12-A coded socket for used to power
There are more applications for the robust M12-A circular connec- Profibus peripheral devices. (Source: Würth Elektronik eiSos)
tors. For example, the IO-Link communication system can be used
to cleverly connect intelligent sensors and actuators to an automa-
tion system in accordance with IEC 61131-9 — using four- or five-pin supply, the B-coded circular connectors are specifically designed
A-coded M12 circular connectors that are connected to a three- for Profibus signal transmission (Figure 4).
or five-wire 20-meter cables. The connection on the three-wire
cable is referred to as “Class A” and the connection connected to a Other industrial bus systems in which the M12 circular connec-
five-wire cable as “Class B”. The device connection can be a captive tors with A-coding are used are RS-411, RS-423, and finally RS-232.
cable or a four- or five-pin M12 A-coding, depending on the desired Eight-, five- and four-pole connectors are suitable for this. The
cross-compatibility. wiring depends mainly on the required signals, the power supply,
and the required earthing.
The M12 connection technology is ideally suited as an intermedi- 240202-01
ate link for industrial bus systems, especially for CANbus, RS-485,
Profibus and the physical levels RS-422, RS-423, and RS-232. While
the CANbus was originally designed for use with a small D-SUB
connector, the five-pin M12-A coded round connector is a popular About the Authors
interface for the CANbus. Only the CAN_H and CAN_L signal pair,
which is wired to pins 4 and 5, is mandatory. The device can be Baptiste Bouix is Product Manager Interna-
supplied with power in this configuration. Twisted signal cable tional at Würth Elektronik France. His areas
pairs with a nominal impedance of 120 Ω is used for electrical of responsibility include board-to-board,
transmission. card connectors and Ethernet connectors.
Previously, he worked in the microelectronics
The RS-485 physical layer is often used for the industrial protocols industry in research and development of
Modbus, OSDP, SSCP, SCSI-2, SCSI-3, Profibus, Nanoréseau, DMX 512 manufacturing processes. With degrees in materials science and
and AES 3. Figure 3 shows a typical RS-485 pin assignment for nanotechnology, he has extensive expertise in silicon technologies,
five-pole A-coded cables. Alternatively, four-conductor shielded signal processing and measurement technology and has become a
cables can also be used. The wiring largely depends on the required specialist in signal chain-oriented product management and design
power supply, but always includes at least the symmetrical TxD/ over the years.
RxD pair in positions two and four to minimize the delay time.
Caroline Poulard is Product Manager for
Profibus enables decentralized concepts. The fact that Profibus circular connectors and DSUB connectors at
can be adapted to different applications using a modular principle Würth Elektronik France. She is a mechanical
also makes this technology attractive in production automation engineer who started working in the automotive
and the process industry. Here, the M12 connection technology industry and then reached for new challenges
is indispensable. While the A-coded variants are used for power in the electronic field.
WEB LINK
[1] M12 A-coded types of connectors:
https://we-online.com/en/components/products/em/connectors/circular_connectors/circular_connectors_m12_a
The Arduino-Inside
Measurement Lab
An 8-in-1 Test & Measurement Instrument for the Electronics Workbench
As far as software goes, the MSR lab program and further infor- To set the frequency, two bytes must be transmitted for the prescaler
mation about the project is posted at [1] where you can also find and the timer. Command 90 has been defined for this purpose.
further information from the author on his (originally German)
publication. if (c == 90){ // OC0A frequency
TCCR0B = USART_Receive();
For a good overview, even with many more inputs and outputs, OCR0A = USART_Receive();
all functions are named according to the pin designations on the }
Arduino. Figure 1 shows a sample screen of the MSR U/I up and
running and indicating the pin name agreement. In the user program, every change at the frequency control HScroll8
leads to a new output. For the finest possible setting, five ranges
DDS Phase Adjustment with different prescalers (1, 8, 64, 256, 1,024) are used. The output
The DDS generator’s sine table (discussed earlier in the book, Ed.) frequency is calculated and displayed on the user screen. Listing 2
has a length of 256 bytes. For a complete period, the high byte in shows the code extract, Figure 3 the pin connections, and Figure 4
the phase accumulator must pass through the range from 0 to 255. the MSR user screen.
Thus, with the same frequency on both channels, a phase relation-
ship of 360 degrees in total is mapped in this range. Accordingly,
a1 = 0x0000 is set, and a received byte parameter is shifted into
the high byte of a2. Command 82 thus triggers a phase jump at
both channels, after which the desired phase relationship exists. D6 (OC0A) A0
Listing 1 shows the relevant program code.
In the user program, the desired phase difference is set with the
HScroll9 slider (Figure 2). At each operation, the command 82
is sent together with the new phase byte.
Figure 3: Pin connections for the frequency generator.
Signal Generator up to 8 MHz
Timer 0 (with a resolution of 8 bits) can be used to generate a
symmetrical square wave signal. For initialization, TCCR0A = 0x42
is set. The following register sets the prescaler. With TCCR0B = 0x00,
the generator is switched off, and with TCCR0B = 0x01 it gets the
full 16 MHz clock frequency. Further prescaler levels reach up to a
divisor of 1,024. The exact frequency is set with OCR0A = 255 (/256,
lowest frequency) to OCR0A = 0 (/1, largest frequency). The counter
increments and jumps to 0 each time OCR0A is reached. At the
same time, output OC0A is toggled at port D6. This results in the
highest frequency of 8 MHz. The lowest frequency is 16 MHz / 2 /
1,023 / 256 = 30.528 Hz.
Many important frequencies can be set precisely, but most frequen- TIMSK1 = 0x01; // Timer1 Overflow Interrupt
cies are odd fractions of 16 MHz. The resolution is high at low TCCR1C = 0;
frequencies and becomes coarser towards the end. The four highest
frequencies are 2 MHz, 2.667 MHz, 4 MHz, and 8 MHz. For compar- For initialization, the counter is connected to input T1 at port D5.
ison: The DDS generator made in this way has a resolution of about Additionally, the interrupt is enabled. The Timer2 interrupt is also
1 Hz across the range, but only reaches up to 5 kHz. used to control the gate time. A time counter t is set up here. At t = 0,
Timer1 is reset together with its external high byte fh1. At t = 1, the
With the square wave generator, frequencies can be set exceed- timer is started. And exactly one second later it is stopped and read:
ing the sampling rate of the oscilloscope. However, reliable
measurements with the oscilloscope are only possible up to half ISR (TIMER2_OVF_vect)
the sampling rate, i.e., up to about 31 kHz. Near the sampling rate {
or its multiples, completely false images are delivered. The double PORTB |= 1;
sampling rate is 125 kHz. If you set the square wave generator to …
127 kHz, an apparent signal of 2 kHz appears, i.e., the difference t++;
frequency. In principle, this problem can be observed with any if (t == 0) { TCCR1B = 0x00; TCNT1 = 0; fh1 = 0; }
DSO, while it never occurs with an analog oscilloscope. Figure 5 if (t == 1) { TCCR1B = 0x07; }
shows an example. Also noticeable are the sloping edges in the if (t == 62501) { TCCR1B = 0x00;f=TCNT1; fh2=fh1; }
oscillogram, despite the actual rectangular shape. They are caused …
by the finite sampling time of the AD converter. The sample-and- PORTB &= ~1;
hold capacitor needs some time to charge up to the actual voltage. }
However, at very high frequencies, the state will already have
changed within the sampling time. As a result, voltages between The lower 16 bits are then in f. In addition, there are the upper 8
the extreme values are measured in the transitions. At very high bits in fh2. Command 91 was defined for transmission to the PC.
frequencies, triangular voltages are even displayed as illustrated In the MSR user program, the frequency readout is refreshed once
in Figure 6. per second. For this purpose, the measured value must be read
out within the timer function. A total of three bytes is combined
Frequency Measurement to form a 24-bit number. Here are the code snippets relevant for
The digital counter uses timer 1, having a resolution of 16 bits. these operations:
Because it is only possible to count up to 65,535 with this arrange-
ment, an interrupt is triggered at each overflow to increment an if (c == 91) { // Timer 1 frequency
additional counter. This contradicts the principle that there should USART_Transmit(fh2);
be only one active interrupt to not disturb the running DDS output. USART_Transmit(f >> 8);
However, the Timer1 interrupt rarely occurs and only occurs when USART_Transmit(f & 0xFF);
frequencies above 65 kHz are measured. }
Questions or Comments?
Do you have any questions or comments related to this article? Email
the author at [email protected] or Elektor at [email protected].
230644-014
4n7 R3 2n2 R6
10k
10k
R1 C2
2
In 10k R4 C4
1 6
4n7 OP1a 10k
R2 3 R5 7
achieves the best fit with the measured signal y(t). For this, 2n2
5
OP1b Out
1k
1k
the sample number N = 4,096. This value can be relatively +5...12V
is multiplied and summed with the sampled cosine wave. OP1 = LM4562
10k
For B, use the corresponding sampled sine wave. A is the C5 8
OP1
value of the cosine function of the signal, while B is the value C6
R8
100n 4
10k
10µ
that an I/Q mixer in an SDR receiver design works. The 16V
From the magnitude and the phase of the input and output signals, it’s
easy to determine the magnitude and phase of the transfer function,
g. The ratio of the signal magnitudes and the phase difference can be
calculated as shown in the example below.
Z = Rq · g / (1 - g)
For initial tests, we can experiment with a fixed coil with an inductance
Rs Ls
L = 10 mH. The circuit can be built on a small prototyping plug board,
which can be seen in Figure 7. The source resistance is Rq = 10 kΩ.
230644-017 The series equivalent circuit of the coil is shown in Figure 8. The
series resistor represents the DC resistance of the coil wire as well
Figure 8: Series equivalent circuit of the inductor. as the (frequency-dependent) losses in the core material and other
properties. The frequency-dependent equivalent circuit values are
shown in Figure 9.
Input Impedance
The frequency-dependent characteristics of this setup flags up a
problem. At frequencies below 30 kHz the value of the series induc-
tance Ls is about 10 mH as expected. The same is true for series resis-
tor Rs. At higher frequencies, Ls increases sharply and even becomes
negative. This means that, at high frequencies, the two-pole network
behaves capacitively. This is because we have not considered the input
impedance of the sound card, which is effectively in parallel with Z.
This impedance can be measured by the system itself by omitting the
impedance, Z, in the voltage divider network according to Figure 6
so that it is only made up of the input impedance. A parallel network
of capacitor Cp and resistor Rp is used as the equivalent circuit to
represent the input impedance. The resulting measured values are
shown in Table 1.
Figure 9: The coil properties, Ls and Rs, from 10 kHz to 90 kHz.
Rp = 12.462 kΩ Cp = 713.40 pF
k=0 frq = 1.00 kHz
Rp = 12.044 kΩ Cp = 647.35 pF
k=1 frq = 12.13 kHz
Rp = 11.591 kΩ Cp = 633.22 pF
k=2 frq = 23.25 kHz
Rp = 11.094 kΩ Cp = 624.68 pF
k=3 frq = 34.38 kHz
Rp = 10.582 kΩ Cp = 618.75 pF
k=4 frq = 45.50 kHz
Rp = 10.049 kΩ Cp = 614.45 pF
k=5 frq = 56.63 kHz
Rp = 9.514 kΩ Cp = 610.30 pF
k=6 frq = 67.75 kHz
Rp = 8.984 kΩ Cp = 606.95 pF
k=7 frq = 78.88 kHz
Rp = 8.387 kΩ Cp = 605.17 pF
k=8 frq = 90.00 kHz
R1
2
C2
1M
1
C1 OP1a Out1
3
In1 100µ
10µ
Vgnd
R2
6
C4
1M
7
C3 OP1b Out2
5
In2 100µ
10µ
R4
Soundcard 16 Bit
10k
8 192 kSamples/sec
C5 C6
OP1 Speaker
R3
C7 100µ 100n 4
Out1 In1 In Out
10k
1M
1M
230644-018
GND
Out2 In2
230644-019
As you can see, the sound card has a relatively low input imped-
ance of about 11 kΩ. The impedance has a capacitive component of Figure 12: Buffer, sound card, and DUT wiring.
approximately 650 pF, which is considerable when compared to the
input characteristics of a typical oscilloscope. It was this capacitive
component which influenced the resonant behavior when the induc- low-noise and highly linear and it’s also low cost, for example, from
tor was being measured. Mouser [3] where it retails for £2.28 for the through-hole version.
Impedance Conversion The connection of the buffer, sound card, and DUT is shown in
To reduce the influence of the sound card’s input stage impedance, we Figure 12. Now, there is a buffer stage in front of each input of the
can use impedance converters. These have high-impedance inputs sound card. Since the same circuit is used for both channels, their
with low capacitance and can be easily built using IC amplifier buffers. influence cancels out when calculating transfer factor g. These buffer
In Figure 10, a suggested circuit uses an LM4562 op-amp, which can stages have a 1 MΩ input similar to the input characteristics of an
be easily built on a piece of prototyping board (Figure 11). oscilloscope, allowing the use of regular scope probes.
The LM4562 op-amp suggested here uses a low bias current, so the Now, using the buffers, a parallel circuit made up of a resistor of
voltage drop across the 1 MΩ input resistor is small. Its gain/bandwidth Rp = 10 kΩ and capacitor of Cp = 100 pF is tested. The results are
product of 55 MHz is sufficiently high for this application. This IC is given in Table 2.
Here you can see that the measurement is now quite accurate through- The yellow curve represents the magnitude of the transfer function.
out the frequency range due to the high input impedance and low You can clearly see that, at resonance, it peaks at about +30 dB.
capacitance properties of the buffer stages. You can also determine The curve extends over a range from -50 dB to +30 dB, resulting in a
the real and imaginary parts of the transfer function of a component. total dynamic range of 80 dB. The red curve at the bottom shows the
The real and imaginary characteristics of a parallel resonant circuit phase response. As expected, the phase shift occurs mainly around
with Lp = 10 mH and Cp = 4.7 nF are given in Figure 13. the region of resonance. The gray/blue crosses track the behavior
of the model function associated with Figure 15. You can see that it
The real and imaginary characteristics can also be represented in the fits quite well. Only the resonance peak is lower in practice than in
x-y plane, as shown in Figure 14. This is called a Nyquist plot. For a theory, which is due to additional losses in the coil. If you reduce the
parallel resonant circuit, it results in a circular trace. value of Rp to 30 kΩ, it produces a curve that, even during resonance,
matches more closely. From this, we can estimate losses in the coil.
Reference Curves This approach is common practice for parameter estimation, where
Often you will already have an idea of how the measured curves should the parameters are adjusted so that the model function matches the
look. The software allows you to overlay such reference curves so you real measurement as closely as possible.
can check how well the model matches up with reality. For conve-
nience, a library of complex AC calculations will be useful for the Options
creation of reference transfer functions and is available for download Table 3 lists the circuit parameters and component values that can
with the project. As an example, we will measure a series resonant be set in the program. This gives a wide range of possibilities for
circuit (Figure 15). circuit analysis.
At resonance, this series-resonant circuit will generate a high output This article has demonstrated how you can measure the frequency
signal. If the signal generator is set to the normal output level, the response of four-pole networks and component impedances in the
output signal from this circuit will overload the voltage measurement frequency range of 100 Hz to 90 kHz using an ordinary sound card,
input at resonance. The simplest remedy is to reduce the generator
signal by a factor of 10. Now it becomes apparent that the sound card
can process even small signals very accurately. The measurement of
the transfer function (magnitude and phase) yields the curves shown
in Figure 16.
Cp
4n7 Rp
Lp
100k
In Out
10mH
230644-004
Figure 15: Series resonant circuit. Figure 16: Gain and phase of the transfer function of a series resonant circuit.
WEB LINKS
[1] Processing: https://processing.org
[2] Elektor project page: https://elektormagazine.com/230644-01
Measuring pH Value
With the Arduino UNO R4
Check the Quality of Your Water
In this article, we present a pH meter that can In addition, this pH measurement system Conversely, if the hydrogen ion concentration
accurately measure the pH value of a solution. also finds application in aquaria, where water is low, the pH will be high, indicating alkalinity.
We use a dedicated sensor, the Arduino quality is vital to the health of fish and all other
UNO R4 Minima board, and a small 0.96″ living organisms. Incorrect pH can upset the As mentioned above, pH is an important
OLED display. The versatility of this system aquatic ecosystem’s balance, causing stress parameter in many scientific and industrial
allows it to be applied in different areas, and disease to its inhabitants. With this pH fields. But it is also fundamental to human
providing reliable and user-friendly results. meter, you will be able to monitor the water’s health, as various biological systems require
pH in real time and make any corrections to an environment with a specific pH to function
Water is a crucial factor in many working ensure an ideal value for each application. properly. pH measurement can be done using
contexts. For example, in hydroponic agricul- chemical indicators or electronic instruments
ture, where plants are grown without the use What Is pH called pH meters, which provide an accurate
of soil, water pH plays a key role in ensuring Before proceeding with the project’s descrip- reading of the solution’s pH and are commonly
optimal nutrient uptake by plants. Constantly tion, let’s see what pH is. pH (potential of used in chemistry laboratories and environ-
monitoring water pH allows farmers and Hydrogen) is a measurement scale used to mental analysis.
operators to adjust acidity or alkalinity levels, indicate a solution’s level of acidity or alkalinity.
thus creating an ideal environment for plant This scale ranges from 0 to 14, where a value Probe for Measuring pH
growth and development. But it is not only of 7 represents neutrality, while values below In our project, we will use an electronic probe
hydroponic agriculture that benefits from this 7 indicate acidity and those above 7 indicate to measure pH (Figure 2). An electronic pH
project. Maintaining the correct pH value of alkalinity (Figure 1). meter probe’s operation is based on electronic
water is also essential, for example, in the and chemical principles. It consists of a
routine maintenance of swimming pools — The pH is determined by the concentration of pH-sensitive glass electrode and a reference
a prerequisite for ensuring a healthy, safe and hydrogen ions (H+) present in the solution. electrode. The former contains a special glass
always-swimmable environment for bathers. When a substance dissolves in water, it can that reacts with hydrogen ions in the solution.
An unbalanced pH can cause irritation to release hydrogen ions that determine the
swimmers’ eyes and skin, as well as encour- solution’s acidity. If these ions’ concentration When the glass electrode is immersed in the
age the growth of bacteria and algae. is high, the pH will be low, indicating acidity. solution, an electrical potential difference is
created according to the solution’s pH. The case, Arduino UNO. For proper operation, the transition for existing shields and projects,
reference electrode provides a stable refer- module must be supplied with a voltage of taking advantage of the extensive and unique
ence point for pH measurement. Usually, a 5 VDC, and, given its low-power consump- ecosystem already created for the original
gel or salt solution reference electrode is tion (between 5 and 10 mA), we can supply it Arduino UNO (Figure 5).
used. The pH probe can detect the differ- directly from the 5 V pin of our UNO R4 board.
ence in electrical potential between the glass For proper operation, it is necessary to wait The new version also offers a faster clock,
electrode and the reference electrode. This at least 60 seconds to get accurate readings. allowing it to perform more accurate calcula-
potential is converted into a pH value using tions and handle complex and sophisticated
an electronic circuit. Arduino UNO R4 Minima designs. It also features a USB-C connector,
The fourth version of the Arduino UNO, the which is a smaller, more powerful, and more
Before use, it is necessary to calibrate the Arduino UNO R4 Minima, is a major step durable standard than previous connectors.
instrument using known pH values (usually forward in the field of DIY and electron- To use the Arduino UNO R4 Minima, you’ll
pH 4 and pH 7) to ensure measurement ics (Figure 4). This new version houses a need to install the UNO R4 Minima board
accuracy. Special care should be taken with 32-bit Arm Cortex-M4 processor, providing package, which is part of the Arduino core for
the glass electrode, which should be stored more computing power and 16 times more Renesas devices. To install it, you will need to
in a specific solution and cleaned periodically memory than previous versions. Despite these have a version of the Arduino IDE, which you
to remove deposits that could affect measure- improvements, the size and 5 V compatibility can download from the Arduino downloads
ments. The probe cannot be connected remain the same. This ensures a seamless page [1].
directly to our Arduino UNO R4 board, but
rather the signal must be amplified and made
readable by the microcontroller via a signal
conditioning board (Figure 3).
float b;
int buf[10],temp;
Connections
In this project, we used several components
to create a pH-detection system, as you can
see in the wiring diagram (Figure 8). The main
component, which is the probe that can detect
pH, was connected to its conditioning circuit
via a BNC connector. As mentioned earlier, this
circuit takes its power directly from the Arduino
UNO R4 board’s 5 V and GND pins. The pH-de-
tection module’s pin P0 was connected to the
Arduino board’s analog pin A0. This connec-
tion will allow the main board to read the pH
values detected by the sensor.
The Firmware
The code written for the Arduino UNO R4
allows us to read the pH sensor values and
display them on the OLED. Let’s look at the
code in detail. The first lines of code include
the libraries needed for the program to work, in
particular the Wire library for I2C and Adafruit’s Figure 9: The completed prototype, ready for testing.
avgValue = 0;
Serial.print(" pH:");
Serial.print(phValue, 2);
Serial.println(" ");
display.clearDisplay();
display.setTextSize(2);
display.setCursor(20, 5);
display.println("Ph Value");
display.setTextSize(3);
display.setCursor(30, 35);
display.print(phValue);
display.display();
digitalWrite(13, HIGH);
delay(800);
digitalWrite(13, LOW);
}
Those who know me are aware that I can get caught up in the finer word games,
sometimes resulting in hilarious situations, like the time I accidentally wanted to
order a “pizza salmonella” from the local pizza place instead of a “pizza salmone.” I
won’t elaborate on the butcher’s wife’s facial expression when my partner accidentally
turned “filet de sax” into something less suitable for publication. Eric Bogers from the
Elektor editorial team is also quite fond of word games, and the strange subtitle of this
piece comes from Eric’s childhood, when his father invariably called ping pong balls
“pangpong butts.” Coincidentally, this pun has grown into the unofficial codename for
this project — and work in progress — of a target with floating balls for air rifles, which
was previously featured in the series, Homelab Tours [1].
Building the Project a euphemism for shooting at all kinds of from insurance premiums, about as dangerous
Judging by the reactions of readers, there objects — including ping-pong balls — is a as bridge. Well, just about, because I know
seems to be quite some interest in this project, welcome change (Figure 1). one shooter who is fond of using extremely
especially from shooting clubs that want to offer heavy calibres, causing his teeth fillings to
something different to their young members. After quite a while of inactivity due to circum- come loose as a result. Since safety is import-
To be honest, repeatedly aiming at cardboard stances, I have picked up the thread, so, ant, even when it comes to airguns, and
cards at your own pace does become a time for an update. If you feel the urge to get because electrical wiring in a shooting range
bit monotonous eventually. Plinking [2], started, I have good news for you, as you can is usually not a good idea, I opted, as far as
now download the CAD drawings, along with the electronics are concerned, for a wireless
photos (see Figure 2 for an example), of the remote control and components from reputa-
entire mechanical construction from [3]. I ble companies. If you thought this could be
have also started designing the electron- a low-cost solution, I have to disappoint you:
ics. In case you fear the thought of tiny SMD This project is a bit more expensive in terms
parts, I can reassure you: To keep things as of material costs. It’s better than having to run
engineer-friendly as possible, except for one up and down through a shooting range every
radio module, everything is built with classic time to get a failing system working again after
through-hole parts (Figure 3). Even that yet another malfunction.
module, with a pitch of 2 mm, is not too diffi-
cult when it comes to soldering. There were also questions about the possi-
bility of customizing the system’s mechanical
You might not suspect it, but shooting sport is components according to one’s own tastes
Figure 1: The prototype (2023). one of the safest sport disciplines and, judging and preferences. The system is based on the
anaconda… koala… err… coandă effect [4], Unfortunately, No Kit world’s largest “Silicon Valley” with 430 billion
although some will claim that Mr Bernouilli If you want to replicate these projects, it’s euros? Those bureaucrats in Brussels [7]
is actually behind it. Despite this, I did not useful to have access to a laser cutter. Perhaps couldn’t care less.
use any complex mathematical formulas in your local makerspace or fablab can assist Translated by Hans Adams — 240030-01
the design and followed the principle of trial you with this. I would have liked to offer you a
and error. So, above all, dare to experiment construction kit, but due to European regula-
yourself. tions, that’s unfortunately no longer possible.
Are you also annoyed by the endless series
Caffeine of irritating cookie pop-ups, caps attached to
Designing is quite exhausting and requires drink bottles, patronizing attitudes, a jungle
serious mental effort. I must confess that I am of labels on consumer products, and a sea
a caffeine junkie of the nocturnal type as well of rules? Tough luck — despite our collec-
as a lover of coffee in capsules because of the tive disdain for bureaucracy, we keep getting
ease of use. Now, ping-pong balls and coffee more of it thrust upon us. This includes the
capsules have one thing in common: they are current regulations around the recycling
both rather round in shape, which is why I had of packaging material [6], which are being
been thinking for some time about applying more strictly enforced and would require us
the operating principle of the ping-pong ball as a small company to register in multiple
dispenser to coffee capsules. The end result European countries, including the submis-
became a coffee capsule dispenser with six sion of annual declarations, not to mention
magazines of ten capsules each (Figure 4). the costs. More and more small companies
If you would like to work on this, CAD files are therefore throwing in the towel because
and photos of the mechanical design are the bureaucracy is becoming unbearable and
also available [5]. The practical purpose of unaffordable. But what’s really important, such
this device may be doubtful, but it is a nice as a stronger industry, strategic independence
gimmick for a maker or hacker space or, if in light of the upcoming American presidential
desired, for the cafeteria of your favorite shoot- elections, or investing in our own chip indus- Figure 4: Caffeine-on-demand: Coffee capsule
ing range — why not? try like South Korea, which wants to build the dispenser.
WEB LINKS
[1] Ilse Joostens, “HomeLab Tours - Work in Progress,” Elektor 5-6/2023: https://elektormagazine.com/magazine/elektor-300/61645
[2] Wikipedia: Plinking: https://en.wikipedia.org/wiki/Plinking
[3] Downloads ping-pong-ball launcher: https://bit.ly/3SRssG1
[4] Wikipedia: Coandă-effect: https://en.wikipedia.org/wiki/Coand%C4%83_effect
[5] Downloads Nespresso-machine: https://bit.ly/3SRCvuz
[6] Packaging license in the EU: The obligations in all member countries: https://verpackungslizenz24.de/en/eu-packaging-licence
[7] Bazarow: Review of the book “Bureaucracy is a squid” by René ten Bos by Bas Leijssenaar:
https://bazarow.com/recensie/bureaucratie-is-een-inktvis-2
FNIRSI 1014D
Digital
Storage
Oscilloscope
loscope is powered by a USB power supply that provides 2 A at 5 V.
With dimensions of 310×145×70 mm, it is compact and portable,
yet large enough to be operated comfortably. With fold-out stands,
it sits at a good angle on the lab bench.
Specifications
Good Performance for The most important technical specifications are:
Tight Budgets > 2 Channels, each with a bandwidth of 100 MHz
> 7-inch LCD with an 800×480 resolution
> 1 GSample/s Sampling Rate
> 240 Kbit memory depth
By Günter Spanner (Germany) > 1 MΩ (1×) or 10 MΩ (10×) input impedance
> 50 mV to 400 V sensitivity
An oscilloscope is an essential tool > 50 s to 10 ns time base
in an electronics lab. For developing > Trigger Mode: Single/Normal/Auto on rising or falling edge
> AC/DC coupling
digital and simple analog electronics, > One-button Auto setting
a bandwidth of 100 MHz and two > Frequency generator with 14 waveforms up to 10 MHz (sine)
channels are entirely sufficient. A > USB export
frequency or function generator is also As is customary with digital oscilloscopes, in addition to signal
practical in many applications. With the representation, values such as voltage (peak, RMS, minimum,
FNIRSI 1014D, you get both functions in maximum, etc.), frequency, and duty cycle are displayed numer-
ically (Figure 1). Users can select which values to display from a
one device. We take a look. menu. Two cursors allow precise measurement of time intervals
The scope comes with two switchable probes (1× and 10×), a USB
power supply, a manual, and a probe adjustment tool. The oscil- Figure 1: Waveforms and measurement results.
and voltages. An auto-set function automatically configures the criterion, even though it displays a 100 MHz signal in an accept-
oscilloscope to sensible parameters based on the input signal. Even able way (Figure 2).
a simple FFT representation of the signal can be displayed.
For further details, see the section “For professionals: Bandwidth
The FNIRSI 1014D can handle a maximum input voltage of 400 V. and Sampling Rate” below.
Triggering can be set on the rising or the falling edge. The scope
also features an automatic triggering function that works reliably. The minimum sensitivity of 50 mV / div is not spectacular. Typically,
a sensitivity of at least 10 mV / div is available on most DSOs. Never-
Power Supply: USB PSU or Power Bank theless, the measured values are within the specified tolerances,
In addition to the standard USB power supply, the scope can and the analysis options are satisfactory.
also be operated by a power bank. In this case, the oscilloscope
is completely electrically isolated, allowing measurements in Saving and Analyzing Signals
switching power supplies, etc., without the need for an isolation All measurements can be saved as a screenshot and/or waveform
transformer. This alone makes the FNIRSI 1014D worthwhile for and accessed through a gallery view. When saving a waveform, it
this application, saving the expense of costly differential probes, can be analyzed even after the measurement, as if the measurement
which, even in a budget version, cost as much as the oscilloscope. signals were still present (Figure 3). For waveforms and screen-
Additionally, by using a power bank, the scope becomes very porta- shots, 1 GB of internal memory is available, and this can be read
ble and can be used in any location, such as power racks or cars. out via a computer. During USB operation, the FNIRSI 1014D is
simply recognized as a removable disk, and no drivers or additional
Using a standard 12 Ah (I max > 2 A) power bank, the FNIRSI 1014D software are required.
runs for about 5 hours in continuous operation. This will be suffi-
cient for most applications. No advanced functions, such as mathematical functions, bus decod-
ing, etc., are available, which is acceptable given the price point.
Nevertheless, a simple Fourier transform display is provided. As
Warning: The FNIRSI 1014D manual states that “the original power it does not allow detailed measurement applications, its value is
supply must be used.” So, using a power bank is at your own risk, limited to simple harmonic analysis (Figure 4).
even though no problems came up during the tests.
Performance Check
Regarding the specified bandwidth of 100 MHz, some things
should not be overlooked. To measure a signal with a maximum
frequency component of 50 MHz, an oscilloscope with a bandwidth
of 100 MHz is required. If a measurement is to be truly meaningful
and well-resolved, the commonly used guideline is the 1:5 rule.
An oscilloscope with a 100 MHz bandwidth can effectively and
accurately display a signal with a maximum frequency compo-
nent of 20 MHz.
Another issue is averaging. Usually, the averaging depth can be Figure 5: FNIRSI 1014D’s measured bandwidth.
> 14 function types: sine, square, triangular, saw-tooth, step, All in all, the FNIRSI 1014D is an affordable, portable digital oscillo-
half-wave, full wave, exponential, logarithmic, exp-log, square scope with two channels and sufficient features and performance.
root, multi-audio, sync pulse, custom It is well-suited for hobby workshops, schools, electronics enthu-
> Duty cycle: 1% to 99% (square wave) siasts, or common repair tasks.
240074-01
Unfortunately, the generator’s amplitude is fixed at 2.5 Vpp, limit-
ing its versatility to a certain extent. Nevertheless, most standard
applications, such as checking resonance curves on audio ampli- Questions or Comments?
fiers, remain possible. Thanks to the variable duty cycle, pulses If you have any technical questions, you can contact the Elektor
and asymmetric square waves are also available. editorial team at [email protected].
WEB LINKS
[1] Jean-François Simon, “Select and Use an Oscilloscope: A Beginner’s Guide,” elektormagazine.com, November 2023:
https://elektormagazine.com/articles/oscilloscope-beginner-s-guide
[2] FNIRSI 1014D in the Elektor Store: https://elektor.com/fnirsi-1014d-2-in-1-2-ch-oscilloscope-100-mhz-signal-generator
[3] Arduino articles on our website: https://elektormagazine.com/tags/arduino
[4] ESP32 articles on our website: https://elektormagazine.com/tags/espressif/esp32
[5] Raspberry Pi Select Page on our website: https://elektormagazine.com/raspberry-pi
2024 An AI Odyssey
Getting Object Detection Up and Running
By Brian Tristam Williams (Elektor) even using a keyboard, as I’m using the PuTTY app [2] in Windows to
SSH into the Pi (Figure 1). Just enter the device’s host name — in my
Exploring object detection on our headless case raspberrypi — in the PuTTY window and click Open. You could
Raspberry Pi, we detail setting up the camera also use an IP address.
and tweaking TensorFlow Lite for real-time Once you’ve established a connection, you’ll need to enter your login
applications. name and password for the Raspberry Pi. It is possible to save these
credentials, and, because you’ll be doing this a lot, recommended.
In our previous installment [1], I installed Tensorflow Lite on the In the past, we needed to run sudo raspi-config and enable Camera
Raspberry Pi, which is running a version of Raspberry Pi OS with under Interface Options, but with the latest Raspberry Pi OS distros,
no graphical user interface (GUI), otherwise known as a “headless” the camera is detected automatically.
installation. This time, I’ll detail how I got the camera up and running
and trying to detect things. To give the camera a quick test on the headless system, I installed a
couple of packages:
Getting the Camera Working
The first thing I wanted to do was to get some camera packages sudo apt-get install -y libraspberrypi-bin
installed to test the camera. I’m running a headless version of Raspberry sudo apt-get install libcamera-apps
Pi OS, so I can’t just click to a camera application. This time, I’m not
After logging in again, it was time to test the camera by sending its
live output directly to my monitor, using
libcamera-hello
That worked, and it’s great that I can see the on-board camera’s live
output on the monitor (Figure 2), but that’s where that hardware
success ended, and we’ll get into that later.
Because I rebooted, I had to enter the tflite1 subdirectory again and start
the virtual environment. Due to much debugging and trial and error,
I ended up creating a new virtual environment called new-tflite-
env, so I entered it using
source new-tflite-env/bin/activate
Then, I had to throw out the recommended scripts from the guide I
was looking at on GitHub, as the Python methods used there were
Figure 1: PuTTY user interface. intended for an OS with a GUI, and we don’t have one. We need
the TensorFlow Lite package, which we already installed, as well as Figure 3: The packages installed in my virtual environment.
numpy. By this time, I had quite a list of Python packages installed,
ready to take on the job. To see what packages you have installed in
your environment, enter pip3 list at the command prompt. My list on your Raspberry Pi’s horsepower, so I would expect more from a
looks like that in Figure 3. If you don’t have numpy, install it using the Raspberry Pi 5 when compared to the 4 that I’m using.
same method as for opencv-python-headless above.
To run the script, at the prompt, just enter
Test Script
Now, onto the test script (Listing 1). Our little Python script uses the python3 objdet.py
TensorFlow Lite Interpreter to load the model and perform object
detection on input images. It continuously captures video frames from Hurdles
a camera, processes each frame to fit the input requirements of the That’s all great, in theory, but when I ran this script, it refused to detect
pre-trained TensorFlow Lite model (detect.tflite), and then uses the anything. Eventually, I tried reducing the confidence threshold to 0.2
model to detect objects within those frames. Detected objects with a instead of 0.5, and then all it would detect is “???” with varying levels
confidence score above 0.5 are printed to the console with their labels, of confidence. To debug, I then added a line to save the captured
confidence scores, and bounding box coordinates. The script uses frame to a file:
OpenCV for video capture and frame preprocessing, and TensorFlow
Lite’s Python API for model inference. cv2.imwrite(ˈtest_frame.jpgˈ), frame
Key components of the script include: I put this right after the cap.read() instruction. Running that and
checking the output, I found out that it was saving a 5,427-byte file
> TensorFlow Lite Interpreter Initialization: Loads the detect.tflite that looked like this, according to the file command:
model and prepares it for inference.
> Video Capture Setup: Initializes video capture from the webcam test_frame.jpg: JPEG image data, JFIF standard 1.01,
using OpenCV (cv2.VideoCapture(0)). aspect ratio, density 1x1, segment length 16, baseline,
> Frame Preprocessing: Converts captured frames to RGB, resizes precision 8, 640x480, components 3
them to match the model’s input dimensions, and wraps them in
a batch format expected by TensorFlow Lite. That all looks as one would expect, albeit that it’s a rather small file,
> Object Detection: Feeds the preprocessed frames into the so I suspected nothing amiss there until I took a look at the file on my
TensorFlow Lite model and retrieves detection results. PC. I used SCP in Windows Command Prompt to bring the file over:
> Result Processing: Iterates over detection results, filtering by
a confidence threshold of 0.5, and prints the label, confidence C:\Users\Brian>scp briantw@raspberrypi:/home/briantw/
score, and bounding box for each detected object. tflite1/test_frame.jpg .
The script uses real-time processing suitable for applications requiring What this does is, after you enter your password, collect the file from
immediate object detection feedback from video streams, showing the Raspberry Pi and write it to the current directory (.) in Windows
objects identified and their locations in the image, with the help of — in my case my default user directory. When I opened the file, much
bounding boxes. How many detections you can do per second depends to my surprise, it had captured nothing but a black image.
I tried to remedy this using everything from Google searches to I would like to digitize them and have AI run the gamut of classification
ChatGPT, and I could not get the camera to give my Python script tasks from object detection to speech-to-text transcription, all added
anything but a black image. I even tried activating seconds-long delays to an online metadata database that’s searchable.
in the code to give the camera time to “warm up” and initialize, to no
avail. I also did an update and an upgrade again, and even updated While the detection accuracy currently leaves me much to desire, the
the firmware using sudo rpi-update and then did a sudo reboot. awesome thing is that you can change the detection source from live
Oddly, the camera does work, as libcamera-hello continues to prove, camera to video file by changing just one line in the script — the one
so this is a software mystery to me. with the VideoCapture() call. I tried a sample video file, one taken on
the grounds of Churchill College in Cambridge last year, and uploaded
Eventually, on a lark, I pulled out a Logitech webcam of mine, and it to the Raspberry Pi using SCP again:
plugged it into the Raspberry Pi. After rebooting the system and re-en-
tering the virtual environment, I ran the script again, and it worked. C:\Users\Brian>scp 20230919_174323.mp4 briantw@
In the script, you can select the camera in use, and, as you see in raspberrypi:/home/briantw/tflite1/20230919_174323.mp4
Listing 1, it says:
and then changed the line in Listing 1 to:
# Initialize video capture from the camera
cap = cv2.VideoCapture(0) cap = cv2.VideoCapture(ˈ20230919_174323.mp4ˈ)
This tells cv2.VideoCapture() to use camera 0. Once I plugged the and off it went, detecting objects in the video. The good news is that
USB webcam in, it became camera 0, and the onboard Raspberry Pi it was so easy to change sources. The bad news is that there was not
Camera Module 3 became camera 2. So, as it stands, the webcam a bicycle to be seen anywhere in the video (Figure 5).
(0) works, and the onboard Raspberry Pi Camera Module 3 (2) just
outputs a black image. Next Time
Now that I have the system running and able to detect objects, I will turn
Detection Results my attention to improving accuracy, and explore different models and
Well, now that the object detection is working, the system outputs the training thereof. If I’m lucky, I’ll get the system to produce pleasing
what it sees. I have pointed my webcam at everything from Elektor results that serve a productive purpose. Will I be lucky? We’ll see.
Magazine editions to movies on my monitor to things in my office, and 230181-F-01
I can report that it sure likes bicycles. It picked up “TV,” “remote,” and
“potted plant” alright, with some false positives, such as “cake” for my
camera light, and it found a “tie” where there wasn’t one. In Figure 4, Questions or Comments?
you see it confidently looking at a dog with a ball and detecting a cat Do you have technical questions or comments about this article?
with a snowboard. When scenes get busy, it reaches for “bicycle” a lot. Email the author at [email protected].
# Load labels
with open(ˈSample_TFLite_model/labelmap.txtˈ, ˈrˈ) as file:
labels = [line.strip() for line in file.readlines()]
# Perform detection
interpreter.set_tensor(input_details[0][ˈindexˈ], input_data)
interpreter.invoke()
cap.release()
WEB LINKS
[1] Brian Tristam Williams, “First Forays Into TensorFlow,“ Elektor 3/2024: https://elektormagazine.com/magazine/elektor-333/62725
[2] PuTTY — Terminal program for remote access to your headless Pi: https://putty.org
[3] Saad Imtiaz, “CaptureCount,” Elektor 3/2024: https://elektormagazine.com/magazine/elektor-333/62717
In complex measurement
Quartz Oven
FTM301 / AOCJY Divider
Ref. Voltage OSC
AGC
VC GND
XO91SMD
highly accurate reference
frequency. This article AGC
Balun + Filter
AD8368
180385-008 Enable
Capacitors Miscellaneous
SMD 0603, unless otherwise specified X1 = 2-pin screw terminal, RM 5 mm
C1 = 4,700 µ / 16 V, electrolytic, RM 5 mm, ø 13 mm * X5 = 3-pin screw terminal, RM 5 mm
C2, C4, C8…C11, C19…C22, C34, C35, C51…C54, C56…C65, C82, C83 = JP1, JP2 = 2-pin header
100n Tr1 = transformer 2× 6 V, 2 x 300 mA, RM 20 mm, PCB mounting *
C3, C5, C12…C18, C33, C36…C40 = 22µ / 20V, SMD SMCB Tr3 = transformer 2× 6 V, 2 x 233 mA, RM 27.5 mm, PCB mounting
C6, C7 = 2,200 µ / 16 V, electrolytic, RM 5 mm, ø 13 mm Tr51…TR81 = ADT1-1, RF transformer, SMD *
C23, C32 = 33p F1 = fuse 250 mA, 20× 5 mm
C24 = 120p Fuse holder for F1, PCB mounting
C25, C90 = 5p6 K1 = relay FTR-B4S, SMD
C26 = 10p
C27 = 150p * See text
Alternatively, the circuit can also be used 3.3 V power supply around Tr1 and IC3. The an external reference signal via AGC takes
simply as a distribution amplifier. If you have heating of an optional OCXO is also fed from place via the +5 V branch, with small RC filters
a high-quality external reference frequency this branch. Its configuration ensures that an (R311/C85 and R312/C84) included. Two LEDs
available, you can feed it into the reference accurate and low-drift reference frequency on the circuit board indicate that the system is
input at the bottom left. After amplitude stabi- is obtained. ready for operation. An additional LED can be
lization by a special RF amplifier (AGC), this mounted on the front panel. When all output
signal is fed to the distribution amplifier bank The analog amplifiers are supplied symmet- stages are fitted, a current of around 180 mA
on the right as a reference. rically with ±5 V from Tr3 and the two classic flows in the ±5 V branch.
voltage regulators IC1 and IC2. To ensure clean
Circuit voltages, a large number of small decoupling Oscillators
As you can see in the circuit in Figure 2, the electrolytic capacitors, each with 22 µF and A high-precision, heated quartz generator
digital and analog parts are supplied separately. 100 nF multilayer capacitors, are distributed of type FTM301 from FOX or, for example,
The clock generation is supplied by the across the circuit. The level stabilization of type OH300-50503CF-020.0M [1] from
0Ω
R14 L8 1µH8 L9 1µH5
4
+3V3 MCP1525TT R18 U2 /Q 390Ω
3 4 2
50Ω CLK 100n
VDD RF OUT GND R51 OSC
IC6 R17 R15 R50
2 3 C23 C24 C27 C28 C31 C32 200Ω
VREF Y1
130Ω
120Ω
100Ω
R52
VC GND 33p 120p 150p 100p 100p 33p AGC
390Ω
1 5
C34 C35 U2 = SN74LVC1G80DBVR
R16
+3V3
R9
XO91SMD
10k
4
+5V C94 +5V
VCC R11
XO1 1
50Ω
OE 10n
C20
3
R312 R311 R317 R313
FO R10
100n
10Ω
180Ω
23
10Ω
10Ω
100Ω
VPSI
11 10
GND VPSI_2 VPSO
12 9
2 VPSI_3 VPSO_2
13
R303 R307 VPSI_4
22 1
75Ω 0Ω VPSI_5 GAIN
LSP1 C81 C87 U1
R304 L301 4µH7
19 8
75Ω INPUT OUTPUT
R318
10n 47p R314
R301 R302 R305 R306 24
TR1 C88 10k ENABLE
0Ω
150Ω
150Ω
nb
nb
5 2
ADT1-1 3p3 DETI DETO
R316
LSP2
68Ω
AD8368ACPZ-WP
R308
4 3
0Ω DECL HPFL
14
DECL_2
15 7
DECL_3 OCOM
6
OCOM_2
20
ICOM
16 21
ICOM_2 MODE
17
ICOM_3 +5V
18 25
ICOM_4 EP
R25
T2 R310
1k
4k7
R309 R315
C82 C84 C85 C92 C90 C91 C89 C93 C86 C83 AGC
2N3904
10k
10k
TR1 OSC
D3 D1 LT1963AET-3.3 +3V3
X1
IC3
2 4
IN OUT
R1 R4 +5V
820Ω
1 5
10k
/SHDN SENSE
D4 D2
JP2
GND
C1 C2 C3 C4 C5
T1 3
2 x 6V R2
2 x 300mA 4700µ 100n 22µ 4k7 100n 22µ
16V 20V R3 20V
D31 K1
LED1
D1...D8 = SK34 2N3904
10k
1N4148 FTR-B4S
TR3
R5
F1 +5V
250mA
D8 D5
0Ω
X5
7805
IC1
R6
1k2
LED2
2200µ 100n 100n 22µ 22µ 22µ 22µ 22µ 22µ MBR0540
2 x 6V 16V 20V 20V 20V 20V 20V 20V
2 x 233mA
LED3 JP1
MBR0540
1k2
IC2
7905
–5V
Figure 2: The detailed circuit of the reference generator is somewhat more extensive, but the seven output amplifiers are constructed in the same way.
8 8 8 8 8 8 8
100n 100n 100n 100n 100n 100n 100n
IC4 IC5 IC7 IC8 IC9 IC10 IC11
4 4 4 4 4 4 4
C59 C60 C61 C62 C63 C64 C65
–5V
Connor-Winfield (Y1 in Figure 2) is used as
50Ω
R54
3
R118
R113
0Ω
the oscillator. For lower quality requirements,
a simple 20 MHz quartz oscillator (XO1 in
1 5
IC5A 50Ω R115 C66
L7
2 7
LSP15
Figure 2, [2]) is also sufficient. Of course, only
IC5B 50Ω
4µH7
6
R56 47p
R53 R55 R57 R117 3p3 ADT1-1 Y1 is fitted, the circuit will draw up to 800 mA
50Ω
470Ω
470Ω
LSP16
R114
0Ω
switching on during heating. The current is
R58
3
R67 then reduced to approx. 350 mA.
50Ω R61 R63 0Ω
1 5
IC4A 50Ω 50Ω R66 C70
L1
2 7
R60
6
IC4B 50Ω
47p
4µH7
LSP3
The frequency of Y1 can be influenced to a
470Ω
R62
R65 C71 TR53 small extent via input VC (pin 1) with a control
voltage of 0…2.5 V generated by IC6 and
470Ω
500Ω ADT1-1
R59 R64 3p3
330Ω
390Ω
LSP4
adjustable with R16. If XO1 is fitted instead of
R68 Y1, IC6 and the trimming potentiometer R16
can be omitted. Some oscillators contain their
0Ω
R69 R78
3
50Ω
IC7A
1
R72
50Ω
R74
50Ω
5
R77 C72
0Ω
own reference voltage, which can be tapped at
L2
pin 2. In this case, IC6 can be omitted and R17
2 7
IC7B 50Ω LSP5
6 4µH7
390Ω
LSP6
R79 frequency can be calibrated with R16, which
R80
0Ω
R89
of course requires a suitable and, above all,
50Ω
3
1
R83 R85
5
0Ω highly precise external reference frequency.
IC8A 50Ω 50Ω R88 C74
L3
2 7
IC8B 50Ω LSP7
6 4µH7
470Ω
R82
R87
47p
C75 TR55
If absolute accuracy is not very important, the
R84
500Ω
470Ω simple and inexpensive XO1 crystal oscillator
ADT1-1
in an XO91 housing will also do. Once again:
R81 R86 3p3
330Ω
390Ω
R90
LSP8
Only one oscillator is to be fitted — either Y1
0Ω or XO1. Due to the lower current consumption,
no extra transformer TR1 is required for XO1
R91 R100
3
50Ω R94 R96 0Ω
1 5
and the rectifier from D1...D4 is also omitted.
IC9A 50Ω 50Ω R99 C76
L4
2 7
IC9B 50Ω LSP9
Instead, R5 is fitted to derive the required 3.3 V
6 4µH7
R93 47p
C77
from the 5.5 V branch. R11 is fitted when XO1
470Ω R98 TR56
R95 470Ω
390Ω
LSP10
R102
50Ω
3
R105 R107
R111
0Ω
of 50% of the 10 MHz signal, the 20 MHz of
the primary clock generator is divided by a D
1 5
IC10A 50Ω 50Ω R110 C78
L5
2 7
LSP11
flip-flop. An alternative is to fit 10 MHz gener-
IC10B 50Ω
4µH7
6
R104 47p
R103
500Ω
R108 3p3 ADT1-1 its input is connected to the output pin by
330Ω
390Ω
R127
6
IC11B 50Ω
47p
4µH7
LSP13
frequency of the filter is 11 MHz, its ripple is
470Ω
R125
R122 C69 TR52 only 0.1 dB, and the input and output imped-
ance is 100 Ω. The voltage divider R14/R15
470Ω
500Ω ADT1-1
R130 R128 R123 3p3
330Ω
390Ω
LSP14
R120 DC voltage components (= half the operat-
ing voltage).
0Ω
180385-009
pot R51 and adapted to the input level range Reference Input and AGC One more note on the design: Good thermal
of the AGC. The relay K1 and a switch on the An AGC IC of type AD8368 [5] from Analog insulation of the OCXO will reduce its power
front panel can be used to select between Devices (U1) is used for this subcircuit. The consumption. It has reached its maximum
the signal from the internal generator and the wiring in Figure 2 corresponds to the recom- accuracy after 30 minutes at the latest.
reference input. mendation in the data sheet. In order not to
overdrive the input, an attenuator of 6 dB is Fitting Options
Distribution Amplifier connected before the HF input transformer As has already become clear, the circuit
IC5A amplifies the signal by a factor of 2 and Tr81. If galvanic isolation is not required, the board provides for several fitting options.
distributes it to six of the seven output stages transformer can also be omitted here and The optional components are marked with
via a line terminated with 50 Ω (R130) to avoid replaced by the two resistors R307 and R308. an asterisk in the parts list. For the sake of
reflections on the PCB traces and to achieve Level stabilization via AGC works with input clarity, the fitting options are specified here
as equal a level as possible at all inputs of signals between 70 and 2,000 mVSS at 50 Ω. once again:
the seven output stages. The 50 Ω resistor Lower input levels will reduce the output level
of these stages is used to decouple the input — higher input levels will increase it. OCXO or Simple Quartz Generator
capacitance of the op-amps installed there. For the OCXO Y1, Tr1, the diodes D1…D4, and
Six of these stages are fitted with two video Power Supply C1 must be fitted. R5 is omitted. For XO1, Tr1,
op-amps each. The amplitudes of these six After switching on the circuit with a cold D1…D4 and C1 are omitted. R5 is fitted instead.
channels can be individually adjusted with OCXO, significantly more current flows than
their 500 Ω trimpots. later in the tempered state. For this reason, Oscillator with 20 or 10 MHz
a relatively powerful transformer with For 20 MHz oscillators, the divider U2 must be
The second op-amp of IC5 drives a serial Schottky diodes and a large filter capacitor fitted. R13 is omitted. For 10 MHz oscillators,
bandpass filter consisting of the two paral- is provided. The stabilized 3.3 V is gener- U2 is omitted. R13 must be fitted.
lel-connected capacitors C66 and C67 plus ated by the LT1963AET-3.3 low-drop regula-
the coil L7 and finally the HF transformer tor (Analog Devices). The regulator must be Reference Voltage of the OCXO
Tr51 of type ADT1-1 [3] via a 50 Ω resistor. cooled. For this purpose, it can be screwed If the OCXO has an internal reference voltage
This output stage has no trimmer potentiom- onto the rear wall of an aluminum housing source, IC6 is not required and R17 must be
eter and its output voltage is therefore not with insulation. Its output voltage can be fitted. Without an internal reference voltage
adjustable. switched off via the shutdown input if you source, IC6 is required. R17 should not be fitted
want to use the external reference frequency in this case.
Generally speaking, if you don’t need galvanic and operate the circuit as a distribution ampli-
isolation, you can leave out the HF trans- fier only. This measure prevents interfer- Internal or External Frequency Generation,
formers Tr51 to Tr57 and fit two 0-Ω resistors ence between the internal generator signal or Both
instead. In my prototype, I used MAX4392ESA and the external reference signal. Relay K1 It is possible to equip only the internal oscil-
[4] op-amps in a SOIC8 package. However, is controlled by a switch on the front panel, lators or only the input for an external refer-
you can also use other video amplifiers that which is connected to JP2. A changeover ence with AGC, or both parts. When using an
are suitable for a power supply of ±5 V. With contact of the relay selects the input signal internal generator, the AGC is switched off.
galvanic isolation and a metal front/rear panel, for the distribution amplifier. The other contact When using the external input with AGC, the
it is obviously necessary to ensure that the controls the SHDN input of IC3 via T1 and the 3.3 V power supply and thus the oscillators
BNC sockets are insulated! ENBL input of the AGC via T2. and the divider are switched off.
WEB LINKS
[1] OH300-50503CF-020.0M datasheet [Digikey]: https://tinyurl.com/4j6bzren
[2] AOCJY-20.000MHZ datasheet [Digikey]: https://tinyurl.com/4v4n23en
[3] HF Transformer datasheet [minicircuits.com]: https://tinyurl.com/4fzxkfky
[4] MAX4392 datasheet: https://analog.com/en/products/max4392.html
[5] AD8368 datasheet: https://analog.com/en/products/ad8368.html
[6] Elektor web page for this article: https://elektormagazine.com/180385-01
NO MATTER
Hall 6 - 342
Highlights
• New M12 A-coding portfolio
• Adapted to work in demanding environments
with IP67 & IP68 protection
• Male & female versions of all connectors
© eiSos
lab • Elektor
or
kt
lab
Ele
O R IG IN A L
ab
Ele
rl
to
r la b k to
k
• Ele
WARNOUT
PM0
PM1
CF4
CF3
CF2
CF1
CS
ZX0
ZX1
ZX2
SDI
SDO
IRQ1
IRQ0
CLK
JP7 D2
VBUS_B
JP5 JP6 1 2 3
+3V3 +5VA 4k7 CC2
+5VA IC2 +3V3-U 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1N5819HW-7-F
R31 SBU1
NJM2882F33-TE1
PM1 DP2
1 5 K2
IN OUT +3V3 DN1
GND
CONTROL
NOISE
D4 D5 D3 CC1
R38 PM2 4k7
2 3 4
R32 SBU2
80Ω
R37
R20
R21
R19
R18
100k VBUS_A
10k
10k
10k
10k
3 x SZSMF4l5.0AT3G
22µ 10n 22µ
+3V3
R22
10k
42
R2 R3 R6 R7 R10 R11 VDD18
C2 C3 C4 C6 C9 C11 C24 43 +3V3
VDD18
2Ω4
2Ω4
2Ω4
2Ω4
2Ω4
2Ω4
1 C1
41 AVDD
18n 18n 18n 18n 18n 18n 100n /RESET 48
K1 DVDD
11 100n 1 40
6 R1 3 VREF +3V3-U GND GND
I1P 1k I1P 2 39
5 R4 4 C12 C13 C8 C10 C5 C7 3V3 IO2
I1N 1k I1N 22 3 38
4 R5 5 ZX0 EN IO2
I2P 1k I2P 23 4 37
R8 6 ZX1 100n 10µ 100n 100n 100n 10µ IO4 TXD0
3
I2N 1k I2N 24 5 36
2 R9 7 ZX2 IO5 RXD0
I3P 1k I3P 6 MOD1 35
1 R12 8 IO6 IO42
I3N 1k I3N 25 7 34
IC1 CF1 IO7 ESP32-S3-WROOM-1 IO41
26 8 33
+12V 13 CF2 IO15 IO40
V1P 27 9 32
14 CF3 IO16 IO39
V1N 28 10 31
D6 D7 15 CF4 IO17 IO38
V2P 11 30
16 ABM8G R33 R34 R35 R36 IO18 IO37
2 x B140HW-7 V2N 29 16.384MHz B4Y-T 12 29
K4 17 WARNOUT IO8 IO36
V3P X1
80Ω
80Ω
80Ω
80Ω
2 4 13 28
6 R30 18 GND GND IO19 IO35
UC 100k V3N 30 14 27
R28 IRQ0 IO20 IO0 +3V3-U
5 LED3 LED4 LED5 LED6
IO9
IO10
IO12
IO13
IO14
IO11
IO46
IO21
IO47
IO48
GND R24 C22 R23 C21 R25 C23 R15 C16 R14 C15 R13 C14 PM1 20
2 OSCI
GND 21
1k
1k
1k
1k
1k
1k
10k
1 37 OSCO
DC IN /CS
38
18n 18n 18n 18n 18n 18n SCLK 9
39 IC
ATM90E32AS-AU-R
SDO 10 K3 C19 C18
40 IC 1 +3V3-U R27 R26
EN1
32 S1 S2
35 TEST Qwiic 3
NC 19 SDA
45 DGND C20 4 LED2 LED1
NC 44 SCL
AP63203WU-7 46 DGND +3V3 +3V3-U
C28 NC 47
1 6 DGND 100n JP3 JP4
FB BST 12 JP1 1 1 GREEN RED
AGND GND 3V3
+12V IC3 100n L1 R39
+3V3 2 2 2
2 5 AGND 3V3 GND C17
EN SW 0Ω 3 3
SRN6028C-3R9M
SCL SCL
D1
BOOT1
4 4
3 4 R40 SCA SCA 100n
VIN GND +3V3-U
80Ω
BAT760-7
1 2 3 4 5 6
C32 C30 C29 C31 LED8
JP2
100n 220µ 220µ 100n
TX
D0
RX
EN
GND
3V3-U
240093-001
Figure 4:
Thus, for each of IC1’s voltage sampling inputs, there is now only one The front and
100 kΩ resistor (R27 to R29). Last time we combined all the phase back of the
voltages into one input, and a lot of feedback was given by the readers PCB layout.
to have the option to use it with either three-phase or single-phase
power if needed. We thought about it, and now we can use it with
both. By default, three-phase mode is configured, but if one wants provided on terminal JP5 and JP6. This enables the energy meter
to make it single-phase, jumper JP8 needs to be shorted. Figure 3 to be used as a module as well with another MCU if the onboard
shows the general wiring illustration for a three-phase system. Note ESP32-S3 is not required.
that the phase wires are connected after the step-down to 12 VAC
from a transformer — using a 12 VAC doorbell transformer can be The ESP32-S3 has the USB feature built in, so it’s really convenient to
useful in this case. program the MCU this way, which is why we added USB-C connector
K2. For troubleshooting, terminal JP2 has been added. Status LEDs
For current sampling and measurement, instead of using the headphone LED1 and LED2, which can be controlled by the ESP32-S3, and push
jack as the connector, a 5.08 mm pitch screw terminal block is used, buttons S1 and S2 are added for interacting with the OLED screen,
i.e., K1. This adds to the overall ruggedness of the energy meter. For which can be connected to JP3 and JP4. Why two connection points?
current coil sensors, the YHDC SCT013 100 A : 50 mA is selected Some I2C OLED screens have ground as the first pin and some have
and the resistors R1 to R12 for all three current sensing inputs are 3V3 supply instead. This way, both types of OLED pinout variants can
calibrated accordingly. be worked with.
Power Supply Optimization Finally, the Qwiic connector at K3 has also been added to enhance
The energy meter is now powered with buck switching regulator IC3, the functionality of the Energy Meter, in case one wishes to add some
i.e., the AP63203WU-7 by Diodes Incorporated. Previously, Hi-Link additional sensors or modules to this project.
HLK5M05 modules were used, but they are much bulkier and more
expensive than this buck converter. This is done as buck converters The PCB Layout
are more efficient than these Hi-Link modules, they cost less, and The PCB layout has been meticulously optimized for compactness,
their size is much smaller. Using IC3 also lets us power the circuit with and easy soldering, shown in Figure 4. At the top, voltage and current
12 VDC at K4 for development purposes and also from the UA, i.e., sampling connections are strategically positioned in one place for DIN
voltage phase 1 of from the same connector, K4, for normal operation. rail format integration. On the right side, connections for any external
microcontroller (MCU) are facilitated through 2.54 mm pitch headers,
Interactive and Modular Features ensuring ease of access and modularity. Centrally located is the connec-
For active, reactive, apparent, active fundamental, and harmonic tion for the OLED screen, flanked by push buttons for intuitive inter-
energy pulse outputs CF1 to CF4, LEDs have been added [7][8]. For action. Adjacent to the OLED display, power and status LEDs provide
the power mode selection of IC1, jumpers PM1 and PM2 are added. immediate visual feedback, while energy pulse output LEDs are conve-
In this version, all the output pins of IC1 ATM90E32AS for MCU are niently situated near the MCU output terminals for direct monitoring.
At the foundation of the design, the USB-C port and the ESP32-S3
module are positioned away from the AC voltage areas to improve
safety. A ceramic capacitor, placed adjacent to the 3 V input of the
ESP32-S3, serves to decouple and significantly reduce any potential
noise. Additionally, electrolytic capacitors are incorporated into the
design, further stabilizing the power supply and ensuring the circuit’s
reliability and performance. This layout streamlines the assembly
process and enhances functionality and user experience by provid-
ing a clear and logical component arrangement. In Figure 5, you can
see the rendering of the assembled PCB. Questions or Comments?
If you have questions about this article, feel free to email the
This design requires the use of mains-powered author at [email protected] or the Elektor editorial team
transformers. People inexperienced with mains at [email protected].
voltages should not attempt this project or should ask
someone with experience who can help them with this
project!
WEB LINKS
[1] Saad Imtiaz, “Project Update: ESP32-Based Energy Meter,” Elektor 1/2024: https://elektormagazine.com/magazine/elektor-324/62641
[2] ESP32 S3 DevKit-C Schematic: https://dl.espressif.com/dl/schematics/SCH_ESP32-S3-DevKitC-1_V1.1_20221130.pdf
[3] ESP32 S3 Pinout Help Guide: https://luisllamas.es/en/which-pins-can-i-use-on-esp32-s3
[4] SCH_ESP32-S3-USB-Bridge-MB_V2.1 Schematic: https://tinyurl.com/usbbridgeschematic
[5] ESP32-S3 Pin Reference: http://wiki.fluidnc.com/en/hardware/ESP32-S3_Pin_Reference
[6] ESP32-S3: Which Pins Should I Use?: https://atomic14.com/2023/11/21/esp32-s3-pins.html
[7] Application Note Poly-Phase Energy Metering IC M90E32AS: https://tinyurl.com/polyphasemetering
[8] Atmel M90E32AS | Datasheet: https://eu.mouser.com/datasheet/2/268/Atmel_46003_SE_M90E32AS_Datasheet-1368788.pdf
[9] ESP32 Energy Meter | Elektor Labs:
https://elektormagazine.com/labs/esp32-energy-meter-an-open-source-solution-for-real-time-energy-monitoring
Err-lectronics
Corrections, Updates, and Readers’ Letters
Compiled by Jean-François Simon (Elektor)
The relays needed for this part of the circuit are reed
relays, with one row of contacts (SIP), 5.08-mm pitch,
12-V coil, type MES1A12, or SIP-1A12, or equivalent, see
for example: Conrad 2273680, Farnell 9561935, Digikey
3008-SIP-1A12-ND. You can also search the part numbers
above on eBay. Concerning the front panel drawing, I
took a look in our archive but, unfortunately, it is not
available anymore. Our apologies for the inconvenience!
_
Got a bright idea or
valuable feedback for Elektor?
Reach out to us at editor@elekto
r.com
– we’re eager to hear from you!
_
X. R. (France)
Thank you for your e-mail. The value is not critical; you often see between 1 µF and 10 µF for
the input capacitors in this type of setup. If you want to calculate more precisely, you have to
look at the high-pass filter, which consists of the capacitor in question and the input resis-
tance, in this case 10 kΩ. We use the classic formula for a first-order filter, f = 1/(2*π*R*C).
You can use a 1 µF capacitor, which will pass all frequencies above about 16 Hz, or a 2.2 µF,
which will pass signals from about 7 Hz. I recommend capacitors of type MKP4 or MKS4,
250 V or 400 V.
240144-01
WEB LINKS
[1] Uninstalling Arduino Libraries: https://support.arduino.cc/hc/en-us/articles/360016077340-Uninstall-libraries-from-Arduino-IDE
[2] TimeClick project software: https://www.elektormagazine.com/magazine/elektor-201102/19542
[3] Microchip Device Support list: https://packs.download.microchip.com/DeviceDoc/Device_Support.pdf
[4] OpenDTU OnBattery: https://github.com/helgeerbe/OpenDTU-OnBattery
[5] OpenDTU OnBattery wiki: https://github.com/helgeerbe/OpenDTU-OnBattery/wiki
[6] Elektor Schaltungs-Sonderheft (Elektor, 2020): https://www.elektor.de/products/elektor-schaltungs-sonderheft-2020
[7] PICProg 2003 software: https://www.elektormagazine.com/magazine/elektor-200309/17563
Price: €69.95
Member Price: €62.96
www.elektor.com/20749
Price: €169.95
Member Price: €152.96
www.elektor.com/20777
www.elektor.com/20775 www.elektor.com/20796
www.elektor.com/20787 www.elektor.com/20774
Raspberry Pi 5
and Beyond
Questions by Jean-François Simon (Elektor)
J.F. Simon, Elektor: The Raspberry Pi 5 has been The addition of a single-lane PCIe “user port” is also
out for a few months now. How are the sales going? opening up new opportunities for experimentation.
We’ve been watching with interest as Jeff Geerling
Eben Upton: Very well. We’re closing in on shipping tries to get his giant collection of PC graphics cards
our first million units. This is a little slower than the up and running with Raspberry Pi 5.
Raspberry Pi 4, and has been limited by production
until very recently. Kudos to the team at Sony for JF: Do you have interesting or funny anecdotes about
getting us to a production rate of 90,000 units per things that happened during the development of the
week. [Editor’s Note: The Sony UK Technology Centre Raspberry Pi 5, and that you may be able to share now
in Pencoed, Wales, manufactures Raspberry Pi boards.] that it’s out?
We won’t need to stay there forever, but it gives us a
chance to catch up with demand and to start to build Eben: What people don’t appreciate about
a little inventory. Raspberry Pi 5 is how long it’s been in development.
The first ASIC team members started work on the
JF: Have you seen exciting projects made with the RP1, then called Project X, in the summer of 2015.
Raspberry Pi 5, that would have been harder to make [Editor’s Note: The RP1 is a custom southbridge, designed
with any prior versions, and that made you particu- in-house by Raspberry Pi, which provides the majority of
larly proud you released it? the I/O capabilities for the Raspberry Pi 5.] So that’s an
JF: In the early 2010s, when you were working on Eben: If you accept my suggestion that we want to do
the first Raspberry Pi, one of the main goals was to a good job for AI workloads, but can’t tax non-AI-cen-
promote the study of computer science, get people tric users with dedicated acceleration hardware, I
to roll up their sleeves and program, and understand think there are two natural consequences for system
how it works. Now there are tools such as ChatGPT design: We end up adding a lot of CPU performance,
that can generate code for you, which mostly works if so low-to-mid-end inference workloads can be run on
it’s given some guidance. Do you think that this kind the CPU (we deliver this with our quad-2.4 GHz A76s on
of tool can make people more and more intellectually Raspberry Pi 5, and our dual 133 MHz M0+s on RP2040
lazy? How do you feel about these tools? for TinyML), and fast interfacing to talk to accelerators
for high-end workloads (USB 3 on Raspberry Pi 4 and
Eben: I’m not sure I agree that ChatGPT can currently 5, PCIe on Raspberry Pi 5).
generate production-quality code even with “some
guidance.” But, in any case, I don’t think they make JF: Just after the Raspberry Pi 5 launch, many press
people lazy or put people out of work: We’ve been articles were published about the differences between
designing tools (assemblers, compilers, higher-level the 4 and the 5. Personally, what is your favorite new
languages) that have increased productivity since feature?
the dawn of the computer age in the 1940s, and they
mostly have the effect of increasing demand for Eben: Honestly, the performance. As I say, it’s the first
computer programmers (see Jevon’s Paradox)! The Raspberry Pi that I sit down in front of and find myself
term for carefully asking ChatGPT to write you some forgetting that I’m not using a legacy Intel PC.
Python is “computer programming:” it’s just program-
ming in a different — and, unfortunately, less precise JF: Now that Bloomberg has broken the news about
— language. the possible initial public offering, and Raspberry Pi
shares being sold to investors, some hobbyists and
JF: In the 1980s, many young enthusiasts cut their makers have been sharing concerns on Reddit, X
teeth on programming with BASIC on systems such as (formerly Twitter), etc. Will you be able to maintain
the BBC Micro. Today, Raspberry Pi champions Python your community-focused ethos in the face of pressures
as the go-to language for beginners. How do you think that come with being a publicly traded company?
this shift in starting languages influences the learn-
ing experience and approach for young programmers Eben: It’s early days in our exploration of the possi-
today? bility of an IPO, but I’m certain we could. You have to
remember we’re already highly incentivized to make
Eben: I think it’s very motivational for young program- great, cost-effective products (because we’re geeks,
mers to be given a language that combines the low and want to make the products we want to buy), and
barrier to entry of BASIC with the high ceiling of a to make money (because the profits from Trading fund
“proper” programming language. Any time you ask the Foundation, which we care deeply about). So, our
someone to change, between computers, or between incentives wouldn’t change post-IPO, and I struggle
languages, there’s always a chance they just say “no,” to see why our behavior would.
and stop. So getting students to use Python, which is a
very beginner-friendly language, and telling them that
they are writing “hello world” in the same language
that professional engineers use to build enterprise
en in
software is very valuable.
Elektor caught up with Ebpte mber
JF: You mentioned in the past that it was difficult
Cambridge, UK, back in Se Eb had
en
of 2023. Check out what erview.
to say during that int
to integrate hardware-based AI in any Raspberry
_gf2M
https://youtu.be/YkXCUW
products, because it’s expensive, and doing so
would have taxed users who don’t need it in favor of
a certain percentage of people who will maybe use it.
Anyway, AI often needs beefy GPUs in order to make
[email protected]
May & June 2024 115
Full speed ahead
Trust the new product introduction leader™
to move from concept to prototype at lightspeed
mouser.com/new