News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

ADS1115

Started by DymDym, Jun 11, 2024, 01:16 PM

Previous topic - Next topic

DymDym

hello!
Does anyone have a working code for ads1115 ?
(Proton PicBasic)...

Pepe

#1
Demo with Proteus for ADS 1015(12bits)

Pepe

New version in post #2

Dolci

Hi Pepe,
 do you have a later version of Proteus for the demo file? Mine is V8.15. Thanks

Pepe

#4
Proteus v15

Pepe

Quote from: Dolci on Jun 12, 2024, 10:25 AMHi Pepe,
 do you have a later version of Proteus for the demo file? Mine is V8.15. Thanks

look post #5

DymDym

I once had a working code like this:

' ADS1115
' A0 - "+"; A1- "-"

Device = 18F452
Xtal = 20

@Config_REQ
@__Config Config1H, OSCS_OFF_1 & HS_OSC_1
@__Config Config2L, BOR_OFF_2 & BORV_20_2 & PWRT_ON_2
@__Config Config2H, WDT_OFF_2 & WDTPS_128_2
@__Config Config3H, CCP2MX_OFF_3
@__Config Config4L, STVR_OFF_4 & LVP_OFF_4 & DEBUG_OFF_4

'-----------------------------------------------------------
All_Digital = TRUE
'-----------------------------------------------------------
Declare LCD_Type ALPHA           
Declare LCD_DTPin PORTB.4         
Declare LCD_ENPin PORTB.3         
Declare LCD_RSPin PORTB.2         
Declare LCD_Interface 4 
Declare LCD_CommandUs 2000
Declare LCD_DataUs 50 
Declare LCD_Lines 2 
Clear
 
Symbol ADS_SDA = PORTD.2  ; ADS1115
Symbol ADS_SLC = PORTD.3  ; ADS1115


;        76543210
PORTD = %00000000 
TRISB = %00000000
 
Dim Dat15       As Word
Dim Resultaat_0 As Float
Dim Resultaat_1 As Float
 
Dim Data2       As Word
Dim Resultaat_2 As Float
Dim Resultaat_3 As Float
 
Cls
DelayMS 100
 
Lees_ADC:
    While 1 = 1
                                            ;5432109876543210
        I2COut ADS_SDA, ADS_SLC, $90, $01, [%1000000100000011]  ; configuratie
                                            ; |||
                                            ; 100 = AIN0 ingang en met ADDR naar aarde.
                                            ; 101 = AIN1 ingang en met ADDR naar aarde.
                                            ; 110 = AIN2 ingang en met ADDR naar aarde.
                                            ; 111 = AIN3 ingang en met ADDR naar aarde.
        DelayMS 15                         
        I2CIn ADS_SDA, ADS_SLC, $90, $48, [ Dat15 ]  ; uitlezen
        DelayMS 5                   
        If Dat15 > 32767 Then  Resultaat_0 = (65535-Dat15) * 0.0001869:  Resultaat_0=Resultaat_0*-1
        If Dat15 <= 32767 Then Resultaat_0 = Dat15 * 0.0001869                                           
       
        If Dat15 > 32767 Then  Resultaat_1 = (65535-Dat15) * 0.1869:  Resultaat_1=Resultaat_1*-1
        If Dat15 <= 32767 Then Resultaat_1 = Dat15 * 0.1869                                         
               
        'Resultaat_1 = Dat15 * 0.1869
        Print At 1,1, Dec3 Resultaat_0, " Volt"
        Print At 2,1, Dec3 Resultaat_1, " mvolt"
        DelayMS 15
        '                             ;5432109876543210
       ' I2COut ADS_SDA, ADS_SLC, $90, $01, [%1101000100000011]  ; configuratie
                                            ; |||
                                            ; 100 = AIN0 ingang en met ADDR naar aarde.
                                            ; 101 = AIN1 ingang en met ADDR naar aarde.
                                            ; 110 = AIN2 ingang en met ADDR naar aarde.
                                            ; 111 = AIN3 ingang en met ADDR naar aarde.
      '  DelayMS 15                         
      '  I2CIn ADS_SDA, ADS_SLC, $90, $48, [ Data2 ]  ; uitlezen
      '  DelayMS 5                   
      '  Resultaat_2 = Data2 * 0.0001869                                           
     '   Resultaat_3 = Data2 * 0.1869
      '  Print At 1,10, Dec3 Resultaat_2, "V"
      '  Print At 2,10, Dec3 Resultaat_3, "mv"
      '  DelayMS 15                                   
    Wend
 End


But recently bought new ADS1115 does not want to work with it. I have a suspicion that I have ADS1015 instead of ADS1115.

Thanks for the code for ADS1015, I will try it!

Dolci

Quote from: Pepe on Jun 12, 2024, 06:04 PM
Quote from: Dolci on Jun 12, 2024, 10:25 AMHi Pepe,
 do you have a later version of Proteus for the demo file? Mine is V8.15. Thanks

look post #5

thank you Pepe

Pepe

Diferencial mode

Pepe

Quote from: DymDym on Jun 13, 2024, 09:33 AMI once had a working code like this:

' ADS1115
' A0 - "+"; A1- "-"

Device = 18F452
Xtal = 20

@Config_REQ
@__Config Config1H, OSCS_OFF_1 & HS_OSC_1
@__Config Config2L, BOR_OFF_2 & BORV_20_2 & PWRT_ON_2
@__Config Config2H, WDT_OFF_2 & WDTPS_128_2
@__Config Config3H, CCP2MX_OFF_3
@__Config Config4L, STVR_OFF_4 & LVP_OFF_4 & DEBUG_OFF_4

'-----------------------------------------------------------
All_Digital = TRUE
'-----------------------------------------------------------
Declare LCD_Type ALPHA           
Declare LCD_DTPin PORTB.4         
Declare LCD_ENPin PORTB.3         
Declare LCD_RSPin PORTB.2         
Declare LCD_Interface 4 
Declare LCD_CommandUs 2000
Declare LCD_DataUs 50 
Declare LCD_Lines 2 
Clear
 
Symbol ADS_SDA = PORTD.2  ; ADS1115
Symbol ADS_SLC = PORTD.3  ; ADS1115


;        76543210
PORTD = %00000000 
TRISB = %00000000
 
Dim Dat15       As Word
Dim Resultaat_0 As Float
Dim Resultaat_1 As Float
 
Dim Data2       As Word
Dim Resultaat_2 As Float
Dim Resultaat_3 As Float
 
Cls
DelayMS 100
 
Lees_ADC:
    While 1 = 1
                                            ;5432109876543210
        I2COut ADS_SDA, ADS_SLC, $90, $01, [%1000000100000011]  ; configuratie
                                            ; |||
                                            ; 100 = AIN0 ingang en met ADDR naar aarde.
                                            ; 101 = AIN1 ingang en met ADDR naar aarde.
                                            ; 110 = AIN2 ingang en met ADDR naar aarde.
                                            ; 111 = AIN3 ingang en met ADDR naar aarde.
        DelayMS 15                         
        I2CIn ADS_SDA, ADS_SLC, $90, $48, [ Dat15 ]  ; uitlezen
        DelayMS 5                   
        If Dat15 > 32767 Then  Resultaat_0 = (65535-Dat15) * 0.0001869:  Resultaat_0=Resultaat_0*-1
        If Dat15 <= 32767 Then Resultaat_0 = Dat15 * 0.0001869                                           
       
        If Dat15 > 32767 Then  Resultaat_1 = (65535-Dat15) * 0.1869:  Resultaat_1=Resultaat_1*-1
        If Dat15 <= 32767 Then Resultaat_1 = Dat15 * 0.1869                                         
               
        'Resultaat_1 = Dat15 * 0.1869
        Print At 1,1, Dec3 Resultaat_0, " Volt"
        Print At 2,1, Dec3 Resultaat_1, " mvolt"
        DelayMS 15
        '                             ;5432109876543210
       ' I2COut ADS_SDA, ADS_SLC, $90, $01, [%1101000100000011]  ; configuratie
                                            ; |||
                                            ; 100 = AIN0 ingang en met ADDR naar aarde.
                                            ; 101 = AIN1 ingang en met ADDR naar aarde.
                                            ; 110 = AIN2 ingang en met ADDR naar aarde.
                                            ; 111 = AIN3 ingang en met ADDR naar aarde.
      '  DelayMS 15                         
      '  I2CIn ADS_SDA, ADS_SLC, $90, $48, [ Data2 ]  ; uitlezen
      '  DelayMS 5                   
      '  Resultaat_2 = Data2 * 0.0001869                                           
     '   Resultaat_3 = Data2 * 0.1869
      '  Print At 1,10, Dec3 Resultaat_2, "V"
      '  Print At 2,10, Dec3 Resultaat_3, "mv"
      '  DelayMS 15                                   
    Wend
 End


But recently bought new ADS1115 does not want to work with it. I have a suspicion that I have ADS1015 instead of ADS1115.

Thanks for the code for ADS1015, I will try it!

If it is not in differential mode it makes no sense to ask if it is greater than 32767 to convert it to negative because in that mode it only gives positive values, also the $48 is wrong, there goes 0 if it is to read the conversion record or 1 if it is to read or write the configuration register