All Projects → cho45 → Ruby I2c Devices

cho45 / Ruby I2c Devices

i2c-devices is a library for using I2C devices by using /dev/i2c-* or /sys/class/gpio with bit-banging.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Ruby I2c Devices

w1-gpio-cl
Command line configured kernel mode 1-wire bus master driver. w1-gpio standard Linux module enhancement/substitution.
Stars: ✭ 17 (-26.09%)
Mutual labels:  gpio, driver
moon c
문c 블로그 with ARM64 Linux Kernel 5.x
Stars: ✭ 17 (-26.09%)
Mutual labels:  gpio, driver
Uhd
The USRP™ Hardware Driver Repository
Stars: ✭ 544 (+2265.22%)
Mutual labels:  driver
Imanager
Advantech iManager Linux driver set for Advantech Embedded Boards
Stars: ✭ 16 (-30.43%)
Mutual labels:  gpio
Pigpio
Fast GPIO, PWM, servo control, state change notification and interrupt handling with Node.js on the Raspberry Pi
Stars: ✭ 747 (+3147.83%)
Mutual labels:  gpio
Neo4j Python Driver
Neo4j Bolt driver for Python
Stars: ✭ 607 (+2539.13%)
Mutual labels:  driver
Displaylink Debian
DisplayLink driver installer for Debian and Ubuntu based Linux distributions.
Stars: ✭ 768 (+3239.13%)
Mutual labels:  driver
Blackhole
BlackHole is a modern macOS virtual audio driver that allows applications to pass audio to other applications with zero additional latency.
Stars: ✭ 6,834 (+29613.04%)
Mutual labels:  driver
Yubihsm Go
A Go client for the yubihsm2 binary protocol and connector service
Stars: ✭ 19 (-17.39%)
Mutual labels:  driver
Cuprite
Headless Chrome/Chromium driver for Capybara
Stars: ✭ 743 (+3130.43%)
Mutual labels:  driver
Adldap2 Laravel
LDAP Authentication & Management for Laravel
Stars: ✭ 825 (+3486.96%)
Mutual labels:  driver
Vigembus
Windows kernel-mode driver emulating well-known USB game controllers.
Stars: ✭ 721 (+3034.78%)
Mutual labels:  driver
Sfud
An using JEDEC's SFDP standard serial (SPI) flash universal driver library | 一款使用 JEDEC SFDP 标准的串行 (SPI) Flash 通用驱动库
Stars: ✭ 608 (+2543.48%)
Mutual labels:  driver
Mongo Cxx Driver
C++ Driver for MongoDB
Stars: ✭ 792 (+3343.48%)
Mutual labels:  driver
Clickhouse Driver
ClickHouse Python Driver with native interface support
Stars: ✭ 562 (+2343.48%)
Mutual labels:  driver
Vsphere Modules
This is my Module Collection for VMware vSphere
Stars: ✭ 18 (-21.74%)
Mutual labels:  driver
Contrib Drivers
Open source peripheral drivers
Stars: ✭ 539 (+2243.48%)
Mutual labels:  driver
Neo4j Javascript Driver
Neo4j Bolt driver for JavaScript
Stars: ✭ 674 (+2830.43%)
Mutual labels:  driver
Hidden
Windows driver with usermode interface which can hide objects of file-system and registry, protect processes and etc
Stars: ✭ 768 (+3239.13%)
Mutual labels:  driver
Upboard ros
ROS nodes for upboard usage
Stars: ✭ 22 (-4.35%)
Mutual labels:  gpio

ruby-i2c-devices

i2c-devices is a library for using I2C devices.

SYNOPSYS

Usage of I2CDevice class directly:

require "i2c"
require "i2c/driver/i2c-dev"
device = I2CDevice.new(address: 0x60, driver: I2CDevice::Driver::I2CDev.new("/dev/i2c-1"))

# like i2c-tools's i2cget command
length = 3
device.i2cget(0x01, length)

# like i2c-tools's i2cset command
device.i2cset(0x01, 0x11, 0x12 ... )

or pre-defiend device driver class:

require "i2c/device/acm1602ni"

lcd = I2CDevice::ACM1602NI.new

lcd.put_line(0, "0123456789ABCDEF")

with driver class

require "i2c/device/mpl115a2"
require "i2c/driver/i2c-dev"

mpl = I2CDevice::MPL115A2.new(driver: I2CDevice::Driver::I2CDev.new("/dev/i2c-0"))
p mpl.calculate_hPa

or GPIO backend driver (this is very slow)

require "i2c/device/mpl115a2"
require "i2c/driver/gpio"

mpl = I2CDevice::MPL115A2.new(driver: I2CDevice::Driver::GPIO.new(
	sda: 23, # pin 16 in raspberry pi
	scl: 24, # pin 18 in raspberry pi
))

p mpl.calculate_hPa

Class

I2CDevice

Generic class for manipulating I2C device.

I2CDevice.new(address: address, driver: driver)

  • address : Integer : 7-bit slave address without r/w bit. MSB is always 0.
  • driver : I2CDevice::Driver : backend driver class. (default: I2CDevice::Driver::I2CDev)

I2CDevice#i2cset(*data) #=> Integer

Write data to slave.

Returns Integer which is bytes length wrote.

I2CDevice#i2cget(param, length=1) #=> String

This method read data from slave with following process:

  1. Write param to slave
  2. re-start
  3. Read data until NACK or length

Returns String.

I2CDevice::Driver::I2CDev

This depends on /dev/i2c-* (i2c-dev) feature on Linux. You may load i2c-dev kernel module.

I2CDevice::Driver::I2CDev.new(path)

  • path : String : Path to /dev/i2c-*

I2CDevice::Driver::GPIO

This depends on /sys/class/gpio feature on Linux and implements by bit-banging.

I2CDevice::Driver::I2CDev.new(sda: sda, scl: scl, speed: speed)

  • sda : Integer : Pin number of SDA.
  • scl : Integer : Pin number of SCL.
  • speed : Integer : I2C clock speed in kHz. (default: 1)

Pin number of sda and scl is not real pin number but logical pin number. Eg. In Raspberry Pi, specifing sda: 23, scl: 24 means using 16 and 18 pin.

You can specify 100 kHz or 400 kHz (or more) to speed but speed is rate-limited by host CPU speed. Typically, this module fall short of requirements of I2C spec (in Raspberry Pi, clock speed is about 1.3kHz). But most slave devices support DC~100kHz clock speed.

REQUIREMENTS

Currently this library depends on Linux's i2c-dev or sysfs with GPIO feature.

  • I2CDevice::Driver::I2CDev /dev/i2c-0 (i2c-dev), default
  • I2CDevice::Driver::GPIO /sys/class/gpio (GPIO)

TODO

  • More supported devices
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].