Jul 16

Nintendo DS Programming

I was just learning some C++ syntax the other day and figured I should give Nintendo DS programming a go since I’ve got a flashcard and it’s always fun to see your result on an actual device instead of an emulator.

I started out with a guide on GBAtemp which, although pretty limited at the moment, gives you enough info to get some basics done. User input checking (both touchscreen and buttons) and displaying a simple message is always a fun way to get started with things. Here’s the code I wrote:

#include <nds.h>
#include <stdio.h>
 
u16 Pressed;
u16 Held;
u16 Released;
 
touchPosition TouchStructure;
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
	consoleDemoInit();
	iprintf("Hello World!\n\n");
	while(1) 
	{
		scanKeys();
		Pressed = keysDown();
		Held = keysHeld();
		Released = keysUp();
 
		touchRead(&TouchStructure);
		int xPos = TouchStructure.px;
		int yPos = TouchStructure.py;
		if(xPos > 0 || yPos > 0)
			iprintf("Position of touch is (%d, %d)\n", xPos, yPos);
 
		if(KEY_A & Pressed)
			iprintf("You pressed the A button!\n");
 
		swiWaitForVBlank();
	}
 
}

This code snippet will display a classic Hello World along with some info whether you pushed the A button or tapped the touchscreen somewhere.

It’s not much but I’ve just got started with it, let’s see how far I get!

Jun 05

Home Automation System – An engineering project (EE5)

Just as I did with our previous projects I’m going to elaborate on the ‘Engineering Experience’ project we’ve done this semester. We opted to build a home automation (Domotica) system from scratch. We, a team of 4 (clicky & clicky) electronics students at Group T University College, spent the last five months or so developing and building a system that, in theory, could be used to control and sense stuff in your house. Here’s some explanation on both hardware/electronics and software.

Hardware

The essential hardware (excluding sensors such as temperature sensors, light sensors, switches, …):

We made a ‘sandwich’ of the Uno, Ethernet and XBee shields which acts as the core, the central coordinator or access point. From here all data is received from and sent to modules around the house. Thanks to the Ethernet connection, a MySQL database is hooked up and a webinterface is able to check and control the entire system. Unfortunately the Uno only has one serial IO channel, which caused some problems in the end due to both shields being connected to that one line. We fixed most of them by software filtering but looking back it would’ve been easier if we had for example an Arduino Mega, which has 3 serial channels.

Module End Device

Module End Device

Arduino Uno - Ethernet Shield - XBee Shield stack

Uno, Ethernet & XBee Shield 

As you can see on the left, the end device “module” is something we designed ourselves. An XBee is used to send over sampling data to the Access Point and to receive commands (set a digital pin to logical 1 or 0).

You can easily attach sensors to any of the 8 available XBee pins (which can be set either to DIO or ADC).

The programming of the XBee devices is done with a tool developed by Digi called X-CTU. We started out with a serial terminal to program the XBees but quickly switched to a more user-friendly application.

X-CTU

X-CTU

This program can be used to quickly change some parameters in the XBee’s firmware. The firmware can also be easily upgraded, which is a great thing since Digi seems to release a newer version every couple of months that introduces more features for the device.

Software

XBees can either be used in transparent or API mode. For more complex actions one quickly leaves the simple transparent mode behind and uses the somewhat more complex API mode. This mode uses packets (frames) of data to send over information.

XBee API packet

XBee API packet

XBeeP

XBeeP

This was quite the challenge to be able to read the data, making sense of it and being able to use it to interpret voltages and status information. That’s why I developed a simple packet parser program in C# that quickly transforms any received data packet into human readable form. And so XBeeP was born!

We transfer data to and from the database by  letting the Arduino do PHP GET requests. Packet data is assembled and parsed on the webserver which translates it into usable information that can be shown on an interface. For ease of use we developed both a regular website and a mobile version with jQuery mobile.

Mobile Interface

Mobile Interface

Regular interface

Regular interface

User Restrictions

User Restrictions

With these bits of software, the possibilities are nearly endless, you can create cron jobs or do a check every time the Arduino fetches a page to automate things like turning on the lights when it gets dark. We’ve added a scheduler where you can set actions to be performed at a certain time. These can also be set to be repeated daily or weekly.

Some other features the webinterface has:

  • User rights management (see screenshot above)
  • Easy overview of your switches and the option to turn them on or off
  • Temperature/humidity graph
  • Motion Detection notifications

Conclusion

This was always just a proof of concept project but it turned out to be pretty usable. Of course, for a commercial project a lot more security would be added as well as the usage of “confirmation” packets a module would send to the access point to notify it has correctly received a command. Some more checksum calculations should be added as well to make sure there is no corruption of information along the way.

To conclude, if you look at Twine, which is somewhat similar I think this project is a beautiful example of home automation systems that allow a lot more interactivity between the system and its users. A funfact here is that if our project would be an actual commercial product on the market it would be cheaper than a Twine with something like $30 to $50 per module and $100-150 for the central access point.

Update: more photos of the finished product can be found at http://ee5.crombeen.be/

Sep 12

Vakantie? I kid you not!

Nu de herexamens gedaan zijn, eindelijk 2 weken tijd om de ‘todo’ lijst in te korten. De helft kon al geschrapt worden op dag 1. Gelukkig zijn er nog zoveel andere dingen die ik eigelijk nog wil doen voor het nieuwe academiejaar begint. Verder C#leren, nog 300 pagina’s te gaan, piano oefenen (en spelen met Synthesia), ooit nog eens nieuwe dingen op gitaar leren spelen, Half Life en Golden Sun 2 uitspelen, VMware installeren en er een Linux distro op zwieren, …

Kortom, meer dan genoeg dingen te doen, die nooit allemaal gaan lukken in de komende twee weken. Gelukkig trekt het weer op nix meer en is er toch niet veel anders te doen.

Een paar dagen geleden heb ik Synthesia gekocht, een soort Guitar Hero maar dan voor piano. Heel leuk om zo liedjes te leren spelen, hoewel je ze zo niet echt onthoudt. Het ‘verslavende’ er aan is toch wel de high score, proberen telkens beter te spelen dan de vorige keer, zo is ‘Do you know the Muffin man’ er al een 60tal keer door gegaan om toch maar eens een run te hebben waar er op de 104 noten lange melodie geen enkele fout zit.

Jammer van het slechte weer, joggen in de regen is vervelend.. En nu juist wanneer het maar een dikke maand meer is tot de 24u loop. Dit jaar is de doelstelling om onder de 1min40 te geraken voor 1 rondje. Vorig jaar had ik een goeie verkoudheid en was toen nog maar net begonnen met routinematig te lopen, ik ga er dus van uit dat het dit jaar toch wel een pak beter zal gaan.

On a slightly unrelated note is er eindelijk schot in de zaak gekomen bij de Netgore Development Kit. De afgelopen dagen heb ik samengewerkt met een nieuweling op het Netgore forum die competent genoeg blijkt te zijn om een deftige DevKit te kunnen afleveren. Helaas is het programmeren van SVO op een laag pitje gevallen waardoor de preview release die deze avond wordt vrij gegeven amper iets nieuw zal bevatten. Gelukkig zal, zodra de DevKit klaar is, er een grote hoop content bij komen waardoor er toch al iets meer te doen zal zijn dan op dit moment.