Skip to content

Commit

Permalink
Tweak to prevent thread interleaving for pimoroni#16
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed May 15, 2018
1 parent a709aac commit 2a6cc9e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions library/automationhat/ads1015.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time

import sys

ADDR = 0x48

Expand Down Expand Up @@ -38,12 +38,13 @@ def read(self, channel=0, programmable_gain=PGA_4_096V, samples_per_second=1600)
# set "single shot" mode
config |= 0x8000

# write single conversion flag
self.i2c_bus.write_i2c_block_data(self.addr, REG_CFG, [(config >> 8) & 0xFF, config & 0xFF])

delay = (1.0 / samples_per_second) + 0.0001
time.sleep(delay)

# write single conversion flag
self.i2c_bus.write_i2c_block_data(self.addr, REG_CFG, [(config >> 8) & 0xFF, config & 0xFF])
t_s = time.time()
while time.time() < t_s + delay:
pass
data = self.i2c_bus.read_i2c_block_data(self.addr, REG_CONV)

value = ((data[0] << 4) | (data[1] >> 4))
Expand Down

0 comments on commit 2a6cc9e

Please sign in to comment.