Controlling Mechanical 7-Segment Displays?! How RS-485 and UART works! || EB#43
Recently, I received those mechanical seven-segment displays which, like the name implies do not use LEDs to highlight each one of their segments but, instead, they use a small piece of white plastic that moves around. To find out how exactly this display works, I opened one up and found out that each plastic segment has a magnet connected to it, which can either get pushed away or attracted by another magnet. In the case of the commercial display, the required seven magnets are electromagnets, who, by alternatingly hooking them up to 12 volts DC reverse their magnetic polarity and thus control each segments. And, best of all, all the electromagnets keep their magnetic polarity even when current is no longer flowing, meaning that as soon as you are done displaying a number it will stay there without requiring any more electrical energy. As you would expect, though, controlling just four of those displays would either require lots of microcontroller pins and simple code or a more sophisticated microcontroller circuit with complex code. which, in both cases, can be a very time-consuming task. Thankfully, the company, AlfaZeta, which produces those seven-segment displays and sent them to me also sent me a big module with ten of them which are attached to a pretty promising-looking control circuit. So, in this video I will try to find out how this circuit works, how we can tell it what to display through the Arduino’s UART and the RS-485 interface and, finally, I will use it in combination with an ESP8266 to build a subscriber counter for my YouTube channel. Let’s get started! This video is sponsored by AlfaZeta First off, in order to properly examine the control circuit, I removed its two mounting screws and then, lifted it off the seven-segment display PCB. And, judging by the number of used IC’s, I was afraid that this circuit will not be an easy reverse-engineering subject. But, never-the-less, I started searching for all the datasheets of the IC’s, as well as finding out how each component is connected to one another through the help of the continuity function of my multimeter. As it turns out, the head of the operation is the ATmega32A microcontroller which, through the help of of high-voltage source driver IC’s and Darlington transistor array IC’s controls all the electromagnets. As far as I figured it out, it seems like one side of all the electromagnets of one display are connected to one source while the other displays all use different source pins. The other sides of the electromagnets are individually connected to a Darlington transistor array pin. While this time all electromagnets with the same segment control function are connected together. Now, if you watched my video about multiplexing, you should by now understand how the microcontroller can control all the displays. If not, then let me tell you that the source IC only powers one display at a time. And, by activating the [unsure] of transistors we power the required segments to form a number. Then the source IC powers the next output, and we can once again set the fitting transistors to form the next number. This process repeats until all numbers are successfully created This is, of course, only my theory but, since the practical testing of the displays later on revealed that they cannot change numbers simultaneously but, instead, have to change numbers one-by-one I was pretty sure that my theory has to be correct. The only question remaining is, how can we tell the microcontroller to display a specific number? For such communication tasks, the PCB comes with two RJ11 female connectors which, according to the manufacturer feature this pinout. But, what exactly does RS485 mean? Well, RS485 aka TIA485 or EIA485 is an industry standard for asynchronous serial data transfer. And, speaking of data transfer, I already talked about the SPI and I2C communication protocols in previous videos which I will use as a comparison example. Both of them use the clock line which basically tells the receiver when to read the data on the data line. This is called a synchronous communication. The RS485, however, is asynchronous which means there’s no clock line, only data lines. That means when an RS485 transmitter starts sending serial data consisting of 1’s and 0’s to a receiver the receiver has to synchronize itself by recognizing the first voltage edge and then using its own clock and set baud rate in order to sample the sent data at the correct time. The transmitter of course also has to use its clock with the exact same baud rate in order to generate the serial data. Otherwise, both of the components will not understand each other. It is also very important to note that, unlike SPI or I2C, which are proper protocols the RS485 only defines the electrical properties of the communication signals. It is not a protocol, nor does it define connection plug arrangements. That is why when you work with RS485 you have to get the proper communication protocol and hardware pinout from the manufacturer which mine kindly provided. Before testing the code, however, I want to name the most important electrical properties of the system. It typically uses one twisted pair of wires where one carries the non-inverted data signal and the other carries the inverted data signal. The receiver then creates the original data signal by creating the difference between those two. That sounds needlessly complicated at first, but the data wires use symmetrical voltage levels, and thus, injected common mode noises equally exist on both lines and therefore get rejected by the differential receiver inputs which makes the system pretty interference-free. Of course, there are more electrical properties but, before boring you to death, and since you can easily look those up online let’s continue with the coding. Now, the given protocol seems simple enough. Just the start command followed by the address of the module, the actual 10 numbers I want to display, and then a stop command. To control the display, I want to first use the Arduino Nano, which luckily comes with a USART interface. If we ignore the letter ‘S’, it stands for Universal Asynchronous Serial Receiver Transmitter which certainly sounds promising when it comes to functioning with the RS485 interface. So, as a simple test, I set the baud rate of the Arduino to 9,600 just like I did for the control PCB and typed in the serial data with the last numbers to display being ‘1234’. After uploading the code to the Arduino, we can hook up an oscilloscope to the serial transmit pin of it in order to find out that it sends out the data we just typed in, in software. And, while this does look promising, we still have the problem that this one data line does not match the RS485 standard. That is when such a MAX485 break-out board comes in to play. This IC can basically turn our microcontroller serial data into RS485 standardized serial data. So, I hooked it up to my Arduino according to this schematic which only utilizes the write functionality of the IC, and not the read functionality, created a twisted wire pair through the help of my electric drill, soldered one side of it to the control PCB’s ‘A’ and ‘B’ line and hooked up the other side to the MAX485 breakout board, and finally, after all this theory it was time to power the control boards as well as the Arduino in order to find out that code does in fact work Brilliant! And if we look at the RS485 data lines with the oscilloscope we can see the non-inverted and inverted data signals pretty clearly. Now, the manufacturer also sent me a bit of example code to display any digit I want which I used to create a simple counter mode. After uploading the code, and me being quiet for a few seconds, you can enjoy the true beauty of mechanical displays. Needless to say, I do love the sound and look of it which is why I decided to use it as a subscriber counter for my channel All I had to do was to connect the serial interface of an ESP8266 to the MAX485 breakout board and merging the Arduino YouTube API library with the 7-segment control board code in order to create this rather lengthy piece of software. After uploading it we can not only see through the serial monitor that the ESP grabbed my YouTube data successfully but we can also see that the 7-segment display shows my subscriber number correctly as well! And with that being said, I hope you enjoyed this small mechanical display RS485 UART adventure and learned a bit along the way. If so, don’t forget to like share, subscribe, and hitting the notification bell. Stay creative and I will see you next time!