I game, I code, I break things
Technical, constructive, fun.
Menu

Jumping Jack Lightning Flash! January 11, 2013

I take a relaxed approach to the project development I do, because I have a full time job and a home and my health to care for. This is why I dedicate at least an hour a week to the game development, to coax it into action. Over the holidays it has been a bit stagnant due to being away from the computer. So it amazes me even more as to the advancement we can do with just a small amount of time.

It's rainy jumpy man!

Here we have a moveable character, with a platform, collision, particles and, though you cannot hear it, background music.

So pleased.

Comments Off on Jumping Jack Lightning Flash!

Self Calibrating Potentiometer December 31, 2012

Update: Code edited for clarity and make sure you read pbrook‘s comment

So I have a dial connected to an Arduino, a potentiometer (pot), it’s the typical item you might use for volume or brightness control, turning it all the way up to 11. Here’s the problem though, you’re reading in the analogue values of the potentiometer and you think it goes from 0 to 1023, possibly higher if it glitches a bit (though this is dependent on how it is handled in your code).

However, what you’re controlling, only goes from 0 to 10, maybe. What do you do?

Well one idea, is that you convert it to a percentage before making the comparison, I think this is effectively ‘normalising‘ the values – statistically speaking. This is really useful. So in this code I’m doing two things, one is that I am normalising the values but the other is that I am calibrating the values that I am reading.

Why should I be calibrating? Well, this code is then portable (the mathematics could apply to anything similar, as I see it), not only that but if the ‘pot’ needs replacing, then if it is placed in the ‘maximum’ value position for a while, then it’ll be accurate (well enough so).

#include "math.h"

int sensorPin = A0;
int maxVal = 0;
float sensorValue = 0.0f;
float percentile = 0.0f;
float temp = 0.0f;

void setup() {
 Serial.begin(9600);
}

void loop() {
 sensorValue = analogRead(sensorPin);
 percentile = (sensorValue / maxVal) * 100;
 temp = fmod(percentile,10.0);
 if (temp > 0.5)
 {
     percentile += 0.5;
 }
 if (percentile > 100.4)
 {
     maxVal++;
 }
 else
 {
     Serial.println((int)percentile);
 }
}

The code utilises the C++ Math library, and rounds the value from the pot up (I think, I should probably double check it) using the function ‘fmod‘. If the pot is set at the maximum it is capable of being at, it will increase the ‘maxVal’ variable to work out the correct 100% value to calculate with.

If anyone has feedback or corrections on this, please comment!

Comments Off on Self Calibrating Potentiometer
Categories: arduino code

Weaponry makes the Perfect Gift December 21, 2012

As a member of the Hackspace it crosses a few members minds of how to use the functionality of the space with the opportunity of giving a present to someone.

A long friend of mine is a devout fanatic of the TMNT – collecting nigh everything available and it’s his 30th birthday this year near christmas. So myself and the girlfriend thought, what better than to give him something he cannot buy?

With Jo‘s talents in Fimo and the resources available to me, we decided upon figurines. However, these required weapons. With a bit of resourcefulness, soldering, patience and heavy hitting by myself and pbrook and some laser off-cuts we managed to produce something resembling the TMNT load-out:

TMNT Weapons

They have since been touched up with a bit of paint to cover the initial attempts at soldering the metal pieces together and neaten up the blades from being hammered. The ‘grips’ on the swords may be lightly painted, to retain the look formed by squishing the metal under great pressure by a vice.

I’m quite happy with the result and the ‘chain’ for the nun-chucks, made by braiding wire together.

Update: Here are the finished items:

TMNT Weapons

Comments Off on Weaponry makes the Perfect Gift

Source Control December 14, 2012

As a small team of two people it may seem a bit over complicated to introduce the practicalities of source control. Or may be what I mean is “revision control“.

I think this is the best time to do it though, because you can learn how it works, how it doesn’t work how you may think and what can go wrong. For example, for the current project we’re both working on an ActionScript v3 project in FlashDevelop, utilising BitBucket. The first stumbling block we happened upon was that, the two don’t directly integrate. It involves the use of at least three to four other applications which, handily, are compacted together into tools such as TortoiseHg and PuTTY – the former contains some hybrid of Mercurial/Git to some extent.

So after discovering that the SourceControl in FlashDevelop doesn’t appear to work beyond ‘Commit’ for the files that have changed (synchronising, especially on the fly doesn’t appear to work from the guides we have found) that having more than one person share the ‘main’ or ‘trunk’ of your project source is just not a good way to go about it:

What a mess

Simply put, partly because I lack the ability to describe what’s going on short of the Wikipedia article on source control, it turns into a mess as shown by what I will call the ‘tree’ (or headed Graph) on the left hand side.

Suffice to say, we’ve decided that to help separate development it may actually be better for us to have a main project which either one or no persons work on it directly, but they ‘fork’ it (effectively making a copy) and then commit and push to their own, with ‘builds’ of files they’ve changed, pushed to the main ‘trunk’ (or main project as I stated) which then means, there’s only merges done that make sense and people can happily mess up their own copy, while re-cloning or pulling from the trunk as required.

It’s taken a bit to get our head around, I try to think of it as a main river splitting off into streams, or a tree trunk into branches (probably the common analogy).

Comments Off on Source Control

Game Development Progress November 29, 2012

For a good, long while I’ve wanted to develop. When I was young, I wanted to create – I would sit there, feeling bored, staring at my Commodore Amiga 1200 without the internet, with little guidance and money and not knowing what or how to do things to actually produce something.

I had access to BASIC on the ZX Spectrum 48k and the Amiga, but aside from coding Pontoon and ‘POKE’ing some code into Manic Miner / Jet Set Willy but I didn’t get much further with it than that.

When I studied at University, I met some fine fellows who were on a Games Development course (and Games Design). Which re-sparked my interest in creating something, aside from doing the HND in Computing (Software Development) which almost scratched the itch, meeting these friends meant years afterwards of the words “let’s make a mod!” (mainly aimed at the game Neverwinter Nights) which, like the other intentions of creating and producing something substantial, unfortunately amounted to little.

However, I’ve tried to push on, between groups I’ve started to prototype some small scale work and today, with the work of three of us, we made it rain in Adobe Flash using ActionScript v3.

Rain

It took one persons familiarity with the API Flixel , my understanding, finding and reading of reference documentation along with the IDE and a person who has good programming knowledge to get it working and acting, like rain.

To this project myself and the other two casually dedicate only an hour a week to the development of it and other projects, but in three weeks (three hours) of work. This feels like an achievement and with that we’re so far satisfied.

Comments Off on Game Development Progress

SD Card Writing with the Minimus32 November 20, 2012

Part of a project that I am working on to measure the temperature and log it, involves writing to an SD Card (reading from it is not so important). So as part of this I purchased some items from the Proto-Pic website, one of which was an SD Card breakout board which came with, as a new person to this, I felt, next to no direct guidelines or instructions on how to wire it up. Sure, there’s schematics and the SanDisk pin-outs. However, nothing particularly clear as to what, connects, to what.

Paul Brook has on his wiki, the pin-outs for the Minimus32 which clearly shows the SPI (that’s effectively how to communicate over serial) but translating this to the break-out board was troublesome. However, after trial and error and running out of memory, I discovered the following works:

SCK /10 -> CLK

SS  /9  -> D3

MOSI/12 -> CMD

MISO/13 -> D0

The first problem I had to overcome was the fact that the Minimus32 has 1k of RAM to work with, some of which is used up by variables, ,code running, etc. This was exasperated by the fact that the library I was using to talk to the SD Card, attempting to use FAT32, was quite bulky.

Thankfully, there is an alternative, FAT16 based library that claims to take up much less memory. The difference? This means that really, I can’t write gigabytes of data to an SD Card. When all I’m doing is logging temperatures, I don’t need that much data.

This FAT16 library requires a bit of hacking to get to work with the Minimus32, it requires a profile for the AVR_AtMega32u2 else it cannot identify the chipset, this is so that it can set the aforementioned PINs properly (I think it’s in SDCard.h in the library, which you put in the sketchbook/libraries/Fat16 folder) and be able to communicate with the SD Card.

In fact, it was this library, which because it was smaller and wrote out to the Serial (monitor-able using the Arduino IDE or HyperTerm or equivalent) gave me an error code which let me work out which cable I had connected incorrectly. (I had the CMD and CD connections crossed on the break-out board).

Damn I was joyous.

Comments Off on SD Card Writing with the Minimus32

Electronics at Leeds Hackspace with Arduino and Minimus32 November 16, 2012

Update: While this version of the Arduino IDE will work, I have attempted a way of getting the latest version.

Within the past few months I picked up a new hobby, my friend Kai mentioned this place to me once before and I’ve always had an interest in electronics so off I went to the Leeds Hackspace.

To prototype electrical, let’s say, gadgets there is a device called the Arduino which with a little bit of C++ programming, some wires, LEDs, buzzers, chips, etc. You can get up and running into a large or small system to do almost whatever you want.

Typical applications involve constructing an autonomous robot to controlling laser cutters. Lasers are fun.

So along came this device, called the Minimus32 which, I’m told, was originally intended for circumventing the copy protection on the Sony Playstation 3. Turns out, however, that this little device uses the same chipset as an Arduino and can run the same code and behave in the same way, especially when it has been flashed with a new DFU Bootloader. The best part about this, is that the Minimus32 is typically about a fifth the price of the equivalent Arduino (possibly Leonardo model).

To get this to work under Linux is quite straight forward (at least within Debian and Ubuntu). You use the Arduino IDE 1.0.1 and you grab the profile information for the board from Paul Brook‘s github repositories which allow you to upload the code and monitor the serial port. It also interprets some of the default pin-outs and Paul also has a slightly re-worked OneWire library to use the internal pull-up resistor on the board.

When it comes to Windows, however, it gets a little bit tricky.

As it turns out, the latest Integrated Development Environment (IDE) for Arduino comes with an ‘avr-gcc’ compiler, which handles the compilation of the C++ code. However, in the windows bundle from the Arduino site this is grossly out of date. When this is combined with Paul’s hardware profile for the Minimus32 and a flashed Minimus, the compiler doesn’t know what to do with it.

Fortunately, I have scoured about, packaged together the IDE, a ‘sketchbook’ folder (where the hardware profiles/libraries are stored), an updated WinAVR compiler along with a recently compiled avr-gcc compiler (c/o Andy Brown). If you do not change your Arduino IDE preferences to use this sketchbook folder, you will not be able to select the minimus32 as your board (which is required).

I’m happy to say, that using the drivers supplied with the latest Arduino IDE for windows (1.0.2) along with the updated compiler and Paul’s hardware profile I’m quite happily compiling and working with the Minimus32 on windows (version 7, 64bit). Oh, and Paul’s hardware profile also include the DFU Bootloader to turn the Minimus32 into an Arduino.

Download: Arduino IDE 1.0.2 for Windows with Compiler + Paul’s Profile / Library (98mb)

Comments Off on Electronics at Leeds Hackspace with Arduino and Minimus32