Controlling a 40106 Oscillator from Raspberry Pi

Controlling a 40106 Oscillator from 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 CanaKit 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.