Hey all, i'm working on designing/building an Arduino setup that uses a A1335 sensor which when in proximity to a permanent magnet can tell you how much that magnet has rotated.
In the picture below you can see the major components. The MCP4725 is controlled through I2C and the A1335 is controlled through SPI.
In my application, I will have an input voltage and based on the rotation on the magnet (i.e. what angle is it at) I want to output a specific voltage.... Also, the output voltage will need to be a function of the input voltage, (i.e. at 90° magnet location output voltage = inputvoltage * 2).
My problem is I don't seem to be reading the correct values from the sensor... I'm just doing temperature and magnetic field strength for now because I know approx. what those values should be (in addition i can easily adjust the temperature of the room and the magnetic strength by moving the magnet further or closer). I'm getting values for both temp and magnetic strength, they just aren't correct nor are they responding to changes i'm making (i.e. moving the magnet further away)
I've been doing the development in stages, first making sure the A1335 sensor is working properly (using the vendors development kit) and then integrating my Arduino Pro Mini and MCP4725 DAC.
I'm at the point now where I have verified the A1335 sensor is working correctly separate from the Arduino (using sensor vendor's software) and then began coding the Arduino. I started off easy, forgetting about the A1335 and making sure I can control the DAC first. I got it working, instead of using magnet strength in the matrix i just use input voltage.
Use the "secret Arduino voltmeter" code to determine what the actual Vin (in this case the ~+5V from the USB cable)
Setup a matrix which allows me to say for a given input voltage this is the output voltage. (note: once I integrate the A1335, this will really be magnet rotation vs output voltage).
A set of statements that looks at the input voltage, if it is higher or lower than the matrix values it clamps the output voltage at the max or low end respectively.
If the input voltage is within the matrix, I have a linear interpolation setup to determine the correct output voltage.
I added some code to read the registers, got the code from here (https://www.arduino.cc/en/Tutorial/BarometricPressureSensor).
I believe I know some of the issues, I just don't know how to solve them.
"const byte READ = 0b11111100" came straight from the example code... I can't find on the A1335 documentation what this sensor's correct value is.
-
The A1335 sensor seems to have two registers addresses for each register whereas the example sensor doesn't... Not sure how to incorporate that into the code.
-
In the example code it says they shift the register over 2 bytes, not sure why and i'm not sure if that is correct for my sensor.
A1335 Datasheet: https://www.allegromicro.com/~/media/Files/Datasheets/A1335-Datasheet.ashx
A1335 Programming manual: https://download.mikroe.com/documents/datasheets/A1335-Programming-Manual.pdf
Here is the code, look towards the end for code specific to the SPI/A1335 interface: