Getting the NIBObee library to work on Linux
I simply wrote this tutorial, because I didn’t find any NIBObee library installation tutorial for Linux. The system I am using here is Ubuntu 14.04 LTS Trusty Tahr. If you use Debian, you should get along well with this tutorial. If you have bought a NIBObee robot, you most likely got it with a CD. The only relevant folder you will need for this is ‘linux’.
Open the root directory of the CD-ROM and look at the content. You will see 5 tar archives containing 4 programs and the NIBObee library.
Now you have at least 2 options:
- Install the 4 programs
avrdude,
avr-libc,
binutils
and gcc from the tar
archives by unpacking and compiling them
- Download and installation of the programs with package management
software like
apt-get,
pacman or
yum
Out of comfortability I recommend using the second option. So type:
sudo apt-get install avrdude avr-libc binutils gcc
After you have done that, you still have some work to do. First, we need to make a project directory for our NIBObee projects.
Here we will create this folder on the desktop with:
mkdir ~/Desktop/nibobee-projects
Assuming you are using the CD, type the following commands to change into the CD-ROM directory and then copy the ‘nibobeelib’ tar file to your newly created directory:
cd /media/$USER/NIBObee/linux/
cp nibobeelib-20110603.tgz ~/Desktop/nibobee-projects/
Now, we can go back into the projects folder and extract the .tgz archive:
cd ~/Desktop/nibobee-projects
tar xvf $(ls | grep nibobeelib)
We are also stuck at another problem without even realizing it. The makers of the CD packaged the include directory for Linux differently as they did for Windows. The include directory is in fact there! But it is located in the src folder and called nibobee instead of include. But don’t worry, this problem will get solved in a few moments.
If you now check the directory, you will find the folders doc, hex, lib and src. And the .tgz file.
- doc contains documentation on the various functions of the NIBObee library. If you want to study the NIBObee library in more detail, you should definitely check it out!
- hex contains interesting precompiled .hex files which you can directly transfer to your robot
- lib contains the library files
- src contains the source code, include files, tutorial programs and much more
This is how I installed the NIBObee library:
sudo mkdir /opt/nibobeelib/
sudo mv doc hex lib src /opt/nibobeelib/
Now you have all files you need, nicely organized in the /opt/ folder
of your Linux distribution.
Let’s copy over a program from the /opt/nibobeelib/ folder and change
into it:
cp -r /opt/nibobeelib/src/tutorial/program1 .
cd program1
Try to compile the program by typing
make
.
But, what just happened? The
console now shows us:
Makefile:13: ../../config-m16-15.mk: No such file or directory
Makefile:14: ../../version.mk: No such file or directory
Makefile:114: program1.d: No such file or directory
set -e; avr-gcc -MM -Os -ffunction-sections -DAVR -I../.. -mmcu= -std=c99 -DF_CPU= -DVERSION="\"\"" -D_NIBOBEE_ program1.c \
| sed 's#\(program1\)\.o[ :]*#\1.o program1.d : #g' > program1.d ; \
[ -s program1.d ] || rm -f program1.d
avr-gcc: error: missing argument to ‘-mmcu=’
make: *** No rule to make target `../../version.mk'. Stop.
This is completely normal and I will now explain what just happened.
The Makefile in this folder uses relative paths instead of absolute
paths. As you can see, the problem occurs with the relative paths,
seen here as dots:
../../
Thus, I have modified the Makefile to take care of that problem.
Download it
here
and replace the default Makefile.
Looking at the diff file, you can see the changes:
1d0
<
6,7c5,6
< LIBDIR = ../../../lib
< HEXDIR = ../../../hex
---
> LIBDIR = /opt/nibobeelib/lib
> HEXDIR = /opt/nibobeelib/hex
9,10c8,9
< LIBDIR = ../../../lib/$(PLATFORM)
< HEXDIR = ../../../hex/$(PLATFORM)
---
> LIBDIR = /opt/nibobeelib/lib/$(PLATFORM)
> HEXDIR = /opt/nibobeelib/hex/$(PLATFORM)
13,14c12,13
< include ../../config-$(PLATFORM).mk
< include ../../version.mk
---
> include /opt/nibobeelib/src/config-$(PLATFORM).mk
> include /opt/nibobeelib/src/version.mk
19d17
<
26d23
<
28c25
< CFLAGS += -Os -ffunction-sections -DAVR -I../.. -mmcu=$(DEVICE) -std=c99
---
> CFLAGS += -Os -ffunction-sections -DAVR -I /opt/nibobeelib/src -mmcu=$(DEVICE) -std=c99
37c34
< LIBS = -lnibobee_base -lnibobee_utils
---
> LIBS = /opt/nibobeelib/lib/libnibobee_base.a /opt/nibobeelib/lib/libnibobee_utils.a
108c105
< rm -f *.d *.o *~ *.elf $(TARGET).hex $(TARGET).lss $(NIBO_OBJS)
---
> rm -f *.d *.o *~ *.elf $(TARGET).hex $(TARGET).lss $(TARGET).xhex $(NIBO_OBJS)
I changed the relative paths so that they point to our /opt/nibobeelib/ directory. Why? This way we can compile the C source code from any folder location without problems. Furthermore, I modified the ‘clean’ function to also delete .xhex files, as the default Makefile doesn’t do that. By now, you should have replaced the original Makefile with the modified version.
Alright, before we compile the program1.c program, we have to first
transfer a .hex file which calibrates the odometry sensors of the
robot.
First make a new project directory called ‘calibration’:
mkdir ~/Desktop/nibobee-projects/calibration/
Copy the hex file from the NIBObee library like so:
cp /opt/nibobeelib/hex/calibration.hex ../calibration
Now, download the script
here
and put it into the ‘calibration’ folder or copy and paste the
following code into a file called calibrate.sh,
which should be saved in the just recently mentioned folder
‘calibration’:
#!/bin/bash
HFUSE=0xd1
LFUSE=0xef
PROGRAMMER=usbasp
TARGET=calibration
printf '\E[31m'"\033[1mFlashing calibration program in 3 seconds\n\033[0m"
sleep 3
sudo avrdude -c $PROGRAMMER -p m16 -B 10 -U lfuse:w:$LFUSE:m -U hfuse:w:$HFUSE:m
sudo avrdude -c $PROGRAMMER -p m16 -B 2 -U flash:w:$TARGET.hex
For this script, I just took the values and commands of the default Makefile and adapted them to a .hex file, because nothing has to be compiled. Okay, flip on the power switch of your NIBObee and connect it via USB to your computer or laptop, then go into the ‘calibration’ directory and transfer the calibration file to the robot with the following 3 commands:
cd ~/Desktop/nibobee-projects/calibration
chmod +x calibrate.sh
./calibrate.sh
You will see the green programming LED (LED4) flashing once and a bunch of messages in your console. The script is flashing the fuses HFUSE AND LFUSE and, last but not least, the FLASH memory.
If everything went fine, the NIBObee is now in calibration mode and you have to calibrate it. Find a white surface and a black surface, ideally a piece of white paper and a piece of black paper. Now place the robot on a white surface and push back the left feeler. You will see the the yellow LEDs blink 5 times. Place the robot on a black surface now and push back the right feeler. You will see the red LEDs blink 5 times.
To save the calibrated values, push both feelers forward simultaneously and all 4 LEDs blink 5 times. The NIBObee should now have saved the calibration values into its EEPROM memory.
You almost completed this tutorial. We are now going to compile the
first program.
Go into the program1 folder like this:
cd ~/Desktop/nibobee-projects/program1/
Then type make
to compile the code and
transfer the .hex file with:
sudo make avrdude
When it’s finished you should see the red LED1 blinking constantly in the same pattern. Congratulations, you successfully installed the NIBObee library on Linux, learned a little bit about Makefile debugging, calibrated your NIBObee robot, compiled and transferred your first program to the robot!
Last update: 22 March 2021
Go to beginning of this page