ibanezmatt13
Posts: 128
Joined: Fri Dec 28, 2012 9:49 am

No i2c detected

Sun Jan 13, 2013 10:04 am

Hi,

I am trying to use a PCF8591 analog to digital converter to convert and analog signal from a TMP36 temperature sensor and input a digital signal into the Pi via the SCL and SDA pins.

When I run the following command:

sudo i2cdetect -y 0

I get the following:

pi@raspberrypi ~ $ sudo i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@raspberrypi ~ $

On the 40x8 line, according to the various tutorial, it should detect an i2c input. This is suggesting that no i2c addresses from any devices are being detected despite me checking over and over that I have installed the correct drivers and I have connected the circuit correctly.

Any suggestions as to what I should do will be greatly appreciated.
Matthew

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: No i2c detected

Sun Jan 13, 2013 1:32 pm

IIRC on rev2 boards i2c bus 0 and 1 were swapped around. So if you have one of these you may have to use 'i2cdetect -y 1'.

HTH
Dirk.

ibanezmatt13
Posts: 128
Joined: Fri Dec 28, 2012 9:49 am

Re: No i2c detected

Sun Jan 13, 2013 2:24 pm

DirkS wrote:IIRC on rev2 boards i2c bus 0 and 1 were swapped around. So if you have one of these you may have to use 'i2cdetect -y 1'.

HTH
Dirk.
Hi, thanks for the reply.

That did the trick! It came up and one of the lines read 48 as expected. There is only one thing now. The code I am using is not working. I keep getting the same error message upon run:

Errno 5: I/O error

I don't know why this is so. I'll paste the code I am using below. Any further help will be greatly appreciated.

Matthew


#Read a value from analogue input 0
#in A/D in the PCF8591P @ address 0x48
from smbus import SMBus

bus = SMBus(0)

print("Read the A/D")
print("Ctrl C to stop")
bus.write_byte(0x48, 0) # set control register to read channel 0
last_reading =-1

while(0 == 0): # do forever
reading = bus.read_byte(0x48) # read A/D
if(abs(last_reading - reading) > 2):
print(reading)
last_reading = reading

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: No i2c detected

Sun Jan 13, 2013 2:42 pm

You'll have to change the bus number in your code too:

Code: Select all

bus = SMBus(1)
Gr.
Dirk.

ibanezmatt13
Posts: 128
Joined: Fri Dec 28, 2012 9:49 am

Re: No i2c detected

Sun Jan 13, 2013 2:54 pm

DirkS wrote:You'll have to change the bus number in your code too:

Code: Select all

bus = SMBus(1)
Gr.
Dirk.
Many thanks, I really appreciate the help. I'll let you know if it works.

Kind Regards
Matthew

ibanezmatt13
Posts: 128
Joined: Fri Dec 28, 2012 9:49 am

Re: No i2c detected

Sun Jan 13, 2013 2:57 pm

DirkS wrote:You'll have to change the bus number in your code too:

Code: Select all

bus = SMBus(1)
Gr.
Dirk.
Hi,

The program runs now, however, it prints a reading of '128'. It should really be a reading of about 21 as it is supposed to tell me the temperature. It reads 128.

Why is this?
Regards
Matthew

BriComp
Posts: 13
Joined: Tue Aug 28, 2012 2:28 pm

Re: No i2c detected

Sun Jan 13, 2013 4:14 pm

I am sorry but you should really read the data sheets of the items you are using.

The TMP36 gives an output of 10mV/deg C but operates from -40Deg C.
In order to do this it puts an offset to the outputed voltage. At 25Deg C the reading output will be 750mV.

On the PCF8591 A/D Converter there are a number of things that can affect the reading. Bye the way the value you are stating is correct for the Power-on reset condition. The first byte read is a hexadecimal 80 (128 decimal ).

Things that affect the A/D - What value are you using for Vref, What value have you put into the DAC data register.

A conversion is initiated by reading a channel. The initial value returned is 80Hex. The value from the conversion is only returned upon the next read. If the auto increment flag is set the next channel read will be +1 on the initial channel until all 4 have been read then the sequence will repeat.
As I say you really need to read the data sheet to understand what is happening.
A valid reading for 21 DegC will be 710mV.

Return to “Beginners”