Part 3: Program and procedure

Posted on by 0 comment

As already mentioned, the heart is a Raspberry Pi 3. The built-in Bluetooth module is handy and can be paired with a Wiimote. 
Operating system is the current Raspbian, and Python version 2.x is used, since the used Wiimote library does not work with version 3.x. 
Ah yes, a tutorial about how to install the library and how to connect the Wiimote is available on this page , for example. Of course, with the Pi 3 you can skip the installation of a Bluetooth dongle.

Here is a section of the Python program:

 while True:

    buttons = wii.state['buttons']

  #Achtung: WiiMote wird quer gehalten, deshalb RIGHT --> Vorwaerts
    if(buttons & cwiid.BTN_RIGHT):
      if(buttons & cwiid.BTN_DOWN):     #DOWN --> rightfor
        Drive_rightfor()
      elif(buttons & cwiid.BTN_UP):     #UP --> leftfor
        Drive_leftfor()
      else:
        Drive_forward()      
    elif(buttons & cwiid.BTN_LEFT):     #LEFT --> Rueckwaerts
      if(buttons & cwiid.BTN_DOWN):     #DOWN --> rightback
        Drive_rightback()
      elif(buttons & cwiid.BTN_UP):     #UP --> leftback
        Drive_leftback()
      else:      
        Drive_back()
    else:
      if(buttons & cwiid.BTN_UP):       #UP --> leftturn
        Drive_leftturn()
      elif(buttons &cwiid.BTN_DOWN):    #DOWN --> rightturn
        Drive_rightturn()
      else:
        Drive_stop()
    time.sleep(0.1)

#Turm drehen mit 1 und 2
    if(buttons & cwiid.BTN_1):
      Turn_left()
    elif(buttons & cwiid.BTN_2):
      Turn_right()
    else:
      Turn_stop()
    time.sleep(0.1)

#Turm heben mit + und -
    if(buttons & cwiid.BTN_PLUS):
      Lift_up()
    elif(buttons & cwiid.BTN_MINUS):
      Lift_down()
    else:
      Lift_stop()
    time.sleep(0.1)

#Band und Bagger
    if(buttons & cwiid.BTN_A):
      if(pressed == '0' and run == 'stop'):
        Band_run()
        pressed = 'A'
      elif(pressed == '0' and run == 'run'):
        Band_stop()
        pressed = 'A'
    else:
      pressed = '0'
    
    time.sleep(0.1)

....

And here is the layout of the Wiimote:

Because no monitor and no keyboard will be plugged into the Pi, the program must start automatically. The Status LED, which is always blue when power is on, flashes red briefly when the Wiimote can be paired (simultaneous pressing 1 and 2). If the pairing is successful, the green LED is additionally lit. 
If the pairing is unsuccessful, the program terminates, but Pi remains on. 
After the pairing has been completed, you can play with the excavator. 
If you have finished, separate the Wiimote with the Home button. Then the Pi shut down. Holding the B button (on the back) while pressing Home will close the connection. The Pi does not shut down.

Last part: it works!

Leave a Reply

Your email address will not be published. Required fields are marked *

Ich benutze Cookies um die Nutzerfreundlichkeit der Webseite zu verbessen. Durch Deinen Besuch stimmst Du dem zu. Wenn Du keine Cookies möchtest, deaktiviere sie bitte im Browser.