October 30, 2007

In holiday with Arduino

I have a 10-day holiday, and, as usual, I am in Rome during my holidays (to see my family, to take my piano lessons, etc.). Of course, I couldn't much stuff, so I just brought my Arduino and the components that came with the "Arduino workshop kit" I bought this summer on an Italian site (yep, the Arduino is make in Italy!!), i.e. LEDs, resistors, caps, pushbuttons, hook-up wires, etc. but I also brought a speaker, some sensors and servos, to have some fun with the Arrrrduino.

I actually like the Arduino platform very much, especially the C language, which isn't available with BASIC Stamps or BASIC Atoms that I use for my boe bot and lynxmotion BRAT robot. It's pretty powerful compared to the normal BS2 (although I am missing the multi-processing power of my favorite, the Parallax Propeller), since it uses an AVR ATMega168 (on the most recent boards, including the last one, the "Arduino Diecimila", which is the one I have), but there are a few inconveniences I think, like waiting at least 10 seconds each time you upload a program, and especially the lack of some coding functions that the BASIC Stamp provides, which are very useful and practical, like PULSOUT/IN, SHIFTOUT/IN, even though I think they will be coming soon, if they haven't already. Powering it through USB is very handy, since you don't have to carry around batteries, but of course, you can use any power supply with it. I miss the little breadboard that's on the Board of Education, but I will probably be getting a "protoShield" from Sparkfun as soon as I can: it's a board of the size of the Arduino itself, that you just plug in the Arduino female headers, so that you can use a tiny breadboard directly; but a good thing of it are the 6 analog input pins, and the 6 PWM output pins, which make it very easy to get input directly from an analog sensor, or anything like that.

So one of the first programs I made when I got it was getting an input from a potentiometer, that would change the output frequency of a speaker. That was pretty easy to do, even though the way I did it isn't very high level. Here is the code I used:

int buzzerPin = 10;
int inputPin = 0;
int val; 
void setup()
    pinMode(buzzerPin, OUTPUT);
void loop()
    val = analogRead(inputPin);
    digitalWrite(buzzerPin, HIGH);
    digitalWrite(buzzerPin, LOW);

A few weeks ago, I saw a MAKE magazine weekend projects podcast where I discovered the "Theremin" instrument, which I find very interesting and cool. So I thought I could do something similar, but in a different way: with distance detection. In fact I brought a Sharp GP2D12 sensor and replaced the potentiometer with it, and with the exact same code, it kinda sorta worked: if the hand is perfectly in the perpendicular plane of the sensor, then it controls the pitch, but as soon as the hand doesn't reflect perfectly the IR beam, it gets messier. And because of the non-linear behavior of this analog sensor, and of its somewhat noisy data , it's hard to play something coherent...

I'll try to post some videos soon.

Later, I thought I could try to make it change pitch by tilting an accelerometer (either the Memsic 2125 from Parallax, which I brought here with me, of maybe even with a wiimote and through serial communication with the computer!)

October 9, 2007

Wiimote controlled Lego Mindstorms NXT using MSRS

This summer, when I was at Carnegie Mellon University (CMU), for a pre-college program, I took a robotics class, in which we used these awesome $5000 robots made by NASA, called MAX, and we used Microsoft Robotics Studio (MSRS) to control them. Since they were PC-Based Robots, they had a lot of power by themselves, and MSRS enabled us to use many of the Windows APIs, like the Speech SDK, the MSN Messenger SDK and other cool stuff (we had teams of 4 people, and in my team, there was a friend whose name is Ryan, who loved making additional projects, as I did, so he spent some time doing a cool speech controlled robot, or even IM-controlled! That was pretty fun).

MSRS uses so-called 'services', which or basically libraries of reusable code, that can either define a robot's behavior (an MSRS application is a service by itself) or it can do some stuff and send back notifications and results to the top-level service (the app we are writing). There was a guy next to my room who brought a WII with him, but never used it, so I thought we could ask for a wiimote (the controller), which I knew could be used with a computer, via bluetooth, and we told him we would do something cool with it: control our robot by sensing acceleration! He liked the idea, and accepted giving it to us just to have fun.

I was the 'leader' of this project, so I started looking for some libraries on the web for the wiimote, and found the best thing ever for our purpose: a guy named Brian Peek, who wrote many articles on Coding4fun (a blog of Microsoft's), wrote a .NET wiimote library, and, the best part of it, he also make an MSRS service for it!!! That was obviously awesome, because we didn't have to write the service ourselves (we were not yet MSRS experts...). So, after the pain of getting the wiimote connected to the laptop via bluetooth, which didn't work with my drivers (I finally got to use BlueSoleil (google it), which worked well. I love it now!), I started (with Ryan next to me) to write the code to remote control MAX, following the subscriptions MSRS tutorial on MSRS website. The whole thing came pretty fast, and after testing in the simulation environment, we tried it on the real robot: it was awesome!!

Now, I don't have the MAX anymore, so I thought I would try to do the same with the Lego NXT kit. I actually got everything working fine, except the fact that the commands execute quite slowly sometimes, I'm not sure whether it's my slow laptop or the bluetooth connection, or the distance... Anyway, I'll have to change my laptop soon, because it's becoming more and more obsolete...

I'll post more info, pictures and videos when I have a better robot (the little robot I made is pretty horrible and isn't very stable (I'm quite bad at building with Lego, but I just ordered a book on amazon), so I'll probably do it with the Tribot or something else I come up with. I'll also either wait for my sister to get the camera (she left this year to London, so I don't have a camera anymore, except a DV camcorder, which has pretty bad quality...) or till I have a new camera...

I'll keep you updated!


Hi, I'm Alberto Bietti, and this is going to be my blog for tech stuff, DIY etc. like Robotics, Electronics, but also my computer stuff (programming, 3D, graphics etc.)

I am going to try to keep my work here, at least in text, and, if I get a camera sooner or later, I hope I'll be able to put some pics and videos as much as possible.

I hope you will enjoy the content of this blog, and happy reading!