Raspberry Pi A1332 Precision Hall - Effect Angle Sensor Java Tutorial
by Dcube Tech Ventures in Circuits > Electronics
3519 Views, 0 Favorites, 0 Comments
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.
What You Need..!!
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.
Code :
The java code for A1332 can be downloaded from our github repository- Dcube Store
Here is the link for the same :
https://github.com/DcubeTechVentures/A1332/blob/master/Java/A1332.java
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.
// A1332
// This code is designed to work with the A1332_I2CS I2C Mini Module
import com.pi4j.io.i2c.I2CBus;
import com.pi4j.io.i2c.I2CDevice;
import com.pi4j.io.i2c.I2CFactory;
import java.io.IOException;
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);
Thread.sleep(500);
// Read 2 bytes of data
// raw_adc msb, raw_adc lsb
byte[] data = new byte[2];
device.read(data, 0, 2);
// Checking valid data
while ((data[0] == 0) && (data[1] ==0))
{
device.read(data, 0, 2);
}
// Convert the data to 12-bits
int raw_adc = ((data[0] & 0x0F) * 256 + (data[1] & 0xFF));
double angle = (raw_adc / 4096.0) * 360;
// Output data to screen
System.out.printf("Magnetic Angle : %.2f %n", angle);
}
}
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.