Giter VIP home page Giter VIP logo

lego-nxt's Introduction

Lego NXT Build Status Coverage Status RubyGems Version

This gem is under heavy development! A lot of the below code may not work, and is certainly not guranteed to be reliable if it does! If you need to base a working project on this, I recommend going back to the ruby-nxt gem this work is inspired by for the time being.

Control a Lego NXT 2.0 brick using Ruby code. This library works by piping commands over a Bluetooth or USB connection to the brick, allowing you to write Ruby scripts to control your NXT brick.

This project used to be based on "ruby-nxt", and Tony Buser's subsequent rewrite "nxt". It is now a complete rewrite, based heavily in some parts on the aforesaid projects internally, but with a brand new external API that should prove cleaner and easier to work with.

This code implements direct command, as outlined in "Appendix 2-LEGO MINDSTORMS NXT Direct Commands.pdf". Not all functionality is implemented yet!

Getting Started

Installing This Library

Install the gem:

gem install lego-nxt

Add it as a Bundler dependency as you see fit!

Connect to Your NXT Brick

In order to start coding with your NXT, you'll need to set up either a USB or Bluetooth connection to it. Follow one of the below sets of steps; if you go for a Bluetooth connection, you'll need to remember the /dev/* address you end up using, as you'll need to provide it when making a connection with this library.

Connecting Via USB

Simply plug in the NXT, and that's it! This library will take care of enumerating the USB host devices to find the NXT device for you, no effort required on your behalf!

Connecting Via Bluetooth

Linux

Make sure you have the bluez package installed, which should include the rfcomm and hcitool commands. We start by searching for the MAC address of our NXT:

$ hcitool scan
  Scanning ...
      90-8E-E0-C1-2A-7B       NXT

Then open the /etc/bluetooth/rfcomm.conf file and add an entry as follows:

rfcomm0 {
  bind yes;
  # Bluetooth address of the device
  device 90-8E-E0-C1-2A-7B;
  # RFCOMM channel for the connection
  channel 1;
  # Description of the connection
  comment "NXT";
}

If you're on a distro which has a Bluetoth daemon running automatically, you can simply restart it. For Ubuntu, that will look something like:

$ sudo /etc/init.d/bluez-utils

On other distros where you manage the Bluetooth daemon yourself, you'll need to do the bind calls yourself:

$ sudo rfcomm bind /dev/rfcomm0 '90-8E-E0-C1-2A-7B'

After that, the Bluetooth connection should be established. Check that by running the rfcomm command with no arguments:

$ rfcomm
rfcomm0: 90-8E-E0-C1-2A-7B channel 1 clean

The NXT should now be accessible from /dev/rfcomm0!

Mac OS X

Turn on the NXT and make sure Bluetooth is turned on. Click the bluetooth icon in the menubar of your Mac and select "Setup bluetooth device". It will prompt you for a device type; choose "Any device". Select the NXT from the list and click continue.

The NXT will beep and ask for a passkey. Choose 1234 and press orange button. Enter the 1234 passcode on your Mac when promted. The NXT will beep again; press the orange button to use 1234 again.

Your Mac will then alert you that "There were no supported services found on your device". Ignore and click "Continue", followed by "Quit".

Now click the Bluetooth icon and select "Open bluetooth preferences"; you should see the NXT listed. Select it, then click "Edit Serial Ports". It should show NXT-DevB-1; if not, click "Add", and use:

Port Name: NXT-DevB-1
Device Service: Dev B
Port type: RS-232

Click "Apply". The NXT should now be accessible from /dev/tty.NXT-DevB-1!

Documentation and Examples

The NXT project has been heavily documented using nice, clean, human readable markdown. YARD is used to generated the docs, and the options have been included in our .yardopts file, so simply run a YARD server to read them:

$ yard server

This documents the API, both internal and external. For bite-sized chunks of NXT code that is much more appropriate for beginners, have a look at the examples.

In addition to this, you might find the tests quite helpful. There are currently only RSpec unit tests, which can be found in the spec directory; the plan is to add some decent feature tests soon.

License

This project is licensed via MIT license.

lego-nxt's People

Contributors

dependabot[bot] avatar nathankleyn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lego-nxt's Issues

What now?

Good evening, and sorry to bug you.
I was wondering what I should do after installing the gem and plugging the NXT into my Windows machine via USB.

You said that "Simply plug in the NXT, and that's it! This library will take care of enumerating the USB host devices to find the NXT device for you, no effort required on your behalf!".

However, when I try to run the examples, I get errors like this one: https://eval.in/204307
Also, I have no clue to how I should use the Bluetooth.

Lastly, I would like to know if I can record dBA with the gem and the NXT for a school project.

Thank you very much!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.