class BBB::Components::WMP
WiiMotionPlus
I2C component. Attach to P9 like this:
Nunchuck/ WMP connector:
| 1 2 3 | | | | 6 5 4 | | —– | |_| |_|
Connections from NunChuck to BeagleBone “P9” connector:
pin 1: green: system data - connect to BeagleBone pin 20 (I2C2_SDA) pin 2: (not connected) pin 3: red: DC 3.3V supply - to BeagleBone pin 3 or pin 4 (DC_3.3V) pin 4: yellow - system clock - to BeagleBone pin 19 (I2C2_SCL) pin 5: (“ATT” - not needed) pin 6: white - GND - to BeagleBone pin 1 or pin 2 (GND)
Copied from: www.alfonsomartone.itb.it/mzscbb.html
Attributes
gyro[R]
positions[R]
Public Class Methods
new(options = {})
click to toggle source
the WMP
uses I2C pins, so you can give it a name like “I2C2_SDA”
# File lib/BBB/components/wii_motion_plus.rb, line 33 def initialize(options = {}) @started = false @calibrated = false @gyro = Gyro.new @positions = [options.fetch(:i2c, nil)].compact @extension = options[:extension] end
Public Instance Methods
calibrate(number=20)
click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 58 def calibrate(number=20) start unless started? @gyro.start_calibration! number.times do update end @gyro.stop_calibration! @calibrated = true end
calibrated?()
click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 54 def calibrated? @calibrated end
i2c()
click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 78 def i2c ; pins.first ; end
pitch()
click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 79 def pitch ; gyro.pitch ; end
raw_read()
click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 83 def raw_read i2c.read(0x52, 6, 0x00) end
roll()
click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 81 def roll ; gyro.roll ; end
set_extension(bytes)
click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 74 def set_extension(bytes) @extension_set = bytes[4] & 0b00000001 end
start()
click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 41 def start begin #check if we can already read, if so, we're already started. raw_read rescue I2C::AckError i2c.write(0x53, 0xfe, 0x04) end @started = true end
started?()
click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 50 def started? @started end
update()
click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 68 def update bytes = raw_read.bytes.to_a @gyro.update(bytes) set_extension(bytes) end
yaw()
click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 80 def yaw ; gyro.yaw ; end