1

Every time I press a button on the wiimote controlling my robot (Rover 5 with PiFace), the pi restarts. My code is as follows:

import cwiid
import time
import pifacedigitalio as pfio

pfio.init()

button_delay = 0.1

print 'Press 1 + 2 on your Wii Remote now ...'
time.sleep(1)

# Try to connect to the Wiimote & quit if not found
try:
  wii=cwiid.Wiimote()
except RuntimeError:
  print "Can't connect to Wiimote"
  quit()

print 'Wiimote connected'
wii.rpt_mode = cwiid.RPT_BTN

while True:
  buttons = wii.state['buttons']
  if (buttons & cwiid.BTN_UP):
    #Forwards
    time.sleep(button_delay)
    pfio.digital_write(2, 1)
    pfio.digital_write(3, 1)

  elif (buttons & cwiid.BTN_DOWN):
    #Backwards
    time.sleep(button_delay)  
    pfio.digital_write(4, 1)
    pfio.digital_write(5, 1)

  elif (buttons & cwiid.BTN_LEFT):
    #Left
    time.sleep(button_delay)         
    pfio.digital_write(2, 1)
    pfio.digital_write(5, 1)

  elif(buttons & cwiid.BTN_RIGHT):
    #Right
    time.sleep(button_delay)          
    pfio.digital_write(3, 1)
    pfio.digital_write(4, 1)

  else:
    pfio.digital_write(2, 0)
    pfio.digital_write(3, 0)
    pfio.digital_write(4, 0)
    pfio.digital_write(5, 0)


#press button A to stop all motors
  if (buttons & cwiid.BTN_A):
    time.sleep(button_delay)          
    for i in pins:
      pfio.digital_write(2, 0)
      pfio.digital_write(3, 0)
      pfio.digital_write(4, 0)
      pfio.digital_write(5, 0)
  • 1
    The usual reason for a restart is the power supply voltage dropping too low. If this coincides with a motor being started that suggest the power supply does not have sufficient amperage. – joan Sep 13 '15 at 15:38
  • Thanks, how would I go about fixing this? – BlueDyno Sep 13 '15 at 15:54
  • A better power supply. How are you powering the Pi and the motors? – joan Sep 13 '15 at 16:01
  • Mains whilst Im testing it,. – BlueDyno Sep 13 '15 at 16:15
  • The Pi is a 5V device. It can't be powered off the mains. I doubt your motors are mains powered either. You are probably using one or more power bricks. Where are they plugged in and what are their amp ratings. – joan Sep 13 '15 at 19:01
1

The power supply you are using to plug the Raspberry Pi to the mains is probably unable to deliver the required power.

You don't say where in the world you are. In the UK, one of these should do the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.