Pitch Follower Potentiometer Inconsistency

Hey group,

I know this is a fairly simple problem, but I can't seem to figure out the inconsistency with my potentiometer.

I'm using a 20K slide pot (http://www.westfloridacomponents.com/P064/Slide+Potentiometer++Linear+NOS+Pot++20K+ohm.html, and the Serial data shows the analog reading from 0 to 1023 as a linear climb.

When I run the pitch follower example, the pitch plays from my 8ohm speaker properly, that is until I bring the slide back to 0 - the next time I slide it towards the 1023 end, the pitch jumps between about 4 different frequencies, and never returns to the original smooth range, unless I reset the Arduino. I thought the pot might be fried, but it works every time I reset, and I've even tried swapping another pot in, with the same result.

Any ideas/suggestions would be greatly appreciated. Thanks. :)

TonyStark

but it works every time I reset

So that means there is nothing wrong with the hardware and your problem is in software. You need to post the code.

It's the code included with the Arudino software:

/* Pitch follower

Plays a pitch that changes based on a changing analog input

circuit: * 8-ohm speaker on digital pin 8 * photoresistor on analog 0 to 5V * 4.7K resistor on analog 0 to ground

created 21 Jan 2010 Modified 4 Sep 2010 by Tom Igoe

This example code is in the public domain.

http://arduino.cc/en/Tutorial/Tone2

*/

void setup() { // initialize serial communications (for debugging only): Serial.begin(9600); }

void loop() {

// read the sensor: int sensorReading = analogRead(A0); // print the sensor reading so you know its range Serial.println(sensorReading);

// map the pitch to the range of the analog input. // change the minimum and maximum input numbers below // depending on the range your sensor's giving: int thisPitch = map(sensorReading, 100, 1000, 100, 2000);

// play the pitch: tone(10, thisPitch, 10);

}

I think the issue is with the tone() function. I'm having the same issue with my granular synthesis code:

/*
  granular synth
  pots on analog pins: 0,1,2
  speaker on digital pin: 9
*/

// pots:
const int pot1 = A0;
const int pot2 = A1;
const int pot3 = A2;
//values
int grainF = 0; // grain fundamental frequency
int grainR = 0; // grain frequency range
int grainD = 0; // grain delay
int grain = 0; // int for grains

int sensorValue = 0;  // value read from the pot

void setup() {
  Serial.begin(9600);
  pinMode(speaker, OUTPUT);
  randomSeed(1234);
}

void loop() {
  //read/map sensors
  sensorValue = analogRead(pot1);
  grainF = map(sensorValue, 0, 1023, 100, 1000);
  sensorValue = analogRead(pot2);
  grainR = map(sensorValue, 0, 1023, 0, 1000);
  sensorValue = analogRead(pot3);
  grainD = map(sensorValue, 0, 1023, 1, 256);
  
  grain = random((grainF - grainR), (grainF + grainR));  // sets the grain frequency range
  
  //Serial.println(grain); //debugging
  
  tone(9, grain, 15);
  delay(grainD);
}

If you check the serial monitor, the tone() function is receiving a properly randomized integer, but the speaker still outputs only about 4 different frequencies.

I think the issue is with the tone() function.

Thanks for the post, prowin. I’m pretty sure you’re right. I’ve found another tone library that works. Too bad Arduino hasn’t addressed this issue.

Too bad Arduino hasn't addressed this issue.

Arduino is open-source. You have access to the tone function code. If you think that there is a problem that can be fixed, fix it. Then, post the fix for comments and incorporation.

I believe the problem with tone() has to do with the latest version 20/21 of the Arduino IDE and has been identified and will be fixed in the next update.

Lefty

I got my code working with the full Tone library, you can find it here:
http://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation

/*
  Graindiuno Granular Synthesizer v0.2
  
  pots on analog pins: 0,1,2
  speaker on digital pin: 9
*/

#include <Tone.h>

// pots:
const int pot1 = A0;
const int pot2 = A1;
const int pot3 = A2;
//values
int grainF = 0; // grain fundamental frequency
int grainR = 0; // grain frequency range
int grainD = 0; // grain delay
int grain = 0; // int for grains

int sensorValue = 0;  // value read from the pot

Tone tone1;

void setup() {
  Serial.begin(9600);
  pinMode(9, OUTPUT);
  randomSeed(1234);
  tone1.begin(9);
}

void loop() {
  //read/map sensors
  sensorValue = analogRead(pot1);
  grainF = map(sensorValue, 0, 1023, 40, 10000);
  sensorValue = analogRead(pot2);
  grainR = map(sensorValue, 0, 1023, 0, 1000);
  sensorValue = analogRead(pot3);
  grainD = map(sensorValue, 0, 1023, 1, 128);
  
  grain = random((grainF - grainR), (grainF + grainR));  // sets the grain frequency range
  
  //Serial.println(grain); //debugging
  
  tone1.play(grain, 25);
  delay(grainD);
}