Reading audio signal from analog input 0?

Hey, I made a little effects (Lo-fi Guitar Pedal)unit that I saw on the instructables.com website from a post by Kyle McDonald.

I made a mono version and the pedal works grand until I try to read the audio signal from analog input 0. As soon as I put in the lines of code necessary to read from the input pin the pedal ceases to work and only emits a continuous hum. Also when I look at the serial monitor it is reading in a continuous stream of values around 504. If I pluck a string on the guitar the values change very slightly. I’m trying to send this data into a Processing sketch.

Here is some of the code with the Serial library lines that I added:


#include “dsp.h”
#include “interface.h”
#define BAUDRATE 9600
#define audioIn 0
#define wait 10

int val = 0;
void setup() {

Serial.begin(BAUDRATE);

pinMode(redPin, OUTPUT); //Sets Pin9 as the red led output
pinMode(greenPin, OUTPUT); //Sets Pin10 as the green led output
pinMode(yellowPin, OUTPUT); //Sets Pin12 as the yellow led output

setupIO(); //calls the setupIO function

}

short prev, originalInput;
void loop() {

updateInterface();
if(delayed > delayLength) {
originalInput = analogRead(left);
short input = originalInput;
switch(mode) {
case bitcrush:
input = input >> value10 << value10;
break;
case bitshift:
input = (input << value10);
break;
case overdrive:
input = (int) (512 + (value20 * (input - 512)));
break;
case binary:
switch(value6) {
case 0: input = input & ~prev; break;
case 1: input = input ^ prev; break;
case 2: input = ~(input | prev); break;
case 3: input = ~(input ^ prev); break;
case 4: input = ~(~input & prev); break;
case 5: input = ~(input & prev); break;
}
break;
}
output(left, input);
output(right, input);
prev = input;
delayed = 0;
}
delayed++;

val = analogRead(audioIn);
Serial.println(val);
delay(wait);

}

void updateInterface() {
if(interfaceUpdate > interfaceSamplerate) {
knoba = analogRead(knobaPin);
knobb = analogRead(knobbPin);
knobc = analogRead(knobcPin);

mode = knoba / modeSpacing; // knoba quantized into mode values
value6 = knobb / 171; // knobb quantized into [0-6]
value10 = knobb / 103; // knobb quantized into [0-9]
value20 = 1 + ((float) knobb / (float) 52); // knobb scaled to [1-20]
delayLength = knobc >> 2;

alternatePin(yellowPin, mode);
digitalWrite(greenPin,
originalInput == 0 ||
originalInput == 1024 ||
(originalInput > 496 && originalInput < 528) ? LOW : HIGH);
switch(mode) {
case bitcrush:
case bitshift:
alternatePin(redPin, value10);
break;
case binary:
alternatePin(redPin, value6);
break;
case overdrive:
digitalWrite(redPin, LOW);
}
interfaceUpdate = 0;
}
interfaceUpdate++;
}

void alternatePin(int pin, int value) {
digitalWrite(pin, value % 2 == 0 ? LOW : HIGH);
}


Sorry if what I’m trying to do doesn’t make sense but I’m new to Arduino and also new to writing code.

I would be very grateful if someone could suggest a way to make this work or even if it is possible at all!!

Cheers!

Do you have a link to the pedal circuitry and how you are wiring it to the Arduino?

A basic problem is that audio is an AC voltage and the Arduino analog input is designed only read dc voltages in the 0-5vdc range. Without some external electronics to rectify, filter, and scale the voltage, the reading you are now getting are bound to be useless.

Lefty

Yeah I have a voltage divider circuit that is creating a DC offset to bring the voltage up to between 0 and 1.1V.

Here is a link to the schematics that I worked from:

http://www.instructables.com/id/SMYVM2DFJBXD091/

Will it be possible to read any useful real time data in this way or am I just being crazy? What I'm basically trying to do is to read some form of data in real time to affect visuals on screen through a Processing sketch.

Thanks for your help!

Will it be possible to read any useful real time data in this way or am I just being crazy? What I'm basically trying to do is to read some form of data in real time to affect visuals on screen through a Processing sketch.

I really can't say. It's not something I've ever attemped to do, processing audio inputs. Maybe someone else around here can give you better opinions on your application.

Good luck;

Lefty

Ok, thanks anyway!!

I’m not sure if this will be helpful… to be truthful I didn’t read through it, but I seen it on the Playground, maybe it’ll help.:smiley:

http://interface.khm.de/index.php/lab/experiments/arduino-realtime-audio-processing/

Hey, yeah thanks very much! there’s stuff about interrupts in there that might be useful.

Much appreciated!!