meekamoo
Posts: 7
Joined: Fri Nov 27, 2015 11:38 am

[solved] Atlas pH + EC IC's via I2C

Fri Nov 27, 2015 12:03 pm

Having the weirdest problem that I just cannot seem to debug on my own.

I'm trying to access the Atlas Scientific ph + electrical conductivity sensor IC's via I2C on a Pi2 B+ and am having no luck.

https://www.atlas-scientific.com/produc ... h-kit.html
https://www.atlas-scientific.com/produc ... 0_kit.html

Code: Select all

[email protected] ~/phi2c $ uname -a
Linux raspberrypi 4.1.13-v7+ #826 SMP PREEMPT Fri Nov 13 20:19:03 GMT 2015 armv7l GNU/Linux
- I was able to access via Serial, but having two devices requires I2C. (other than a second UART chip)
- GPIO 3 SDA - connected to both IC's SDA pins.
- GPIO 5 SCL - connected to both IC's SCL pins.
- 5V/ground as normal. (Tried 3.3V too)

Wired same as diagram below:
Image

I tried adding 4.7k pullups to both SDA+SCL but that did not appear to do anything (I added a resistor between each data line and 5V). Thought just maybe I was getting I2C wrong and mixing up with UART so even tried swapping the SDA and SCL lines to no avail.

I2C appears to be working, as I can run i2cdetect and just shows no devices on the bus. Yesterday I was able to get one device to appear, but as soon as I tried to access it either via i2cget or the atlas example python code, the device disappeared from i2cdetect.

Code: Select all

[email protected] ~/phi2c $ cat /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

#snd-bcm2835
#stmpe_ts

i2c-bcm2708
i2c-dev

Code: Select all

[email protected] ~/phi2c $ dmesg |grep i2c
[    4.263670] bcm2708_i2c 3f804000.i2c: BSC1 Controller at 0x3f804000 (irq 79) (baudrate 100000)
[    4.267132] i2c /dev entries driver
Today, I am not able to even get the device to appear in i2cdetect any more - let alone both devices. According to the datasheet the device is in I2C mode (You can short 2 pins to force it into I2C mode which I have. Onboard LED's indicate current mode)

Code: Select all

[email protected] ~/phi2c $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --   
What does worry me is the output from gpio readall...

Code: Select all

[email protected] ~/phi2c $ gpio readall
 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 | ALT0 | 1 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI | ALT0 | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO | ALT0 | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT  | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | OUT  | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
As far as I was aware, SDA + SCL should both be in Alternative mode (ALT0).

I tried pigspio (ran the daemon, then used the CLI command) to change the pins to ALT0 but that does not appear to work either:

Code: Select all

[email protected] ~/phi2c $ sudo pigpiod 
[email protected] ~/phi2c $ pigs m 3 0
[email protected] ~/phi2c $ gpio readall
 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 | ALT0 | 1 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI | ALT0 | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO | ALT0 | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT  | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | OUT  | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
Has anyone managed to get the atlas sensor IC's to communicate via I2C? Or maybe know a little something to help point in right direction?

Thanks
Bryan
Last edited by meekamoo on Mon Nov 30, 2015 6:14 pm, edited 1 time in total.

User avatar
joan
Posts: 13557
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Atlas pH + EC IC's via I2C

Fri Nov 27, 2015 1:20 pm

Could you try pigs mg 3?

It should report 4 for a GPIO set to ALT0.

If can't think of a reason for a mode change to fail. Either a pretty drastic hardware fail on that GPIO or some software is running in the background setting the GPIO as an input.

What does gpiotest report?

meekamoo
Posts: 7
Joined: Fri Nov 27, 2015 11:38 am

Re: Atlas pH + EC IC's via I2C

Fri Nov 27, 2015 1:32 pm

Sure. Yeah I'm rather stumped why modechanging isn't working either.

Code: Select all

[email protected] ~/bin $ pigs mg 3
0
First removed the sda/scl wires, then:

Code: Select all

[email protected] ~/bin $ ./gpiotest.sh 
This program checks the Pi's (user) gpios.

The program reads and writes all the gpios.  Make sure NOTHING
is connected to the gpios during this test.

The program uses the pigpio daemon which must be running.

To start the daemon use the command sudo pigpiod.

Press the ENTER key to continue or ctrl-C to abort...

Testing...
Skipped non-user gpios: 0 1 28 29 30 31 
Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 
Failed user gpios: None
- $ pigs m 3 0
- $ gpio readall
- still set to INPUT

Weird.

meekamoo
Posts: 7
Joined: Fri Nov 27, 2015 11:38 am

Re: Atlas pH + EC IC's via I2C

Fri Nov 27, 2015 1:43 pm

joan wrote:If can't think of a reason for a mode change to fail. Either a pretty drastic hardware fail on that GPIO or some software is running in the background setting the GPIO as an input.
You got it there! Found a cronjob running an old DHT temp sensor which was changing the pin mode.

50% Success!

Code: Select all

[email protected] / $ gpio readall
 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 | ALT0 | 1 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 | ALT0 | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 0 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 0 | ALT0 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI | ALT0 | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO | ALT0 | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT  | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | OUT  | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 0 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 0 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
But still:

Code: Select all

[email protected] / $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --     

User avatar
joan
Posts: 13557
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Atlas pH + EC IC's via I2C

Fri Nov 27, 2015 1:48 pm

The gpiotest should have set the mode for GPIO 3 to write during the test (they are put back into the original mode at the end of the test).

So try setting the other modes and read them back.

Code: Select all

for m in r w 0 1 2 3 4 5; do echo $m; pigs m 3 $m mg 3;done
r
0
w
1
0
4
1
5
2
6
3
7
4
3
5
2
Overlapping posts.

meekamoo
Posts: 7
Joined: Fri Nov 27, 2015 11:38 am

Re: Atlas pH + EC IC's via I2C

Fri Nov 27, 2015 1:55 pm

Yeah that seems to work alright:

Code: Select all

[email protected] ~ $ for m in r w 0 1 2 3 4 5; do echo $m; pigs m 3 $m mg 3;done
r
0
w
1
0
4
1
5
2
6
3
7
4
3
5
2
The pins seem to be in the correct mode now, yet i2cdetect is still giving nothing back.

User avatar
joan
Posts: 13557
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Atlas pH + EC IC's via I2C

Fri Nov 27, 2015 2:03 pm

Back to the basics, check that the ground, power, SDA, and SCL connections are good.

meekamoo
Posts: 7
Joined: Fri Nov 27, 2015 11:38 am

Re: Atlas pH + EC IC's via I2C

Fri Nov 27, 2015 2:32 pm

So I unplugged it all, and re-seated everything from scratch.

Still nudda :(

Image
http://i.imgur.com/3fJ0PJO.jpg

GND+PWR must be working because both devices are flashing LED's
SDA to both (labelled) TX pins
SCL to both (labelled) RX pins

Hmmm.

User avatar
joan
Posts: 13557
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Atlas pH + EC IC's via I2C

Fri Nov 27, 2015 2:51 pm

Does the same sensor do serial as well as I2C? In the blurb the I2C sensors were labelled SDA/SCL whereas the one on your breadboard seem to be labelled RX/TX (as for the serial sensors).

Some breadboard power/ground rails are not continuous, they may be broken into 3 segments.

meekamoo
Posts: 7
Joined: Fri Nov 27, 2015 11:38 am

Re: Atlas pH + EC IC's via I2C

Fri Nov 27, 2015 3:10 pm

joan wrote:Does the same sensor do serial as well as I2C? In the blurb the I2C sensors were labelled SDA/SCL whereas the one on your breadboard seem to be labelled RX/TX (as for the serial sensors).

Some breadboard power/ground rails are not continuous, they may be broken into 3 segments.
Yes, it shares the same pins for serial + I2C. The PDF says TX=SDA and RX=SCL. I've even thought I had them wrong way around and swapped it - nothing.

Multimeter shows +5 on power rail + ground rail.

I've tried sending an email to Atlas too, they say on the website that you can email them for tech support - so I've given that a bash too.

EDIT: the website datasheet shows the wiring https://www.atlas-scientific.com/_files ... iagram.pdf

GadgetUK
Posts: 61
Joined: Thu Jan 19, 2012 6:02 pm

Re: Atlas pH + EC IC's via I2C

Sat Nov 28, 2015 5:18 pm

Have a read of the datasheet

https://www.atlas-scientific.com/_files ... asheet.pdf

You need to put the modules into i2c mode. There are two methods for this, using a serial command, or a hardware configuration change.

stevend
Posts: 189
Joined: Fri Oct 11, 2013 12:28 pm

Re: Atlas pH + EC IC's via I2C

Sat Nov 28, 2015 10:38 pm

Don't the Pi's I2C signals run at 3.3V (rather than 5V)?
(If so, the pullup resistors have probably saved you blowing up your Pi - they would probably have limited current enough).
If your sensors need 5V on the I2C, there are level shifter chips such as the PCA9512, as well as various circuits published using discrete components.

meekamoo
Posts: 7
Joined: Fri Nov 27, 2015 11:38 am

Re: Atlas pH + EC IC's via I2C

Mon Nov 30, 2015 6:13 pm

Whoa - never doubt the power of a full cold-restart!

I unplugged the Pi before going to bed - switched on and now everything is working.

I have both devices discovered in $ i2cdetect and they both respond to i2c commands.

Code: Select all

[email protected] ~/phi2c $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- 63 64 -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
[email protected] ~/phi2c $ ./read-ph.py 
>> Atlas Scientific sample code
>> Any commands entered are passed to the board via I2C except:
>> Address,xx changes the I2C address the Raspberry Pi communicates with.
>> Poll,xx.x command continuously polls the board every xx.x seconds
 where xx.x is longer than the 1.50 second timeout.
 Pressing ctrl-c will stop the polling
Enter command: address,99
I2C address set to 99
Enter command: r
Command succeeded 3.846
Enter command: address,100
I2C address set to 100
Enter command: r
Command succeeded 0.00,0,0.00,1.000
Enter command: 
stevend wrote:Don't the Pi's I2C signals run at 3.3V (rather than 5V)?
(If so, the pullup resistors have probably saved you blowing up your Pi - they would probably have limited current enough).
If your sensors need 5V on the I2C, there are level shifter chips such as the PCA9512, as well as various circuits published using discrete components.
Dang - thank you for that piece of important information. I have switched the sensors to 3.3v (they support 3.3/5v). Pi still working!

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: DEADMOON and 10 guests