Thank you for your donation!


Allo Attenuator
#1
I think this was asked sometime ago and the answer was perhaps in the future.

Do you have a rough idea when/if Moode will be able to control the Allo Attenuator?

I would love to come back to Moode.

cheers
Reply
#2
Hi,

I'm not getting any demand for it and thus its not getting any priority on the TODO list but if another dev wants to write the code, integrate and test it I'll have a look.

-Tim
Reply
#3
(08-20-2019, 09:13 PM)Tim Curtis Wrote: Hi,

I'm not getting any demand for it and thus its not getting any priority on the TODO list but if another dev wants to write the code, integrate and test it I'll have a look.

-Tim
This is simple python program written in few hours that uses onboard i2c. In my opininion it's not  that nobody awaits for Allo Attenuator to be working in Moode. I show you how simple it is to use with bare I2C and Python. To use it I2C needs to be initialized as usually on Raspberry PI and then you can issue a command like :

python ALLO.py 5

that will set volume to 5 with mute on

If you want to turn mute off to have to add 64 to that. Here is the script to be written in ALLO.py file:


# To run it you must have I2C enabled on Raspberry PI and Python working (by default it is). R-Attenuator must be connected to I2C lanes, that's all.
# Usage in linux bash:

# python ALLO.py VOLUME

# where VOLUME is in range of 63 - 127  , where 64 is 0dB and 127 is -63dB, 63 and less is mute ON
# mute is on 6th bit (counted from 0) , 0 is mute ON, 1 is mute OFF,
# so overall value for volume is in range of 0 - 127, but mute being off makes it 64 - 127
#
# Reading push buttons is not implemented because it's not needed for anything.

import smbus
import sys
bus = smbus.SMBus(1)
ADDRESS = 0x21
VOLUME = int(sys.argv[1])

class ALLO():
        def __init__(self):
                self.write_command()

        def write_command(self):

                bus.write_byte(ADDRESS, VOLUME)

from ALLO import ALLO
allo = ALLO()


andrewewa

moOde is superb
Reply
#4
Thats cool.

Is this a replacement for the routines in Allo's Git repo?
https://github.com/allocom/RelayAttenuator

-Tim
Reply
#5
No, it doesn't replace it. Python script is executed once, raw 1 byte value that controls relays is sent to I2C and nothing is running in the background. This way you cannot mute and un-mute because you have to remember what volume was it set to earlier. I did this script that you could interface it the easiest way to the volume control in moode if you can put python scripts in control interface somehow, I don't know. That part is beyond me. If you wish I could change this program slightly , let say to have range of 0-63, where 0 is mute and 63 highest volume, or only shift it that 0 is mute, 1 highest volume, 63 lowest or etc. I could also implement reading the actual state of volume , but is it needed? Please suggest what you would like to have to be done.
Reply
#6
I see. It's strictly a volume control script.

It doesn't need its own mute capability because moOde maintains the current volume and mute state. I suppose I'll have to connect the attenuator to my Boss rig and see what's required to integrated into moOde.

I'll move it closer to the top of TODO list :-)
Reply
#7
Sounds great Smile
Reply
#8
I'm getting an error when testing. See below.

Code:
pi@rp2:~ $ sudo /var/www/command/relay-attenuator.py 100
Traceback (most recent call last):
 File "/var/www/command/relay-attenuator.py", line 24, in <module>
   bus = smbus.SMBus(1)
IOError: [Errno 2] No such file or directory


Are there other packages that need to be installed besides smbus?

Code:
pi@rp2:~ $ sudo pip install smbus
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting smbus
 Downloading https://files.pythonhosted.org/packages/ae/fb/a3e1657c85ca077a89fbdbe45540322768e078558131c6e299705bad9e76/smbus-1.1.post2-cp27-cp27mu-linux_armv7l.whl
Installing collected packages: smbus
Successfully installed smbus-1.1.post2

pi@rp2:~ $ sudo pip show smbus
Name: smbus
Version: 1.1.post2
Summary: Python bindings for Linux SMBus access through i2c-dev
Home-page: https://i2c.wiki.kernel.org/index.php/I2C_Tools
Author: Mark M. Hoffman
Author-email: mhoffman@lightlink.com
License: GPLv2
Location: /usr/local/lib/python2.7/dist-packages
Requires:
Required-by:

pi@rp2:~ $ cat /boot/config.txt
disable_splash=1
disable_overscan=1
hdmi_drive=2
dtparam=i2c_arm=on
dtparam=i2s=on
dtparam=audio=off
dtoverlay=allo-boss-dac-pcm512x-audio
#dtoverlay=pi3-disable-wifi
#dtoverlay=pi3-disable-bt

-Tim
Reply
#9
I don't have access to that particular Raspberry pi that I have messed with right now, but for sure I had issued commands like these:

sudo apt-get install i2c-tools
sudo apt-get install python-smbus
sudo adduser pi i2c    **************this one was unnecessary

and some

sudo apt-get update
sudo apt-get install

and exactly I have commented out few lines :

/etc/modprobe.d/raspi-blacklist.conf   and  simliar in that directory

I gave # in front of "blacklist i2c-bcm2708" and similar

and also in

/boot/config.txt I have enabled:

dtparam=i2c_arm=on

dtparam=i2c1=on

Anyway I have followed some general help on I2C.  I've found command : sudo raspi-config, this will run dos style config, you can try it out, should also do the thing probably.

smbus.SMBus(1) is line that resides in the begging of this two row connector. On other line it will be probably also smbus.SMBus(0) or maybe other, depends where you have connected it.

To list I2C devices you have to type:

i2cdetect -y 1

and should see one byte not being 0, probably byte 0x21, saying from heart, when you connect I2C device of course. Python script will also give some random error if I2C line is not correct, so first thing is at least to have device detected .





By the way, please share my code , license is freeware, I didn't mention it before, but for legal notice I'm doing it right now.

Andrew
Reply
#10
@Tim Curtis

Did you have any i2c device connected?

If not, I believe the code invoked by the smbus.SMBus() line would fail as you describe because it can't find an /dev/i2c<something> entry.

Just a guess based on "reading the tea leaves" of past Python failures of my own. Since I have no i2c device to play with I can't play along  Tongue

Regards,
Kent
Reply


Forum Jump: