#RGB ledpanel with Arietta G25

<abstract>
Led panel in a project to realize a very bright and internet
ready digital signage useful for a wide range of applications like message 
notifications, alarms, synchronized clock, scrolling text, etc. The project 
is open and based on the tiny Linux board Arietta G25 wired to a 32x32 RGB led panel
and interacts with the user smartphone via a WiFi link.
</abstract>

As shown below all the electronic parts can be fixed inside a cheap and elegant 
[IKEA RIBBA photo frame](http://www.ikea.com/it/it/catalog/products/00078051/?cid=it%7Cba%7Cgoogle%7Cmerchant%7C1x1%7Cside_banner%7C1).

<img class="img-responsive center-block" width="50%" src="./ledpanel_ribba.jpg">

The whole project is based on the full color RGB led panel made by 
the Chinese company <a href="http://www.linsnled.com/linsn-indoor-led-module.html" target="_blank">
Linsn</a>. 

It is composed by 1024 rgb led ordered in 32 rows of 32 leds each and mounted with a lot of logic
on a black PCB 19x19 cm size. Everything in enclosed in a plastic frame with a set on placement 
for M3 screws to use for mounting.

The cost of creating a panel like this for an European company could be around 200 eur just for manufacturing
and components so the best thing to do is to <a href="/catalog_ledpanel" target="_blank">buy it :-)</a>

<img class="img-responsive center-block" width="40%" src="/products/LEDPANEL-01.jpg" title="32x32 RGB led panel P6">

The datasheet of this panel with a correct explanation about how it works is not easily available.
In <a href="lepanel_pinout" target="_blank">this page</a> I'll try to explain how "it seems to work" :-)

On the rear an <a href="/arietta">Arietta G25 module</a> is used to generate all the 
signals requested by the RGB panel starting from a 32x32 pixel graphic image.

The Pyhton graphic library called <a href="https://python-pillow.github.io/" target="_new">Pillow</a> 
is used to create the image starting from graphic primitives, true type fonts, and jpg, png, etc images.

The WiFi capability of the Arietta G25 (also in Access Point mode) and the Python module for
the networking, open a lot of possible uses of this project.

Linux is loaded in few seconds from an 8GB microSD with more than 7.8 GB free !!

Tons of softwares, tools, languages and libraries can be installed. Complete step by step guides 
are available on this site.

###Software used

<ul>
	<li>Linux Kernel version 4.2.3 and Buildroot Linux 2015.08.1 freely downloadable from this 
	site or created from scratch following my guide on this site
	</li>

	<li>Python interpreter</li>
	<li>Python Web server made with <a href="http://www.tornadoweb.org/en/stable/">Tornado</a>. 
	Any other web solution (Apache, lighttpd, etc) can be used instead</li>
	<li>SSH server to access to the microSD contents via WiFi (other rete access systems can be used like
	Netbios, ftp, etc</li>
</ul>

##How the RGB led panel works 

The RGB led panel has a two 16 pins male connector where 
to send data using a synchronous serial transmission.

* Three data lines are for the Red, Green and Blue (Rx, Gx, Bx)
* One line is for the serial clock (CLK)
* One line is for latching the data sent after 32 clock pulse (STB) 
* One line is to enable the latch output line to the led (OE)

The panel is logicaly splitted in two section:

* Top 16 rows of 32 led each
* Bottom 16 rows of 32 led each

R0, G0 and B0 are the data sent to the top block

R1, G1 and B1 are the data sent to the top block

Four address lines (A,B,C and D) select to which row of led
are sending the data on Rx,Gx and Bx lines

This is the  lock diagram of the internal parts of a RGB led panel

<img class="img-responsive center-block" width="50%"  src="./ledpanel.jpg"/>

##Pinout

This is the pinout of input data connector:

<img width="320px" src="./data_in_rgb_panel.jpg"/>  


| LED Pin # | Signal | Description    | Arietta pin # | Line | gpio ID |
|-----------|--------|----------------|---------------|------|---------|
| 1         | R0     | Red 1st bank   | J4.10         | PA21 | 21      |
| 2         | G0     | Green 1st bank | J4.8          | PA22 | 22      |
| 3         | B0     | Blue 1st bank  | J4.7          | PA23 | 23      |
| 4         | GND    | Ground         | J4.9          |      |         |
| 5         | R1     | Red 2nd bank   | J4.11         | PA24 | 24      |
| 6         | G1     | Green 2nd bank | J4.13         | PA25 | 25      |
| 7         | B1     | Blue 2nd bank  | J4.15         | PA26 | 26      |
| 8         | GND    | Ground         | J4.9          |      |         |  
| 9         | A      | Row address    | J4.28         | PA5  |  5      |
| 10        | B      | Row address    | J4.27         | PA6  |  6      |
| 11        | C      | Row address    | J4.26         | PA7  |  7      |
| 12        | D      | Row address    | J4.25         | PA8  |  8      |
| 13        | CLK    | Clock          | J4.17         | PA27 | 27      |
| 14        | STB    | Strobe         | J4.19         | PA28 | 28      |
| 15        | OE     | Output Enable  | J4.21         | PA29 | 29      |
| 16        | GND    | Ground         | J4.9          |      |         |

<br/>
<img  width="320px"  src="./power_in.jpg"/>

<br/>
On the output data connector just replicates the input lines for a wire
another RGB led  panel display. 

The power supply connector needs 5 VDC @ max 3A. At this current all leds are 
on at maximum brightness. 


##Examples

<abstract>
Here are some user space example to use our RGB panel led. All the examples
are in Python and can be downloaded on your Arietta with a single git clone 
command.
</abstract>

Download the examples repository:

<pre class="terminal">
~# <b>git clone git://github.com/tanzilli/led-utils.git</b>
Cloning into 'led-utils'...
remote: Counting objects: ..., done.
remote: Compressing objects: 100% (../..), done.
Receiving objects: 100% ..., done.
Resolving deltas: 100% ..., done.
~# <b>cd led-utils</b>
~/led-utils# <b>./clock-py</b>
</pre> 
    
###Install PIL

All the utilities use the Python Interface Library to manage 
images, font, etc so before trying any example install PIL on
your Arietta G25 by typing:

<pre class="terminal">
# apt-get update
# apt-get install python-imaging
</pre>
    
This is the list of utilities available. If you can't run something
try to update your repository by typing: __git pull__.
        

<fieldset markdown="1">
### Example: Convert and display any image from web 

<blockquote markdown=1>
Let's see now how to convert an image to a byte array to be displayed on the led panel. 

We will use, for example, this 256x256 pixel jpeg image but the same concept is 
valid for any images:

<img src="./right_arrow.jpg">

Download this image directly on Arietta G25 using __wget__ and the image URL:

<pre class="terminal">
# <b>wget http://www.acmesystems.it/www/ledpanel_examples/right_arrow.jpg</b>
</pre>    

Now launch __convert.py__ with the local filename of the image:

<pre class="terminal">
~/led-utils# <b>./convert.py right_arrow.jpg</b>
------------------------
[1] <- Brightness -> [2]
[3] <-  Contrast  -> [4]
[5] <-   Color    -> [6]
[7] <- Sharpness  -> [8]
[q] <-   Rotate   -> [w]
[i] Invert color        
[r] Reset               
[s] Save                
------------------------
Select (space exit):
</pre>    

With the keys [1] and [2] changes the brightness until the arrow color 
became equal t the original. 

Pressing the [s] key it is possible to save a screenshot of the 
image with the name "__panel_xxxx.rgb__" where __xxxx__ is an incremental counter.

The __*.rgb__ file contains the raw byte array image at 3 bytes per color 
ready to be sent to __/sys/class/ledpanel/rgb_buffer__.

To display is return to the command line and type:

<pre class="terminal">
~/led-utils# cp panel_0000.rgb /sys/class/ledpanel/rgb_buffer
</pre>

<img src="./right_arrow_led.jpg">

If you collect some screenshots it is possible to create a simple animation
with a simple shell script like this:

<pre class="prettyprint">
#!/bin/bash
while [ 1 ]
do
	for f in *.rgb; 
	do
		cp $f /sys/class/ledpanel/rgb_buffer
		sleep 0.5
	done
done
</pre> 

## Design a 32x32 icon from scratch
    
If you need to design a 32x32 icon from scratch you could use [x-IconEditor](http://www.xiconeditor.com).

X-IconEditor is an on-line graphic editor to create favicon.ico icons for the web pages but 
you can download and convert the favicon.ico file generated with convert.py and display it
on your panel. 

<center>
<a href="http://www.xiconeditor.com/">
<img  width="640px" src="./x-iconeditor-screenshot.png"/>
</a>
</center>

Source code: [convert.py](https://github.com/tanzilli/led-utils/blob/master/convert.py)

</blockquote>
</fieldset>

##Demo gallery

### Example: Simple 2 digit countdown counter    

<blockquote markdown="1">

This example written in Python shows a count down from 99 to 0 using a full size TTF font.

<img src="./counter.jpg"/>

<pre class="minicom">
~/led-utils# <b>./counter.py</b>
</pre>    
    
Source code: [counter.py](https://github.com/tanzilli/led-utils/blob/master/counter.py)

</blockquote>

### Example: Sliding messages

<blockquote markdown=1>
This example, written in Python, shows a sliding message using a big TTF font

<iframe width="560"  height="315" src="//www.youtube.com/embed/SFXTDLlJQiI" frameborder="0"></iframe>
 
The RGB color and the message to display are given from the command line.

<pre class="minicom">
~/led-utils# <b>./text.py "text" R G B</b>
</pre>    
    
The R, G and B values are in range of 0 (off) to 7 (max)

Source code: [text.py](https://github.com/tanzilli/led-utils/blob/master/text.py)

</blockquote>

### Example: Sliding clock    

This example shows the system time in HH:MM:SS format using a big TTF font and slide the line horizontaly.

<blockquote markdown=1>
<iframe width="560"  height="315" src="//www.youtube.com/embed/Qszwey7jYl4" frameborder="0"></iframe>

The RGB color is given from the command line.

<pre class="minicom">
~/led-utils# <b>./clock.py R G B</b>
</pre>    
    
The R, G and B values are in range of 0 (off) to 7 (max)

Source code: [clock.py](https://github.com/tanzilli/led-utils/blob/master/clock.py)

Is available a demo version of this programm called __clock_demo.py__ which 
changes automatically the colors during the time sliding:

<pre class="minicom">
~/led-utils# <b>./clock_demo.py</b>
</pre>    

Source code: [clock_demo.py](https://github.com/tanzilli/led-utils/blob/master/clock_demo.py)
</blockquote>


##The Linux driver ledpanel.c

All the rgb led panel are generate in bit banging mode using
normal GPIO lines. To go as fast as possible a Linux driver written in C code
is required.

The driver I wrote can update the whole panel contents 
679 times per second leaving enough time to Linux
to do other jobs in the meanwhile.

The main routine of this driver is a callback function called by a hrtimer 
10800 times per second at interval of 92uS.

In just 22uS this routine check the brightness of each color and send a simulated 
pwm signal to any led (32 x 3 color = 96) on a single row then exit. It will be 
called again by the Kernel after 66uS.

The fully source code of this driver is available under GPL licence 
on GitHub: [ledpanel source on GitHub](https://github.com/tanzilli/ledpanel/blob/master/ledpanel.c)

###How the driver works

<center>
<img class="float" src="driver_scheme.jpg"/>
</center>

###Compile and install ledpanel.c

To compile ledpanel.c it is requested a Linux Ubuntu PC 
on where install the cross compiler toolchain and Linux Kernel sources:

* @article='compile_linux_4_1'

During the __make menuconfg__ be sure to enable the 
High Resolution Timer Support:

<pre class="minicom">
General setup  --->
	Timers subsystem  --->
		[*] High Resolution Timer Support  
</pre>

Clone the GitHub repository on your Linux PC:

<pre class="minicom">
$ <b>git clone git://github.com/tanzilli/ledpanel.git</b>
$ <b>cd ledpanel</b>
~/ledpanel$
</pre>

Compile the module by typing:

<pre class="minicom">
~/ledpanel$ <b>make -C ~/arietta/linux-4.1.10 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- M=`pwd` modules</b>
</pre>

and copy in inside Arietta G25

<pre class="minicom">
~/ledpanel$ <b>sshpass -p acmesystems scp ledpanel.ko root@192.168.10.10:/root</b>
</pre>

Open a command session on Arietta and load the Kernel module:

<pre class="minicom">
root@arietta:~# insmod ledpanel.ko
</pre>

Now you can try some example to show something on the display.

<!--<h1>Led panel microSD repository</h1>-->

<div class="row">
	<div class="col-md-2">
		<h2>Led panel</h2>
		<img src="/images/icon_microsd_image.jpg" class="img-thumbnail"/>
	</div>
	<div class="col-md-10">


		<div class="panel panel-default">
			<div class="panel-heading">
				<h3 class="panel-title">Kernel Linux 3.18.1 - Debian Wheezy 7.2 - WiFi</h3>
				<small>Version: 16-oct-2015</small>
				<br/>
				MicroSD contents for Arietta G25 to run Led Panel application
			</div>
			<div class="panel-body" markdown="1">
###Binaries

* First microSD partition files: [boot.tar.bz2](http://terzo.acmesystems.it/download/microsd/ledpanel-01/boot.tar.bz2)
* Second microSD partition files: [rootfs.tar.bz2](http://terzo.acmesystems.it/download/microsd/ledpanel-01/rootfs.tar.bz2)

###How-to create a bootable microSD
<small>A Linux Ubuntu PC is required</small>

* Format a microSD with gparted ([read more](/microsd_format)) and mount it
* Download the binaries
* Uncompress the binaries to the microSD with the following commands:
<pre class="terminal">
$ tar -xvjpSf boot.tar.bz2 -C /media/$USER/boot 
$ sudo tar -xvjpSf rootfs.tar.bz2 -C /media/$USER/rootfs 
</pre>
* unmount the microsd and try it on your Arietta

###Login data

* Login: <b>root</b> Password: <b>acmesystems</b>

###How to use

Access to WiFi LedPanel and go to these address from your browser:

* [http://192.168.0.1](http://192.168.0.1)

			</div>
		</div>
	</div>
</div>
			


##Related Links

* [IKEA RIBBA photo frame](http://www.ikea.com/it/it/catalog/products/00078051/?cid=it%7Cba%7Cgoogle%7Cmerchant%7C1x1%7Cside_banner%7C1)
* [The 10 best free Pixel Fonts](http://beeex.net/freebies/fonts/the-10-best-free-pixel-fonts)
* [The ImageDraw Module](http://effbot.org/imagingbook/imagedraw.htm#tag-ImageDraw.Draw.text)  
* [Font TTF](http://www.1001fonts.com/digital+clock-fonts.html)
* [PIL format](#https://infohost.nmt.edu/tcc/help/pubs/pil/formats.html)   
* [PIL examples](https://github.com/daviddoria/Examples/tree/master/Python/PIL) 
* [High Resolution Timers](http://elinux.org/High_Resolution_Timers)
* [Icon file format](http://fileformats.wikia.com/wiki/Icon)
* [x-Icon editor](http://www.xiconeditor.com/)
	</div>

</div>

@include='bio_tanzilli'

@shop='LPA-01-PCB'
@shop='LPA-01'
@shop='ARIETTA-G25'
@shop='ARIETTA-G25-256'
@shop='WIFI-2'
@shop='AN-WIFI-01'
@shop='LEDRGB-02'
@shop='LEDRGB-03'
@shop='PS5V10A'

## Similar products

@shop='HAT-A3-M'
@shop='TS802'
@shop='RV908'



