Nov 18 2012

Interfacing the Arduino to the Taos TCS3414 via I2C, continued

By Max

Taos TCS3414

November, so soon!  I kind of had to put this one down for awhile and work on things that were not laptop-centric, I just was spending too much time in front of a computer screen.  Luckily, Tiuri De Jong was on the case, and he has developed the proof-of-concept code I posted earlier into a fully-working demonstration.

I uploaded it to my Arduino, and I’m getting stable results with an apparently linear response, although the specific numerical values themselves aren’t particularly meaningful.    For example, under my workbench lamp that I metered at about 40fc and has a CCT of 5000K, it measured 290fc at 3500K.  I get that the part would require calibration before it would be useful, but it’s strange to me that it would be off by 1500K color temperature and a factor of 5 for illuminance, out of the box?  I’d be interested to know if anyone else has a similar experience.

What I’m working on now is measuring the values given by the TCS3414 vs. a known accurate illuminance and color temperature meter, to tell if the deviation from true value is a constant, or a linear function, or what.  I’ve verified that the calculations are done correctly in the code per the datasheet.

But in the meantime, it seems like a shame to deprive everyone else of Tiuri De Jong’s complete and, might I add, lucidly written code, so it may be downloaded here:

2012-11-18 Light Meter Code Rev5

I’ve also posted the code in full after the jump.

Continue reading “Interfacing the Arduino to the Taos TCS3414 via I2C, continued” »


Jun 7 2012

Interfacing the Arduino to the Taos TCS3414 via I2C

By Max

Well, this was a productive night:  I’ve been working with the Taos TCS3414, which is a light and RGB color sensor.  It’s a tiny little guy, about 2.5 x 3.5 mm I would guess, and shown above is mounted on breakout boards.  I just had a breakthrough night with it, getting it to correctly return values from the sensors, so I thought I’d share my preliminary code for the benefit of all.

Update: better code here!

Helpful tips:

  • The TCS3414 is I2C, whereas the TCS3404 uses the similar SMBus.  The Atmega 328 can do both, but I2C is easier for reasons of both hardware and libraries, so get the TCS3414.
  • I2C is on analog pins 4 and 5, not digital pins 4 and 5.
  • It’s a 3.3V device, so make sure you power it via the 3V output on the Arduino, not the 5V output.  It draws 9ma max, so the 50ma capacity via Arduino is plenty.
  • Similarly, you’ll need to level shift 5V bidirectionally to 3V from the Arduino to the sensor, so google logic level converters.  I used a pair of NTE491 MOSFETs.

Here’s what my hardware looks like (note, my breakout board pins aren’t the same layout as the sensor):

That all being said, here’s my (working concept only) code!:

// 6 June 2012

#include

int ledPin = 13; // LED connected to digital pin 13

byte receivedVal = 0x00;

unsigned int clearLow = 0;
unsigned int clearHigh = 0;

void setup()
{
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);

// join i2c bus (address optional for master)
Wire.begin();

Serial.begin(9600);
Serial.write("Serial started" "\n");

digitalWrite(ledPin, HIGH); // set the LED on

Wire.beginTransmission(0x39);
Wire.write(0x80);
Wire.write(0x03); // Turn the device on and enable ADC
Wire.endTransmission();

Wire.beginTransmission(0x39); // Request confirmation
Wire.requestFrom(0x39,1);
receivedVal = Wire.read();
Wire.endTransmission();

if (receivedVal == 0x03) {
Serial.write("ADC Started" "\n");
}
else {
Serial.write("Connect to sensor failed with code: ");
Serial.println(receivedVal, DEC);
}

delay(50); // wait for a moment to allow ADC to initialize
digitalWrite(ledPin, LOW); // set the LED off
}

void loop() {
Wire.beginTransmission(0x39);
Wire.write(0xB8);
Wire.endTransmission();

Wire.beginTransmission(0x39); // Request confirmation
Wire.requestFrom(0x39,2);
clearLow = Wire.read();
clearHigh = Wire.read();
Wire.endTransmission();

clearHigh = (clearHigh * 256) + clearLow;

Serial.println(clearHigh, DEC);

delay(500);
}

If you’ve done it right, it should start spitting out meaningless numbers, that decrease when you hold your hand over the sensor!  More to come on this topic soon!


Jun 15 2011

Electricity Quick Reference Cards

By Max

These are some quick reference guides I made for my dad, for Christmas.  I am posting it now because June is the next month after December, clearly.  So my dad has been hampered in working on his classic cars and rental properties with their myriad electrical problems because he’s never been exposed to the fundamentals of electricity.  I figured that what he needed in lieu of a formal physics course was a quick reference that he could refer to as needed. Continue reading “Electricity Quick Reference Cards” »


Oct 13 2010

My Nixie Clock Build

By Max

It’s finally done, jesus. A few years ago, I bought some electronics components from a former Eastern Bloc country.  Nixie tubes are apparently still widely available over there, so since the largest line item in the order was shipping costs, I had them throw some Nixies in with the order.  They sat in my parts bin until, a few months ago, I decided to make a clock out of them. Continue reading “My Nixie Clock Build” »


Oct 9 2010

Rev15 of the Arduino DMX Reception Software Released

By Max

New in this version:

  • Tested and working with IDE version 0021.  I have not tested it with the new Arduino Uno hardware, but can’t think of any reason why it wouldn’t work.  If you have any success or otherwise with the new hardware, drop a line in the comments.
  • A bug has been fixed in the addressing routine caused by button debounce, and the addressing routine logic has been simplified and made clearer.  Big thanks to Ron Barber for pointing out the source of the bug and contributing new code.
  • There is now a check when the previously stored address is read from EEPROM to ensure that it is in the valid range of 1-511, to prevent a bad value being read in from uninitialized EEPROM.
  • Fixed a potential bug in the break detection routine that could cause the read values to be off by one in cases where the break from the microcontroller was exactly 88uS.

You can grab it here or mosey on over to the original post for the instructions.


Jul 10 2009

Rev13 of the Arduino DMX Reception Software Released

By Max

New in this version:

  • Tested and working with IDE version 0016.
  • The number of channels to receive is now easily user-configurable.
  • Replaced static variables with #define statements for RAM optimization (+48 bytes, woot!).

You can grab it here or mosey on over to the original post for the instructions.

Ed. Note: This is no longer the latest version.  Head to here for the latest.


Jun 20 2009

Arduino Theremin/Synth Final Walkthrough

By Max

P1000478DNG

It’s Done! I gave it to my sister last weekend and she really liked it.  If you’re just tuning in now, I have posts about the hardware development, waveform crafting, an early demonstration, and the software algorithm.  The final version has the following features:

  • Four octaves of continuous pitch variation by moving your hand nearer or farther from an ultrasound sensor
  • Digital volume control
  • Continuous waveform variation–can generate a pure sine tone like a classic theremin, or one with overtones, which sounds like an 80′s synth organ.
  • Spectral glide–similar to a Wah pedal or the instrument used in Peter Frampton’s ‘Do You Feel Like I Do’
  • Decay/Sustain–envelope shaping to play notes
  • Distortion–sounds like the guitar effect.

Listen to the Tone of the Future:

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

  1. 0:00-0:00 Pure tone, no effects
  2. 0:45 Waveform selection– no overtones
  3. 1:05 Decay effects
  4. 1:37 Wah
  5. 2:45 Distortion

And here is a video with me demonstrating the operation (and also explaining several key features completely incorrectly):

Continue reading “Arduino Theremin/Synth Final Walkthrough” »


Jun 4 2009

Arduino Theremin/Synth Update II

By Max

The Hardware, Oh the Hardware. I’ve been making some great progress on shaping the generated tone and getting some more musicality — I’ve programmed a decay function and that’s made a huge difference, depending on the input values I’ve got a pretty good harp simulacrum, and also something that sounds like an early 1980′s analog synth piano, which I <3.  I’ll try to get a demo up of where I’m at with tonality.  Mainly, I’ve been trying to figure out the analog inputs to control the tone sensing, as well as volume, attack, decay, echo, etc.  This is really two separate problems.  For the frequency control, I want to detect distance from 2″-3′ with good precision, stability, and ideally linearity.  For the volume and effects control, I want a 0-5V analog input over about 1-1.5″ of travel, that can be operated with a single finger.  Here’s what I’ve looked at: Continue reading “Arduino Theremin/Synth Update II” »


May 29 2009

Generate Real-time Audio on the Arduino using Pulse Code Modulation

By Max

TEK-434 1973-2009 RIP :(

TEK-434 1973-2009 RIP :(

So. There are a bewildering variety of options for generating sound via the Arduino, but I’m trying to make a real-time synthesizer, with the following features:

  • Arbitrary waveform shape, including the ability to add harmonics for a more musical sound
  • Generate any frequency dependent on sensor input
  • Efficient processor usage to allow for effects such as reverb, echo, envelope shaping, etc.
  • A minimum of external hardware

Audio output for the Arduino is pretty well-tilled soil, but surprisingly most of the previously published options are geared towards canned sound playback, or tone generation without a focus on musicality.  I’ve implemented an algorithm called Pulse Code Modulation, and I think it has a lot of potential.  Keep reading for an explanation of how it works and why it’s awesome.

Continue to page 2…


May 26 2009

Arduino Theremin/Synthesizer Update

By Max
Banana bread and chips were vital to the DAC processing

Banana bread and chips were vital to the DAC processing

An Update: I’ve made considerable progress in improving the quality of the audio output.  In the prior post, I was generating a square wave with the pulse frequency determined by an input from a capacitive sensor.  It sounded, to put it succinctly, awful.  Since I was generating it through the main loop() code, it was also susceptible to processor load problems, i.e. when an analogRead() was done, it would stop the waveform generation and start it again for ~100mS.  I’m now using interrupt-driven Pulse Code Modulation to generate an arbitrary waveform, and it sounds surprisingly decent, actually.

It’s Like This, Y’all: Since with this setup I can generate an arbitrary waveform, I first spent some time investigating what makes a tone sound musical, or not.  I started by taking a recorded piano key and doing a frequency spectrum analysis of it in Audacity.  Here’s what that looks like:

piano-waveform

The waveform of a middle C (261.626Hz) piano key

And the accompanying spectrum analysis:

piano-spectrum

You can see that the strongest tone is at the fundamental frequency of middle C, 261Hz.  But there are also spikes at the harmonics of that frequency, e.g. 523Hz, 784Hz, 1046Hz.  Interestingly enough, the strongest harmonics are those corresponding to powers of 2, i.e. f * 2n.  I’ve read that even-numbered harmonics are more pleasant-sounding than odd-numbered harmonics, and this would seem to support that idea.  Also, as you add in the odd-numbered harmonics, the waveform approaches a triangle wave, which is definitely less pleasant to listen to than a sine wave.

Thus Informed, I started working to create a waveform of my own.  I set up a frequency and a bunch of multiples of it in Audacity, and played around with increasing or decreasing the amplitude of specific overtones, until I had a sound I was happy with, like so:

middle-c-tone

On the left, you can see that I’ve varied the amplitude of the various overtones

From this I discovered that the undertone (1/2 * f) and other partials make a huge difference in the quality of the tone.  I wanted to post this file up so other people can play around with it, but apparently with the associated sample files it’s around 50Mb, so you’ll have to recreate it yourself.  I highly recommend it, it’s interesting.  For comparison, here is a recording of a piano, middle c tone:

grand-piano-fazioli-major-c-middle1

And here’s my generated tone:

middle-c-generated-rev1

The generated version sounds different because there’s no envelope shaping on it– it’s just a constant amplitude.  However, I if you listen to both a few times the tone is somewhat similar.

Next, I started working at digitizing a single waveform.  I couldn’t figure out an easy way to do this directly from my generated tone, so instead I built the values in Excel:

 

handcrafted!

handcrafted!

I then copied the summed values (column N) into a 48 element char array in my Arduino sketch.  If you want this spreadsheet, here ya go.  Finally, here’s another Unintended Comedy Amateur Hour video of me playing around with the generated sound in the Arduino:

I’m going to talk a little more about the specific programming techniques I used to make the Arduino do this in a separate post.

Update: that post is here.