Mozzi Library help, not sure why my Potentiometer isnt changing Frequency.

Hello, I have recently started a project for a 4 voice synth using Mozzi that is controlled via 4 Ribbon thin pot potentiometers.

not having much experience with coding I tried to see if I could edit an example from the library to control a basic sine waves frequency.

Using parts of code from “The Arduinitar Project” by Andrew McPherson Queen Mary University of London who had a similar idea, i thought i could make a simple program to do this.

in the serial monitor i am getting readings from the analogue pin, of 255 downwards, but i am not getting any changed output signal from the PWM pin 9.

I’m using an Arduino Mega

Any help would be great, thanks.

almost_working_ribbon_test.ino (3.47 KB)

Start by posting you code in a more accessible way

Please follow the advice on posting code given in Read this before posting a programming question in order to make your sketch easy to follow, download and test

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

If the code exceeds the 9000 character inline limit then attach it to a post

i am not getting any changed output signal from the PWM pin 9.

What determines which pin the output should appear on ? I see no sign of it in the code that you attached

thankyou for the quick reply, and also for helping me with finding a better way to post code, sorry again, really new with this stuff

Pin 9 is the default output pin for the Mozzi library, I haven't changed that at all in any of the libraries config files

#include <MozziGuts.h>
#include <Oscil.h> // oscillator template
#include <tables/sin2048_int8.h> // sine table for oscillator
#include <mozzi_midi.h>
#include <tables/sin2048_int8.h>
#include <tables/saw2048_int8.h>
#include <tables/triangle2048_int8.h>
#include <tables/cos2048_int8.h>
#include <AutoMap.h>
#include <Metronome.h>
#include <IntMap.h>

// use: Oscil <table_size, update_rate> oscilName (wavetable), look in .h file of table #included above
Oscil <2048, AUDIO_RATE> inBass;

const char INPUT_PIN = A0; // set the input for the knob to analog pin 0

// to convey the volume level from updateControl() to updateAudio()
byte pitch;
long out;
long finalOut;
// Basic pitch of the instrument (MIDI 45 = A2)
#define MIDI_NOTE_MIN (Q16n16)(33L << 16L)

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

void setup(){
  //Serial.begin(9600); // for Teensy 3.1, beware printout can cause glitches
  Serial.begin(115200); // set up the Serial output so we can look at the piezo values // set up the Serial output so we can look at the input values

  Serial.println(finalOut, BIN);

  startMozzi(); // :))

void updateControl(){

 static Q16n16 midiNote, midiNoteInt, baseFrequency;
  static long midiNoteFrac;

  // map it to an 8 bit range for efficient calculations in updateAudio
 pitch = mozziAnalogRead(INPUT_PIN);

 midiNote = MIDI_NOTE_MIN + (Q16n16)(pitch << 11);

 midiNoteInt = (midiNote + 0x00008000) & 0xFFFF0000; // Nearest MIDI note (Q16n16 rounding)
  midiNoteFrac = (long)midiNote - (long)midiNoteInt; /* Fractional part only */ /* Scale the fractional part */
  midiNote = midiNoteInt + midiNoteFrac;

   baseFrequency = Q16n16_mtof(midiNote);


  // print the value to the Serial monitor for debugging
  Serial.print("pitch = ");
  Serial.println(finalOut, BIN);

int updateAudio(){

 out = (;
  finalOut = (out);
  return finalOut;    

void loop(){
  audioHook(); // required here

Thanks for posting teh code in code tags. It really does make it easier to deal with

I have no idea whether it makes a difference, but the PWM output frequency on pin 9 of a Mega is 490 Hz whereas the frequency on pin 9 of a Uno is 976 Hz

How have you established that there is no PWM output on pin 9 of your project ?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.