# @jcoreio/i2c

> Native bindings for i2c-dev. Plays well with Raspberry Pi and BeagleBone.

Latest version **1.0.3** (published 2024-05-29) · BSD-3-Clause-Attribution license · 0 weekly downloads

## Install

```sh
npm install @jcoreio/i2c
pnpm add @jcoreio/i2c
yarn add @jcoreio/i2c
bun add @jcoreio/i2c
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2024-05-29 |
| First published | 2020-11-23 |
| Weekly downloads | 0 |
| License | BSD-3-Clause-Attribution |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 46.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 0 |
| Author | Kelly Korevec |
| Maintainers | gravitate1838, avramdodson, forrest-keller, jrmclaurin, jedwards1211, eladendorf |

## Links

- npm: https://www.npmjs.com/package/@jcoreio/i2c
- Repository: https://github.com/jcoreio/node-i2c
- Homepage: https://github.com/jcoreio/node-i2c#readme
- Issues: https://github.com/jcoreio/node-i2c/issues
- npm.io page: https://npm.io/package/@jcoreio/i2c

## Dependencies (2)

- [nan](https://npm.io/package/nan.md) ~2.19.0
- [bindings](https://npm.io/package/bindings.md) ~1.5.0

## Recent versions

- 1.0.3 (latest) — 2024-05-29
- 1.0.2 — 2020-11-23
- 1.0.1 — 2020-11-23
- 1.0.0 — 2020-11-23

## README

# i2c

Bindings for i2c-dev. Plays well with Raspberry Pi and Beaglebone.

Based on [kelly/node-i2c](https://github.com/kelly/node-i2c), converted from CoffeeScript
to TypeScript and from callbacks to promises, but with only a subset of the original
project's methods.

## Install

```bash
$ yarn add @jcoreio/i2c
```

## Usage

```typescript
import I2C from '@jcoreio/i2c'
const i2c = new I2C({ device: '/dev/i2c-1', address: 0x50 })
const OFFSET = 16

// In an async function
const writeData = Buffer.alloc(8)
try {
  await i2c.write(OFFSET, writeData)
  // wait 1 ms before reading back
  await new Promise(resolve => setTimeout(resolve, 1))
  // read back
  const readData = await i2c.read(OFFSET, 8)
} finally {
  i2c.close()
}
```

## Raspberry Pi Setup

```bash
$ sudo vi /etc/modules
```

Add these two lines

```bash
i2c-bcm2708
i2c-dev
```

```bash
$ sudo vi /etc/modprobe.d/raspi-blacklist.conf
```

Comment out blacklist i2c-bcm2708

```
#blacklist i2c-bcm2708
```

Load kernel module

```bash
$ sudo modprobe i2c-bcm2708
$ sudo modprobe i2c-dev
```

Make device writable

```bash
sudo chmod o+rw /dev/i2c*
```

Install gcc 4.8 (required for Nan)

```bash
sudo apt-get install gcc-4.8 g++-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8
sudo update-alternatives --config gcc
```

Set correct device for version

```javascript
new I2C({ address, device: '/dev/i2c-0' }) // rev 1
new I2C({ address, device: '/dev/i2c-1' }) // rev 2
```

## Beaglebone

```bash
$ ntpdate -b -s -u pool.ntp.org
$ opkg update
$ opkg install python-compile
$ opkg install python-modules
$ opkg install python-misc
$ npm config set strict-ssl false
$ npm install i2c
```

## Node 0.11 and under

```bash
npm install i2c@0.1.8
```

## Projects using i2c

- **bonescript** https://github.com/jadonk/bonescript/
- **ADXL345** https://github.com/timbit123/ADXL345
- **HMC6343** https://github.com/omcaree/node-hmc6343
- **LSM303** https://github.com/praneshkmr/node-lsm303
- **MPU6050** https://github.com/jstapels/mpu6050/
- **MCP3424** https://github.com/x3itsolutions/mcp3424
- **blinkm** https://github.com/korevec/blinkm
- **click boards** https://github.com/TheThingSystem/node-click-boards
- more: https://www.npmjs.org/browse/depended/i2c

## Contributors

Thanks to @alphacharlie for Nan rewrite, and @J-Cat for Node 14 updates.

## Questions?

http://www.twitter.com/korevec

---
_Source: https://npm.io/package/@jcoreio/i2c · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
