PICAXE and I2C ADS1015

GW@PE

New Member
I have used I2C single channel ADC and Temperature sensors on an 08M2 and am interested in expanding the ADC to use 4 channel ADS1015 devices. I cannot find useful info re the channel selection on the TI data sheet. here is an example of portion of picaxe code I have used in the past, adapted from code written many years ago by others in the picaxe community


'###########################################################

' I2C Sensors picaxe 08M2 slave
' 9/4/2012
'
'###########################################################



#picaxe 08m2

setfreq m4

symbol sensor_value = w0

symbol ADC_sensor_1 = w1

symbol lo_byte = b0
symbol hi_byte = b1

symbol I2C_setup = i2cfast_4

'%%%%%%%%%%%% ADC SETUP %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

symbol control_ADC = %10001101 'Cb=%10001101

symbol ADC1 = %10010010 'A1=%10010010

start:

pause 1000

sertxd ("[Initializing I2C]",13,10)

'adc1
i2cslave ADC1,I2C_setup,i2cbyte
writei2c (control_ADC)
pause 20


main:

pause 2000

ReadSensors:

'%%%%%%%%%%%%%%%%%% ADC Sensors %%%%%%%%%%%%%%%%%%%%%%%%%%%

i2cslave ADC1,I2C_setup,i2cbyte

gosub Read_ADC

ADC_sensor_1 = sensor_value

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

gosub Send_Data

goto main

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Read_ADC:


readi2c (hi_byte,lo_byte)

...............................................................................

I am not sure how to transition to get individual channels from a multple input device

Not keen on the Arduino route.

Any help would be appreciated
 

westaust55

Moderator
Welcome to the PICAXE forum.

From the datasheet:
http://www.ti.com/lit/ds/sbas473e/sbas473e.pdf

Selection of which of the analog inputs is used for the conversion and reading via the i2c interface is determined by bits 12, 13 and 14 of the “configuration” register.
See figure 21 and Table 6 on page 24 of the datasheet.

To set up the configuration register, as per figure 16 you need to send a sequence of 4 databytes for the
1. Slave address
2. Register pointer
3. & 4. The configuration register desired 16 bits of data


To read an analogue value from the ADC conversion again as per figure 15 this time you must first write 2 bytes and then read two bytes of data.

Sorry using my iPhone to access the forum at the moment so not going to try and give actual lines of code.
 
Last edited:

GW@PE

New Member
Thnx westaus55, I found the register. I will experiment now to get the correct sequence.

I had tried with an Arduino, using adafruit library and a nano. can write and read to I2C, but data returned is gibberish. will go back to the picaxe that can be controlled directly.

I do like to reset I2C devices and then read them. I will be making a Lithium battery maintenance system of 8 cells. I use a picaxe 18M2 with great success on 4 cells, but need better accuracy for 8 cells.
 
Top