Posts Tagged ‘electronics’

High speed M&M sorting machine

Monday, December 22nd, 2014

M&M sorting machines are a popular project for people who like combining electronics, programming and machine building. I decided I’d try to make my own version but with a different approach to the majority of existing M&M (or Skittles / Smarties!) sorting machines out there.

Most of them send a single M&M down a chute to a simple colour sensor where the colour sensor will then take a second or two to figure out the colour. A servo motor will then rotate a chute that will direct the M&M into the correct pot.

My approach sends M&Ms down a chute to start with. But I don’t stop the M&M for colour recognition. Instead I use an iPhone to capture the colour of the M&M as it is in freefall. As it is still falling the iPhone talks to a Bluetooth module attached to an Arduino and that fires off the correct electro magnet controlled gate. This sends the M&M into the correct pot. Even though this is just a rough prototype it is reasonably fast because the colour recognition and path that the M&M takes down the chute is decided and determined whilst the M&M is moving under gravity. Here’s a video of the prototype:

mandm sorting machine front 12

Initial M&M sorting ideas

I’d been thinking about making an M&M sorter for a while as a fun project so I could play around with an Arduino. But I didn’t want to stop the M&M for colour recognition or use a servo motor to direct the M&M as these approaches seemed slow to me.

It was this video of a high speed coin counting machine that got me thinking about some kind of binary gate that would deflect the M&Ms into the correct place. What they’ve done is really cool and impressive – the coins zoom through a sensor faster than you can see, and are nudged down the correct path by a pop up nodule.

M&M dispenser

Starting from the top of the machine I had to figure out how to ‘release’ the M&Ms one by one.

I did attempt to make some kind of spinning ‘thing’ that would shoot M&Ms down a tube in the style of the coin sorter video I saw. It did kind of shoot them down the tube, but mostly it sent the M&Ms flying all around my living room. I still don’t know if I’ve found them all!

The problem here was making the M&Ms come out one at a time (they often came out in bunches), and the fact that they flew out at different angles and velocities – this would lead to them bouncing around which would make it hard to predict where they were going to go next.

mandm sorting machine dispense experiment 17

I also experimented with a cylinder that the M&Ms would go into first, and then they’d fall though the holes when the holes lined up. I realised here that the amount of torque I’d need to rotate these two tubes would be too much for my motors. Plus there was still the problem of the M&Ms falling out in twos.

mandm sorting machine dispenser experiment 18

I had more success with trying to replicate this tried and tested design adopted by a number of other successful M&M sorters. The M&Ms are in the container and they drop into the holes as the holes become empty.

mandm sorting machine dispenser experiments

The trick to success is to ensure that the height of the hole that the M&M drops into is about the same height as the M&M. This ensures that only one M&M is in the hole at a time. And then as the M&M rotates and approaches the chute it goes under a covered area (like a bridge which touches the surface of the spinning disk) which ensures that when the M&M and the hole line up only the M&M in the hole can fall down.

mandm sorting machine dispenser 10

The bridge is barely visible in the photo as it is obscured by the sides – it is right at the front and is secured into place with that screw. The piece of foam board on the left perhaps helps to encourage the M&Ms into the hole but may not be necessary. I have the dispenser angled to the back so that the M&Ms fall to the edges (I want to ensure that they all go through the sorter).

Spinning the dispensor

I initially bought a 6V 500RPM motor from Amazon, and a set of motor mounts to attach the motor to the spinning disk.

I tried to decrease the speed to something sensible using a set of gears that I got from Maplin. However with my crude setup there was so much juddering that it prevented the M&Ms from falling smoothly.

mandm sorting machine motor gears 3

So I bought a 12V 80RPM high torque motor from eBay along with a motor speed controller which allowed me to direct drive the spinning disk. It was much smoother now, and this shows that simpler is often better.

mandm sorting machine motor 14

Electro magnet gates

I’d decide to try deflecting the M&Ms down the correct chute by using electro magnets to control quick reacting gates. Electro magnets can react very fast – much faster than the slow turning of a servo.

I first bough a very small low powered electro magnet – it was useless as it was so tiny it wouldn’t have been able to move anything. So I bought a bigger 12V 2A pull magnet from eBaay. This had pulling power (and goes back to its original position when the power is off because of the spring).

My first attempt was a simple ‘pull’ gate. Here the pulling of the magnet would close the gate.

mandm sorting machine slide gate 7

I tried doing this with both the magnet on the same level as the chute (above) and also below the chute (below).

mandm sorting machine chute experiments

The problem was that the magnet only pulls 1cm, and taking the diagonal into account that does not fully close the chute. It worked a lot of the time, but sometimes an M&M would slip past the gate. As I couldn’t find electro magnets with a larger pull length (one with 2-3cm would have made all this much simpler!) I went for a ‘chop’ gate instead.

As the electro magnet pulls back the gate ‘chops’ downwards by means of 3 pivot points. This design turns the small amount of electro magnet movement into something much larger which can cover the entire width of the chute diagonally.

The difficulty is figuring out the exact shape and size of the moving parts. I didn’t have any scientific way of doing this – I just experimented. First using thin cereal box cardboard as shown in the image on the right. Then using rigid plastic sheet that I bought from a hobby shop. On the left is the final design I went for. These gates react extremely fast, and make quite a bang as the plastic hits the bottom of the chute.

mandm sorting machine electro magnet gates experiment

I had to make 5 of them and here is what they were looking like when glued (using a glue gun) onto the foam board. I added a bit of black tape (which was loose at the bottom) to slightly muffle the sound.

mandm sorting machine side electro magnet gates

Colour sorting of M&Ms

I knew that I was going to use an Arduino to control the M&M sorter so it seemed natural to buy the Arduino compatible colour sensor that most of the other projects were using. The colour sensor is in the photo on the left and is the thing that the bright white light is coming from. What I discovered though using it was that the sensor is very slow. You have to individually sample the 4 colour sensors (red, green, blue and white) and then figure out the colour. This isn’t as easy as the sensors aren’t calibrated with each other, so you need to figure out the calibration first.

mandm sorting machine side arduino bluetooth

I abandoned the colour sensor as too slow (I can see why the designs that use this sensor have to stop the M&M to figure out the colour now) and decided to use an iPhone 5S camera instead. The iPhone’s camera and CPU was fast enough to film the M&M in free fall and 1) spot that there was an M&M in the field of view and 2) figure out what colour it was. The traditional cheap colour sensors available for the Arduino wouldn’t have even been able to detect that an M&M was even there as it wizzed past in freefall.

The camera is placed a bit back from the chute to give it a wider field of view. And for efficiency it is only processing the vertical strip of pixels that make up the chute. No need to process the parts of the image that the M&M will never appear in.

I bought a Bluetooth LE module for the Arduino (shown in red above) so that the iPhone could talk to the Arduino.

To make determining the colour more simple I flattened the colour palette of the video images as they came in. I made it so the software only saw the colours of the M&Ms that I was interested in seeing (so no shadows which were a big problem!) and everything else was white. It was then simply a matter of counting the number of coloured pixels, and then if the number was above a threshold sending the Bluetooth command to the Arduino.

mandm sorting machine iphone 5

Here you can see the Bluetooth board plugged into the Arduino and wired up to the relay. Wires are then heading out of the relay to the electro magnets.

mandm sorting machine back arduino 13

Putting the M&M machine together

Once the three key problems of the 1) M&M dispenser, 2) electro magnet gates and the 3) colour recognition were solved it is just a matter of putting it all together. This involved a lot of foam board and glue from a hot glue gun.

I used a sharp hobby knife to cut the foam board, and bought a cutting compass so that I could cut neat circles for the dispenser.

As I started testing various bits together I did find a few problems.

  • The M&Ms would ricochet about as they fell down the chute, sometimes ricocheting down the wrong chute before they had reached their gate. I kind-of solved this by putting the chute at an angle so the M&Ms would be ‘encouraged’ to stay on the smooth side of the chute.
  • The electro magnets could get very hot if left on. So hot in fact they could melt the glue that was holding them in place. I had to modify the software to disengage the magnets after they’d been fired (but after the M&M had hit) rather than leaving them in the engaged position.

Here’s a side view of the assembled prototype.

mandm sorting machine side 15

And here is the front view. It differs slightly from the version in the video as I extended the M&M ‘pots’ at the bottom to store more M&Ms and I added a button to turn the motor on/off at the top as well as a speed dial for the motor.

mandm sorting machine front 12

I have a small compilation of video snippets of earlier M&M sorting experiments on YouTube.

Future improvement ideas

I think there is a lot of potential for improving on this design. I think with some improvements the speed and accuracy of the M&M sorting could be better.

  • Try to get rid of the whole iPhone / Bluetooth setup. I think to do this you could try using a Raspberry Pi with a high speed (60/120FPS) capable camera directly attached. The Pi probably has the processing power to do the image processing.
  • At the moment there are three power supplies – one for the Arduino, one for the electro magnets, and one for the motor. It would be great to get everything running off a single power supply.
  • More work on the image processing – you may have noticed I wasn’t sorting brown M&Ms. They are a pain to distinguish from orange and shadow. Obviously it can be done but it would need a bit more software work and perhaps some LED lighting on the chute to reduce the effect of the shadows.
  • 3D printing of the parts – my prototype is very rough – it would be amazing to see it as a smooth 3D printed consumer unit.

Currently the gates are in a line – this causes slight timing issues – there is less time between the camera recognising the M&M colour and the first gate needing to fire than the last gate needing to fire. NES4_Life came up with the suggestion of having all the chutes arranged in circle (like a flower) and then have the chutes move into the centre at the correct time. This would mean a fairly constant time between colour recognition and firing the electro magnet which could simplify things, especially if the speeds get higher. I did a quick test of the concept (below) and I think it has potential but I haven’t figured out exactly how to do it.

mandm sorting machine flower gate experiment 24

Some of the items I bought for the M&M machine

Here a partial list of what I bought – I’ll try to add more if I remember!

Bought and used on final prototype

  • Arduino Mega kit – comes with lots of extra components to play with.
  • Extra jumper cables
  • 8 channel relay module
  • Arduino Bluetooth Low Energy (BLE)Shield – £18.05
  • Various power supplies (which I won’t give links to as the ones I got were really dodgy ones that I’m sure weren’t properly safety tested!)
  • DC 12V 2A Push Pull Type Open Frame Solenoid Electromagnet 10mm 20N 4.4LB * 5 – ~£5 each, the ones I bough are listed on eBay not but there from the same seller but are loads of other identical ones on the site
  • 12V 80RPM motor from eBay – £6.30
  • Motor mounts – for attaching the motor to the spinning dispenser disk.
  • PWM Pulse Width DC Motor Speed Control Controller Governor 6V-28V 3A – £5.59 from eBay
  • 30cm steel ruler
  • Circle cutting compass – from any good hobby shop
  • Foamboard – lots of this!
  • Plastic sheet – white for the electro magnet gates
  • Plastic sheet – clear to cover the M&M chutes and stop the M&Ms bouncing out on their way down to their designated pot.

Bought but not used on the final prototype

Other M&M / Skittles sorting projects

Here’s a list of other M&M sorting projects that I’m aware of (in alphabetical order). It is definitely worth looking at all of them to get inspiration for your own.

Lego Mindstorms M&M Sorting Machine
Lego Mindstorms NXT – The M&M Dispencer
m&m’s sorter
m&m sorter #3, take two
M&M sorter
M&M Sorter (da Vinci’s Workshop)
Skittles Sorting Machine 3
Sorting Machine – Skittles and M&M’s

And there’s even more if you search on YouTube!

NatAmi ‘Native Amiga’ interview

Wednesday, March 23rd, 2011

Peter Kaltstein, Software Developer, talks to reviewmylife about the NatAmi project and the Amiga computer.

1. What is the NatAmi project?

NatAmi stands for Native Amiga and is a reimplementation of the former Commodore Amiga design, aiming at more performance while still keeping low level compatibility. The original concepts are strongly tied to DMA and multiple programmable special purpose chips.

natami amiga board

Thomas Hirsch started with his idea in 2003, first as an Amiga compatible disk controller that evolved into a full AGA Amiga implementation by time. His main motivation was that he wanted to have Amiga back, but also the technical challenge itself.

2. What is your role and how did you get involved?

I met Thomas first, when we were both working in a computer company in Böblingen in 2007. Seing his early prototype in action convinced me to join to help revive the Amiga.

Because of my Linux skills, I have set up the Natami server and development infrastructure – both for public and team internal usage. We use IRC, TRAC and Subversion to synchronize work. As a software developer I am looking forward to getting my Natami MX-board soon, when OS & application development can start.

3. Who are the key people involved in the project?

Thomas is the PCB and chipset designer. The 68050 is done mostly by Jens and Gunnar. Andi, Keith, Jens, and Gunnar wrote 68k testcases for it. Many team members joined and helped the project: Bartek did the graphics for the 2D demo game prototype and web banners, while Guillaume is a professional musician and contributed his own compositions for Natami. Additional members help on programming and more.

4. How was the hardware specification for NatAmi decided?

The 1st design based on 68060 originally included the CPU socket and SDRAM. Since this design would have been very expensive it evolved into a more modular concept and also switched to DDR2 memory.

Jens and Gunnar started developing a softcore 68k highend CPU, that is included into the same FPGA containing the Amiga compatible chipset. This makes the CPU-card with a physical 68060 optional.

natami amiga circuit board

5. How do you organise the work amongst yourself?

Since this is a spare time project, we organize work items in the internal side of the web forum and on IRC.

6. Are you getting any input from the original Amiga designers / programmers, or are you working everything out yourselves?

Everything is done by ourselves based on public specifications.

7. How do you go about designing the chipsets to be compatible with the original Amiga chipsets?

We can’t give a compatibility percentage yet but any game that already runs on a 68060-AGA-amiga is very likely to run also on Natami. With WHDload there is already a project improving compatibility of the old games and this project also helps the games on Natami.

8. What are the most challenging parts of creating NatAmi?

It is difficult to name only one but here are some examples: For Thomas a lot of effort was needed in adapting the Amiga chipset to make use of a pipelined DDR2 memory controller. As another example Jens spent quite some effort on an efficient CPU-cache design on the N050.

9. How is the NatAmi project financed?

Everything is financed privately. Thomas payed all the prototypes and parts he ordered for stock by himself. However the biggest sacrifices are the working hours spent. Since the journey is the reward, this makes a project possible, that otherwise would only be possible with a big investor.

10. How and when will Amiga fans be able to get hold of a usable NatAmi retail device?

Currently Thomas is ensuring that all components on the MX-board are working. Afterwards the board can be distributed first to team members and then after additional testing and driver development to the public. Please understand we can’t provide an exact date yet, but we will publish on in our news blog, when ordering can start and provide more info when the team-internal board testing starts.

11. Will Amiga fans that have old games or applications on 3½ inch floppy disks be able to use them with NatAmi?

3.5″ disk games already booted on the 1st Natami prototype and are still supported on the latest board, the Natami MX. However many will probably prefer to copy them to harddisk-images or use a compact flash onboard.

12. What do you think the retail NatAmi device will look like?

As of now the Natami MX design with its current configuration is decided to be the board that will be sold. Additionally to the LX the MX features Gigabit LAN onboard and also USBv2.

13. Why is the Amiga still relevant today?

The OS and hardware were extremely sophisticated at its time and very much superior to the x86-PC. People have different reasons for wanting Amiga back. Replacing still used Amigas with a full compatible successor can be one. Another aspect of the retro-movement might result out of the fact that current systems appear bloated and are not always fast to use, despite of having several GHz of CPU clock and lots of memory.

Since AmigaOS is very fast, light-weight and friendly to use and was so much ahead of its times, it still can be a nice niche platform not only for retro-gaming but many other tasks and to develop for. On the Amiga a programmer has low level access to the hardware which is an interesting challenge and very efficient.

14. What Amiga’s do you own, and what was your favourite Amiga?

I still own an Amiga 4000 desktop. My machine history before is A1000 and A2000. Actually every Amiga I owned was great at its time for me, but I have to admit, that up from 68060 times on, I also started using Linux and continued to use it on PowerPC.

For more information visit the website. Photos used with permission of the NatAmi team.