Showing posts with label circuit bending. Show all posts
Showing posts with label circuit bending. Show all posts

Tuesday, June 06, 2017

Interfacing with a Toy - Process and Example

Overview
There are many ways in which to interface a toy with an electronic system.

The main considerations are:

  • What types of control does the toy have? 
  • With what can these types of control be replaced? 
  • To what should the replacement of control be mapped? 
For example, take a simple button on a toy. This can be replaced with a relay, 40106-based oscillator, 4066 switch IC, 4051 multiplexer IC, digital switching mechanism, mercury tilt switch, magnetic switch, mechanical switch. This can be mapped from the physical world (tilting, magnetism), analog electronics (using the resistance of a pot of a 40106 oscillator to set the triggering speed), MIDI (note on, note off, CC, pitch bend etc), serial (on / off), ethernet etc. 

Let's examine an specific example of implementing this process. A simple toy phone was taken apart, and controlled via Teensy and USB-based MIDI.





In particular:
  • The battery pack was disconnected. 
  • The toy was powered by the Teensy instead of batteries.
  • The speakers were disconnected. 
  • The audio output of the toy was routed through a digital pot for volume control
  • All buttons of the toy were disconnected
  • Three of the buttons were replaced with a multiplexing setup
  • The resistor clock of the toy was removed
  • The resistor clock was replaced with a digital pot for pitch control
  • Velocity, pitch bend and note events were mapped to the toy

This example brings together a number of different ideas: 





Disassembly 

This is the toy featured in this example. Of particular interest was the camera click sound for the camera button. 


The toy is opened up, and the circuit board is visually and functionally explored. 


This is the close up of the circuit board. 


Functionally, there are a number of points of interest, labelled A to J in the image. 
  • Point A is ground, and is connected to the negative terminal of the battery
  • Point B is 3V, and is connected to the positive terminal of the battery
  • Point C is a speaker terminal connection 
  • Point D is the other speaker terminal connection 
  • Point E is the connecting pin for the third row of buttons in the button matrix
  • Point F is the connecting pin for the second column of buttons button matrix
  • Point G is the connecting pin for the third column of buttons button matrix 
  • Point H is a connecting pin for the play button, which triggers a sound
  • Point I is one connection for the clock resistor
  • Point J is the other connection for the clock resistor 
Of note is that the main matrix of nine buttons (on the front face of the toy) are connected to the chip via nine pins. Three pins (labelled on the circuit board as P13, P12 and P11) represent the rows, and another three pins (labelled on the circuit board as P20, P21, P22) represent the columns. 



When a row pin and a column pin are connected (by pressing a key, for example), then a sound is triggered. Three pins are set as inputs, the other three as outputs. 

The software can set two outputs low and one output high (for instance, column 1 high, column 2 low, column 3 low) and then measure on the other three pins (therefore row 1, row 2, and row 3). 

If a given row is measured as high, then the combination of the current column and the measured row indicates which button is pressed. This process is repeated for all three columns. 

By connecting Point E from the previous image to Points G or H, this is making these column to row connections - and as a result, triggering the sound. 


The speaker and batteries are removed. 










Soldering

A set of six wires are prepared. The end of each wire is stripped back a little, and a small amount of solder is added to each end of the wire. These six wires will be soldered to points E, F, G, H, I and J so that the connections for the button pressing and pitch bend can be made to a breadboard. 

This is the underside of the circuit board. Conveniently, points F, G and H are all through-hole connections, with a small copper area perfect for soldering on the front side. The wires can be sent through the holes from the underside, and then soldered to the front side easily. 


The toy is now completely removed from the casing. The black wire is ground, the red wire is 3V, the the white wires to the bottom of the board are the speaker connections. 


Four wires are soldered to points E, F, G and H. These will be connected to a multiplexer, so as to replace three of the buttons. In the case of point E, the copper surface had to be scratched back using a screwdriver - this made it possible to attach solder and hence the wire to it. 


The clock resistor is desoldered. One wire is soldered to point I, another wire is soldered to point J. In both cases, a small amount of additional solder onto the circuit board made it easier to connect the wire to the circuit board. 










Hardware Setup 


The toy is connected to a breadboard. The speaker outputs are connected to a digital pot. The key connections are connected to a multiplexer. The power supply terminals are connected to the 3V supply of the Teensy. 


The Teensy 3.6, 4051 multiplexer and MCP4241 digital pot are all placed on the breadboard. 

In terms of the breadboard setup, the following connections are made: 
  • Teensy ground to breadboard ground
  • Teensy 3V to breadboard power supply
  • Teensy digital pin 0 is connected to 4051 pin 6 (Enable)
    • This will enable a note on event to turn on a button, and a note off event to turn off a buttoin
  • Teensy digital pin 1 is connected to 4051 pin 11 (Address A)
    • This is bit 0 of the multiplexing address
  • Teensy digital pin 2 is connected to 4051 pin 10 (Address B)
    • This is bit 1 of the multiplexing address. Having 2 bits worth of addressing will allow the Teensy to control all three desired buttons
  • Teensy digital pin 10 is connected to MCP4241 pin 1 (SPI slave select)
    • This is the chip select signal for digital pot
  • Teensy digital pin 11 is connected to MCP4241 pin 3 (SPI master out slave in)
    • This is the data signal going from the Teensy to the digital pot 
  • Teensy digital pin 14 is connected to MCP4241 pin 3 (SPI clock)
    • This is the clock signal for digital pot
  • MCP4241 pin 4 is connected to ground
    • This is the Vss pin 
  • MCP4241 pin 14 is connected to 3V
    • This is the Vdd pin
  • MCP4241 pin 12 is connected to 3V
    • This is the shutdown pin, and is active when low
  • MCP4241 pin 11 is connected to 3V
    • This is the write protect pin, and is active when low
  • MCP4241 pin 8 is connected to the outside leg of a 1M potentiometer
    • The potentiometer will coarsely adjust the pitch of the toy
  • MCP4241 pin 9 is connected to one pin of the clock resistor on the toy
  • The middle leg of the 1M pot is connected to the other clock resistor connection on the toy
  • MCP4241 pin 5 is connected to ground
    • This is the grounding for the volume output of the toy
  • MCP4241 pin 6 is connected to the audio input signal connection of a sound card input
  • Ground is connected to the audio input ground connection of a sound card input
  • MCP4241 pin 7 is connected to the speaker output from the toy
  • 4051 pin 3 common pin is connected to the Point E of the toy (the row 3 pin of the keypad matrix)
  • 4051 pin 7 Vee is connected to ground
  • 4051 pin 8 gnd is connected to ground
  • 4051 pin 9 is connected to ground
    • This is bit 3 of the 4051 multiplexing address
  • 4051 pin 13 is connected to Point F of the toy
    • This is the first channel of the multiplexer
  • 4051 pin 14 is connected to Point F of the toy
    • This is the second channel of the multiplexer
  • 4051 pin 15 is connected to Point F of the toy
    • This is the third channel of the multiplexer
  • 4051 pin 16 Vcc is connected to 3V









Software and Mapping


This is the code used to control the toy. 

The code responds to MIDI data. Different pitches will trigger different buttons (out of the three connected buttons). Pitch bend will control the playback rate of the sound. Velocity will control the volume. 

The SPI library is included and a slave select pin is defined. In the setup function, the slave select pin, and pins used for the 4051 are set as outputs. Handlers are set for note data and pitch bend data. The SPI bus is started. In the loop function, the USB MIDI bus is read. 

The function that is executed when a note on message is received sets the volume digital pot based on the velocity, selects the appropriate button via the two address bits of the 4051, and sets enable to on for the 4051. This triggers a button, at a pitch, with a certain volume. 

The function that is executed when a note off message is received sets the volume to zero, and sets the enable to off for the 4051. 

The final function is an encapsulation that writes data to the MCP4241. 

Tuesday, May 30, 2017

Replacing the Clock Resistor - Process and Example

Many children's toys that make electronic sounds contain a 'clock resistor'. This is a discrete resistor that is usually a surface mount component, and regulates the playback rate (pitch and speed) of the sound and all other time-based functions, including aspects like LED flashing rate and triggering interval of button inputs.

To locate the clock resistor:

  • Remove the circuit from the housing of toy
  • Continuously make sound with the toy. 
  • During audio playback, run fingers over the components and listen to any variations in playback rate. 
  • Narrow down this change to one component (or the connection between two point on the board). 


Once the clock resistor has been found, a number of different modifications can be made:

  • A physical pot can be added to the circuit at the two points where a change of pitch was detected. The physical pot will only change the playback rate up (and not down). 
  • The clock resistor can be removed by desoldering carefully. The clock resistor can then be replaced with a physical pot - the middle leg and one outside legs are connected to the two points where a change of pitch was detected.
  • Instead of using a physical pot, a light dependent resistor can be used. 
  • Instead of using a physical pot, a flex sensor can be used.  
  • Instead of using a physical pot, a digital potentiometer can be used.
  • Instead of using a physical pot, a series of pots wired as a sequencer can be used.

In the example shown below: 
  • The circuit board of the toy is removed from the housing
  • The clock resistor is located
  • The clock resistor is removed via desoldering
  • Two new connections are soldered on in place of the clock resistor. This is achieved by added some solder to each point on the circuit board, and the inserting a small wire per connection. 
  • Note how much of a playback rate change can take place when the clock resistor has been removed 
  • A light dependent resistor is added, and now controls the playback rate








Thursday, June 09, 2016

Circuit Bending Basics: Replacing Button Contacts



Button contacts can be replaced easily if there are other solder points already in the circuit that are directly connected to the two contact points of a button. Two wires can be easily soldered onto the pre-existing solder points.

The two wires, when connected, can then trigger the sound of the toy. Instead of physically connecting these wires, digital pins, relays or transistor-based solutions can be used to trigger the button.


















Button contacts can be also replaced if there are no obvious solder points. Conductive area on the button pads can be scraped back, and then soldering directly onto by adding two wires connected to the button pads.

The two wires, when connected, can then trigger the sound of the toy. Instead of physically connecting these wires, digital pins, relays or transistor-based solutions can be used to trigger the button.


Thursday, June 02, 2016

Circuit Bending Basics: Using a Relay to Simulate A Button Being Pressed

Previously, I've written about different way in which a Teensy or other Arduino-based microcontroller can be used to trigger button presses on a toy.

A relay can be used to the same effect, and may be successful in situations where other methods fail.

A relay is an electromagnetic coil. When a current is passed through the coil of sufficient voltage, the magnetic field physically moves a switch, thus making a connection that was previously unconnected.

A relay will have at least four pins, in two pairs. The first pair is the coil, and this is what is used to open or close the connection. The second pair is the actual connecting contact points that are either open or closed, depending on whether or not the coil is charged. A digital pin on the Teensy is used to control the coil, thus making or breaking a circuit.

In the relay above, the four pins are arranged as pairs, and are perpendicular to one another (one short pair, one long pair). The pair that is the longest away from each other, along the length of the relay, are the contact pair and should be connected to any two points that are to be controlled by the relay. The pair of pins that are the shortest is the coil, and should be connected to the Darlington transistor array described below.

A Darlington transistor array is used between the Teensy and the relay for three reasons. The digital pin on the Teensy cannot provide enough voltage for the relay to trigger. The digital pin on the Teensy cannot provide enough current for the relay to trigger. The relay may damage the Teensy if connected directly.

For these reasons, the ULN2003 Darlington transistor array chip is used as a switching source, with the Teensy pin as an input and the relay as the output. The connections are quite straightforward, as shown below:

• Teensy digital pin 0 is connected to pin 1 of the ULN2003 (red jumper wire)
• Teensy ground is connected to pin 8 of the ULN2003 (blue jumper wire)
• Teensy 5V is connected to pin 9 of the ULN2003 (blue jumper wire)
• ULN2003 pin 1 is connected to one side of the relay coil (white jumper wire)
• Teensy 5V is connected to the other side of the relay coil (green jumper wire)
• One side of the relay contact is going to one contact point of a button press on a toy (orange jumper wire)
•  The other side of the relay contact is going to the other contact point of a button press on a toy (orange jumper wire)

Once this has been set up, a HIGH state on Teensy digital pin 0 will energise the relay, and the two orange wires will be electrically connected. A LOW state on Teensy digital pin 0 will stop the relay, and the two orange wires will be electrically disconnected.

Example code is shown below to turn the relay on or off depending on incoming note on / note off events.






Wednesday, June 01, 2016

Radio Noise

Monday, May 30, 2016

Ableton Live Circuit Bending - Toy Elephant

Controlling an Elephant Toy in Different Ways




Using a physical pot for pitch / speed control.






Using a physical pot for pitch / speed control, but using a MIDI data and a Teensy to trigger sounds. 






Using the Teensy to control the pitch and to trigger sounds



 The toy in question









 Finding and adding a point for pitch bends






Finding and adding a point for triggering sounds digitally





Two Toys, One Teensy

Combining multiple toys. Powered and controlled from one Teensy.







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.