WIIMOTE
This is the a sample python script that use serial to send command to the arduino board. it's still not complete but should help you study the wiimote and specialy the #bot.write command. pressind A+B quit the script. Those motions are based on OGA arduino sketch that add a command to turn off the servos.
import cwiid
import time
import sys
import serial
import os
import datetime
#Wiimote and related
button_delay = 0.3
#Rapiro related
bot = serial.Serial('/dev/ttyAMA0', 57600, timeout = 10)
data = []
#connecting to the wiimote. This allows several attempts
# as first few often fail.
print 'Press 1 + 2 on your Wii Remote now ...'
time.sleep(1)
wm = None
i=2
while not wm:
try:
wm=cwiid.Wiimote()
except RuntimeError:
if (i>5):
print("cannot create connection")
quit()
print "Error opening wiimote connection"
print "attempt " + str(i)
i +=1
print 'Wii Remote connected...\n'
print 'Press PLUS and MINUS together to disconnect and quit.\n'
wm.rumble = 1
time.sleep(0.5)
wm.rumble = 0
#set wiimote to report button presses and accelerometer state
wm.rpt_mode = cwiid.RPT_BTN | cwiid.RPT_ACC | cwiid.RPT_CLASSIC | cwiid.RPT_NUNCHUK
#turn on led to show connection has been established
wm.led = 1
#wiimote
wiibuttons = wm.state['buttons']
buttons = wiibuttons
while True:
if (buttons & cwiid.BTN_1):
print (wm.state)
time.sleep(0.8)
if (buttons & cwiid.BTN_2):
print (wm.state)
time.sleep(0.2)
if (buttons - cwiid.BTN_PLUS - cwiid.BTN_MINUS == 0):
print '\nClosing connection ...'
wm.rumble = 1
time.sleep(0.4)
wm.rumble = 0
bot.write('#M08')
time.sleep(5)
bot.write('#M00')
time.sleep(3)
print '\nExiting program ...'
bot.write('#H')
exit(wm)
if (buttons - cwiid.BTN_A - cwiid.BTN_B == 0):
print '\nExtra rapiro movement STOP'
time.sleep(1)
bot.write('#H')
if (buttons & cwiid.BTN_HOME):
print 'Home Button pressed'
time.sleep(button_delay)
bot.write("#H")
if (buttons & cwiid.BTN_LEFT):
print 'Left pressed'
time.sleep(button_delay)
if(buttons & cwiid.BTN_RIGHT):
print 'Right pressed'
time.sleep(button_delay)
Login with google-oauth2
Login with facebook
Help