All right this is the review on the next two lessons on linear hall sensors. Lesson 02 uses an analog linear hall sensor and an analog to digital conver IC ADC0832. The lesson 03 uses a linear hall sensor with added comparator, which allows some sensitivity tuning of the sensors by adjusting the potentiometer. The code for both lessons is the same, thus the review is all in one post.
The fun part of this lesson is on getting familiar with “what on earth is analog to digital conversion ?”. Grate resources on this matter are: Wikipedia article and Sparkfun article
For those of you that prefer to learn while watching awesome videos check this out Electronics 201: Analog / Digital Conversion.
In particular for this lesson we have the IC ADC0832CCN and the datasheet can be found here. The datasheet of the hall sensor can be useful as well for further hacks.
The hole idea is about converting the voltage fluctuations (produced by a magnetic field) into a digital number value which represents the intensity of the magnetic field. The hall sensor generates the analog voltage variations and the ADC0832 encodes the numeric values that can be interpreted in the code.
The original C code is correct, but rather difficult to understand and not optimal. For example the switch of pin ADC_DIO to an input mode is inside of the first for loop. This is unnecessary and confusing. And the ADC0832 initialization code has some extra steps not required and it is not easy to understand. After a good reading of the datasheet I was able to understand what is going on in that part of the code.
For more detail: Raspberry Pi digital Hall sensor in JAVA
Current Project / Post can also be found using:
- hall sensor raspberry