User avatar
flypig
Posts: 6
Joined: Tue May 29, 2012 9:19 pm
Location: Liverpool
Contact: Website

Re: Lego RCX/NXT robotic programming with Pi.

Thu Sep 20, 2012 5:27 pm

thomasd538 wrote:How is your raspberry pi, python, NXT project coming along?
I am teacher in the US and I have NXTs and awaiting a shipment of Raspberry Pi computer to arrive Friday.
Tom
Hi Tom,

In case it's helpful to know, we demonstrated a Raspberry Pi controlled NXT robot to our new students last week and it seemed to generate some interest. In my opinion, it's a great way to illustrate basic programming concepts (command sequences, loops, conditionals) in a very concrete way. It's basically logo using Python.

The fact you can control the robot using Python is particularly nice, since it's a very immediate language. However, I found it was necessary to use something like PyGame to create a simple event loop. This avoids the difficulty of using threads to manage control, sensing and input simultaneously.

I'd be really interested to hear about the results you get with your students. Can I ask what your NXT-to-student-to-Pi ratio will be?

thomasd538
Posts: 11
Joined: Thu Sep 20, 2012 3:01 pm

Re: Lego RCX/NXT robotic programming with Pi.

Sun Sep 23, 2012 2:39 am

I wil one-to-one ratio with my first test group. I probably will be 2-1 normally. I also plan trying to use Arduinos with the Pi (s).

GoneToTheBar
Posts: 1
Joined: Sun Nov 24, 2013 10:40 am

Re: Lego RCX/NXT robotic programming with Pi.

Sun Nov 24, 2013 10:53 am

Hi Guys,
I apologise if this isn't the right forum to post this in, but here goes:

I've managed to hook up my raspberry pi to my lego mindsorms nxt brick and had some pretty good results with my mindstorms shooter via keyboard remote control. The main thing is that movement isn't jerky ...even if the code below isn't that great.

I have a couple of questions for you.... firstly, i'm no programmer. So, what changes would you make to the code below to tidy it up and make it more professional looking?

And secondly, id really like to get this working over the internet. I've tried executing a python script via php but it always fails on:

b= nxt.locator.find_one_brick()

Can you guys suggest where either where i'm going wrong or what solutions you would use to make this possible?


=============================================
# Os
import os

# nxt python
import nxt
import nxt.locator
from nxt.motor import *

### setup and start streaming on port 8080
#os.system("mkdir /tmp/stream")
#os.system("raspistill --nopreview -vf -w 640 -h 480 -o /tmp/stream/pic.jpg
-tl 3 -t 9999999 -th 0:0:0&")
#os.system('LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -
f /tmp/stream -n pic.jpg" -o "output_http.so -w /usr/local/www"&')

def turn_right(b):
m_left = Motor(b , PORT_C)
m_left.run(-100)

def turn_left(b):
m_right = Motor(b, PORT_C)
m_right.run(100)

def turn_down(b):
m_left = Motor(b, PORT_B)
m_left.run(-60)

def turn_up(b):
m_right = Motor(b, PORT_B)
m_right.run(100)

def shoot(b):
m_right = Motor(b, PORT_A)
m_right.turn(120,360)



b = nxt.locator.find_one_brick()



def getkey():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
key = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return key




key=' '
print "Ready"
while key != 'q':
key = getkey()
if key== 'w':
print "Up"
turn_up(b)
elif key== 'x':
turn_down(b)
print'Down'
elif key== 'a':
turn_left(b)
print 'Left'
elif key== 'd':
turn_right(b)
print 'Right'
elif key=='s':
shoot(b)
print 'Shoot'
else:
print "still"

time.sleep(0.01)
if key=='w' or key =='x':
Motor.brake(nxt.motor.Motor(b, nxt.motor.PORT_B))

elif key=='a' or key=='d':
Motor.brake(nxt.motor.Motor(b, nxt.motor.PORT_C))
#time.sleep(0.02)
print "Finished"

User avatar
williamhbell
Posts: 291
Joined: Mon Dec 26, 2011 5:13 pm
Contact: Website Twitter

Re: Lego RCX/NXT robotic programming with Pi.

Fri Dec 27, 2013 8:52 am

Hi,

Have you tried using a BrickPi
http://www.dexterindustries.com/BrickPi/
?

It is a much cheaper solution that allows the Raspberry Pi to be used to directly talk to LEGO motors and sensors. It can programmed with C, Python or Scratch.

Best regards,

Will

lcww1
Posts: 31
Joined: Sat Jun 01, 2013 6:40 pm

Re: Lego RCX/NXT robotic programming with Pi.

Tue Jan 21, 2014 11:53 pm

I know this thread is quite old now, but I thought I'd just follow-up on the suggestion, made at the beginning of the thread, more than a year ago now, by ghans, of using NQC - http://bricxcc.sourceforge.net/nqc/ - on the Pi to control an old Lego Mindstorms RCX programmable brick (http://www.mralligator.com/rcx/).

It turns out to be straightforward to get NQC compiled and running on a Pi under Raspbian, and then to get the Pi to program an RCX via NQC using either a serial or a USB Lego IR tower.

I found some generic instructions on installing NQC under linux here http://pbrick.info/2013/10/configuring- ... -on-linux/ and here http://pbrick.info/2013/10/making-the-l ... permanent/. I subsequently came across some detailed instructions (in Italian) on installing both NQC and the LeJOS system (http://www.lejos.org) specifically on a Raspberry Pi running Raspbian in this - https://137.204.107.21/trac/Tirocini/ex ... pi_rcx.pdf - repository at the University of Bologna!

Just follow the instructions on the pbrick.info site, or in the rip_rcx.pdf file from the University of Bologna, to get NQC running on your Pi today! I've also made a set of instructions for installing NQC on the Pi on my blog here - http://minordiscoveries.wordpress.com/2 ... rcx-brick/ - which may, or may not, be clearer than the sources of information above. I've also linked to some sources for the RCX firmware, which you'll need in order to program the RCX from NQC, and which can be otherwise tricky to obtain without access to a Windows PC.

I realise this may all be old news to some, but I've not found any evidence on the web, other than the instructions at the University of Bologna, of people actually using NQC/RCX with a Pi. I'd be interested to know if others are using this system, and what your experiences have been.

I think these old RCX units continue to have a lot of educational potential, particularly now in combination with a Raspberry Pi. The NQC language is also quite nice, easy to use, and has the advantages of lots of high quality example code, and free educational materials, being readily available on the internet e.g. http://oreilly.com/catalog/lmstorms/chapter/ch04.html.

Some earlier posts on this thread reasonably comment on the (relatively) high cost of Lego NXT (and now EV3) systems, but the RCX bricks can be found quite cheaply (similar to the cost of a Pi) on the second hand market. The RCX brick also seems to be pretty robust, as most units are now > 10 years old, and despite often rough usage, they seem to just keep going!

Lastly, if you do find an old RCX unit for sale somewhere, then don't be put off by signs of corrosion on the battery terminals. The first RCX I bought was covered in corrosion, but it's quite easy to take an RCX apart (http://www.ifixit.com/Guide/RCX+1.0+Cas ... ement/4352), and it's also quite easy to successfully remove the corrosion (http://lego-robotics.996304.n3.nabble.c ... d3388.html). My corroded RCX unit cleaned up beautifully, and works very nicely!

MZAdmin
Posts: 1
Joined: Fri May 30, 2014 1:55 pm

Re: Lego RCX/NXT robotic programming with Pi.

Fri May 30, 2014 2:13 pm

lcww1 wrote:I know this thread is quite old now, but I thought I'd just follow-up on the suggestion, made at the beginning of the thread, more than a year ago now, by ghans, of using NQC - http://bricxcc.sourceforge.net/nqc/ - on the Pi to control an old Lego Mindstorms RCX programmable brick (http://www.mralligator.com/rcx/).

It turns out to be straightforward to get NQC compiled and running on a Pi under Raspbian, and then to get the Pi to program an RCX via NQC using either a serial or a USB Lego IR tower.

I found some generic instructions on installing NQC under linux here http://pbrick.info/2013/10/configuring- ... -on-linux/ and here http://pbrick.info/2013/10/making-the-l ... permanent/. I subsequently came across some detailed instructions (in Italian) on installing both NQC and the LeJOS system (http://www.lejos.org) specifically on a Raspberry Pi running Raspbian in this - https://137.204.107.21/trac/Tirocini/ex ... pi_rcx.pdf - repository at the University of Bologna!

Just follow the instructions on the pbrick.info site, or in the rip_rcx.pdf file from the University of Bologna, to get NQC running on your Pi today! I've also made a set of instructions for installing NQC on the Pi on my blog here - http://minordiscoveries.wordpress.com/2 ... rcx-brick/ - which may, or may not, be clearer than the sources of information above. I've also linked to some sources for the RCX firmware, which you'll need in order to program the RCX from NQC, and which can be otherwise tricky to obtain without access to a Windows PC.

I realise this may all be old news to some, but I've not found any evidence on the web, other than the instructions at the University of Bologna, of people actually using NQC/RCX with a Pi. I'd be interested to know if others are using this system, and what your experiences have been.

I think these old RCX units continue to have a lot of educational potential, particularly now in combination with a Raspberry Pi. The NQC language is also quite nice, easy to use, and has the advantages of lots of high quality example code, and free educational materials, being readily available on the internet e.g. http://oreilly.com/catalog/lmstorms/chapter/ch04.html.

Some earlier posts on this thread reasonably comment on the (relatively) high cost of Lego NXT (and now EV3) systems, but the RCX bricks can be found quite cheaply (similar to the cost of a Pi) on the second hand market. The RCX brick also seems to be pretty robust, as most units are now > 10 years old, and despite often rough usage, they seem to just keep going!

Lastly, if you do find an old RCX unit for sale somewhere, then don't be put off by signs of corrosion on the battery terminals. The first RCX I bought was covered in corrosion, but it's quite easy to take an RCX apart (http://www.ifixit.com/Guide/RCX+1.0+Cas ... ement/4352), and it's also quite easy to successfully remove the corrosion (http://lego-robotics.996304.n3.nabble.c ... d3388.html). My corroded RCX unit cleaned up beautifully, and works very nicely!

Thank you!

I am a site tech at a elementry school thats big into teaching kids basic programming and we have are expanding so much we want to be able to reuse some old RCX kits and this may be just the thing. Saved me a lot of research time.

Mach_5
Posts: 70
Joined: Fri Jun 07, 2013 9:22 pm

Re: Lego RCX/NXT robotic programming with Pi.

Tue Jul 01, 2014 6:34 pm

I can also confirm that the Raspberry Pi with NXT-Python works with a NXT brick over bluetooth. :D (You just need a bluetooth adapter) I am using this setup to make a Raspberry Pi robot communicate with a NXT robot.

jhfoo
Posts: 1
Joined: Tue Mar 06, 2018 12:41 am

Re: Lego RCX/NXT robotic programming with Pi.

Tue Mar 06, 2018 2:20 am

It's 2018. Is anyone still having fun with NXT and Pi?

Looking to have some fun with NXT+Pi3+Node. Unable to maintain a bluetooth connection between Raspbian Stretch and the NXT brick. Looking for people to solve and have fun together!

W. H. Heydt
Posts: 8769
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Lego RCX/NXT robotic programming with Pi.

Tue Mar 06, 2018 8:21 pm

Welcome to the fourms.

I think that's a record for necro'ing a thread....

Return to “Staffroom, classroom and projects”

Who is online

Users browsing this forum: No registered users and 5 guests