You are viewing outdated content for BUG. If you have a BUG Y.T. edition or 2.0 series device, please visit our updated wiki: http://wiki.buglabs.net
Getting Started with the BUGduino
From BUG Wiki
backend AND duinoServerFrontend HAVE BEEN UPDATED (THEY NOW WORK EVERY TIME). IF YOU DOWNLOADED THEM BEFORE July 22 at 1:00 PM, DOWNLOAD THEM AGAIN
Disclaimer
Misuse of the BUGduino module has the potential to damage both it and the BUGbase. Proceed at your own risk. Refer to this page for all of the exciting ways that you can destroy the BUGduino or damage the BUGbase.
Before you Begin
The things described here have only been tested on the BUG 1.4.3 kernel. If you are using a BUG 1.X and you do not have the 1.4.3 kernel, now is as good of a time as any to [http://www.bugcommunity.com/wiki/index.php/Update_your_BUG_memory_card upgrade. Additionally, you will need a SAMTEC breakout "module" in order to be able to communicate with the BUGduino over UART. This is because the first run of the BUGduino boards have a problem that prevents them from receiving serial data over UART. This is compensated for by running the UART through another port, which is accomplished using the SAMTEC breakout "modules".
Which IDE is Right for Me?
You must also choose: Eclipse IDE or Arduino IDE? If you are developing an application for the BUGduino in parallel to some other BUG application such as an OSGi service in Java, you may find the Eclipse route more convenient - you can do all of your development in one place. If your BUGduino project will largely stand alone and is not going to be developed in parallel to another BUG application, then you will likely find the Arduino IDE to be simpler (and more familiar - if you are not accustomed to Eclipse). Additionally, there are some quirks with Eclipse that prevent the Arduino environment from being fully integrated in to it, so if you are uploading an application that you have already written to the BUGduino, you will have to change a few things (mostly #including more files) to make it work properly.
Don't be too concerned if you can't decide now - you have all the way until Phase Gamma before you must decide.
Phase Alpha: Setting up AVRDUDE
Before you Begin
Above the basic requirements outlined above (and the obvious ones, like a keyboard), you will need:
- BUG 1.4.3 ONLY: The Poky SDK - (be sure to get the right one - there's a 32 bit and a 64 bit version). This is essentially a version of GCC that allows you to compile things on your x86/x64 architecture computer for a computer with an ARM processor, like the BUG. For the most part, it functions identically to GCC. See below for tips on installing this.
- The AVRDUDE sources (I did all of this with 5.10, so that's a safe bet). This allows you to actually program the BUGduino (or any Arduino, for that matter) over the serial port.
Digression: Installing the Poky SDK
- Download the Poky SDK:
- Next, unpack it:
- Install it to the right directory:
- In order for it to run correctly, you'll need to:
- As a sanity check, enter:
32-bit: cd /tmp;wget http://bugcommunity.com/development/poky_sdk/poky-eabi-glibc-i686-arm-toolchain-sdk-1.4.3.tar.bz2 64-bit: cd /tmp;wget http://bugcommunity.com/development/poky_sdk/poky-eabi-glibc-x86_64-arm-toolchain-sdk-1.4.3.tar.bz2
32-bit: tar -xjvf ./poky-eabi-glibc-i686-arm-toolchain-sdk-1.4.3.tar.bz2 64-bit: tar -xjvf ./poky-eabi-glibc-x86_64-arm-toolchain-sdk-1.4.3.tar.bz2
32-bit: cp -r ./usr / 64-bit: cp -r ./usr /
source /usr/local/poky/eabi-glibc/arm/environment-setup
It may be a good idea to add that to your ~/.bashrc file if you plan on doing a lot of cross-compiling, because otherwise you'll need to type it in every time you open a terminal window. Note that doing this may interfere with things that you are trying to compile to run on your native architecture.
arm-poky-linux-gnueabi-gcc
And you should see an error message indicating that you did not specify any input files
Digression: Installing the Angstrom SDK
Compiling and Installing AVRDUDE
With the appropriate SDK set up, compiling AVRDUDE is easy (and fun).
- Download the sources:
- Unpack the sources:
- Configure to compile with the Poky SDK. Note that if you mess up this command, it is likely that no error will be returned. You will have to enter "make clean" before trying again.
- Compile it. Gaze in awe at the mounds of compile output that it generates.
- Check to make sure that it compiled correctly:
- Send it over to the BUG
- Download avrdude.conf and send it to the BUG (this is the same one that exists inside of the Arduino IDE)
cd /tmp;wget http://nongnu.askapache.com/avrdude/avrdude-5.10.tar.gz
tar -xvf avrdude-5.10.tar.gz;cd ./avrdude-5.10
./configure --host=arm-poky-linux-gnueabi
make
file avrdude
should output:
avrdude: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.10, not stripped
scp avrdude root@[BUG IP]:/usr/bin
cd /tmp;wget [avrdude.conf location];scp avrdude.conf root@[BUG IP]:/etc
Phase Beta: Setting up the Drivers
Compiling the drivers from source is a slightly a non-trivial task because it requires you to muck around in the kernel. If you want to skip this process, you can simply download the BUGduino driver binaries here:
1.4.3: wget http://bssvn.buglabs.net/svn/!source/11385/bug/branches/mhorowitz/BUG_1.4.3/bmi_duino.ko
If you want to compile them yourself, you may want to first check out either this, for the 1.4.3 kernel
Back already? Okay.
- I'm going to assume that you've got a copy of the kernel sources now. Note that it may be a good idea to do this on a backup copy that you have because it is possible that it will cause the kernel to compile oddly (or not at all) with the makefile that is included. Now you'll want to get all of the necessary files from SVN. Note that it's a good idea to use svn export rather than SVN checkout here. Export does not copy SVN meta-data. If the SVN meta-data is present, then it will overwrite the SVN meta-data in the kernel directory, which may cause problems.
- You'll find in that directory there is another directory called "to_kernel". Copy the contents of this directory to your kernel source base directory. Some files will be overwritten - that's okay. Those files contain tables of data, and the new ones are updated to include BUGduino data.
- Now navigate to /path/to/kernel/sources/base/directory/drivers/bmi/pims/duino and execute make
- scp the resulting .ko file over to the BUG
1.4.3: svn export svn://svn.buglabs.net/bug/branches/mhorowitz/BUG_1.4.3
From within the BUG_* directory: cp -rf ./to_kernel/* /path/to/kernel/sources/base/directory
cd /path/to/kernel/sources/base/directory/drivers/bmi/pims/duino;make
scp ./bmi_duino.ko root@[BUG IP]:~
Now is as good of a time as any to test out the drivers, so get a terminal to the BUG and execute:
cd ~;insmod ./bmi_duino.ko
Ideally, a message should appear indicating success. If you do not see the message (because you are not using minicom), try executing "dmesg". Additional output messages are generated when a BUGduino module is inserted or removed.
Phase Gamma: Setting up the BUGduino server
The BUGduino server is the complement to the BUGduino Eclipse plugin or the modified Arduino IDE. It sits on the BUG and waits for data, at which point it calls AVRDUDE to program the BUGduino. It is composed of two parts: a Java program and a C shared object. The Java program calls a C function through JNI, which does all of the low-level system calls and device file manipulation. Compiling this from source is a nontrivial task. If you should choose to compile it from source, be sure that you followed at least steps 1 and 2 of Phase Beta. Otherwise, just download the following two files and skip to step 3 below:
(files will be available shortly)
- You should have earlier entered:
- In those directories, you may have noticed the presence of a to_bug folder. Let's start with the frontend:
- That's all there is to it! scp backend/libjavabugduino.so and and duinoServerFrontend/Main.class over to your BUG. Put libjavabugduino.so in /home/root and Main.class in /home/root/duinoServerFrontend (this is important). To execute, enter (on the BUG):
1.4.3: svn export svn://svn.buglabs.net/bug/branches/mhorowitz/BUG_1.4.3
1.4.3: javac -source 1.4 duinoServerFrontend/Main.java
That was easy enough. (-source 1.4 tells it to compile to an older version of Java, which 1.4.3 supports). The backend will be slightly more difficult. You will need to edit the makefile. For this to compile correctly, you will need to make sure that the two -I arguments of the makefile point to the correct directories. The first one should be the one that contains jni.h, and the second one should be the include directory of your kernel source.
1.4.3: java-cdc duinoServerFrontend.Main
Phase Delta: Setting up the IDE
Phase Delta-A: Setting up the Arduino IDE
DO NOT DO THIS IF YOU INTEND TO PROGRAM THE BUGDUINO THROUGH ECLIPSE - GO HERE INSTEAD
Setting up the Arduino IDE
By default, the Arduino IDE does not allow you to program stuff through the BUG - you will need to recompile a modified version. Don't worry - it's a lot easier than it sounds.
- Get the Arduino IDE sources (I used revision 18, but this will probably work with other revisions)
- Acquire the modified source file
- Replace the original source file in the Arduino IDE
- Compile the Arduino IDE (you may need to sudo apt-get install ant first)
- The output is in the "work" directory
svn checkout http://arduino.googlecode.com/svn/trunk/ arduino
svn export svn://svn.buglabs.net/bug/branches/mhorowitz/arduino
cp /path/to/arduino_(with_the_modified_source_file) /path/to/arduino-read-only
cd /path/to/arduino-read-only/build;ant
cd /path/to/arduino-read-only/build/[linux/windowx/macosx]/work
You'll also need to set up a configuration file. This is a temporary and somewhat inelegant way of configuring the BUGduino, and it will change soon. As of now, simply:
echo "[BUG IP] [SLOT THAT BUGDUINO IS PLUGGED IN TO INDEXED STARTING WITH 0]" > /etc/bugduinoEclipse.conf
(yes, the name is right - both use the same configuration file)
Phase Delta-B: Setting up Eclipse
DO NOT DO THIS IF YOU INTEND TO PROGRAM THE BUGDUINO THROUGH THE ARDUINO IDE - GO HERE INSTEAD
Before you Begin
You will need to download and install the following:
- Dragonfly Eclipse (just unpack it to your favorite directory and it's installed)
Installing the Eclipse Plugins
The AVR Plugin for Eclipse
Eclipse plugins are available that extend Eclipse functionality in many ways. The BUGduino plugin makes it possible to program a BUGduino from within Eclipse. It does not, however, integrate an AVR compiler in to Eclipse. This functionality is added by a pragmatically titled plugin called "The AVR Plugin for Eclipse". You can get this plugin by opening Dragonfly Eclipse and going to help -> install new software and in the "Work with" field, enter:
http://avr-eclipse.sourceforge.net/updatesite/
From CDT Optional Features, select at least "AVR Eclipse Plugin". You will not need the sources.
The BUGduino Plugin for Eclipse
You can get the BUGduino plugin from SVN:
svn co svn://svn.buglabs.net/bug/branches/mhorowitz/eclipse
Copy the file in ./eclipse/plugins to /path/to/eclipse/plugins
You'll also need to set up a configuration file. This is a temporary and somewhat inelegant way of configuring the BUGduino, and it will change soon. As of now, simply:
echo "[BUG IP] [SLOT THAT BUGDUINO IS PLUGGED IN TO INDEXED STARTING WITH 0]" > /etc/bugduinoEclipse.conf
Setting up the Arduino Enviornment in Eclipse
First off, you may need the avr-gcc compiler and libc. To get these, enter:
sudo apt-get install gcc-avr avr-libc
This does not, however, include the complete Arduino environment - none of the nifty header files or high level functions are here yet. These must be extracted from the Arduino IDE. For instructions on how to do this, see: Arduino Playground - Eclipse (ignore the part about "uploading"). Also note that your build configuration must be called "Debug" for this to work.
Programming the BUGduino Through Eclipse (simple)
- Ensure that you have set up /etc/arduinoEclipse.conf and that you are running duinoServerFrontend.Main on the BUG.
- Press the hammer button on the menu bar in Eclipse to build the project.
- Right click on the project in the Project Explorer window (on the left side of the screen) and go down to BUG-AVR and press "Send AVR Program to BUG". If all goes well, you should see a whole bunch of output on the terminal where duinoServerFrontend.Main is running.
See? It was simple.
Programming the BUGduino Through Arduino (very simple)
- Ensure that you have set up /etc/arduinoEclipse.conf and that you are running duinoServerFrontend.Main on the BUG.
- Press the "Upload" button in the Arduino IDE
See? It was very simple.
Programming the BUGduino Through the standard(not modified) Arduino IDE
- connect your sparkfun FTDI basic to your bugduino
- select your USB serial port trough tools->serial port
- select the "Arduino Duemillanove or Nano w/ ATmega 328" in tools->board
- go to file->example->basics->blink
- press the send button which looks like that
- connect a led between pb5 and led, if you're unsure how to wire it, try both ways.
- watch the led blinking
Programming the BUGduino Through AVRDUDE (complicated but worth doing once)
IF YOU ARE USING A BUG 1.4.3, YOU MUST INSTALL THE DRIVERS BEFORE YOU CAN PROGRAM THE BUGDUINO
To program the BUGduino, you'll need the Arduino IDE to compile the BUGduino program. I am going to assume that you are already familiar with the Arduino and the Arduino IDE. The gist of this process is to take the file that the Arduino IDE compiles your sketch in to and send it over to the BUG and do the programming part yourself.
- Open the Arduino IDE, load your favorite sketch that you know works (one of the example blink sketches might be a good choice here) and press the "Verify" button in the top left corner of the IDE right under the File menu.
- This is when it gets somewhat tricky. When you press "verify", the Arduino IDE compiles the file and dumps the output in a temporary directory. This directory is located in your /tmp folder and has a name along the lines of "build6693428103774218650.tmp". If there are multiple of these, you will need to find the one that contains files with the same name as the one you just compiled. In here, you will find a .hex file. Take this and scp it over to your BUG (scp [NAME].cpp.hex root@[BUG IP]:~)
- Get a terminal on the BUG (minicom, SSH, etc.) and navigate to the root home directory. If you did everything right, then you should see the [NAME].cpp.hex file there.
- If you are using the BUG 1.4.3, load the drivers (this will be less inelegant in the future).
- Plug the BUGduino in to slot 0, and plug the SAMTEC breakout "module" in to slot 2 (ensure that TX and RX are connected properly - TXD from the SAMTEC breakout goes to PD0 of the BUGduino, RXD goes to PD1 and ground goes to ground.
- Here comes the magic:
- -C/etc/avrdude.conf tells AVRDUDE to use the correct configuration file.
- -v -v -v -v tells AVRDUDE to output FOUR levels of verbosity. I bet you didn't think that was even possible.
- -pm328p tells AVRDUDE that the target is an ATmega328p - the microcontroller on the BUGduino board.
- -cstk500v1 tells AVRDUDE what programmer to use. This seems to tell it to program over UART.
- -P/dev/ttyX tells AVRDUDE which serial port to use.
- -b57600 tells AVRDUDE what baud rate to use.
- -D tells AVRDUDE to disable auto-erase of flash memory when the -U switch (the next one) is given.
- -Uflash:w:./test.cpp.hex tells AVRDUDE to perform some operation to some type of memory using some file (memory_type:operation:file). Here, we're writing the hex file to flash.
insmod bmi_duino.ko
1.4.3: avrdude -C/etc/avrdude.conf -v -v -v -v -pm328p -cstk500v1 -P/dev/ttymxc3 -b57600 -D -Uflash:w:./test.cpp.hex
Woah. What was all of that? Let's go through it:

