How To Get the Arduino Time Library up and going

I’m working on a new arduino project at the moment and for it to work, I need the arduino to be able to tell the time. 

To make this work, I decided to use the Arduino Time Library (specifically the updated Time library). I was going to use the TimeSerial sketch. I expected this would be an easy task, and indeed it did look straight forward, with nice simple functions to call up the hours (hour()), minutes (minute()) and seconds (second()).

However, despite this, I really struggled in working out what the actual time was. And I’m not sure if it was just that it was late at night, and my brain wasn’t functioning at its fullest, but I really could not find an easy guide anywhere. After lots of trial and error I worked it out, and here, for you, is the tutorial of how to flipping get the flipping Time Library to work.

Know the software to use

I didn’t get this, but you will need to use both the Arduino IDE and Processing. For some reason I thought it was the case that you use one or the other. The Arduino IDE talks to the arduino, and Processing is responsible for getting the time.

Know the programs to run

You will need to run two programs: TimeSerial (in Arduino IDE) and SyncArduinoClock (in Processing). Get these both opened in their respective software.

Image

Edit the Processing sketch

Now what’s going to happen, is Processing is kind of going to “jump start” the Arduino and give it the time at a certain time point. The arduino is capable of keeping time (if it has power) once it knows what the time is initially. So you need to get Processing talking on the right port. When I opened it, the line “public static final short portIndex = 0;” was set to 0, which is a bluetooth port. When you run it, it will try and talk to bluetooth, which wasn’t useful to me. But what was useful, was that in the terminal window at the bottom of Processing, it told me what was on each of the ports. Reading this I saw this line “[4] “/dev/tty.usbserial-A600bMH2″” and so changed the line of code to read “public static final short portIndex = 4;” so that it was now talking to the right port.

Image

Start your engines (in the correct order)

This step got me for a while, you need to start your sketches running in the correct order. If you start Processing first then Arduino complains that it can’t get to the port it wants to. So, start the TimeSerial arduino sketch, in Arduino. If you open the Serial viewer, you’ll see a message that says “Waiting for sync message”. This is because it is waiting for a message from Processing.

At this point, start the SyncArduinoClock Processing sketch. A box will hopefully appear that says “Click to send time sync”. Click it.

Image

You should now see in the Arduino serial monitor that there is a lot of weird text appearing. That is because it’s trying to count for itself, and also receiving sync messages from Processing. Go back to Processing, and stop that sketch running. And back to Arduino, and hopefully, you should be getting a nice neat print out of the date, and time every second. 

You’ll never be late for anything again.

Hope that helped someone avoid the long hours of struggle trying to understand how to get the stupid thing to work!

Tagged ,

Google Translating Numbers

I am came across a post on reddit recently (in the wonderful subreddit “mildlyinteresting“, I’d recommend it if you like your internet entertainment mild) in which someone had put some numbers into the Google Translate engine, and got some interesting results. It turns out, that when you write a list of numbers, each with a full stop after them, and tell google you’re translating from Spanish to English, that some odd things happen.

1. translates as 1., but then 2. translates and Two. (the same happens for 3./Three.) but then, and here’s where things get really mildly interesting, 4. translates as April, as do the next four months.

Image

Go home Google Translate, you’re drunk etc. The interesting thing about this is the settings that are required to make this happen. There have to be dots after every number, without them google is boring and translates the numbers to numbers. This tells us something about why google is treating “5.” as May. Google has learnt (through user feedback and various algorithms) that when there’s a dot after a number, it’s likely to be a date. BUT JUST IN SPANISH. When you set the source language to things other than Spanish, google now decides that 4. is 4. Why on earth should this be the case for just Spanish text? I do not know the answer, do you?

Other languages do produce interesting results, translating from Armenian causes semicolons and parentheses to appear all over the place (link here). Then there are those that mix and match when words or digits are used. When translated in Catalan, the first five numbers translate as “First. Two. Three. Four. 5.”. A translation in Romanian will have the first 9 numbers translated as months apart from 3.

A Belarusian translation makes all the numbers ordinal, and rather cryptically translates 3. as “The Third”. (WHAT IS SO SPECIAL ABOUT 3?!) Is this a result of Kings and Queens in Belarusian history? A quick look at the wikipedia article shows there are indeed some people who are “the third” but there are equally some “the seconds” and “the fourths” out there. Mysterious.

Image

This translation quirk highlights the fact that a single digit can represent a whole range of things, depending on context. It is only because these numbers have been taken out of context that it seems odd to us. In the date today 20.8.13, it’s obvious that 8 stands for August, and that 20 should be read as twentieth (if you’re reading the date in the UK). When we see a digit, we see a whole range of different things. And this, dear readers, is one of the reasons that studying number entry is cool and interesting and a reason to be friends with me.

Tagged ,

Controlling Number Entry Using Sifteo Cubes

As you have probably gathered, I am really interested in Number Entry. I’ve been thinking a lot about how we enter numbers – whether we think of them as a series of digits, or as full numbers. This has implications for the way we might ask people to enter numbers on an interface.

I was given an opportunity to test this out recently at the CHI+MED interface hack day. Last Friday (9/8/13) a group from CHI+MED came together at Swansea university to hack some interfaces to investigate novel number entry methods.

I got a chance to play with some Sifteo Cubes. Sifteo Cubes are fun little blocks with screens that are aware of which other blocks they are next to. This allows for some fun physical interaction, with the user picking up and moving the blocks around.

At a previous idea generation session, we came up with the idea that you might want to let a user enter numbers on the sifteo blocks using both a digit and number strategy. The difference between the two meaning that you could either control the number digit-by-digit (that is, incrementing the digit 9 in the number 659 would result in 650) or by controlling the whole number (that is incrementing the digit 9 in 659 would result in 660).

Using one Sifteo block as the “controller” and the other two as the numbers, I created a system to allow the user to enter numbers using any strategy they like. See the video for an example. You can see that they can control each block separately. When the blocks are joined, the entire number can be incremented (by placing the control block to the left or right) or just the digit can be changed (by placing the control block above or below).

Programming the Sifteo blocks was an interesting challenge. You need to program in C++ (a language I haven’t looked at for a few years) and at first, reading the example code was a bit daunting. But after a while I managed to hack it together. The really strange thing about doing this was working with images. Unlike many programs where you can directly write text (or numbers) to the screen, when programming for the Sifteo cubes you are dealing with lots of static images, and swapping them in and out as you need. Meaning in my application in the video, I have 10 different image files, one for each digit.

I enjoyed the experience of hacking and playing with the blocks. I think there are some interesting questions that could be explored using them. We will see!

Tagged , , ,

Distribution of dates

Once more, Randall (from xkcd.com) and I are on the same wavelength.

In his latest comic, he analyses the frequency of dates used throughout all of the internet. Go and look at the comic now.

In months other than September, the 11th is mentioned substantially less often than any other date. It's been that way since long before 9/11 and I have no idea why.

It is very similar to my work on the distribution of numbers and digits used to program infusion pumps. See the poster here, full journal paper, and amusing web comic to follow.

Tagged

Ocean’s Eleven-ing the Bank

In a move that will only cause me to get abuse from my colleagues, I’m about to tell you about a super fun little maths problem I’ve been working on this evening. To make it even more likely that I will be called a nerd/geek, this problem was inspired by a photo of a number pad I took a few days ago. Here is the photo, and here is the story.

This photo was taken in a bank. It was also taken with a lot of espionage skill. It’s the number pad on the back of the cashpoint. This is inside the bank, and will be used when the cash in the machine needs to be stocked. If you wanted to steal the money from the machine by going in this way, you’d need to know the PIN. Which makes the security of that PIN pretty important.

Now, I know the photo is blurry (I didn’t have time to take a decent photo else they’d have thought I was casing the joint) but you can see that some of the keys are brighter than others. This is an example of a Desire Path (which is a post I still need to write about). A desire path shows you how people really truly want to use an object. The cleaner keys show you that these are the ones getting regular use, the dirty keys are not getting pressed as much. The reason this is interesting is that I now know which numbers are used in the PIN of this entry system. Awesome.

Now this made me started thinking about the security of such a system. If you, for whatever reason, can’t avoid giving away which numbers you’ve pressed on one of these key pads, how can you make sure you’re choosing the most secure set of numbers? Just choose any four numbers and hope that the fact the person trying to crack it can’t tell which order you typed them in? Well, as it turns out, no that’s not the best strategy.

If you know that my PIN involves the numbers 1, 2, 3 and 4 then that tells you my PIN is one of 24 possible different combinations, because the order you use those numbers matters. My PIN might be 1234 or 4321 or 1243 or 2314 and so on. So choosing 4 different numbers for the PIN for this machine in the picture means a potential thief would have to guess up to 24 different combinations. Which actually, isn’t that secure.

This is where the maths comes in, what happens when the PIN involves a repeated number? In this case, only 3 of the keys on the number pad would be clean, rather than 4, as one key would be pressed twice. For instance, if the PIN was 1233, only the number 1, 2 and 3 would be clean. It may seem counter intuitive, but this approach actually increases the security of the PIN in this situation, even though it uses fewer numbers. The reason is it adds an element of uncertainty to the mix, there are now three different sets of four numbers that coud be used in the PIN. If 1, 2 and 3 are clean, the numbers in the PIN could be 1233, or 1223 or 1123. Even though there are fewer ways to arrange these numbers, because there are three is actually means that knowing the three numbers used in a four digit PIN means the thief would have to try up to 36 different combinations of numbers.

So my advice to the bank, after doing this maths is that they should pick a PIN with only three different numbers in it, not one with four. Or they should just clean the number pad, it looks kind of gross.

(The maths in the post was a series of permutation calculations, I’ve saved you from having to read them but if you’re interested I can share. Maths is cool.)

 

 

Tagged ,

Other people who think that number frequncy research is cool

Today’s xkcd comic made me oh so happy. Mainly because Randal Munroe (the comic’s creator) and I are clearly incredibly cool people who are fun to talk to at parties.

Image

As someone who never sets their alarm to a number ending in 0 or 5 (I woke up at 06:56 this morning) I can sympathise with the character in the comic. But more importantly, this is an example of number frequency information being used for humour! Yes!

It reminded me of the one other time I have seen this done. In the TV series Nathan Barley the title character extolls the virtues of his Wasp T12 Speechtool phone. Aside from built in decks and anti-shark technology, “It’s got a massive number 5 because thats the most common number.”*

Image

Now I’m not saying that this phone is the entire reason for my most recent research. But. Well. Maybe it is*?

*Almost definitely not true but hard to prove. Also look at this asterisk efficiency.

Tagged ,
Follow

Get every new post delivered to your Inbox.