You are not logged in. Login or Register for free.
Title only?
Strange sound and vision from here to the end of the world.
"We're fans first, journalists second."
nxtlibc 0.1 - Lego Mindstorms NXT Bluetooth library in C for linux
Tuesday, April 17th, 2007

This is the first release of my library which is specifically aimed at linux (and un*x) systems for bluetooth control. Not all functions have been tested, and in fact I don't know what all the functions do (like poll_command). I also have some problems like how to switch the ultrasonic sensor to cm. So let me know where I'm wrong, what can be fixed, what feature requests you would like, etc..

You might probably notice some calls like draw_pixel are pretty slow, this is because for all calls I have "reply required" turned on. In the next release I will add a function to turn off reply required for all non-necessary functions.

NOTE: You MUST have already paired with the NXT brick from the device you will e using the library with. It does not do the secret pin transaction.

Also I must give credit to Michael Collins, whose ultrasonic and other code from his LEGO::NXT perl module I looked at while writing this.

Here is the API.

If you get an "undefined reference to round" add -lm.
I forgot, you must compile with "-lm -lbluetooth -lnxtlibc"
And the source code is available from: http://sourceforge.net/project/showfiles.php?group_id=192706


RSS Feed for comments

Comments

Hi!
I am just trying to use your library and a I getting the following error when compiling test.c:

/usr/local/lib/libnxtlibc.so: undefined reference to `round'

Is the round function created by you or is
it defined somewhere else?

I'am looking forward for this library cause
I really want to control my NXT from Linux.

Thanks

Posted by: R Delgado | April 18, 2007 12:23:09 pm | permalink

Hi Again!

I've just solved the problem. I forgot to include -lm in gcc.
Now, it seems that the program connects to BT but now I get the following when running:

rfcomm connection to XX:XX:XX:XX:XX:XX good.
nonblock failed: : Bad file descriptor
Failed to initialize bluetooth

Do you know what does that means?
Do you know what could be going on?

Thanks Again!

Posted by: R Delgado | April 18, 2007 12:42:17 pm | permalink

user icon Hey sorry I should have mentioned, you must have already paired with the nxt brick from the device you are using. In linux, "hcitool cc XX:XX...." should work.

Posted by: quietearth | April 18, 2007 01:16:51 pm | permalink

I keep on having trouble. I cannot get them the pair correctly... anyone else having this same problem?

Posted by: Erik | April 19, 2007 02:14:06 pm | permalink

Hi, I finally got it working. I can now read some simple things (firmware version, battery level) from the NXT. Thanks for the library so far. I have some suggestions. I'm not experienced in C or C++. I saw that I couldn't use the program from C++ without adding extern "C" { #include "nxtlibc.h"
} around it. This may seem a trivial thing, but it was a full day of searching and asking around for me. Perhaps others also want to use it in C++ software. I propose that you add this to the top of the header file:
#ifdef __cplusplus
extern "C" {
#endif

and at the bottom:
#ifdef __cplusplus
}
#endif

Source: http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html#faq-32.4

Thanks again for this lib! Keep up the good work!

Posted by: ErikDeBruijn | April 20, 2007 03:04:22 pm | permalink

Hi!

I still can't make it work.
I keep receiving the:

rfcomm connection to XX:XX:XX:XX:XX:XX good.
nonblock failed: : Bad file descriptor
Failed to initialize bluetooth

message. I use de hcitool command and it seems to connect but then I get the same error message.

Any suggestions?

Thanks!

Posted by: R Delgado | April 22, 2007 06:36:59 pm | permalink

user icon You have to get it to pair with the nxt brick using a pin. Try restarting your bluetooth daemons and re-running the hcitool cc XX.... You might need to do this a few times.

Posted by: quietearth | April 22, 2007 07:02:40 pm | permalink

Hi,
I'm building a generic real-time image recognition system that constructs a 3d model of the Lego robot and its world. I wanted to fully control the robot from the same C++/C code as the rest was (also because URBI only runs on windows and I can't connect to a windows box, even with the Windows Firewall turned completely off). Windows lacks the transparency for me (I can't look at the code when I get stuck).

For reading variables, generating beeps the library works fine.

How could I control the servos? Right now I must start a program from each thing I want to do (such as a-up, b-down10).

I tried creating a servoMove C++ function that calls _set_output_state(), but this takes so many parameters that I can hardly make something out of it. When I enter values that I expect that they should do something, I get no behavior out of the servos. It also returns a TRUE, suggesting no (reported) error. Running just the beeper also works (so it seems to be specific to servo control).

The enumerations/defines such as MOTOR_ON are not available in the function I'm programming. Can I use 0x00 instead for the first one, and e.g. 0x10 for the third?

I'll post my function when it works. You may then add it to the nxtlibc package.

Posted by: ErikDeBruijn | April 24, 2007 04:32:10 am | permalink

user icon Of course you can use the values in place of the #defines if they are not available, and I'm sorry I don't have more explanation for motor states, this is all the bluetooth api specifies. I wrote this before actually making a robot (which I should be doing soon) and I would be glad to incorporate any new functions (macros) for motor functions you come up with in next releases, as I also plan to do the same when I get around to actually building something.

Posted by: quietearth | April 24, 2007 10:10:37 am | permalink

After a reinstall of Kubuntu I had mayor difficulties (again) with getting pairing right... Last time it was difficult and now the tricks I learned (starting the bluetooth-applet from gnome) was not enough.
I did the following:
dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hci0 org.bluez.Adapter.RemoveBonding string:00:16:53:02:xx:xx
dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hci0 org.bluez.Adapter.CreateBonding string:00:16:53:02:xx:xx
After that I had to click the bt-applet icon in the system tray.

Posted by: ErikDeBruijn | June 11, 2007 08:06:39 pm | permalink

Hi!
I am just trying to use your library and a I getting the following error when execute test

./test: error while loading shared libraries: libnxtlibc.so: cannot open shared object file: No such file or directory

I work in ubuntu

Help!

Posted by: juan | July 31, 2007 04:37:56 am | permalink

user icon Hey Juan, you need to set your LD_LIBRARY_PATH variable to include the dirfectory where libnxtlibc.so is.. then it will be able to find it.

Posted by: quietearth | July 31, 2007 11:19:02 am | permalink

Thank you very much quietearth!!

this library is sensational

Posted by: juan | July 31, 2007 02:23:59 pm | permalink

Hey i'm having a problem when i launch test :

./test: error while loading shared libraries: libbluetooth.so.1: cannot open shared object file: No such file or directory

Posted by: Jonathan | October 17, 2007 03:30:42 am | permalink

i have this problem:

rfcomm connection to XX:XX:XX:XX:XX:XX good.
nonblock failed: : Bad file descriptor
Failed to initialize bluetooth
?????

Posted by: Elkin | November 16, 2007 06:02:13 pm | permalink

I also get the error :

rfcomm connection to XX:XX:XX:XX:XX:XX good.
nonblock failed: : Bad file descriptor
Failed to initialize bluetooth

I fixed it adding :

s = nxtsock;

on bluetooth.c:219 and recompiling the library.

Thanks for this library.

Posted by: Nacho | November 30, 2007 02:37:01 pm | permalink

Hi.
Jonathan, i´m having de same problem:
./test: error while loading shared libraries: libbluetooth.so.1: cannot open shared object file: No such file or directory
Someone can help us?

Posted by: Radek | May 3, 2008 05:54:45 am | permalink

Hi, I've downloaded the library and I've compiled it with "make all". But while trying to compile test.c (gcc test.c -o test -lm -lbluetooth -lnxtlibc) I get this:


jorcoval@jorcoval-laptop:~/Desktop/nxtlibc-0.1$ gcc test.c -o test -lm -lbluetooth -lnxtlibc
/usr/bin/ld: can't find -lnxtlibc
collect2: ld devolvió el estado de salida 1

Any solutions?

Posted by: Anonymous | May 6, 2008 04:20:24 pm | permalink

user icon see the post on LD_LIBRARY_PATH

Posted by: quietearth | May 6, 2008 05:02:40 pm | permalink

I have this problem:

rfcomm connection to XX:XX:XX:XX:XX:XX good.
nonblock failed: : Bad file descriptor
Failed to initialize bluetooth

Itry solve it adding:

s = nxtsock;

on bluetooth.c:219 and recompiling the library, but it dont fixed the problem.

How can I fixed it?

Posted by: Radek | May 11, 2008 04:52:39 am | permalink

This appears to be exactly what I'm looking for, I hope. What firmware does the brick need to have for this to work? Lejos + bluetooth = disaster.

Posted by: Conor | November 7, 2008 11:04:08 pm | permalink

Hi! This library is great!

But, i have an issue. I need read accelerometer values. From HiThechnic data sheet, says that register for the accelerometer starts at 40H and ends in 47H. My question is: there are a way to read that memory locations?

Greetings!

Posted by: Manolo | January 23, 2009 01:08:42 pm | permalink

Hey!Great Library and great job!

I'm trying to set up a positioning system including three PCs with Bluetooth for triangularization, measuring the distance between the NXT and each of them via the signal strenght..

It's a research project for the university.

Thanks a lot!

Posted by: Anonymous | August 15, 2009 12:24:43 pm | permalink

I'm doing a Qt4 interface with your libraries.
Very nice project.
I just get some minor problems with synchronous calls but is not a big issue.

Posted by: Epokh | February 23, 2010 08:16:11 am | permalink

Hello, I have set up LD_LIBRARY_PATH to LD_LIBRARY_PATH=/opt/nxt/nxtlibc-0.1/ where the library is but compiling with gcc -lm -lbluetooth -lnxtlibc c.c -o c I receive the following error:
/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../i486-slackware-linux/bin/ld: cannot find -lnxtlibc
collect2: ld returned 1 exit status
Where I exactly missed something? Thank You for your support

Posted by: Simo | May 19, 2010 04:56:44 am | permalink

Solved. I didn't executed make install. ;)

Posted by: Simo | May 19, 2010 05:10:26 am | permalink

hi, good work :) i want use two brick how to make connection between my laptop and two bricks?

Posted by: mcoder | July 18, 2010 09:25:49 am | permalink

Post a comment

Name:
(default is Anonymous)
Contact:
(email or url, optional)
Comment:
(no html or bbcode)
Captcha:



rss | subscribe via email | the team | contact us | mobile
© 2006-2009 Don Neumann (except where applicable)
We are looking for free hosting with a cut of sales, you'll get a link right here.
If you want news of your film posted, use our contact page and we'll check it out
Permission is granted to use material from this site if you provide a reference to us via a link and DO NOT HOTLINK.


GenreBanners.com Banner Exchange