SpanglefishDMS Consulting | sitemap | log in
This is a free Spanglefish 1 website.

Java I2C Software

 

The Project

The idea behind this project was to write Java JNI routines to allow Java to drive an I2C bus. The bus could be on any machine that could run Java - all that would be required was the JNI routine and an I2C bus.

The Package

The package was developed on a PC using Eclipse and Java. There were three specific parts.
1) The JNI routine to interface between Java and the OS Drivers.
2) The Java Driver to make it easier to use the JNI interface routine.
3) The Java Drivers for the different I2C chips.

I2C Introduction

I2C - Inter Integrated Circuit - is a multi master, multi slave, single ended serial computer bus invented by Philips Semi Conductor. It consists of three wires - Serial Data Line - SDA Serial Clock Line - SCL Ground The bus will run at several speeds - 100 KHz, 20KHz, 400 KHz, 750 KHZ. The master controller can talk to up to 128 slave units using 7 bit addressing.

Uses

A large number of I2C chips are now available and most are not expensive. Each chip has a base address and often more addresses that can be wired. The chips - Control motors - on, off, forward, backward, slow, fast Control lights - on, off, blink, vary brightness A2D - measure current, voltage or resistance D2A - adjust voltage Range finders - Ultra sonic, Laser

The Bus Hardware

To add an I2C bus to a PC, a USB Dongle was used. There were saveral available - I bought the YS-CH341T on EBay. It has a major problem in that it does not support 'clock stretching' but in most cases, slowing the baud rate works.
There is a driver that works on most Windows Systems 32 or 64 bit. The source of an interface routine is also available but only 32 bit. You can still use a 64 bit Windows but need to use a 32 bit JVM. There is still a very large range of I2C chips and modules that work fine on this dongle.

Using the Raspberry Pi is very straight forward. The I2C bus is on the GPIO. Connect to pins 3-SDA, 5-SCL and 6-GND. Using the Pi's 5V is not advisable as there is not a lot of spare current available.
The I2C implementation on the PI is very poor but can be made to work. Like the YS-CH341T and due to a hardware design fault, it does not support 'clock stretching'. Unlike the YS-CH341T, changing the baud rate is difficult and does not always fix the problem but there is still a large range of I2C chips and modules that work fine on this system.

Looking on the web for a better I2C dongle, I found the UMFT4222EV supplied by a company based in Glasgow. The product is new and some of the software is still being developed. The advantages of this device are that it supports different baud rates and also clock stretching.
It works on a Windows PC, a Raspberry Pi, an Android Tablet and should work on a Linux PC.
The Windows drivers work well and I have developed a JNI driver. The Raspberry PI drivers and JNI driver also work well.
The Android driver works and I have developed the equivalent to the JNI driver. This driver will not be available in the first release. This dongle works fine with all of the I2C chips and modules that I have tested.

The Software

The PC can support I2C by using a USB Dongle. These devices require device drivers before my Java JNI programs can talk to them.
USB I2C Dongles and Drivers

The Raspberry Pi has it's own I2C and should only require a simple JNI driver. To use the UMFT4222EV you will need different JNI drivers.
Raspberry Pi Drivers

Software Development

The Eclipse Foundation

 

 

 

WikanikoWork from Home
sitemap | cookie policy | privacy policy