Monday, June 4, 2012

Raspberry Pi

A Raspberry Pi arrived late last week, just before I came away for the bank holiday. So I bought a cheap USB keyboard, checked that an old iPod power supply coupled with a Kindle cable would provide enough oomph (just about), and took the lot to my mother's. Unfortunately the keyboard (PC World Essentials) turned out to be one which won't work. Also, I can't keep coming to my mother's house every time I want access to a TV with an HDMI socket. Here's how I got access to the board via my laptop, which runs both Windows and Ubuntu Linux 12.04 - instructions are for the latter, and while I think the instructions below could be adapted for Windows they would probably be more complex. In any case, if you're going to be doing things with an ARM board running Linux, why wouldn't you also be running Linux on your other machines?

  1. Enable SSH. I paid for an SD card pre-loaded with Debian. Stick the card in the laptop, rename boot_enable_ssh.rc to boot.rc, and put the card back into the Pi before powering up.
  2. Plug the Pi into one of the ports on the back of the wireless router. Using a web browser on the laptop, go to the router's management page and look up the list of attached devices. I found that the Pi was on 192.168.0.3.
  3. Open a command prompt on the laptop, and do "ssh pi@192.168.0.3". Password is "raspberry", and you should be logged on to the Pi.
  4. Update packages: sudo apt-get update followed by sudo apt-get upgrade.
  5. Install a VNC server: sudo apt-get install tightvncserver.
  6. Run the server: tightvncserver - you'll be asked to set a password.
  7. Start a VNC server with a resolution that will fit in your monitor - I used vncserver :1 -geometry 800x600 -depth 24
  8. On the laptop, run vinagre, a VNC client, and choose to connect to 192.168.0.3:1 via VNC - the password you will be asked for is the one you set in step 6, not the password from step 3.
  9. An LXDE desktop should appear:

Friday, January 6, 2012

Lectures

"Students expect lectures", I am told. I think lectures are a rotten way to try to teach programming - it is a practical skill, and you learn (at least at the elementary level) by doing it, not by reading about it. Via the philosophy/politics blog Crooked Timber:


I already subscribe to too many podcasts, but this looks good.

As an aside, this section on teaching physics echoes some of the material on "folk psychology" I studied a couple of years ago as part of an OU philosophy course - "eliminative materialists" think our traditional analysis of mental events ("folk psychology") can be replaced with a more scientific version, just as "folk physics" has been replaced by mathematical physics (and I think Hestenes and Halloun were cited in the paper I read - I'll have to dig it out). If you ask people who haven't studied physics how weights behave in gravity, what happens if you cut a pendulum string, and other similar questions, they'll give the wrong answer. But chuck a ball at them, and they'll catch it (that's "folk physics" - being able to predict how things behave, despite lacking an underlying theory).  What reminded me of the philosophy paper was the observation that even after a course of lectures, most of the students who had in theory been taught mathematical physics were still giving the wrong answers.

Friday, December 16, 2011

A stack on the Arduino



 I have put together a collection of Python scripts which allow me to build proper C++ programs for the Arduino Uno and Mega 2560 from the command line, and upload them all in one go. At the moment, these are only working in Linux but I think I know enough now that in principle I could get this going on Windows, possibly within Dev-C++ - a project for after Christmas, I think.

Wednesday, December 14, 2011

Home Made

I used to be really, really terrible at soldering things. Thank goodness for instructional videos on YouTube. The board was programmed by the method described in the previous post.

Bypassing the IDE

A colleague has objected, justifiably, that the Arduino can't be used for teaching C/C++ as it stands because of the way the environment works (hiding the main function, and confusing issues of scope, global variables, etc).  Judging by a conversation I had this afternoon there is probably no money in the equipment budget to buy fifty of the things for next year's programming course anyway, but it would be nice to try.  There are various tutorials on the web dealing with using the avr-gcc compiler directly, mainly reliant on using modified makefiles.  The Arduino 1.0 release seems to have broken these (some of the files are now in different directories, some have disappeared), so I tried looking at the output if you ask the Arduino environment to give detailed output on compilation and upload (in File / Preferences).

Friday, December 9, 2011

Arduino classes

Underneath the Arduino programming environment is C++, but I didn't think I'd be trying to find my copy of Leendert Ammeraal's C++ for Programmers this Friday afternoon (I have Stroustrup, of course, but it's not a book to find a quick and easy solution in).  I hooked up four of the RGB LED units to the Arduino Mega's 12 PWM pins, and wanted to implement a little algorithm I had run with one unit earlier in the week - set a random "target" value for the RGB values, gradually increase (or decrease) the intensity to reach the target, and then set a new random target.  The effect is to gradually change the colour and intensity of each unit, but in a pleasant drifting manner rather than jumping around all over the place.  Once I had written the code, I looked for ways to make it simpler - first using a struct, but there are difficulties writing functions for the Arduino which take a struct as a parameter (as I understand it, the pre-processor shuffles the code around so that your function ends up before the struct declaration, which means the compiler doesn't recognise the struct when it comes to compile the function).  The answer was to go straight to writing a C++ class, which turned out to be fairly simple (though I did try writing a proper constructor function, and was reminded what a complete bloody nightmare that can be especially on a Friday afternoon in a very warm office when you haven't written any O-O C++ code for about a decade - once you start dabbling in constructors, you need to think hard about copy constructors, destructors, deep and shallow copies, all that stuff).


Arduino Mega and ethernet shield

I bought an Arduino Mega 2560 to reward myself for doing well in a philosophy module.  To connect it to the ethernet shield, the solution in the Arduino forum works - connect pins 11, 12 and 13 on the ethernet shield to 51, 50 and 52  on the Mega (in that order, of course).

Edit: the Mega sorted out the problems I'd been having with getting a web server to read off the SD card - with the Arduino Uno it kept falling over and resetting the board, with the same code on the Mega I was able to run a slow, but quite usable, server.