0

I’m using a Micro:Bit and Bit:Bot to do some simple things but am getting unexpected results from the Bit:Bot motor.

Simply put, i’m trying to:

    • move the Bit:Bot forward for 1 second (with a few Green Neopixels on)
    • Stop motors (& clear all neopixels)
    • reverse (with some Red Neopixels on)

Here is my program, written in MicroPython:

from microbit import *
import neopixel

# pin13 gives access to the robot's neopixels.
myLightShow = neopixel.NeoPixel(pin13,12)
myLightShow[3]= (0,255,0)
myLightShow[4]= (0,225,0)
myLightShow[5]= (0,255,0)
myLightShow[9]= (0,255,0)
myLightShow[10]= (0,255,0)        
myLightShow[11]= (0,255,0)
myLightShow.show()

#for driving the motors the following pins are used:
#pin8 (left wheel) and pin12 (right wheel) sets the direction. 
#set pin to 0 for forward, set pin to 1 for reverse

# pin0 (left wheel) and pin1 (right wheel) sets speed. 0 - 1023 range
# both, therefore, are write_analog statements.

#Below, the 5 statements tell motors to go forward, at speed 300 for 1 sec
pin8.write_digital(0)
pin12.write_digital(0)
pin0.write_analog(300)
pin1.write_analog(300)
sleep(1000)

#Stop motors and clear neopixels (i.e. off)
pin0.write_analog(0)
pin1.write_analog(0)
pin8.write_digital(0)
pin12.write_digital(0)
myLightShow.clear()

# reverse at speed 350
pin8.write_digital(1)
pin12.write_digital(1)
pin0.write_analog(350)
pin1.write_analog(350)

# turn on selected neopixels and show.
myLightShow[0]= (255,0,0)
myLightShow[1]= (255,0,0)
myLightShow[2]= (255,0,0)
myLightShow[6]= (255,0,0)
myLightShow[7]= (255,0,0)
myLightShow[8]= (255,0,0)
myLightShow.show()   

When i run the program on my bit:bot, it moves forward for 1 second, as expected, then stops (as expected) but then continues to move forward again!

I have been troubleshooting this for ages and don’t know what the problem is.

Can anyone help please? Thanks

Tiny
  • 409
  • 2
  • 8
  • 20
  • What is the flow at the end of your python? Remember, there is no OS on a microbit. You should also remove the neopixel part of your example code - check it is not relevant, we don't want to see it. – Sean Houlihane Mar 02 '18 at 07:57
  • @SeanHoulihane the robot's motors continued to move forward, then pause, then forward repeatedly. (I.e. no reverse movement) – Tiny Mar 02 '18 at 12:08
  • I've edited my original program and placed a sleep(1000) command immediately after myLightShow.clear() It seems to function as expected now. I wonder why this was the issue? – Tiny Mar 02 '18 at 12:10
  • Without comments explaining the pin functions, I'd only be guessing. – Sean Houlihane Mar 02 '18 at 12:11
  • Have you had the 'bot move backwards successfully using pin8.write_digital(1) pin12.write_digital(1) ? – Oppy Mar 02 '18 at 14:06
  • @oppy yes, I tested these movements separately. The original problem is resolved when I add a sleep(1000) command to make the robot stop. Without stopping (resting for 1 second) the output is very unpredictable. I'll just have to remember to stop motors for 1sec before commencing next manoeuvre. – Tiny Mar 02 '18 at 15:08
  • Perhaps the micro:bit is resetting on the sudden motor reverse, either from a voltage spike & noise, or through a big current pull causing the supply voltage to drop too much. To test this theory have your micro:bit briefly display an image on program start. If you see it mid-run, it's resetting. If this is the case, and it's doing it on fresh batteries, I'd feed back to the developers of the robot. Perhaps they can advise you on how to add some better protective circuitry. Making your changes more gradually to motor direction and speed will improve things, as you've found. – neillb Mar 15 '18 at 00:38

1 Answers1

0

Adding a sleep(1000) command seemed to rectify the issue and now the bit:bot moves as expected.

Tiny
  • 409
  • 2
  • 8
  • 20