Tux and his Gibson
His main hobby is playing guitar, especially electric guitar which makes the sound of the guitar to be heard from the Earth to the Moon. Tux told me that the first guitar which performed analog-to-digital conversion was a Gibson guitar in 2002.
An analog-to-digital converter takes an analog signal as input and outputs a digital signal. See the below image to fully understand the difference between these two types of signals.
In the past weeks our goal was to develop a driver for an ADC sensor, the ADS1118. By looking through the existing ADC drivers in the Linux Kernel source we found out that there is a converter with similar characteristics and that converter is ADS1015.
The main difference between ADS1118 and ADS1015 is the serial communication interface. The first one is on SPI (serial peripheral interface) and the second one is on I2C interface.
The challenge was to split the code for ADS1118 into a core file and an I2C file and to add the SPI file. As you may guess, the core file contains the common functions used to read from channels and to convert the signal into digital values. The SPI and I2C files, are used for the communication between the sensor and the adaptor or microcontroller.
Compile and configure the Linux Kernel for Raspberry Pi
For checking if the I2C communication is still working after the split, I used a Raspberry Pi. If you have a Raspberry Pi and want to a connect a sensor from linux/drivers/iio, follow these steps:
Download the from the official site.
Write the Raspbian image to the SD card using Etcher.
Download the kernel source for Raspberry.
git clone --depth=1 https://github.com/raspberrypi/linux
Make the default configuration.
Compile the kernel.
make -j4 zImage modules dtbs
Install the modules.
sudo make modules_install
Copy the files to /boot.
sudo cp arch/arm/boot/dts/*.dtb /boot/
sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
sudo cp arch/arm/boot/zImage /boot/kernel7.img
Reboot the Raspberry
Connect the pins
Before connecting the sensor, be sure that you have the right tools. Install the i2c-tools and check the pins.
sudo apt-get install i2c-tools
sudo i2cdetect -y 1
Make the following connections from ADS1015 to your Raspberry Pi:
* VDD to 3v3 Power (pin 1)
* SDA to Data (pin 3)
* SCL to Clock (pin 5)
* GND to Ground (pin 6)
The Raspberry’s pins and ADS1015’s pins can be found in the below images.
Measure the voltage
Now that we have the wire connections, create a new IIO device with the command:
echo 0x48 > /sys/bus/i2c/devices/i2c-1/new_device
After the sensor initialization, we can start measuring the voltage.
For example, connect a wire from the Raspberry’s Pin 1 to the ADS1015’s A0 pin and check the /sys/bus/iio/devices/iio:device0/in_voltage0_raw file.
Another example is to connect a wire from Raspberry’s Pin 6 to the ADS1015’s A0 pin and check the same file. You will find that the voltage is 0 because A0 is wired to ground.
We managed to check the two examples after splitting the ADS1015 into the 2 files: core, i2c.
The next challenge is to check if the ADS1118 implementation is working. This ADC sensor has a SPI interface. See you soon!