Monday, May 30, 2016

Circuit Bending Basics: Two Easy Ways of Triggering Buttons on Toys

Introduction 
It may be desirable to trigger a button on a toy using MIDI or some other type of data. For instance, a toy generates sound when one or more buttons are pressed. Instead of physically pressing the buttons, note on / note off events can be used to simulate the pressing of buttons.

To achieve this, consider common the types of connections that may be found in toys in terms of button interaction. Whenever a button or a switch is pressed, normally a circuit is closed by connecting two conductors. This is commonly achieved by having a conductive pad attached to a button which, when pressed, physically and electrically connects two previously separated conductive surfaces, as in the image below.



There are a number of ways in which such a button may be wired:

1) One pin of the button is connected to a pin on the microcontroller of the toy, and the other pin is connected to the positive terminal of the battery (may also be labelled Vdd or Vcc)

2) One pin of the button is connected to a pin on the microcontroller of the toy, and the other pin is connected to the negative terminal of the battery (may also be labelled Vee or Vss)

3) One pin of the button is connected to a pin on the microcontroller of the toy, and the other pin of the button is connected a different pin on the microcontroller of the toy

4) It is unknown or difficult to tell where one or both of the pins of the button is connected to

In the methods given below, a Teensy LC or Teensy 3.1 is used to trigger the button connections of a toy using MIDI note data. This simple guitar toy is used as an example. Naturally, these concepts can be expanded to include multiple buttons, different data types etc.




Using A Digital Pin as a Trigger
If the button in question is in category 1 or 2 of the four possibilities mentioned above, then it may be possible to use a digital pin on the Teensy to directly trigger the button connection.

The idea is straightforward - on side of the switch is connected to positive or negative, and the other side of the switch is connected to a pin on the microcontroller of the toy.

When the button is pressed, the positive or negative terminal of the battery is then connected to the pin on the microcontroller of the toy, thus registering a high or low signal and triggering the sound.

The Teensy can act as a replacement for the positive or negative terminal of the battery in this instance, and provide a high or low signal to simulate the connection of the battery to the input pin of the microcontroller.

The great thing about this is that the connections from the Teensy to the toy are very straightforward, as it is simply a matter of connecting the digital pin on the Teensy to the micrcontroller pin of the button of the toy.

If there are inconsistent results, note that it may be necessary to either:
• connect the ground of the Teensy to the negative battery terminal of the toy or
• remove the battery of the toy and power the toy from the 3V pin on the Teensy (assuming a total voltage in the range of 3V - 4.5V)


Consider the simple guitar toy. The connections of one of the buttons that triggers sound on the toy are shown above. Note that the manufacturer has conveniently labelled the two pins of the button with VDD and P11. VDD is connected directly the positive terminal of the battery, and P11 is connected to the microcontroller of the toy.

As a result, whenever a high state is registered on the pin marked P11, the toy assumes that the button has been pressed and the sound is triggered. Whenever a low state is registered on the pin marked P11, the toy assumes that the button has been depressed.

In this example, it is also necessary to power the guitar toy using the Teensy.




Three connections from the Teensy to the guitar toy are necessary to directly trigger P11:
• The battery is disconnected from the toy
• Ground from the Teensy to the point on the circuit board where the negative terminal of the battery was connected (white alligator lead)
• 3V from the Teensy to the point on the circuit board where the positive terminal of the battery was connected (red alligator lead)
• Teensy digital pin 0 to connection P11 on the guitar toy (black alligator lead)



Example code is shown below. Note that if this method is used (and the code expanded upon), each digital pin on the Teensy can be theoretically used to trigger a different button on a toy or multiple toys.



A demonstration video is shown of this setup. Note that the fastest triggering rate is approximately 45ms. Ableton Live is used to drive the data.







Using a 4066 IC to Simulate Button Presses
Although the above method will work in certain situations, a more complex method may be used in the following situations:
• One pin of the button is connected to a pin on the microcontroller of the toy, and the other pin of the button is connected a different pin on the microcontroller of the toy

• It is unknown or difficult to tell where one or both of the pins of the button is connected to


This method will use the 4066 IC to simulate button presses. This chip is a fourteen pin quad switch, meaning that the switch has the facility to make and break connections for four pairs of points. Each pair of connections can potentially be connected to pairs of button pins on toys to simulate button presses

The 4066 is shown below:

The pin functions are as follows:
Vdd - positive terminal of power supply
Vss - ground
in / out - one point on a switch, labelled A, B, C and D
out / in - the other point on a switch labelled A, B, C and D
control - the control mechanism that determines whether or not a particular switch is currently open or closed, labelled A, B, C and D

By applying a low signal to the control pin of a switch, the in / out and the out / in pins are disconnected. By applying a high signal to the control pin of a switch, the in / out and the out / in pins are connected.

In terms of connecting this chip to the Teensy and the toy, the following setup is required:
• Vss Pin 7 of 4066 to Teensy ground - an orange breadboard jumper
• Vdd Pin 14 of 4066 to Teensy 3V - another orange breadboard jumper
• Control A Pin  13 of the 4066 to Teensy digital pin 0 - a green breadboard jumper
• In / Out of Switch A Pin 1 of 4066 to toy button pin (in this case P11 on the guitar) - the black alligator lead
• Out / In of Switch A Pin 2 of 4066 to the other toy button pin (in this case Vdd on the guitar) - the red alligator lead

These connections are shown below:





Example code is shown below. Note that if this method is used (and the code expanded upon), each of the four 4066 switches can be theoretically used to trigger a different button on a toy or multiple toys. The code is identical to the previous method.



A demonstration video is shown of this setup. Note that the fastest triggering rate is approximately 56m - significantly slower than the previous method. Ableton Live is used to drive the data.

0 comments: