ADS1115 16 bit ADC on ESP8266?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
User avatar
raspi3ua
Posts: 21
Joined: Sat Mar 18, 2017 4:49 pm
Location: Kiev, Ukraine
Contact:

Re: ADS1115 16 bit ADC on ESP8266?

Post by raspi3ua » Thu Apr 06, 2017 12:36 pm

Hello,
Can you show some example for alert_start(channel, threshold) and alert_read()?
Should we use 0x7FFF High threshold for ADS1115?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ADS1115 16 bit ADC on ESP8266?

Post by Roberthh » Thu Apr 06, 2017 1:13 pm

For continous measurement use conversion_start()/alert_read(). Otherwise you can set the threshold to 0x7fff, since that is the high threshold. I'll try to send sample code tonight.

User avatar
raspi3ua
Posts: 21
Joined: Sat Mar 18, 2017 4:49 pm
Location: Kiev, Ukraine
Contact:

Re: ADS1115 16 bit ADC on ESP8266?

Post by raspi3ua » Thu Apr 06, 2017 1:43 pm

Roberthh wrote:For continous measurement use conversion_start()/alert_read(). Otherwise you can set the threshold to 0x7fff, since that is the high threshold. I'll try to send sample code tonight.
>>> from machine import Pin, I2C
>>> i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)
>>> i2c.scan()
[72]
>>> import ads1x15
>>> adc = ads1x15.ADS1115(i2c,0x48)
>>> adc.read(0)
3142
>>> dir(adc)
['alert_start', '_read_register', 'diff', '__module__', 'alert_read', '__init__', 'read', '_write_register', '__qualname__', 'gain', 'i2c', 'address']


In which library I can find conversion_start()?


Change GAIN. Seems correct.
0.3984V on A0.
3.3V on VDD

>>> adc.gain=0
>>> adc.read(0)
2131
>>> adc.read(0)
2126
>>> adc.gain=1
>>> adc.read(0)
3189
>>> adc.read(0)
3189
>>> adc.gain=2
>>> adc.read(0)
6378
>>> adc.read(0)
6377
>>> adc.gain=3
>>> adc.read(0)
12756
>>> adc.read(0)
12761
>>> adc.gain=4
>>> adc.read(0)
25510
>>> adc.read(0)
25511
>>> adc.gain=5
>>> adc.read(0)
32767
>>> adc.read(0)
32767

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ADS1115 16 bit ADC on ESP8266?

Post by Roberthh » Thu Apr 06, 2017 2:29 pm


User avatar
raspi3ua
Posts: 21
Joined: Sat Mar 18, 2017 4:49 pm
Location: Kiev, Ukraine
Contact:

Re: ADS1115 16 bit ADC on ESP8266?

Post by raspi3ua » Fri Apr 07, 2017 12:11 pm

Thanks. Testing now.

Run your sample code (+add two timer):

Code: Select all

from machine import I2C, Pin, Timer
import ads1x15
from array import array

addr = 72
gain = 1

BUFFERSIZE = const(512)
#
# Interrupt service routine for data acquisition
# activated by a pin level interrupt
#
def sample_auto(x):
    global index_put, ads, data
    if index_put < BUFFERSIZE:
        data[index_put] = ads.alert_read()
        index_put += 1

data = array("h", [0] * BUFFERSIZE)
index_put = 0

i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)
irq_pin = Pin(13, Pin.IN, Pin.PULL_UP)
ads = ads1x15.ADS1115(i2c, addr, gain)

ads.conversion_start(5, 0)
time.ticks_us()                                                               <------- add 
irq_pin.irq(trigger=Pin.IRQ_FALLING, handler=sample_auto)

while index_put < BUFFERSIZE:
    pass
time.ticks_us()                                                                <------- add
irq_pin.irq(handler=None)
Results on my ADS1115. 3.3V on VDD.
ALRT connected to D7(GPIO13) through osciloscope .
A0 connected to potentiometer.

>>>
91219056
<IRQ>
93326058
<IRQ>
>>>
>>> data
array('h', [5478, 3967, 4359, 5177, 5437, 4660, 3969, 4467, 5328, 5332, 4548, 3961, 4546, 5462, 5225, 4449, 3975, 4651, 5521, 5124, 4319, 4031, 4806, 5526, 5026, 4173, 4132, 4921, 5539, 4951, 4049, 4247, 5032, 5516, 4841, 3960, 4340, 5152, 5456, 4688, 3944, 4433, 5304, 5366, 4564, 3941, 4506, 5430, 5233, 4470, 3953, 4607, 5508, 5132, 4346, 4005, 4766, 5539, 5045, 4202, 4097, 4893, 5533, 4959, 4067, 4204, 5011, 5515, 4860, 3968, 4330, 5120, 5476, 4724, 3941, 4411, 5265, 5386, 4580, 3947, 4493, 5410, 5273, 4483, 3955, 4591, 5510, 5161, 4364, 3991, 4734, 5534, 5055, 4232, 4064, 4874, 5542, 4980, 4093, 4189, 4977, 5531, 4891, 3980, 4286, 5088, 5493, 4761, 3944, 4388, 5232, 5414, 4609, 3941, 4470, 5371, 5301, 4503, 3939, 4556, 5483, 5181, 4388, 3976, 4688, 5543, 5093, 4261, 4051, 4843, 5541, 5003, 4120, 4153, 4946, 5535, 4912, 4001, 4265, 5063, 5520, 4786, 3951, 4362, 5199, 5446, 4646, 3935, 4448, 5349, 5322, 4523, 3932, 4535, 5477, 5212, 4414, 3961, 4657, 5533, 5109, 4286, 4019, 4805, 5540, 5016, 4145, 4128, 4934, 5542, 4934, 4018, 4238, 5036, 5516, 4814, 3942, 4338, 5168, 5460, 4672, 3942, 4437, 5307, 5356, 4554, 3939, 4510, 5455, 5229, 4445, 3951, 4626, 5528, 5125, 4326, 4010, 4779, 5542, 5045, 4169, 4097, 4903, 5546, 4960, 4043, 4216, 5009, 5527, 4856, 3965, 4324, 5139, 5476, 4711, 3941, 4413, 5271, 5371, 4576, 3938, 4496, 5418, 5262, 4471, 3944, 4596, 5515, 5146, 4353, 3990, 4733, 5545, 5053, 4207, 4074, 4879, 5545, 4973, 4075, 4191, 4983, 5537, 4880, 3968, 4286, 5099, 5489, 4744, 3937, 4394, 5246, 5402, 4609, 3935, 4475, 5385, 5281, 4495, 3936, 4567, 5502, 5176, 4381, 3974, 4709, 5537, 5082, 4247, 4056, 4857, 5538, 4989, 4114, 4166, 4955, 5542, 4899, 3991, 4267, 5066, 5505, 4776, 3942, 4367, 5210, 5432, 4634, 3931, 4460, 5352, 5310, 4521, 3929, 4542, 5475, 5207, 4414, 3966, 4661, 5533, 5099, 4283, 4029, 4815, 5537, 5011, 4138, 4141, 4931, 5539, 4929, 4008, 4251, 5044, 5511, 4815, 3945, 4342, 5169, 5451, 4660, 3942, 4442, 5316, 5353, 4548, 3932, 4520, 5458, 5226, 4432, 3953, 4624, 5519, 5127, 4311, 4008, 4781, 5548, 5034, 4173, 4097, 4915, 5542, 4954, 4038, 4220, 5013, 5521, 4844, 3957, 4322, 5138, 5471, 4707, 3935, 4417, 5280, 5372, 4565, 3935, 4496, 5424, 5263, 4471, 3953, 4606, 5512, 5156, 4352, 3984, 4736, 5540, 5054, 4215, 4074, 4881, 5547, 4969, 4071, 4197, 4983, 5532, 4872, 3965, 4300, 5105, 5489, 4740, 3934, 4392, 5248, 5410, 4603, 3939, 4482, 5393, 5283, 4495, 3940, 4574, 5494, 5180, 4374, 3977, 4705, 5531, 5085, 4246, 4052, 4858, 5546, 4990, 4101, 4155, 4958, 5543, 4900, 3989, 4276, 5080, 5515, 4774, 3941, 4377, 5209, 5432, 4636, 3923, 4459, 5361, 5313, 4527, 3934, 4542, 5490, 5205, 4406, 3968, 4666, 5540, 5102, 4280, 4022, 4812, 5547, 5008, 4141, 4138, 4943, 5544, 4921, 4010, 4243, 5041, 5519, 4814, 3947, 4345, 5172, 5456, 4652, 3924, 4441, 5317, 5351, 4545, 3936, 4520, 5451, 5226, 4439, 3953, 4629, 5529, 5116, 4309, 4007, 4778, 5550, 5039, 4173, 4099, 4906, 5541, 4953, 4041, 4222, 5015, 5523, 4841, 3951, 4320, 5145, 5484, 4706, 3932, 4417, 5295, 5376, 4573, 3935, 4498, 5427, 5254, 4460, 3950, 4601, 5524, 5150, 4339])

Now calculate:
>>> 93326058-91219056
2107002 <----- us for 512 sample
>>> 2107002/512
4115.238 <----- us for 1 sample
>>> 1000000/4115.238
242.9994 <----- samples in 1 sec

Seems ok for speed rate 5 for ADS1115
(ADS1015 / ADS1115)
0 : 128/8 samples per second
1 : 250/16 samples per second
2 : 490/32 samples per second
3 : 920/64 samples per second
4 : 1600/128 samples per second (default)
5 : 2400/250 samples per second
6 : 3300/475 samples per second
7 : - /860 samples per Second


But I can't understand picture from osciloscope (ALRT pin from ADS1115).
Measuring during code running.
conversion_start_5.jpg
conversion_start_5.jpg (195.85 KiB) Viewed 7531 times
Osciloscope show 60 us between ALRT (it's near 1600 samples per second).
Any idea?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ADS1115 16 bit ADC on ESP8266?

Post by Roberthh » Fri Apr 07, 2017 12:30 pm

Hello @raspi3ua, I tested the signal with an oscilloscope too, and the time difference between two alert puses was stable 4 ms, with a 8 µs pulse duration.

User avatar
raspi3ua
Posts: 21
Joined: Sat Mar 18, 2017 4:49 pm
Location: Kiev, Ukraine
Contact:

Re: ADS1115 16 bit ADC on ESP8266?

Post by raspi3ua » Fri Apr 07, 2017 1:11 pm

Roberthh wrote:Hello @raspi3ua, I tested the signal with an oscilloscope too, and the time difference between two alert puses was stable 4 ms, with a 8 µs pulse duration.
Yes. It's my fault.
Repeated test with oscilloscope.
Result is correct. Thanks.

Code: Select all

=========================================================
	#rate 3 :  920/64 samples per second
=== ads.conversion_start(3, 0)
482525968
<IRQ>
490630606
<IRQ>
>>> 490630606-482525968
8104638  <----- us for 512 sample
>>> 8104638/512
15829.37 <----- us for 1 sample
>>> 1000000/15829.37
63.17371  <----- samples in 1 sec

	15ms between two alert puses on oscilloscope 

=========================================================
	#rate 4 :  1600/128 samples per second (default)
=== ads.conversion_start(4, 0)
764045279
<IRQ>
768151206
<IRQ>
>>> 768151206-764045279
4105927  <----- us for 512 sample
>>> 4105927/512
8019.389 <----- us for 1 sample
>>> 1000000/8019.389
124.6978  <----- samples in 1 sec

	8ms between two alert puses on oscilloscope 
	
=========================================================
	#rate 5 :  2400/250 samples per second
=== ads.conversion_start(5, 0)
977358562
<IRQ>
979454119
<IRQ>
>>> 979454119-977358562
2095557  <----- us for 512 sample
>>> 2095557/512
4092.885 <----- us for 1 sample
>>> 1000000/4092.885
244.3264  <----- samples in 1 sec

	4ms between two alert puses on oscilloscope 

=========================================================
	#rate 6 :  3300/475 samples per second
=== ads.conversion_start(6, 0)
177355837
<IRQ>
178454710
<IRQ>
>>> 178454710-177355837
1098873  <----- us for 512 sample
>>> 1098873/512
2146.236 <----- us for 1 sample
>>> 1000000/2146.236
465.9321  <----- samples in 1 sec

	2ms between two alert puses on oscilloscope

Post Reply