Mearm And Espruino - Remote Controlled Robot Arm

About the project

The MeArm is a small, cheap Robot Arm kit designed by Ben Gray of Phenoptix. It uses Servo Motors and laser cut acrylic.

Project info

Difficulty: Easy

Platforms: Espruino

Estimated time: 2 hours

License: Apache License 2.0 (Apache-2.0)

Items used in this project

Hardware components

2621  ARM Espruino Pico 2621 ARM Espruino Pico Or another Espruino board x 1
Servo Motors Servo Motors x 1
IR Reciever IR Reciever http://www.espruino.com/IRReceiver x 1
A TV remote control A TV remote control x 1
MeArm MeArm http://www.phenoptix.com/products/mearm-pocket-sized-robot-arm or laser cut your own from design files on Thingiverse: http://www.thingiverse.com/thing:360108 x 1

Story

Wiring Up

Plug the Servo Motors into the servo header on the Espruino board as follows:

And plug the IR receiver directly onto the board, such that:

Software

Just copy and paste the following code into the right-hand side of the Web IDE, and click Send to Espruino.

We've explained in comments how everything works, but as you won't have the same TV remote control as us, when you press a button Espruino will print Unknown 12345789. Copy the number you get when you press each different button, and replace the numbers that we used with your numbers.


  1. // Where the Servos are connected
  2. var servos = {
  3. shoulder : B15,
  4. elbow : B14,
  5. base : C6,
  6. hand : C7,
  7. };
  8. // Add a variable that the 2 functions below will use
  9. Pin.positions = {};
  10. // A function that will set pulse width modulation up on the servo
  11. Pin.prototype.goto = function(pos) { // -1 .. 1
  12. Pin.positions[this] = pos;
  13. console.log(this,pos);
  14. analogWrite(this, E.clip(0.5*pos+1.5,1,2)*0.05, {freq:50});
  15. };
  16. // This will just move one step in the direction that is given
  17. Pin.prototype.move = function(dir) {
  18. Pin.positions[this] = E.clip(Pin.positions[this]+dir,-1,1);
  19. this.goto(Pin.positions[this]);
  20. };
  21.  
  22. // Is the hand clenched?
  23. var clenched;
  24. // These are the values for how much the servo should move if the hand is clenched or not. The values you need will depend a lot on how you assemble your MeArm
  25. var hand_on = 0.15;
  26. var hand_off = -0.2;
  27.  
  28. // On initialisation, set the MeArm up to it's default positions
  29. function onInit() {
  30. servos.shoulder.goto(-0.5);
  31. servos.elbow.goto(0);
  32. servos.base.goto(0);
  33. clenched = false;
  34. servos.hand.goto(hand_off);
  35. }
  36.  
  37. /* This is a simple scripted sequence of movements. The base is left alone, but the arm:
  38. * * Moves to it's starting position with an open gripper
  39. * * Reaches out
  40. * * Closes the gripper
  41. * * Returns to its original position
  42. * * Releases the gripper
  43. */
  44. function doGrab() {
  45. servos.shoulder.goto(-0.5);
  46. servos.elbow.goto(0);
  47. servos.hand.goto(hand_off);
  48. setTimeout(function() {
  49. servos.shoulder.goto(-1);
  50. servos.elbow.goto(-0.4);
  51. setTimeout(function() {
  52. servos.hand.goto(hand_on);
  53. setTimeout(function() {
  54. servos.shoulder.goto(-0.5);
  55. servos.elbow.goto(0);
  56. setTimeout(function() {
  57. servos.hand.goto(hand_off);
  58. }, 800);
  59. }, 500);
  60. }, 800);
  61. }, 800);
  62. }
  63.  
  64. /* As we're plugging the IR receiver right into 3 GPIO pins,
  65. we have to set them up to give it the power it needs */
  66. A1.write(1);
  67. A0.write(0);
  68.  
  69. /* Set up the IR receiver. The codes used here are the codes that we got
  70. from our remote control, so you'll have to use the codes shown by the
  71. `print("Unknown "+code)` statement below. */
  72. require("IRReceiver").connect(C3, function(code) {
  73. switch (code) {
  74. case "111100000111000000100000010111111": onInit(); break; // power
  75. case "111100000111000000101100010100111": doGrab(); break; // menu - start 'grab' sequence
  76. case "111100000111000000100100010110111": servos.elbow.move(0.1); break; // ch +
  77. case "111100000111000000000100011110111": servos.elbow.move(-0.1); break; // ch -
  78. case "111100000111000001010011001011001": servos.base.move(-0.1); break; // left
  79. case "111100000111000000100011010111001": servos.base.move(0.1); break; // right
  80. case "111100000111000000000011011111001": servos.shoulder.move(0.1); break; // up
  81. case "111100000111000001000011001111001": servos.shoulder.move(-0.1); break; // down
  82. case "111100000111000000001011011101001": clenched = !clenched;
  83. servos.hand.goto(clenched ? hand_on : hand_off); break; // ok
  84. default: print("Unknown "+code);
  85. }
  86. });
  87.  
  88. // Finally, initialise
  89. onInit();

Credits

Photo of Espruino

Espruino

Espruino, Espruino Pico and Puck.js are low-power Microcontrollers that run JavaScript. Espruino is a JavaScript Interpreter for Microcontrollers that is designed to make development quick and easy. The Espruino interpreter is firmware that runs on a variety of different microcontrollers, but we also make Espruino Boards that come with the interpreter pre-installed and are the easiest devices to get started with. However Espruino itself isn't just the interpreter firmware or hardware - there's also the Web IDE, command-line tools, documentation, tutorials, and modules that form a complete solution for embedded software development.

   

Leave your feedback...