Jun 1 2014

Breadboard-friendly i2c logic level converter

By Max

IMG_20140531_222803 (2)Lately I’ve been using my 5V Arduino in concert with 3.3V devices via i2c, and so I’ve found myself requiring an interface part to convert the two logic levels.

I had previously done this on the breadboard with two 2N7000 MOS-FETs according to this Philips application note AN97055:

i2c Logic Level Shifter Schematic

This worked, but it was a lot of parts to set up on the breadboard each time, and I wanted something hardwired so that I could focus on other things when it came time to troubleshoot.  So I cooked up this little guy:

IMG_20140601_134500~2

Testing the waveform with an oscilliscope, you can see some noise is introduced on Channel 1, but I always wonder in these cases how much of that is just because I have a bunch of probes stuck everywhere– the act of measuring changes the measured behavior and so on.  But, it should be perfectly adequate for prototyping purposes.

i2c SCL line

5V signal in blue (channel 2). Resulting 3.3V signal in yellow.

Downloads:

If you’d like my Eagle files to incorporate this into your file, 3V to 5V i2c Eagle Files.

A pdf ready to etch is here: 3V to 5V i2c Eagle Files Level Shifter Rev0.

One note: if you look at the pictures of the finished product, you’ll see that rather than the usual way of doing things where you put the PCB on the bottom plane, then drill through and put the components on top, I’ve instead mirrored the layout, and soldered the components on the top plane.

 I did that so that I could solder the pin headers on top, as you can’t solder them to the bottom traces because the plastic connectors get in the way.  If you download the pdf I linked to, it’s already been flipped and is ready to go.  If you download the eagle files, make sure you select “mirror” from the print options.

Hope it comes in useful for you!

 


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” »