Hardware Reference
In-Depth Information
If you see these modules loaded, you're good to go. Otherwise, manually load them now:
$ sudo modprobe i2c−bcm2708
$ sudo modprobe i2c−dev
Assuming the Raspberry Pi rev 2.0+, you'll use I2C bus 1 (see Chapter 12 of Raspberry
Pi Hardware Reference [Apress, 2014] if you're not sure). Scan to see whether your
Nunchuk is detected:
$ sudo 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: −− −− 52 −− −− −− −− −− −− −− −− −− −− −− −− −−
60: −− −− −− −− −− −− −− −− −− −− −− −− −− −− −− −−
70: −− −− −− −− −− −− −− −−
If the Nunchuk is working, it will show up in this display at address 0x52. With the
hardware verified, it is time to move on to the software.
Nunchuk I2C Protocol
The Nunchuk contains a quirky little controller that communicates through the I2C bus.
In order to know where to store bytes written to it, the first byte must be an 8-bit register
address. In other words, each write to the Nunchuk requires the following:
One register address byte, followed by
Zero or more data bytes to be written to sequential locations
Thus for write operations, the first byte sent to the Nunchuk tells it where to start.
Any following write bytes received are written with the register address incremented.
Tip
Don't confuse the register address with the Nunchuk's I2C address of 0x52.
It is possible to write the register address and then read bytes instead. This procedure
specifies the starting location of data bytes to be read.
A quirky aspect of the Nunchuk controller is that there must be a short delay between
writing the register address and reading the data. Performing the write followed by an
immediate read does not work. Writing data immediately after the register address does
succeed, however.
Note
the Nunchuk uses I2C address 0x52.
 
 
Search WWH ::




Custom Search