EasyManua.ls Logo

adafruit learning system MAX9744 - Python Installation of MAX9744 Library; CircuitPython & Python Usage

adafruit learning system MAX9744
39 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Next you'll need to install the necessary libraries to use the hardware--carefully follow the steps to find and install these
libraries from Adafruit's CircuitPython library bundle (https://adafru.it/zdx). Our introduction guide has a great page on
how to install the library bundle (https://adafru.it/ABU) for both express and non-express boards.
Remember for non-express boards like the, you'll need to manually install the necessary libraries from the bundle:
adafruit_max9744.mpy
Before continuing make sure your board's lib folder or root filesystem has the adafruit_max9744.mpy file copied over.
Next connect to the board's serial REPL (https://adafru.it/Awz) so you are at the CircuitPython >>> prompt.
Python Installation of MAX9744 Library
You'll need to install the Adafruit_Blinka library that provides the CircuitPython support in Python. This may also require
enabling I2C on your platform and verifying you are running Python 3. Since each platform is a little different, and Linux
changes often, please visit the CircuitPython on Linux guide to get your computer ready (https://adafru.it/BSN)!
Once that's done, from your command line run the following command:
sudo pip3 install adafruit-circuitpython-max9744
If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use
CircuitPython on Python 2.x, it isn't supported!
CircuitPython & Python Usage
To demonstrate the usage of the amplifier we'll initialize it and control the volume from the board's Python REPL. Run
the following code to import the necessary modules and initialize the I2C connection with the amplifier:
Make sure some audio is playing through the amplifier, then you can control the volume using a few commands.
The first option is to set the volume property to an explicit value. This can be any number from 0 to 63 where 0 is
off/muted and 63 is maximum intensity (be careful, this amplifier can produce 20 watts of output which might damage
small speakers!)
For example to set a moderate half-way to max volume:
Or to mute/turn off the output:
import board
import busio
import adafruit_max9744
i2c = busio.I2C(board.SCL, board.SDA)
amp = adafruit_max9744.MAX9744(i2c)
amp.volume = 31
amp.volume = 0
© Adafruit Industries https://learn.adafruit.com/adafruit-20w-stereo-audio-amplifier-class-d-max9744 Page 35 of 38