Saturday, June 10, 2017

Photos from Sound Bytes - June 2017

Tuesday, June 06, 2017

Interfacing with a Toy - Process and Example

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: 


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. 


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. 

Sunday, June 04, 2017

Trail: One Night at Waitpinga Road

I spent one night on the Heysen Trail, camping at the corner of Waitpinga and Range Road. This spot was about an hour's walk from the Encounter Bay public bus stop, two hours from the Victor Harbour stop.

A cold, but peaceful night. Walking back in the early morning was worth the view of fog in the valley, and looking down across the bay.

Wednesday, May 31, 2017

New Me-ism: May 2017 Wrap Up

Cross posted:


I've been wallowing in my comfort. Borrowed from the future, and subsidised by distant others.


Let's start off with a negative. I've put on some weight this month, and my body and mind feels sluggish as a result. Nothing too major, and nothing that can't be adjusted for. I would put this down to stresses brought on by workload and other events. A nice excuse, as always. On the plus side, I've been walking nearly every day of distances up to 25km - including to work and back a few times.

It's been another month of progress. The first week of May was spent doing the $2 per day Live Below the Line challenge, which was an interesting and eye-opening experience.

I've minimised glass use, removed tins and cans completely, and reduced plastics as well. Towards the end of May, I also started experimenting with making my own mouth wash and dish washing detergent. I am still trialling different combinations, but it's a start - and the results are promising enough to continue. I will report back on this next month.

I've also been gravitating towards sage again, which feels good. Cleansing. 


Below is my trash for the month. This includes only garbage that is leaving my house in some way, whether as a recyclable component or waste. I didn't include some Hungry Jacks and a coffee cup lid.

As always, the top row, from left to right, is glass, tins, paper. The bottom row, from left to right, is hard plastic, soft plastic, and miscellaneous.

Lots of soft plastics still! However, massive reductions in tins and glass, which is a plus.

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