EasyManuals Logo

Arduino uno User Manual

Arduino uno
311 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #168 background imageLoading...
Page #168 background image
After including all of the libraries we need, we define the
NUNCHUK_DEVICE_ID
constant. I
2
C is a master/slave protocol; in our case, the Arduino will be the
master, and the Nunchuk will be the slave. The Nunchuk registers itself at
the data bus using a certain ID (0x52), so we can address it when we need
something.
In
initialize
, we establish the connection between the Arduino and the Nunchuk
by sending a handshake. In line 7, we call
Wire
s
begin
method, so the Arduino
joins the I
2
C bus as a master. (If you pass
begin
an ID, it joins the bus as a
slave having this ID.) Then well begin a new transmission to the device
identified by
NUNCHUCK_DEVICE_ID
: our Nunchuk.
We send two bytes (0x40 and 0x00) to the Nunchuk, and then we end the
transmission. This is the whole handshake procedure, and now we can ask
the Nunchuk for its current status by calling
update
. In the following figure,
we see the message flow between an Arduino and a Nunchuk.
Arduino Nunchuk
6 data bytes
Handshake (0x40, 0x00)
Request new data (0x00)
6 data bytes
}
repeat
update
first pauses for a millisecond to let things settle. Then we request six
bytes from the Nunchuk, calling
Wire.requestFrom
. This doesnt actually return
the bytes, but we have to read them in a loop and fill our buffer.
Wire.available
returns the number of bytes available on the data bus, and
Wire.read
returns
the current byte. We cannot use the bytes we get from the Nunchuk directly,
because the controller obfuscates them. Decrypting them is easy, as you
can see in
decode_byte
.
Finally, we call
request_data
to tell the Nunchuk to prepare new data. It transmits
a single zero byte to the Nunchuk, which means prepare the next six bytes.
Before we actually use our
Nunchuk
class in the next section, take a look at the
documentation of the Wire library. In the Arduino IDEs menu, choose Help
> Reference and click the Libraries link.
report erratum discuss
Building a Nunchuk Class 151
www.it-ebooks.info

Table of Contents

Other manuals for Arduino uno

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Arduino uno and is the answer not in the manual?

Arduino uno Specifications

General IconGeneral
Form factorArduino
CertificationRoHS, FC, CE
Processor model-
Processor frequency- MHz
Microcontroller modelATmega328
Microcontroller frequency16 MHz
DC input voltage7-12 V
Operating voltage5 V
DC current per I/O pin40 mA
Flash memory0.032 MB
Maximum internal memory- GB
SRAM (Static Random Access Memory)2 KB
EEPROM (Electrically Erasable Programmable Read-Only Memory)1 KB
Wi-FiNo
Number of analog I/O pins6
Number of digital I/O pins14
Weight and Dimensions IconWeight and Dimensions
Board dimensions53.4 x 68.6 mm

Related product manuals