HardwareX 6 (2019) e00055
Contents lists available at ScienceDirect
HardwareX journal homepage: www.elsevier.com/locate/ohx
A novel analogue keyboard for embedded applications, based on integer division truncation M. Mariola a,⇑, C. Bemont b, F. Petruccione a,c a
University of KwaZulu-Natal, School of Chemistry and Physics, University Road 4000, Durban, South Africa University of KwaZulu-Natal, School of Engineering, King George V Avenue, EMERG, Durban 4001, South Africa c National Institute of Theoretical Physics (NITheP), KZN, South Africa b
a r t i c l e
i n f o
a b s t r a c t
Article history: Received 31 January 2018 Received in revised form 15 February 2019 Accepted 15 February 2019
Keywords: Microcontroller Arduino Controls Keyboard
Modern micro-controllers are powerful control devices available in a range of packages with a variable number of input/output pins. Smaller microcontrollers, for example the Attiny45, have only six available pins for input/output but relatively powerful performance in terms of processing. However, it is often not possible to exploit the resources of such a microcontroller due to the limited number of pins available. Using an analogue keyboard only one pin of a microcontroller is required. In other analogue keyboards, each character or command corresponds to an analogue value produced on the nodes of a voltage divider composed of several resistors. The principle difference between the system proposed here and previous analogue keyboards is in the algorithm. Because no resistor has zero tolerance, the voltage drop across the voltage divider nodes in a standard analogue keyboard is never precisely as expected. Thus, in order to function correctly, the microcontroller must be programmed for such a system so as to recognise that each analogue value lies between two particular fixed values. In the proposed system, the discretisation is instead entrusted to an approximation from an integer division. Using the same approach, it is also possible to easily convert a standard potentiometer into a discrete switching device. This keyboard is not intended to replace a standard alphanumeric computer keyboard, rather it is an alternative for any case where a cheap, compact microcontroller based device requires control, particularly when a microcontroller has limited input/output pins. Lastly it can be implemented as an analogue rotating selector, and is adaptable because the number of selection steps/keys is set purely as a software parameter. Ó 2019 Published by Elsevier Ltd. This is an open access article under the CC BY-NC-ND license (http://creativecommons.org/licenses/by-nc-nd/4.0/).
Specifications table Hardware name Subject area
Analog keyboard General Engineering Educational Tools and Open Source Alternatives to Existing Infrastructure (continued on next page)
⇑ Corresponding author. E-mail address:
[email protected] (M. Mariola). https://doi.org/10.1016/j.ohx.2019.e00055 2468-0672/Ó 2019 Published by Elsevier Ltd. This is an open access article under the CC BY-NC-ND license (http://creativecommons.org/licenses/by-nc-nd/4.0/).
2
M. Mariola et al. / HardwareX 6 (2019) e00055
(continued)
Hardware name
Analog keyboard
Hardware type Open Source License Cost of Hardware Source File Repository
Electronic engineering and computer science CC BY-NC-ND $5 https://data.mendeley.com/datasets/49ty67n8jw/draft?a=3583475b-258e-4118-8aebc2376d127f66
1. Hardware in context Microcontroller systems often require an operator to input data when performing tasks. The data input can be performed via various methods, for example using a touch screen [1], which will require a dedicated driver to be used. For simple, robust or low cost system a mechanical or a membrane keyboard is usually preferable, driven by a stand-alone chip or integrated with the principal microcontroller [2]. To integrate a 16-character keyboard into a microcontroller, via a matrix of switches, a minimum of 8 digital pins are usually necessary [3]. This can be a problem when the microcontroller has limited pins available for a particular design. To reduce the number of pins used, some keyboards have an encoder that transmits characters to the microcontroller via serial communication. An analogue keyboard is an alternative solution for controlling an embedded system via serial communication or via a large number of digital microcontroller pins. The keyboard presented here is not intended to replace an alphanumeric personal computer keyboard, rather it is an alternative for any case where a micro-controller based device requires control. The keyboard will not recognise simultaneous keyprocesses in its current form. In other proposed analogue keyboard solutions [4,5] the circuit is designed using a voltage divider, where the number of resistors depends on the number of keys required. In such systems the voltage divider uses different resistors values for each key and the key is recognized by measuring the voltage drop across the nodes of the voltage divider, followed by a series of conditional statements to determine the key pressed. Since the nominal values of the resistors are always affected by a tolerance error, the microcontroller is programmed so as to recognise the voltage drop for each key as lying between two values. For that solution, a number of conditionals statements are necessary to recognise the chosen key. The multiple constants used in the conditional statements must also be loaded into the microcontroller memory, which might be used more beneficially for other purposes. A different system [6], patented in 1977, utilises resistors of different values and does not appear flexible in terms of the number of keys implementable, further the design must be altered according to ADC bit resolution. Another way to implement a keyboard, and identify a key pressed, utilises a voltage divider to change the charging time of a capacitor wired to a digital pin [7], here it is again important to carefully set the values of the voltage divider resistors. These systems also require effort to reprogram all the conditional statements and their constants if a different resolution ADC is implemented, or if a key is added or removed. In the proposed system a single conditional statement is necessary, and the key is recognised simply by exploiting the property of integer division, with the result directly correlating to the integer value of the relevant key. Differences from traditional analogue keyboards, and the potential advantages of the proposed keyboard are further discussed in Section 2.2. Broadly, the advantages of the proposed keyboard are:.
A single simple algorithm No floating or real division operations are required A microcontroller may be controlled using a single analogue input No firmware is required Readily available components Can be built on Veroboard Can be readily implemented as a rotating selector dial with a variable number of positions
2. Hardware description 2.1. Hardware scheme The voltage divider is wired to the reference voltage of the internal analogue to digital converter (ADC) of the microcontroller. The nominal values of the resistors Rn are the same and the value of the resistor RL must be several times greater than the equivalent resistance of the voltage divider. The circuit described is shown in Fig. 1. The analogue reference is indicated as Aref and the analogue input is indicated as Analog Input. The analogue input cannot be floated and the resistor RL must used to provide a ground reference for it. As depicted in Fig. 1(a), if the button nn is pressed the series resistors RN1 and RN are in parallel with the resistor RL . If the resistor RL is several orders of magnitude larger than the summation of the voltage divider resistors, then its contribution is negligible in the system proposed and the error produced by neglecting it in the associated system equations is small. It is advantageous to ignore RL in the equation because the algorithm, is substantially simplified as shown in the following section, and thus processing time reduced.
M. Mariola et al. / HardwareX 6 (2019) e00055
3
Fig. 1. Analogue keyboard scheme – (a) the keyboard is represented by the resistors Rn ; RL and the buttons n. The nominal values of the resistors are the same except the resistor RL which must be larger than the resistors in the voltage divider by several orders. (b) Scheme to use a potentiometer as switch.
2.2. Detection of key pressed The total number of series resistors are indicated by N and the button pressed is indicated by the index n. The voltage divider resistors Rn each have the value R. If the first button is pressed, and the effect of the resistor RL is neglected, then the voltage drop is simply:
V1 ¼
V RðN 1Þ R þ Rð N 1Þ
ð1Þ
It is possible to generalise (1) to obtain the voltage drop for any button n pressed:
Vn ¼
V V RðN nÞ ¼ ðN nÞ NR N
ð2Þ
Considering a generic analogue to digital converter (ADC) of b number of bits, the voltage resolution Q is:
Q¼
V
ð3Þ
2b
Then from (2), the equivalent binary code Vnd , converted for a generic node n, for pressed button n is: V
V nd ¼ N
ðN nÞ V 2b 2b ¼ ðN nÞ ¼ ðN nÞ : N V N Q
ð4Þ
As seen from Eq. (4), V nd depends on the button pressed n, and the total number of voltage divider resistors used, N. By the inversion of (4) the pressed button n can be easily calculated once the ADC provides the measured value V nd :
n¼
2b V nd 2b
N
ð5Þ
It is noted that the voltage V applied to the voltage divider, used for the reference voltage, does not enter Eq. (5). This means that compared to other analogue keyboards [8], which use differing resistor values and whose algorithms also require more processor power, the proposed device does not require the microcontroller to be programmed in terms of applied reference voltage. The keyboard and its equation work under the assumption that the nominal value of the resistors R are the same (only RL is different). If the ADC resolution increases, the result for a specific node does not change significantly, as can be shown from Eq. (5), where the terms 2b and V nd are seen to grow proportionally. Integer division provides an approximation of the number n which, for a small variation in V nd , does not affect the final result for a limited number of buttons. This is discussed further in Section 2.3.
4
M. Mariola et al. / HardwareX 6 (2019) e00055
The fact that the keyboard utilises integer division is a significant difference from existing analog keyboard designs. This is firstly because the algorithm does not then require the declaration of a reference voltage and therefore is not subject to reference voltage variation or error. Further, the function is significantly easier to implement on, for example Arduino because Eq. (5) is all that is required, particularly for microcontrollers that cannot inherently perform fixed point division our algorithm is easier to implement and requires less processing power. Also, the proposed algorithm does not require conditional statements. Further, due to the sequential nature of our algorithm’s integer output and of asci code, characters can if convenient be printed directly from our algorithm. Situations where this might be useful are, for example when implementing a hexadecimal keyboard that outputs to a programming display (on a system to, for example, program memory). For example, the character A corresponds to ASCII 65. Thus, if the 10th button is pressed, the character can be transmitted directly to the display as ‘‘10 + 55”, thus printing letter A. Finally, the system and the Equation proposed is implementable on a rotary knob type potentiometer and can be mapped and re-mapped in any equi-spaced manner required, as for example according to changing or multiple (situation based) input notations displayed on a screen or printed around the knob. The buttons indicated in red in Fig. 1 are not considered in this simulation, but can be added. The button n0 was also not considered because it is linked directly with the voltage source and the result is always n ¼ 0. Experimentally it was observed that the quality of the printed circuit board, the connections with the microcontroller and the value of the resistor R used, affect the keyboard reliability on the last node, where some random error occurs, thus this node is simply not utilised. 2.3. Equations and Monte Carlo simulation to determine the maximum number of keys for given RL In the previous section was state that the Eq. (5) does not consider the contribution of the resistor RL , and that the RL value must however be chosen carefully according to the equivalent resistor of the voltage divider. In this section the error produced by the resistor RL , and the ADC resolution is studied considering ideal resistors with 0% tolerance. In the ideal case, the measured value V n has an error produced only byRL . If the resistor RL is not consider, the voltage drop for a specified node n is:
Vn ¼
VðN nÞ N
ð6Þ
The voltage drops on the node n, by considering the contribute of RL is given by Eq. (7).
Vn ¼
V RL RðN nÞ : RðNnÞ R þ RðN nÞ L R n þ RRLLþR ðNnÞ
ð7Þ
Introducing a new function f d as difference of Eqs. (6) and (7), we obtain the Eq. (8), that described the effect of the resistor RL .
fd ¼
V ðN nÞ V RL RðN nÞ : N R n þ RL RðNnÞ RL þ RðN nÞ
ð8Þ
RL þRðNnÞ
The resistor RL can be expressed as per Eq. (9)
RL ¼ x N R;
ð9Þ
where x is a multiplication factor of the equivalent series resistance of the voltage divider N R. Since:
f d ¼ f ðn; N; x; RÞ 2 C 1 8n > 0jn 2 N;
ð10Þ
The maximum node for which the error f d is maximum can be calculated by:
2 3 3 2 @f d ðn NÞ n n N 3nxN þ N x V ¼ ¼ 0: @n n2 nN xN2 N
ð11Þ
The solution of the Eq. (11) is
n3 n2 N 3nxN2 þ N3 x ¼ 0:
ð12Þ
From the last equation it is clear that the node for which error is a maximum, is not a function of the applied voltage. Eq. (12) has three unknowns, but the number of keys are fixed by the designer ðN ¼ number of key þ 2Þ and x can be chosen as for example two times NR as a first attempt. The third order polynomial Eq. (12) has three solutions but only one solution lies between n ¼ 0 and n ¼ N. Starting with a low xvalue, and as nM the node for which the error is maximum, it was numerically determined that the maximum error is located on nM ¼ 7. As shown in Fig. 2, even when x increases the maximum error is located in approximatively the same node. For ideal resistors, the value of RL can be calculated by imposing the Condition (13),
5
M. Mariola et al. / HardwareX 6 (2019) e00055
Fig. 2. The plot shown that for different chosen values of x, the node, for which the voltage deviation between the absence and the presence of RL is maximum, is sensibly stable.
fd ¼
V ðN nM Þ V RL RðN nM Þ V n V nþ1 < ; N 2 R nM þ RL RðNnM Þ RL þ RðN nM Þ
ð13Þ
RL þRðNnM Þ
The last condition states a limitation due the potential deviation introduced by RL . Real resistors deviate from the nominal value according to a specified tolerance and the condition (13) can be used to determine a first approximation of RL . Since the nominal value of the resistors statistically change according to a specified tolerance, a general keyboard can be designed by utilising the SciLab script ‘‘keyboardsim.sce” supplied with the manuscript, which performs a Monte Carlo analysis [9]. The script is used to determine if the chosen values of R and RL produce an error less keyboard. This script performs the analysis of a keyboard composed from a desired number of keys. The user specifies the number of resistors N, the nominal values of the resistors R and RL , the tolerance expressed in percent, the ADC resolution and number of iterations. The script calculates the voltage drop per each node V n according to the Eq. (14).
V V n ¼ Pn P P ð i¼1 Ri Þ þ ð Ni¼nþ1 Ri ÞRL =ðð Ni¼nþ1 Ri ÞþRL Þ
N X
! ,
Ri RL
i¼nþ1
N X
!
Ri þRL
!
ð14Þ
i¼nþ1
For each iteration the script randomly changes the nominal value for each resistor for a specified tolerance and calculates V n . After the calculation of V n the software converts this value into a decimal number V nd according to the resolution of the ADC used. By applying Eq. (5) for each node n, the software records the number of time an error occurs for each iteration. This manuscript does propose a specified keyboard size, however the errors occurring for a twenty key keyboard was assessed as an example. For this keyboard, the series resistors have a value of 100X 5%, RL of 7:5 kX. The simulation was performed while also considering different ADC resolutions. The ADC resolutions considered were 10, 12, 16 and 24 bit. The results of the analysis are graphically represented form Figs. 3–6; and in order to obtain a clear graphical representation for each resolution, the charts were split according to odd and even pressed keys. The frequency detected per 100 000 button presses is shown. Considering for example Fig. 3 depicting the odd keys, when the button 7 is pressed, it is noted that a small number of events result in an error where Eq. (5) produces number 8 (not an odd key), instead of number 7. It should be noted that errors select one key above that depressed. From the simulation it was observed that for the same value of RL , increasing the ADC resolution does not affect reliability the results. It is also possible to observe that the errors related to the key pressed mainly drop in the same node as found for the maximum of the solution of Eq. (12) (see Fig. 2). The statistical analysis above is only shown for 5% tolerance resistors, because importantly, for 1% or lower tolerance resistors errors are not present. From these results is also clear that the error is strictly related to the resistances chosen, a generic keyboard design is compatible with several micro-controller systems. It is suggested to use resistors of tolerance less than 5%, however if the resistors are taken from the same stock the real tolerance is lower than 5% and the keyboard is likely to work perfectly, as confirmed via a number of keyboards built from 5% tolerance resistors in our lab. This will be discussed further in Section 6. Fig. 7 shows the error probability for a 30 key keyboard using resistors with tolerance ranging from 0.5 to 2%. When increasing the number of keys, the value of RL must also increase to maintain no errors. 2.4. Dependence of the resistor tolerance and maximum number of keys In this section the effect of resistor tolerance versus the maximum number of keys is investigated. This study is performed by considering the effect of the resistor RL and the tolerance of the resistor Rn that contributes to the errors. Due to the arbitrary nature of resistor tolerance, the approach used added or subtracted the maximum resistor tolerance for all possible combinations for each resistor within the voltage divider. The total number of combinations, for a number N of resistors are:
Number of possibility ¼ 2N 2:
ð15Þ
6
M. Mariola et al. / HardwareX 6 (2019) e00055
Fig. 3. Frequency test performed for 100,000 iterations considering a 5% resistance tolerance for an ADC of 10 bit.
Fig. 4. Frequency test performed for 100,000 iterations considering a 5% resistance tolerance for an ADC of 12 bit.
Fig. 5. Frequency test performed for 100,000 iterations considering a 5% resistance tolerance for an ADC of 16 bit.
Fig. 6. Frequency test performed for 100,000 iterations considering a 5% resistance tolerance for an ADC of 24 bit.
M. Mariola et al. / HardwareX 6 (2019) e00055
7
Fig. 7. The plot shows error probability for a variable resistor RL for different value of resistor tolerance considering an analogue to digital converter of 10 bit.
Due to the large number of possibilities, as well as the contribution of RL a Montecarlo simulation approach was used. The simulation considers a resistor R in the voltage divider of 100 X, a variable value of the resistor RL and different tolerance values. Each random analysis for tolerance and resistor RL value considered was performed 300 times. The results of the simulation are represented in Fig. 8 for an ADC resolution of 10 bits. It is interesting to note that from the above plot, for ideal resistors the maximum number of keys increases linearly as a function of the resistor value RL used. If the tolerance increases, the maximum number of keys reliably implementable decreases, and a convergence is observed at 2% tolerance. Increasing RL does not improve the number of keys implementable beyond a tolerance of about 2%. Further, for a 0% tolerance on R, the number of possible keys might approach the ADC resolution if the effect of resistor RL were neglected. In practice, as the number of keys is increased, the value of resistor RL must increase so as to ensure that its effect is negligible. Increasing the value of RL enables a larger number of implementable keys, as shown, and likely that number could be increased significantly beyond 50, however increasing RL eventually creates interference errors related to the last node (discussed in Section 2.5). The experimentally measured noise on RL is of a similar magnitude to the voltage drop across the last node resistor when errors occur. One solution is not to use the last node, which will allow a larger total number of keys, but eventually, increasing RL will cause errors on the second to last node. By simulation it is shown that for a zero percent tolerance, to achieve a total number of keys close to the resolution value of a 10 bit ADC (1000 keys), with R ¼ 100X a resistor RL of 586MX is required. When the resistor R is 1X the resistor RL must be 5:86MX. Since the value of R cannot be reduced to values where current in the voltage divider becomes large, it is seen that there are practical limits to the implementable number of keys which are not associated to ADC resolution. 2.5. The keyboard An analogue 20 key keyboard was built and tested using an ArduinoTM Leonardo microcontroller board. In the Arduino, the timer of the internal ADC is set by default to obtain the best conversion performance [10]. The Arduino, or more accurately the microcontroller used, has a 10 bit Successive Approximation Register (SAR) ADC for which the conversion time is
Fig. 8. Maximum reliable number of keys as a function of resistor tolerance. The maximum number of keys also differed according to the value of resistor RL , per legend.
8
M. Mariola et al. / HardwareX 6 (2019) e00055
independent of the acquired voltage per each node [11]. The time until key recognition, due to the integer division required, is related to the analogue value converted [12]. Arduino boards are commonly used for such experiments due to their adaptability and user friendliness. The Arduino was paired with the manufactured analogue keyboard printed circuit board, depicted in Fig. 9(b). The implementation of the keyboard does not require particular attention to the value selected for the voltage divider resistors or to their variable tolerances, as is required for other analogue keyboard systems [4], and the keyboard is extremely lean on hardware and software resources. The physical keyboard was tested key by key and the stability of its output was confirmed. However, incorrect results are possible due to incomplete closure of a button when depressed. To avoid this, the analogue conversion might be repeated twice before outputting the data, or better quality buttons might be used. If the value of RL is excessively high, noise in the Analog Input becomes problematic and the keyboard will not work reliably. If the value of RL is the order of magnitude of 100 kO or higher, a significant noise is present with no button pressed. The value of this noise in volts, is numerically close to the voltage present on the last node for a keyboard that contains more than 20 keys. This error is likely related to the higher sensitivity to interference produced by a high resistance value. For a more than 24 keys, experimental testing and optimisation is necessary, that is due to the high value of RL to be used and consequently the possible error generated as previously explained.
2.6. Flow-chart of the microcontroller algorithm As depicted in Fig. 10, the microcontroller continuously reads the analogue signal until it is greater than a minimum set value Min_val that in the case describe in the manuscript can be zero. Once the signal is greater than that minimum value, then applying (5) pressed key is determined. An action programmed to that key, such printing a particular character or executing a command, can then of course be followed. In the flow-chart a routine to avoid errors related to button bounce, via a short delay, is included [13]. Because the use of an interrupt is not incorporated into this system, once the action is concluded, a new reading procedure is immediately initiated. Using the Arduino IDE, it was possible to measure the memory space required by the keyboard algorithm. The program and dynamic memory required is 538 bytes and 11 bytes respectively.
2.7. Alternative use of the algorithm - potentiometer Due to the nature of the discretization induced by the proposed algorithm, it can also be applied using a linear resistance potentiometer as shown in Fig. 1(b), instead of the buttons utilized per Fig. 1(a). The number of discrete tasks n required to be distinguished by the potentiometer is set by N in Eq. (5), where N ¼ n þ 2, and n is the number of tasks. The position of the potentiometer shaft will then set the resistance and thus switch between tasks every equal number of degrees, as required. The total resistance of the potentiometer does not need to be known accurately and the resistor RL is not necessary, since the wiper is always wired to input Analog Input. Thus, it is possible to drive the microcontroller to perform a given (and variable) number of tasks by changing only the algorithm parameters – no hardware modification is required. The maximum number of tasks (steps) that the potentiometer can differentiate is as per the discussion in Section 2.2 regarding the maximum number of buttons that may be implemented.
Fig. 9. (a) Printed circuit board of the analogue keyboard; (b) Wiring between Arduino Leonardo and the keyboard. Left to right the keyboard measures 95 mm key to key in its current format; each key measures 15 mm by 15 mm.
M. Mariola et al. / HardwareX 6 (2019) e00055
9
Fig. 10. The figure shows the algorithm used to read from the keyboard. The configuration of the algorithm for which the final block of the flow diagram is start, indicates that once the action is concluded, a new reading is initiated.
3. Design files summary
Design file name
File type
Open source license
Location of the file
keyboard.pro
KiCad
CC BY 4.0
keyboard.sch
Schematic KiCad Netlist KiCad KiCad PCB
CC BY 4.0
https://data.mendeley.com/datasets/49ty67n8jw/draft?a= 3583475b-258e-4118-8aeb-c2376d127f66 https://data.mendeley.com/datasets/49ty67n8jw/draft?a= 3583475b-258e-4118-8aeb-c2376d127f66 https://data.mendeley.com/datasets/49ty67n8jw/draft?a= 3583475b-258e-4118-8aeb-c2376d127f66 https://data.mendeley.com/datasets/49ty67n8jw/draft?a= 3583475b-258e-4118-8aeb-c2376d127f66 https://data.mendeley.com/datasets/49ty67n8jw/draft?a= 3583475b-258e-4118-8aeb-c2376d127f66 https://data.mendeley.com/datasets/49ty67n8jw/draft?a= 3583475b-258e-4118-8aeb-c2376d127f66 https://data.mendeley.com/datasets/49ty67n8jw/draft?a= 3583475b-258e-4118-8aeb-c2376d127f66 https://data.mendeley.com/datasets/49ty67n8jw/draft?a= 3583475b-258e-4118-8aeb-c2376d127f66 https://data.mendeley.com/datasets/49ty67n8jw/draft?a= 3583475b-258e-4118-8aeb-c2376d127f66
Keyboard1.net Keyboard.kicad_pcb keyboardtes.ino
CC BY 4.0 CC BY 4.0
keyboardsim.sce
Arduino file Scilab File
CC BY 4.0 CC BY 4.0
demo.xlsx
Excel file
CC BY 4.0
keyboardscomponents
pdf
CC BY 4.0
keyboardcopper
pdf
CC BY 4.0
keyboard.pro is the file that contains the project of the board keyboard.sch contains the schematic file keyboard1.net netlist of the circuit keyboard.kicad_pcb is the PCB file keyboardtes.ino is the Arduino program to use the keyboard to output to an excel file (to be modify by the user) keyboardsim.sce is a program that requires as inputs the system reference voltage, the ADC number of conversion bits, the resistance values R and RL, the resistor tolerances, the number of keys and the number of iterations required in the Monte Carlo simulation, in order to predict keyboard error ratio for a new keyboard with new parameters.
10
M. Mariola et al. / HardwareX 6 (2019) e00055
keyboardcomponent.pdf is the pdf file of the component layout keyboardcopper.pdf is the pdf file of the copper side 4. Bill of materials
Designator
Component
Number
Cost per unit currency
Total cost currency
Source of materials
Material type
n
20
$ 0.10
$ 2.02
AliExpress.com
R
12 12 mm 7.3 mm Push button Resistors 100E ,1/4W, 5%
22
$ 0.03
$ 0.66
R
Resistor 100 k, 1/4W, 5%
1
$ 0.03
$ 0.03
Copper plate
1
$ 1.74
$ 1.744
Mantech South Africa Mantech South Africa AliExpress.com
Nonspecific Nonspecific Nonspecific Single Side
5. Build instructions Before starting the keyboard construction, run the SciLab [14] software keyboardsym.sce and insert the values as request from the program, illustrated in Figs. 11–14. If the simulation returns zeros error for a large number of iterations, the user may proceed to build the keyboard proposed. The keyboard can be built on a prototyping board by utilising the KiCad [15] schematic, analkeyboard.sch or alternatively a printed circuit board (PCB) can be produced on a single sided copper laminate. One technique to build a PCB, the toner transfer method, utilises a projector transparency and a laser printer, one single sided copper laminate board and a household iron, temperature set to ‘‘Cotton”. Alternatively, if a UV lamp is available it is possible use a pre-sensitized copper plate. The well-known toner transfer method for amateurs to realize a PCB is described here. Download the KiCad file, analogkeyboard.pro and open the PCB in KiCad. Using a laser printer, print the PCB drawing on a transparency. Clean the copper laminate board using a steel wood scourer until the oxidation is completely removed. A steel wool scourer is preferred over sandpaper, but either may be used. To remove traces of grease, clean the copper using pure alcohol. Then set a clothes iron to the cotton temperature and allow it to reach temperature. Place the laser printed transparency face-down on the copper, so that the ink is in contact with the copper. Iron the copper plate for three or four minutes until the toner has completely adhered to the copper. The transparency will be stuck to the copper. Place the board, transparency down, on a cool surface, as shown in Fig. 15(a). Once the board has cooled, gently peel the transparency off, as shown in Fig. 15(b). If in some areas, the ink track trace may not have fully adhered to the copper, redraw the track in such places using a permanent marker for CD-ROM labelling, as shown in Fig. 16(a). If some areas are marked in toner ink where they should not be, remove it by scraping away, as shown in Fig. 16(b). The last part of the PCB manufacture involves etching the copper. For this a ferric chloride (FeCl3) etchant is usually used. Immerse the copper plate in the solution and wait several minutes until the copper is etched away where the toner is not present. The time required in the copper bath will depend on the ferric chloride concentration and the temperature of the solution and may be monitored. The ferric chloride is a hazardous substance (UN1773) and must only be used while using protective wear such as latex gloves and goggles, and only in an aerated or open area. Ferric chloride can be reused extensively until the solution is saturated, at which time it should be disposed of as hazardous waste. Remove the copper board from the solution and rinse and wash it. Then remove the toner ink using a steel wool scourer. Remove the residual toner using acetone. The finished PCB is shown in Fig. 17.
Fig. 11. Input data - reference voltage and ADC resolution.
M. Mariola et al. / HardwareX 6 (2019) e00055
11
Fig. 12. Input data - number of keys (2 less than the total of resistors) and the nominal value of the series resistors.
Fig. 13. Input of the value of the resistor RL and the tolerance of the series resistors.
Fig. 14. The last input is the number of iterations required. Illustrated on the right are the final results of the simulation.
Fig. 15. (a) To cool down the board after ironing, place it copper side down (transparency) on a cool surface; (b) then peel the transparency from the copper board.
12
M. Mariola et al. / HardwareX 6 (2019) e00055
Fig. 16. (a) Covering the tracks in places where the toner ink did not adhere; (b) Residual of ink to be removed. Track width is 1 mm the above images.
Before placing any components onto the PCB, inspect it for possible short circuits and check using a multimeter. Excess copper can be removed by using a sharp tool. The final phase is the drilling of the board and the soldering of the components to it. 6. Validation and characterization 6.1. Validation of the hardware per Monte Carlo simulations To test the simulation and the equations of Sections 2.2 and 2.3, a 40 key modifiable keyboard was built. The keyboard depicted in Fig. 18, is composed from 42 resistors of 100 X and resistor RL of 10 kX, all with 5% tolerance. This keyboard was built to verify the maximum number of keys for a defined resistor value and tolerance. The pin headers were wired to the node of the voltage divider and starts from the node 11 as depicted in Fig. 18, since for 10 nodes the keyboard is reliable. By linking the node n to the pin header GND we can change the number of keys. Experimentally it was observed that the maximum reliable number for this configuration was 24. The experiment shows that 25 resistors (24 keys) is the maximum value for which the keyboard is error free. With 26 resistors key 9 gives an intermittent error reading of 10 instead of 9. After the keyboard was tested, the resistors were measured as presented in Table 1. From these measurements we can say that the nominal value of this subset is 99.7 O with a 1.8% tolerance. By running the software keyboardsym.sce for 23 keys (25 resistors), the error is absent, while for 24 keys (26 resistors), for one thousand iterations the probability to obtain an error is 1.7%. This result confirms that it is possible to dimension the keyboard based on available resistor values and tolerance using the Monte Carlo simulation software provided.
Fig. 17. Cleaned board.
13
M. Mariola et al. / HardwareX 6 (2019) e00055
Fig. 18. Keyboard used to validate the algorithm.
Table 1 The table represents the measured values of the series resistors used. For this subset we found that the tolerance is 1.8% Resistor Number
Measured value (X)
Resistor Number
Measured value (X)
Resistor Number
Measured value (X)
Resistor Number
Measured value (X)
Resistor Number
Measured value (X)
1 2 3 4 5
99.9 99.4 102 99.9 99.4
6 7 8 9 10
99.3 99.7 99.9 100.3 98.5
11 12 13 14 15
98.4 99.9 99.4 99.4 98.6
16 17 18 19 20
99.5 99.2 99.3 101.3 99
21 22 23 24 25
99.5 99.2 99.2 99.4 99.6
6.2. Final hardware implementation characterization To validate the keyboard, correspondence between the key pressed and the integer value generated by Eq. (5) was experimentally tested. The integer numbers generated by Eq. (5) were printed to a text file via an Arduino Leonardo [16]. The results are shown in Fig. 19. Another experiment was performed to show the potential to assist in simple data collection. The Arduino Leonardo was programmed to acquire values from the keyboard and then execute particular tasks such as: Write into an excel file By pressing button 19, Arduino Leonardo automatically prints to a spreadsheet the signal being measured on its analog input (A0).
Fig. 19. Correspondence between the key pressed and that recognized by the Eq. (5) algorithm was measured. The column in green shows that by holding the button we obtain the same value every time.
14
M. Mariola et al. / HardwareX 6 (2019) e00055
Fig. 20. Test of the keyboard using Excel.
A computer cannot interact with a microcontroller without being correctly programmed. With the analog keyboard it is possible interact with a computer and simultaneously with the micro-controller system. In this way proprietary or open source software can be used, without the need to develop another program, and without a driver. The results of the test are shown in the Fig. 20. In this test, an Excel sheet and chart, was prepared to acquire 27 values from three analog inputs. By pressing button 19, the microcontroller works as an automatic keyboard. It is able to transmit the data and the plot can be done simultaneously, in real time. 7. Conclusion An alternative keyboard that uses a single analogue input of a microcontroller is presented. The circuit presented does not require particular attention from the builder in selecting the value used for the voltage divider resistors or their tolerances. The requirement is simply that the value of the parallel resistor permanently wired to the analog input should be substantially larger than the total resistance of the voltage divider. The algorithm executed to determine which key is pressed is extremely simple and lean on memory. This system, tested with a 28 pin Atmega328P and an Arduino LeonardoTM, can be used on smaller microcontrollers with limited input/output ports, since it requires just one analogue input. It permits maximum exploitation of microcontroller resources by saving memory, processing and pins. It requires relatively smaller, cheaper microcontrollers and quicker programming with little variation between implementations on different microcontrollers, features that might be valuable to hobbyists looking to reduce size or cost, particularly for mobile applications. An alternative use of the proposed equation is possible using a linear potentiometer instead of a series of switches. In this configuration the microcontroller can call a number of subroutines via the position of the potentiometer shaft. The number of positions and corresponding subroutines is programmed via the principal equation (Eq. (5)), and no hardware modifications are required to set that number. Therefore, in this implementation, because the number of selection steps (effectively keys) is dependent only on software parameters, selection position on a rotating dial can readily be modified according to the number of options on a particular screen when for example cycling through selection screens on a device. Declaration of interests None. Acknowledgments This work is based on research supported by the South African Research Chair Initiative of the Department of Science and Technology, the National Research Foundation and the Technology Innovation Agency, South Africa.
M. Mariola et al. / HardwareX 6 (2019) e00055
15
References [1] F. Feng, Y. Liu, Y. Chen, Effects of quantity and size of buttons of in-vehicle touch screen on drivers’ eye glance behavior, Int. J. Hum.-Comput. Interaction 34 (12) (2018) 1105–1118. [2] Xiangqun Chen, Xiangqi Xiao, Rui Huang, Design of Low Power Handheld Meter Reading Terminal Based on S3C6410 and CLRC632, Journal of Physics: Conference Series, IOP Publishing, 2018. [3] C. Platt, in: Encyclopedia of Electronic Components, O’REILLY, United States of America, 2012, pp. 33–34. [4] STMicroelectronics, Application Note AN1809/0205, STR71x ADC Driving an Analog Keyboard, 2005. [5] Microchip Technology Inc., Application Note 234 (DS00234A), Hardware Techniques for PICmicroÒ Microcontroller, 2003. [6] STRANDT, Earl R. Keyboard encoding circuit utilizing an A/D converter. U.S. Patent No 4,015,254, 1977. [7] Microchip Technology Inc., Application Note DS01146B, Compiled Tips ’N Tricks Guide, 2009, pp.1-4. [8] A. Mascolo, OnewireKP. https://playground.arduino.cc/Code/OneWireKeyPad), 2016 (accessed 20/12/2018). [9] R.C. Jaeger, Microelectronic, Circuit Design, McGrow-Hill, New York, 2011, pp. 29–32. [10] Arduino, ‘‘AnalogRead( ),”
, (accessed 03/09/2018). [11] J. Luecke, Analog and Digital Circuits for Electronic Control System Applications: Using the TI MSP430 Microcontroller, Elsevier, Burlington, 2004, pp. 74–75. [12] H. Huang, The Atmel AVR Microcontroller: MEGA and XMEGA in Assembly and C Delmar USA, 2014. [13] P. Horowitz, W. Hill, The Art of Electronics-Third edition, Cambridge University Press, New York, 2015. [14] Scilab, , (accessed 03/09/2018). [15] KiCad, , (accessed 03/09/2018). [16] M. Banzi, M. Shiloh Sebastopol USA, in: Getting Started with Arduino, 2015, pp. 77–87.