Intro: Raspberry Pi A1332 Precision Hall - Effect Angle Sensor Java Tutorial
A1332 is a 360° contactless high resolution programmable magnetic angle position sensor. It is designed for digital systems using an I2C interface. It is built on Circular Vertical Hall (CVH) technology and a programmable microprocessor based signal processing is also incorporated in this sensor. Here is the demonstration with a java code using Raspberry Pi.
Step 1: What You Need..!!
1. Raspberry Pi
LINK : https://www.controleverything.com/content/Hall-Effect?sku=A1332_I2CS
3. I²C Cable
LINK : https://www.controleverything.com/content/I2C-Cables?sku=I2CAFF3
4. I²C Shield for Raspberry Pi
LINK : https://www.controleverything.com/content/I2C-Master?sku=TOUTPI2
5. Ethernet Cable
Step 2: Connections:
Take a I2C shield for raspberry pi and gently push it over the gpio pins of raspberry pi.
Then connect the one end of I2C cable to A1332 sensor and the other end to the I2C shield.
Also connect the Ethernet cable to the pi or you can use a WiFi module.
Connections are shown in the picture above.
Step 3: Code :
The java code for A1332 can be downloaded from our github repository- ControlEverythingCommunity
Here is the link for the same :
The datasheet of A1332 can be found here:
We have used pi4j library for java code, the steps to install pi4j on raspberry pi is described here:
You can also copy the code from here, it is given as follows:
// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
// This code is designed to work with the A1332_I2CS I2C Mini Module available from ControlEverything.com.
public class A1332
public static void main(String args) throws Exception
// Create I2C bus
I2CBus Bus = I2CFactory.getInstance(I2CBus.BUS_1);
// Get I2C device, A1332 I2C address is 0x0C(12)
I2CDevice device = Bus.getDevice(0x0C);
// Read 2 bytes of data
// raw_adc msb, raw_adc lsb
byte data = new byte;
device.read(data, 0, 2);
// Checking valid data
while ((data == 0) && (data ==0))
device.read(data, 0, 2);
// Convert the data to 12-bits
int raw_adc = ((data & 0x0F) * 256 + (data & 0xFF));
double angle = (raw_adc / 4096.0) * 360;
// Output data to screen
System.out.printf("Magnetic Angle : %.2f %n", angle);
Step 4: Appplications:
A1332 is ideal for automotive applications requiring high speed 360° angle measurements, such as: electronic power steering (EPS), transmission, torsion bar, and other systems that require accurate measurement of angles. This sensor is designed for fulfilling the requirements of the systems which incorporate measurement of angle and exact position with high precision.