background preloader

Tutoriales

Facebook Twitter

John's Linux Blog: Programming I2C. Although you can perform simple i2c reads and writes using the command line tools i2cget and i2cset, for a more integrated approach you can use a programming language to talk to the bus. The are dozens of languages which make claims about ease of use and learning etc. and I am sure you can program i2c from them. What I will demonstrate here is the simple way to do it from c. Although I don't aim to teach how to program in c, I will try and explain what the code is doing so you can follow along even if you are new to c. This will use some basic i2c read and writes as described at We will also need to perform some IO Control (ioctl) which are i2c specific.

First we need some code to get us started. #include <stdio.h>#include <fcntl.h>#include <unistd.h>#include <sys/ioctl.h>#include <linux/i2c-dev.h> All of our code will live in the main function for now. main() is where all c programs start. char *dev = "/dev/i2c-1"; int addr = 0x48; I2C on the Beaglebone | Making A Quadrotor. I got I2C working well a couple of weeks back and got both the modules I am using working well with the beaglebone. I later modified the code to allow API calls to read the values from the two modules. Now I have a proper working directory for the complete project and I’ve decided to test out other things separately and then import them into this single working directory. This post is to describe how to get the I2C working on the Beaglebone.

I got some help from The only problem was that I planned on using C/C++, not python, for better support with OpenCV. I’ll explain the protocol along with the code together. This post assumes you know a bit of electronics. What needs to be is this: Include these header files: #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <linux/i2c-dev.h> or the corresponding cpp header files. What you need to understand about I2C is that it is a bus. i2cdetect -y -r 3 In my example, I write to i2cbus 3. i2c. Native bindings for i2c-dev. Plays well with Raspberry Pi and BeagleBone. npm install i2c Want to see pretty graphs? Log in now! Read Me Bindings for i2c-dev. Install $ npm install i2c Usage Raspberry Pi Setup $ sudo vi /etc/modules Add these two lines i2c-bcm2708 i2c-dev $ sudo vi /etc/modprobe.d/raspi-blacklist.conf Comment out blacklist i2c-bcm2708 #blacklist i2c-bcm2708 Load kernel module $ sudo modprobe i2c-bcm2708 Make device writable sudo chmod o+rw /dev/i2c* Set correct device for version new i2c(address, device: '/dev/i2c-0') new i2c(address, device: '/dev/i2c-1') ` Beaglebone $ ntpdate -b -s -u pool.ntp.org $ opkg update $ opkg install python-compile $ opkg install python-modules $ npm config set strict-ssl false $ npm install i2c Projects using i2c Questions?

JavaScript Functions. Using I2C from userspace in Linux. I’ve been using various I2C things in Linux for the past year and a bit, and I’ve learnt a few things about it from that. Here I hope to collate some of this information. Linux has an i2c subsystem. This provides methods for interacting with I2C clients connected to the same bus as the machine running Linux. As far as I know, Linux can only be a master at the moment. If you’ve got an I2C client that needs to interact with your Linux system then you’ve got two options. The first is to write a driver as a Linux kernel module.

Preparing your system The first thing to do is to make sure that the kernel that you’re going to be running this program under has the “I2C device interface” driver either compiled in or as a module. When one has both the i2c-dev module and the kernel module for the I2C adapter loaded, a device file called /dev/i2c-0 (or /dev/i2c-1, /dev/i2c-2 etc.) will be created. . % mknod /dev/i2c-0 c 89 0 Which will create the device file. Opening the device Operations SMBus functions. Port - Linux equivalents for Arduino I²C libraries (Wire) Kernel. Arduino-like userspace libraries for the Beagle.

Interfacing with I2C Devices. This page is meant to provide some basic information about how to interface with I²C devices through the /dev/i2c interface. The I²C bus is commonly used to connect relatively low-speed sensors and other peripherals to equipment varying in complexity from a simple microcontroller to a full-on motherboard. I²C is extremely popular due to its ease-of-use and ability to control multiple peripherals while utilizing only two pins on the host controller. Although I²C has a variety of modes, this page will deal purely with communication between a Linux-based master and a slave peripheral for the time being.

Note: Examples shown on this page were developed based on a Texas Instruments BeagleBoard and some changes will be required depending on the system being utilized. Beagleboard I2C2 Enable The TI BeagleBoard has 3 I²C buses available, which control a variety of on-board peripherals, including the DVI display driver and power sequencing. i2c-tools $i2cdetect -r 2 Opening the Bus Writing to the ADC.