PATRON: DIY Synth

by noewwwwwww in Circuits > Arduino

1924 Views, 22 Favorites, 0 Comments

PATRON: DIY Synth

PATRON: DIY Synth

Introducing Patron, a DIY audio synthetizer done with Arduino R4! Patron is a full twelve keys synthetizer, can plays accords and modulate a waveform with ADSR. Read the instructables and build your own version of Patron, we want to see new features! This project was submitted to 'Creative Electronics', a Beng Electronics Engineering module at University of Málaga, School of Telecommunications.

Supplies

arduino-uno-r4-minima.jpg
Screenshot from 2023-12-07 11-10-39.png

1x Arduino R4 (Minima or Wi-Fi)

5x Potenciometers

16x Switches

12x 220 Ω resistances

1x 74LS157

1x 74LS153

1x 74LS158

1x Small Perfboard

1x Speaker and amplify

1x Power supply (could be included with the speaker)

1x AC connection cable

Single-wire cable


My tools:

1x Welder

1x Oscilloscope (optional)

1x Glue gun

1x 3D printer

Signal Generation

EDE16859-2A28-4EC6-97A0-D27A8FBF85DD.JPG
DAC-Digital-to-Analog-Converter-58474537.png

This project is a low level and intuitive way to generate music using an Arduino that can be modified to generate different sounds. The first step to obtain a musical waveforms is know how a DAC works. Digital to analog converter is a electronic subsystem that transform the value of him digital inputs into a analog value from a range. In our case, the arduino's DAC have 12 inputs so we can generate (in theory) 2¹² (4096) different voltages values, from 0 to 5 volts. For example, if we want a 2.5 volts output we should send a 2048 (half from total) to the DAC register. This way, the program will send periodically different values to "draw" the calculated waveforms. Even now you're probably wondering: What do you mean by periodically? Ok, if we want a frequency stable signal we need to set a timer at any frequency (in our case 40kHz) so all the periods could be the same than the others. From now we will name this frequency as "sample frequency". Why a timer? The program work using classic Arduino's delays but the audio quality could be affected.


Now, the waveforms may be generated. We used a simple method: checked the lower voltage level, the higher one and calculated for a specified time (frequency) how much we must add to a number to reach the higher level. This "increment" is a floating number, DAC just receive integer numbers so we need to cast this floating number to a uint16_t, this kind of data takes 16bits (DAC uses 12 bits but arduino's registers are 16 bits in length). We have programmed three different waveforms: sawtooth, triangle and square. Using a digital input connected to a push button the kind of sound can be chosen, press one time and the waveform will change. You can design your own algorithm and generate any signal you want, we're looking forward to seeing it! At first, our idea was generate different kind of signals such as FM modulation, noise bass... A second version should include them ;)

ADSR

download.png

Now, let's explain ADSR. Is just a envelope that modify the amplitude of the signal. If you doesn't use an ADSR , when the key will be pressed the sound will increase from zero to the max level and do it again to zero (released). Using an envelope the signal can take more time to reach the max level and different kind of sounds could be generated.


Attack: Is a time that begin when a key is pressed and ends when the signal reach the max level(each key has it own envelope).

Decay: Once the max level was reached in attack time the note will decrease till the value will be the same than "sustain".

Sustain: Is the level of the signal when the key is pressed. When attack and decay time finishes the signal keeps this level till it will be unpressed.

Release: Begin when the key is unpressed and set the time that the signal will take to down to zero again.

Software Design

About the software design: we created a library, Sound.h. There are parameters that interact with the hardware. At first, we tried to calculate the waveforms in real time using equations but the ALU isn't enough to calculate them in real time. Then, tried to save all the values of a period of each waveform into different look-ups tables but we ran out of RAM! Coding the ADSR thought about generating the waveforms using float numbers with increments and then casting it to integers of sixteen bits (thanks to Arcadio and Luis for those conversations about Nyquist). The code implement other functionalities: set the volume, set the frecuency, calculate the increments for each kind of signal, set mutual exclusion mutex for the ADSR and much more. In addition, I wanna say that the function that implement the key's logic is usable for other projects and easily could be modified to other projects. In addition, want to thank TriodeGirl and Grumpy_Mike for their conversations into Arduino's forum, they really helped me to find a good way to implement my idea, we took our DAC's configuration from her baremetal examples . And finally, thank to Lmtanco for him modification of a previous library that implement a debounce software code.

Keys Logic Design

ORCAD.png
download.png
PHOTO-2024-01-21-21-01-21.jpg
PHOTO-2024-01-21-21-01-15.jpg

We wanted a thirteen-keys keyboard so anyone who plays the instrument could use an octave. The R4 have just fourteen general input/output and more keys for control was needed. In consequence, the keys might be multiplexed in any way to reduce the number of digital pins used to read from this number of keys. Decided to use a three multiplex circuit, from three digital outputs (A[3:0]). The Arduino choose the key that will be readed by two digital inputs (the outputs of the multiplex's circuit). The control inputs must be connected directly to three input pins from Arduino (in our case D9, D10, D11). The outputs must be connected to two digital inputs (in our case D8 and D12). Be aware of using the D13 in Arduino R4 because it have a parallel LED wired onboard and could take enough current to cut down the voltage, therefore the board might read a low TTL level.

We used three chips to solve the problem, 74LS157, the chip have four multiplex two to one with a common input of control, 74LS158N, the same but her output inverted and the last chip is 74LS153, chip is a multiplex four to one, with two control input. For do the circuit, we need to connect her first buttons to the chip 74LS157, the rest of the button connected to the chip 74LS158N. The output of both chips are connected to the input of the chip 74LS153 and her output connnected to the digital input of the arduino. The control input of the chip 74LS157 and 74LS158N is connected at the same digital input of the arduino. The two control inputs of the 74LS153 are connected at the two different input of the arduino. Other inptus was connected to low logic level.

Hardware Design

fritzCircuit.jpg
CC2A6A58-DC97-414D-8631-081C59DD0911.JPG

First let's talk about the digital design for keys. Inputs of previous picture are wires connected to push buttons with a pull-down circuit, same as this schematic. Is easier weld all the buttons and their resistances, then connect the input wires to their nearer buttons. In the code, all inputs will be messy so you just need to check using the raw array (array_teclas[]) which index turn into 1 when you push any button. It's easier connect the wires according to their positions and then change the values in the code. Be aware of connect all wires well to the arduino and between them, any problem with the continuity will generate noise at the output. We designed the case to put a huge (and old) transformer and amplify that was recycled from trash (old PC sound system), probably using a custom or just newer amply and power supply the size of the case could be smaller. The amply have an internal buck that generate 12v, using the onboard R4's buck converter generated a 5v DC signal. An Oled Adafruit screen was going to be installed to see the current waveform, ADSR levels, synth's logo and more but we don't have enough time to make the library compatible with Arduino R4 so we cannot do it, so sad :(

Case Design

AAAAAAA2.jpg
download.png
download.png
PHOTO-2024-01-21-21-01-20.jpg

The draw is our first sketch, we discarded the idea because this kind of models can't be easily 3d printed. Chose the way of design our own case, more simple to spend less plastic and time designing it. The case must keep in all the components and not be free space because it will be bigger. Depend of the kind of used push buttons the lid's height will need to change, is easier print it (a little bit higher than needed) and then cut it by yourself. With this, you can adjust the keyboard's sensibility, changing the force applied to any key. If you use a different material than PLA just need to adjust radius of the file's holes and the height mentioned before.


The case is splitted in two pieces, the first is a rectangular base with the holes of the elements that we need to get out. There are one for the screen, five for knob, four for buttons, one for keyboard and a grid for the speaker. For the other piece, we made a thin plane with thirteen pillars for the keyboard's buttons. The keyboards was modified by us, making it smaller. The knob's model, keyboard first model and heart charm was taken from ThingiVerse. All our 3D files are published in Noewwww 's Thingiverse profile, using the same licences than this post.

Hardware Implementation

D788A646-3183-4B58-8E04-5BDE6824E6CD.JPG
EC2C801D-B1E5-4582-B90D-BF336D017969.JPG
JEJESCREWWWWW.jpg

Wire all of this was so funny when the system works but we wanted to cry at times. There are too much junctions interacting between them. In order to improve your experience wiring this copper-hell we have a list of failures and tips:


  • Make sure that all finished subsystem works fine alone. If you try to implement different subsystems and doesn't prove their correct functions one by one, probably, when something fail, that will fail, find the error would be so difficult.
  • We've found so much problems, any of them will be as stupid as you thought that any chip was well placed but it's actually the other way around. Never think that something cannot fail, it will do it at first!
  • If you can't use an oscilloscope to see the waveforms use an microcontroller (other arduino) with an ADC-read program to see the signals and be aware about what are you generating.
  • Be aware with the connections to AC because sometimes is easy forgot that it can kill you in a second. Please try to probe the systems using a lab power supply and when the AC will be connected check that your socket is connected to a electric differential automatic.
  • Try to check all the connections using a continuity mode in your multimeter. It will help when are dozens of junctions!
  • Remind that this kind of buttons have a couple of wires for each node. Must use this to connect VCC to all of them from the previous one, the first must be wired to the PCB.
  • We forgot include some mechanism to close the case. It was solved melting the plastic with the weld by three points, then glued a nut to the case below each hole. A homemade way to finish the case!

At last, want to remind you'll that the most important part of any project is enjoy the way, don't care if it doesn't works and you need to change the entire projects multiple times. Journey before destination!