JeroenSH, to linguistics
@JeroenSH@lingo.lol avatar

Don't be afraid of | Language Log, by Victor Mair

So says Stuart Jay Raj, a Thai-based Australian polyglot who speaks several tonal languages. Linked is a half-hour video by him which is heavy, but is actually an effort to simplify and systematize how tones work. For example, Raj makes a sharp distinction between and , something that many people get all mixed up about.

https://languagelog.ldc.upenn.edu/nll/?p=62127&utm_source=rss&utm_medium=rss&utm_campaign=dont-be-afraid-of-tones

diyelectromusic.wordpress.com, to random

This is a bit of an odd one, but I was asked to put something musically related together as a game to get in the spirit of the season, so I thought something along the lines of an Arduino adjustable tone generator with the aim being the player has to tune it by ear to as close to concert A – 440Hz – as possible.

This shows how I used my Nano Audio Experimenter Sheild PCB to do it. Note, as with most of my builds, this isn’t particularly mechanically satisfying, but it did the job 🙂

Warning! I strongly recommend using old or second hand equipment for your experiments. I am not responsible for any damage to expensive instruments!

These are the key Arduino tutorials for the main concepts used in this project:

If you are new to Arduino, see the Getting Started pages.

Parts list

  • Nano Audio Experimenter Sheild PCB.
  • Arduino Nano.
  • SSD1306 OLED display.
  • 1x temporary make, toggle switch.
  • Amplification and audio connections.
  • Power – either (micro) USB or a 7-9V barrel jack.

The Circuit

This uses the Nano Audio Experimenter Sheild PCB with the following configuration:

  • No DAC fitted.
  • Audio tone output via D3 through the audio output stage.
  • Audio GND jumpered across to digital GND via DAC header (see later).
  • SSD1306 OLED display fitted.
  • Switch connected to a free IO pin (recommend D4-D6).
  • No MIDI circuitry required.
  • Powered either by 7-12V barrel jack or 5V USB direct to the Nano.

https://diyelectromusic.files.wordpress.com/2023/12/arduino-frequency-game-1.png?w=1024The photo shows the key configuration options. To get an audio output whilst using PWM, the analog GND portion of the board needs connecting to the main GND. This can be done by adding a link between the two holes highlighted below:

https://diyelectromusic.files.wordpress.com/2023/12/nanoaudioexperimentershield-pcb-gnd-link.png?w=669In my case, as I’m using a pre-build PCB I’ve added a separate single-pin header socket which then can be used to jumper across these two connectors without removing the future ability to use a DAC again.

The frequency is set using all three pots. This gives a lot more variability as a game than using a single pot. The OLED display is used to show the frequency once it has been chosen. This happens while the switch is pushed.

The Arduino tone function will be used, which provides a 0-5V DC biased square wave output. Sending this through the audio filter and output stage means that the voltage is reduced (via the resistor potential divider) and the DC bias is removed (via the coupling capacitor) so it can be used as a more typical audio line output and connected to an old amp or similar.

There are a number of options where a GPIO pin is available via a header which can then be used to connect to a simple push switch:

  • Top: D9 is exposed in the PWM output jumper (which is set to select D3).
  • Far Right: D4-6 are exposed for use with an analog multiplexer.
  • Right: D7 is also exposed both in the jumper that can be used to set the behaviour of S4 and (assuming the jumper is actually set to make the link) D7 becomes exposed on the far right header too.
  • Far Right: A3 is also exposed on the far right header and so could also be used if required.

The downside of all of these is that my ready-made board requires header pin sockets which isn’t particularly robust for a game.

Advanced Option

But then I realised there is one additional pin exposed in a way that could still be used as an input but with a far more robust connector. D1 (TX) is linked to the MIDI OUT 5-pin DIN socket too, albeit via a 220Ω resistor. This means that I also have the option of connecting a switch across a 5-pin DIN Socket’s pins 2 (GND) and 5 (TX) and using that instead. The 5 pin DIN socket makes a much stronger and robust connection to the board, even if it is a little unconventional.

WARNING: The switch must NOT be connected between pins 4 and 5, which are the normal MIDI connections or from pin 4 to GND. Depending on the configuration used, there is a risk of connecting 5V to GND in the Arduino Nano and shorting something out. You might get away with it, depending on which resistors you end up having in the circuit (5V / 220Ω is just under 30mA), but it is really important to double checking the wiring before use!

Here is a “from the front/plug side” and “from the back/wiring side” view of a 5-pin DIN plug showing which pins are 5 and 2.

https://diyelectromusic.files.wordpress.com/2023/12/arduino-frequency-game-2.png?w=451Using D1 this way means that the serial port cannot be used (even though this project isn’t using MIDI) as TX is now being reconfigured as an INPUT.

RX isn’t an option as a populated MIDI circuit has an optoisolator between the external DIN socket and the GPIO pin.

Of course if a new PCB is being used, the MIDI section can be left unpopulated and it would then be possible to directly connect one of the MIDI sockets to either RX or TX. But for this project I’m just planning on reusing my generic, fully populated board, hence RX is not an option.

The Code

The basic tone generation is simply the Arduino tone function (more here). The frequency is a simple sum of the three potentiometers giving a range from 0 up to 3069. In musical terms this spans the range of notes from A0 (and lower) almost up to G7 (just over 3kHz).

Once the choice of frequency has been made, by ear alone, the button can be pressed and the display used to show both the frequency chosen and the numerical difference from 440Hz. The winner is the person closest to 440Hz.

To add an additional feeling of skill, but in reality to add a dose of luck, I’ve added two decimal points in the display which are actually randomly chosen each time the button is pressed. The idea being that if two players both get a pretty close 440Hz then the winner is essentially selected by random!

In order to avoid having to do decimal arithmetic in the code however, when calculating the difference I’m multiplying the frequency by 100, adding in the (random) decimal as if it was just a number between 0 and 99 and then comparing the result to 44000.

D3 is selected as the audio output and D4 is selected as the trigger button for the display using the following two lines:

int SPEAKER = 3;<br></br>int TRIGGER = 4;

Additional notes from the code:

  • I’ve implemented a software smoothing algorithm for the reading of the potentiometers in an attempt to remove some jitter. Although again a small amount of jitter brings another element of luck into the game.
  • When printing out, I have to take care of blank spaces in the frequency to keep the decimal point aligned for anything from 1 to 4 digits; but also have to allow for an extra leading zero in the case of randomly selecting a decimal in the range 0.01 to 0.09.
  • I’m using the Adafruit GFX and SSD1306 libraries for the Arduino.
  • When the button is pressed, the display changes to show the frequency. When it is released the frequency is hidden again.

https://diyelectromusic.files.wordpress.com/2023/12/img_7478.jpg?w=1024https://diyelectromusic.files.wordpress.com/2023/12/img_7479.jpg?w=1024Find it on GitHub here.

Closing Thoughts

This was a bit of a diversion and I could have easily knocked something up from solderless breadboard or stripboard with some pots and a display. But being able to just grab the PCB and experiment with the code made putting it together pretty easy.

Kevin

https://diyelectromusic.wordpress.com/2023/12/01/arduino-guess-the-frequency-game/

image/png
image/png

Hiker, to random

Habe euch noch ein Ton-Rätsel für heute Abend. Wer erkennt das?

eyesquash, to guitar
@eyesquash@mastodon.world avatar

I just read that #guitar #amp #wattage should be twice that of the #speakers, and that if too low, the sound will be muffled.
This may explain the #tone I get from my 5 watt tube amp through a Fender GE-412 300 watt cab.

caidan, to internet_funeral

My friend just showed me #tone #indicators because I mentioned I have a hard time reading tone through #text.

Would love to see these more in use across the #fediverse /gen

smallcircles, to random
@smallcircles@social.coop avatar

Two more nice Creative Tools added to the curated #delightful list maintained by @ADHDefy

https://delightful.club/delightful-creative-tools

#Graphite: Alpha-stage graphics editor for 2D raster and vector art, powered by a node graph compositing engine. It is lightweight and runs in your web browser.

https://github.com/GraphiteEditor/Graphite

#Tone: Audio tagger for dumping and editing metadata from multiple audio formats, such as FLAC, MP3, M4B, and more.

https://github.com/sandreas/tone

  • All
  • Subscribed
  • Moderated
  • Favorites
  • anitta
  • khanakhh
  • mdbf
  • InstantRegret
  • Durango
  • Youngstown
  • rosin
  • slotface
  • thenastyranch
  • osvaldo12
  • ngwrru68w68
  • kavyap
  • cisconetworking
  • DreamBathrooms
  • megavids
  • magazineikmin
  • cubers
  • vwfavf
  • modclub
  • everett
  • ethstaker
  • normalnudes
  • tacticalgear
  • tester
  • provamag3
  • GTA5RPClips
  • Leos
  • JUstTest
  • All magazines