The ADS1115 Datasheet specifically tells you what to put in to get a reading... and I think I'm doing just that. The problem is... I'm not getting any errors, but the chip constantly reports MSB = 0 and LSB = 0 and it does not matter if I tie the AN0 pin to 3.3vdc or Ground.
I have three outputs... each is a Textbox and my routine sends the data there. A TIMER1 pings the routine once a second.
I also have text printing to the debugger area so I know it is running the routine. I have tried putting the data in as binary &b00000000& as HEX &H00& and as a plain old decimal. Same thing.
here is the code... maybe I'm just too close... overlooking a blatant error.
Code: Select all
'-------------------------------------------------------------------------------------------------
' Gambas3 ADS1115 Test Program Version 1.0
'-------------------------------------------------------------------------------------------------
' Load the pigpio library
Library "/usr/local/lib/libpigpio"
'-------------------------------------------------------------------------------------------------
' Library Setup Section
'-------------------------------------------------------------------------------------------------
Public Extern gpioInitialise() As Integer 'call at start of program to initialise
Public Extern gpioTerminate() As Integer 'call at end of program to release resources and terminate threads
Public Extern gpioVersion() As Integer
Public Extern gpioHardwareRevision() As Integer
Public Extern gpioSetMode(iPin As Integer, iMode As Integer) As Integer
Public Extern gpioRead(iPin As Integer) As Integer
Public Extern gpioWrite(iPin As Integer, iLevel As Integer) As Integer
Public Extern gpioSetPullUpDown(iPin As Integer, iMode As Integer) As Integer
Public Extern gpioServo(servo_pin As Integer, servo_value As Integer) As Integer
'-------------------------------------------------------------------------------------------------
Public Extern i2cOpen(i2cBus As Integer, i2cAddress As Integer, i2cFlags As Integer) As Integer
Public Extern i2cClose(i2c_handle As Integer)
Public Extern i2cWriteByte(i2c_handle As Integer, i2cByte As Byte) As Integer
Public Extern i2cReadByte(i2c_handle As Integer) As Integer
Public Extern i2cWriteWordData(i2c_handle As Integer, i2cReg As Integer, i2cWord As Integer) As Integer
Public Extern i2cReadWordData(i2c_handle As Integer, i2cReg As Integer) As Integer
'-------------------------------------------------------------------------------------------------
' Define constants
'-------------------------------------------------------------------------------------------------
Const PI_INPUT As Integer = 0
Const PI_OUTPUT As Integer = 1
Const PI_RESISTOR_UP As Integer = 2
Const PI_RESISTOR_DOWN As Integer = 1
Const PI_RESISTOR_OFF As Integer = 0
'-------------------------------------------------------------------------------------------------
' Define Public Variables
'-------------------------------------------------------------------------------------------------
Public i2c_handle As Integer = 0
'-------------------------------------------------------------------------------------------------
Public Sub Form_Open()
Dim intReply As Integer
intReply = gpioInitialise()
If intReply < 0 Then
DSP_Software_Stat.Text = "Failed: must be run as root"
Else
DSP_Software_Stat.Text = "OK. Initialised: PIGPIO Version Number: " & intReply
Endif
'-------------------------------------------------------------------------------------------------
' Open I2C Port on BUS 1 for the ADS1115 A/D Chip
'-------------------------------------------------------------------------------------------------
Print "Open the i2C port on Bus 1 for the ADS1115 A/D Chip."
i2c_handle = i2copen(1, &H48&, 0)
' Configure ADS1115 for constant conversion mode, Address 100, Port AN0
' - First byte: 0b10010000(first 7 - bit I2C address followed by a low R / W bit)
i2cWriteByte(i2c_handle, &H90&)
' – Second byte: 0b00000001 (points to Config register)
i2cWriteByte(i2c_handle, &H01&)
' – Third byte: 0b10000100 (MSB of the Config register to be written)
i2cWriteByte(i2c_handle, &H84&)
' – Fourth byte: 0b10000011 (LSB of the Config register to be written)
i2cWriteByte(i2c_handle, &H83&)
Print "ADS1115 set to port AN0 and GND in continious read mode."
'-------------------------------------------------------------------------------------------------
' Other Tasks
'-------------------------------------------------------------------------------------------------
End
Public Sub Form_Close()
gpioTerminate()
End
Public Sub Timer_1_Timer()
Dim LSB As Byte
Dim MSB As Byte
Print "==============================================="
Print "I2C Read Request Initiated"
' The chip was already set when the form Opened.
' Write to the POINTER REGISTER
' - First byte: 0b10010000 (first 7 - bit I2C address followed by a low R / W bit)
i2cWriteByte(i2c_handle, &H90&)
' – Second byte: 0b00000000 (points to Conversion register)
i2cWriteByte(i2c_handle, &H00&)
Print "Pointer Written."
' Read the CONVERSION register.
' - First byte: WRITE 0b10010001 (first 7 - bit I2C address followed by a high R / W bit)
i2cWriteByte(i2c_handle, &H90&) ' Address and HIGH (Read) bit
Print "Address sent, pushed READ command."
' – Second byte: READ the ADS111x response with the MSB of the Conversion register
MSB = i2cReadByte(i2c_handle)
' – Third byte: READ the ADS111x response with the LSB of the Conversion register
LSB = i2cReadByte(i2c_handle)
Print "Data Revovered. MSB = " & MSB & " LSB = " & LSB
DSP_MSB.Text = Str(MSB)
DSP_LSB.Text = Str(LSB)
DSP_DEC.Text = Str((MSB * 256) + LSB)
End
Thanks,
Jerry