lundi 14 décembre 2020

Rspberry pi python programming for GPIO with if/else contition

I am trying to generate a pulse train (using raspberry pi zero w) and read that pulse train (using an analog to digital converter AD1015 module). Below shows my code.

import RPi.GPIO as GPIO

import time

import Adafruit_ADS1x15

import RPi.GPIO as GPIO

import time

import Adafruit_ADS1x15

GPIO.setwarnings(False)

ADC = Adafruit_ADS1x15.ADS1015()

GPIO.setmode(GPIO.BCM)

GPIO.setup(4,GPIO.OUT)

GAIN = 1

print('Reading ADS1x15values, press Ctrl+C to quite')

print('|{0:>6}|'.format(*range(1)))

print('-'*37)

while(1):
      
     GPIO.output(4,GPIO.HIGH)
     time.sleep(5)
     GPIO.output(4,GPIO.LOW)
     time.sleep(5)

A = GPIO.output(4)

 if (A == True):
      
     for i in range(1):
        values = [0]*1 
        values[i] = ADC.read_adc(i,gain=GAIN)
        print('|{0:>6}|'.format(*values))|
        time.sleep(0.5)
        
 else:
     
    for i in range(1):
        values[i] = ADC.read_adc(i,gain=GAIN)
        print('|{0:>6}|'.format(*values))
        time.sleep(0.5)

        time.sleep(0.1)

My problem is after compiling this code it gives no analog to digital converted reading as result. Below show my result after compilation.

After compilation given result After compilation given result

Can anyone help me work on this?

Aucun commentaire:

Enregistrer un commentaire