Arduino Compilation
Arduino Compilation
ARDUINO COMPILATION
ALL ARTICLES FROM ELEKTOR ● 233 PAGES
N ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ●
ARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ●
EARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ●
GN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ●
HARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ● LEARN ● DESIGN ● SHARE ●
Arduino Software
Development
with Atmel Studio
By Wolfram Pioch
(Germany)
Debugging applications on the Arduino Due
3
46 | December 2014 | www.elektor-magazine.com
Arduino compatibility
The procedure described here assumes you have
Atmel Studio 6.2 (or later) installed under Win-
dows. To make the Atmel IDE compatible with
Figure 3.
Arduino, you also have to install a free add-in
The Micro Explorer window
called Visual Micro [2], which is an Arduino IDE
of Visual Micro.
for Microsoft’s Visual Studio and Atmel Studio.
Visual Micro is directly available in Atmel Studio tion Explorer window in Atmel Studio. There the
after it has been installed. Arduino references are shown as links on the
Reference tab. A click on one of the entries takes
The USB-based Arduino debugger available from you to the corresponding website in the config-
[2], which is not free, is not necessary because ured browser. The Examples tab holds a list of
debugging with the Atmel ICE is significantly more examples (including library examples) from the
convenient. The latter tool is available in vari- Arduino IDE, grouped by topic.
ous webstores at prices in the 100 dollar range
(see the review in the October 2014 issue of Sketches in Atmel Studio
Elektor [3]). The expenditure is worthwhile if A major benefit of the Atmel Studio IDE is the
you use Atmel microcontrollers more than just code completion function, which you now have
occasionally. available for Arduino sketches as well. For this
With this debugger you can set real breakpoints you have to enable Visual Assist X via VAssistX
without recompiling the program, observe vari- Enable/Disable. With this enabled, all possi-
ables in the Watch window, and examine or ble completion options are listed each time you
Figure 4.
change memory contents. What’s more, you can type a character in the Code window. For exam-
The Atmel Studio editor
inspect the numerous I/O registers and alter them ple, if you type “S” at the start of a new line in
helps you avoid typos
with a mouse click. a sketch, the terms Serial, Server, SPI and so on
by suggesting function
After you install Visual Micro, a new toolbar are suggested. You can then select the appro- names and options for
appears in Atmel Studio. On this toolbar you priate term directly, with no risk of typos. Even autocompletion.
can select the current Arduino version (1.5.x), better, after you type a dot, for example after the
the board (Arduino Due) and the programming term “Serial”, the existing attributes and methods
interface (programming port) as illustrated in of this class are listed for selection (Figure 4).
Figure 1. After this you have to configure the
appropriate virtual serial interface, which you At this point you could create or open a sketch
can find by looking in the Device Manager win- in the Arduino IDE in the usual manner and then
dow when the Arduino Due is connected to the import it into Atmel Studio. However, you now
PC with a USB cable. As in the Arduino IDE, the
serial monitor button is located to the right of
these settings. Adapter for SAM ICE +3V3
If the settings do not appear automatically, for This adapter is necessary for using
JTAG
example because the Arduino IDE software is the SAM ICE debugger/programmer SAM-ICE
2 1
not located in the default directory, you have to with the Arduino Due. 4 3
+3V3
window shown in Figure 2. There you have to It connects the 10-pin JTAG 10 9 2 1
12 11 JTAG_TCK 4 3
enter the correct folder location manually, since pinheader with 50 mil (0.05”; 14 13 JTAG_TDO 6 5
16 15 JTAG_RESET 8 7
no selection dialog is available. 1.27 mm) pin pitch on the Due board 18 17 10 9
20 19
Clicking the question mark on the menu bar in to the 20-pin JTAG connector on the
Figure 1 opens the Micro Explorer window (Fig- SAM ICE device. 130392 - 66
4
www.elektor-magazine.com | December 2014 | 47
5
48 | December 2014 | www.elektor-magazine.com
Arduino IDE, a copy of this file is also located in The actual structure of the downloaded Arduino
the debug folder for the sketch. It can be seen program can be seen in the Solution Explorer win-
in the Solution Explorer window of the code gen- dow, where the main.ccp file is selected and the
eration instance of Atmel Studio under “Output cursor is positioned on the first line of this routine
Files” (Figure 8).
6
www.elektor-magazine.com | December 2014 | 49
SpeedTest
Only the following two instructions are executed
in the main loop of the example sketch (see the
SpeedTest listing):
digitalWrite(TP1,1); //On
digitalWrite(TP1,0); //Off
Figure 14.
Microcontroller PIO register. With an oscilloscope, you can see a pulse wave-
form on this pin while the program is running,
with a pulsewidth of 2.35 µs and a period of
6.6 µs (Figure 13), which corresponds to a fre-
quency of about 150 kHz. That is not very high,
and you could hardly be blamed for thinking that
there’s no reason to use an ARM controller clocked
at 84 MHz for this when a simple 8-bit AVR micro-
controller can do it better.
7
50 | December 2014 | www.elektor-magazine.com
Listing 1. Speed-Test.
//*******************************
//Speed-Test with Arduino Due
//*******************************
void setup()
{
/* add setup code here */
// set the digital pin as output:
pinMode(TP1, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(TP1,1); //On
digitalWrite(TP1,0); //Aus
}
8
www.elektor-magazine.com | December 2014 | 51
#else
digitalWrite(TP1,1);
digitalWrite(TP1,0);
#endif
}
9
52 | December 2014 | www.elektor-magazine.com
C Modules
Software for Elektor Extension Shield,
Relay Board and more
By Jens Nickel (Elektor Germany)
10
56 | November 2014 | www.elektor-magazine.com
11
www.elektor-magazine.com | November 2014 | 57
RELAIS
ing to the Arduino-Uno board has the name
ARDUINO BoardEFL_ArduinoUnoCore.
#0
RS485
#2 #2 #3 #3
• We can now use several extension boards in
our project, since each of the corresponding
code files has a different name, for example:
#1
ExtensionEFL_Arduino_
SHIELD
ElektorExtensionShield.c/.h
140328 - 17 ExtensionEFL_ECC_RS-485.c/.h
ExtensionEFL_EEC_Relay8.c/.h
12
58 | November 2014 | www.elektor-magazine.com
Short code
The application itself can be viewed in Listing 1. CONN#1
ADC#0
13
www.elektor-magazine.com | November 2014 | 59
BlockEFL files
Up till now BoardEFL and ExtensionEFL files have still included the so-called Low Level/Block Functions, such as for example
the Function
COMMON
independent of which particular route the bytes take to reach
the Display. This Block Function must be defined once in the BOARD BLOCK BLOCK BLOCK
DISPLAY IO UART
project if a Display is provided on any of the boards. HARDWARE
LAYER
Logically we therefore provide a dedicated file pair in the CONTROLLER
Hardware folder for the Low Level/Block Functions required
by the Display. If a Display is used anywhere in a project, HARDWARE
you need to integrate BlockEFL_Display.h/.c in addition. A 140328 - 14
Figure 5.
You can display the EFL Tables using a Terminal program.
The Blocks are set out centrally.
14
60 | November 2014 | www.elektor-magazine.com
15
www.elektor-magazine.com | November 2014 | 61
Virtualization
Port expanders and external A-to-D converters are two The concept of ‘Virtualization’ is now broadened to analog
sample applications for chips that extend the capabilities of inputs. In our case the external ADC is located on the
a Controller. Frequently these chips are addressed via an EEC/Gnublin ADC Expansion board, so the code in file
I2C Bus or some other serial interface. ExtensionEFL_EEC_ADCModule16bit.c must take over
the activation of its ADC. When the board is initialized with
A modular prototyping library should, as far as possible, the Function ExtensionEFL_EEC_ADCModule16bit_Init(…)
be based on the hardware used. For someone developing the external ADC is integrated into the EFL Tables like
an application (or a Library that activates Peripherals) an internal ADC (in our case with the Block number #1),
it should be immaterial how the wiring tracks run on where, however, it is assigned to the virtual Port 0x40. In
the board or to which Controller pins the Peripheral is addition the I2C interface is made ready. Furthermore the
connected. Ideally the developer should also not need to Function Virtual_ADC_GetValue(…) is notified to the
know whether an input or output is connected to a genuine Controller code.
Controller pin or merely to a Port expansion chip. We
can solve that problem by assigning to the Controller in Using the Function ADCSimple_GetRawValue(uint8
addition to its Ports 0, 1, … etc. some extra ‘virtual’ Ports ADCBlockNumber, uint8 ADCPosition) users now have
that begin with the number 0x40 = 64, so as to be able to access to an ADC pin in a specific ADC Block, independent
differentiate these from ‘real’ Ports. of the connection to the Controller. The Function directly
If for example you wish to activate a relay connected to a calls up the Controller Function ADC_GetValue(…). The
Port expansion device, then access to the relay from the Controller refers to the EFL Tables and on account of the
RelayEFL Library will be forwarded perfectly normally to high Port number recognizes that an internal ADC is not
the Function SwitchDigitalOutput(…), located in the file intended but instead it should call up the Function Virtual_
BlockEFL_IO.c. This Function refers in the EFL Tables which ADC_GetValue(…), located in the code file of the Expansion
Controller Port and pin the relay belongs and calls up the board. This results in giving access to the external ADC over
Function IO_SetPinLevel(…) in the Controller file. In the I2C.
Tables a Port 0x50 is recorded for the relay and normally
this would be the end of it, as the Controller is unaware As well as the Function ADC_GetValue(…) our application
of any Port 0x50. However, for such situations when the also virtualizes the Function ADC_GetParameter(…), with
relay board is initialized, a special Function of the relay which the resolution and voltage range of an ADC can
board code is passed to the Controller code that is called be read off. In this way ADC values can be calculated in
up in cases like this. This same Function then sends the millivolts.
corresponding I2C commands to set the output pins of the
Port expansion unit located on the board.
DISP#0
ADC#0
Figure 7.
CONN#1
Internal and external ADCs can be addressed using the
SHIELD 140328 - 13 same Functions, with the Block numbers #0 and #1 used
for differentiation.
16
62 | November 2014 | www.elektor-magazine.com
17
www.elektor-magazine.com | November 2014 | 63
It had always fascinated me what I might hear—or ten in Europe where the AC supply frequency is
rather see on an oscilloscope—if I could connect 50 Hz but exactly the same methods will work
a pick-up coil, with a couple of hundred turns on in territories where the line frequency is 60 Hz.
it, to an extremely sensitive amplifier. A dozen Please read ‘60’ wherever you see ‘50’ from now
or so years ago I decided to turn this supposition on, if you live in a 60 Hz country. Ed.]
into fact using modern electronics. Eventually, after I submitted my received data to
The first circuit I constructed for this purpose FFT-versus-Time analysis, it became very clear to
differed from the version presented here only me that that this ‘wriggling about’ on the screen
by having a cruder filter and a somewhat old- was the result of recurring signals of typical struc-
er-fashioned method of analog to digital con- tures, which could be resolved only if they could
version. To my surprise there appeared on the be compressed over prolonged periods of time.
monitor screen more than the power frequency They were also audible if played back at higher
hum that I was expecting but unfortunately the speed, sometimes reminiscent of animal sounds
confused serrations of the complex time signals or teletype transmissions on the short waves. In
did not allow me to draw any conclusions from any case, all this was sufficiently interesting to
about their composition. [this article was writ- keep me occupied with it ever since. Readers who
18
8 | October 2014 | www.elektor-magazine.com
are interested will find further detailed informa- be connected to other recording devices, all the
tion at the blog vlf.it [3], which is a platform for time keeping in mind that signals below 16 Hz
enthusiasts involved with receiving and experi- will be attenuated heavily by PC sound cards.
menting in the ELF and VLF bands. I have pub- The circuit is made up from a combination of a
lished a number of articles there on this theme highly sensitive voltage amplifier and a steep
along with many screen shots. (36 dB per octave) Sallen Key low-pass filter with
Among other things, we need to understand that a cut-off frequency of approximately 21 Hz. The
supply transformers in residential areas radiate receiver has the task of amplifying extremely
extremely weak magnetic waves between around weak magnetic waves in the frequency range
0.3 Hz and 25 Hz. These are up to 1,000 times from 21 Hz down to (almost) 0 Hz and filtering
weaker than the interference fields produced by out line hum interference in the process. Figure 1
the 50 Hz AC supply. To receive the desired fre- shows the schematic for this receiver, which is
quencies without interference, we need to filter made up from the functional groups that follow.
out the 50 Hz (60 Hz) supply hum as early as
possible ahead of the main amplifier in order to Linearizer and preamp
avoid over-driving the receiver. The extremely weak (in the microvolt region) AC
signals of interest here are picked up with a coil
The circuit and once processed and optimized in a combi-
The receiver described here operates in conjunc- nation of preamplifier and low-pass filter (IC1),
tion with the ADC module described in a separate they are directed to the Sallen Key low-pass filter
article, an Arduino Uno and some free—that goes that follows. This simple upstream low-pass filter
without saying—recorder software for the PC. This (a pre-filter so to speak) is necessary specifically
combination makes it possible to detect, display for attenuating any 50 Hz line frequency interfer- Figure 1.
and log weak alternating currents and/or alter- ence in relation to the wanted signal to prevent Schematic of the ELF
nating magnetic fields at frequencies down to less overloading that might generate a square-wave Receiver (without Data
than 1 Hertz. The receiver output can additionally signal between the maximum output voltages Logger).
R7
56k K2(S1)
1 2
R6
C1 3 4
120k TP1
5 6
R5 IC3 = TL074
10n 390k
R2 C6
10M R4 C4
9
470k C2 1u TP2
K1 6 8
IC1
8
6 2 1 5
OP07 10k R8 R9 IC3A 18k 220k
1
3 6 3
Coil OP07 22k 180k C7 TP3
3 C5
C3 22n
47n
68n
IC4
IFX25001TS V50 +5V
S2 L1 L2 +12V R16 P1
1 3
47k
100u 1 6 100u
+VIN +VOUT C22 C20 C18 1M
C8 C9 R15
13 K3
2
2 4 0Ω6
-VIN -VOUT 10u 100n 47u 900mA
63V L3 25V
100u -12V
+12V +12V +12V +5V
R17
C10 C12 C14
1k5
7 7 4
100n 100n 100n
IC1 IC2 IC3 D1
C11 C13 C15
4 4 11
19
www.elektor-magazine.com | October 2014 | 9
of the op-amp. This could occur were the coil The stage built around IC2 is a well-known ‘stan-
to be placed close to a power cable in which a dard’ circuit involving an inverting amplifier. The
heavy current was flowing. The circuitry associ- gain factor can be varied by selecting one of sev-
ated with IC1 has a second function: the char- eral feedback resistors. This feature is absolutely
acteristics of the coil at the input of the circuit necessary since completely different intensities
mean that low frequencies are attenuated appre- of the received signal may arise, according to
ciably, so that the amplitude of received signals the position of the receiver. R4 is not a built-in
in the region of zero Hz is weakened increasingly. part of the selector switch, ensuring that there is
We can compensate or ‘linearize’ this to a large always some degree of negative feedback, even
extent using the effect of capacitor C1 in paral- when the switch settings are open-circuit. This
lel with R2. Figure 2 shows the amplification at has the advantage that at the moment of swi-
the output of IC1. tchover, when the switch contact ‘hangs in mid-
air’ for a very brief timespan, no interference
pulses appear on the receiver output.
The gain or amplification of the inverting ampli-
Audio Precision
+24 fier arises from the quotient negative feedback
+23
resistance divided by the upstream resistor:
+22
+21
+20
V = Rg/Rv
d +19
B
r +18
+15
-40
50 Hz signal relative to the desired signal makes
d
B
-50 this filter extremely necessary, to prevent over-
r -60
A -70
loads. To learn more about Sallen Key Filters you
-80
can find the desired background information in
-90
-120
Figure 3. -130
stated, 21.5 Hz, which is far enough removed
10 20 50 100 200 500 1k
Filter IC3 achieves a slope of Hz 140035 - 55
-10
-20
-30
anteed. Figure 3 shows how steep the flanks of
-40
the resulting filter are (measured at the output
-50
d
-60 of IC3C).
B -70
r
-80
A
-90
-100
High-pass and final stage
-110 At high levels of gain (according to the setting
-120
-150
quite small offset voltages could nevertheless
6 10 20 50 100 200 500 1k 2k
reduces interfering noise by Hz 140035 - 56 be sufficiently large to shift the output signal by
up to 40 dB. several volts into the positive or negative regions
20
10 | October 2014 | www.elektor-magazine.com
21
www.elektor-magazine.com | October 2014 | 11
Installation and
operation of the recorder
Now connect the ELF receiver to the 16-bit Data-
logger module described in the September 2014
edition of Elektor [13]. The ADC samples the
signal with a resolution of 15 bits and a sampling
rate of around 112 Hz. The article also explains
how the ADC module can be connected to an
Arduino Uno, which accepts the digitized data
using a simple program (Sketch) and relays this
to the PC and the recording software.
The recorder software is written in the Processing
programming language [12], which resembles
C. Curly brackets are used for code blocks; each
instruction must be closed off with a semicolon.
The programming environment is very simple:
just open the Editor and write the source text.
Then click on the Start button and you’re rolling.
22
12 | October 2014 | www.elektor-magazine.com
What is ELF?
ELF signals are a mysterious and, to some
degree, myth-ridden subject that amounts in
reality to nothing more than electromagnet-
ic waves of extremely low frequency (hence
ELF) from 3 Hz to 30 Hz. Because commercial
radio transmissions do not exploit such low
frequencies, it is naturally fascinating to inves-
tigate what is going on in this profound realm.
Wow! This signal occurred on one single occasion
over a night in September 2013. Duration around
In residential areas many of the signals de-
one hour. Recording made with electrodes. Frequency
tectable with the receiver described here
range: 0 to 20 Hz.
clearly take the form of magnetic waves ra-
diated by supply transformers at the local
substation. The sprawling network of metallic
conductors (ground connections, water and
gas pipes, etc.) evidently behave like a vast
underground antenna that gathers up the
weakest low-frequency alternating currents
flowing in the ground, wherever they may
arise from, and transports them to a common
connection point at the local substation. Here
A square-wave signal of 1.6 Hz, which arises in
(this is merely an assumption) these currents various locations across all Europe at irregular times.
are radiated as magnetic fields by the ground- Typical characteristics: phases of activity and intervals
ed Petersen Coil (used for ground/earth leak- changing regularly.
age compensation).
23
www.elektor-magazine.com | October 2014 | 13
Operation
Operation of the software recorder in the Win-
Figure 8.
dows-style window (Figure 9) is virtually self-ex-
Power section and filter/
planatory. The test results are shown in three
amplifier should be placed
windows on the left-hand side.
as far apart as possible from
one another. Inductance L4
is fitted in between them Time signal
(here on the underside of An iteration takes five seconds. After the program
the PCB). starts a signal is always visible here, even if it is
not being recorded—and after recording stops.
Software installation
To get a Processing program to run on your com- FFT vs. Time
puter, you need to download the necessary soft- Every x seconds (x depending on the value set
ware from the Internet onto your machine. when downsampling) a new line is plotted—even
Go to the Processing website [7] and follow the if no recoding is being made—and after record-
instructions given there. The data downloaded ing stops.
can go into any folder you choose on the hard
disk. Within this data is also a file with the name Supervisory signal
processing.exe. Run this program if you want to After each iteration of 5 seconds, the highest
write Processing software of your own. Numerous amplitude of this time segment is indicated in
impressive sample programs not only showcase the upper window.
the powerful capability of this language but also
indicate how you can make the best use of it. The parameters for measurement and display
The Recorder program written in Processing can are set on the right-hand side of the recorder:
be downloaded from the Elektor website [8] into
any folder of your choice. Recording time
Length of the recording.
Important: The Processing program must be
located in a sub-folder bearing the same name Downsampling
as the program itself—but without the ‘.pde’ suf- Zoom in the Y direction in order to see the lower
fix. Also all resources required by the program frequencies better. Relates only to the FFT dis-
(such as .wav files or associated graphics) must played and not to the recording.
be kept in this sub-folder. After double-clicking
on the recorder file (Recorder_.....pde) the Pro- FFT brightness
cessing editor window opens automatically and Renders the FFT displayed brighter or darker.
the program code is implemented. Relates only to the FFT displayed and not to the
In the following line you need to replace ‘COM3’ recording.
and enter the COM interface of the PC allocated
by Arduino (see Device Manager in Windows): FFT scrolling
Pages forwards and backwards through the
serport = new Serial(this, “COM3”, 115200); analysis data displayed. Valid only for the data
recorded during the current recording phase still
Then save the program code with File Save. held in RAM. FFT data is not stored on the hard
After a (single) click on the arrow at top-left in disk.
the Editor window, the program begins. The Editor
window with the source code remains during this Mouse position
process on the screen (in the background). Unfor- Mouse position coordinates and number of but-
tunately (and not for want of searching count- tons clicked. Very important if you wish to work
less different sources) I have not managed to on the program yourself.
find a working .exe file for the program. Further
information about Processing can be found in the Recording
Editor itself (Help Reference) and on countless Left-hand button
other Internet pages. Normal method of starting a recording of a dura-
24
14 | October 2014 | www.elektor-magazine.com
Web Links
[1] Online ELF blog: www.vlf.it
[2] https://en.wikipedia.org/wiki/Sallen%E2%80%93Key_topology
[3] Coiled wire: http://www.jameco.com/1/1/379-30pe-awg-plain-enamel-magnet-wire-1-4-lb-825-ft.html [USA],
http://www.scientificwire.com/acatalog/Solderable_Enamelled_Copper_Wire.html Ref: SX0250s-D200 [UK].
Alternatively just look on eBay.
[4] Input transformer: http://www.jensen-transformers.com/ln_in.html
[5] http://blackboard.serverpool.org/
[6] www.elektor-labs.com/project/arduino-16-bit-low-frequency-datalogger-130485-i-140035-i.13703.html
[7] http://processing.org/
[8] www.elektor-magazine.com/140035
[9] https://groups.yahoo.com/neo/groups/VLF_Group/info
[10] http://naturalradiolab.com/
[11] http://en.wikipedia.org/wiki/Schumann_resonances
[12] http://en.wikipedia.org/wiki/Processing_(programming_language)
[13] www.elektor-magazine.com/130485
25
www.elektor-magazine.com | October 2014 | 15
This project is a good example of where our Hunting for ELF signals
web-based project platform Elektor.Labs [1] has At Elektor.Labs you can read more details of the
provided the spark for new ideas. Kurt Diedrich, original project [2]: The ELF signal picked up by
an author well known to us, has recently been the large wire loop is first amplified, filtered and
busy experimenting with an Arduino Uno to then given a DC offset of 2.5 V so that the signal
expand his knowledge of microcontroller firm- swings between 0 and 5 V and does not go nega-
ware. It didn’t take too much encouragement tive. The Arduino Uno uses an ATmega328 which
to persuade Kurt to share his experiences with already has a built-in A/D converter but with only
a wider audience via Elektor.Labs. One of the 10-bit resolution. Kurt Diedrich did some research
designs he came up with is a data logger where and ended up ordering a small PCB from Ada-
an Arduino Uno measures a signal level and fruit which has on-board an ADS1115 (from TI).
sends it to a PC [2]. Kurt’s previous experience
with PC programming and graphical user inter- This particular A/D converter has four input chan-
face design could now be put to good use: using nels and can measure signals with 16-bit reso-
the programming language called Processing lution [3]. An I2C bus is used for control and to
he designed a Tool that not only represents the pass information between the chip and microcon-
sampled signal but can also performs spectral troller. It wasn’t long before Kurt was studying
analysis. The complete setup is ideally suited the Arduino code examples and software libraries
for processing the reception of low-frequency supplied by Adafruit. The routines he needed to
electromagnetic signals to be discussed in a implement are not complex; after a little tin-
follow up article describing an ELF Receiver kering with the code examples the data logger
(ELF = extremely low frequency). firmware was finished. An endless loop in the
26
40 | September 2014 | www.elektor-magazine.com
The concept
The prototype worked really well but the fin- USB
ished set up looked a bit untidy with all those
flying leads between the ADC module and Arduino
board. Labs set about making improvements; the 130485 - 12
main decision was to not make the design into a
dedicated ADS1115 Arduino shield but instead
opt for a more flexible approach that would allow
the board to easily interface to a number of dif-
ferent systems [4]. C1
+3V3
47p
R2 ALERT/RDY POWER
100k
The ADS1115 chip should derive its power from D1 D2
R1
the attached controller board and be controlled 4
100k
REF2912 1
via an I2C bus. A good choice for the interface +3V3 AIDBZT R3 IC2
3 1V022
120k R8 R9 R10
would be the 14-way pin header used by the EEC/ 1 5
IC3 2 0V511 OPA377
C4
560R
C3 C2 R4 R5 T1
nected via a length of flatcable to the Elektor-Li-
270k
120k
AIN0 7 8 K3
VDD
AIN1 4 1 EEC/Gnublin
AIN0 ADDR
Voltages 5
AIN1 ALERT/RDY
2 1 2
6 9 3 4
The ADC board circuit diagram is shown in Fig- 7
AIN2 SDA
10 5 6
K2 AIN3 SCL
ure 2. The Gnublin/EEC connector used by the R6 R7 7 8
GND
AIN2 9 10
board specifies a 3.3 V supply voltage but the ADC
2k2
2k2
AIN3 ADS1115 11 12
3
chip can operate with a supply range between IDGST JP2 JP3 13 14
2.0 and 5.5 V.
+3V3
130485 - 11
27
www.elektor-magazine.com | September | 41
VDD
ADS1115 Comparator
Voltage
Reference ALERT/RDY
AIN0
AIN1 ADDR
AIN2 16-Bit 2
MUX PGA IC SCL
AIN3 ADC Interface
SDA
Figure 3. Oscillator
The data sheet [3] gives details of how the chip diodes on the inputs which provide some degree
can be controlled and configured using I2C com- of protection but the data sheet recommends fit-
mands. It can be configured to measure: ting external zener diodes and series resistors to
give better protection.
• The voltage level on AIN0, AIN1, AIN2
and AIN3 relative to ground (i.e. four ‘sin- Jumper JP1 can be fitted to provide a 1.022-V
gle-ended’ inputs). offset. The voltage level is made up of the 1.25-V
• The voltage level on AIN0 relative to AIN1 reference voltage level produced by IC3 and the
and the voltage level on AIN2 relative to standard op-amp IC2. When the offset is applied
AIN3 (two differential inputs). the input voltage range is ±2.048 V. An AC input
• The voltage level on AIN0 relative to AIN3 signal swinging between the values of around
and from AIN1 relative to AIN3 (two differ- –1 V and +1 V will be translated into a voltage
ential inputs with a common node). at the ADC input AIN0 swinging between 0 to 2 V
with 15-bit resolution. In the software be aware
The chip outputs a digital value in the range that higher input voltages produce lower output
from –32768 to 32767; negative values indicate values (inversion).
a negative differential voltage (negative values
are expressed in twos-complement format). In Another possibility is to add the offset to AIN0 and
single-ended mode the voltage will always be use the tip described above. With the measured
positive so that the output values will be in the voltage applied to AIN1 or AIN3, the correspond-
range 0 to 32767 which corresponds to a 15-bit ing differential mode configured and a full-scale
resolution. Using a workaround suggested by Ton range of ±1.024 V set. This method makes it
Giesberts in our lab and described in more detail possible to measure a voltage in the range from
on the .Labs Website [8] it allows measurement 0 to 2 V with a 16 bit resolution.
of negative-going signals while producing a 16-bit
value: Apply a fixed DC voltage, say 1 V on input Timing
AIN3. Now an input voltage of 0 to 1 V on the The ADC operates using the Delta-Sigma princi-
inputs AIN0 and AIN1 produces a negative out- ple, which gives good resolution and accuracy.
put value when the corresponding differential This method of A-D conversion however is not the
mode is selected. fastest. A rate of up to 860 samples/s is possible.
The sample rate is configurable and has a default
In addition to an internal voltage reference the value of 128 samples/s. Like many other ADCs
ADC also has a built-in programmable amplifier the ADS1115 can work in single-shot or contin-
which allows you to setup the full scale voltage uous mode. In single-shot mode it is necessary
range that the ADC will measure. In our case, with to issue a command to the chip to tell it to mea-
a 3.3 V operating voltage, the ranges ±2.048 V, sure the input voltage. Once the measurement
±1.024 V, ±512 mV and ±256 mV are of interest. is complete and a valid digital value is available
With this board it is important to ensure the the chip will set a bit in one of its internal regis-
measured input voltage does not go above 3.6 V ters. The external microcontroller monitors the
or below –0.3 V. The chip uses integrated ESD state of this bit and reads the new value from an
28
42 | September 2014 | www.elektor-magazine.com
internal register when it becomes available. It can the role of a slave. Using just write operations you
then go on to request a new measurement. In can, for example set up an internal configuration
continuous mode the chip continually measures registers or tell the chip to start a measurement
the input voltage and produces digital values process. In order to read out a digital value we
without the need for any external intervention. need to both write and read over the I2C bus.
In all our programs including the ELF receiver To be precise you need to write twice (which
application we use single-shot mode in a contin- includes the slave address) and then read once.
uous loop. After each new reading (and before The chip’s slave address can be set-up externally
issuing the next sample command) the value is so it allows more than one ADS1115 chip to be
processed in the microcontroller (e.g. to show connected to the same two bus wires (provided
on the display or send over the serial interface). you use different addresses for each chip). The
Using the default sample rate of 128 samples/s slave address is defined by how pin 1 is con-
produces a data rate of about 100 to 120 Hz nected. There are four possible slave addresses
which should be sufficient for the majority of available; pin 1 can be linked to either pin 3, 8,
data logger applications. 9 or 10 using a jumper on the header pins of JP4
to define the address.
The comparator
The Conversion-Ready-Pin (IC1 pin 2) can be The two I2C signals are connected from the
used to indicate when an A-D conversion has chip to pins 5 and 6 of the EEC/Gnublin connec-
been completed. The ADS1115 can also be con- tor. Jumpers JP2 and JP3 allow you to use the
figured to act as a comparator (Figure 3) and on-board pull-up resistors. The beauty of the
in this mode the pin acts as an alert output. I2C bus is that you can safely interface a slave
Now using values stored in the Low Threshold device operating at 3.3 V with a controller such
and High Threshold registers you can allow a as an Arduino Uno running at 5 V.
sort-of hysteresis or apply a voltage compari-
son window to the measured value so that an The software library
alert occurs only if the measured value is outside When it comes to the control software you know
these stored values. that even if you opt for the default settings of
In our module this output is made visible via the ADC you will still need to spend some time
transistor T1 and a yellow LED. In addition this studying its data sheet. Controlling a microcon-
signal is routed to pin 11 of the Gnublin/EEC con- troller’s I2C interface can also sometimes be a
nector K3 where it is available for use by either bit tricky. Don’t worry; we have simple solutions
the Linux- or Xmega-board but has no connection that should get around these potential problems.
on the Elektor extension shield. The technical boss at the Elektor Labs Clemens
Valens has written a C library that avoids the need
I2C to define which registers you need to address in
As we already mentioned communication with the the ADC and instead provides high level func-
ADC occurs over an I2C interface where it plays tions to control the chip. As a bonus he has also
Web Links
[1] www.elektor-labs.com
[2] www.elektor-labs.com/project/arduino-16-bit-low-frequency-datalogger-130485-i-140035-i.13703.html
[3] www.ti.com/lit/ds/symlink/ads1115.pdf
[4] www.elektor-magazine.com/130485
[5] www.elektor-magazine.com/130214
[6] www.elektor-magazine.com/120126
[7] www.elektor-magazine.com/140009
[8] www.elektor-labs.com/contribution/from-the-lab-using-differential-mode.14034.html
[9] www.elektor-magazine.com/120668
29
www.elektor-magazine.com | September | 43
ADS1x1x_start_conversion(&my_adc);
and
are available.
void soft_i2c_scl_write(uint8_t value) // write high or low state to the SCL pin
void soft_i2c_sda_write(uint8_t value) // write high or low state to the SDA pin
void soft_i2c_sda_mode(uint8_t value) // configure SDA pin as O/P (value=1) or I/P (value=0)
Five further functions bind the ADC library (from you will find more demo programs and interesting
Clemens) with the I2C software library, this code applications which make use of the Embedded
can just be dropped 1:1 into the project. Firmware Library [9].
30
44 | September 2014 | www.elektor-magazine.com
Our Arduino sketch performs the same software It is probably easiest to upload the sketch using
function as Kurt Diedrich’s original project: An the Arduino bootloader, that way you only need
endless loop repeatedly tells the ADC chip to a USB cable between the Arduino and PC. Once
measure and digitize the voltage at input AIN0 in the firmware has been flashed the measured val-
single-ended and single-shot mode. The measure- ues can be seen on the serial monitor display
ment range extends from –2.048 V to 2.048 V, in the Arduino development environment or via
while in Single-ended mode only 0 to 2048 mV a simple terminal emulator program (data rate
can be measured and with only 15-bit resolu- set to 115,200 Baud and the corresponding COM
tion. The decimal output values (0 to 32767) port selected).
after conversion are sent out as ASCII characters To achieve the highest measurement accuracy
over the serial interface, followed by a <CR> and it is better to power the Arduino from a bench
<LF> character. power supply rather than from a USB port. It
will provide much better common-mode noise
For testing we used an Arduino Uno fitted with performance.
the Elektor extension shield described in the
last issue [7] connected to the ADC board via a Some spooky signals
14-way ribbon cable. The I2C address of the ADC If you like you can now try out the recorder soft-
board is configured as ‘ground’ i.e. the jumper ware that Kurt Diedrich developed for a his ELF
is placed in the first position of JP4 nearest the reception experiments. Now when you turn the
Gnublin/EEC connector. Initially we will not use pot the values are recorded over time in soft-
any offset correction (JP1 jumper fitted nearest ware. You can also switch in the 1022 mV offset
the terminal blocks). and see how the measured values change. Volt-
Now to generate the voltage to measure we con- age levels in the range of approximately –1 V to
nect a flying lead from the Arduino pin A3 (you +1 V can be measured with 15-bit resolution,
can connect it at the shield box header connec- this set up can be put to good use investigating
tor as shown in Figure 4) to the AIN0 input the presence of ELF signals in your location. If
of the ADC board. The voltage on A3 can now this sounds interesting have a look at the ‘ELF
be adjusted by twiddling the pot on the shield; Receiver’ project described in this issue you may
this gives us a rudimentary test set-up to check be in for some surprises!
operation of the ADC board. The voltage at A3 (130485)
can be turned up to 5 V but it’s important that
the input voltage level does not exceed 3.6 V so
before connection ensure that the pot is turned
all the way down so that the voltage is at 0 V
then slowly increase it.
31
www.elektor-magazine.com | September | 45
Arduino is a Tool
By Clemens Valens Barring you just woke up from a 10-year long coma you will have heard about
(Elektor.Labs) Arduino. Everybody is talking about Arduino and all & sundry are developing
programs (“sketches”) and extension boards (“shields”) for Arduino. We have
filled scores of pages in Elektor about, or on using Arduino. Here is another one.
to the Arduino
board to make
the serial port
MIDI compatible
(the Data signal
has to be inverted)
and connected it to the
device-under-test (DUT).
This article however is slightly different because We c o u l d h ave d o n e
it is not about an Arduino project but about without the transistor if we
using Arduino as a tool. I use Arduino quite had used a software serial
often because it is so easy to program and use. port on the Arduino, but it would have meant
I sometimes even use it as a calculator because more testing.
it is quicker to write an Arduino program (called
a ‘sketch’) than a PC application. With the tester ready all we had to do was power
up everything, lean back and watch everything
To give you an example, the other day at Elektor. work just fine. This to me shows the real power
Labs we had to test our prototype of the MIDI of Arduino: an easy-to-use multi-purpose tool
Channel Analyzer [1]. Hedwig our secretary had that can help you out in many prototyping and
brought a nice keyboard with MIDI capabilities test situations.
from home, but, for some reason, it wouldn’t allow So, if you are still wondering what all this Arduino
us to test the analyzer properly. We had run into fuzz is about, try to remember this article the
the chicken-and-egg paradox where we needed next time you can’t figure out how to test your
a MIDI analyzer to figure out the MIDI behavior almost-completed-but-not-working yet super-
of this keyboard to test the MIDI analyzer. So duper ultra gadget.
we called Arduino to the rescue. It took me less (140059)
than five minutes to write a sketch that sent a
Note-On and Note-Off message every second on
Web Link
a different, incrementing, MIDI channel. Elektor.
Labs veteran Ton Giesberts added a transistor [1] www.elektor-labs.com/node/3380
32
82 | July & August 2014 | www.elektor-magazine.com
By Jens Nickel Like it or not, very low-cost, mass-produced are fed out to two rows of socket headers which
(Elektor Germany) microcontroller boards have changed the electron- provide the basis for the shield concept. If you
ics landscape. If you want to or have to develop equip another PCB with a matching set of pin
a working project or demo that does not need headers, you can plug it directly into the micro-
very much computing power, you can simply controller board. A shield can hold a wide variety
grab an Arduino Uno – and there’s bound to be of peripheral devices, including displays, sensors,
one lying around somewhere, just waiting to be or interfaces such as Bluetooth or WLAN. Thanks
used. Beginners in particular benefit from the to the widespread use of the small Arduino Uno
free Arduino development environment, and all board, there are now hundreds of commercially
you need to download programs is a USB cable. available shields.
If you prefer to program in Basic, you can also
work with Bascom and the boot loader. Complex Getting started
programs in C or C++ are also possible with the Many of our readers are interested in learning
free AVR Studio environment and a small pro- how to work with microcontrollers and program
grammer, such as the AVR ISP mk2. in Bascom and/or C. For them, the Arduino Uno
is a natural choice. To become truly familiar with
Intelligent shields programming a microcontroller, you need to come
There aren’t many peripheral devices on the to grips with the key interfaces of the IC yourself
Arduino Uno; a single LED is all you get from at least once. The best way to do this, of course,
the board designers. You can also use the USB is to work with peripheral devices that use these
interface to access the microcontroller on the interfaces. Unfortunately, there is hardly any
Uno board (an Atmel ATmega328P) over its UART shield available that provides all the necessary
port. However, most of the microcontroller pins peripherals in a small, low-cost package, so we
33
66 | July & August 2014 | www.elektor-magazine.com
Socket headers Table 1. Arduino pins, microcontroller pins and shield functions
The socket headers of the Arduino Uno are dupli-
Arduino Pin ATmega328 Function
cated on the shield. There is an Arduino standard
SCL PC5 EEC-SCL (*)
for the signals available on these headers, which
must be adhered to regardless of the microcon- SDA PC4 EEC-SDA (*)
troller fitted on the Arduino board concerned. IO13/SCK PB5 ISP-SCK
The individual sockets are also called “Arduino IO12/MISO PB4 ISP-MISO
pins”. The Arduino pins and the corresponding IO11/PWM/MOSI PB3 ISP-MOSI
pins of the ATmega328 microcontroller are listed IO10/PWM PB2 LED2
in Table 1.
IO9/PWM PB1 ECC-GPIOB
IO8 PB0 ECC-GPIOA
Due to the display and the buttons, it is not
possible to plug another shield piggy-back onto IO7 PD7 LCD-D7
the Elektor shield. However, all of the Arduino IO6 PD6 LCD-D6
pins remain accessible when the Elektor shield IO5 PD5 LCD-D5
is plugged in, and in most cases their operation IO4 PD4 LCD-D4
is not affected by the connected shield, as you IO3 PD3 LCD-E
can see from the circuit diagram in Figure 2.
IO2 PD2 LCD-RS
Among other things, this applies to the analog
IO1/TX PD1 ECC-TX
inputs AD0 and AD1, the serial interface pins
RX and TX, and the digital IO pins IO8 and IO9. IO0/RX PD0 ECC-RX
Additional I/O pins can be freed up by pulling AD0 PC0 S1
the jumpers (JP1 and JP2) and unplugging the AD1 PC1 S2
display module. AD2 PC2 LED1
AD3 PC3 P1
LEDs, buttons and potentiometer
AD4 PC4 EEC-SDA
Two supply voltages are always generated on
AD5 PC5 EEC-SCL
Arduino boards: 5 V and 3.3 V. They are available
(*) Connected to AD4 and AD5 on the Arduino Uno
on a socket header and can be used by shields
34
www.elektor-magazine.com | July & August 2014 | 67
R7
RESET 5
SCK
MISO 1
1k
GPIOA which can easily be configured in software as
R4
a digital output. LED1 is connected to AD2 and
10
2
4
6
8
3
ECC
ICSP
K1
K7
can also be used as a photosensor, as described
1
3
5
7
9
6
4
2
+5V
+5V
in the Microcontroller BootCamp article in this
MOSI
TX
100R
issue. According to the Arduino standard, pin
R6
GPIOB
1k
IO10 must be able to output a PWM signal. This
R5
R/W
RS
VL
D0
D1
D2
D3
D4
D5
D6
D7
LCD_E
LCD_D4
LCD_D5
LCD_D6
LCD_D7
K4
SCL 10
SCL AD1 to still be used as analog inputs, we omitted
P2
10k
SDA
+5V
9
SDA
K3
8
8
7
AREF pull-up resistors and debounce circuitry. However,
7 GND
IOREF SCK 6
it’s very easy to connect internal pull-up resis-
3V3
6 RESET 1k IO13
RESET MISO 5
R3
LED3
3V3 +5V
5 IO12
3V3
5V
4
MOSI 4
3
IO11 tors in the ATmega328, both in C and in Bascom.
3 1k IO10
GND GPIOB 2
The potentiometer is connected to analog input
R1
JP1
LED2
2 IO9
GND GPIOA 1
1 IO8
VIN
1k
LED
AD3. If you configure the A/D converter of the
R2
JP2
LED1
LCD_D7 8 IO7
LCD_D6 7 IO6 is common practice, the setting range is 1 to
S1
LCD_D5 6
K5
SDA IO5
AD0
1 330R LCD_D4 5 IO4 1023 (10 bits).
R8
2 LCD_E 4
AD1 IO3
LED LCD_RS
14
12
10
3 3 IO2
8
6
4
2
AD2
4 TX 2
EEC
AD3 IO1
K2
Display
S2
5 RX 1
AD4 IO0
140009 - 11
6
13
11
9
7
5
3
1
AD5
The alphanumeric display module from Electronic
+5V
SCL
10k
P1
330R
3V3
RS485
PORT-
EXPANDER
UART connector
K1 is a fully wired Embedded Communication
Connector (ECC), which has been described in
WIFI
detail in a previous article [4]. In accordance
(PLANNED) T-SENSOR
with the specification, the UART signals TX and
SHIELD
RX as well as two digital I/O lines are available
ECC EEC/
GNUBLIN ADC here, with a logic high level of 5 V. There is also
BLUETOOTH (PLANNED)
(PLANNED)
5 V constantly available on one pin for powering
140009 - 12
connected peripheral devices. In this case the
35
68 | July & August 2014 | www.elektor-magazine.com
Component List
Resistors K1 = 10-pin boxheader, 0.1” pitch
R1,R2,R3,R4,R5 = 1kΩ K2 = 14-pin boxheader, 0.1” pitch
R6,R7 = 100Ω K3,K4,K5,K6 = Arduino Shield stacking
R8,R9 = 330Ω header, Adafruit ID 85
P1 = 10kΩ trimpot with adjuster K7 = 6-pin (2x3) pinheader, 0.1” pitch
P2 = 10kΩ trimpot, SMD, Vishay JP1,JP2 = 2-pin pinheader with jumper, 0.1”
TS53YJ103MR10 pitch
LCD1 = LCD 2x8 characters with back-
Semiconductors ground lighting, Electronic Assembly
LED1,LED2 = LED, low-current, red (SMD DIPS082-HNLED
0805) 2 pcs. 7-way precision socket strip for LCD1,
LED3 = LED, low-current, green (SMD 0805) TE Connectivity 1814655-7
PCB # 140009-1 [1]
Miscellaneous or
Assembled board # 140009-91 [1]
S1,S2 = pushbutton
peripheral device is a small module that gives already been developed in the Elektor labs. The
user projects access to various interfaces to the latter allows the Arduino board to transmit and
outside world (see Figure 3). An RS485 module receive data wirelessly at an ISM frequency like
[4] and a wireless communication module have 433 MHz [5].
Advertisement
100uH
toroid YOU DESIGN IT – WE MACHINE IT
♦ ♦
♦♦••••
••••••
••••
From one piece and at a fair price! Simply
download our free Front Panel Designer at
www.schaeffer-ag.de, design your front
panel and order it directly.
36
www.elektor-magazine.com | July & August 2014 | 69
Voltages
Due to the countless shields now boards and automatically adjust which would make the shield more
available, the layout and pin to the operating voltage of the complicated and more costly.
assignments of the Arduino Uno socket microcontroller. That is why the However, we have not yet rejected
headers have become a sort of quasi- Arduino socket headers always have this plan, and there are already
standard for extension connectors. not only 5 V and 3.3 V supply voltage several prototypes in the labs. We
More and more microcontroller boards, pins, but also an IOREF pin that is decided to design a less complex
even with 32-bit processors, are being connected to the supply rail for the shield without level converters for the
equipped with this interface. However, microcontroller. Microcontroller BootCamp series from
some of these microcontrollers require Burkhard Kainka and relatively small
an operating voltage of 3.3 V instead We originally planned to develop projects. It is nevertheless possible
of 5 V as on the Arduino Uno board, a shield suitable for all types to connect 3.3 V peripheral devices
and their inputs and outputs are of microcontroller boards, and to the partially wired EEC connector,
therefore compatible with 3.3 V signal furthermore equipped with ECC and and the shield can even be used on a
levels. EEC extension connectors compatible 3.3 V microcontroller board with some
with both 5 V and 3.3 V peripheral restrictions.
Ideally, a shield can be plugged onto devices. That would of course compel
both 5-V and 3.3-V microcontroller the use of several level converters,
All signal pins of the ECC (TX, RX, GPIOA and a master device operating at 5 V, such as the
GPIOB) are connected to the corresponding Ardu- ATmega328 in this case, can easily be connected
ino pins through resistors, based on a suggestion to a slave device operating at 3.3 V, such as a
from Burkhard Kainka. This provides a bit of pro- Gnublin module. Both lines are held at the high
tection in the development environment, so that level by pull-up resistors, which in this case are
the Uno microcontroller will not die immediately located on the extension module, and pulled to
if something a bit higher than 5 V is inadvertently the active low level by the master or the slave.
connected to a pin. Resistors R8 and R9 attenuate reflections on rel-
atively long lines and provide some protection
EEC/Gnublin against noise pulses.
Extension modules compliant with the Gnublin/ The Gnublin modules available in the Elektor Shop
EEC standard can be connected to K2, which is include a board with eight relays, a port extender
configured as an Embedded Extension Connector with sixteen I/O lines, a temperature sensor and
(EEC). This connector is not fully wired because other devices [6].
the standard specifies a 3.3 V level and we omit-
ted a level converter to keep the cost down (see Programming
the “Voltages” inset). Most of the Gnublin mod- The Elektor shield provides everything you need
ules developed by the company Embedded Proj- for experimenting with or learning about the
ects, which are also available in the Elektor Shop, essential function of the ATmega microcontrol-
are controlled using only the I²C lines SDA and ler or another 5 V microcontroller on some other
SCL. One of the advantages of the I²C bus is that Arduino board: digital outputs and inputs, analog
inputs, a parallel interface (four bits), a serial
UART interface and I²C. The only thing that’s
Web Links missing is SPI. The pins for this are fed out to
[1] www.elektor-magazine.com/140009 connector K7, a 2x3 pin header. You can use
this connector to program the ATmega328P on
[2] www.lcd-module.de/eng/pdf/doma/dips082e.pdf
the Arduino Uno board, with the aid of a simple
[3] www.datasheetcatalog.com/datasheets_pdf/S/T/7/0/ST7066.shtml programmer such as the AVR ISP mk2. That will
[4] Elektor March 2014, www.elektor-magazine.com/130155 overwrite the Arduino boot loader, but it can be
[5] Elektor May 2014, www.elektor-magazine.com/130023 downloaded again using the Arduino IDE.
(140009-I)
[6] Elektor Gnublin series http://www.elektor.com/development/gnublin
37
70 | July & August 2014 | www.elektor-magazine.com
Attention Bridgeport lathe and milling machine Without even scratching the surface of elemen-
users; get in touch with an electronics geek and tary metalworking and finishing, electronicz peo-
have him build this circuit for you. ple should know that the turning speed is crucial
Attention Arduino users: build this circuit for a for anything that cuts, drills, mills, finishes or
nearby Bridgeport lathe owner and get access polishes metal, wood, glass, and recently, hard
to his prize machinery. plastics, Teflon® and rubber too. In the case
of a round steel bar being milled to end size,
In this project a reflective IRED / phototransistor the turning speed used to do the first couple of
device is used as a sensor to produce a retrofit rough passes using toolbit ‘A’ at angle x may
readout of the number of revolutions of a spin- differ considerably from that applied much later
dle (or “shaft”) on a lathe, a milling machine or for an ultra-smooth surface finish using toolbit
a similar piece of equipment in the metalwork- ‘B’ at angle y. In both cases, the shaft speeds
ing toolshop. have to be set and verified by the operator using
38
14 | June 2014 | www.elektor-magazine.com
whatever gears or reduction drives are available black adhesive tape or similar is secured around
on the machine. the lathe’s shaft, leaving a narrow gap (of about
To the metalworker, the turning speed his prized 3 mm). Whenever the light emitted by the LED
machine is running at equals the supply volts and reflects off the shaft at the position of the gap,
amps to the electronics engineer. Get the turning it illuminates the internal phototransistor, caus-
speed (≡voltage) wrong and you risk destroying ing the SENS+ line to drop logic Low, and High
your precious stock material (≡64-bit ARM MPU), again when the LED light is not reflected. Hence
object being created (≡Linux dev system) and/ the speed of the rising edges of SENS+ signal
or $50K Bridgeport lathe (≡128-bit LeCroy logic indicates the shaft speed. Note that due to reduc-
analyzer). ≡You don’t want that to happen. tion gears being present in the lathe or milling
Where we write spindle or shaft in the remainder machine the shaft speed is not the motor speed.
of this article of course we mean chuck, 3-claw The Arduino Micro can be reset to force it to start
Figure 1. Schematic of
head, 4-claw head, boring head, end mill, polish executing its firmware from scratch by press-
the precision rev counter
pad, drill, tap, etcetera, since all of these tools are ing S1.
for CNC lathes and milling
fitted eventually to the powered shaft or spindle machines. All measurement
of the lathe or milling machine. Finally, the function of LED2 on Arduino Micro and control functions are
line D7 is free to assign by the programmer—like handled by an Arduino Micro
How it works over rev or call keith [4]. plug-on board.
As with most applications of embedded technol-
ogy the schematic in Figure 1 does not reveal
a lot about the workings or aim of the circuit. In
IC1
fact, you could be looking at NASA’s latest alliga- D1 78L05Z +5V
K1.1
tor counter for use at Cape Canaveral. One of the
reasons for the happy scarcity of components in 1N4148 R1
BT1
the schematic is the use of an Arduino Micro board
390R
C2 C1
9V
in position MOD(ule)1, resulting in all manner of
100n 100n LED1
things being controlled and decided by software
rather than discrete parts. The Arduino Micro is K1.2
first programmed with the project firmware of
+5V
course via its micro USB connector.
+5V R2
MOD1 +5V
alkaline battery (or a 7 V to 9 V power adapter)
R3 R4
enters the circuit on K1, and gets reduced to 1 1
100R
S1 MOSI SCK
22k
On indicator. LED+
1
RESET
3
TX VIN
3
2 4 ICSP 4
The Adafruit OLED (organic light emitting diode) LED– RX GND
3 5 5
SENS+ RST RST
display module [1] is connected straight onto 4 C3 6 6
SENS– GND +5V
8-pin connector SV1. The OLED module with its 7
D2 NC
7
10n
monochrome, 128 x 64 graphic display gets its SENSOR 8
D3 NC
8
SV1 9 9
5-volts supply voltage from the same regulator D4 A5
8 10 10
D5 A4
as the Arduino Micro. Other OLED modules may 7 11 11
+5V D6 A3
be used but be sure you match their pinout to 6 12
D7 A2
12
5 OLED_CS 13 13
the board. D8 A1
4 OLED_RESET 14 14
The only input device to the circuit, a reflective D9 ARDUINO A0
3 OLED_DC 15 MICRO 15
D10 REF
IRED / phototransistor (“reflective optical sen- 2 OLED_CLK 16 16
D11 3V3
sor” device) like the one at Yourduino [2], is 1 OLED_MOSI 17
D12 D13
17
R5
connected on K2. The LED inside the device is
OLED
390R
39
www.elektor-magazine.com | June 2014 | 15
er
.e l e k
K1.2 K1.1
v i c e.c
D1
Resistors
ww
R4 K2 R1,R5 = 390Ω 5%, 0.25W
Module 1 R3
om
R2 = 10kΩ 5%, 0.25W w
R2 R3 = 100Ω 5%, 0.25W
MOSI SCK C2
IC1
SS MISO
C1
R4 = 22kΩ 5%, 0.25W
TX VIN
RX GND
RST RST Capacitors
C3
GND +5V C1,C2 = 100nF 10%, 100V, 5mm pitch
D2 Arduino C3 = 10nF 10%, 100V, 5mm pitch
D3 Micro S1
D4 A5
D5 A4 Semiconductors
D6 A3 IC1 = 78L05Z
R5
D7 A2 LED1 = LED, yellow, 3mm
D8 A1 LED2 = LED, 3mm, color t.b.d., optional, see text
D9 A0
D10 AREF
D11 3.3V Miscellaneous
D12 D13 MOD1 = Arduino Micro, Farnell/Newark # 2285194
S1 = pushbutton, PCB mount, 6x6x9.5mm
SV1
SV1 = 8-way pinheader receptacle
8 1LED2 K2 = 4-way pinheader receptacle
R1 LED1 K1 = 9V battery connector clip + wires
Reflective Optical Sensor, like TCRT5000
Monochrome 0.96” 128x64 OLED graphic display, Adafruit #
Figure 2. Printed circuit board layout
326 (UG-2864HSWEG01)
designed by Elektor Labs for the project. 34-pin DIP socket for Arduino Micro (DIY from SIL pinheader
receptacles)
PCB # 130470-1
Software
Listing 1. Excerpt from Firmware.ino
The program “Firmware.ino” is recommended
//to be done when when sensor is interrupted: educational reading if you want to understand
void interrupt_rpm_time() all the ins and outs of the control program, and
{ how it got developed and tweaked. The program
// current_interrupt_time = micros();
is richly commended by the author.
// if (micros() - previous_interrupt_time > (1/fMax))
{
Arduino users will know how to transfer the file
current_interrupt_time = (micros() - previous_interrupt_time);
to their Arduino Micro board, starting from file
previous_interrupt_time = micros();
130470-1.zip, which can be downloaded free of
// Serial.print("+");
charge at [3].
// Serial.println(current_interrupt_time);
// digitalWrite(ledPin, HIGH);
} The Arduino program waits for a rising edge at
} its INT1 input and uses five rising edges to com-
pute the average time between them. Using some
math the rpm (revolutions per minute) is calcu-
void calc_run_Time() lated and sent to the OLED display.
{ A snippet of the program code is printed in List-
//calculating running time ing 1. Here we see how the interrupt produced
unsigned long elapsed; by the sensor gets handled, and the Tachometer’s
unsigned long over; internal clock is ticking to display the “up” time.
elapsed=millis();
h=int(elapsed/3600000); Build it, use it
over=elapsed%3600000; The printed circuit board designed by Elektor Labs
m=int(over/60000); has through-hole parts only and its component
over=over%60000;
overlay is given in Figure 2. Let the electronics
s=int(over/1000);
people handle the programming, board stuffing,
ms=over%1000;
soldering and wiring, and the mech people do
}
the mounting of the board in a case, and the
40
16 | June 2014 | www.elektor-magazine.com
Figure 3. The Arduino Micro board secured on to the Figure 4. The Lathe Tacho board has boards fitted at
solder side of the tachometer board (early prototype). either side: an Arduino Micro at the solder side, and
a .96” OLED display at the front. Note the use of SIL
pin strip receptacles to ensure the correct mounting
distance.
Over to you
The project being open in terms of hardware and Web Links
software, there should be nothing in your way to
[1] OLED display: www.adafruit.com/product/326
do custom adaptations like getting that k right. It
will be insightful for sure. The hardware for exam- [2] Reflective Infrared Sensor:
ple may be adapted to support different types http://yourduino.com/sunshop2/index.php?l=product_detail&p=217
of sensor types like Hall effect. Other possible [3] Arduino Micro firmware: www.elektor-magazine.com/130470
applications include a step counter, a rev counter [4] Keith Fenner’s Turn Wright Machine Works on Youtube:
for model planes, a PWM percentage meter, or a www.youtube.com/user/KEF791
simple event driven animation on the display. It
41
www.elektor-magazine.com | June 2014 | 17
3D Pad:
Touchless Gesture
Control interface
point to make the point
42
8 | May 2014 | www.elektor-magazine.com
43
www.elektor-magazine.com | May 2014 | 9
R9 IC6.A
1
3
2 & IC7.C
8
10
Figure 1c.
EN_TOP = ‘1’ 9 &
IC7.D
Detail of the switched ‘1’ 12
11
electrode oscillator circuit 13 &
from Figure 3. Here, the
logic circuit is shown ‘1’
configured with the top
electrode (EN_TOP = 1) 130505 - 15
connected to the oscillator.
multiplexing. The software’s job, at each step the logical AND and NAND operators (IC6, IC7,
in the scanning, is to analyze the oscillator fre- and IC8). You’ll also see that the switching and
quency with each of the electrodes in turn. receiving electrode (EN_X) selection signals come
Figure 1c shows the electrode oscillator in the from the Arduino Uno board (top left). The nom-
state it is at the moment the top receiving elec- inal frequency of our oscillator, in the absence
trode is in circuit. The control signal EN_TOP is of hand influence, is set by R9–R14 at around
high, all the other control signals EN_X are low. 1.6–1.8 MHz.
The three ports IC6A, IC7C, and IC7D now form
just a simple inverter. IC6D is also configured Now that we have an oscillator whose frequency
as an inverter. varies by a few hundred ppm according to the
So this circuit is equivalent to that of the “easily proximity of a hand, all that remains for us to
influenced oscillator” in Figure 1b. With a bit of do is to derive – if possible using a simple solu-
concentration, once you have familiarized your- tion―from that a signal that can be used for a
self with the circuit, you’ll be able to find it in final application. To do this, we need a frequency
the full circuit diagram in Figure 3, by spotting comparator comprising:
external
12 VDC linear 9V 3D Arduino Shield
power supply regulator
préscaler
12V top
phase/frequency
Aalog comparator 9V 5V
Input
buffer
right
center
left
injection
Arduino UNO
SPI reference
DAC SPI VCO
bottom
reference
VCO
USB 5V 9V
serial Port
Figure 2.
130508 - 14
The functions of each of the data to host
three boards.
44
10 | May 2014 | www.elektor-magazine.com
IC5 TP1
VCO_INH 4 5 ENOSC_SENSE 2
2 3 MODE GND
LED1 3 6 SYNC_SCOPE
3 2 13 8
LED2 2 7
4 TX +9V
1 8
5 RX
K4 K5
* IC6.D
47k
82k
22k
13
11
& 12 IC6, IC8 = HEF4011BT
K2 IC7 = HEF4081BT
IC8.A IC9 = 74HC50
MOD2 1 ELEC_BOT 1
3
130508 - 2 2 EN_BOT 2 & IC7.A
1
3 3
IC8.B 2 & IC9.C
4 ELEC_RIGHT 5
4 IC7.B 7 6
EN_RIGHT 6 & 5 1
4
IC8.C
6 &
IC9.D
ELEC_CENTER_BR ELEC_REFB 8
10 9 10
EN_REFB 9 & 1
82k
22k
OSC_SENSE1 2 3 11 12
1 1
13
11
& 12 IC9.F
OSC_SENSE2 4 5 14 15
1 1
IC9.B
+5V
SYNC_SCOPE
VCO_INH
+5V
TP4
C3
C6
R1
CPF_OUT
100n 10k
100n
TP5 16
14 R3 T1
TP7 VDD C1
VDD 12 3 13
Q1 CIN PC2
1M
SCPF_CLEAR
IC2 11 4 1
OSC_SENSE1 1 Q2 VCOUT PP 2n2
CLK 9 5 2
Q3 INH IC1 PC1 2N7002
6 14 6
Q4 SIGIN CX
74HC24 Q5
5
DEM
10 C2
ENOSC_SENSE 2
RST 4 15 +5V
Q6 ZEN
3 12 HEF4046 7 220p
Q7 R2 CX C7
VSS 11 BT 9
R1 VCOIN
7
VSS 100n
4
OSC_SENSE2
R4
120k
8
R7
TP8 VDD
Figure 3.
Full circuit diagram. Top
10k
R5 R2
IC3 1 DAC_CS
R6 SYNC
+5V
470k
6 3 SPI_DATA
10k DOUT DIN
2 SPI_CLK
C5 C4
R8
DAC8311
SCLK
and below it, the electrode
plane. Everything else is
18k
GND
4u7 100n 5
10V
on the Arduino shield. The
130508 - 11 supply voltage comes from
the Arduino Uno board.
45
www.elektor-magazine.com | May 2014 | 11
Figure 4.
The scanning of each
electrode generates a
sawtooth whose amplitude
is an indication of the
capacitance detection.
46
12 | May 2014 | www.elektor-magazine.com
47
www.elektor-magazine.com | May 2014 | 13
Software
The software (sketch) to be downloaded into the
Arduino UNO consists of a file named _3Dpad_sen-
sor.ino and a library ElektorLabs3DPad, to be
installed into the Arduino IDE in the usual way.
This program sends the data to the terminal via
48
14 | May 2014 | www.elektor-magazine.com
the USB port, which is used in COM port mode right), rotating movements with turns counting
(fig. 7). The data sequence contains the four and detection of the rotation direction, and push-
electrode measurement values: ing a virtual button (Push).
And for testing, with the _3Dpad_test.ino file
>IN/OUT EL_Gauche EL_Droite loaded instead of _3Dpad_sensor.ino, we have
EL_Haut EL_Bas < commands that allow us to activate the oscilla-
tors continuously, by choosing the electrode to
IN/OUT indicates when the hand is perceived be used. This lets us check the frequencies and
as being (IN) the detection field or not (OUT). adjust the resistors R9–R14 if necessary. There
The program on the UNO board has two main is also a command to make the VCO work with
functions: on the one hand, the scanning and these set-points: 0, Max and ½ (i.e., at the DAC
sequential measurement of the electrodes, on the output, 0 = 0 V, ½ = 2.5 V and Max = 5 V).
other, the regulation, i.e. maintaining the operat- As a bonus, I am offering a very simple but fairly
ing point, taking the two reference electrodes into comprehensive application program, for PC under
account. The principle is the same as for Touch Windows (XP and 7): this displays the 3D co-or-
detectors, e.g. the ones from Atmel. The level is dinates in the form of a cursor whose position on
regulated outside the detection window, which the screen reflects X and Y, while the Z axis is
makes it possible to overcome slow variations represented by the diameter of the cursor; it also
(mainly caused by temperature changes); then displays the words “Air Swipes” when it detects
when the detection is active, this regulation is a sideways sweep of the hand along one of the
usually blocked. In our case, this implies princi- four axes, or the word “Push” when you make
pally that the VCO set-points for each electrode the movement of pushing a button (Z axis); and
measurement are continuously being corrected lastly, it indicates the rotation direction of the
[8]. I can’t go into a detailed description of the hand or finger it detects and the number of turns
software here – it would take a whole article at (very handy for carrying out settings).
least as long again as this one. However, here It will be easy for you to draw inspiration from
are the successive states of the 3D-Pad: this program in Visual Basic 6 for your own
applications.
Self-calibration: (when first brought into ser-
vice or on command via a serial link) the sys- Set-up
tem seeks the operating point for each electrode, Your Arduino UNO board is operational and you
then memorizes the set-points into EEPROM on have installed the software into the Arduino IDE.
the Arduino. You’ll need a voltmeter, an oscilloscope, and a
frequency meter (the latter is unnecessary if you
Setup: each time it is powered up, or on com- can measure frequencies with the ’scope). Once
mand via a serial link, the system quickly (less the components have been correctly soldered,
than one second) seeks the operating point, start- I recommend the usual checks: orientation of
ing from the set-points read from the EEPROM. the integrated circuits and polarized components,
There are also automatic configuration conditions, examination of the soldering using a magnifier
e.g. in the event of saturation of the electrodes. (especially for the DAC IC3).
Run: the normal operating state, which always The tension mounts: Plug together all the
follows on from a successful configuration. boards to form the stack of PCBs (Figure 6)
then plug the 12 V DC supply into the Arduino
The software’s other tasks are: UNO external power jack. It’s a good idea to
check the power rail voltages: 12 V on K3-1, 9 V
Interpolating the co-ordinates: from the mea- on TP1, and 5 V on TP2.
surement values of the top, bottom, left and
right electrodes, it calculates 3D co-ordinates: All OK? Then upload and run _3Dpad_test.ino.
X, Y, and Z. Open the connection with the terminal set to
115,200 baud; a menu of the commands avail-
Gesture recognition: it recognizes swipes in all able appears.
four directions (upwards, downwards, left, and Let’s check the oscillators are working:
49
www.elektor-magazine.com | May 2014 | 15
VCO: enter the command to activate the VCO via the serial link, the corresponding command
oscillator with a set-point ½: you should see (e.g. “T” = top electrode, or “B” = bottom one)
2.5 V on TP8 and a nice square wave on TP5 at and check the oscillation signal on TP6. The fre-
a frequency of 100–110 kHz (depending on com- quency should likewise be close to 100–110 kHz.
ponent tolerances). The other commands are documented in the soft-
ware source code.
Electrodes: make sure you clear everything
away from around the electrode plane. For each If these checks are satisfactory, load the normal
of the six electrodes, use the terminal to send, program _3Dpad_sensor.ino in place of the test
Component List
3D-Pad Arduino shield
Resistors
SMD 0805, 0.125 W)
r p c bs
R1, R6, R7 = 10kΩ to
er
.e l e k
R2, R8 = 18kΩ
v i c e.c
R3 = 1MΩ
R9,R12 = 47kΩ
ww
om
R4 = 120kΩ w
R5 = 470kΩ
R10,R13 = 82kΩ
R11,R14 = 22kΩ
R15,R16 = 470Ω
Capacitors
default: SMD 0805
C1 = 2.2nF
C2 = 220pF
C3,C4,C6,C7,C8,C9,C10,C11,C15,C16,C17,C18 = 100nF
C5 = 4.7µF 16V (pitch 2mm)
C12 = 100µF 16V (pitch 3.5mm)
C13, C14 = not fitted
Semiconductors
IC1 = HEF4046BT
IC2 = CD74HC4024M
IC3 = DAC8311 ou AD5641AKSZ
IC4 = CD4504BM
IC5 = 78L09 (SOT-89)
IC6, IC8 = HEF4011BT
IC7 = HEF4081BT
IC9 = CD74HC4050M
T1 = 2N7002
Miscellaneous
K5, K6 = 8-pin pinheader*
K3, K4 = 6-pin pinheader *
K1, K2 = 4-pin pinheader *
K7, K8 = 2-pin pinheader
Electrode Plane
Semiconductors
LED1,LED2 = LED, green, SMD, Kingbright type KPT-2012SGC
Miscellaneous
K1,K2 = 4-pin pinheader*
K3, K4 = 2-pin pinheader*
PCB # 130508-21
* 0.1’’ pitch
50
16 | May 2014 | www.elektor-magazine.com
program. A good way of checking the 3D-Pad in scrolling on the terminal [9]. You can launch a
operation consists in connecting a ’scope probe to reconfiguration at any time, either with the com-
TP8 (DAC output) and another to TP4. The sync mand “R” from the terminal, or by saturating the
is taken from TP8. At first switch-on, or follow- electrodes by bring your hand flat within a few
ing the self-calibration command (send “A” from millimeters of the electrode plane.
the terminal), the voltage level on TP8 will fall
gently: this is the search for the set-points for I’ll be there to help you if you need help getting
each electrode. After a few moments, this trace it going or information for a specific application,
should be stabilized (end of self-calibration) and or if you have any suggestions for developing the
your oscilloscope screen should look like the one project. Don’t hesitate to contact me on Twitter
shown in Figure 4b. Bring your hand closer to the [10], I’ll be delighted to answer you personally.
electrode plane: you should see the sawtooth on (130508)
TP4 change and also the measurement values
Web Links
[1] games
Fruit Ninja: http://fruitninja.com/
Despicable Me - Minion Rush: https://play.google.com/
[2] CC BY-NC-SA 4.0 http://creativecommons.org/licenses/by-nc-sa/4.0/
[3] www.embedded.com/design/prototyping-and-development/4008781/
Getting-in-touch-with-capacitance-sensor-algorithms
[4] injection locking: http://en.wikipedia.org/wiki/Injection_locking
[5] www.elektor.com/arduino
[6] assembled, tested UNO board from the Elektor e-shop
www.elektor.com/arduino
[7] www.elektorPCBservice.com
[8] www.rtcmagazine.com/articles/view/101626
[9] video of the sawtooth signal on TP4 http://youtu.be/rYdyR49qFzU
demo video: http://youtu.be/11QGUxXFYq8
[10] @junowhynot + #3DpadElektor: https://twitter.com/junowhynot
51
www.elektor-magazine.com | May 2014 | 17
Microcontroller
BootCamp (1)
Arduino and Bascom
By Burkhard Kainka
(Germany)
You might ask why you should use a microcon- For comparison: the NE555 timer IC
troller when it’s possible to do so much with First of all there’s the output. When you look
ordinary analog electronics. At first glance, this at the internal block diagram of the NE555 on
looks like a good question. New microcontrollers the data sheet (Figure 1), you can see that it
with more features, higher performance, higher has a push-pull output stage that can actively
clock rates and even more memory are appear- switch high and low. Microcontrollers have exactly
ing all the time, but the first demo program for the same kind of outputs. They are called ports,
every one of them invariably makes a LED blink. where the name “port” can stand for a set of
This leads to the justified criticism that you could outputs or for pins that can be configured either
get the same result by simply taking an NE555 as inputs or as outputs. The circuitry connected
timer IC and adding a couple of resistors and a to the output for a LED blinker application is also
capacitor. That’s absolutely right, and the com- the same: a LED with a series resistor, connected
parison is better than you might think because either to ground (GND) or to the supply voltage
a lot of the elements of an NE555 timer IC can (Vcc). The NE555 also has a second output driven
also be found in a microcontroller. by an open-collector transistor, which can only
52
30 | April 2014 | www.elektor-magazine.com
switch something to ground. Many microcontrol- the other hand, an analog electronics solution is
lers can also emulate this function. Actually the a better and more economical choice for quite a
only difference is that microcontrollers usually few simple tasks.
have several outputs but the NE555 has only one,
since the push-pull output and the open-collector Anyone with a bit of experience in microcon-
output are not independent. troller development can also mention another
advantage of microcontrollers: once the circuit
Next we have the inputs of the NE555, which is complete, you don’t need to touch the solder-
consist two inputs to a comparator that controls ing iron again. From that point on, all you do is
an internal flip-flop. A typical application for this write and test code. Changes to device functions
is an astable multivibrator, which hobbyists often can be implemented and tested very quickly.
call a blinker circuit. You can put all this together Microcontrollers are general-purpose and versatile
in almost no time. You just plug the numbers computation workhorses. The learning curve is
into a couple of formulas to determine the right worth the effort, since you ultimately save time.
component values, and then the NE555 does Your first exposure to a microcontroller data
exactly what you want. Determining the compo- sheet may put you off, since it can easily amount
nent values for an NE555 circuit and program- to 300 pages or more. Fortunately, there are
ming a microcontroller are actually comparable
tasks. There’s another thing that’s very similar:
both devices (NE555 and microcontroller) have
VCC
a Reset input that you can use to set everything
RESET
back to the starting point. And with both devices 4 8
VCC
the Reset input is usually high in the quiescent
state and must be actively pulled to ground.
5k
DIS-
THRESHOLD 6 INHIBIT/ 7
Figure 2 shows a simple square-wave genera- R
RESET CHARGE
CONTROL 5
tor in the form typically used as an LED blinker. VOLTAGE
DIS
controller are summarized in Table 1. You could
3
OUT
formulate the result of a fair comparison as fol- 9V 6 NE555
THR
lows: The microcontroller has a bit more of 2 TR
1k
CV GND
everything and is therefore generally the better
5 1
choice for complex tasks. For example, a single LED
53
www.elektor-magazine.com | April 2014 | 31
54
32 | April 2014 | www.elektor-magazine.com
1k
4 11
D2 D5
on a display, and much more. However, perhaps 5
D3 D4
6
55
www.elektor-magazine.com | April 2014 | 33
56
34 | April 2014 | www.elektor-magazine.com
for them will be a frequent topic in this series on doesn’t work in practice, and likewise a micro-
microcontroller programming. controller with nothing in its program memory
cannot program itself. However, this is possible if
You can type in the program in Listing 1 yourself a boot loader is already present in memory, and
or download it from the Elektor page. The file the Arduino comes with a built-in boot loader.
UNO_LED1.bas is located in the zip folder [3]. The development environment on the PC also has
Compiling the program is very easy: simply click to be able to download program code using the
Program/Compile, click the corresponding icon Arduino boot loader. Fortunately, Bascom devel-
on the toolbar (a black IC), or press the F7 key. oper Mark Alberts already guessed that some-
If there is any sort of error in the source text, one would want to program an Arduino board in
an error message will be displayed. If there are Bascom at some point in time, so this capabil-
no problems, a pop-up window shows what per- ity is already incorporated. After you configure
centage of the memory is occupied. In this case the right settings, everything is quite easy. Here
it is less than 1%, which is rounded down to 0%. we describe how this works with the demo ver-
What matters is the resulting hex file UNO_LED1. sion, since there is a small difference with the
hex or the binary file UNO_LED1.bin, which are full version.
two different file formats with the same con-
tent. They contain the executable code for the
microcontroller. Now you have to load this code
into the microcontroller’s flash memory. There
are many ways to do this, and for now we only
describe the simplest way. Other options will be
described in subsequent instalments.
57
www.elektor-magazine.com | April 2014 | 35