{"id":18071568,"url":"https://github.com/cho45/ruby-i2c-devices","last_synced_at":"2026-03-10T07:01:35.069Z","repository":{"id":14152600,"uuid":"16858373","full_name":"cho45/ruby-i2c-devices","owner":"cho45","description":"i2c-devices is a library for using I2C devices by using /dev/i2c-* or /sys/class/gpio with bit-banging.","archived":false,"fork":false,"pushed_at":"2018-09-07T13:42:13.000Z","size":67,"stargazers_count":22,"open_issues_count":1,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-02-18T17:38:47.114Z","etag":null,"topics":["driver","gpio","i2c-device","i2cdev","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cho45.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-15T07:17:40.000Z","updated_at":"2023-04-07T00:04:06.000Z","dependencies_parsed_at":"2022-07-08T06:40:41.966Z","dependency_job_id":null,"html_url":"https://github.com/cho45/ruby-i2c-devices","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/cho45/ruby-i2c-devices","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cho45%2Fruby-i2c-devices","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cho45%2Fruby-i2c-devices/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cho45%2Fruby-i2c-devices/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cho45%2Fruby-i2c-devices/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cho45","download_url":"https://codeload.github.com/cho45/ruby-i2c-devices/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cho45%2Fruby-i2c-devices/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30326893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T05:25:20.737Z","status":"ssl_error","status_checked_at":"2026-03-10T05:25:17.430Z","response_time":106,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["driver","gpio","i2c-device","i2cdev","ruby"],"created_at":"2024-10-31T09:15:49.037Z","updated_at":"2026-03-10T07:01:35.044Z","avatar_url":"https://github.com/cho45.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"ruby-i2c-devices\n================\n\ni2c-devices is a library for using [I2C]( http://www.i2c-bus.org/ ) devices.\n\nSYNOPSYS\n========\n\nUsage of I2CDevice class directly:\n\n```\nrequire \"i2c\"\nrequire \"i2c/driver/i2c-dev\"\ndevice = I2CDevice.new(address: 0x60, driver: I2CDevice::Driver::I2CDev.new(\"/dev/i2c-1\"))\n\n# like i2c-tools's i2cget command\nlength = 3\ndevice.i2cget(0x01, length)\n\n# like i2c-tools's i2cset command\ndevice.i2cset(0x01, 0x11, 0x12 ... )\n\n```\n\nor pre-defiend device driver class:\n\n```\nrequire \"i2c/device/acm1602ni\"\n\nlcd = I2CDevice::ACM1602NI.new\n\nlcd.put_line(0, \"0123456789ABCDEF\")\n```\n\n\nwith driver class\n\n```\nrequire \"i2c/device/mpl115a2\"\nrequire \"i2c/driver/i2c-dev\"\n\nmpl = I2CDevice::MPL115A2.new(driver: I2CDevice::Driver::I2CDev.new(\"/dev/i2c-0\"))\np mpl.calculate_hPa\n```\n\nor GPIO backend driver (this is very slow)\n\n```\nrequire \"i2c/device/mpl115a2\"\nrequire \"i2c/driver/gpio\"\n\nmpl = I2CDevice::MPL115A2.new(driver: I2CDevice::Driver::GPIO.new(\n\tsda: 23, # pin 16 in raspberry pi\n\tscl: 24, # pin 18 in raspberry pi\n))\n\np mpl.calculate_hPa\n\n```\n\nClass\n=====\n\nI2CDevice\n---------\n\nGeneric class for manipulating I2C device.\n\n### I2CDevice.new(address: address, driver: driver)\n\n * address : Integer : 7-bit slave address without r/w bit. MSB is always 0.\n * driver : I2CDevice::Driver : backend driver class. (default: I2CDevice::Driver::I2CDev)\n\n### I2CDevice#i2cset(*data) #=\u003e Integer\n\nWrite `data` to slave.\n\nReturns `Integer` which is bytes length wrote.\n\n### I2CDevice#i2cget(param, length=1) #=\u003e String\n\nThis method read data from slave with following process:\n\n 1. Write `param` to slave\n 2. re-start\n 3. Read data until NACK or `length`\n\nReturns `String`.\n\nI2CDevice::Driver::I2CDev\n-------------------------\n\nThis depends on /dev/i2c-* (i2c-dev) feature on Linux. You may load i2c-dev kernel module.\n\n### I2CDevice::Driver::I2CDev.new(path)\n\n * path : String : Path to /dev/i2c-*\n\n\nI2CDevice::Driver::GPIO\n-----------------------\n\nThis depends on /sys/class/gpio feature on Linux and implements by bit-banging.\n\n### I2CDevice::Driver::I2CDev.new(sda: sda, scl: scl, speed: speed)\n\n * sda   : Integer : Pin number of SDA.\n * scl   : Integer : Pin number of SCL.\n * speed : Integer : I2C clock speed in kHz. (default: 1)\n\nPin number of `sda` and `scl` is not real pin number but logical pin number.\nEg. In Raspberry Pi, specifing `sda: 23, scl: 24` means using 16 and 18 pin.\n\nYou can specify 100 kHz or 400 kHz (or more) to `speed` but speed is rate-limited by host CPU speed.\nTypically, this module fall short of requirements of I2C spec (in Raspberry Pi, clock speed is about 1.3kHz).\nBut most slave devices support DC~100kHz clock speed.\n\nREQUIREMENTS\n============\n\nCurrently this library depends on Linux's i2c-dev or sysfs with GPIO feature.\n\n * I2CDevice::Driver::I2CDev /dev/i2c-0 (i2c-dev), default\n * I2CDevice::Driver::GPIO /sys/class/gpio (GPIO)\n\nTODO\n====\n\n * More supported devices\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcho45%2Fruby-i2c-devices","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcho45%2Fruby-i2c-devices","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcho45%2Fruby-i2c-devices/lists"}