Device::SMBus - Perl interface for smbus using libi2c-dev library.
version 1.06
use Device::SMBus;
$dev = Device::SMBus->new(
I2CBusDevicePath => '/dev/i2c-1',
I2CDeviceAddress => 0x1e,
);
print $dev->readByteData(0x20);
This is a perl interface to smbus interface using libi2c-dev library.
Prerequisites:
sudo apt-get install libi2c-dev i2c-tools build-essential
If you are using Angstrom Linux use the following:
opkg install i2c-tools
opkg install i2c-tools-dev
Enabling the I2C on a Raspberry Pi:
You will need to comment out the driver from the blacklist. currently the I2C driver isn't being loaded.
sudo vim /etc/modprobe.d/raspi-blacklist.conf
Replace this line
blacklist i2c-bcm2708
with this
#blacklist i2c-bcm2708
You now need to edit the modules conf file.
sudo vim /etc/modules
Add these two lines;
i2c-dev
i2c-bcm2708
Now run this command(replace 1 with 0 for older model Pi)
sudo i2cdetect -y 1
you should now see the addresses of the i2c devices connected to your i2c bus
Device path of the I2C Device.
* On Raspberry Pi Model A this would usually be /dev/i2c-0 if you are using the default pins.
* On Raspberry Pi Model B this would usually be /dev/i2c-1 if you are using the default pins.
This is the Address of the device on the I2C bus, this is usually available in the device Datasheet.
* for /dev/i2c-0 look at output of `sudo i2cdetect -y 0'
* for /dev/i2c-1 look at output of `sudo i2cdetect -y 1'
returns IO::Handle->error() for the device handle since the last clearerr
$self->writeQuick($value)
$self->readByte()
$self->writeByte()
$self->readByteData($register_address)
$self->writeByteData($register_address,$value)
$self->readNBytes($lowest_byte_address, $number_of_bytes);
Read together N bytes of Data in linear register order. i.e. to read from 0x28,0x29,0x2a
$self->readNBytes(0x28,3);
$self->readWordData($register_address)
$self->writeWordData($register_address,$value)
$self->processCall($register_address,$value)
$self->writeBlockData($register_address, $values)
Writes a maximum of 32 bytes in a single block to the i2c device. The supplied $values should be an array ref containing the bytes to be written.
Destructor
This module provides a simplified object oriented interface to the libi2c-dev library for accessing electronic peripherals connected on the I2C bus. It uses Moose.
Please report any bugs or feature requests through github at https://github.com/shantanubhadoria/device-smbus/issues. You will be notified automatically of any progress on your issue.
This is open source software. The code repository is available for public review and contribution under the terms of the license.
https://github.com/shantanubhadoria/device-smbus
git clone git://github.com/shantanubhadoria/device-smbus.git
Shantanu Bhadoria <shantanu at cpan dott org>
Neil Bowers <neil@bowers.com>
Shantanu <shantanu@cpan.org>
Shantanu Bhadoria <shantanu.bhadoria@gmail.com>
Shantanu Bhadoria <shantanu@cpan.org>
root <root@beaglebone.(none)>
This software is copyright (c) 2013 by Shantanu Bhadoria.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.