Skip to content

vmendivil/InfraredVolumeAdjustment

Repository files navigation

What this project does?

This project is inteded to record IR signals from a remote controler, specially volume up and volume down signals, then read the volume level from a device and based on preconfigured parameters decide if the volume is above or below of what is an ideal level of sound and based on that send IR signals to the device to increase or decrease the volume in order to try to keep a constant level of sound.

The project can receive a parameter to decide what piece of code to execute which include just reading audio levels, or independantly sending IR volume up/down signals as well as running the application that will merge all the functionality to effectively read sound levels and send IR signals as needed.

BOM

Circuit Diagram

Circuit diagram source file is part of this repository. Frizting is the software tool used for its design.

Circuit Diagram

Analog-Digital Converter

Diagram is using a different chip because the drawing software didn't have the chip that was effectively used.

Correct chip is ADC PCF8591. Correct port mapping for the chip is displayed below. Physical connections in the diagram are correct and match PCF8591 pins.

PCF8591

Sound Detector

The diagram represents an audio input. Current implementation uses Sparkfun Sound Detector and uses Envelope pin output to determine the sound level.

Configure I2C

The i2c interface in raspberry is closed by default, it has to be open manually.

Steps:

1) Run command: sudo raspi-config
2) Follow path:
	a. 5 Interfacing Options
	b. P5 I2C
	c. Yes
	d. Finish
3) Restart Raspberry

To validate i2c module is started:

• Command: lsmod | grep i2c

Install i2c-Tools

• Command: sudo apt-get install i2c-tools

Detect device addresses (which will be used in the program):

• Command: i2cdetect -y 1

Restart Raspberry.

Functions

1) Record IR signals from remote controller.
2) Send IR signals from raspberry and IR transmitter to device.
3) Read and process data from sound detector
4) Define rules about how program will work to process sound levels from device and send IR signals to device.
5) Configuration of profiles and audio levels.
6) Manual adjustments of level on the fly.

Code and Libraries

This program uses F# and Python for different purposes.

F# is used as the main programing language to drive the logic that will read the sound level and will trigger the instructions to increase/decrease the volume level.

Python is used to have quick and easy access to pigpio library. This library provides an example on how to record and reproduce IR signals.

F# uses Unosquare.RaspberryIO NuGet package. Python uses pigpio library.

Install pigpio in Raspberry

Follow instructions: http://abyz.me.uk/rpi/pigpio/download.html

How to record IR signals from console

1) Connect IR receiver to Raspberry.
2) Download python pigpio script to record and reproduce IR signals.
	a. Link: http://abyz.me.uk/rpi/pigpio/examples.html#Python%20code
		i. IR Record and Playback: http://abyz.me.uk/rpi/pigpio/code/irrp_py.zip
3) Start pigpio daemon: sudo pigpiod
4) To record the GPIO connected to the IR receiver, a file for the recorded codes, and the codes to be recorded are given.
	a. Command: sudo python irrp.py -r -g4 -fir-codes vol+ vol- 1 2 3 4 5 6 7 8 9 0
5) Recorded signals get saved in a json file format
6) Stop pigpio daemon: sudo killall pigpiod

To get help on available commands and options, run command: sudo python irrp.py -h

How to playback IR signals from console

1) Connect the IR transmitter to Raspberry
2) Download python pigpio script to record and reproduce IR signals.
	a. Link: http://abyz.me.uk/rpi/pigpio/examples.html#Python%20code
		i. IR Record and Playback: http://abyz.me.uk/rpi/pigpio/code/irrp_py.zip
3) Start pigpio daemon: sudo pigpiod
4) To playback IR signals through the IR transmitter, we need to provide the file generated while recording IR signals and the commands that we want to reproduce.
	a. Command: sudo python irrp.py -p -g18 -fir-codes 2 3 4
5) Stop pigpio daemon: sudo killall pigpiod

Read data from Sound Detector

Sound detector functionality is explanied in the below link. We are using the Envelope output.

https://learn.sparkfun.com/tutorials/sound-detector-hookup-guide

Rules on how the program Volume Leveler program works

1) Program will be written in F#, why? Just for fun.
2) Program will call functions inside python script to record/send IR signals.
3) A range should be configured to determine acceptable audio levels.
	a. If above that range, reduce the volume.
	b. If below that range, increase the volume.
4) A maximum/minimum threshold of allowed IR signals must be configured to prevent indefinitely increase/decrease of volume.
5) Should provide the ability to select what profile/configuration will be used by the IR transmitter.
6) A rate per second read frequency should be configured for audio lectures.

How to run the program

The program follows some assumptions:

a) You have python installed
b) You have pigpio python package installed
c) You have dotNet installed
d) You can properly ssh into your Raspberry

API functionality will be added in the future.

Deploy app from outside the Raspberry

1) Clone repo
2) Open PowerShell and modify/run Deploy.ps1 script
	a. Script assumes you can ssh to your Raspberry.
	b. $SshPrivateKey must be the path to your private key
	c. Update the IP and path where you will be deploying your code

Run console app

1) Ssh to your raspberry and navigate to the folder where the code was deployed
2) Run program: dotnet AutomaticInfraredAudioLeveler.dll