Marcus Johnson
Published © GPL3+

BrickPi Robotic Arm

This robotic arm was created using a Lego Mindstorms NXT kit and it uses the BrickPi board attachment for the Raspberry Pi.

IntermediateFull instructions provided2,347
BrickPi Robotic Arm

Things used in this project

Hardware components

Raspberry Pi 1 Model B+
Raspberry Pi 1 Model B+
×1
BrickPi
×1
Lego Mindstorms NXT kit
×1

Story

Read more

Custom parts and enclosures

Robot Arm Schematics

Schematics

BrickPi connected to Raspberry Pi

This image shows how the BrickPi is connected to the Raspberry Pi. The BrickPi board is connected to the first 26 pins of the RPI's GPIO if you're using a B+ or RPI2. If you're using a model B RPI and below, you can just fit the BrickPi to cover all the GPIO pins. You will notice several ports around the BrickPi that look like telephone jack connectors. These are the ports for the lego motors and sensors. The motor ports (A, B, C, D) are lined along the back of the BrickPi. The ports for the sensors are on the sides of the board.

Code

RobotArm.py

Python
# Motor B controls Left-Right movement
# Motor C controls the height of arm
# Motor A controls the fingers

# Direction keys - to move the arm
# Space will open the claw
# Z will close the claw

# The light sensor will be configured to also close if a certain 
# threshold is reached with an object being in front of it


from BrickPi import *   #import BrickPi.py file to use BrickPi operations
import curses #curses library is used to get realtime keypress and time for sleep function

BrickPiSetup()  # setup the serial port for communication

BrickPi.MotorEnable[PORT_B] = 1 #Enable the Motor B
BrickPi.MotorEnable[PORT_C] = 1 #Enable the Motor C
BrickPi.MotorEnable[PORT_A] = 1 #Enable the Motor D

BrickPi.SensorType[PORT_2] = TYPE_SENSOR_LIGHT_ON   #Set the type of sensor at PORT_2

BrickPiSetupSensors()   #Send the properties of sensors to BrickPi

stdscr = curses.initscr()	#initialize the curses object
curses.cbreak()			#to get special key characters 
stdscr.keypad(1)		#for getting values such as KEY_UP

key = ''
while key != ord('q'):		#press 'q' to quit from program
    
    #lightValue = BrickPi.Sensor[PORT_2]
    #print lightValue;
    key = stdscr.getch()	#get a character from terminal
    BrickPi.MotorSpeed[PORT_B] = 0	#first setting all speeds to zero
    BrickPi.MotorSpeed[PORT_C] = 0
    BrickPi.MotorSpeed[PORT_A] = 0
   
    stdscr.refresh()
    
        #change the motor speed based on key value
    if key == curses.KEY_LEFT : 
        BrickPi.MotorSpeed[PORT_B] = -125
    elif key == curses.KEY_RIGHT : 
        BrickPi.MotorSpeed[PORT_B] = 125
    elif key == curses.KEY_UP :
        BrickPi.MotorSpeed[PORT_C] = 125	#different values are used to bear the weight of arm and object
    elif key == curses.KEY_DOWN :
        BrickPi.MotorSpeed[PORT_C] = -125
    elif key == 32 :
        BrickPi.MotorSpeed[PORT_A] = -90	
    elif key == 122 :
        BrickPi.MotorSpeed[PORT_A] = 90

    #After setting the motor speeds, send values to BrickPi
    BrickPiUpdateValues()
    time.sleep(.1)	#pause for 100 ms
curses.endwin()

Credits

Marcus Johnson

Marcus Johnson

9 projects • 28 followers
Software engineer with professional experience creating, maintaining, integrating, and testing software in Windows and Unix environments.

Comments