Replies: 3 comments 1 reply
-
Hello. ADS1115 is quite different from PCF8591 and more complex. It won't work just changing some code from PCF8591.py file. Unless you wish to learn how to write your own I2C library, your best bet is to use an existing ADS1115 library, and the compatible SMBus class. I wrote an example in EasyMCP2221/examples/ADS1115. |
Beta Was this translation helpful? Give feedback.
-
@electronicayciencia : Many thanks for the link of de ADS1115 library. A lot of work has been done already ! Traceback (most recent call last): So I am not able to read out A0-A3 of de ADS 1115 break out board. |
Beta Was this translation helpful? Give feedback.
-
I'm glad it works. BTW, it is not a good idea to reveal your employee ID (emp629995), company (BE Semiconductor Industries N.V) and parts of the corporate technology stack (OneDrive, Python 3.10) on a public forum. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am trying to read the 4 channels of a 16 bit ADC (ADS1115) by the MCP2221 break-out board of Adafruit in a python (3) program
I found a nice example on github/EasyMCP2221/examples directory. It is called PCF8591.py The PCF8591 chip is a 8 bit ADC.
The code I made was the following : (comment out region starts with a .#)
--------------------------------------------------------start code---------------------
.#I2C example to read PCF8591 module values.
from time import sleep
import EasyMCP2221
.# Connect to MCP2221
mcp = EasyMCP2221.Device()
.# Default address is 0x48 for both PCF8591 and ADS1115
addr = 0x48
.# Control register:
.# .0.. .... - No DAC output
.# ..00 .... - 4 individual inputs
.# .... .1.. - Auto-increment channel
.# .... ..01 - ADC start channel 1
.#mcp.I2C_write(addr, [0b0000_0101]) # control byte for PCF8591 module
.#data=[0b1100_0011_0000_0011] # control byte for ADS1115 module
mcp.I2C_write(addr,[0b1100_0011_0000_0011])
for n in range (0,100):
(ntc, ldr, flo, pot) = mcp.I2C_read(addr, 4)
print(" NTC: %2d%%, LDR: %2d%%, Float: %2d%%, Pot: %2d%%" %
(
ntc / 256 * 100,
ldr / 256 * 100,
flo / 256 * 100,
pot / 256 * 100))
print (n)
sleep(0.1)
------------------------------------------------------end code-------------------------------------
I figured out that the control byte for the ADS1115 is =[0b1100_0011_0000_0011]
which can be found in the attached documentation of de ADS1115 and the readout example in attached file I2CreadoutADS1115. pdf on page 13.
ads1115.pdf
I2CreadoutADS1115.pdf
Unfortunately, simply altering the PCF8591.py file, does not work. I got the error :
Traceback (most recent call last):
File "C:\Users\emp629995\OneDrive - BE Semiconductor Industries N.V\Documents\PythonFiles\ReadoutTest.py", line 20, in
mcp.I2C_write(addr,[0b1100_0011_0000_0011])
File "C:\Program Files\Python310\lib\site-packages\EasyMCP2221\MCP2221.py", line 1554, in I2C_write
rbuf = self.send_cmd(header + list(chunk))
File "C:\Program Files\Python310\lib\site-packages\EasyMCP2221\MCP2221.py", line 217, in send_cmd
self.hidhandler.write([REPORT_NUM] + buf + padding)
File "hid.pyx", line 184, in hid.device.write
ValueError: bytes must be in range(0, 256)
My question is the following: What should I alter in the original PCF8591.py file so that I can read 4 channels of the ADS1115 ?
Beta Was this translation helpful? Give feedback.
All reactions