Nokia N810 Arduino Setup
Getting the Nokia N810 to talk to an Arduino UNO board is not a difficult task, but it’s the year 2013, and none of the now obsolete blog posts and tutorials on the Internet are quite valid anymore, primarily because the new Arduino UNO boards have dropped FTDI USB chips in favour of an open source solution: cheaper and more versatile.
So here is a little reference guide on how to hook them up. I will also be including a sample file to test drive it.
Note 1: I have added a ZIP archive with files from mixed sources. You can find the links to the original downloads and their instruction pages throughout this guide. I strongly advise you to take the time to run through those links and grab updated versions of those files where available.
Note 2: I know you know this, but just to be absolutely sure we are on the same page, all the command lines in this guide are preceded by a character, such as $ for user and # for root. These characters are there only for convenience and must not be typed in the terminal window.
Note 3: When I use the term X Terminal I mean the command line on the Nokia device, which is accessible under Utilities/X Term.
Note 4: I’m assuming the Nokia N810 Internet Tablet you are about to work on is a development tool. The steps in this guide will wipe out your device completely, so if there is data you want to stick to, YOU MUST BACK UP ALL YOUR DATA ON THE DEVICE BEFORE PROCEDING!.
0) SHOP AND DOWNLOAD: Before we start, you will want to shop for a micro-to-female USB cable or female-to-female USB adaptor, unless you want to end up at the point at which we connect the devices and you realise it’s too late and the shops are closed. I would go nuts! What these adapters do is ground a pin that is otherwise left open (read: unwired) on peripheral cables. Look for something like the pictured one.
Also, go ahead and download a ZIP archive I prepared with the files we will be putting on the device: N810_Arduino_Setup.zip.
1) FORMAT THE INTERNAL MEMORY CARD: First things first, your N810 will likely have been shipped with a bugged system image. It’s nothing serious but might cause loss of data at some point. Simply open the File Manager and click on Tools/Format Memory Card. That will update the registered specs of the internal memory card and fix the problem (as described here http://talk.maemo.org/showthread.php?t=18043).
2) GET THE FLASHER SOFTWARE: The next thing to do is get a hold of an updated Flasher executable for your computer, you can easily find one from Nokia at http://tablets-dev.nokia.com. Notice that the latest Flashers aren’t able to set usb-host-mode anymore, this is not a big concern because we will set the device to OTG mode manually (this is an automatic peripheral/host mode switching). We also needn’t set R&D mode anymore, since rootsh enables us to gain root access without it being enabled (R&D mode slows things down and causes my device to crash and restart unpredictably).
3) GET THE LATEST FIRMWARE: Download the latest firmware BIN file for your N810 (at the time of writing this is Maemo 5.2008.43-7, a.k.a. DIABLO), from the Nokia website: http://tablets-dev.nokia.com/nokia_N810.php.
4) FLASH YOUR DEVICE: using the Flasher executable on your computer, you will need to burn the latest firmware on the device (it might work with older versions, but I haven’t tried that). To do so, fill up the N810′s battery, disconnect the charger, the USB cable and switch the device off. Leave it disconnected from the computer, then launch the Flasher from your computer’s command line as such:
$ path/to/flasher --fiasco "path/to/bin/file" --flash --reboot
The command line will show something on the lines of “Suitable USB device not found, waiting“.
Now connect the device to the computer with the original USB cable, and switch it on while holding the Swap button (the top button of the two available on the front facia).
The computer should instantly start flashing the N810, it will take only a few seconds, then the device will reboot… you will need to go through the Setup Wizard again, and add your home WiFi connection. We don’t need to fetch or compile a new kernel, we can easily configure the N810 to load the necessary modules at boot (more on this later).
5) ENABLE EXTRAS REPOSITORY: Once the device has booted up again, open the Application Manager, go to Tools/Application catalog… click on maemo Extras and then Edit. You need to uncheck the Disabled checkbox.
6) INSTALL ROOTSH, OPENSSH AND PYTHON: Now you can search for rootsh and openssh (both client and server) in the Application Manager.
rootsh will let you gain root access via the following command:
$ sudo gainroot
openssh on the other hand will let you access your device via SSH (either from the device’s X Terminal, or from a computer’s command line over WiFi). The installation process will prompt you for a root password (rightly so, remember that someone might SSH into your device through the WiFi connection!).
While you’re at it, just get Python (maemo-python-device-env) on your device too. You will likely make use of it sooner or later.
7) INSTALL PERSONAL LAUNCHER, OR PERSONAL MENU: These utilities will enable you to create shortcuts (either on the home screen or in a menu) to applications, X Terminal commands and files. Believe me, these will completely change your experience with the device! Learning to use Personal Launcher is beyond the scope of this guide.
8) PREVENT THE TABLET FROM DIMMING THE SCREEN AND SLEEPING: The following commands (you will have to launch them in X Terminal) will add new options to the display settings page, so you can set screen dimming and sleep timeouts to an hour. On a side note, after having installed openssh, you can use your computer’s keyboard to type in command lines on the N810 by connecting to it like so: $ ssh email@example.com (change the IP address to whatever the device has been assigned on your WiFi network).
$ sudo gainroot # gconftool-2 -t list –list-type=int -s /system/osso/dsm/display/possible_display_blank_timeouts [30,60,120,300,600,1800,3600,0] # gconftool-2 -t list –list-type=int -s /system/osso/dsm/display/possible_display_dim_timeouts [30,60,120,300,600,1800,3600,0]
At this point you can go to the Display settings page (you can get there from clicking on the brightness icon on top of your screen) and set Brightness period and Switch off display timeouts to 60 minutes. As described in IDEO Lab’s Tips for Prototyping with the Nokia N770 Tablet.
9) INSTALL SERPROXY AND SET FLASH SECURITY: Grab the following files from the ZIP file you download at the beginning of this guide:
The serproxy.cfg file defaults to /dev/ttyACM0, which should be where your Arduino will be attached. We will check if that is the case later on.
Hook up your N810 to the computer, it will mount as a drive. Simply copy the files to it (what you see in fact is the internal memory card, they will be accessible via X Terminal at /media/mmc2).
You will need to launch these commands in X Terminal to copy the files to the right folders in the device’s internal memory, and make serproxy executable:
$ sudo gainroot # mv /media/mmc2/serproxy /home/user/MyDocs/serproxy # mv /media/mmc2/serproxy.cfg /home/user/MyDocs/serproxy # chmod 777 /home/user/MyDocs/serproxy
Now go back to the extracted ZIP archive, and grab the following file:
You will need to create a couple folders and move this file. Start again by copying the file into the N810′s internal memory card from your computer.
$ sudo gainroot # mkdir /etc/adobe # mkdir /etc/adobe/FlashPlayerTrust # mv /media/mmc2/trustPath.cfg /etc/adobe/FlashPlayerTrust
This should cover Flash and the serial port on the Nokia N810 side, as described by Ideo here.
10) FETCH AND INSTALL THE USB DRIVER: Again, grab the following folder from the ZIP file you downloaded at the beginning of this guide:
With the N810 connected to your computer via USB, copy the modules folder in it, then open X Terminal to move the files to the final location:
$ sugo gainroot # mv /media/mmc2/modules /lib
The folder contains (also) a generic USB driver that will recognise the Arduino UNO’s USB-serial chip, which has a new Vendor ID and Product ID, compared to previous boards. I have included these files in the ZIP archive for convenience, you can find the originals here: diablo-usb-drivers-1.tar.gz, along with instructions here: http://wiki.seabright.co.nz/wiki/CdcAcmAndMaemo.html.
11) TIME TO DO A FIRST TEST: Let’s find out if when we attach the Arduino board to the N810 a connection is established. At this time it’s not important what sketch is running on Arduino. Grab the micro-to-female USB cable, attach it to the N810′s original USB cable and stick the USB B male connector to the Arduino board.
Before connecting the other end to the N810, open X Terminal and type the following:
$ sudo gainroot # echo otg > /sys/devices/platform/musb_hdrc/mode # insmod /lib/modules/2.6.21-omap1/kernel/drivers/usb/class/cdc-acm.ko # insmod /lib/modules/2.6.21-omap1/kernel/drivers/usb/serial/usbserial.ko
What we are doing here is, explicitly telling the N810 to go into OTG mode (basically an automatic detection of whether it should toggle Host or Peripheral mode for USB), then we are manually loading drivers to manage the USB connection and the USB-serial conversion.
This is what we are going to add to a script to be loaded at boot time, to save us from typing in this code every time.
OK, now connect the USB cable, look at the Arduino UNO coming to life. How much do we love to watch that little LED on pin 13 blink?
The N810 should shiver a little, giving outputs like USB device not supported. Don’t worry, it’s just telling you this is not recognised as a USB memory drive. Wait a few seconds, then type the following (you will need to open a new X Terminal window, as the previous one is taken by the serproxy daemon, to check the system log for confirmation that Arduino has been attached.
$ sudo gainroot # dmesg | grep -i tty
We are starting with the least amount of data from the system log, this way you won’t go crazy looking for a specific line among hundreds of lines. The previous command should have returned something like this (the number in brackets is the seconds, and fractions, since boot up):
[14107.148437] cdc_acm 1-1:1.0: ttyACM0: USB ACM device
If you didn’t get something like this, you should try widening your search within the system log, like this:
$ sudo gainroot # dmesg | grep -i usb
Any USB-related message should appear. What you should see, is a message where the word “attached” is used, and a device name, such as ttyACM0. If that is not the case, and you find messages such as “auto-suspend” instead, then for some reason the driver hasn’t recognised your Arduino. You will have to troubleshoot it.
12) AMEND THE SERPROXY CONFIGURATION: If in the previous step the output showed you a USB device address different from ttyACM0, you need to amend the /home/user/MyDocs/serproxy.cfg file we uploaded to the device earlier. You simply need to replace ttyACM0 with whatever address has been assigned to your Arduino. You can modify the file on the fly directly from X Terminal with Vi (standard issue on Maemo 5):
$ sudo gainroot vi /home/user/MyDocs/serproxy.cfg
Explaining how to use Vi, a.k.a. Vim, is beyond the scope of this guide. It’s a really easy and versatile piece of software, just Google about it and you will be up and going in 2 minutes!
13) ADD BOOT SCRIPT: Now that we know that the USB connection works, we can add a little script to the N810′s boot sequence, to load the drivers for us. It contains the same commands we executed earlier. Grab it from the ZIP archive you downloaded at the beginning of this guide:
Again, save this file to your N810′s internal memory card from your computer via USB, then type the following commands to move it to it’s final location and add links for RC to pickup on boot:
$ sudo gainroot # mv /media/mmc2/arduino-connection /etc/init.d # chmod +x /etc/init.d/arduino-connection # cd /etc/init.d # update-rc.d arduino-connection defaults
Now reboot your device, and when the system is ready, open X Terminal again and type the following:
$ sudo gainroot # dmesg | grep -i acm
You system log buffer should output something like this:
[ 7.460937] usbcore: registered new interface driver cdc_acm [ 7.460937] /home/michaelh/src/maemo/kernel-source-diablo-2.6.21/kernel-source/drivers/usb/class/cdc-acm.c: v0.25:USB Abstract Control Model driver for USB modems and ISDN adapters
If that is the case, we successfully added the drivers to the boot sequence!
14) UPLOAD THE FLASH FILE: At this point we are finished setting the device up. You just need to upload the Flash file and launch it. Hook up the N810 to the computer one last time, and grab the following file from the ZIP archive you downloaded at the beginning of this guide:
You can leave this file on the internal memory card, so long as you know how to find it with File Manager on your device when you need to launch it.
15) UPLOAD THE ARDUINO SKETCH: Last but not least, upload the sketch provided in the ZIP archive you downloaded at the beginning of this guide:
Simply open the sketch in the Arduino IDE, connect the Arduino UNO to your computer via USB and upload as you normally do.
16) FIRE IT UP: Ok, take a break, breath, have a beer, give your best friend a call. Who am I kidding, let’s get this baby rolling, there’s always time to sleep later!
I am assuming you have reset your N810, if not, just take the battery out, then switch it on.
While the device is booting, prepare the USB cable: you need to take Arduino’s USB cable (a standard A-B USB cable, like the ones found on desktop printers) and connect it to the micro-to-female USB adaptor cable we purchased. Plug it on Arduino’s side. The provided sketch only blinks the board’s internal LED (on pin 13), so you don’t need to add anything else.
When the N810 is done booting (we know the required USB drivers have been loaded, and that the device is in OTG mode), we only need to launch the serproxy daemon (a daemon is a program that runs in the background, in other words a program that remains alive until you kill it explicitly) to manage the connection between Flash and the virtual serial port over USB:
$ sudo gain root # /home/user/MyDocs/serproxy
If everything went as it should, you should read an output trace on the lines of: Serproxy – (C)1999 Stefano Busti, (C)2005 David A. Mellis – Waiting for clients.
This means the server has loaded and is waiting for something to happen. And so let’s give it something to listen for: plug the other end of the USB cable(s) to the Nokia tablet.
Again, discard the information notices that tell us the device was not recognised.
The last step you need to do is launch the Flash file. On the N810 open the File Manager, browse to the location where you saved it. Double click on it (it will load in the default browser) and wait a couple seconds. On a side note, the N810 has a Fullscreen Toggle button on the top left side which comes in very handy. You might want to disable the toolbar first, by unchecking the option for it in: View/Show Toolbar/Fullscreen.
In the meantime the Arduino should have blinked 5 times on startup, communicating it booted correctly. On the other hand the Flash file should have become visible, and you should read the following printout:
Socket Connected Message Received from Arduino : INITIALIZING Message Received from Arduino : READY
Simply click the toggle button in Flash to see the Arduino start blinking again. The toggle will start and stop the blinking.
You’re done, it’s working! You can develop your own prototyping GUI’s from here on.
I have to credit Mike Chambers for publishing a Flash file that saved me a lot of work re-learning AS3. His file was originally designed to work on a desktop computer, using TinkerProxy to connect Flash to the serial port. I strongly advise you to fly over to his website, you will find a lot of inspiring information. And he takes some stunning photographs too!