The P10 Display.
In this post, we will be seeing on how can we use the STM8s microcontroller to drive the Chinese dot matrix display. In this process we will be understanding how exactly does the display work (the schematics and work flow), and further will be interfacing the display with the STM8s Discovery Board (both the code and hardware will be discussed.) Once we understand how the display works, writing the code should be a piece of cake then.
What is the P10 display?
The P10 display is an LED Panel, a very cheap one, 32X16 i.e has 32 LED’s in horizontal and 16 in vertical (one panel). The 10 in P10 stands for the pixel distance that is 10mm. It is widely used in advertising and to grab attention in local markets. You must have seen a variant of P10 display on the Buses in Delhi (image below). This one has a much bigger pixel distance something around 13-15mm so these might be P13 or P15 displays but the working concept is the same. Further, we can cascade more and more LED panels to get a bigger panel.
The thing about these Chinese displays are that they come with absolutely 0 documentation. I tried searching on the web and was able to find a few russian blogs but it did not help much. These displays are based on an undocumented protocol (hub12). The Chinese don’t want anyone to replicate their extreme low cost design and remove their monopoly in this market so they dont provide any reference to understand their products. However, this not being a very complex device, it was easy to reverse engineer the display.
The display
The front panel consists of 512 LED’s in a 32*16 matrix. On seeing the backside of the panel we see sixteen 74HC595. This is an 8 bit serial-in parallel-out Shift Register.
Every single 8 bit shift register can be used to control 8 LED’s. So we can control 128 LED’s by the given number of shift registers on one panel but the number of LED’s are 512. How does the display control 512 LED’s when it is just capable of controlling 128 LED’s? Here comes the concept of refresh rate.
At one instant, the shift registers can only control at a maximum of 128 LED’s so we select which of the 128 LED’s to be controlled by using two extra bits. The rows switch faster than the refresh rate of the human eyes, such that for the human eye it looks static. Think of this as when you take a laser light and move it from one place to another, you see a line of that laser light, but is it actually a light? Its just a dot in real. This is the concept of refresh rate used in this P10 display to smartly reduce the production cost. To understand this concept better, see this image. It took me an hour or two to figure out how data shifts through the 74HC95. I’d recommend the reader to try this on their own after reading this post. Refer the picture on the right.
The white boxes show the LED’s controlled by every shift register. At one instant only one row out of the four can be enabled/controlled by using the A and B control bits as below.
A | B | Row |
---|---|---|
0 | 0 | 1,5,9,13 |
0 | 1 | 2,6,10,14 |
1 | 0 | 3,7,11,15 |
0 | 0 | 4,8,12,16 |
Now that we know how exactly the display works, we can get started on writing the code and making the hardware connections to display any content on the display. Things will be a lot clear once we write the code and make the connections.
The Connections
The connections are pretty straight forward. The pin configuration for the display was available online (shown in the image below) , and as we are communicating through SPI, we just need to configure the pins accordingly. Do keep the pin configuration of the STM8s discovery board handy. It is available here.
The connections which I have used are as follows: Refer the user manual to understand these connections.
PS: Don’t forget to connect power supply to the P10 board and the microcontroller. A 5v, 2A adapter should be sufficient to power the P10 board. Always power the display board first and then the other microcontroller otherwise the board might suck power from the microcontroller thus damaging the controller.
Now that we are done with the connections, lets get started by writing the code to drive the display.
The Code.
To start with, we will need to configure the GPIO’s of the microcontroller. Comments are added so it should be easy to understand the code.
Once we write configure the GPIO pins to do the custom functions as per our connections to the P10 display, we are ready to send data to the display through SPI. The SPI block is configured and initialized as well.
To send the data through SPI we write another function, which sends an unsigned 8 bit integer through SPI. We also add a delay function, which just counts from a 32bit number to 0 according to the clock speed.
Now, like we saw previously, the display has a scan ratio of 1/4. Hence we need to scan one row at a time. We also saw how to configure the A and B bits to choose the row which we need to display.
We need to have something which we need to display. I wont go into much detail here, and advise the reader to try to understand the code by trying and testing. Make a digits2 array and enter random 8 bit values(0xFE, 0xFA etc.) to get started. You will understand eventually.
I am adding a sample digits[2] array which you can modify to test.
The code is as below:
Then, just show each row accordingly. I would recommend the reader to play around these values in digits2[] and see how the display changes. It will help the reader greatly in order to understand the exact functioning of the board.
One important thing to note is that in the P10 display, the LED burns on 0 and is off on 1.
Finally our main program would look something like this
So it is quite clear that in this we configure the clock and the pins, and in the infinite loop, we display, the first row, second row, third row and fourth row thus using the concept of Scan Ratio and Refresh Rate. to see how this works add a delay in between the showRow(i); something like This
You will get an idea how this actually works.
Hoping by now, you have a fair idea on how to work with the P10 display using the STM8s microcontroller.
Thanks for reading!
Powered by Jekyll