Auduino i/o

I have just started using the Arduino, Thought I'd try the Auduino but after downloading the sketch can only adjust the sound using analog input 4. No other pot affects the music tone or tempo at all. The pot on input 4 moves from a low frequency low pitch to high freq high pitch and sounds quite nice. I have loaded v5 sketch and also tried v4 both do the same thing. I notice in the sketch folder there is the v4 or 5 coding and also an applet folder. What is this for? I am powering the duemilanove board via the usb. it seems to accept the download ok. It seems i am missing something on such a great looking project. can anyone offer suggestions?

after downloading the sketch

Which sketch would that be? Can you give a llink or post your code (use the "code" (#) button, please) ?

Thanks for your quick reply
The code and project come from this link

Other people don’t seem to have any issues so I think its something i’m omitting when i upload the sketch??

// Auduino, the Lo-Fi granular synthesiser
// by Peter Knight,
// Help:
// More help:
// Analog in 0: Grain 1 pitch
// Analog in 1: Grain 2 decay
// Analog in 2: Grain 1 decay
// Analog in 3: Grain 2 pitch
// Analog in 4: Grain repetition frequency
// Digital 3: Audio out (Digital 11 on ATmega8)
// Changelog:
// 19 Nov 2008: Added support for ATmega8 boards
// 21 Mar 2009: Added support for ATmega328 boards
// 7 Apr 2009: Fixed interrupt vector for ATmega328 boards
// 8 Apr 2009: Added support for ATmega1280 boards (Arduino Mega)

#include <avr/io.h>
#include <avr/interrupt.h>

uint16_t syncPhaseAcc;
uint16_t syncPhaseInc;
uint16_t grainPhaseAcc;
uint16_t grainPhaseInc;
uint16_t grainAmp;
uint8_t grainDecay;
uint16_t grain2PhaseAcc;
uint16_t grain2PhaseInc;
uint16_t grain2Amp;
uint8_t grain2Decay;

// Map Analogue channels
#define SYNC_CONTROL         (4)
#define GRAIN_FREQ_CONTROL   (0)
#define GRAIN2_FREQ_CONTROL  (3)

// Changing these will also requires rewriting audioOn()

#if defined(__AVR_ATmega8__)
// On old ATmega8 boards.
//    Output is on pin 11
#define LED_PIN       13
#define LED_PORT      PORTB
#define LED_BIT       5
#define PWM_PIN       11
#define PWM_VALUE     OCR2
#elif defined(__AVR_ATmega1280__)
// On the Arduino Mega
//    Output is on pin 3
#define LED_PIN       13
#define LED_PORT      PORTB
#define LED_BIT       7
#define PWM_PIN       3
#define PWM_VALUE     OCR3C
// For modern ATmega168 and ATmega328 boards
//    Output is on pin 3
#define PWM_PIN       3
#define PWM_VALUE     OCR2B
#define LED_PIN       13
#define LED_PORT      PORTB
#define LED_BIT       5

// Smooth logarithmic mapping
uint16_t antilogTable[] = {
uint16_t mapPhaseInc(uint16_t input) {
  return (antilogTable[input & 0x3f]) >> (input >> 6);

// Stepped chromatic mapping
uint16_t midiTable[] = {
uint16_t mapMidi(uint16_t input) {
  return (midiTable[(1023-input) >> 3]);

// Stepped Pentatonic mapping
uint16_t pentatonicTable[54] = {

uint16_t mapPentatonic(uint16_t input) {
  uint8_t value = (1023-input) / (1024/53);
  return (pentatonicTable[value]);

void audioOn() {
#if defined(__AVR_ATmega8__)
  // ATmega8 has different registers
  TCCR2 = _BV(WGM20) | _BV(COM21) | _BV(CS20);
#elif defined(__AVR_ATmega1280__)
  TCCR3A = _BV(COM3C1) | _BV(WGM30);
  TCCR3B = _BV(CS30);
  TIMSK3 = _BV(TOIE3);
  // Set up PWM to 31.25kHz, phase accurate
  TCCR2A = _BV(COM2B1) | _BV(WGM20);
  TCCR2B = _BV(CS20);
  TIMSK2 = _BV(TOIE2);

void setup() {

void loop() {
  // The loop is pretty simple - it just updates the parameters for the oscillators.
  // Avoid using any functions that make extensive use of interrupts, or turn interrupts off.
  // They will cause clicks and poops in the audio.
  // Smooth frequency mapping
  //syncPhaseInc = mapPhaseInc(analogRead(SYNC_CONTROL)) / 4;
  // Stepped mapping to MIDI notes: C, Db, D, Eb, E, F...
  //syncPhaseInc = mapMidi(analogRead(SYNC_CONTROL));
  // Stepped pentatonic mapping: D, E, G, A, B
  syncPhaseInc = mapPentatonic(analogRead(SYNC_CONTROL));

  grainPhaseInc  = mapPhaseInc(analogRead(GRAIN_FREQ_CONTROL)) / 2;
  grainDecay     = analogRead(GRAIN_DECAY_CONTROL) / 8;
  grain2PhaseInc = mapPhaseInc(analogRead(GRAIN2_FREQ_CONTROL)) / 2;
  grain2Decay    = analogRead(GRAIN2_DECAY_CONTROL) / 4;

  uint8_t value;
  uint16_t output;

  syncPhaseAcc += syncPhaseInc;
  if (syncPhaseAcc < syncPhaseInc) {
    // Time to start the next grain
    grainPhaseAcc = 0;
    grainAmp = 0x7fff;
    grain2PhaseAcc = 0;
    grain2Amp = 0x7fff;
    LED_PORT ^= 1 << LED_BIT; // Faster than using digitalWrite
  // Increment the phase of the grain oscillators
  grainPhaseAcc += grainPhaseInc;
  grain2PhaseAcc += grain2PhaseInc;

  // Convert phase into a triangle wave
  value = (grainPhaseAcc >> 7) & 0xff;
  if (grainPhaseAcc & 0x8000) value = ~value;
  // Multiply by current grain amplitude to get sample
  output = value * (grainAmp >> 8);

  // Repeat for second grain
  value = (grain2PhaseAcc >> 7) & 0xff;
  if (grain2PhaseAcc & 0x8000) value = ~value;
  output += value * (grain2Amp >> 8);

  // Make the grain amplitudes decay by a factor every sample (exponential decay)
  grainAmp -= (grainAmp >> 8) * grainDecay;
  grain2Amp -= (grain2Amp >> 8) * grain2Decay;

  // Scale output to the available range, clipping if necessary
  output >>= 9;
  if (output > 255) output = 255;

  // Output to PWM (this is faster than using analogWrite)  
  PWM_VALUE = output;

Double check the wiring for your pots. Their drawing may be a little difficult for you to follow. All the right hand contacts of all the pots wire together and then on to the Arduino ground pin. All the left contacts of all the pots wire together and then on to the Arduino 5vdc pin. The center of each pots wires straight to a Arduino analog input pin. That is assuming standard pot layout with the center pin being the adjustable leg.


Yes I have the pots correctly wired 5 volts across the pot and the variable volt drop going in to each analog 0-4 inputs. Thanks for your reply. I'm thinking that the code I used is only part of what is needed? What is the applet folder for that comes with this code?

you can ignore the appletfolder. It's generated by the compiler and contains the files which are tranfered to your arduino

Thanks for your reply, so if i compile and download the code then others have had success so should I. I have checked the volt drop across each pot which is very close to 5 volts and the cetre lead seems to vary with the pot turning. Only other thing is the ground ing of inputs and output and powersupply or wiring?

all grounds need to be connected to each other

All fixed. It came to me as I was looking at a photograph of the Arduino board I had the audio out in pin 13 not pin 3!! So the lesson is get to Know the board and its pin numbering and check and recheck the wiring.
So now a few modifications to try like light sensitive resistors, microphones touch pads and also a permanent home instead of the cardboard box its mounted in.

Thank you all for your suggestions. much appreciated. :slight_smile: