Skip to contentSkip to author details


A 2-post collection

Controlling a 40106 Oscillator from Raspberry Pi

Written by Michael Earls
 diy  electronics  Lunetta  programming  development  synth  raspberry pi

I have been working with electronics lately moving slowly toward my end goal of creating circuits that can "create" their own "music".

As part of that journey, I have had to establish some baby steps in order to get there. Here are the basic steps I have accomplished so far:

  • Acquire a Raspberry Pi (or other microcontroller) - I chose the Raspberry Pi zero due to its small size (and great price- $5). I recommend the Raspberry Pi starter kit from Adafruit as it has everything you need to get started
  • Acquire basic electronic components - I ordered a lot of passive components (capacitors, resistors, transistors, jumper wires, breadboard, etc.). I've found that the best place to start is, then head over to Mouser Electronics for the little stuff (in big quantities), then All Electronics as a last resort. Adafruit Industries is the best place to buy add-ons, full kits, and great peripherals for your electronic projects.
  • Install an operating system on the Raspberry Pi - I am using Raspbian
  • Configure the WiFi using the serial cable (I don't have a USB hub, so I only had a single USB port on the Pi. This meant that I couldn't install the WiFi adapter and a keyboard & mouse). Once I had the serial adapter, I used PuTTY (I'm on Windows) to connect to the command line and configured WiFi from there
  • Once WiFi was configured, I installed an RDP server so I could use the Remote Desktop client to log into the desktop on the Pi. I rarely use this, but it's nice to have a desktop from time-to-time.
  • Install mono (cross-platform .NET runtime) - I use the C# programming language at my day job, so I'm comfortable with it. The Raspberry Pi supports many different programming languages, so pick the one you are comfortable with.
  • Install monodevelop on the Pi - monodevelop is the IDE that runs on Linux for developing .NET applications. This was not required, but I wanted to see if it would work. It did, without any issues.
  • Once I had the .NET runtime (mono) installed on my Pi, I opened up Visual Studio 2015 Community edition on my Windows 10 machine, added the raspberry-sharp-io NuGet package, and developed a simple application that toggles pin 7 (turning it on) when it starts up, waits for the user to press the ENTER key, then toggles pin 7 again (turning it off).

Here is the source code for my application (I learned the essentials from the raspberry-sharp-io wiki page):

using Raspberry.IO.GeneralPurpose;
using System;

namespace LunettaControl
  class Program
    static void Main(string[] args)
      var led1 = ConnectorPin.P1Pin07.Output();

      using (var connection = new GpioConnection(led1))

        Console.WriteLine("Press [Enter] to quit");


Now I had to set up a circuit on my breadboard that controls a 40106 oscillator so that I can turn it on or off using C# and the Raspberry Pi.

Here is my schematic:

Gated Oscillator Schematic Revision 2

The Raspberry Pi is providing +5v that drives the 40106 and the 4093.

The oscillator (pins 1 and 2 of the 40106) is cycling at a fairly low frequency, as controlled by the 1M resistor and the 470nF capacitor (I haven't timed it as I don't have measuring equipment, though I will be able to write some with C# when I get into input pin management on the raspberry-sharp-io library).

I can now use this to control each individual oscillator on the 40106 independent of one another.

The key to making this work is the NAND gate (pins 1, 2, and 3 of the 4093). When combining the signals from the Raspberry Pi (Pin 7 in this case) and the output from the oscillator on pins 1 and 2, we can control the output on pin 3 of the NAND gate.

IC 4093 Quad 2-input Schmitt trigger NAND Gate

4093 Quad 2-input Schmitt trigger NAND Gate IC

40106 Hex Schmitt trigger IC(Logic Gates)

40106 Hex Schmitt trigger IC (Logic Gates)

That means that when Pin 7 of the Pi goes high, it will raise pin 1 of the gate. Then, each time the 40106 oscillates (it is constantly oscillating as long as power is being sent to the IC), it will trigger pin 2 to go high, which causes the gate to go high on pin 3, thereby causing the transistor to pass +3v to the LED and lighting it up (I wanted to isolate the voltage of the LED from the +5v that's driving the oscillator and gate circuit as a proof of concept for managing components with different voltage requirements).

This schematic is actually bad design. I have a few errors (mostly due to using the transistor incorrectly, as well as using an NAND gate rather than an AND gate).

It seems to be working now, but I'm not sure if it's absolutely correct.

The frequency of the blinking is controlled by the oscillator (because pin 7 of the Pi is staying high based depending on whether or not the program is running). When the program stops running, pin 1 of the gate goes low and the gate remains closed, thereby stopping the blinking (oscillator output). Currently, the LED stays lit. I'm guessing this is caused by using a NAND gate rather than an AND gate.

I'd like to thank the following users for their assistance in getting this circuit working (from the Lunetta forum)

Also, the excellent Intro to Lunetta CMOS Synths document helped me get started. Without it, I would not have known what CMOS chips to buy initially.

Intro to Lunetta CMOS Synths

Here is the thread I created on for my question on gating an oscillator:

Clock signals through a Transistor

The following video is similar to my first video about blinking an LED using C#, but this time, the blinking is the result of the oscillation of the 40106, not a timer built into the program. This program simply toggles pin 7 to the "On" position until the user presses the key and then toggles it off again. This video was created before I modified the schematic and removed the indicator LED.

Why I really got back into electronics

Written by Michael Earls
 electronics  diy  music  hobbies  Lunetta  art

Why I really got back into this hobby

A few weeks ago, I stumbled on a DIY synthesizer community based on synthesizers called "Lunettas" (after Stanley Lunetta, the guy who pioneered the process). I'll let you read about it if you're interested.

Intro to Lunetta CMOS Synthesizers

Lunetta on Breadboard

Basically, Lunettas are CMOS-based (usually) integrated circuits that are setup to generate clock frequencies within the range of human hearing. The circuits are created using very inexpensive chips containing "oscillators", very much like the more expensive Moog or Eurorack alternatives (one Lunetta CMOS with six oscillators costs less than $0.50 while a single simple Eurorack oscillator costs about $150). However, the sound from Eurorack modules is more "mature" and musical, while Lunettas tend to be a bit "beepy" and chaotic.

An example of a Lunetta Synth

WARNING! Obnoxious beeping ahead!

I hope to change that by removing the annoying beeping sounds from the resulting output of my Lunetta device and replacing them with more musical results.

The possibilities are endless when you combine CMOS-based (along with some passive components to change clock frequencies driving the components) with a Raspberry Pi and software.

I have a lot of ideas, but every time I get a new Idea, I research the underlying theory and get caught up in the science of it all. The idea behind Lunettas is that they're supposed to be experimental and a way to just play around with circuitry to make cool sounds. I'm applying an enormous amount of brain energy thinking of ways to control the sounds based on theories like the General Theory of Generative Music (GTTM).

Honestly, I just need to sit down and play with these circuits before I can build my ultimate "smart" machine that "composes" its own music.

One of my biggest desires in life is to create a machine that can create art based on minor inputs from me and a little guidance along the way. I want it to "learn" how to listen to music, develop its own "tastes" and then create "music" based on what it has "learned". All of those words in quotes are because I'm not really trying to build a self-realizing AI, I just want to build a machine that creates art.
Google AI Deep Dream Artwork