Monday 14 September 2020

Helios-ONE Arduino synth - Part 4 - Final Code



**Update**
**End of update**

It's taken a while but part 4 of the code is finally ready.  This version adds an LFO, with an on/off switch and two pots controlling the rate and amount;

Newest Code Version 4.6

On top of the previous bill of materials, you'll need 

x2 10k pots

x2 220 Ohm resistors

x1  On/Off switch (2 way)

If you're starting from scratch, here's the complete BOM:

TIP: Connect the ground for the headphone out as far away from the ground from the 6n138, as it picks up noise.

Code Explanation;

For those wanting to know more about the new code, I'd suggest looking into the following links. The LFO was based on the Mozzi example code 'State Variable Filter' (which is a filter that's being modulated with an LFO), you should load that up, then compare it to these versions where I gradually add pots to the original sketch;

1. State Variable filter with 1 pot added

2. State Variable filter with 2 pots added

Then compare the latest version of the Helios ONE code (v4.6) to the older 3.1 code, to see how it was all added in.

Problems with the code;

The biggest problems were the synth would break into distortion then stop working, and also the filter frequency was changed by the LFO amount.  The first problem was solved by trial and error, gradually changing the filter and LFO pot-map values, and also further adding resistors to the pots. I also changed the shift value in the audio update section from 8 to 10. This reduces distortion, but also make the synth quieter.  These final values seemed to be the best trade off (feel free to correct me).  

Using an Arturia keystep controller while playing the highest notes, with filter on full, LFO on full, it now doesn't crash. There's perhaps a touch of distortion, but not enough to worry about. It's possible due to tolerances between pots/resistors, you might have to slightly change values if you experience problems. (btw. I checked my pots with a multi-meter and picked the ones closest to 10k).

The second problem, where the filter frequency was being changed by the LFO amount, I still haven't fully solved, unless you count changing from calling it a problem to calling it 'character'. That seemed like the best solution to me.  I think the problem comes from the update audio part of the code, as I wasn't fully sure how to implement two filters together so I ended passing one through another (SVF & LPF);

int updateAudio(){
int asig = (envelope.next() * oscil1.next()) >> 10; // multiplying by 0-255 and then dividing by 256
int asigSVF = svf.next(asig); // SVF
int asigLPF = lpf.next(asigSVF); // LPF
return (asigLPF);
}

 One day I'll come back to it a figure it out, but for now it'll do.  Give me a shout if you've got the answer.

Is this the final part?

I think for now, the code is finished.  The main aim of this synth was to build something as simply and cheaply as possible, but also something that could be considered an instrument.  I love the Atari punk console, but this is no harder to build but is far more playable.  Hopefully you may have learnt enough to be able to expand the synth yourself (or at least fix my errors). Hint: look at the mozzi examples and steal them :-)

I think you could build this synth for about £10, especially if you were to buy enough parts to make a few.  It's all open-source, so feel free to make some and sell them, I'd love to see people playing it.

The future

With the simplest version now mostly finished, I have a few plans; either make a tutorial about soldering it together then putting it in a case, or build a more advanced Rev 2 version.  If I go straight to the Rev 2, then I'll add a case tutorial after that.

The Rev 2 version would have an analog filter, analog distortion and a digital delay (all fun things).  Using an analog filter would also mean we could get rid of the digital filter, freeing up two more pots for something else (full ADSR?).  It would also solve the problem of the LFO affecting the digital filter.

Further into the future I'd like to make a polyphonic version and an FM Synth.  For these we'll need a more powerful micro-controller (about £20), but we'll also be able to add more pots.  

At the rate I move, this should be within the next 20 years.

Cheers!

Previous Parts

Part 3 - Adding a Low Pass Filter

Part 2 - Adding an envelope to our synth

Part 1 - MIDI controlled Oscillator with Wave switch

10 comments:

  1. Awesome!!! Excited to try it out.

    ReplyDelete
    Replies
    1. Cheers! I hope it's not disappointing... I'll hopefully get around to improving it at a later date

      Delete
  2. Excellent series.
    This is on my to-do list, and will probably be bumped to top of the list with priority 1.. just got to go get myself some Midi sockets.
    And yes, I shall build all 4 versions, I have to do something with my 30+ Arduino's.

    Question: Do you see an issue with running these on either the Nano, Pro Mini or STM32 boards ?

    ReplyDelete
    Replies
    1. Hey Lance! I'm in the process of writing a tutorial of how to build this synth from scratch - I'll be using a nano for this, which I believe works without any other changes (although I have noticed a nano has an extra analog pin, so it would be possible to add an extra knob/function). I haven't finished building it yet but I'll hopefully get it published soon (well, maybe a month or two!). I'm not so sure about the pro mini or STM32. Perhaps they would be fine, but Mozzi (the arduino synth library used) might not be compatible... perhaps read the mozzi forums before you buy anything?

      Delete
  3. Good stuff. Thank you for sharing.

    ReplyDelete
  4. Thank you for sharing this. I am trying to upload the sketch to an Arduino Nano (from what I can tell it is compatible is this correct?
    I get the following errors when uploading and wondered if you could help please? I'm very new to all of this.

    C:\Users\Ian\Documents\Arduino\sketch_oct09c\sketch_oct09c.ino:61:0: warning: "CONTROL_RATE" redefined
    #define CONTROL_RATE 128 // powers of 2 please

    In file included from C:\Users\Ian\Documents\Arduino\sketch_oct09c\sketch_oct09c.ino:6:0:
    C:\Users\Ian\Documents\Arduino\libraries\Mozzi-master/MozziGuts.h:46:0: note: this is the location of the previous definition
    #define CONTROL_RATE 64

    text section exceeds available space in board
    Sketch uses 16542 bytes (115%) of program storage space. Maximum is 14336 bytes.
    Global variables use 1162 bytes (113%) of dynamic memory, leaving -138 bytes for local variables. Maximum is 1024 bytes.
    Sketch too big; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing it.
    Error compiling for board Arduino Nano.

    ReplyDelete
    Replies
    1. Hi, think I have sorted it. The only issue I have now is that sometimes not every note will play. This may be due to the memory error above which I am not sure about. Thanks again for an awesome project

      Delete
    2. Hey Ian, glad you got it sorted... it looks like there was too much code trying to be loaded onto the nano. I guess you managed to reduce it? If it's skipping some notes, it could be that you've set the control_rate to high? If it's set at CONTROL_RATE 128, it means the processor is checking the knobs for movement 128 times per second (I think), which depending on how much other code you have running, means it might start skipping instructions to keep up (like when a video game gets bogged down by too many items being on screen). The more it checks though, the smoother the response of the pots are reported (like the smoothness of the filter etc), so you need to find the perfect balance between performance/responsiveness. A more powerful arduino wouldn't struggle as much (plus would have a larger amount of memory so you could load larger sketches). Cheers!

      Delete
    3. Thanks for the reply, much appreciated. I will have a look at the control rate and see if it makes a difference. Kind regards, Ian

      Delete

Say something...