How to create a low frequency oscillator (LFO) with an Arduino/ESP32/Teensy/etc (DIY)

  Переглядів 5,277

MoThunderz

MoThunderz

3 роки тому

In this tutorial I show how to use the class below to generate an LFO with an Arduino or HW compatible device (ESP32, Teensy, etc). The LFO is synchronized to the Arduino internal clock with the micros() command. This makes the LFO very stable and precise. The LFO frequency range is dependent on the host platform, but on an Arduino Due it scales from DC to ~1kHz.
NOTE: small correction about the roll-over from the micros() function -- this rolls over every 71 hours, not 71 minutes. In addition, this problem is resolved in the meantime in the examples provided with the library on Github.
Code: github.com/mo-thunderz/lfo
The LFO is part of the ADSR+LFO solution presented here:
Part 1: • Arduino based LFO+ADSR...
Part 2: • Arduino based LFO+ADSR...
See as well my other videos:
Arduino-based ADSR: • How to create an ADSR ...
Ableton-Arduino communication: • How to send data betwe...
Updates:
29.12.2020: updated code uploaded to Github where problem with _mode1_rate was fixed
22.05.2021: updated code with fix for roll-over after 71 minutes

КОМЕНТАРІ: 15
@matthieumongeon4040
@matthieumongeon4040 Рік тому
Awesom library and video! I'm really excited to use it on a project I'm working on. I'm having some trouble with generating the saw-tooth and triangle waves for some reason. I'm running the program on an arduino nano every and an external 12 bit DAC and it works great except for those two waves. Wondering if it's somehow not compatible with the arduino nano every's ATmega4809. I'm not really sure and not too well versed in C++ either so it's hard to troubleshoot.
@mothunderz
@mothunderz Рік тому
Hi Matthieu, thank you for your feedback. I have not tried out the code on a nano yet. It should not be dependent on that. I have to check if I have one somewhere... However, debugging is super easy for you. Just open lfo.cpp in some text editor (like notepad++) and scroll down to the bottom. The relevant function you need is: int lfo::getWave(unsigned long l_t) I am not 100% sure, but looking at the function I noticed that the two wave shapes you have problems with both have the DAC size in the routine whereas the other functions dont. Can you describe what the waveshape looks like when you configure these waves? Did you set the DAC size correctly? As a tryout you can set the DAC size very low (256 or so) and see if that works correctly. It might be a scaling problem. Good luck with your project! Sander
@mothunderz
@mothunderz 3 роки тому
Big thanks to Thomas for pointing out a simple fix for the roll-over problem after 71 minutes. By slightly changing the "if statement" this problem is resolved. I have updated the example codes on Github. For reference on the fix, please see: www.norwegiancreations.com/2018/10/arduino-tutorial-avoiding-the-overflow-issue-when-using-millis-and-micros/ @Thomas: I tried to answer to your comment, but some way or the other it does not show up in the list anymore, so instead here my answer as general comment. Thanks for contributing!
@redbackmike850457
@redbackmike850457 2 роки тому
Awesome. Can this library be used to create quadrature LFOs? I would like to program a quadrature LFO with both TRI and SAW outputs for use in Shepard tones.
@mothunderz
@mothunderz 2 роки тому
Hi Mike, yes, you can use the LFO library for a quadrature LFO. The easiest way is to just create 4 instances of the class in your Arduino code and set the phases to 0, 90, 180, 270 degrees. However, please do make sure that you have the LFO on lfo_class.setMode(1); -> this is the mode where the LFO can be synced to an external clock. That way you can create the 4 phases in 4 different class instances. With setMode 0 this wont work (you could implement that easily but that would mean adapting lfo.cpp a bit). Good luck with you project!
@VaibhavPandita
@VaibhavPandita 3 роки тому
And its you again! MORE RESOURCES YAYAYAYAYA permanent subscriber and imma mention you when i make it in my channel bro!
@mothunderz
@mothunderz 3 роки тому
Cool! Might you post a vid of ur project, let me know 👍
@stephengoss3604
@stephengoss3604 3 роки тому
Hey thanks for the code and the Ideas, would love use my Due as an LFO on my modular rig. I loaded this example code, but I cant see anything out of either of the 2 DAC outputs. Did I miss something?
@mothunderz
@mothunderz 3 роки тому
Hi Stephen, sorry to hear you could not get the LFO running straightaway. There could be quite a few reasons why it is not working for you. How did you measure the DAC output? Did you use a scope? I set the default freq to 30Hz, so you will need a scope to measure that. Did you get errors programming? Make sure you use the programming port of the Due. My example codes cycles through all wavelforms and this includes DC. I just realized that this can be tricky if you measure the DAC port at exactly the time the DAC is outputting DC (as this equals 0 per default). I have now removed DC from the example code online. Might this not help for you: I have uploaded a second example file called LFO_example_LED.ino to Github. Pls check if this one works for you. This one generates simple square pulses with gradual increasing frequency and writes it to the internal LED (port 13). If that works for you, it probably is the DAC you should focus on. Good luck! Let me know if you were able to find the fault.
@mothunderz
@mothunderz 3 роки тому
One more note: you will need to add amplification after the Arduino Due before you can use this signal for your modular rig. Please refer to my video below where I give an example of what such an amplifier can look like (at 58 seconds). ukposts.info/have/v-deo/jISBhG-bmqx7qWw.html
@kellenjaydon2017
@kellenjaydon2017 3 роки тому
Awesome 😍💋 💝💖♥️❤️
How to create an ADSR envelope with an Arduino/ESP32/Teensy/etc (DIY)
8:40
DIY VCO Part 1: The analog oscillator core anyone can build
27:09
Moritz Klein
Переглядів 410 тис.
Эта Мама Испортила Гендер-Пати 😂
00:40
Глеб Рандалайнен
Переглядів 9 млн
格斗裁判暴力执法!#fighting #shorts
00:15
武林之巅
Переглядів 7 млн
How to use a Rotary Encoder with an Arduino - CODE EXPLAINED!
21:11
MoThunderz
Переглядів 28 тис.
ESP32: How to create a config file with SPIFFS or LittleFS
12:46
MoThunderz
Переглядів 10 тис.
Building a MIDI Controller Using Arduino
15:41
Switch & Lever
Переглядів 619 тис.
Casper Electronics DIY synth building. Part 1: Oscillators
30:07
casperelectronics synthesizers
Переглядів 321 тис.
Raspberry Pi Looper/synth/drum thing
15:50
otemrellik
Переглядів 732 тис.
ESP32: Webserver, Websockets and JSON (WiFi Part 2) - Arduino
35:17
MoThunderz
Переглядів 73 тис.
DIY Teensy-based polyphonic synth
4:58
Florian Loretan
Переглядів 108 тис.
Modular Synth VCO Design & Build
14:38
vk2seb
Переглядів 79 тис.
Эта Мама Испортила Гендер-Пати 😂
00:40
Глеб Рандалайнен
Переглядів 9 млн