Jonathan Thomson's web journal

Halloween 2016 – Jackpot October 31, 2016

Filed under: Electronics,Halloween — jethomson @ 9:17 pm

music_box_slot_machine

 
 
Construction
I attached a nylon belt to a toy slot machine coin bank so I could hang it around my neck, and created a music box using an ATtiny861 to play sound effects. The music box uses three differently colored gumdrop LEDs that hover over mini push button switches, so that pushing down an LED results in a push button switch being depressed. The LEDs were made to spring back by bending their leads at a right angle, running them through heat shrink, and gluing the heat shrink to the board (see the picture below). If the player hit the jackpot I pressed the green button to play winning sound effects. If a jackpot wasn’t hit the red button was pressed, and a losing sound effect was played. The orange button played Halloween themed sound clips. A schematic can be found by following the link in the README.md found in the GitHub repo for the code.

 
 
gum_drop_push_buttons

 
 

 
 
Music Box Code on GitHub

Advertisements
 

Halloween 2014 – Jack Skellington October 31, 2014

Filed under: Electronics,Halloween — jethomson @ 8:38 pm

First, I printed out two copies of Jack Skellington’s divided-up face in yellow on a few sheets of paper. Then I put a little bubble wrap to act as a diffuser around a bunch of flickering yellow LEDs. The LEDs were powered by CR2032 coin cells with three LEDs per cell. Finally I sandwiched the LEDs between each copy of a part of Jack’s face, and attached these to an orange shirt with double sided tape.

 

jack_skellington_halloween_2014

 

 

PDF of Jack’s face divided into four pages

Source for yellow flickering LEDs

 

Level Headed – EL Wire Decorated Headphones July 5, 2013

Filed under: Electronics — jethomson @ 12:25 am

 

I decorated a pair of headphones with electroluminescent wires (EL wire) that react to the music you’re listening to. I modified an inverter taken from a graphical equalizer T-shirt to respond to an audio signal from my mp3 player instead of sound. Here’s a link to the instructable.

 

How Big is Lily Pad Lake? November 4, 2012

Filed under: Uncategorized — jethomson @ 8:53 pm

Here’s a common brain teaser:

“In a lake, there is a patch of lily pads. Every day, the patch doubles in size. If it takes 48 days for the patch to cover the entire lake, how long would it take for the patch to cover half of the lake?”

 

Many people answer a bit too quickly and say 24 days. However, the correct answer is 47 days assuming the doubling on the 48th day doesn’t overshoot the area of the lake. On the 47th day the lily pads cover half of the lake and on the 48th day they double covering the entire lake. But what I’m really interested in is how big is Lily Pad Lake?

 

Let’s denote the area of lily pad Lake by A.

 

Then the area covered by the lily pads on the 48th day is A. Therefore the formula for determining the area covered by the lily pads on day n is:

 

On the 48th day Alily is equal to A, and on the 0th day Alily = A/(2^48). The problem doesn’t state how many lily pads are present on the 0th day, but to minimize the size of Lily Pad Lake I’ll assume just one lily pad is present. Thus on the 0th day Alily is equal to the area of 1 lily pad. Assuming the area covered by one lily pad is 5 square feet, then:

 

That’s 1.4 quadrillion square feet or 50,482,628 square miles or 130,749,410 square kilometers. For comparison purposes the Pacific Ocean is 155,557,000 square kilometers and the next biggest ocean is the Atlantic at 76,762,000 square kilometers. So perhaps a better name for Lily Pad Lake would be Lily Pad Ocean, which would have to be a freshwater ocean since lily pads don’t live in salt water.

 

 

Notes
Typical [lily pad] plant size 5-10′ square

The Pacific Ocean is 155,557,000 sq km

 

Evaluating an Off-the-shelf Actinic Bulb for use in Blue Light Therapy Acne Treatment

Filed under: Spectrometer — jethomson @ 7:48 pm

 

There’s been some research showing that light at around 415 nm is effective at killing the bacteria that cause acne. This type of acne treatment is know as blue light therapy although the light in the region around 415 nm is actually violet. The British paper “Phototherapy with blue (415 nm) and red (660 nm) light in the treatment of acne vulgaris” by P. Papageorgiou, A. Katsambas, and A. Chu states in its Materials and Methods section that the blue light source they used “had an asymmetric peak of 415 nm +20/-15 nm” and an irradiance of 4.23 mW/cm^2 at 25 cm (about 10 inches). Actinic lamps produce blue light with a peak irradiance around 415 nm. I used my homemade spectrometer to capture the actinic spectrum of a Coralife 50/50 20W compact fluorescent. In the range of wavelengths from 400 to 430 nm I measured a total irradiance of approximately 0.7 mW/cm^2 at 3 inches (7.65 cm). Therefore the Coralife actinic lamp has only a sixth of the strength of the lamp used in the British paper. However, the experiment used an irradiance time of 15 minutes such that the patient was exposed to a “cumulative dose of 320 J/cm^2”. Since the Coralife actinic lamp is a sixth power of the experimenter’s lamp, then multiplying the exposure time by six should result in the same dosage. Therefore one could hypothesize that an exposure time of 90 minutes with a Coralife 20W lamp will produce similar results to those seen in the paper. I haven’t tested this hypothesis because 3 inches is quite a small distance and having the lamp that close would prevent me from doing anything else during the therapy session. The lamp would obstruct my field of view and the blue light is an eye hazard. Given that it would take 90 minutes to receive a full dose and that a portion of the light output is in the UV wavelengths makes blue light therapy by means of a Coralife bulb even less attractive. However, it might be possible to spread the exposure time over multiple sessions and use those sessions to rest or listen to music. If anyone tries this out please leave a comment.

 

How to use the TSL2561 May 22, 2012

Filed under: Electronics,Spectrometer — jethomson @ 2:07 am

The TSL2561 is a light-to-digital converter from TAOS. It senses light intensity and transforms its measurement into a digital output that is transferred over I2C or SMB. If you are familiar with the TSL230R light sensors, you shouldn’t have much trouble working with TSL2561s, but there are a few important differences. The TSL230R outputs its data as a pulse train, so a microcontroller with frequency counting code is required to read the sensor’s output. The TSL2561 outputs its data directly over I2C or SMB, so the sensor’s output is simply read from the bus. The TSL230R is controlled by bringing purpose specific pins high or low. The TSL2561 is controlled by writing data to it over the bus. The TSL230R is available in a breadboardable package and runs at 5V. The TSL2561 needs an adapter board for breadboarding and it’s power supply must not exceed 3.3V. The TSL2561 also has a second diode specifically for sensing infrared.

Since the TSL2561 is so similar to the TSL230R in theory, I’ll only be writing one condensed article for the TSL2561. Please refer to the series of article of the TSL230R for a more in-depth explanation of how to acquire and process data from these sensors.

 

Serial Control
TSL2561_DAQ.ino (view online) enables serial control of the TSL2561 via a simple serial protocol between the host computer and Arduino. It allows the user to set the number of output samples, adjust the TSL2561’s sensitivity and integration time, and switch power to a light source. The Arduino IDE has a built in serial monitor, which you can use for testing serial commands. However, Tod E. Kurt’s arduino-serial is smaller and has more functionality.


The command:
./arduino-serial -b 9600 -p /dev/ttyUSB0 -d 3000 -s s016 -d 100 -s i101 -d 100 -s l111 -d 100 -s t005 -d 10000 -r -d 500 -r -d 500 -r -d 500 -r -d 500 -r -d 500 -r -d 100 -s l000

Outputs one read for each -r:
read: 697

read: 697

read: 696

read: 697

read: 696

read: EOT

This command waits three seconds for the bootloader to load the program (-d 3000) then it tells the program to set the sensitivity to 16x (s016), the integration time to 101 ms (i101), turn the light on (l111), and transmit five samples (t005). The command then waits 10 seconds for the buffer to fill (-d 10000), reads five samples (-r -d 500 repeated five times), and finally turns the light off. The blank lines in the output are from the line feed (i.e. \n) printed after each number. The uc code uses Serial.print('\n') instead of Serial.println() and the string “EOT” so that it can communicate with code written for GNU Octave and MATLAB.

 

Data Acquisition Scripts
The archive TSL2561_code.zip contains the m-files (view online: get_data, save_data, serial_open) necessary for controlling the TSL2561 within GNU Octave and MATLAB and reading the counts output from the ATmega uc.

 

Spectral Responsivity

The spectral responsivity for the Channel 0 diode when the gain is 16x, the integration time is 101 ms, Vdd = 3V, and Ta = 25°C is saved in Re2561.mat in the essential_data_sets folder within the archive TSL2561_code.zip

 

Converting Counts to Irradiance
With Re(λ) and a model of the spectral content of the light source irradiating the photodiode array we can calculate the spectral irradiance and total irradiance of the light source more accurately than in the simplistic case of assuming all the light source’s photons are 640 nm in wavelength.

For example, if we model a red LED with a peak wavelength at 640 nm and a full width at half maximum (FWHM) of 34 nm with MATLAB like so:

   % mathematically model lamp's spectrum as a gaussian curve with a peak 
   % wavelength at 640 nm and full width at half maximum of 34 nm
   e = exp(1);
   func_lamp = @(mu, FWHM) e.^(-2.7726*((lambda_Re-mu)/FWHM).^2);
   X = func_lamp(640, 2*17);  % [uW/(nm*cm^2)]

Then the output counts, cX, that would result if X irradiated the photodiode array can be calculated thusly:

 

However, cX is not the actual output counts of the TSL2561 because X is only a model of the shape of the light’s spectrum and lacks radiometric calibration. Since we can measure counts, finding the proper radiometric calibration multiplier for X is as simple as dividing counts/cX.

 

Therefore, a good approximation of the radiometrically calibrated spectral irradiance of the light source should be:

 

and the total irradiance is:

 

Acknoledgements

Newark gave me a TSL2561T light to digital converter from TAOS to evaluate as part of their product road testing program.

Thanks go out to ladyada for providing a library and basic example for working with the TSL2561.

 

Using a Wii Nunchuk as an Earthquake Sensor May 16, 2012

Filed under: Electronics,QCN — jethomson @ 9:57 pm

 

 

This article explores the suitability of a Wii nunchuk based USB accelerometer as an earthquake sensor for the Quake-Catcher Network (QCN) project. It examines the nunchuk over several metrics: precision and range, frequency response, total cost and availability.

The Quake-Catcher Network is a collaborative initiative for developing the world’s largest, low-cost strong-motion seismic network by utilizing sensors in and attached to internet-connected computers. With your help, the Quake-Catcher Network can provide better understanding of earthquakes, give early warning to schools, emergency response systems, and others. The Quake-Catcher Network also provides educational software designed to help teach about earthquakes and earthquake hazards.

Range and Precision
QCN supports a few different USB accelerometers. The most basic one is the JoyWarrior24F8 (JW24F8), which is a 3 axis accelerometer with 10 bits of precision and a measurement range of +-2g, +-4g, or +-8g. QCN uses the +-2g range. According to WiiBrew, the Wii nunchuk’s accelerometer also has 10 bits of precision over a range of +-2g. Therefore, the nunchuk meets the first criteria for evaluating its suitability as a QCN sensor.

Data Comparison
I don’t have access to a shake table so I’m unable to directly evaluate the frequency response of the nunchuk based USB accelerometer. However, QCN did provide me with a JoyWarrior24F8 USB accelerometer for comparison. Since the frequency response of the JoyWarrior24F8 was already deemed suitable by Prof. Cochran for QCN, I simply had to attach the JoyWarrior24F8 and the nunchuk to the same substrate, shake them by hand at various frequencies while recording data from both sensors simultaneously, and compare the Fourier transform of the nunchuk’s data to the transform of the JW24F8’s data.

Here are comparisons of an official (i.e. STMicroelectronics accelerometer) nunchuk to the JW24F8. The microcontroller code used was mega32u4_hard-i2c_no_filter.zip and the plots were made using the Octave scripts found in the code section below.

 

Accelerometer X-axis data comparison
Time domain plots:

 

Frequency domain plots:

 

Accelerometer Y-axis data comparison
Time domain plots:

 

Frequency domain plots:

 

Accelerometer Z-axis data comparison
Time domain plots:

 

Frequency domain plots

 

The STMicroelectronics based nunchuk appears to have a response that is very similar to the JW24F8’s response. It should be noted that I was shaking the accelerometers by hand so I don’t think I covered the entire range of frequencies of interest.

Fakes
Unfortunately, there are fake (i.e. 6331 accelerometers) nunchuks that are unsuitable earthquake sensors because their accelerometer data has stuck bits. Even worse, it can be very difficult to impossible to tell if a nunchuk is official by external examination only.

Microcontrollers
The nunchuk uses I2C to transfer its data. Therefore, a microcontroller that supports USB and I2C is required to read the data from the nunchuk, filter it, and pass it to the host computer. Three different microcontrollers were evaluated: an ATmega32U2 board that supports hard USB and soft I2C, an ATmega328P with V-USB that supports soft USB and hard I2C, and an ATmega32U4 (teensy) that supports hard USB and hard I2C. The ATmega32U2 only works with 6331 based nunchuks and only at 100 kHz. The ATmega328P works with both STMicroelectronics and 6331 based nunchuks, but the two-wire interface (TWI) eventually locks up for an unknown reason. The ATmega32U4 works with both types of nunchuks tested and with no crashes observed over a two-week period. The STMicroelectronics nunchuk works at 100 and 200 kHz with hard I2C only. The 6331 based nunchuk works at 100, 200, and 400 kHz when hard I2C is used.

Cost
A Quake Catcher Kit from Saelig is $42.25 with about $12 for shipping to a U.S. residence, for a total of $54.25.

A Teensy with a 3.3V regulator and shipping costs about $22. A genuine, official nunchuk is approximately $20 shipped. A nunchuk extension cable from eBay is around $4.50. For a total price of $46.50. However, the cost of a proper mount for the nunchuk as well as the labor cost of assembly has not been included. Therefore, I believe that Quake Catcher Kit is most likely a better deal for your time and money.

Code
All of the code in one GitHub repo.

_Microcontroller code_
The output resulting from microcontroller code that didn’t filter the accelerometer data was the most similar to the output of the JW24F8. Code that filters the accelerometer data with Chebyshev and moving-average filters is included for comparison purposes and because I’d already written it.

This code is for research purposes only; it uses an Atmel USB VID/PID pair for LUFA demos only. This code doesn’t work with QCN because the QCN software checks the joystick’s name to make sure it’s a JoyWarrior. This code can be easily made to work with QCN by modifying its USB descriptors, which I’ve done, but I won’t be releasing this code since it uses Code Mercenaries’s VID/PID. The code also checks the connected controller’s identification bytes to make sure its a genuine Wii nunchuk. It doesn’t work with fake nunchuks.

Wii Nunchuk quake sensor code for teensy (no filter)

Wii Nunchuk quake sensor code for teensy (moving average)

Wii Nunchuk quake sensor code for teensy (chebyshev)

_Host code_
Joystick Accelerometer Data Acquisition code for Linux

Octave plotting scripts