Monday, July 2, 2012

Using the Arduino PT2322 library for audio control

There are a limited set of audio volume & tone processors available on the market especially in an easy to use DIP format. The PT2322 is in common use in audio equipment around the world. However it hasn't been picked up by the Arduino community; most likely because of the lack of an available library. In the process of developing an internet radio around this chip and an MP3 decoder I created a library for the PT2322. The PT2322 is available from oddWires here.

The PT2322 is an interesting chip and is very flexible for audio control. It's designed as a 5.1 audio processor enabling you to control your audio setup from your Arduino. oddWires has the only library written for the Arduino for this device. Download it here: Library and Example. In addition to its designed use you could use the 6 channels to control an active loudspeaker system using 3 channels for hi/mid/lo over two channels. It's very cost-effective if you use any of the chip amps oddWires has on the site. There is also a PCB board for LM1875/TDA2030 chip amps available here.

PT2322 is a 6-Channel Audio Processor IC utilizing CMOS Technology specially designed for audio applications. 6-channel individual input, 6-channel master volume control, 6-channel individual volume trim control, 3-band tone control (treble, middle, and bass), mute function, 3D effect function, tone defeat function are all built into a single chip having the highest performance and reliability with few external components. The features are shown below.

  • Very Low Power Consumption (DC=9V)
  • I2C Bus Control
  • 6-Channel Individual Input
  • 6-Channel Master Volume Control: 0 to -79 dB (1 dB/step)
  • 6-Channel Individual Output TRIM Volume Control: 0 to -15 dB (1dB/step)
  • 3-Band Tone Control (Treble, Middle, Bass): + 14dB , 2dB/step
  • Mute Function
  • 3D Effect Function
  • Tone Defeat Function
  • Low Noise
  • High Channel Separation
  • Low Harmonic Distortion
  • Few External Components
  • Easy to Use
  • 28-pin DIP Package 
Functional Diagram

Constructing the PT2322 circuit

At first, the wiring diagram may seem to require a lot. In fact, much of the circuitry is repeated. It consists of impedence setting resistors & DC blockers on all the inputs and outputs. Then there are a set of RC circuits for shaping the treble, mid and bass response. Hooking up the Arduino is simple as the PT2322 is an I2C device using SDA & SCL. You'll hook these up to pin 4 and 5 respectively on your controller board unless you have an Arduino Mega where the pins are 20 and 21.  The chip works from 5 to 15V DC. I used the 9V supply used to power my Arduino. A regulated supply would be preferable. the oddWires PT2322 Library

Once you have it wired up, you're ready to start. You could program it directly using the standard Arduino Wire library but an easier solution is to use the library referred to above because it handles all the control necessary to drive the device per the datasheet to perform all of its capabilities:

      int init(void);
    void muteOn(void);
    void muteOff(void);
    void _3DOn(void);
    void _3DOff(void);
    void toneOn(void);
    void toneOff(void);
    void leftVolume(unsigned char flv);
    void rightVolume(unsigned char frv);
    void centerVolume(unsigned char cv);
    void rearLeftVolume(unsigned char rlv);
    void rearRightVolume(unsigned char rrv);
    void subwooferVolume(unsigned char sv);
    void masterVolume(unsigned char mv);
    void bass(unsigned char tb);
    void middle(unsigned char tm);
    void treble(unsigned char tt);

Just call init() first and then use the functions above as you wish. An example is supplied with the library. The example has additional functionality and shows how to use four buttons and a 16 x 2 LCD to display the current settings, change settings, mute etc.

The PT2322 is available from oddWires here.

Saturday, June 23, 2012

Burning a bootloader into a bare ATmega328


Burning the standard Arduino boot-loader onto a bare ATMEGA328 is fairly straightforward but the steps that make it a more streamlined process are not found altogether on the web. This post gives you all you need to do it yourself. If in the end you decide not to do it yourself you can get an ATmega328P with a boot-loader already installed here for $4.95.

You will be using an existing Arduino Uno or Mega as an ISP (In-System Programmer) to program a bare ATmega328 micro-controller. You do not require any ancillary components at all despite what you may have read elsewhere. Neither do you need any other software than the Arduino IDE. You will need to create a simple circuit on a breadboard that you will use to interconnect with the Uno/Mega.

Here are the steps:
  1. Prepare the Arduino environment
  2. Wire up the simple breadboard circuit
  3. Burn the boot-loader

Prepare the Arduino environment

The Arduino IDE is already set up for use with multiple boards. However you need to be able to specify the minimal bread-boarded ATMEGA328 as a target. You can enable the IDE for this by using a predefined boards.txt file. You can download the required boards.txt file in a zipped breadboard folder containing it here .

Once you have downloaded the zip file, unzip it and place the breadboard folder in a folder called hardware in your Arduino sketches folder.  You need to restart the Arduino IDE  to see an option in the Tools/Boards menu for ATmega328 on a breadboard (8 MHz internal clock). The reason it shows 8Mhz rather than 16Mhz is that you will be using the built-in internal clock on the ATmega328 of 8Mhz rather than an external 16Mhz clock to simplify the bread-boarding (no external crystal required).

Next you need to load the ArduinoISP sketch provided with the IDE. Just make one change to the sketch for Arduino 1.0. Locate the delay(40) in the heartbeat() function and change it to delay(20).

Make sure you specify Uno/Mega or whatever Arduino you are using as the programmer in Tools/Boards. Once you have done this you are ready to bread-board your ATmega328.


Wire up the simple breadboard circuit

This is taken from the Arduino tutorial that can be found here. Pin connections are per this table (all boards except the Mega use the Uno connections):

Arduino Programmer                      ATMega328 Target
Uno Pin   Mega pin  Function Function Pin
9 9  GND


+5V 7

11 51  MOSI MOSI 17
12 50  MISO MISO 18
13 52  SCK SCK 19

+5V 20

GND 22

Once you have finished bread-boarding you're ready to burn the boot-loader.


Burn the boot-loader

Select  Tools/Boards/ATmega328 on a breadboard (8 MHz internal clock).  Then  Tools/Burn Bootloader. You should see avrdude do its thing. The result should be similar to this:

################################################# | 100% 0.06s

avrdude: 1 bytes of lock written

avrdude: verifying lock memory against 0x0F:

avrdude: load data lock data from input file 0x0F:

avrdude: input file 0x0F contains 1 bytes

avrdude: reading on-chip lock data:

Reading | avrdude: Send: V [56] X [58] . [00] . [00] . [00]   [20] 
avrdude: Recv: . [14] 

avrdude: Recv: . [cf] 

avrdude: Recv: . [10] 

################################################## | 100% 0.02s

avrdude: verifying ...

avrdude: 1 bytes of lock verified

avrdude: Send: Q [51]   [20] 

avrdude: Recv: . [14] 

avrdude: Recv: . [10] 

avrdude done.  Thank you.

And that's it! Use your bootloaded ATMega328 as you like. Of course, if this sounds like too much effort you can get an ATmega328P with a bootloader already installed here for $4.95.