Pick and Place Machine

From ZB45 wiki

Mechanical Parts

NEMA17 1.8 degrees/step - 200 steps per turn

Z-motion and rotation are dependent. To move in z, run only the z motor. To rotate, run both the rotation and z motor at the same rate.

Axis travel

Approximate (micro)steps/mm for the two axes using belts:

  • 96.87 steps per mm X (left/right)
  • 98.28 steps per mm Y (forward/backward)

probably the true vales are the same. Backlash may cause inaccuracy.

Electronics designs

Motor control: USB Joystick -> Raspberry Pi B+ -> Arduino Mega -> RAMPS board


One diode on our RAMPS board has been removed, so the board does NOT power the Arduino. This allows the RAMPS board to use a higher supply voltage, but the Arduino must be powered separately.

Microstepping settings: all jumpers present (under the Pololu boards) -> 32 micro steps / step. Our drivers are DRV8825.

Arduino Mega

Arduino Mega pin mapping

End stops

Omron inductive proximity sensor data sheet

The end stop part number is not visible on the end stop, only the manufacturer Omron.


Brown - Vcc, 12-24 V

Black - open collector output, pulled low when end stop is activated.

Blue - GND

Wiring: 10k pull-up to 5V on the output, to get the output between 0 and 5 V. Possibly: internal pull-up of the arduino is enough, then no external wiring needed!

RAMPS board: VCC in the end stop connector is 5V. Pinout: signal, gnd, Vcc, with signal towards edge of the board. End-stop cables: Red-Vcc, Black-GND, Green-signal.

The sensor seems to work with Vcc = 5V -> we can use the end stop connectors directly - except for the pin-out. The stops on the machine has the pinout gnd, signal, vcc. Female connector.

  • Current state*: the current cables are 70 cm, which is too short. 2 of them are joined by pin-header pieces - temporarily. The X end-stop is wired with jumper wires to the socket on the machine. The firmware doesn't

support endstops yet.

Power supply

12V. Brown lead -, blue lead +.

Suction pump

The suction pump can be wired between +12V and the 3rd screw connector from the left - D9 on the Arduino. 4th screw from the left is +12V. A red LED on the RAMPS board lights up when this output is active. At 12V, the pump draws 100 mA while running, 500 mA if stalled (inlet blocked). The pump is rated for 24V.


GitHub repository : pick_n_place

Arduino program

The arduino program controls the stepper motors using the AccelStepper library.

Installation of AccelStepper: download zip Arduino IDE: sketch->include library-> add .zip

The arduino receives commands over the serial link, and generates stepping pulses. The program contains configuration variables for the maximum acceleration (steps/sˆ2) and axis range (steps). The program will not step outside the defined range for any axis, or below 0.

The current commands are:

S Stop Stop as soon as possible without loosing position.
W Where Reply with the current position, four integers.
V x,y,z,r Velocity Set the target velocity for each axis x,y,z,r are integer values for steps/second.
P pick turn on suction pump
p place turn off suction pump
  • integers can be negative
  • if arguments are missing, they are assumed to be 0

The V command sets the target velocity. The motors accelerate to this velocity, with the maximum acceleration for each axis, which is defined in the arduino program.

Additional planned commands, not implemented:

G x,y,z,r Go Go to the absolute position specified by x,y,z,r as fast as possible.
M x,y,z,r Move Move x,y,z,r steps relative to the current position as fast as possible.

Also needed:

  • vacuum pump and valve control
  • set acceleration and axis ranges ?
  • home

Note: This is not Gcode. A move will not be along a straight line, since the axes can have different acceleration settings. The Accelstepper library supports straight-line movement for several motors, but only with a constant velocity - not with acceleration. These commands will be useful for bookmarking locations, e.g. above the component storage and above the target circuit board.

Raspberry program


  • on some platforms, it seems pygame will not process events unless a display is initialized
  • on the raspberry, there were some permission issues. I had to run the script as root to access the joystick.
    • no longer the case with the latest Raspbian

Raspberry Pi 3 setup

  • Copy Raspbian image to SD card
  • boot
  • resize SD card in the raspberry config GUI, set keyboard layout (US)
  • WiFi: add to /etc/wpa_supplicant/wpa_supplicant.conf




  • aptitude update, upgrade,
  • sudo aptitude install arduino emacs
  • clone the repository
    • make ssh public key, add to github as deployment key
    • git clone git@github.com:fjansson/pick_n_place
    • host program: pick_n_place/host/control-pygame.py
  • Arduino IDE


  • python modules
  • camera
    • menu->preferences->Raspberry Pi Config, enable camera
    • set GPU memory to 128

Joystick interfacing

We currently have the following two joysticks.

Logitech WingMan Extreme Digital

PC game port joystick. The old-school analog mode works, but only when the joystick is powered. The two stick axes, the hat switch, and two buttons work in the analog mode. In the github repository is a program for a Pro Micro board, to convert an analog game-port joystick to and USB joystick (pick_n_place/joystick/pro_micro_joystick/).

The joystick has a digital mode as well, which gives access to more buttons, but I could not get this to work. [1] [2]


USB joystick. Will use this one for now, since it gives easy access to all buttons.

Button numbering (starting from 1, most buttons have their number printed on them):

  • trigger - 1
  • hat - 2 down, 3 up, 4 left, 5 right
  • base 6 - 11 , clockwise from top left: 6,7 left side, 8,9 towards user, 10,11 right side


Camera cable options:

Camera software

PiCamera python module

  • rotation is in multiples of 90 degrees - same in raspi-vid etc
  • can position and size the preview window - move it on top of a regular window to simulate real windowing?