31 May 2013
Bus Pirate is a USB device that connects to a variety of digital electronic components (e.g. EEPROMs, sensors) via protocols such as I2C, SPI, UART, 1-wire. Towards the host-side it offers a serial terminal with a single text interface, so no software to install.
So I want to hook up a TAOS TSL45315 ambient light sensor (ALS) via I2c. The most difficult part is to find the right cables of the Bus Pirate for the SDA, CLK, GND and 3v3 signals.
Then fire up a terminal (minicom -D /dev/ttyUSBx
) and you'll see the Bus Pirate prompt: HiZ>
.
Help is available with ?
.
Typing m 4 3
changes to I2C mode, W
turns on the power supply output, P
enables pullups.
Entering (1)
runs a macro which scans the I2C bus for devices; here a chip with 7-bit address 0x29 shows up (yeah, this is our TSL45315 -- check the datasheet!):
I2C>(1) Searching I2C address space. Found devices at: 0x52(0x29 W) 0x53(0x29 R)
To turn on the sensor and make a measurement:
I2C>[0x52 0x80 0x03] I2C START BIT WRITE: 0x52 ACK WRITE: 0x80 ACK WRITE: 0x03 ACK I2C STOP BIT I2C>[0x52 0x84 [ 0x53 rr ] I2C START BIT WRITE: 0x52 ACK WRITE: 0x84 ACK I2C START BIT WRITE: 0x53 ACK READ: 0xC6 READ: ACK 0x00 NACK I2C STOP BITThe first command (
[0x52 0x80 0x03]
) addresses the chip for writing (0x52) and sets the value 0x03 to register 0x00 (the MSB has to be set).
The second command ([0x52 0x84 [ 0x53 rr ]
) selects the data low register (0x04, MSB set, hence 0x84) and then instructs the chip to read two bytes. The results is 0xc6, 0x00 which gives the ambient light in lux: (0x00 << 8) | 0xc6.
posted at: 11:44 | path: /projects | permanent link