Kitronik sell a buggy kit for a £25 (plus £5 postage), but you can get the same motor, wheels, and a much nicer chasis for about about £7 on eBay. To make the cheap one work all you need is a motor driver board. They also sell one of those for £11.50 (its included in the buggy kit). It's a nice looking board. but you can get exactly the same functionality using a generic board which costs £1.50. The only catch is you will need a breakout board so you can hook stuff up to the microbit, (kitronik £4.50), but you'll need one of those anyway for other projects. It's also going to get a bit messy, so the Kitronik motor board is probably a good choice if you want an all in one solution, but if you've already got some motors, and a breakout then the £1.50 eBay motor driver is a great addition to your parts box.
This is the sort of board you want (eBay: Arduino motor driver). They can look a bit intimidating to hook up as theres lots of wires but they're pretty obvious.
Starting at the end, the screw terminals on the left and right are where the motors go. Just connect the two wires from the motor into a terminal pair and tighten them up. Don't worry about connecting them the right way - get it wrong and your motor runs backwards. You can either fix this in software, or just switch the wires around (in workshops the first thing I get kids to do once they've hooked up a motor is check its direction, and reverse wires if necessary so everyone's idea of forwards is the same!).
The terminal block with three wires is marked (from left to right) 12v, Gnd, 5V. Don't worry that we won't be operating at these voltages... 12v is a maximum(ish). If you're using the "yellow" motors, then they can run up to about 6v, so connect a power source/batteries of 5-6v between the left input, and to the Ground pin. The left pin provides power to the motors, but it also provides a lower voltage supply to the rest of the electronics on the board - that's what the 5V is for. If you're using a microbit DO NOT CONNECT ANYTHING ELSE TO 5V!
That's the heavyweight side hooked up - now to look at the controller side:
There are four pins on the board labeled in1-in4. (There are also a couple of pins labeled en-A and en-B butthey should have jumpers on them, and we can ignore them) - these need to be connected to four output pins on the Microbit. If you just want to control one motor you could connect them with croc-clips to D0 and D1, but i'm using the MB^5 (MicroBit Breakout Board Breakout Board) I build in the last post. It exposes pins 13-16 as a row of headers which is perfect for this. I just connected them straight across. You could connect them straight to a regular microbit breakout board - you'll just spend more time counting/checking pins. You'll also note there's also a ground connection from the boards GND pin to the 0V pin on the Microbit. DO NOT ATTEMPT TO CONNECT POWER BETWEEN THE BOARDS... you'll destroy your Microbit.
With that in place we're read to do some software:
make m1fw digital output D13
make m1bw digital output D14
when start
.forever
..set m1fw to yes
..set m1bw to no
..wait 1 secs
..set m1fw to no
..set m1bw to yes
..wait 1 secs
Here I've set up a single motor. Microbit pins 13/14 are connected to in1,in2 of the motor board, which control out1/out2 which are connected to what we'll call motor 1.
Driving a motor using two pins can be a bit confusing, but a little creative variable naming goes a long way. I've called the two output m1fw and m1bw: motor 1 forwards and backwards. So to go forwards, set m1fw to yes, and m1bw to no. To go backwards m1fw is no, and m1bw is yes. To stop you set them both to no (or set them both to yes if you want, but no make more sense).
We could do the same for motor 2, but we can be a bit more clever.
make m2fw analog output D15
make m2bw analog output D16
make speed number
when start
.forever
..set speed to sin of (timer*100)
..if speed>0
...set m2bw to 0
...set m2fw to speed
..if speed<0
...set m2fw to 0
...set m2bw to -speed
..wait 0.1 secs
If you remember when we flashed an LED we used an analog output to flash the LED very fast, and it looked like it was dimming. We can use the same trick to control the speed of our motor. Pins 15/16 are driving in3/4 on the board. I've created a variable called "speed", which I set to something between -1 and +1, which are going to represent full reverse and full forwards. I use a Sin wave just to create something interesting.
If speed is positive we want to go forwards, so set m2bw to 0, and m2fw to how fast we want to go forwards. If we're going backwards, then M2fw is 0, and m2bw to -speed (because speed is negative, so -speed is how fast we go backwards).
The "turning on and off fast" can break if we try and change the speed to often, so we add a 0.1 second delay in there just to keep things running smoothly. If I was using this in a bigger program I might write an update motor script to handle all of this and make everything a bit cleaner:
make speed number
when updateMotor
.if speed>0
..set m2bw to 0
..set m2fw to speed
.if speed<0
..set m2fw to 0
..set m2bw to -speed
when start
.forever
..set speed to sin of (timer*100)
..broadcast updateMotor
...wait 0.1 secs
If you like you can even write it as:
make m2fw analog output D15
make m2bw analog output D16
make speed number
when start
.forever
..if speed>0
...set m2bw to 0
...set m2fw to speed
..if speed<0
...set m2fw to 0
...set m2bw to -speed
..wait 0.1 secs
when start
.forever
..set speed to sin of (timer*100)
While this isn't the most efficient system it is the most "scratch-like". We've got one script updating the motor speed every 1/10th of a second, so the "main" program at the bottom can just do its thing, and set the speed it would like the motor to be running at, without worrying about how that happens.
Hopefully as the microbit ecosystem matures we'll see a whole range of cheap boards but there's a whole load out of bits on ebay already that are easy to hook up once you've got some kind of breakout.
I'm a bit confused here. Maybe you can help? The documentation I have on the micro:bit shows pins 15 & 16 as MOSI and DIO (P16) respectively. Which micro:bit pins can you use for PWM? Some references say there are two and some say there are three.
ReplyDelete13/14/15 are SPI pins (Clk/MISO/MOSI) but if you're not using SPI then you can use them as regular DI/O. Sniff only initialised SPI if you "make" an SPI device, so they're otherwise free to use. Other languages may set things up differently.
ReplyDeleteSo far PWM has worked on every pin I've tried.
Interesting that PWM works on all the pins you've tried. I'd better have a go myself! Thanks.
ReplyDeleteI forgot to say that the Kitronik motor board DOESN'T have enable pins so you can't use PWM. They told me that they might change this in a future version of the board. Stick to the cheap L298 boards.
ReplyDeleteI think because the Kitronik board's driver chip decodes its inputs you don't need an 'enable' line. You get that effect by putting both control lines low (or put them both high for brake). So if the pins it's connected to are PWM-capable then you should be able to drive PWM on the direction you want while holding the other line steady.
DeleteHow are you powering the micro:bit?
ReplyDeleteThe microbit itself is powered via USB. However the motors have a separate power supply. The MB can only supply a very small amount of power, and in any case its good practise to power motors from a separate supply to the electronics as they can generate a lot of electrical noise. Motor Driver boards also invariably are designed so you can drive the motors from a higher voltage (up to about 24v is common, but check your spec's) that the controller board (MB or Arduino), as this is more efficient.
ReplyDeleteMaking these options, like any option, means considering your options and having established strategies to cope with incidents while driving. To achieve this, https://zutobi.com/us most driving training schools seek to change the thinking style and the behavior of drivers.
ReplyDeleteThanks for the blog filled with so many information. Stopping by your blog helped me to get what I was looking for. Now my task has become as easy as ABC. Impaired Driving Lawyer
ReplyDeleteA driving test generally consists of one or two parts; the practical test, called a road test, used to assess a person's driving ability under normal operating conditions, and/or a written or oral test (theory test) to confirm a person's knowledge of driving and relevant rules and laws. ket bilietai nemokamai
ReplyDeleteI have worked in the credit industry for over 8 years. The credit repair industry is one that has been plagued with fraud and corruption. The three main credit bureaus, Experian, Equifax, and TransUnion control the destiny of many Americans who would like to make credit based purchases. Industrial Air Compressors
ReplyDeleteYou can also obtain fake drivers licence and Asian fake ID cards from online stores. Many websites will sell original Australian driver licence at cheap prices.VICTORIA FAKE DRIVER LICENCE
ReplyDeleteDriving is quite possibly the most well-known and fundamental abilities. Regardless of whether in urban communities, towns or provincial zones it is typically basic that the normal individual can drive a vehicle. Western Australia fake driver licence
ReplyDeleteIt is extremely nice to see the greatest details presented in an easy and understanding manner. Driving instructor
ReplyDeleteIn one infamous episode, a driver was tossed from her vehicle. windscreen replacement cost
ReplyDeleteHave you ever been to a city where one of the main types of transportation was via bike? Many people of all ages around the globe use a bike as their primary source of transportation because it's cheaper, environmentally-friendly, healthy and easy. When using a road bike it can also be speedier option in many cases. golden motors
ReplyDeleteAt last the candidate should breeze through the necessary driving assessment coordinated by the actualizing guidelines. Prior to stepping through the driving examination, the candidate is to take a fixed number of driving exercises from an endorsed driving school. Kentucky Fake driver's license
ReplyDeleteBeing a car dealer in Chicago has many perks. For starters, the employment outlook for those who are car dealers in Chicago is one that is steady. Automobile sales are something that may decrease during some months, however the sales even out when looked at it yearly Autohändler Oberhausen
ReplyDeleteScholastically, Brian was enduring as well. He put that as an issue of need over his driving exercises needs so frequently dropped driving exercises to do explore and other school course work. certified preowned program in Missouri & Kansas
ReplyDeleteLamborghini, or Automobili Lamborghini S.p.A. as it's officially called, produces some of the most exciting sports cars in the word. Some of the newer Lamborghini models are the Countach, the Diablo, the Gallardo and the Murcielago. Lamborghini Rental
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteA 토토사이트 can also be secure and secure.
ReplyDeleteA blend that is too lean I.e insufficient two stroke oil can harm your small scale moto's motor as the moving parts are not as expected greased up. This can make the motor seize.Adresse
ReplyDeleteAdmiring the time and effort you put into your blog and detailed information you offer!.. Honda outboard motors for sale
ReplyDelete