Early Birds at TechDays 2014

Some of the early birds who caught my first session

Some of the early birds who caught my first session

I must admit I wasn't convinced about the plan to start the TechDays sessions at 7:45 in the morning. Particularly as to my UK body clock this meant 6:45... I wondered to myself if anyone would actually turn up. But they did. I had a very good turnout and the session turned out very well. Thanks to being such a fantastic, and wide awake, audience folks. The subject of the talk was Windows Phone 8 Bluetooth and Near Field Communications (NFC). I've put the slide deck and the sample code here. There are demos, sample code and all kinds of stuff. And around 110 slides....

In the afternoon I did my second session of the day. This was the fun hardware one. This had all kinds of scary demos, which ended up working which was nice. I had my Windows Phone devices all talking to Arduino controlled lights and stuff. You can find all the slides and demos here

At the end of the session I took a picture of the audience. Thanks for coming folks.

Plenty of Bluetooth

If you want to connect your Windows Phone to any kind of hardware I can strongly recommend the HC-06 Bluetooth adapter. I've found it to be very easy to connect to and it works "right out of the box". It plays a major part in my TechDays presentations. You just connect the devices to a power supply (from 3.3 to 6 or so volts) and then your device (usually an Arduino) can talk to the adapter over a serial connection which by default is set to 9600 baud. 

The connections to the device are only supposed to work at 3.3 volt levels but I've had no problem using the 5 volts signals that the Arduino produces. 

You can change the name of the device by sending it commands, but you can pair any number of them with a single phone and then when your program runs it will connect to the first one it finds.

You can find these devices very cheaply on places like eBay. Search for "Arduino HC-06" and you should find quite a few. If you are prepared to wait for them to arrive from China you can get them very cheaply, but beware of buying ones marked as "carriers". These are very, very cheap but they actually don't have any chips on them...

Storing Constants in Arduino Programs

Welcome to another of my "I put this into my blog because otherwise I forget how to do it and have to go onto the net and find out again" posts.....

I really like writing programs for the Arduino platform. The good news is that the devices can do a lot, but the programs themselves are actually very tiny. The bad news is that you are working in an environment where there is hardly enough of every kind of resource. Particularly memory. 

In an Arduino there are two kinds of memory. There is RAM (random access memory) which is where your program stores the variables it is working on at any given time and there is EEPROM (Electrically Erasable Programmable Read Only Memory) which is where the program code lives. When you put your program into the Arduino it is stored in the EEPROM part and runs from there. If your program creates any variables, these are stored in the much smaller RAM. 

If you want things like large look up tables (which would usually be stored in the memory of your computer) then you are heading for trouble, as you only have a strictly limited space to store data values. Fortunately you can move constant data into the program memory of the device, so that it doesn't need to be stored in the precious data space.

const byte big_lookup_table [] PROGMEM= {
      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 };

The statement above creates a big (actually not that big, but you get the picture) array of bytes that I've called big_lookup_table. I've added the modifier PROGMEM to tell the compiler I want the table to be located in program memory, not RAM. The table could be quite big (an Arduino UNO has around 28K of program memory available as I recall), you could save things like sound samples or images here if you wanted to. 

The only slight complication is that when you want to get hold of the elements in the array you can't just directly access them. Instead you have to use a macro which will do the fetching for you.

x = pgm_read_byte(&big_lookup_table[i]);

The statement above takes the element at location and fetches it into byte variable x. This also means that fetching data from program memory is a tiny bit slower than "normal" variables, but in practice you don't notice the difference. 

C4DI Hardware Meetup - With Nerf Guns

Lots of Industry

Lots of Industry

Tonight was our second hardware meetup at C4DI. I knew that things were going to go well when I arrived to find everyone had already set up and was building stuff and making it do things without us needing to do anything. Peter was in charge of the exercise tonight (you can find his lab here) and he had made really good use of the flex sensor in the SparkFun Redboard Kit to create a shooting game that you can play with Nerf guns. Which he had thoughtfully provided too....

Everyone had great fun building up the circuit, getting the software working and playing with the result. The lab was great because it shows how you can create a fully formed solution (a shooting game where you have a few seconds to hit the target three times) based on this technology. 

No Cows were harmed in the making of this game

No Cows were harmed in the making of this game

Peter had even provided a bunch of 3D printed parts that support the flex sensor target, and some cows (taken from milk cartons) to use as targets. 

Wireless works better with Wires

There is apparently a difference between seems to work, and actually working. I spent a good chunk of today finding this out. The devices you can see here are used to send wireless signals from one place to another. You put a signal into the input pin on the transmitter (the one at the top) and it emerges from the receiver.  People say they seem to work. So I thought I'd have a go with them.

The first thing I did needed to do was prove that the devices work so I wired up a couple of Arduino controllers and used the lovely VirtualWire library to waggle the wireless signals up and down and transfer data. It worked first time. Yay for me. 

I really wanted to use these devices to transmit signals to control some lights, so the next thing to do was write some code that turned the lights on when it received the appropriate commands. So I wrote that and ran it and it worked. But only once. Not so much yay.

So I built a theory that light software and the VirtualWire library were fighting over Arduino hardware and losing data as a result. And I spent a while trying isolate the usage of the signal pins that they use. And getting nowhere. 

And then I had a brainwave. I took out the wireless devices and replaced them with a piece of wire between the two Arduinos. And the program worked perfectly. Flickering lights and everything. 

Most confusing. After a bit of thought I reckon I've figured out what is happening. The receiver likes being given a nice healthy 5 volt supply. And when the program starts running it gets exactly that. But when I send the command to turn some lights on this causes the voltage to drop (taking current out of a system often causes this) and so the receiver stops working. I'm now working finding a few volts from somewhere to beef up performance.

Working with hardware devices is like this. You don't just have to get the software to behave, you also have to consider the electrical environment too. But I'm still having fun.

Get a Multimeter. Preferably with a needle...

If you are at all serious about electronics you probably need to get a multimeter. This is a thing that lets you measure electrical items of various kinds, voltage, current and resistance. I got my first one a very long time ago. In fact, they were quite expensive and I actually ended up buying the bits and putting my own box around the thing. 

Nowadays you can get them very cheaply, and they tend to be digital. They show their readings as numbers. This is fine, but I much prefer one with a needle, like the one above. With a needle it is easy to see if something has just gone up or down. With digits you have to start comparing numbers. Most of the time when I'm testing a circuit I'm really checking to see if something is there or not and I don't really need an accurate value.

I thought you couldn't get cheap multimeters with needles on them, but it turns out I was wrong. You can get the above for less than five pounds from here. So I did. It works well enough and I'm already finding it useful to have around the office.

One important note though. As you can see above the dial has settings that indicate that the meter can read up to 1,000 volts. This is true enough, but you really, and I mean really should not be poking those kinds of probes into signals at that level, on account of a mistake making you suddenly, and electrically, not alive any more. For battery voltages and things like embedded controllers its fine, and it can also measure resistance.  But for high voltages I'd suggest you look at much higher specification tools that will have better insulated cables and probes.

Arduino Fun and Games at C4DI

We had some great fun at C4DI tonight. We were all playing with Arduinos and trying to get lights flashing, make strange buzzing noises (with a little sounder that is part of the kit) and then reading buttons and reacting to input.

C4DI turns out to be a great environment to do this kind of thing. I'm really grateful to them for letting us have access to such a well set up area. It is a great place to do little sessions like this.

I think the mood of the night was best summed up by one chap who had come along to take part. We'd given him one of the loan kits to work with and at the end of the session he handed it back in again because on the strength of the evening he was going to get a device of his own.  

The next session will be on Thursday 3rd of April at the same time, same place. I'll bring along a Mars Bar for the best thing that anyone has made. The fun will start at 6:00 with setup/show and tell, and then we'll begin the practical stuff at 6:30. 

Keep an eye on the Hull Digital Meetup calendar to register for the event. If you want to have a go at the labs you can find all the notes here

Using Big Led Panels with Arduino

So last week I found these Big Led Panels at Cool Components. And today I got one working. The wiring was quite fun, pushing jumper wires into connectors.  Turns out that was the easy part though. Once I'd got the hardware connected I had to get the software working. There are a couple of libraries out there that you can just download and use. But they didn't work. 

Whenever I tried a build I got loads of messages about symbols not being present in my code. I'm not sure why, but the build process seems to search the entire library structure for include files and it found some Adafruit_GFX ones in the Robot_Control folder that caused real problems. The solution was just to remove the Robot_Control folder from the Arduino libraries folder. After that the programs built and I got some stunning displays. The picture above, even after some serious tinkerage, doesn't really do them justice. 

This is a bit better, but doesn't really capture the eye-watering brightness of the pixels. The display is quite solid, but my little Arduino Uno is going pretty much flat out just to generate the colours. There was noticeable flicker during the display updates and so I think I need something with a bit more processing grunt to get smooth animation on it.

One plan is to make a coffee table, but I've just found some 8x8 inch picture frames that I think would take a panel very nicely. So maybe I put the panels in frames and turn them into works of art. Either way, great fun is being had....

Hardware at C4DI

Robin talks radio

Robin talks radio

Tonight we had our first "proper" Hardware meetup at the C4DI. There were talks from Robin and Mike about radio hardware and one from Robert about robots. With added robot. And I stood up and waved some flashing lights around and talked about our upcoming Arduino sessions. Very, very interesting.

The first two talks, about radio communications, were amazing. It was all about the challenge of using tiny amounts of power to send signals huge distances and of designing and refining analogue circuits.

Analogue electronics has always seemed like a kind of magic to me. I'm very happy with digital signals, where things are either on or off. But analogue signals are all about signals that can take any value. The good news is that the signals obey a bunch of laws, and we can use this to build circuits that process analogue inputs in particular ways. I'm used to writing instructions for programs that tell them what to do with data that comes in. Analogue circuit design is programming with hardware. You use your maths and physics knowledge to come up with component configurations and values that should work. Then you spend ages tweaking the imperfect physical realization of your design until it does what you want.

Robin and Mike described the challenges, but also the deep satisfaction that you can get from contacting people in distant countries using hardware that you designed and made yourself. And this technology also lets you communicate when you can't get any signal bars on your shiny smartphone. 

Robert then took another hardware tack. He'd brought along a robot which contained around 34 lines of program code. Not a lot perhaps, but enough to make it navigate round the room avoiding obstacles. It even backed up slowly (with appropriate warning beeper) if things got too close for comfort. Robert did a great job of explaining how what appeared to be complex behavior was actually very simple from a programming point of view. 

Finally I got up and talked about our plans for future developments. We thought it might be fun to do some Arduino sessions getting to grips with programming the device, and I suggested that the Sparkfun RedBoard Starter kit would be a good basis for our work. Then something amazing happened, Ross Hamilton, C4DI regular and all round good egg, offered to sponsor our sessions to the tune of 10 RedBoard kits. This means that although it would be useful for you to have your own hardware, at a reasonable cost of 36 pounds each (less than the price of a video game) now you don't need to. I've set up a special part of this site  where you can sign up for more information, and I'll post any materials that we produce up there as well. 

The Configurable Joystick Project

DSC04501-Edit.jpg

Some time ago Simon and I were wondering if you could make a game based around a configurable joystick. My vision for this would be of you flying your trusty spaceship through, er,space, while evil aliens shot off parts which caused your controls to break.  You would be having to plug and re-plug the control elements while you were flying the ship and decide whether you needed a fire button or a back control on the joystick as you limped home. 

We thought it might be a fun little project and so we made it the basis of our Global Gamejam entry. I was to 3D print the case and build the electronics and Simon and crew would come up with a game based on it. 

This is not quite how it turned out. 

What happened was that number one son was consigned to soldering hell, while I failed to print boxes that were the right size to fit everything in. And then at the end, we found a fundamental flaw in the circuitry that rendered the controller mostly useless.  Although we did win a prize for the "Most Ambitious Failure". 

But I've stuck with it. Above you can see "prototype one". And tonight I got it fully working for the first time. Each control element holds a resistor network that allows the controller to decide which socket it is plugged into. The 8x8 dot matrix screen is to be used for status displays. I've got it talking to the PC rather handily now, next step is to integrate it into the gameplay, 

Great fun. 

The Squarewear Arduino

squarewear.PNG

I'm getting quite keen on the Arduino devices. While they are nowhere near as powerful or easy to program as my beloved .NET Microframework platform  they do come in a huge range of prices and configurations. 

The Squareware 2.0 device you can see here is no exception. It is really designed for use as a wearable device. It has nice big holes that can be soldered into press-studs or connected to conductive cloth. It also has an on-board rechargable battery and recharging circuitry for an off-board one too. There are temperature and light sensors along with a buzzer and I reckon it is a pretty complete package.   It also has a pair of quite beefy drivers so it can switch more current into devices like larger lights or motors. 

You can pick it up from Tindie for 23 dollars, which I think is a reasonable price. Postage is reasonable too, and mine got here in only a week or so from the 'states. 

I've not done anything with mine yet, but I'm sure I'll think of something...

Hardware Group at C4DI

WP_20140116_18_30_40_Raw__highres.jpg

Tonight we had our first meeting of the new C4DI hardware group. There seem to be lots of peple who are keen on getting to grips with hardware and embedded systems, with interest in Raspberry Pi, Arduino and Gadgeteer to name a few. I took along some toys, as had other folks. Above you can see the insides of my Tagomatic device, along with some pinball machine related shenanigans which includes using an Arduino to capture messages inside the pinball table circuitry and some coils of electro-luminescent wire. That lights up and looks really cool. 

Stay tuned for details of future events, this looks like it is going to be great fun, and it's not too late to sign up over at the meetup page for C4DI.