Twenty years of .NET - Yay!

Blimey. Twenty years eh? The .NET framework has been part of nearly a third of my life. Highlights for me:

  • Going to amazing sessions at Cambridge University and learning all about the new framework from the people that built it.

  • Launching the first ever .NET Masters Course at Hull University and delivering a couple of modules for it, including one where we modified the razor open source .NET compiler to make broken programs and then got the students to try and debug their code with it.

  • Switching to C# as our teaching language in the department and creating the world famous (in my world) C# Yellow Book.

  • Getting into mobile development with the .NET Compact Framework and revelling in being able to create C# code for a mobile platform.

  • Exploring the XNA Framework and making the immortal “Cheese Lander” game. Running it on a Zune (because I could).

  • Putting .NET programs into teeny, tiny devices using the .NET Micro Framework.

  • Running Sliverlight and XNA in a Windows Phone on what is still the most beautiful user interface there has ever been for a mobile platform.

  • Using .NET Gadgeteer to make amazing embedded devices, even down to their circuit diagrams. All in Visual Studio with in-device debugging.

  • Using ASP.NET to create a web controlled multi-player robot fighting game for Three Thing Game.

  • Writing the first Begin to Code book for C# and building an entire UWP environment called Snaps to make it easier to make useful applications quickly.

Here’s to the next 20 years.

Return of the .NET Micro Framework (Please)

I love the .NET Micro Framework. We used it for years in our teaching of embedded systems. This year, with the robots and other components showing their age we moved onto the new fangled Arduino platform.  It's nice enough, and very popular at the moment. But I really miss being able to run (and debug) C# code inside a tiny embedded device. 

But how the Micro Framework might be roaring back. Colin Miller (the chap that wrote the foreward to the wonderful book above) recently wrote a blog post about new plans for the platform. With a bit of luck, and the rise of the Internet of Things (tm), it might be that the "little platform that could" might be returning. 

I certainly hope so. 

Final Tags of Fun Lecture of 2013

image_thumb[2]

This is the latest design for the “Tagomatic” box. Expect a smaller one for next year.

We had our last 5:15 pm lecture today. I can’t say that I’ll miss them, although this one was quite fun. I went through the exam paper for last year (you can’t get more fun than that) and gave away four owls, including a “Golden Christmas Owl” to someone who’s name I completely failed to pronounce properly. Oh well, perhaps the next version of the “Tagomatic” can have text to speech. For those that haven’t heard of it, the “Tagomatic” is a little Gageteer powered box that reads the RFID tags of folks at a lecture and then picks a random winner from the assembled multitude. I first used it for the welcome party, where we had it allocating the free drinks, and I’ve been using it in my Friday First Year lectures to make things a little more interesting.

People have seemed to engage very well with the project, bringing along their tags and scanning them for a chance to win small prizes. I even had someone get in touch asking where they can get a tag from…. Next year I’m planning to have multiple tag readers, spot prizes and Bluetooth networking back to my phone.

It almost makes me wish for another 5:15 lecture on Friday. Almost……

Secret Agent Watch Secrets at the MVP Summit

Actually there are no secrets here really. It was rather nice to go to a session and hear the presenter say “You can blog all you want about this.”. So I am doing. Chris Walker, Founder of Secret Labs had come along to tell us about the new Secret Agent watch that his company launched on Kickstarter a while back. He’d brought along some hardware samples and the latest version of the software that lets you use the accelerometer in the device via a funky new emulator. I had a play with this and one of the demos shows how to make a big font watch face.

The code is very simple, each of the letters is a gif image that is just drawn on the watch screen.

image

If you fancy having a play with this you can download the software from the Agent Watches web site.Above you can see the emulator.The hardware looks very nice. Two processors, one a low power device, ground breaking power monitoring and new display technology. Great stuff.

DSC03896.jpg

This is the watch.

DSC03907.jpg

This is the hardware inside, with the display.

Chris was telling us that there have been some delays on the hardware (this is nothing particularly surprising when you are making stuff) but that it should be available after Christmas.

Winning Prizes with Tags of Fun

design

I’ve decided to use the Tags of Fun at our 5:15 Friday lectures. Today I took along the latest incarnation, housed in an attractively designed black and white box that is just a bit too small to hold the batteries properly.

But it worked fine. Everyone who had hung on to their tags from the welcome party was able to sign in and win prizes, in this case plastic owls and some nougat from the fair. And most of the names were right too, which was nice.

I’m going to refine the design, week on week, to expand what the reader does, and maybe make a second one that will make signing up for prizes even easier.

Above you can see the Gadgeteer configuration of the device. The printer is plugged in when I need to make labels for tags, the Bluetooth lets the device talk to my Windows Phone. By Christmas it should be an amazing system. But that might be Christmas 2020……

GHI Game–O

image

Sponsoring Kickstarter projects is kind of habit forming (OK, I’ve sponsored two other ones so far). Tonight I signed up for the GHI Electronics Game-O handheld console. This is not because I’m looking for a replacement for my trusty PlayStation Vita, but because I really fancy having a handheld console that I can program using C#.

The device is powered by the .NET Micro Framework and even contains some Gadgeteer ports so that it can be interfaced to all kinds of interesting hardware. I’ve a lot of respect for the makers, GHI Electronics, they’ve made some stunning little .NET Micro Framework and Gadgeteer boards and interfaces over the years (we use a lot of their hardware in our teaching) and I’m really looking forward to having a play with the device.

The project has reached it’s funding goal, but there is still time to get in there and get hold of one of these neat devices.

Secret Agent Watch SDK now out

Secret Agent Watch

Well, the Kickstarter for the Secret Agent watch has now ended. They’ve finished up with over a million in backing. Good for them. I got my order in early, so in December I might realise another of my dreams, and have a watch I can actually program in C# and make talk to my phone.

I got quite close five years ago, when I got hold of a Microsoft Spot watch. That ran the .NET Microframework and could run C# programs, just not ones that I could write.

The Secret Agent Watch is different. The team have already released an SDK which you can download for free from their web site. This comes with an emulator so that we can begin making our programs now. With a Bluetooth link to a Windows Phone, the possibilities are very exciting.

Note: If you do download the SDK and install it you might find that the first time you try to create a new project in Visual Studio 2012 it hangs. I found that stopping Visual Studio, restarting it, opening an existing project and then making a new one sorted things out.

Now I’m really looking forward to December.

Building a Door of Mystery

IMG_6031_2_3.jpg

After a considerable amount of tweakage of designs and waiting for the printer to finish I now have my “Door of Mystery” machine complete. This is how it looks inside. I’ve added a WiFi card so that the door can upload pictures after they have been taken.

After all my careful planning the box needed a bit of surgery because I’d forgotten that power connector protrudes from the front of the board, but apart from that (and having to go and get some more bolts) it is now pretty much complete.

IMG_6067.jpg

This is the finished device. I’m going to have to slightly adjust the hole for the RFID reader in the next version, but it is quite pleasingly solid and works a treat.

You buy an RFID tag to enter the competition, show it to the “Door of Mystery” above and it will give you your entry number and take your picture. Then, I can use my special “Pick a Winner” tag to pick a random entry and even view their picture. We might even use this for bashes, where we might want to give out random prizes, pick team members or let people take it in turns to use some of the games.

Get a Scope

image

I really am a sucker for mailshots (hmm. Perhaps I shouldn’t put that in the blog). Anyhoo, I got a mailshot from Cool Components advertising the above (or actually the slightly cheaper version 2 which you don’t seem to be able to get any more). So I bought one. It is a tiny digital storage oscilloscope which costs around 80 quids or so. I reckon this is extremely good value. It has an SD card that you can use to store waveforms and the whole thing is powered by a Cortex A3 and open source, so you can even put your own firmware in there if you fancy it. It is powered from a rechargeable battery and will go up to 1 MHz which for me is fine.

If you are not sure what an oscilloscope is, it lets you “see” electrical signals. It draws a plot of the voltage in the signal as it changes over time. The original ones used a cathode ray tube that drew a single dot on the screen. The dot was moved across the screen at a regular rate by a timebase generator and the value of the voltage in the signal was used to control the height of the dot. If the signal was regular then you could take a a peek at the waveform and see what it was doing.  Newer ones are of course digital. The input voltage is converted into numbers which are then used to draw a graph on the screen.

Sometimes, when a circuit just doesn’t work you need to take a look at what is happening. A voltmeter will tell you if there is anything on the wire, but not how it is changing over time. If you have any hardware aspirations I think a little device like this is a pretty good investment, and it only costs around the same as a couple of video games.

Just the Wrong Size

IMG_6046.jpg

So today I had a go at printing out my designs. Above you can see the result. And I’d made a mistake that I’ve made before. I made the holes exactly the same size as the things intended to fit into them.

Do. Not. Do. This.

Of course they don’t fit. One thing just sits on top of the other looking exactly the same. Wah. I did think I could solve the problem by filing a bit off. Not a win.Turns out that PLA is actually quite tough stuff. After about ten fruitless minutes and quite a bit of pain (who knew you could get splinters from plastic things) I gave up and went back to the software. The good news is that I just have to tweak a couple of values and rebuild everything. I’ve even added a feature where objects can cut holes in the entire finished piece, so that the SD card and the screen can cut slots for themselves.

Ongoing.

Making Boxes with Software

BaseDesign

This is the base design I came up with. You can also see one of the Gadgeteer part designs where it will be fitted in the finished product.

I’ve been designing a box for the “Door of Mystery” Gadgeteer device that I built for the Red Nose Day event. But I’m very lazy. I don’t want to have to lay out the various elements by hand and position them individually. I want this to happen automatically. So I’ve wanted to write a program to do this. Peter likes OpenSCAD, so I went there first.  OpenSCAD lets you create 3D images programmatically. It is really easy to use, and you can preview your designs very quickly.

module panel(width, height, x, y)
{
    translate([x,y,0])
    {
         cube(size=[width, height, baseDepth]);
    }
}

I used this tiny snippet of OpenSCAD to place a panel on the drawing surface. I move the axis to the position of the panel and then create a box of the required size. You can perform unions to merge things together and differences to cut one shape from another. In no time at all I was programmatically creating bases for the Gadgeteer devices. And then I hit a brick wall. What I really wanted to do was have the program work out where each device goes in relation to the other ones and lay out the box contents.To do that my program has to keep track of where things have been put. This means that I need some variables.

OpenSCAD does not provide variables as such. It provides constants (such as baseDepth above) but these are evaluated at compile time, and so I can’t use them to keep track of things as the program runs. This is not necessarily a criticism of OpenSCAD, it isn’t really meant to run programs, but it does mean I can’t use it.

So I went back to my old friend FreeCAD. I first used this ages ago, when I made the case for my Tweet Printer. FreeCAD can be controlled by Python programs and I’ve always fancied learning a bit of Python, so of I went. The designer has a Python console into which you can paste and run lumps of code. You can also add libraries and user interfaces on top, but I was happy to cut and paste for now. All the actions you take in the designer are exposed as Python calls via the console, which makes it quite easy to figure out how to do things. You just do it in the designer and then look at what comes out on the console. There is also an API reference which tells you how the commands work.

def makeBoard(self,x,y):
    b = Part.makeBox(self.width,self.height, 5, Base.Vector(x,y,0))
    return b

This method is a member of my “Filler” class which places the filler (which has a width and a height) at a particular place on the design. Note that the filler is 5mm thick in the above code. The program can take the object that is returned and fuse or cut it with other shapes as you build up the finished design. By the end of all my fiddling I’ve got a class hierarchy of Gadgeteer device specifications and a layout engine that will place them in a box of a particular size.

def MakeTop():
    doc=FreeCAD.newDocument()
    f1 = Filler("Filler", 5,25)
    f2 = Filler("Filler", 6.5,25)
    f3 = Filler("Filler", 6.5,20)
    rfid = RFIDReader("rfid", "landscape")
    camera = Camera("camera", "landscape")
    display = DisplayT35("display", "portrait")    
    topComponents = [rfid,f1,camera,f2,display,f3]
    test = Layout(91,121,topComponents)
    board = test.layout()
    Part.show(board)
    Gui.SendMsgToActiveView("ViewFit")
    Gui.activeDocument().activeView().viewAxometric()

The MakeTop method creates the top of the box which contains an RFID reader, a touch display and a camera. These are laid out in an area with a dimension of 91x121 mm. Each component can be either “landscape” or “portrait” orientation and you can create filler elements to push things around in their row. The design method is given a list of components and an output area. The finished design looks like this:

TopDesign

These elements cut extra holes for themselves so that they show through the front of the box. The layout method also creates the sides and puts fixing holes in them, so that I can join the top and the bottom together. If I want different size of panel thicknesses I just change the static members that control these values and run the method again. If I want to make a different design I just create a new method which contains the devices that want.

The system is not completely automatic, what I end up doing is fiddling with the output from the method and then changing the orientation and adding fillers until I get what I want. The good news though is that it provides a really quick way of making Gadgeteer boxes. I’m going to have a go at printing the designs later in the week.

I find it fascinating that I’m now writing programs where the output is a physical artefact. We do live in interesting times.

TechDays 2013 Sessions Now Online

image

If you want to see a proper Gadgeteer session, not in rhyme, but with working demos and a lot more detail, then you can get hold of my TechDays session on gadget development by clicking on the above image. If you want to see all my Channel 9 sessions (including the ones on Windows Phone Agents and Windows Phone Speech) you can find them here:

http://channel9.msdn.com/Events/Speakers/Rob-Miles

Red Nose Day Door of Mystery

DSCF0363.jpg

Sometimes a good idea can take away your entire Sunday.

“The Door of Mystery” is an unique fundraising idea that takes the old style, simple, raffle idea and turns it into a new, high-tech, complicated form. To take part all you have to do is buy one of our special “Red Nose Day” tags for two pounds and then take it to “The Door of Mystery” at my office in the Robert Blackburn building to find out your entry number. Then, at the presentation on Friday we will build a “Door of Mystery” machine of our own and then use it to pick the winner of the competition. The prize, courtesy of Microsoft Research Cambridge, is a Gadgeteer kit of your own.

The tags contain an RFID chip which is read by a Gadgeteer board inside the door unit. The unit contains an SD card with a list of RFID values which are mapped to entry numbers. Show your tag to the door and it will tell you your magic number.

DSCF0373.jpg

This is the guts of the prototype device. I’ve cannibalised my Tweet Printer case to use for the project. I’m going to print a proper one later. If I get round to it.

DSCF0383.jpg

I’ve got 100 RFID tags to sell for Comic Relief. Each one has been keyed to the system and you can buy them from the departmental office. Perhaps we’ll think of other uses for them over time..

You can sponsor the whole shebang over at: http://my.rednoseday.com/sponsor/robmiles

Catching Heartbeats with the Gadgeteer

image

I reckon the Gadgeteer has more interfaces than just about any other embedded framework. Including neat things like this Pulse Oximeter from Seeed. They make the point on the product description that you should not use this as a medical instrument but, what with the theme of GlobalGameJam being heartbeats, and me having one to play with, the temptation to use it in our game was very hard to resist.

Using it is very easy indeed. You can bind to events that fire when connected (i.e. someone has put their finger into the sensor), disconnected (when someone has pulled their finger out, so to speak) and on a pulse detected event. You can also read the sensor object to find out pulse rate, blood oxygen levels and signal strength.

This is my code to bind methods to the sensor events:

pulseOximeter.ProbeAttached += 
   new PulseOximeter.ProbeAttachedHandler(pulseOximeter_ProbeAttached);
pulseOximeter.ProbeDetached += 
   new PulseOximeter.ProbeDetachedHandler(pulseOximeter_ProbeDetached);
pulseOximeter.Heartbeat += 
    new PulseOximeter.HeartbeatHandler(pulseOximeter_Heartbeat);

The handlers then do all the work:

void pulseOximeter_Heartbeat(PulseOximeter sender, 
PulseOximeter.Reading reading) { sendMessage("P" + reading.PulseRate.ToString()); }

The sendMessage method takes a string and sends it on to the game via a serial port interface that is also connected to the Gadgeteer device. The sensor has proved to be quite sensitive and works rather well. It is quite unnerving to be playing a game and find that the gameplay matches your heartbeat.

Printing LED Enclosures with Ultimaker

DSCF0325.jpg

Spent some time today doing some 3D printing with the Ultimaker. And by some time I mean quite a while.

DSCF0338.jpg
Nearly a six hour print, one of my longest so far

I’m making an enclosure for a set of Gadgeteer LED Matrix Modules from GHI. I want to combine four of them to make a 16x16 dot LED display. Once I’ve built it and got them working I’ll figure out what to do with them. I spent a while last week printing out version one of the enclosure. Rather stupidly, I made this exactly the right size, i.e. 120mm wide internally. I figured that since the units were 60mm in size each that would work fine. Not so. It made them just the right size to not fit. It is a testament to the Ultimaker printer that they would not fit either way because they were exactly the same size as the opening in the enclosure. Darn.

So it was out with FreeCad and away to design a new enclosure with an extra mm all round, so that I could actually get the units into it. I also added some support pillars that engage with the Gadgeteer boards behind each display. What I need now are some really slim nuts so that I can bolt the displays in place.

DSCF0340.jpg

This is the finished print, complete with “sprue” that I’ll have to clean off. It took me ages to prise it off the blue tape. I think I need to adjust the platform a bit to make the top layer a bit smoother although, for this build, you don’t actually see this bit.

DSCF0344.jpg

Here is the tray with the LED units fitted.

New Embedded Stuff

There are quite a few new embedded toys that I’ve discovered just recently. Here are three.

image

First up is the DAGU racer. This is a neat little Bluetooth controlled racing car. They’ve got it on discount at RoboSavvy at the moment. It comes with an Android app that you can use to control it, but they also expose the Bluetooth command set so that you can control it from anything, including Gadgeteer I reckon. It is powered by a tiny lithium ion battery and even comes with a set of stickers you can use to customise the racer. And for under twenty quid it was very tempting. So I got one.

image

I got all excited when I first found out about the Electric Imp. This is a wireless embedded device that fits into an SD card socket. You can’t actually use it as a memory card but you can use it to control a connected net appliance. And you can get it for around twenty quid. My excitement dissipated quite a lot though when I discovered that every device is bound to the imp cloud service which is where it registers its data and where messages come from.

I’ve bought these kinds of devices before, my Chumby and Nabaztag rabbit worked in a similar way. The idea of the company behind them is usually that they don’t make much money on the devices themselves, but build a subscription model which lets them pay for the infrastructure by getting cash somehow from the users of each device. Snag is, if that doesn’t work and the company goes bust you are left with a paperweight.The folks behind the imp seem quite confident that they can make it work, and the service is free at the moment. But they are talking about $50 subscriptions for business users and stuff like that, so I think I’ll pass on this, amazing as it is.

image

Now this I really do like. It brings you the best of the .NET Micro Framework, Arduino and Gadgeteer in a single board that costs less than thirty quid. You can feed it five volts and it just works. You’ve got an Arduino shield, three Gadgeteer ports, SD card, USB client and host and a space to put an Xbee or WiFi receiver. I’ve been looking at very simple devices that I’d like to make using the Gadgeteer and wanting a cheap, simple board that just gets things done. The FEZ Cerbuino Bee seems to fit that bill perfectly. For less than the price of a video game you get a device you can program with .NET, connect lots of Gadgeteer devices to and put onto WiFi at a bearable cost.

If you are learning C# and want to dip your toes into embedded development I can’t think of a better start. Lovely.

Reading your Gas Meter with Gadgeteer

IMGP0058.jpg

One of my favourite cartoons when I was a kid was a picture of a bloke in a uniform wearing the logo of the Gas Company, with a notepad and pen in his hands and looking exhausted. Someone says to him “You look tired” and he replies “So would you be if you’d just done 100 meters”.

Funny eh? Peter doesn’t want to have to wait until his gas supplier tells him how much gas he has used, he wants to know instantly the effect of having that hot bath. You can find out how he is using Gadgeteer to read meters safely by reading this.

IR Blasting

Amplified IR Led

I’m working on content for next semester at the moment. One of the modules that I deliver is a second year course called 08249 Electronics and Interfacing. In this module we get to fiddle around with robots and stuff. Last year we created a controller and a slave robot. To send commands between the two devices we were using wires link the two together.

Next time I want to use infrared instead. This has proved quite an interesting challenge. Infrared is “light you can’t see”. The wavelengths of infrared signals are outside the range of the human eye, although some cameras can see them (as you can see above), where the LED appears to be lit but to the human eye it is off. I’ve actually taken pictures in the dark using an infrared sensitive camera (most mobile phone cameras pick up IR) and “painting” with a TV remote control…

However, f you want to use infrared signals to transfer data you can’t just shine an infrared light at a receiver. This is because sunlight contains lots of infrared. The receiver would not be able to distinguish the remote data from sunshine. So remote controls use modulation to make their signal stand out from the background. Modulate means change up and down. Rather than shining continuously a TV remote flashes the control signal on and off 38.000 times a second. The receiver detects signals which are changing at that rate and ignores any others, so that it can filter out background noise. This is a bit like a sailor who can tell a flashing lighthouse lamp from the light of the moon.

If you buy an infrared receiver device it will have this demodulation behaviour built in to the hardware, which is very useful. Unfortunately you don’t get this when you buy a transmitter. An infrared LED (a light that shines with infrared light) just works as a continuous light source, and so you can’t use it directly. Fortunately the .NET Micro Framework has a number of tricks that you can use to make a modulation signal. So I connected an infrared e-block to a GHI FEZ device and got started. And I found it doesn’t seem to work very well.

The reason (as I found by using my phone camera) is that the infrared led doesn’t shine very brightly. When I took a look at the circuit I found that the IR led is connected directly to the output from the microcontroller. The microcontroller can’t produce much power, and so the light was very dim. This is the same as what would happen if you connected a big speaker to the headphone output of your phone. Because the headphone output can’t deliver much power, the sound produced would not be very loud. They’ve probably designed the circuit this way so that it is fine for short range communications, but can’t produce signals that could travel a long way and affect other devices.

I don’t care about that, I just want more power. So I took a look at the visible LED e-block. This has a transistor to amplify the signal from the FEZ controller and provide more power. I decided that it would be worth swapping the visible LED for an infrared one. So I did this. Actually this part is quite funny. I very carefully took the LEDs off the two E Blocks using a solder sucker and lots of patience, and then, equally carefully, I soldered the infrared led back onto its original board. Idiot. Fortunately I managed to unsolder it again and, as you can see above, it does work and I can send an infrared signal a reasonable distance (although I’d like to send it further).

Next step is to create some kind of message protocol to send commands to a robot. Infrared commands are not very reliable (that’s why your TV remote repeats them continuously when you hold the button down) but I reckon we should be able to send enough to tell the robot what to do. Great fun.