• Stars
    star
    174
  • Rank 219,104 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created over 9 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Implementation of I2C-bus written in Golang. Forked from davecheney/i2c.

I2C-bus interaction of peripheral sensors with Raspberry PI embedded linux or respective clones

Build Status Go Report Card GoDoc MIT License

This library written in Go programming language intended to activate and interact with the I2C bus by reading and writing data.

Compatibility

Tested on Raspberry Pi 1 (model B), Raspberry Pi 3 B+, Banana Pi (model M1), Orange Pi Zero, Orange Pi One.

Golang usage

func main() {
  // Create new connection to I2C bus on 2 line with address 0x27
  i2c, err := i2c.NewI2C(0x27, 2)
  if err != nil { log.Fatal(err) }
  // Free I2C connection on exit
  defer i2c.Close()
  ....
  // Here goes code specific for sending and reading data
  // to and from device connected via I2C bus, like:
  _, err := i2c.Write([]byte{0x1, 0xF3})
  if err != nil { log.Fatal(err) }
  ....
}

Tutorial

My repositories contain quite a lot projects, which use i2c library as a starting point to interact with various peripheral devices and sensors for use on embedded Linux devices. All these libraries start with a standard call to open I2C-connection to specific bus line and address, than pass i2c instance to device.

In its turn, go-i2c use go-logger library to output debug and other notification's lines which produce all necessary levels of logging. You can manage what level of verbosity you would like to see, by adding call:

// Uncomment/comment next line to suppress/increase verbosity of output
logger.ChangePackageLogLevel("i2c", logger.InfoLevel)

Once you put this call, it will decrease verbosity from default "Debug" up to next "Info" level, reducing the number of low-level console outputs that occur during interaction with the I2C bus. Please, find examples in corresponding I2C-driven sensors among my projects.

You will find here the list of all devices and sensors supported by me, that reference this library:

Getting help

GoDoc documentation

Troubleshooting

  • How to obtain fresh Golang installation to RPi device (either any RPi clone): If your RaspberryPI golang installation taken by default from repository is outdated, you may consider to install actual golang manually from official Golang site. Download tar.gz file containing armv6l in the name. Follow installation instructions.

  • How to enable I2C bus on RPi device: If you employ RaspberryPI, use raspi-config utility to activate i2c-bus on the OS level. Go to "Interfacing Options" menu, to active I2C bus. Probably you will need to reboot to load i2c kernel module. Finally you should have device like /dev/i2c-1 present in the system.

  • How to find I2C bus allocation and device address: Use i2cdetect utility in format "i2cdetect -y X", where X may vary from 0 to 5 or more, to discover address occupied by peripheral device. To install utility you should run apt install i2c-tools on debian-kind system. i2cdetect -y 1 sample output:

          0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
     00:          -- -- -- -- -- -- -- -- -- -- -- -- --
     10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
     20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
     30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
     40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
     50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
     60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
     70: -- -- -- -- -- -- 76 --    
    

License

Go-i2c is licensed under MIT License.

More Repositories

1

go-dht

Golang library to interact with DHT11/DHT22/DHT12 temperature and humidity sensors from Raspberry PI.
C
132
star
2

go-rsync

Best GTK+ frontend (backup application) for RSYNC utility.
Go
119
star
3

go-bsbmp

Golang library to interact with Bosch Sensortec BMP180/BMP280/BME280/BMP388 temperature, pressure and humidity sensors via I2C-bus from Raspberry PI.
Go
42
star
4

go-max7219

Golang library to interact with LED driver MAX7219 via SPI-bus from Raspberry PI.
Go
14
star
5

go-vl53l0x

Golang library to interact with ST VL53L0X time-of-flight ranging sensor via I2C-bus from Raspberry PI.
Go
11
star
6

go-sht3x

Golang library to interact with Sensirion SHT3x relative humidity and temperature sensor's family via I2C-bus from Raspberry PI.
Go
6
star
7

upstream-hostapd-force-ht40-mode-patch

Add option "force_ht40" to force 802.11n 40MHz AP mode, to override overlapping BSSes detection and escape fallback to 20MHz mode.
6
star
8

go-si7021

Golang library to interact with Silicon Labs Si7021 relative humidity and temperature sensor via I2C-bus from Raspberry PI.
Go
6
star
9

go-aosong

Golang library to interact with humidity and temperature Aosong Electronics DHT12/AM2320 sensors working via i2c-bus
Go
5
star
10

go-shell

Auxiliary library for the launch and control external applications, making syscals and catching of SIG-calls.
Go
2
star
11

go-logger

Golang logger functionality with logging separation by package to improve debug process
Go
2
star
12

jsonc-bash

JSON and JSONC (JSON with comments) bash parser.
Shell
1
star
13

go-bh1750

Golang library to interact with BH1750 ambient light sensor from Raspberry PI.
Go
1
star
14

sqlg

Go
1
star
15

go-mpl3115a2

Golang library to interact with MPL3115A2 pressure and altitude sensor from Raspberry PI.
Go
1
star