XOJO example code with ADS1115 A/D converter

I’m relatively new to the Xojo world and I know I still have a lot to learn.

I would like to do a proof of concept using the ADS1115 A/D converted connected to a RsPi. I’ve been trying this test for several days but I still haven’t gotten satisfactory results.

I have also not found example code using this ADC on the Internet or this forum.

Since I’m sure someone has had to use this ADC in Xojo, could someone share some of their code on how to initialize and read any of the ADC’s?

Thanks in advance, Pablo EA4TX

have you seen this example from einhugur about mcp4725 ?
https://einhugur.com/GPIO/I2C/I2CMCP4725.html

it’s not your adc, but it is quite similar as it is a i2c adc on a Pi with xojo
this could help you
or please post your wiring and code so that we can help you.

The ADS1115 is on my list to make a guide for.

But I am working on other very large guide at the moment so will be a while until the ADS1115 gets investigated and written about by me.

1 Like

Many thanks Jean-Yves and Björn for your replay. I appreciate your help!

I usually program the PICs (18Fxxx family) in C, then I looked for a library for my compiler for the ADS1115 and together with the ADC Datasheet I performed reverse engineering.
The result has been positive and I now have a method to be able to read any of the 4 Analog inputs of the IC. From the tests I have carried out it works well, then I leave the code here in case it is of interest to someone who has to access this ADC.

Rgrds, Pablo EA4TX

Var FileHandle As Integer
Var Data As Integer
Var MyADC1 As UInt16
Var Reg0 As UInt8
Var Reg1 As UInt8
Var Reg2 As UInt8

Var mb As New MemoryBlock(4)
Var buf As New MemoryBlock(3)

Const HEX48 = &b1001000 //Hex 48
Const HEX49 = &b1001001 //Hex 49
Const HEX4A = &b1001010 //Hex 4A
Const HEX4B = &b1001011 //Hex 4B

Const ONESHOT_ON = &b10000001
Const ONESHOT_OFF = 0

Const AI0 = &b01000000
Const AI1 = &b01010000
Const AI2 = &b01100000
Const AI3 = &b01110000

Const GAIN1 = &b00000000 //Full Scale Voltage is: 6.144 + or -
Const GAIN2 = &b00000010 //FS 4.096
Const GAIN3 = &b00000100 //FS 2.048 (defecto)
Const GAIN4 = &b00000110 //FS 1.024
Const GAIN5 = &b00001000 //FS .512
Const GAIN6 = &b00001010 //FS .256
Const GAIN7 = &b00001100 //FS .256
Const GAIN8 = &b00001110 //FS .256

pi = New pigpio
Call pi.gpioInitialise()
pi.Handle = pi.pigpio_start(Nil, Nil)

FileHandle = pi.i2c_open(1, HEX48,0)

’ Set OneShot + AN1 + Gain3
Reg0 = 1
Reg1 = ONESHOT_OFF + AI1 + GAIN3
Reg2 = &h85

’ Load 3 Registers
buf.Int8Value(0) = Reg0
buf.Int8Value(1) = Reg1
buf.Int8Value(2) = Reg2
Data = pi.i2c_write_device(FileHandle,buf, 3)
’ Read ADC1
MyADC1 = pi.i2c_read_word_data(FileHandle,0)

’ Swap the bytes around
mb.UInt16Value(0) = MyADC1
mb.LittleEndian = Not mb.LittleEndian
MyADC1 = mb.UInt16Value(0)

’ output the digital value (ADC1)
Print "ADC = " + CStr(MyADC1)

1 Like

Have you considered and Arduino rather than R-Pi? They have built in dedicated ADC channels. Super easy to capture data and send back to a desktop Xojo app via USB serial.

I can’t consider using an Arduino because I really need many more things besides the ADC. It is a fairly ambitious project and the Arduino would surely be too small.

1 Like

You can’t really compare the Arduino’s 10-bit ADC with the 16-bit ADS111x family with built-in precision reference and programmable-gain amplifier. ADS111x is a great part, I’ve used it in a few PIC-based projects.

1 Like

I would have used an arduino too, more specifically an esp8266 or esp32
connected the ads1115 to it
get the adc values in real time
then send the result to the Pi to manage it, display it,etc… using a xojo app.
I don’t think the Pi is good at real time data sampling (compared to an espXX)

anyway, we don’t have enough data on the project itself to say more about it !