pimoroni / ads1015-python

Python library for the Pimoroni ADS1015 breakout
MIT License
10 stars 5 forks source link

ads1015.set_sample_rate(3300) #11

Open paddygoat opened 3 years ago

paddygoat commented 3 years ago

import time
from ads1015 import ADS1015
import smbus

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt
import numpy as np
import time

channel = 'in0/ref'

print("""read-all.py - read all three inputs of the ADC

Press Ctrl+C to exit!
""")

ads1015 = ADS1015()
ads1015.set_mode('single')
ads1015.set_programmable_gain(2.048)
ads1015.set_sample_rate(3300)

print("Get the sample rate 1:  " + str(ads1015.get_sample_rate()))

reference = ads1015.get_reference_voltage()

print("Reference voltage: {:6.3f}v \n".format(reference))

# sudo i2cdetect -y 1

i2c_bus = smbus.SMBus(1)
i2caddress = 0x48
configRegister = 0x01
# sample rate (3300 SPS, 0xC0)

sample_rate_value = i2c_bus.read_word_data(i2caddress, configRegister)

#    0b110000011110101   default
#    0b110001111110101
#    0b110001101110101   FAST
#    0b110000001110101   SLOW
#    0b110000011010101   FAST
# goes from 15 to 0 , left to right.
# 3300 7 to 5 is 111 or 110.

print("Get the sample rate 2:  " + str(hex(sample_rate_value)))

i2c_bus.write_word_data(i2caddress, configRegister, 0b110000011010101)
time.sleep (2)

sample_rate_value = i2c_bus.read_word_data(i2caddress, configRegister)

print("Get the sample rate 3:  " + str(hex(sample_rate_value)))
print("Get the sample rate 4:  " + str(ads1015.get_sample_rate()))
print("")
print("")```

Can't set the sample rate :(
Results:
read-all.py - read all three inputs of the ADC

Press Ctrl+C to exit!

Get the sample rate 1:  None
Reference voltage:  1.242v 

Get the sample rate 2:  0x60f5
Get the sample rate 3:  0x60d5
Get the sample rate 4:  None

...... I cannot change the sample rate using any of the above methods. Seems to be stuck at about 220 SPS. Please help !!!!!!!!!
Gadgetoid commented 3 years ago

Looks like you stumbled upon a bug. I compared the code with the datasheet and found the sample rate config was 1-bit out. Should be fixed it in #12