Tuesday, January 7, 2020

How to make Ambilight TV using Orange Pi Zero with any HDMI Input.


I have seen lot of how to do Ambilight using Raspberry Pi and not one with Orange Pi. This is a long pending project for me. I had an Orange Pi Zero 512 MB that I bought for the same purpose. I had to do more time on research than making it. Making was only a days job. Finding the right component and debugging took a lot of time. The end result of the project is more satisfying and came well than I had expected.

Materials required

Item  Quantity  Price per item Price(AED)
Orange Pi Zero 1 134.15 134.15
Comon board PCB dotted  1 4 4
Splitter HDMI Full HD 1 65 65
HDMI to Composite  1 35 35
Video Audio VHS VCR USB Video Capture Card 1 40 40
HDMI Cable  3 20 60
AV Cable 1 10 10
Power cable 1 20 20
Power Extention  1 45 45
5 Port Powered USB 3.0 Hub Splitter
, 4 Port USB Data Hub + 1 Smart 2.4A Charging Ports USB Hub
1 70 70
SN74HCT00N  1 0.5 0.5
Heat Sink 1 15 15
Power supply 20A 5 V  1 46 46
APA102 5M IP30 60 LED per meter 1 141 141
Shipping and other charges  1 100 100
Total 785.65

Bought from:
Orange pi Zero -
https://ar.banggood.com/Orange-Pi-Zero-H2-Quad-Core-Open-source-512MB-Development-Board-p-1110210.html?rmmds=buy&cur_warehouse=CN

SN74HCT00N 
https://www.aliexpress.com/item/32964289834.html
Heat sink for Orange pi
https://www.aliexpress.com/item/32801098575.html
Power Supply 20A 5V
https://www.aliexpress.com/item/32879719595.html
APA102 LED strips
https://www.aliexpress.com/item/32878004298.html


Other items are bought from local stores
careful choosing the video grabber, first one I bought did not work. Even though I was able to open the video in mplayer v4l2 of hyperion could not detect.
sample of the grabber
https://www.amazon.ae/0-2-Meter-Portable-Easier-Cable/dp/B07MW82Z7Z/


The Making

1. OS download from Armbian website.
https://dl.armbian.com/orangepizero/Bionic_current
The version I used is
Armbian_19.11.3_Orangepizero_bionic_current_5.3.9
2. Burn using balenaEtcher
Download from https://www.balena.io/etcher/
3a. connet ttltousb use putty and set baudrate 115200
https://www.aliexpress.com/item/4000120687489.html

Power up the Orange pi zero after connecting.
Find out the COM port number from device manager in windows.

3. login as root with password 1234
Create new user by following the instructions given by the armbian
4. Type the following command to configure wifi
sudo nmtui 
5. After configuring wifi (choosing SSID and filling password) update the OS using the below command
sudo apt update & apt upgrade 
(reboot after this. you can use armbian-config to do this too)
6. Login as new user
 sudo apt-get install git cmake build-essential libqt4-dev libusb-1.0-0-dev python-dev libxrender-dev python
export HYPERION_DIR="hyperion"
git clone --recursive https://github.com/tvdzwan/hyperion.git "$HYPERION_DIR"
 mkdir "$HYPERION_DIR/build"
 cd "$HYPERION_DIR/build"
cmake -DENABLE_DISPMANX=OFF -DENABLE_OPENCV=OFF -DENABLE_SPIDEV=ON -DENABLE_X11=OFF -DCMAKE_BUILD_TYPE=Release -Wno-dev ..
make -j $(nproc)
strip bin/*
sudo cp ./bin/hyperion-remote /usr/bin/
sudo cp ./bin/hyperiond /usr/bin/
 sudo cp ./bin/hyperion-v4l2 /usr/bin/
sudo mkdir -p /usr/share/hyperion/effects && sudo cp -R ../effects/ /usr/share/hyperion/
sudo mkdir -p /etc/hyperion
#copy hyperion.config.json to /etc/hyperion (SPI is 1.0 and color is bgr no-change as video standard) This file is attached in the link below
https://drive.google.com/open?id=1vGN3vltVbZdioBn_0Ww6Or3sBkS1JCYx

sudo mkdir -p /etc/init/ && sudo cp ../bin/service/hyperion.initctl.sh  /etc/init/hyperion.conf
sudo cp ../bin/service/hyperion.init.sh  /etc/init.d/hyperion
sudo cp ../bin/service/hyperion.systemd.sh  /etc/systemd/system/hyperion.service
sudo apt-get install v4l-utils
sudo systemctl enable hyperion
sudo systemctl start hyperion
Now add the user created to sudoers list and make it not to ask for password
sudo visudo -f /etc/sudoers.d/90-kiran
Add below line in the file. here kirant400 is the user name I have choose. Replace it with the one that you provided in step 3.
   
kirant400 ALL=(ALL) NOPASSWD:ALL
Finally edit /boot/armbianEnv.txt file to enable gpio and spi adding the below line
you can use command
sudo nano /boot/armbianEnv.txt
overlays=usbhost2 usbhost3 w1-gpio uart1 i2c0 spi-spidev
param_w1_pin=PA20
param_w1_pin_int_pullup=1
param_uart1_rtscts=1
param_spidev_spi_bus=1

Careful while editing this file if we make a wrong entry system do not boot and we have to redoo all the steps again

Final File content may look like:

verbosity=1
console=both
overlay_prefix=sun50i-h5
overlays=usbhost2 usbhost3 w1-gpio uart1 i2c0 spi-spidev
rootdev=UUID=abc1d3dd-6193-4fb7-93fb-f50382b8a8b9
rootfstype=ext4
param_w1_pin=PA20
param_w1_pin_int_pullup=1
param_uart1_rtscts=1
param_spidev_spi_bus=0
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u

Assembling 

Connection Diagram is given below
Connection of Orange pi Zero and APA 102 LED strips
I had double sided LED strips which was pasted on the edges of the TV Screen. Make sure the TOP and Bottom has same number of LED, similarly right and left has the same number.
Note these numbers. This is used for configuring the LEDs in Hyperion Config(https://hyperion-project.org/wiki/HyperCon-Information).


Connect both ends of +5 and GND together and to the 5V 20A power supply. Current rating depends on the number of LEDs on the screen.

Configuration

HyperCon is the software used for configuring.
Only configurations made are:
LED type selected APA102, color order is changed and SPIdev1.0 given below
                "type"       : "apa102",
"output"     : "/dev/spidev1.0",
                "colorOrder" : "bgr"
Other change was Enabled  grabber-v4l2 and standard manually edited value as "no-change" as given below
                "standard" : "no-change",

Other important change I did was to change the configuration of my grabber using v4l2-ctl command
First Install v4l2-ctl
sudo apt-get install v4l-utils
And now change the grabber setting
v4l2-ctl --set-fmt-video=width=640,height=480,pixelformat=1 

This I have added in the service script prior to hyperion service start. 

Working

After powering up all the mentioned connections our Ambilight is ready.

We can also download hyperion free mobile app and control the lights. This App is available for iOS and Android.

Troubleshooting 

I have first tested light alone using Arduino code before and after attaching to TV. 

For the grabber to check 
1) mplayer install and make sure it is being able to show the video input
2) use hyperion-v4l2 for taking screenshot and see if hyperion is able to get the grabber input. Below command is used for taking a screenshot 
sudo hyperion-v4l2 --width 320 --height 180 --screenshot

Also change the configuration to write to a file and inspect the file for RGB values if hyperion is able to detect.
I also change the BLACKBORDER detection  threshold to 0.2 for better detection.

1 comment:

  1. Alguno que diga si está funcionando y para que es el chip que se pega a la Orange pi ??

    ReplyDelete

Contributors