Nxt::usb

From ZENotes
Revision as of 20:49, 14 October 2011 by Admin (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Mother-Of-All-Them-Threads on the NXTasy.org forum to get USB and BT speaking to your brick WAS here - but they moved to a new website called MindBoards -- HEY John H. & Minboards staff, feel free to contact me on lola@_this_server_name.net to rectify this and share the fun.

Newer thread here

Contents

Welcome folks

The above thread WAS is the one that got my several machines here speak with my NXT brick (succeeded with Slackware, Debian, Arch, Fedora and Ubuntu), so what's written down here is pretty much Tried & Tested. I did some simplifications, used GUI apps for, well, stuff you can do in a GUI (And that happened not to work on my Fedora machines at the time).

'buntu users around: you have to add sudo in front of an instruction when here below it starts by #. And, yes, for everybody other *nixer around, # means a command that you run as ROOT; whenever your average user is enough, it is $.

Tools of the Trade

Hosted in my own small server for ease of use - please do not trust me, try to find the original binaries by yourself, and at least be aware that these, while working with my NXT 1.0, may not be latest version. You enter WORK-FOR-ME territory here, you can do better.

nbc is the compiler, find it here in static binary version, as are the following executables:

t2n is a lightweight tool to send files to the brick

nexttool is a full-featured file manipulation tool for your NXT brick.


Find here official releases from John H.: [1]

New kid on the block is the GUI-based nxtcc - haven't extensively tested as of now.


OK, Let's find that Brick first

You start with a terminal, as root or with sudo. A lot of this must be done as root, so forget about it if you are not King of your Kingdom. Plug your NXT brick, wait for it to boot (as soon as the logo disappears & you see files you're good) and do (or sudo, I won't say it again):

         # lsusb

it should return something like:

         [root@DC266 ~]# lsusb
         Bus 005 Device 001: ID 0000:0000  
         Bus 007 Device 003: ID 0c76:0005 JMTek, LLC. USBdisk
         Bus 007 Device 001: ID 0000:0000  
         Bus 002 Device 001: ID 0000:0000  
         Bus 003 Device 001: ID 0000:0000  
         Bus 004 Device 002: ID 0694:0002 Lego Group 
         Bus 004 Device 001: ID 0000:0000  
         Bus 006 Device 001: ID 0000:0000  
         Bus 001 Device 002: ID 1131:1001 Integrated System Solution Corp. KY-BT100 Bluetooth Adapter
         Bus 001 Device 001: ID 0000:0000

Of this, obviously, Bus 004 Device 002: ID 0694:0002 Lego Group is the one that matters here. Obviously, the figures with Bus 004 and Device 002 are hardware dependent & are probably different on your system; it doesn't matter, just for the sake of stability while going through this tutorial, leave the brick on and plugged in the same port. Now try:

         $ dmesg|tail 

should return something like this as last line(s) if the last thing you did was plug in/power on your brick:

         usb 4-1: new full speed USB device using uhci_hcd and address 3
         usb 4-1: configuration #1 chosen from 1 choice

So, yes, your computer (if you have a 2.6 kernel & a functional UDEV subsystem) does recognize your brick; it just doesn't really know what to do with it.

If the brick hasn't showed up after 20 (twenty) seconds of being "On" and Plugged in USB, then I can't help I am afraid; don't waste your time on this document anymore. You may have to plug - unplug the USB wire with the brick "On" just to be safe, even plug in another port; then 20 secs is really a maximum. Your lsusb and dmesg|tail output should be way faster than that if it works as expected. Don't forget to do that as Root; for everybody but *buntu distros, even sudo won't do it since Linux may not like end-users messing with Hardware Layers! Unfortunately, the Brick itself won't tell nothing about being "hooked".

Now, get it plugged for real

From here on, everything is liberally, and shamelessly, sucked out from John Hansen' post --deadlink-- on NXTasy.org forum --deadlink--- look here now for newer info.

For all recent linux distributions here is John's procedure, slightly simplified though, that is recommended to configure your Linux box for use with the NXT:

1. Add/create an nxt group and add yourself to it.

For KDE users, use kuser; gnome people should use config-system-users. 
Original tute on NXTAsy forum recommends CLI that didn't work on Fedora (don't alsk!).
Create a group called nxt (WARNING: LINUX IS CASE SENSITIVE!) then go to the users management tab and 
add the group nxt to all users on this machine that will need it.

1.b Super-nerds may do

 groupadd nxt
 gpasswd -a <Your_Login_Name> nxt

This part is quite crucial in order to avoid being As Root all the time when dealing with the brick.

2. As root, navigate to /etc/udev/rules.d and create there a file called 70-nxt.rules; the easyiest way of doing that is, from a terminal:

         $ su -
         [Password]
         # cd /etc/udev/rules.d
         # nano 70-nxt.rules                        or gedit, or kate or mousepad, anything, even vim if you feel like.

Its contents should look like this, you can Copy'N'paste after reviewing to be sure I am not planting something in your system:

         SUBSYSTEM=="usb_device", ACTION=="add", SYSFS{idVendor}=="0694",
         SYSFS{idProduct}=="0002", SYMLINK+="nxt-%k", GROUP="nxt", MODE="0660", RUN+="/etc/udev/nxt.sh"

3. Still using your Rootly-Powered Text Editor, create there a file called nxt.sh the same way, and save in up one directory into /etc/udev. Its contents should look like this:

         #!/bin/bash
         #
         GROUP=nxt
         if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ]
         then
             chmod o-rwx "${DEVICE}"
             chgrp "${GROUP}" "${DEVICE}"
             chmod g+rw "${DEVICE}"
         fi

4. Shut down the Text Editor; we'll re-use the terminal you used to fire it up to Make the little nxt.sh script executable. From a terminal prompt type

         # chmod a+x /etc/udev/nxt.sh

You MAY or MAY NOT have to reboot at this time, I cannot tell

That should be all you need to do to make sure that your NXT will always be accessible via USB for any user who is a member of the nxt group. Whenever you plug in your NXT it should show up in /dev (you can go back to "user" mode now, with exit for instance:

         $ ls /dev/nx* 

returns (lots of):

         /dev/nxt-x-y

where x and y depend on which USB port you plug the NXT into. There will be other entries such as /dev/nxt-usbdevx.y where y increments but you should be able to use the above device alias without any problems.

!! That should take care of USB support!!

Yeah, Let's Speak to The Brick now

Just for the sake of testing, go to your nexttool folder, fire up the brick, plugged into your PC, and try (that is, if you did not linked it or copied in somewhere in your path):

         ./nexttool /COM=USB -deviceinfo

So that you know if everything went right if you get an output (reminder: NexTTool doesn't give an output in case of failure). And if it did, then it's all thanks to John --deadlink-- Look here now, not me. I am just spreading the word, that's my contribution to it. Remember Linux is case-sensitive, and John's original name for this is NexTTool.


Some personal tips: Clean Up && make it easy

You really don't need much to start programming the next NXT-based MarsRover: you do not need a powerful machine or that much of ram (Way, way less than with NXT-G), you can do it with a text editor, a decent USB stack and the above mentioned nbc, Nexttool and t2n; and if you feel like going Python or whatever, you won't need more anyway. One thing though that started to annoy me was the sheer number of micro-apps that I had to keep in one single place & start with ./ + the need to have the not-yet-compiled candidate there too if I did not want to change folders all the time; so:

(to have your system aware of the new alias do $ source .bashrc now)

Just do something like this to link them without messing up your system too much:

#ln -s /home/jarch/bin/ld/nexttool /usr/bin/nexttool


Now i am working from a neat ~/mindstorms/compile/ folder where the only non-nxc/nbc/rxe thingie is a subminimal

Little script

 #!/bin/bash
 nbc x1.nxc -O=output.rxe
 t2n -put output.rxe
 nexttool /COM=USB -run=output.rxe
 nexttool /COM=USB -runningprogram
 t2n -b

This script assumes you are working on the x1 project, and that you want to put it & start it on the brick as output.rxe; I do this with every "draft" snippet, and then I name them properly and compile them with the appropriate output name for archival/sharing when I am happy with the result.

OK, that was the HowTo Plug, now for the WhatToDoWithIt, may I recommend my Success Story?


Lola 17:21, 7 July 2008 (UTC)

Sample Snippets are here.

Links

Brickcc and nbc: http://bricxcc.sourceforge.net

t2n: http://www-verimag.imag.fr/~raymond/edu/lego/t2n

NexTTool is now quoted here as a Mac software (?) http://bricxcc.sourceforge.net/utilities.html The one linked on my server is intended for linux

New kid on the block, by John H. again: http://bricxcc.sourceforge.net/nxtcc.zip

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox