<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Juju: ruby-nxt Progress</title>
    <link>http://www.juju.org/articles/2006/08/04/ruby-nxt-progress</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Sufficiently Advanced Technology</description>
    <item>
      <title>ruby-nxt Progress</title>
      <description>&lt;p&gt;Following up on my &lt;a href="http://juju.org/articles/2006/08/03/ruby-nxt-bluetooth-data-logger"&gt;ruby nxt datalogger&lt;/a&gt; from yesterday, I've got two way communication working now.  Doesn't do much yet, just sends a play tone command to the nxt, sends a bluetooth message, or read a mailbox.  It's a start.&lt;/p&gt;

&lt;p&gt;Unlike the datalogger, this requires creating a serial port for the NXT device using Dev B service.  (in OSX that's under Bluetooth Preferences -&gt; Devices -&gt; NXT -&gt; Edit Serial Ports.  Device Service: Dev B, Port type: RS-232, require pairing for security)&lt;/p&gt;

&lt;p&gt;Also, if you want to send messages to a program running on the NXT, make sure you run this script first before starting your program on the NXT.&lt;/p&gt;

&lt;p&gt;One problem I can't figure out is I created an NXT-G program and made it send a bluetooth message on connection 0 but I get no output on the serial port... however, if I go into the NXT and tell it to connect to my computer using my datalogger I get output there.  The NXT shows my computer as being connected to both connection 0 and 1, which I thought wasn't possible.  The documentation says the NXT can only be a Master or a Slave, not both.  So who knows.&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;require &amp;quot;serialport&amp;quot;

@tty = SerialPort.new(&amp;quot;/dev/tty.NXT-B&amp;quot;, 57600, 8, 1, SerialPort::NONE)
@tty.flow_control = SerialPort::HARD

puts &amp;quot;bluetooth SPP connected&amp;quot;

if fork

  puts &amp;quot;input thread started&amp;quot;

  while (res = @tty.getc)
    puts &amp;quot;Response: %02x\t%s&amp;quot; % [res,res]
  end

else

  puts &amp;quot;output thread started&amp;quot;

  # play tone
  tone_cmd = [0x05,0x00,0x00,0x03,0xff,0x00,0x10,0x00,0x00]

  # write True to mailbox 0
  write_cmd = [0x06,0x00,0x00,0x09,0x00,0x02,0x01,0x00]

  # read mailbox 0 from slave?
  read_cmd = [0x05,0x00,0x00,0x13,0x0A,0x00,0x00]

  while true
    while (key = STDIN.gets.chomp) do
      if key == &amp;quot;w&amp;quot;
        puts &amp;quot;MessageWrite&amp;quot;
        write_cmd.each do |b|
          @tty.putc b
        end
      end
      if key == &amp;quot;r&amp;quot;
        puts &amp;quot;MessageRead&amp;quot;
        read_cmd.each do |b|
          @tty.putc b
        end
      end
      if key == &amp;quot;t&amp;quot;
        puts &amp;quot;PlayTone&amp;quot;
        tone_cmd.each do |b|
          @tty.putc b
        end
      end
    end
  end

end&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
      <pubDate>Fri, 04 Aug 2006 00:57:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:62ac8f0b-8797-4736-9d76-148c368acf53</guid>
      <author>Tony Buser</author>
      <link>http://www.juju.org/articles/2006/08/04/ruby-nxt-progress</link>
      <category>Mindstorms</category>
      <category>Code</category>
      <category>Robots</category>
      <category>Ruby</category>
      <category>nxt</category>
      <category>ruby</category>
      <category>mindstorms</category>
      <category>bluetooth</category>
      <trackback:ping>http://www.juju.org/articles/trackback/403</trackback:ping>
    </item>
  </channel>
</rss>
