Etienne36
Posts: 6
Joined: Mon Jan 16, 2017 3:47 pm

[JAVA] [SOLVED] Pin’s address of ADS1015 (A0,A1,A2..)

Mon Jan 16, 2017 3:50 pm

Hi,

I’m using a raspberry pi 3 with Raspbian and Java 8 and need some help : I can’t find how to receive data from ADS1015’s pin.
I’m using NetBeans 8 with Java and I have Pi4J installed ( cf http://pi4j.com/ ).
My ADS1015 is detected by my Raspberry at 0x48 address (which is the one I had selected).
I tried something like :

Code: Select all

I2CBus i2cbus = I2CFactory.getInstance(I2CBus.BUS_1);
I2CDevice device1 = i2cbus.getDevice(0x48);
System.out.println(device1.read());
But it doesn’t work and returns 133 all the time and I don’t understand why.
I need to read data from ADS1015’s pin (A0, A1, A2 or A3) and I can’t find the specific command to proceed.
Please, help me !

Thanks in advance
Etienne
Last edited by Etienne36 on Tue Jan 17, 2017 11:09 pm, edited 1 time in total.

User avatar
clicky
Posts: 501
Joined: Thu Oct 25, 2012 7:34 am

Re: [JAVA] I can’t find pin’s address of my ADS1015 (A0,A1,A

Tue Jan 17, 2017 10:17 am

I don't think it is as simple as that. Maybe you want to read more about the chip itself (for instance here: https://cdn-shop.adafruit.com/datasheets/ads1015.pdf). Also, there's an example written in python (thanks to Adafruit) here: https://github.com/adafruit/Adafruit_Py ... ADS1x15.py (check _read method).

In general it seems that it goes like this:

1. First you need to write configuration as two bytes at local chip's address 1. Something like:
byte[] writeBuffer = new byte[]{(byte)0x40, (byte)0x0};
device1.write(1, writeBuffer)
I am not 100% sure if config of 0b0100000000000000 (as two hex bytes 0x40, 0x00) is correct (select first input as positive end and ground as negative end). If that's correct that second input should be 0b0101000000000000 (0x41, 0x00) and so on...

2. Read two bytes from local chip's address 0. Something like:
byte[] readBuffer = new byte[2];
device1.read(0, readBuffer)
and then you need to convert those two bytes in integer - first byte is MSB and second LSB (as per PDF above).

I hope this will give you something to start with. Unfortunately I don't have it nor time to set up everything to give it a go myself.

Etienne36
Posts: 6
Joined: Mon Jan 16, 2017 3:47 pm

Re: [JAVA] I can’t find pin’s address of my ADS1015 (A0,A1,A

Tue Jan 17, 2017 3:29 pm

Yersterday, I tried the Python's code given by Adafruit ; and it works (but it's not a Java code...).

I already read the Datasheet of ADS1015. There is no java code example ; whereas at page 22, perhaps something about pin's adress but I don't understand it very well (second row in the table).

Thanks for your reply, I'll further investigate today and try to test your advices.

Etienne36
Posts: 6
Joined: Mon Jan 16, 2017 3:47 pm

Re: [JAVA] [Solve] Pin’s address of ADS1015 (A0,A1,A2..)

Tue Jan 17, 2017 11:09 pm

I found the solution !

Inside the ZIP file of Pi4J, there is a file "Pi4J-extension" and I haven't see it before ! I have just installed it as Pi4J (as a libraries in NetBeans) and it works !

User avatar
clicky
Posts: 501
Joined: Thu Oct 25, 2012 7:34 am

Re: [JAVA] [SOLVED] Pin’s address of ADS1015 (A0,A1,A2..)

Wed Jan 18, 2017 8:56 am

Oh, cool! Sorry - didn't see that! That should do it!

Return to “Java”