

Wire.endTransmission(true) //true=send stopĪrduino addresses are 7 bit (excluding RW bit), so I2C byte address 0x40 needs to be changed to 0x20 for arduino functions. 0=success, 1=tx buff overrun, 2=NACK on address tx, 3=NACK on data tx, 4=other error If (Wire.endTransmission(false) = 0) //false=send restart (IMPORTANT-THIS ENDTRANSMISSION DOES NOT SEND STOP!). No need to send stop as done automatically Uint8_t BytesReceived = Wire.available() //The slave can send less than was requested Wire.requestFrom(0x5a, 2) //Address, no of bytes

Result: 0=success, 1=tx buff overrun, 2=NACK on address tx, 3=NACK on data tx, 4=other error Uint8_t Result = Wire.endTransmission(true) //true=send stop When I write, Serial.Println("End"), in the line after Wire.endTransmission() in function nunchuck_init(), it does not display on Serial Monitor.Īlso, it does not display Nunchuck ready on Serial Monitor since it is written after nunchuck_init() has been called.Seems to be 7 bit value with bit0=lower bit (not I2C RW bit), so left shifted by 1 when sent over the wire. Return nunchuck_buf // FIXME: this leaves out 2-bits of the data Return ((nunchuck_buf > 1) & 1) ? 0 : 1 // voodoo Setup No setup is required, however you can access the files that comprise the wire library in the program folders installed with your Arduino IDE. Return ((nunchuck_buf > 0) & 1) ? 0 : 1 // voodoo returns zbutton state: 1=pressed, 0=notpressed only needed if you use one of the regular wiimote drivers Encode data to format that most wiimote drivers except so we have to check each bit of byte outbuf it also contains the least significant bits for the accelerometer data byte nunchuck_buf contains bits for z and c buttons Int accel_z_axis = nunchuck_buf // * 2 * 2

Int accel_y_axis = nunchuck_buf // * 2 * 2 Int accel_x_axis = nunchuck_buf // * 2 * 2

so we read 8 bits, then we have to add If we recieved the 6 bytes, then go print them Nunchuck_send_request() // send request for next data payload Nunchuck_buf = nunchuk_decode_byte(Wire.receive()) Wire.requestFrom (0x52, 6) // request data from nunchuck Send a request for data to the nunchuck Wire.endTransmission() // stop transmitting Wire.beginTransmission(0x52) // transmit to device 0x52 and tell the nunchuck we're talking to it initialize the I2C system, join the I2C bus, Uses port C (analog in) pins as power & ground for Nunchuckĭelay(100) // wait for things to stabilize This issue has been discussed in several other forums, and the best solution I've found so far is to use an alternate library. It is possible for the endTransmission function to hang the microcontroller in different scenarios. Static uint8_t nunchuck_buf // array to store nunchuck data, A existing problem with the stock Arduino Wire library is that there is no timeout. I am working on a project, syncing Nintendo Nunchuk with Arduino.
