# How to connect a sensor via I2C on an OSX computer?

I am growing a sort of interest for hardware projects; and lately I started to experiment with BeagleBone and various types of sensor.

Now I realize that, to reduce the size of your hardware (and costs of course), you can't always have an Arduino or a BeagleBone attached to your sensors, to drive the I2C chain. So I am looking for alternatives, that allows me to have a I2C chain of sensors, without using the beagle bone or the Arduino.

The first idea would be to use a computer to drive the sensors (after all, the hardware would run in conjunction with an application that is running on a computer). I have done a search for USB to I2C, but seems that most of these adapters are not simple translators but they have a ton of features that I don't need (hence the high cost).

Either via USB or via wireless would be fine; all that I need is to drive these sensors, gather the data and then send it out for processing. At the moment I can do it with the beagle bone, but I would like to explore alternatives. My sensors works either with I2C and with SPI, I have 5 of them.

I am new to the world of hardware hacking; I barely was able to connect a temperature sensor to the BeagleBone, and write a console app to process the data from it; so I am not even sure if this is possible with normal means, or if I need more experience and skills to make my own interfaces and boards. Although it seems quite strange to reinvent the wheel every time :) If hardware development is similar to software development; there must be someone else that already had that issue and made a solution, so you don't have to write the same thing over and over.

• There are plenty of microcontrollers which can provide similar functionality to an Arduino and will fit inside a USB connector shell; some may even be source-compatible to a fair degree. If you feel like doing wild hacks, you might see if you can somehow leverage a video port's ability to read properties of a connector monitor over an I2C-like interface, but this seems less plausible/straightforward on a Mac than it might be on other systems. – Chris Stratton Feb 7 '14 at 23:36

A BeagleBone actually is the right sort of answer.

I fully understand the problem. A BeagleBoard is vastly overpowered for this job. it is inefficient and physically vulnerable.

There's no technical reason you couldn't get this down to a small, reliable, compact, durable $5 adapter, with USB on one end and 3 screw terminals on the other. Such adapters exist for USB to RS-232, for example. The reason such adapters do not exist is simple: low potential sales volume. The first step towards the ideal, starting from a general-purpose development board like the BeagleBone, is to switch to the smallest microcontroller that can drive both a USB and I²C bus simultaneously at the full data rate of the I²C side. This is how the early USB to RS-232 adapters worked. They were rather costly and bulky by current standards, but because they were made entirely from off-the-shelf hardware, they were quick to get to market. Because of the low potential sales volume, I'd expect to pay at least$20 for such thing, and would only expect to find it from a company like Adafruit or SparkFun, since their product diversity combines many small income streams into a single large one.

The reason you've found others charging much more than this is that is that a specialist manufacturer must go for the high end of the market. It's the only way to survive when the market size is naturally small.

Consider PC database systems.

In the early days of personal computing, general-purpose database systems didn't really exist for PCs. Many of the dedicated geeks who bought these early PCs solved problems we'd now solve with a DBMS with custom BASIC code, or even assembly. If you have any personal computing magazines from the late 1970s or early 1980s, look for the ads by companies selling $100 sorting programs! That level of technology is analogous to what you're doing now: writing BeagleBone code to lash I²C peripherals to a USB bus, so they can talk to a computer that doesn't have an external I²C bus. Getting back to the historical analogy... In the early 1980s, word processors and spreadsheet programs started to get bundled with simple general-purpose DBMSes. By the mid-1980s, most everyone had a database system. The software bundle often came with the computer. As the 1980s wore on, many of the uses for PC DBMSes started being better addressed by custom software, shrinking the user set size for DBMSes, increasing specialization. Feature set sizes and complexity grew, so that by the early 1990s, DBMSes started dropping out of office suites, because they had turned into software developer tools. The PC DBMS market eventually stabilized, with a wide gap between Excel-as-DBMS and Access/FileMaker, because the middle ground is unprofitable. (As a Mac user, you probably watched the failure of Bento, which sat itself right in the middle of that gap.) The gap continues to widen. Access and FileMaker are development environments unto themselves, and will continue to get more complex as they focus more on custom development and less on one-offs by solo dilettantes. I expect them to die off, too, at some point, as DBMS development moves to mobile and the cloud, further increasing complexity and specialization. The I²C equivalent in this analogy is that I²C is now a commodity microcontroller peripheral, a datasheet checklist item. In the same way that true DBMSes are now served by a cadre of specialist software developers, most I²C work is done by specialist EEs writing code to talk to their μC's I²C peripheral. The only way to get from that point to the point where you could expect to buy a$5 plastic-molded mass-produced adapter from the local computer store is for someone to come out with a custom IC, an I²C equivalent of the ubiquitous PL2303. I can't see this happening, ever.

The market size is fundamentally limited but the fact that USB is an outside-the-case sort of interconnect, but I²C is an inside-the-case interconnect, owing to the combination of relatively high data rate and single-ended signaling. The only reason USB to RS-232 adapters exist — despite the fact that RS-232 is also single-ended — is that RS-232 normally maxes out at 115,200 bps, just barely faster than the slowest I²C links. At normal I²C speeds, you really need differential signaling if you're going a long distance outside a shielded enclosure.

The point is, USB to I²C adapters are going to remain special-purpose things, hence expensive, bulky, clumsy, and/or overpowered.

• This an excellent answer. However, Capitalism always finds a way: mouser.com/ProductDetail/FTDI/UMFT200XD-01/… USB to I2C for $9.50 at Mouser – lyndon Feb 8 '14 at 23:05 • You got exactly the point, Sir. I am quite sad to use an overpowered solution (and bulky...altho I am removing the network connector and the 2 connectors headers, since I will need just the I2C pins, so at least it will be slimmer), but the alternatives are sadly almost in the same price range. It really anger me that there are plenty of serial connection solutions, but for I2C you need to buy a specific solution. Thanks for the excellent reply. – rataplan Feb 8 '14 at 23:20 • I think that I have found something that will in fact work for what I need: Adafruit has a product which is not sold as I2C to USB converter, but it is in fact a micro controller with SPI and I2C support, for less than 10 dollars: adafruit.com/products/1501 – rataplan Feb 9 '14 at 5:06 • @newbiez: Isn't the lack of a serial monitor port going to be a problem in this application? You'd have to write direct USB code to talk to it from your Mac. The FTDI product from Mouser looks like a better bet to me. Not much more expensive, and already set up and ready to go. Only thing I don't like is how stripped-down it is. No enclosure, no USB-A shield, and insecure 0.1" headers on I2C side. You could fix all that with a USB-A extension cable and a project box, which Mouser also carries. – Warren Young Feb 9 '14 at 14:56 • @newbiez: The FTDI device emulates an RS-232 serial port on the USB side, so that you read/write to the I²C port as if it were a serial port. See section 9 in the FX200XD datasheet. (That's the chip at the heart of the board Lyndon found.) The Trinket lacks this feature, so you have to get the sensor data out another way. Adafruit has a page explaining the problem and giving one solution. – Warren Young Feb 10 '14 at 2:44 The simplest approach would be to use an Arduino or BeagleBone (or Raspberry Pi, or Intel Galileo or any number of these things) to read the sensors, buffer them, and assemble them into a serial packet which can be transmitted either directly through the onboard USB->Serial (as in the case of the Arduino or the Galileo boards), or through a simple USB->serial adapter using the on-board UART. This is assuming that the bit-rate of the I2C device is less than the fastest typically supported UART rate (115200 baud, approximately 10KByte/s). Alternatively, you can get something like this: eBay link. These devices emulate a serial port, but give you I2C instead (e.g. you can talk to it through /dev/tty*). Keep in mind that really what is in them is a simple micro-controller with some code that does the translation/buffering for you. Of course, not that many have support for Mac OSX. There's a chance you'll have to find the Windows driver and reverse engineer it for Mac. • Yeah, so far it seems that it is an overkill to put such nice board in a project box, just because you need I2C connectivity, but the alternatives are limited (especially for OSX) – rataplan Feb 8 '14 at 23:22 Googling for "mac i2c" throws up I'd try one or two of those. Personally I'd consider just putting someything like an Arduino nano into a suitable enclosure and program that to translate I2C to virtual serial. • Thanks for the reply. I did a search too, the second solution works only if you have a laptop with that video port; I use a Mac Pro. The Arduino cost as much as the BeagleBone that I already have; so would not make sense to spend the same amount for something different, that does the same of what I already use :) The idea was to get a cheap converter (just the converter), to allow me to make something smaller and cheaper (40 dollars are not an issue for a prototype, but on 100 units, is 4K...quite a lot of money for just a I2C interface). – rataplan Feb 8 '14 at 23:25 • @newbiez, Don't forget, you can buy an Arduino nano clone for$7. For a 100 units you can use something like 100xATtiny85 with soft-USB. (e.g. Your own variant of Adadfruit's trinket). – RedGrittyBrick Feb 9 '14 at 10:30
• Thanks RGB; but are these clone from China, reliable? I am not making thousands to worry, but I want to be sure that my prototypes works :) BTW seems that the tiny85, used for the trinket@adafruit, is not doing USB transmission natively, looking into it right now to see if it can be eventually used or not. – rataplan Feb 10 '14 at 10:13