Built Using PIC16 MCU
The year 2019 marked the 150th anniversary of the periodic table. As a tribute, Dev built a desktop accessory that helps students learn the chemical symbols and the order of the chemical elements in the periodic table. The circuit is based on a Microchip PIC16 MCU, and it continually runs when powered by a commonly available 5V charger, or intermittently with a long-lived battery supply.
The United Nations proclaimed 2019 to be the International Year of the Periodic Table of Chemical Elements (IYPT2019). In 1869, Russian chemist, Dmitri Mendeleev (1834-1907), first organized all the chemical elements known at that time into a table based on atomic weight. In this effort, he built on the earlier work of many other chemists, notably Antoine Lavoisier (1743-1794), Humphry Davy (1778-1829), John Dalton (1766-1844) and Jacob Berzelius (1779-1848). The table revealed regularity in the properties of the elements, so it’s now known as the Periodic Table.
Some of the elements of small atomic number—such as iron, copper and zinc—have been known since antiquity. Some other elements are bound together in minerals, and they were only isolated after chemistry was sufficiently developed. The gaseous elements, invisible as they are, were likewise difficult to identify. Other naturally occurring elements were first known only after their synthesis in nuclear reactions. These are promethium, polonium, astatine, francium, actinium, protactinium, neptunium and plutonium. There are other elements—those of atomic number 95 and greater—that have such a short lifetime that they are not found in nature and are only obtained through synthesis.
Each chemical element is represented by a one- or two-letter symbol in the Periodic table. When you scan these symbols, most of them make sense, like “O” for oxygen, “Al” for aluminum and “Ne” for neon. Mixed among these are some “oddball” chemical elements whose symbols don’t match their English names. That’s because their symbols derive from their names in other languages (Figure 1).
The symbol Na for sodium derives from the Latin word for salt which is natrium. Latin provides other symbols, such as potassium (K, kalium, from the word for potash), iron (Fe, ferrum), silver (Ag, argentum), tin (Sn, stannum), antimony (Sb, from the name of its mineral, stibium), gold (Au, aurum), mercury (Hg, hydrargyrum, for silver water) and lead (Pb, plumbum). The symbol for tungsten, W, comes from the German name of its mineral: wolframite.
Presently, 118 chemical elements are known. The 118th element, oganesson, was first synthesized in 2002 at a nuclear research facility near Moscow, and it’s named after Russian nuclear physicist, Yuri Oganessian. Oganesson is in Group 18 of the periodic table, and it completes the 7th period. A consequence of this is that the next element, 119, with the temporary name “ununennium,” Latin for a hundred and nineteen, will be difficult to synthesize. As a consequence, we’ll have 118 chemical elements for quite a while.
My desktop circuit (Figure 2) operates in several modes. It will display the symbols for all 118 chemical elements, either sequentially or in random order. In the sequential mode, it displays the symbols in order of atomic number, from hydrogen (H) to oganesson (Og). In the random mode, it first displays the atomic number, and then the symbol. This latter mode is useful for learning the association of the atomic number and symbol. It could also serve as the basis for a periodic table memory game.
The device can be powered from a 5V charger. The current demand is surprisingly low—10 to 12mA—because the matrix display LEDs are very efficient. As a consequence, nearly any 5V charger can be used as a power supply. There’s provision for intermittent operation in either sequential or random mode by pushing a button, and this is a useful mode when using battery power.
In my device, I incorporated a battery holder for three AA batteries. These have enough voltage to power the PIC and display. Since alkaline AA batteries have a capacity of about 2,000mA-hours, this means that theoretically, the battery supply should operate the device continually for 200 hours, or about 100,000 push-button cycles.
The characters are displayed on two 8×8 LED matrix displays that have a total of 128 LEDs. The LED matrix displays used were Luckylight KWM-R30881CPGB, which are available from a variety of sources. These have the LED cathodes connected to the rows.
In each display, the LEDs are wired in a matrix of eight columns and eight rows, with the LED cathodes connected to the row lines. If you happen to have displays in which the anodes are connected to the row lines, you can use the hardware without change and invert some values in the microcontroller (MCU) source code. The LEDs are multiplexed for display by supplying the proper 16 data bits for each row to the column lines, and cycling through the rows. Since there are 16 columns and 8 rows, we need 24 I/O pins to drive the display. Additionally, we need two data lines as an interface for an I2C serial EEPROM that contains the character set (that I’ll described shortly) and a mode switch.
I used a 40-pin MCU, the Microchip Technology PIC16F877A , to accommodate all this I/O. The PIC also has pins available for in-circuit serial programming, which made for easier development. The circuitry around the PIC MCU is shown in Figure 3, and the connections for the LED matrix displays are given in Figure 4.
Since precision timekeeping isn’t required, the clock for the PIC is provided by its internal RC oscillator, with the frequency set by an external 4.7kΩ resistor and 22pF capacitor. This gives a clock frequency of about 4MHz, which is the upper limit for the internal oscillator. The actual operating frequency can be checked at pin 14, which outputs a signal at one-quarter the clock frequency. The 100Ω current-limiting resistors at the pins that drive the LED columns provide a bright display, and the actual brightness is set by a pulse-width modulation (PWM) in the source code.
The character set is contained in a Microchip 24C256 serial EEPROM, whose data are accessed using I2C SDA and SCL signal lines. The required storage for the character set is slightly less than 2KB. The 256KB capacity of this EEPROM is certainly overkill in this application, but it’s hard to source less dense serial EEPROMs. Since we want to minimize battery drain in the MCU’s sleep mode, this serial EEPROM is powered by one of the PIC I/O pins. The pull-up resistors for the mode pins are powered by the same I/O pin.
There are quite a few connections from the PIC pins to the LED matrix displays, and many of the signal line conductors need to cross each other. Figure 5 shows the component side view of the main circuit board. While this is easily done in a multi-layer PCB, I use boards with a single copper plane that I etch for my own circuits. To simplify construction, I mounted the LED matrix displays on a daughter board that plugs into the MCU board. The daughter board still requires a few jumper wires to route the display signals. Figure 6 shows the front and bottom views of the final assembly, showing the daughter board placement before insertion into the plastic case.
The Periodic Table Trainer operates in several modes that are selected by the logic signals present on the connections to PIC pin-37 (RB4) and pin-38 (RB5). These are set at a logical “1” by the two 100kΩ resistors, and they are set to a logical “0” by connection to ground by switches. When B4 is at zero, the device operates in a single-shot mode, in which one element is shown after each reset. When B4 is a one, the device continually shows elements. If B5 is at zero, a random element is displayed each time, and when B5 is a one, the elements are displayed in the order of their atomic number. In that case, the displayed element is stored in the PIC non-volatile memory so that the order is preserved between button presses in single-shot mode.
I originally wanted to use 16-segment alphanumeric displays, but these weren’t available in the desired large size. The 8×8 LED matrix displays were a good second choice.
The next problem was that I needed character set data for the chemical element symbols and the atomic numbers from 1-118. I designed my own, based on a 5×7 character set, but I included some aesthetic enhancements. One was to have the five lowercase “dangler” characters—g, j, p, q and y—drop below the baseline of the leading uppercase characters. While no chemical elements have symbols that require either uppercase or lowercase j or q, I included these for completeness.
The symbols for the chemical elements are one or two characters, and these are easily displayed on two, side-by-side 8×8 matrix displays. However, the atomic numbers can be as large as 118. While you might initially think that we need three matrix displays to accommodate the atomic numbers, the leftmost digit is the slender character one. I was therefore able to squeeze all the necessary numbers into two matrix displays in my character set. The row data are stored as sequential bytes in the serial EEPROM. Figure 7 shows how.
Integrated circuit (IC) technology has advanced considerably since the late 1970s, when I built my first home computers. At that time, erasable read-only memory chips had just a few kilobytes of data space, and they were erased only by exposure to intense ultraviolet light. The IC packages had windows that allowed the ultraviolet light to penetrate the silicon chips and erase them by recombining the electrons and holes in the memory capacitors (Figure 8). Today, read-only memory chips have memory space that is orders of magnitude greater, they’re erased by a quantum tunneling effect and they’re called “electrically erasable programmable read-only memories” (EEPROM).
Several years ago, the 24C08 was a popular EEPROM for MCU circuits because it was serially alterable by an I2C interface. This device contained 8KB of memory, which was usually sufficient for most applications. Today, this device has been superseded by the 24C256, a plug-compatible device with 256KB of memory. Not surprisingly, the 24C256 chips are available at a lower price than that of the 24C08, so I could hardly complain when I used this chip to store my 2KB character set.
The character set initially needs to be loaded into the serial EEPROM. There are many choices for purchase of a device programmer, but, if you just need to program a device for the Periodic Table Trainer, that’s an unnecessary expense. One of my many Raspberry Pi computer boards solved that problem, because these boards have an integrated I2C interface. The circuit shown in Figure 9 allows connection of the serial EEPROM to the Raspberry Pi I/O header. It’s so simple that I built mine using point-to-point wiring on a prototyping circuit board, but I’ve included a circuit board layout in the online repository.
The I2C is not activated by default on the Raspberry Pi, but it’s a simple procedure to do that using the raspi-config program in the Raspbian operating system. Run the configuration program by typing the following in a command line:
Then, at Interfacing Options, enable I2C, select <Finish> and then reboot. After reboot, you can verify that the I2C system is active by this command:
The Raspberry Pi will respond by indicating that the user I2C system, i2c-1, is active.
One command-line utility you should install for debugging is i2c-tools. This is installed with the following command:
sudo apt-get install -y i2c-tools
In particular, i2c-tools will probe the entire I2C address space to report what devices are connected. When the serial EEPROM is connected, you will see the display shown in Figure 10, which indicates that there is a device at hex address 0x50, after entering the following command:
i2cdetect -y 1
The 0x50 address is a consequence of the upper 4 bits of this EEPROM being logically set at 0101 inside the integrated circuit. When combined with the three lower address bits set at a logical “0” by grounding the address pins, we get an address of 0101000, which is 0x50.
Although the user I2C interface of the Raspberry Pi is accessible from several available programming languages, I’ve found that the easiest of these is Python. However, some things are more easily done using one of my favorite languages, PHP, so I’ve written a program in PHP that writes the character set data into a text file, which is read by a Python program that programs the serial EEPROM through the I2C interface. Source code for these programs is included on Circuit Cellar’s article code & files webpage, and the text file of the character set is included so that it isn’t necessary to run the PHP program if the character set is unmodified. From the same directory that includes the file named elements_hexfile.txt, run the following to program the serial EEPROM:
As with all my PIC projects, I wrote the firmware using the PICBasic Professional compiler from ME Labs . Because I use Linux exclusively, I run an older version of this compiler and its associated programmer on a very old Windows operating system installed as a virtual machine. The folder on Circuit Cellar’s article code and files webpage for this article include a compiled hex file, to program a PIC without needing a compiler. It would be easy enough to rewrite the source code in C so other compilers can be used, including the free MPLAB C compiler  from Microchip Technology, manufacturer of the PIC MCUs.
At the time of writing this article, it’s possible to buy 8×8 LED matrix display subsystems with an I2C bus interface. I avoid publishing circuits that utilize a particular component that might be hard to source in the future, so I didn’t use these in my design. If you are able to buy these, you can still use the character set in the serial EEPROM, and there would be a considerable simplification of the circuit. A smaller PIC can be used, since much of the complexity is off-loaded to these I2C display subsystems, and I’m sure that Arduino fans would have no trouble building and programming a device using these displays.
 The datasheet for the PIC16F877A is available at the Microchip Technology website at https://ww1.microchip.com/downloads/en/devicedoc/39582b.pdf
. Information on the PICBASIC PRO Compiler is available at https://melabs.com
 Information on the free, unrestricted-use, MPLAB XC C Compiler is available at https://www.microchip.com/mplab/compilers
Wikipedia has a very complete article about the periodic table at https://en.wikipedia.org/wiki/Periodic_table
PUBLISHED IN CIRCUIT CELLAR MAGAZINE • MARCH 2020 #356 – Get a PDF of the issueSponsor this Article