Monthly Archives

7 Articles

Posted by on

Sammy the Boblebot Part 3: Course Correction with an Optical Mouse

So, we have our Arduino-based robot and he goes forward backwards, left and right (part 1). And he now does so with a little control over his speed thanks to PWM (part 2).

The next problem is that his chassis isn’t exactly sophisticated and the floors he is travelling over aren’t exactly flat. His front castor gets caught easily, and his back wheels lose traction, causing him to turn left and right in an unwanted fashion. How to correct for these little bumps and skips to get him going straight forward?

Mouse Hacking

A little googling found that a number of people had tried interfacing an optical mouse with an Arduino for various reasons and this seemed like a good option. An optical mouse doesn’t rely on contact with the floor, so should be immune from bumps and skips. And it gives us exactly the type of x and y measurements we would need to do course corrections (and maybe to start mapping the room that Sammy is travelling around).

My first attempt followed the guidelines from Martijn Thé here. This involved stripping down a mouse and hooking a serial connection directly into the main camera chip and reading the x and y motion from the registers there. This seems to have worked for lots of people, but unfortunately despite my years of hoarding I couldn’t find a mouse with the right chip. The chip I did try (an OM02 if you’re interested) turned on and seemed to enter the right mode, but I just couldn’t get anything out if its registers, even with the help of the relevant data sheet.

I then discovered the PS/2 library. This allows the connection of keyboards and mice via the old-school PS/2 connector, now largely replaced by USB. Aha! Now I should be able to just plug in a mouse, run the library, and get X and Y movements from there — as well signals from the mouse’s on-board microswitches (from the buttons) and maybe even the rotary encoder (from the wheel).

I desoldered a PS/2 port from an old serial X10 MouseRemote receiver (which may come in handy down the line), and hooked up the relevant wires to the Arduino following the instructions here. I didn’t have a PS/2 optical mouse handy so I experimented with an old ball mouse. Sure enough, it worked!

I then started writing a simple function to take the input from this mouse and correct for any stray movements left or right when the robot was moving forward. This isn’t very sophisticated: it breaks a forward motion down into a series of single-unit-delay loops, making the robot inch forward and run error correction after each tiny movement. If there has been a movement of say 10 left (x=-10) it steers right until it has moved 10 units to the right, cancelling out the initial movement. I’ll need to do some work on this, as you will see later.

Not All Mice Are Created Equal

At the first opportunity I popped out to the shops to pick up a cheap optical mouse with a PS/2 port from my local PC hardware shop. I’m lucky enough to live within a few minutes of both Aria and Microdirect — perfect for those occasional cable/peripheral/hard disk needs or for full on upgrades. The mouse cost less than £4. I could have bought about five second hand ones from the Computer Fair at the weekend for the same price, but frankly I just couldn’t wait that long.

Unfortunately, it didn’t work. There was nothing wrong with the mouse, and it powered up but I got no readings.


OK, maybe that’s a little melodramatic but I was peeved to say the least.

The best diagnosis I could come up with is that not all PS/2 controllers support the ‘Remote Mode’ needed for the Arduino’s PS/2 library to work (great explanation of the PS/2 protocol here). This is a kind of debugging mode where the mouse only sends back data on request and it allows the creation of a kind of master/slave relationship between the Arduino and the mouse chip.

So, I would have to go to the Computer Fair after all. Or would I?

USB To the Rescue

When doing my initial experiments I had tried plugging in a USB optical mouse with a PS/2 converter. This hadn’t worked at all. But given my latest experience I wondered if this was an issue with the USB to PS/2 conversion or in fact the same issue as I was having now. I dug around in my box of old peripherals and found a little portable USB optical mouse. If this worked it would be ideal because it was small enough to fit between the robot’s back wheels and its front castor. Sure enough, I plugged it in, fired up the Arduino and it worked first time.


So, with a little Meccano fabrication and some tweaks to the code (I had to mount the mouse in reverse in order for the cable to fit) it was time for a test.

Function Fail

Now, testing was a mixed bag. About 60% of the time it seemed to work like a charm, with Sammy auto correcting his course along a very straight line until he hit something. But some of the time he just seemed to go off in circles. It seems to make a big difference whether he is started off on the ground and then placed down, or started with his wheels on the floor.

My suspicion is that this is a software problem and my very rudimentary correction algorithm is letting me down. There’s also the fact that the mouse is an extra couple of millimetres off the floor than normal, meaning its optics won’t be perfectly focused (the sensor is basically a camera). Over time I can try to fix both these issues and post the results here. Adding other sensors to give Sammy alternative frames of reference for location will also help. Unfortunately when I came to video the tests the morning after completing this stage, it all went horribly wrong: I couldn’t get Sammy to go straight for love nor money.

More work to be done on this issue and I will post my sketch when I have it working. But for now I’m going to jump over to the next piece: stopping him bumping into stuff. So, next: PING! Sammy gets Bat Vision using an ultrasonic rangefinder…

Posted by on

Sammy the Boblebot Part 2: A Little Self Control with PWM

So, in part 1 we (my daughter and I) made a start on our simple Arduino robot, and as you could see from the video, he lacked a certain degree of self-control.

The first thing I wanted to do was structure the code sketch a little better so that I could break the work down into chunks. I started by creating little functions for each of the main movements: forwards, backwards, turn left, turn right, spin left, spin right. These movement functions would likely evolve over time and I wanted to keep the main loop as simple and descriptive as possible. Now instead of telling the robot what to do and how long to do it for inside the main loop, you pass the period of the action to the function: go forward for n amount of time. You can find this sketch here.

Next I did a little work on Sammy’s construction. A while back I bought a stack load (technical term) of knock-off Meccano from The Works. Cost me about £15 and I got LOADS of the stuff. I has this project in mind at the time and it has come in very handy. Between a few bits of Meccano and some double-sided sticky tape, Sammy now looks a lot tidier, as you can see in the pic below.

That said, this chassis is only every meant to be for development: in the long run I hope to get him into something a little more sci-fi and anthropomorphic.

The final thing to do in this batch of developments was to apply a little more decorum to those movements. Using Pulse Width Modulation — as it sounds, a way to pulse the voltage going to the motors — it is possible to vary their speed. In the long term I will probably have the main motions accelerate slowly up to speed, but for now I was happy to have options for slow, normal, and fast modes of movement. These are set up at the start and can then be passed to any one of the motion functions. So for example, I can tell Sammy to go forward fast for n amount of time.

You can get the updated sketch with PWM here.

This is cool, and a step forward, but I still noticed a problem: every time Sammy skids or hits a bump on the floor, he strays off course. And with no sensors there’s no way to correct this. So, next: how do you tell a robot he’s going off course and get him to correct it?

Posted by on

Sammy the Boblebot Part 1: It’s Alive!

I started a new project last week with my 3yr old daughter. You could call it a belated entry into the world of physical computing — for me, not her — though I’ve been hacking hardware with varying degrees of success since I was old enough to hold a screwdriver.

Like most of my projects I expect this one to be long term — this time deliberately so. We’re building a robot and I want it to evolve as my kids grow, as a platform for teaching them about electronics and programming. Note that I let my daughter have naming rights and hence, Sammy is his name.

Today it is simply the chassis from unfinished previous project bolted to an Arduino but there is more to come. The chassis is something I’ve been hording for about a decade. It will look familiar if you remember the week by week Real Robots series. Fortunately I completed the chassis before losing patience/realising how much the finished thing would end up costing.

The chassis has an H-bridge attached to a couple of geared electric motors. The H-bridge circuit enables forward and reverse motion on the motors from its own power supply (x4 AA batteries) separate from the Arduino’s supply. Hooking this up to the pins on the Arduino was simplicity itself. At the front is a castor. Apply different speeds to the two driven wheels and the whole thing will turn.

Initial experiments focused on getting it moving — as you can see from this video*.

Not very slick and not very controlled, but it was alive and that was very, very exciting. If you like mucking around with electronics and computers or even just generally making stuff, I would highly recommend getting your hands on an Arduino and having a play. The first few steps along the path are both simple and rewarding.

I’ve posted the very, very simple sketch (the code for the Arduino) here, not that I expect it to be any use to anyone other than the fact that I have tried to include comments to make it really easy to follow.

*If you’re intrigued by the odd video proportions that’s from an iPhone 5 in portrait mode

Posted by on

Why Technology Will Have the Greatest Impact In Shaping Our Near Future

The future’s a pretty big topic. Life, the Universe and Everything big. To narrow it down I tend to focus on the next 20–30 years: bits that I will experience and a time frame into which you can interpolate current trends.

Even inside that brief window though there are many different influences to take into account. The rest of the classic PESTLE format for example: Political, Economic, Social, [Technological], Legal and Economic factors. But in our cosy corner of the Western world, these factors all have something in common: they tend to move at a slow, steady, linear pace.

It’s a long time since we’ve had a revolution in the UK (though given the current government’s penchant for bills that weren’t in either manifesto or coalition agreement, you could argue we have had a coup). Social and economic freedoms are consistently improving, with a few minor blips. Legal factors are largely driven by the political, the social and the economic.

The big global changes happening: population growth, climate change, are going to have a massive impact on our lives. Our landmass will shrink and demand for scarce resources grow. But even issues of this scale will not change our lives as much as technology in the next 20–30 years.

Because technology changes at an explosive, exponential pace.

Take Moore’s Law for example. Gordon Moore noted back in 1965 that the number of transistors on a silicon chip was doubling every two years. Incredibly this trend has continued and looks set to do so — at least after a fashion. Until now the number of transistors has been roughly proportional to the processing power of a chip. And inversely proportional to the cost of that processing power. Eventually we will have to move away from transistors on silicon as we reach the physical limits of this processing technology. But many are optimistic that whatever replaces it will continue the trend.

Now given the impact of computing on our everyday lives, it would be enough had the explosive growth and concurrent fall in cost of processing power only affected this one aspect of technology. But because of the applications of that processing power, many other fields of technology have advanced at a similarly exponential rate. For example, DNA sequencing, once the work of whole global research efforts is now a commercial service charged to consumers at a few hundred pounds.

The result is rapid advances in medicine and even the ability for us to create new, designed life. Again the rate of progress is not slowing.

If you want to know how our lives will change in the next 20–30 years then clearly there are many sources of information and influence. But technology will be the dominant factor.

Posted by on

Our World in High Definition: What Really Big Data Means for Life in the Future

“What gets measured, gets done” is a popular piece of management speak. It came to mind when I was listening to the World Service at half past four this morning*.

The thought was triggered by an interview on Click, the BBC’s technology show. It featured PressureNet, an attempt to use the barometers now featured in many Android smartphones to better map global air pressure changes.

Until now pressure data** has come from weather stations, those beige boxes you see by the roadside with an anemometer on the top and various tubes sticking out. These measure much more than pressure, but they are large and expensive units. You can only put them in so many places. Smartphones by contrast are small, cheap, readily available and widely distributed throughout the population. By pulling in data from thousands of smartphones — maybe even millions — the idea is to create a pressure map with much greater fidelity than was previously achievable.

Smartphones and sensors

There are a number of such schemes. People have talked about using the accelerometers in smartphones to measure seismic activity. GPS, Wi-Fi and cell tower locations can better map the environment and track information like traffic flow. Temperature, altitude, movement and more can all be tracked and put to good use.

It’s not just about smartphones. More and more devices are becoming connected, especially with the advent of the new ‘Weightless’ chips, designed for just this purpose. Sensors and their associated packaging are becoming cheaper, smaller and more robust. So businesses, scientists and governments are deploying more and more of them. The result? We have more data on the world around us than ever before and this trend is only going to continue. We are measuring everything. Our view of the world is increasing in resolution: we will soon be able to see almost every aspect in high definition.


Where before data was usually collected by a central authority, editorialised and disseminated, this is data in its raw form. Localised, decentralised and real-time data is becoming available for you to consume and process.

This makes it much more useful. Compare Twitter with local news, for example. Twitter is an interesting data source in its own right, and is equally localised and real-time. You might have to do your own filtering on the veracity of what is on there, as you will with other unfiltered data. But local happenings are almost always reported there hours before the news gets them, be it traffic, fires, crashes or happier events.

PressureNet offers another example of why the real-time, unfiltered data is valuable. It was designed to improve weather forecasting but it turns out that low pressure can be associated with migraines. Instead of rain users are forecasting migraines when their local pressure drops, and pre-emptively taking medication. Every data set probably has a thousand different uses like this.

What we need is open access to the data and applications to make use of it, and this is coming. Governments and other bodies are progressively opening up access to their data in ways that can be accessed by software. And in the smartphone and its supporting cloud, we have the hardware to process all this data and turn it into useful information.

Prepare to know a lot more about the world around you. To have a ‘sixth sense’ for the weather, traffic, train delays, and even whether you’re likely to get a headache.

*I listen to the World Service at odd times quite a lot now that I have two children to get me up in the night. I love it, though it’s not as relaxing as it used to be now that they have a bouncing dance beat as the theme for the news.

**Language nerds I know: data is the plural and I’m using it as a singular. But frankly it sounds better and that is increasingly common parlance. So unless anyone strongly objects I shall continue to do so.

Posted by on

Why the Drugs Don’t Work and the Market Won’t Fix Them

This winter, like most winters, I’ve been ill. As an asthmatic* I’m susceptible to every respiratory bug going. With two kids in nursery, it’s pretty much guaranteed that every bug going will find its way to me. And so, for about the fourth year in a row, I’m on antibiotics.

I hope they work as well this time as they have in the past. But they might not. And it’s even less likely they will work in the future.

Because some strains of Staphylococcus aureus, the bacterium infecting my lungs, are gathering resistance to antibiotics. Heard of MRSA? Well the ‘SA’ stands for Staphylococcus aureus.

Natural selection

The drugs we have for treating bacterial infections are becoming progressively less effective as new strains of the bacteria develop with better and broader resistance to the antibiotics we have. It’s a fascinating process that causes this: a kind of accelerated natural selection.

Some strains have always had a natural resistance to antibiotics. Sometimes a bacterium mutates, acquiring resistance. But in both cases these resistant bacteria have been dominated by the non-resistant strains being more numerous and widespread. Until we started killing those non-resistant strains with antibiotics, leaving the environment — human bodies — clear for the resistant strains to thrive.

Novelty value

Our solution to this in the past has always been to introduce new antibiotics. Ones to which the bacteria have not evolved resistance. This was always a fixed-term game but by minimising the use of these more powerful antibiotics to the cases where they were absolutely needed, we could extend their useful life. Now however there are so many cases where bacteria have proved to be resistant to first line treatment that the long term effectiveness of our second and third line treatments is under threat.

So, we have a massive pharmaceutical industry lining up the next round of big guns, right?


As this chart from the research group Extending the Cure (which I picked up from this article in Wired) shows, the number of new antibiotics in development has fallen sharply.

Market forces

I always imagined that making and selling drugs was a pretty good business to be in. If your drug can cure someone’s sickness or even alleviate the symptoms, then they’re pretty motivated to pay for it. And there are a lot of people in the world suffering some pretty common complaints that you could alleviate. Surely the volumes of antibiotics used worldwide guarantee a pretty good return on researching new ones?

It seems not. One widely accepted reason for the dearth of new drugs is that antibiotics just aren’t profitable enough. As William Schaffner, chairman of preventative medicine centre at the Vanderbilt University Medical Centre in Nashville put it in an interview with ABCNews: “If you create a new drug to reduce cholesterol, people will be taking that drug every day for the rest of their lives. But you only take antibiotics for a week or maybe 10 days.” He likened it to selling a car that could only be driven if every other vehicle wasn’t working.

Now I don’t entirely buy this analogy: if you have a fairly fixed timetable within which the other cars are going to be off the road, surely there’s reason to invest today? But the drug companies know an awful lot more about profiting from drugs than I do. However important their work is to human wellbeing, they are companies and what they are there to do is make profit for their shareholders.

Alternative models

I have no issue with capitalism as such. It has done OK at getting us to the point we’re at today. But examples like this really point out its holes. When there are no economic incentives to create drugs that save lives and alleviate suffering, you know the system is a little bit broken.

Some have suggested creating incentives for the drug companies to go back to making new antibiotics. But when you have to twist a market to serve such noble ends, perhaps the solution lies elsewhere?

And this is where I get to the future aspect of this post. In the creation of drugs, as we increasingly will in other areas crucial to human life and happiness, I think we need an alternative to the market.

When the drugs don’t work, and the market won’t fix them, it’s time to think a little differently.

*You’re now picturing the stereotype of a wheezing geek, probably with glasses. I can assure you that’s not entirely accurate.

Posted by on

I Am Not a Number (Or An Email Address): The Problem With Online Identity

I pop up on You and Yours later today talking about disposable email addresses and phone numbers. These are near-instant alternative/fake identities you can use online or off when you don’t want to give out your real details. For example, you might use a disposable email address from someone like Mailinator to sign up for a discount voucher when you don’t want the shop concerned to keep spamming you with offers. Or you might use a temporary phone number — not so widely supported in the UK yet but coming soon — when placing a classified ad, be in it on Gumtree or in your local paper. As soon as you receive your voucher or sell your item, the temporary details can be disposed of.

These disposable contact details raise an issue with the nature of our online identities. In the physical world our identities — or our names at least — are distinct from a means of contact. Just by knowing my name you can’t send me a message. In fact, owing to the number of people who might share my name (OK, not many in my case), the number of different places I might live or phone numbers I might have, without me giving up some details either directly or to a third party database, it is very difficult for you to contact me from just my name.

Online — and I’m including the mobile phone as part of being ‘online’ — the two are indistinguishable. Having an online identity usually means being contactable in some way, be it through your email address or phone number, or through the social network on which you have a username.

This is at least in part responsible for the fact that even if we don’t use these disposable services, we often have multiple online identities. A work email address and a personal email address. Work phone and personal phone. LinkedIn profile and Facebook.

But which is the ‘real’ us?

The answer doesn’t matter when it comes to signing up for voucher codes. But what about when it comes to matters of finance or law? Buying a house or getting a job? The more our lives are lived online, the more the evidence of our online lives becomes legitimate territory for our less frivolous interactions.

How does an individual or company get a feel for the ‘real’ you when you hold multiple identities? To put it another way, how does a mortgage lender decide you are a good risk or a bad risk, when most of the evidence for your life and career are online? Which version of your online identity do you want them to trust?

Lots of people have examined the problem of some sort of verified online identity — one that confirms you are you. The best we have today is some sort of aggregation: looking at the collection of profiles that may be you through services like Rapportive.

If we are to have a single, verified online identity, it will need better protection than a username and password. As Deloitte highlighted in its TMT predictions, 10,000 words cover 98.1% of all passwords, and it doesn’t take a machine long to try 10,000 options.

A single, verified identity will also need strong filtering and segmentation, so that we can define who can know what about different areas of our lives, and importantly, who can contact us. If you only have one true identity replacing email addresses, phone numbers and social profiles, you certainly don’t want it loaded with spam.

Tom Cheesewright