Justin MinerLuke Zwilling
Published © GPL3+

ME461 Wii Remote Controlled TMS320F28379D Launchpad Robot

This robot uses a custom breakout board, 3d printed parts, spi and serial communication to get data from a wii remote and pixy camera.

AdvancedShowcase (no instructions)8 hours346
ME461 Wii Remote Controlled TMS320F28379D Launchpad Robot

Things used in this project

Story

Read more

Code

evtest

Python
This is the main code on raspberry pi to send the wiimote code
#Justin Miner 12/8/21
#Before running this code, change the shell script to have the correct Bluetooth address

import os, serial
from evdev import InputDevice, categorize, ecodes
from time import sleep

#sees if the gamepad is already connected otherwise runs the script
#try:
#   gamepad = InputDevice('/dev/input/event0')
#except:
#    run the config script to connect the remote
#    os.system("sudo make ./connectwii.sh")
#    os.system("sudo ./connectwii.sh")
#    sleep(.5)
#    gamepad = InputDevice('/dev/input/event0')

#run the config script to connect the remote
#os.system("sudo make ./connectwii.sh")
#os.system("sudo .connectwii.sh")

#opens the serial connection
ser = serial.Serial("/dev/ttyUSB0", 115200)

#initialize variables for each button
a = 0
b = 0
minus = 0
plus = 0
home = 0
one = 0
two = 0
updown = 0
leftright = 0
txt = "{:011b}"

#array variables to store button values and past values
arr = []
arr1 = []

#message variable to give binary message
msg = 0;

#initialize the gamepad object
gamepad = InputDevice('/dev/input/event0')
#prints the specific gamepad
print(gamepad)

#each change in state is regarded as an event
for event in gamepad.read_loop():
        #finds the type of the event
        wiievent = categorize(event)
        
        #determines what to do for each type
        #first if is for direction pad events
        if event.type == ecodes.EV_ABS:  
            if ecodes.bytype[wiievent.event.type][wiievent.event.code] == 'ABS_X':
                leftright = wiievent.event.value
                if leftright == 1:
                    leftright = 2
                elif leftright == -1:
                    leftright = 1
            if ecodes.bytype[wiievent.event.type][wiievent.event.code] == 'ABS_Y': 
                updown = -1*wiievent.event.value
                if updown == 1:
                    updown = 2
                elif updown == -1:
                    updown = 1
        #this is for button presses (event codes correspond to each button)
        elif event.type == ecodes.EV_KEY:
            if event.code == 304:
                a = event.value
            if event.code == 305:
                b = event.value
            if event.code == 307:
                one = event.value
            if event.code == 308:
                two = event.value
            if event.code == 314:
                minus = event.value
            if event.code == 315:
                plus = event.value
            if event.code == 316:
                home = event.value
        
        #takes the old status and assigns it to previous array
        arr1 = arr
        arr = [a,b,one,two,minus,plus,home,updown,leftright]
        
        #checks for change in array to create new messsage
        if arr != arr1:
            message = 0
            for i in range(len(arr)):
                #checks if it is a 1 bit number or 2 bits (2 bits are stored at end)
                if i<8:
                    #adds to number in binary
                    message += arr[i] << i
                elif i==8:
                    message += arr[i] << i+1
            
            #formats number in text in order to output got rid of 0 message for less spam
            if message != 0:
                print(str.format(txt,message))
            ser.write("!" + str.format(txt,message) + "\n\r")
            sleep(0.1)

conectwii

SH
This is the connection code in shell
#!/bin/bash
modprobe uinput
sleep 1 # Wait until Bluetooth services are fully initialized
hcitool dev | grep hci >/dev/null
#change the value below
if test $? -eq 0 ; then
    echo "Trying to connect"
    #input bluetooth address below
    wminput -d -c  /home/pi/bin/mywinput 00:1E:35:72:CA:43 &
else
    echo "Blue-tooth adapter not present!"
    exit 1
fi

mywinput

SH
button mapping code
#WiiMote
Wiimote.A  = BTN_A
Wiimote.B = BTN_B
Wiimote.Dpad.X = ABS_X
Wiimote.Dpad.Y = -ABS_Y
Wiimote.Minus = BTN_SELECT
Wiimote.Plus = BTN_START
Wiimote.Home = BTN_MODE
Wiimote.1 = BTN_X
Wiimote.2 = BTN_Y
# Nunchuk
Nunchuk.C = BTN_C
Nunchuk.Z = BTN_Z
Plugin.led.Led1 = 1
#Plugin.led.Led2 = 1
#Plugin.led.Led3 = 1
Plugin.led.Led4 = 1

TMS Code

Upload this to the Launchpad through code composer

Credits

Justin Miner

Justin Miner

1 project • 0 followers
Luke Zwilling

Luke Zwilling

1 project • 0 followers

Comments