Home Contacts Terms Send money


www.acmesystems.it


I2C bus interface

I2C is a multi-master serial single-ended bus invented by Philips that is used to attach low-speed peripherals to an embedded system. SMBus, defined by Intel in 1995, is a subset of I2C. This article is a practical guide to use the I2C bus on the Acme Systems Linux embedded boards

To have a more in depth idea of how the I2C works under Linux please read the Linux Kernel documentation on:

Using i2c-tools

The faster way to do the first experiments with this board is by installing and using the i2c-tools.

i2c-tools is a package contains a heterogeneous set of I2C tools for Linux such as:

To install i2c-tools on the FOX Board just type:

~# apt-get update
~# apt-get install i2c-tools

Using i2cdetect

i2cdetect is an userspace program to scan an I2C bus for devices. It outputs a table with the list of detected devices on the specified bus.

Example of use:

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

In this case a device has been detected on address 20 hex.

Using i2cset and i2cset

i2cget is a small helper program to set registers visible through the I2C bus.

The follow simple command writes the byte value 255 to the I2C device at address 20 hex on the i2c bus 0 (/dev/i2c-0).

~# i2cset -y 0 0x20 255

If for example you are using a DAISY-22 module with a PCF8574 I2C I/O expander this command will set all the GPIO lines to 1.

i2cget i2cget is a small helper program to read registers visible through the I2C bus.

The follow simple command read a byte from an I2C device at address 20 hex on the i2c bus 0 (/dev/i2c-0).

~# i2cget -y 0 0x20
0x01

Python code example

python-smbus is a Python module allows SMBus access through the I2C /dev interface on Linux hosts. The host kernel must have I2C support, I2C device interface support, and a bus adapter driver.

Write a register

The following example sends a sequence of values from 0 to 255 to the PCF8574 I2C I/O expander at address 0x20.

Run it by typing:

~# python write.py

Read a register

The following read the GPIO status of a PCF8574 I2C I/O expander at address 0x20. Note that we have to write 1 on the input line we want to read.

Run it by typing:

~# python read.py

C code example

Write a register

The following example sends a sequence of values from 0 to 255 to the PCF8574 I2C I/O expander at address 0x20 in C language.

Compile it by typing:

~# gcc write.c -o write

Then launch it:

~# ./write

Read a register

The following example get the state of the GPIO line from a PCF8574 I2C I/O expander at address 0x20.

Compile it by typing:

~# gcc read.c -o read

Then launch it:

~# ./read

Related links


ARIAG25-128 : ARM9 Linux Embedded Module EURO 24.00

Aria G25 is a small and low-cost multi-chip module that integrates:

  • an ARM9 @ 400Mhz CPU Atmel AT91SAM9G25
  • a 128MB of DDR2 RAM
  • 10/100 Ethernet interface
  • up to 3 USB 2.0 host ports
  • Normal temperature range version (-0 +70)

| Product description... |

TERRA : Linux embedded board for fast prototyping EURO 169.00

TERRA is a carrier board conceived both to evaluate the Aria G25 SoM and to make prototypes or small production batches of OEM equipments using the Daisy cabling system.

| Product description | Terra catalog |


FOXG20 : FOX Board G20 EURO 139.00

FOX Board G20 is a "ready-to-run" Embedded Linux System perfect to use as a solid state WEB server or as a core engine for your embedded appliances.

A fully Open Source environment is available to customize and build your own kernel image or to develop user applications using standard GNU tools. Version with Atmel AT91SAM9G20 with 256KB of FLASH memory, 64MB of RAM and up to 16GB of microSD.

FOXG20 needs some extra accessories in order to be operative:

  • a bootable microSD with Linux OS (see DEBM2G or DEBM4G products)
  • a 5 Volt DC power source (see PS5V1A product)
  • a 3V lithium battery for internal RTC circuitry (see CH23-1220 product)

An evalution kit with all the accessories you need to get started with FOX Board G20 is available on-line on this link: COMBO-2.


| Product description... |

LCD-1 : Mini size 16x2 characters I2C LCD EURO 6.00

Winstar display model WO1602I-TFH-AT#

  • Black on white Alphanumeric characters: 16 colums x 2 lines
  • Backlight type: LED, White
  • LCD mode: FSTN positive
  • I2C interface
  • Power supply: 3.3 or 5 volt Datasheet
  • How to use it




Acme Systems srl
Via Aldo Moro 53 - 00055 Ladispoli (RM) - Italy
P.IVA/C.F. 08114831004
Tel +39.06.99.12.187 - Fax +39.06.622.765.31
http://www.acmesystems.it
Iscritta al Registro delle Imprese di Roma al n. 08114831004


Atmel© Certified Partner

Documentation Terms of Use
Acme Systems provides this documentation "as is" without warranty or guarantees of any kind. We not provide any direct support for the Open Source preinstalled software but, through these pages and forum posts, all of the information required to obtain the sources, install, use and update the Open Source software that can be run on the Acme boards. Please note that all of the preinstalled software, used on the Acme Systems products, are Open Source so you have to check the license terms provided by the authors (usually the GPL) before using it in any commercial or non-commercial product, by yourself. Before to contact us please note that WE ARE MAINLY HARDWARE DESIGNERS and NOT LINUX GURUS and therefore could be better to post your questions to the Acme Systems forum and ensure that all of the site contributors and large software community can read and reply to your questions.

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Creative Commons License