PIR Sensor
Hardware
Raspberry Pi |
EEPROM |
PIN
|
GND |
A0 |
1
|
GND |
A1 |
2
|
GND |
A2 |
3
|
GND |
GND |
4
|
+5V
|
VCC |
5
|
--- |
WP |
6
|
SCL |
SCL |
7
|
SDA |
SDA |
8
|
Terminal
# i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x03-0x77.
Continue? [Y/n]
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- 2d -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 49 -- -- -- -- -- --
50: 50 51 52 -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- 69 -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
DUMP EEPROM DATA # i2cdump 0 0x2d
No size specified (using byte-data access)
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0, address 0x2d, mode byte
Continue? [Y/n]
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
10: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
20: 8a 8b de bb c9 d8 d0 1d ff ff aa c1 9e c1 9e e3
30: ba cc a8 d8 b2 ed c2 e4 bb 3c 32 e1 e1 e1 00 00
40: 01 c3 00 00 00 00 40 50 2d 01 01 40 01 95 00 a3
50: 10 01 80 ff ff ff 00 00 11 ff ff ff ff ff ff ff
60: 8a 8b de bb c9 d6 d1 1d ff ff aa c1 9e c1 9e e3
70: ba cc a8 d8 b2 ed c2 e4 bb 3c 32 e1 e1 e1 00 00
80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
90: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
a0: 8b 8b de bb c8 d9 d1 1d ff ff ab c1 9e c1 9e e3
b0: ba cc a8 d8 b2 ed c2 e4 bb 3c 32 e1 e1 e1 00 00
c0: 01 c3 00 00 00 00 40 50 2d 01 01 40 01 95 00 a3
d0: 10 01 80 ff ff ff 00 00 11 ff ff ff ff ff ff ff
e0: 8a 8a de bb c9 d8 d1 1d ff ff aa c1 9e c1 9e e3
f0: ba cc a8 d8 b2 ed c2 e4 bb 3c 32 e1 e1 e1 00 00
i2cget and i2cset
For advanced debugging you can use the i2cget and i2cset commands to read from, respectively write to, an I2C device. As fori2cdump, you should be very careful when using these commands, if you don't know what you're doing, chances are that you'll break something. The general usage is:
i2cget <bus> <chip> <register>
i2cset <bus> <chip> <register> <value>
For example, the following writes the value 0x22 to register 0x10 of device 0x2d on i2c bus 0:
# i2cset 0 0x2d 0x10 0x22
isaset
For advanced debugging you can use the isaset command to write to an ISA device. It is the ISA equivalent of i2cset. Again, you better know what you are doing when using this command. The usage is:
isaset <addrreg> <datareg> <register> <value>
For example, the following writes the value 0x22 to register 0x10 of an ISA device present at address 0x290:
# isaset 0x295 0x296 0x10 0x22
Read Write by Python
from smbus import SMBus
smb=SMBus(1);
slaveaddr=0x50;
def eeprom_set_current_address(addr):
a1=addr/256;
a0=addr%256;
smb.write_i2c_block_data(slaveaddr,a1,[a0]);
def eeprom_write_block(addr,data):
a1=addr/256;
a0=addr%256;
data.insert(0,a0);
print('data : ',data)
smb.write_i2c_block_data(slaveaddr,a1,data);
def eeprom_read_byte(addr):
eeprom_set_current_address(addr);
return smb.read_byte(slaveaddr);
eeprom_set_current_address(0);
#Read Address from 0x00 to 0x10
print '0 to 10'
for x in range(0,10):
print eeprom_read_byte(x);
# Write input data to 0x00
print 'Write 0xc0 to Address 0x00'
x = input(">>> Input: ")
savedata = [x]
print('savedata : ',savedata)
eeprom_write_block(0,savedata)
|