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.
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
Overview
A digital pot is a digitally-controlled potentiometer, which is a very useful device. It allows a microcontroller, such as the Teensy, to change a potential or a resistance using data values instead of having to turn a physical pot with a human hand. There are many instances where a physical pot is used can be substituted with a digital pot.
Uses include: dimming LEDs, controlling the resistance of circuit bent toys, conditioning audio signals, setting the volume of audio signals, creating auto stereo panning devices, controlling an oscillator, creating a digital to analogue converter and so on.
The MCP4241 IC contains two digital pots, with each being 100k. The resolution is 7 bits for resistance. The two channels can be addressed independently. The Teensy 3.6 uses an SPI bus to communicate with the MCP4241.
Hardware Setup
The MCP4241 connects and communicates with a microcontroller (such as an Arduino or a Teensy) via the SPI Bus. SPI is a protocol that allows microcontrollers to interface easily with a large number of external chips and sensors.
SPI is a host / slave type bus. A single host microcontroller can interface with one or more slave chips or sensors.
SPI uses up to four pins for communication:
- CS (may also be called SS): chip select:
Used by the microcontroller to select each device. The host microcontroller has a CS output pin for every slave device that is to be used.
- SCK (or CLK): serial clock:
Used by the host microcontroller to time the data that is moved to and from the slave device. There is one SCK connection that is shared amongst all SPI devices.
- SDI (or MOSI): slave data in:
Used by the host microcontroller to send data to a slave device. There is one SDI connection that is shared amongst all SPI devices.
- SDO (or MISO): slave data out:
Used by the host microcontroller to receive data from a slave device. There is one SDO connection that is shared amongst all SPI devices.
All SPI slave devices require the CS and SCK pins. However, many device may not require both the SDI and SDO connections, as they might only either send or receive data.
With the MCP4241 chip, the resistance of a digital potentiometer is set using data from a host microntroller. As a result, only CS, SCK and SDI are required, because the information needs to travel only from the host to the slave device (i.e. from the Teensy to the MCP4241).
The hardware setup is shown below.
Digital output pin 10 of the Teensy is SPI Chip Select (CS or SS), and is connected to pin 1 of the MCP4241.
Digital output pin 13 of the Teensy is SPI Clock (SCK or CLK), and is connected to pin 2 of the MCP4241.
Digital output pin 11 of the Teensy is SPI digital output (MOSI or SDI). Teensy ground is connected to pin 4 of the MCP4241 (VSS).
Teensy 3V is connected to pin 11, 12, 14 of the MCP4241 (WP or Write Protect, SHDN or Shutdown, and VDD respectively).
The first digital pot is formed from pins 8, 9 and 10 while the second is pins 7, 6 and 5 of the MCP4241.
Software Setup
The MCP4241 can be easily addressed using the SPI library in combination with writing the correct bytes and addresses to the chip.
An example encapsulation is shown below:
This function can then be used, as shown below in the example code.
Example 1 - Incrementally Increase Resistance, and Loop
In this example, the digital pot is connected via the SPI bus. A multimeter is set to measure resistance with a range of 0 - 200K. The value of the digital pot is controlled so that the resistance increases by one step for every 100 milliseconds, looping after 128 steps.
This is a simple example of how to use a digital pot with the Teensy 3.6. The digital pot can be used to map MIDI control to change in resistance, thus allowing a setup such as this to control, say, the volume and pitch of a 40106 oscillator (or a wide array of signals).
Overview
DC motors rotate when a voltage is applied across the terminals. The speed of the motor is related to the voltage.
When using a microcontroller to control a DC motor a PWM (or pulse width modulated) signal is used. The Teensy forms a pulse wave, whereby the duty cycle is proportional to the average, equivalent over time. The duty cycle refers to the percentage of the waveform that the pulse wave is high as opposed to low.
A PWM output with a duty cycle of 50% will result in an average of half the voltage of the digital pin, a duty cycle of 25% in one quarter and so on. More information can be found about PWM signals here.
For instance, given a 3V digital pin with a PWM wave of 50%, this would provide the equivalent voltage of 1.5V over time. Thus, the digital PWM outputs on a Teensy can change the speed of a DC motor, not just turn it off and on.
The default frequency for PWM signals on the Teensy 3.6 is 488.28 Hz. Digital outputs 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 16, 17, 20, 21, 22, 23, 29, 30, 35, 36, 37, 38 are all PWM-capable pins. More information about the PWM functionality of the Teensy can be found here.
When using a PWM signal to control a motor, a certain amount of current is needed to power the motor. The outputs of the Teensy cannot provide sufficient current for the DC motor, and attempting to do so may damage the Teensy.
Instead, a Darlington transistor array in a convenient chip form can manage power source, current and control input and act as mediator between the teensy, the USB power and the DC motor. Note that anything more heavy duty than a very light motor will require an external power supply.
The Darlington transistor array comes packaged in an 8-channel version (ULN2803AN) and 7-channel version (ULN2003AN). In both cases, multiple channels can be combined to control larger motors. Each channel can provide up to 500mA of current, if a sufficient power supply is used.
In the example shown below, a single channel of a ULN2803AN is used to drive a single DC motor using 3V from the Teensy USB power supply.
Hardware Setup
Ground from the Teensy is connected to pin 9 of the ULN2803AN. 3V from the Teensy is connected to pin 10 of the ULN2803AN. Digital pin 2 of the Teensy is connected to pin 1 of the ULN2803AN. Pin 18 of the ULN2803AN is connected to one terminal of the motor. 3V from the Teensy is connected to the other terminal of the motor.
Software Setup
To control the motor, make sure that the motor is connected to a PWM-capable pin. Digital outputs 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 16, 17, 20, 21, 22, 23, 29, 30, 35, 36, 37, 38 are all PWM-capable pins.
Use analogWrite(pin, value) to set the speed of the motor. The pin is the pin number. The value is a range of 0 - 255.
There is no need to set the pin as an output pin in setup().
Example 1 - Turning the DC Motor On and Off
The motor is turned on and off.
Summary
DC motors can be easily controlled via analogWrite(), however they require additional hardware to work. Combined with MIDI control, there can be used in projects of various types.
Overview
A servo motor is a physical actuator that usually rotates for half a circle or less, or moves forwards and backwards by a set amount. Arduino add-on includes a servo library, which can be used to easily control a servo motor.
A simple, lightweight servo motor can be connected and powered by the Teensy 3.6. Note that anything more heavy duty than a very light motor will require an external power supply.
A servo motor has a control input, which expects a pulse wave with a duty cycle of around 1 - 2 ms and a period length of 20 ms. The duty cycle determines the angle or position of the servo. A duty cycle of 1 ms sets the minimum rotation or position. A duty cycle of 2 ms sets the maximum rotation or position.
Hardware Setup
The servo motor has three connections. Black or brown is usually ground, and should be connected to Teensy ground. Red is usually the positive power terminal, and should be connected to Teensy 3.3V. Orange or yellow is usually the control input, and should be connected to a Teensy digital pin, in this case pin 0.
Note that if a more heavy-duty servo motor is used, an external power supply is required. In this case, the ground of the motor, teensy and power supply should be connected. The positive terminal of the power supply should be connected to the positive terminal of the servo. The control input should be connected to a Teensy digital pin.
Software Setup
The servo library must be included at the start of the code. A servo object with a unique name can then be created by using the Servo structure.
The servo object can then be attached to a digital pin of the Teensy. This can be any digital pin. Two optional arguments as part of attaching the pin set the minimum and maximum duty cycle time periods in microseconds. A suggestion is to start with 1000 microseconds and 2000 microseconds, and adjust from there.
To control the servo motor, the write command is used with the Servo object. The value is in degrees, from 0 - 180.
Example 1 - Rotating the Servo
In this example, a servo is connected to the Teensy. The servo is then simply rotated and delayed on loop via the servo library.
Example 2 - Controlling the Servo via MIDI
In this example, the servo is controlled via a MIDI control message on channel 1, controller 1. The range of 0 - 127 is mapped to 0 - 180 degrees.
Overview The Teensyduino add-on for Arduino allows the Teensy 3.6 to easily read MIDI messages such as notes and control changes over USB. A computer or other USB-enabled device sends a MIDI message, and then the Teensy received the message, and can perform a given set of actions based on the contents of that message. For example, Ableton Live sends a control message for controller 1, value 127 and channel 1 to the Teensy. Note that MIDI has 128 controllers per channel, across all 16 channels. The value range is 0 - 127. The code on the Teensy can then read the USB MIDI bus, recognise that a control message has been received, filter just the channel 1 messages, filter just the messages that have a control number of 127 and so on, and then set the modulation amount of an oscillator based on the incoming controller value. The examples presented here provide a very basic structure that can be added to, modified and extended. Nonetheless, this is illustrative of receiving control messages and then responding in some way. Consider how control messages can be mapped to different hardware and software components, as there are many possibilities. To read more information about this, please see the Teensyduino documentation here: https://www.pjrc.com/teensy/td_midi.html. Hardware Setup
There is no hardware setup, as the onboard LED is used as a response to incoming MIDI data. Software Setup A DAW must be configured so that the Teensy is an output device for note and control data. With Ableton Live, go to the Link MIDI preferences panel, and set Track, Sync and Remote MIDI In for the Teensy to OFF, Sync MIDI Out for the Teensy to OFF and Track and Remote MIDI Out for the Teensy to ON, as shown below.
Using a MIDI track (without a virtual instrument), set the output to the Teensy, as shown below.
Any note or control data sent from this track will now be received by the Teensy. To read and then respond to the data, the Teensy code must contain three components. The first is that the main loop() function should contain usbMIDI.read() in order to read any incoming data from the USB port. The second is that the setup() function should contain a usbMIDI.setHandleControlChange(OnCC) function. The argument used for usbMIDI.setHandleControlChange() points to a user-defined function, and could have any name at all. usbMIDI.setHandleControlChange() connects the receiving of control messages with a particular function that is executed whenever a note message is received. The third component is that for every argument used in a setHandle function, there must exist a corresponding user-defined function that takes a particular form depending on the type of MIDI data received.
Every time a new control message is received by usbMIDI.read(), the function that is defined as the argument set by usbMIDI.setHandleControlChange() then processes the control message. The order of arguments of the user-defined function must be channel, controller number, controller value.
Example 1 - Turn LED On for CC Values Above 64
The Teensy receives control data. If the control value is above 64, then the LED is turned on.
Example 2 - Turn On LED for Controller Number 1, Turn Off LED for Controller Number 2
The Teensy receives control data. If the message is from controller 1, then the LED is turned on. If the message is from controller 2, then the LED is turned off.
Overview The Teensyduino add-on for Arduino allows the Teensy 3.6 to easily read MIDI messages such as notes and control changes over USB. A computer or other USB-enabled device sends a MIDI message, and then the Teensy received the message, and can perform a given set of actions based on the contents of that message. For example, Ableton Live sends a MIDI note on message for middle C, velocity 127 and channel 1 to the Teensy. The code on the Teensy can then read the USB MIDI bus, recognise that a note on message has been received, filter just the channel 1 messages, filter just the notes that have a velocity of 127 and so on, and then set the frequency of an oscillator based on the incoming pitch. The examples presented here provide a very basic structure that can be added to, modified and extended. Nonetheless, this is illustrative of receiving MIDI note messages and then responding in some way. Consider how note on / note off messages can be mapped to different hardware and software components, as there are many possibilities. To read more information about this, please see the Teensyduino documentation here: https://www.pjrc.com/teensy/td_midi.html. Hardware Setup
There is no hardware setup, as the onboard LED is used as a response to incoming MIDI data. Software Setup A DAW must be configured so that the Teensy is an output device for note and control data. With Ableton Live, go to the Link MIDI preferences panel, and set Track, Sync and Remote MIDI In for the Teensy to OFF, Sync MIDI Out for the Teensy to OFF and Track and Remote MIDI Out for the Teensy to ON, as shown below.
Using a MIDI track (without a virtual instrument), set the output to the Teensy, as shown below.
Any note or control data sent from this track will now be received by the Teensy. To read and then respond to the data, the Teensy code must contain three components. The first is that the main loop() function should contain usbMIDI.read() in order to read any incoming data from the USB port. The second is that the setup() function should contain a usbMIDI.setHandleNoteOn(OnNoteOn) function and usbMIDI.setHandleNoteOff(OnNoteOff) function. The two arguments used for usbMIDI.setHandleNoteOn() and usbMIDI.setHandleNoteOff() point to two user-defined functions, and could have any name at all. usbMIDI.setHandleNoteOn() and usbMIDI.setHandleNoteOff() connect the receiving of MIDI note messages with a particular function that is executed whenever a note message is received. The third component is that for every argument used in a setHandle function, there must exist a corresponding user-defined function that takes a particular form depending on the type of MIDI data received. To read more information about this, please see the Teensyduino documentation here: https://www.pjrc.com/teensy/td_midi.html. Every time a new MIDI note on message is received by usbMIDI.read(), the function that is defined as the argument set by usbMIDI.setHandleNoteOn() then processes the note on message. This is illustrated in the following simple example, which lights up the LED if a note on message is received, and turns the LED off if a note off message is received. Note that the user-defined function named OnNoteOn must have three bytes as arguments, and the byte order must be channel, pitch, velocity. int LED = 13; void setup() { usbMIDI.setHandleNoteOn(OnNoteOn); usbMIDI.setHandleNoteOff(OnNoteOff); pinMode(LED, OUTPUT); } void loop() { usbMIDI.read();
} Of course, OnNoteOn can be much more complex - for example, filtering based on pitch, velocity or channel variables. Nonetheless, it is the OnNoteOn and OnNoteOff functions that process the incoming MIDI notes. Example 1 - Turn LED On and Off from Note On and Note Off Messages For every Note On message, the LED is turned on. For every Note On message, the LED is turned off. Download here: http://milkcrate.com.au/_other/downloads/arduino/teensy_3_6_basics/Receiving_MIDI_Notes_Example_1/ Example 2 - Turn LED On and Off from Note On and Note Off Messages - But Only on Channel 1 For every Note On message, the LED is turned on. For every Note On message, the LED is turned off - however, the Teensy will only respond on channel 1. Download here: http://milkcrate.com.au/_other/downloads/arduino/teensy_3_6_basics/Receiving_MIDI_Notes_Example_2/ Example 3 - Turn LED On and Off from Note On and Note Off Messages - But Only on Channel 1 and Pitch 60 For every Note On message, the LED is turned on. For every Note On message, the LED is turned off - however, the Teensy will only respond on channel 1 and for pitches of 60. Download here: http://milkcrate.com.au/_other/downloads/arduino/teensy_3_6_basics/Receiving_MIDI_Notes_Example_3/ Example 4 - Turn LED On and Off from Note On and Note Off Messages - But Only on Channel 1, Pitch 60 and Velocities Above 80 For every Note On message, the LED is turned on. For every Note On message, the LED is turned off - however, the Teensy will only respond on channel 1, for pitches of 60 and for velocities that are above 80. Download here: http://milkcrate.com.au/_other/downloads/arduino/teensy_3_6_basics/Receiving_MIDI_Notes_Example_4/ Summary Responding to notes are an integral part of dealing with MIDI data when interfacing with external circuits, motors, lights, LEDs etc.
Note for Teensy 4.1: All of the ideas explored in this post are compatible with Teensy 4.1 with two changes:
1) Teensy 4.1 must use the FastTouchRead library by Adrian Freed instead of the native TouchRead functions
2) The FastTouchRead library will return values in the range of 15 - 75 instead of the 1000s, so any scaling or thresholds will have to reflect this.
Overview
The Teensy 3.6 is able to use capacitive sensing through the included touchRead functions, which are part Teensyduino. Capacitive sensing can sense the capacitance of the human body as a data value, and requires a conductive element that forms the sensor. This could be a copper plate, antenna, or a piece of fruit / vegetable.
The sensor is simply connected to a touch input on the Teensy, shown in yellow on the pinout reference.
In this way, the Teensy 3.6 can easily accomodate up to eleven capacitive sensors. Depending on the type of sensor and physical configuration, many more can be multiplexed.
Hardware Setup
The hardware setup is simple. A sensor - in this case an apple - is connected to digital pin 0 of the Teensy 3.6, which is a touch pin.
Example 1 - Sending Capacitive Touch Values from an Apple as Serial Data
The touchRead function is used to read the value of the apple. This data is sent to the serial port, and displayed using the Arduino serial monitor. Minimum values might range from 800 - 1200. Maximum values might range from 2500 - 10,000. The sensor, power supply of the Teensy, grounding, signal noise and individual may all influence a reading.
Due to the large data value range, it is important to test out a capacitive touch sensor to determine the boundaries of expected values, so that the input can be scaled, constrained and mapped for use.
Example 2 - Sending Capacitive Touch Values from an Apple as MIDI Continuous Control Data
The touchRead function is used to read the value of the apple. This data is then scaled, and constrained, and then sent as a USB MIDI CC message if the reading has changed from the previous value.
Example 3 - Triggering a MIDI Note Using an Apple
When the apple is touched, a MIDI note on message is generated. When the apple is let go a MIDI note off message is generated.
A threshold value is used to set the point at which the note is triggered. A play flag variable allows the Teensy program to keep track of whether or not a note is currently playing, thereby avoiding repeated note on or note off events.
The value from the touchRead function is compared to the threshold value.
If the touch value is above the threshold and the note is currently not playing, then a note on event is generated and the play flag is set to 1 indicating that there is now currently a note playing.
If the touch value is above the threshold and the note is currently playing, no action is taken.
If the touch value is below the threshold and the note is currently playing, then a note off event is generated and the play flag is set to 0 indicating that there is not currently a note playing.
If the touch value is below the threshold and the note is currently not playing, no action is taken.
Example 4 - Triggering Two Different MIDI Notes Using Two Apples
A second apple is added to the setup, using digital pin 1.
When a given apple is touched, a MIDI note on message is generated. When the apple is let go a MIDI note off message is generated. Each apple has its own unique MIDI note, and is triggered individually. Chords can be played by touch both apples at once.
A threshold value is used to set the point at which the note is triggered. A play flag variable allows the Teensy program to keep track of whether or not a note is currently playing, thereby avoiding repeated note on or note off events.
The value from the touchRead function is compared to the threshold value.
If the touch value is above the threshold and the note is currently not playing, then a note on event is generated and the play flag is set to 1 indicating that there is now currently a note playing.
If the touch value is above the threshold and the note is currently playing, no action is taken.
If the touch value is below the threshold and the note is currently playing, then a note off event is generated and the play flag is set to 0 indicating that there is not currently a note playing.
If the touch value is below the threshold and the note is currently not playing, no action is taken.
What is it to be a good consumer? This is something that I've been thinking about lately. From politicised consumer revolts to discussions around meat consumption, sweatshop products or energy use.
I can't help but to think that we all turn a blind eye to aspects where the need for comfort is outweighed by negative outcomes. Diffusion of responsibility plays a role in this, too, of course.
In the end, we need to ask ourselves: What do I need? What do I want? And what can I do without?
---
April was a solid month. Even through some stressful times, I managed to find time for camping on the sand dunes near the southern ocean.
I didn't make any major changes to my 'system' in terms of food, cooking, waste and so on, however I did manage to sign up for the Live Below the Line. I'll be living on $2 a day for food and drink from May 1 - 5 to raise money for charity. I've made my goal, which is very generous of people!
My ingredients came to a total of of AUD$9.58, and will yield 2280 calories per day across five days with 20% protein, 15% fat and 65% carbs.
---
Quite a bit of waste reduction this month:
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.
Note that this is the waste that is leaving my house, everything is either used directly or stored for future use. Additionally, four beer cans from a party have not been included.