Skip to content
This repository was archived by the owner on Dec 20, 2018. It is now read-only.

working with threads #10

Closed
IngRandall opened this issue Apr 12, 2018 · 1 comment
Closed

working with threads #10

IngRandall opened this issue Apr 12, 2018 · 1 comment

Comments

@IngRandall
Copy link

IngRandall commented Apr 12, 2018

Hello, thank you for your attention, this code is working great:

 import Adafruit_ADS1x15
 import time
 import threading
 from threading import Timer
 import RPi.GPIO as GPIO

 pin_activar_voltaje = 10

 GPIO.setwarnings(False)
 GPIO.setmode(GPIO.BCM)
 GPIO.setup(pin_activar_voltaje,GPIO.OUT)

 adc_multi = Adafruit_ADS1x15.ADS1115(address=0x4B)

 while(1):
     GPIO.output(pin_activar_voltaje, True)
     temp = adc_multi.read_adc(0)
     print("voltaje_0: " + str(temp))
     GPIO.output(pin_activar_voltaje, False)
     leer_entradas = 0
     time.sleep(1)

But if you want to do the same with a thread, the result of adc_multi.read_adc (0) is 0 in many cases:

 import Adafruit_ADS1x15
 import time
 import threading
 from threading import Timer
 import RPi.GPIO as GPIO

 pin_activar_voltaje = 10

 GPIO.setwarnings(False)
 GPIO.setmode(GPIO.BCM)
 GPIO.setup(pin_activar_voltaje,GPIO.OUT)

 adc_multi = Adafruit_ADS1x15.ADS1115(address=0x4B)

 def leer_entradas_analogas():
     GPIO.output(pin_activar_voltaje, True)
     temp = adc_multi.read_adc(0)
     print("voltaje_0: " + str(temp))
     GPIO.output(pin_activar_voltaje, False)
     leer_entradas = 0

     timer_leer_entradas_analogas = threading.Timer(1,leer_entradas_analogas)
     timer_leer_entradas_analogas.setDaemon(True)
     timer_leer_entradas_analogas.start()

 timer_leer_entradas_analogas = threading.Timer(1,leer_entradas_analogas)
 timer_leer_entradas_analogas.setDaemon(True)
 timer_leer_entradas_analogas.start()

 while(1):
     pass

I would like, if possible a little help, thanks

@caternuson
Copy link
Contributor

Hi! We are deprecating this library. This issue is either fixed or may need updating for the new library:
https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15

Please see issue summary here:
#13

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants