www.joy-it.net
Pascalstr. 8 47506 Neukirchen-Vluyn
2. COMMISSIONING WITH THE RASPBERRY PI
Code example:
The higher the analog input voltage, the higher the measured natural gas or methane va-
lue.
The value range is from 0 to 5.
The D0 pin of the sensor is automatically set to LOW when the limit value is reached.
With the blue potentiometer on the board, you can set the limit value.
In the following code example, the analog value of the sensor is read out every 5 seconds
and displayed in the console.
from time import sleep
import board
import busio
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN)
# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)
# Create the ADC object using the I2C bus
ads = ADS.ADS1115(i2c)
ads.gain = 2/3
# Create single-ended input on channels
chan0 = AnalogIn(ads, ADS.P0)
chan1 = AnalogIn(ads, ADS.P1)
chan2 = AnalogIn(ads, ADS.P2)
chan3 = AnalogIn(ads, ADS.P3)
try:
while True:
if GPIO.input(17) == GPIO.LOW:
print("Warning: Limit exceeded!!!")
print("{:>5.3f}".format(chan0.voltage))
sleep(2.5)
except KeyboardInterrupt:
GPIO.cleanup()
Installation:
To be able to use the ADC, you must first enable I2C.
Enter the following command:
Navigate to Interfacing Options -> I2C and enable the I2C interface.
You must also install the Python library of the ADC.
Enter the following commands:
sudo raspi-config
sudo apt-get update
sudo apt-get install python3-pip
sudo pip3 install adafruit-circuitpython-ads1x15