DIY Handmade Hexapod With Arduino (Hexdrake)

by Deividmaxx in Circuits > Arduino

156962 Views, 726 Favorites, 0 Comments

DIY Handmade Hexapod With Arduino (Hexdrake)

2013-10-06 11.56.36.jpg
2013-10-06 11.54.28.jpg
2013-10-06 11.55.51.jpg
2014-05-03 11.17.52.jpg
2014-05-03 11.18.03.jpg
2014-05-03 11.18.27.jpg

Hello, I'm David and in this instructable I'll show how I made this hexapod whose name is Hexdrake.

Since I was 16 I became interested in electronic and later in robotics. After getting some level and programming skills using arduino I decided to build a robot something more interesting than a simple robot with two wheels . I liked the idea of having a hexapod but did not have much money to buy one.

So I built a low cost 2DOF hexapod made with hand-cut wood and Sg90 servos.

Parts Needed

2014-04-17 09.52.12.jpg
2014-04-17 09.52.50.jpg
2014-04-17 09.53.42.jpg
2014-04-17 09.53.58.jpg
2014-04-17 09.54.13.jpg
2014-04-17 10.01.33.jpg

Designing the Parts and Making the Templates

sg90servo02.jpg
2014-03-27 20.07.05.jpg
2014-03-27 20.07.41.jpg
2014-03-27 20.07.56.jpg
2014-03-27 20.08.13.jpg
P1752_05-04-13.JPG
P2100_17-03-13.JPG
P2007_23-03-13.JPG
P2101_17-03-13.JPG
P2116_25-03-13.JPG

I designed the pieces according to the size of SG90 servos. The CAD file is only for reference. I designed the templates before on paper. I used a sheet of wood about 3 mm of thick. After having the templates the next step is to pass them on to the wooden board.

According to the size of the servo the number of pieces are:

48x A part

6x B

12x C

12x D

12x E

12x F

12x G

12x H

6x I

2x J


Time to Cut!!!

P1758_10-03-13.JPG
P2055_13-03-13.JPG
P1759[01]_10-03-13.JPG
P2055[02]_13-03-13.JPG
P1826_14-03-13.JPG
P1940_23-03-13.JPG
P1240_24-03-13.JPG
P1823[01]_20-03-13.JPG
P1823_20-03-13.JPG
P2043[01]_23-03-13.JPG
P1811_24-03-13.JPG
P1845[01]_24-03-13.JPG
P1811[01]_24-03-13.JPG
P1845_24-03-13.JPG
P1108_26-03-13.JPG
P1307[01]_26-03-13.JPG
P1835_05-04-13.JPG

Tools for this Step:

Saw, lime, electric dril and a good hand.

Before cutting some pieces is easier to drill the holes using a 3mm drill. I advise to use a fine saw to cut all the pieces accurately. After cutting each piece file the edges to be soft.

Glue Certain Parts Between Them

P2054_13-03-13.JPG
P2055[01]_13-03-13.JPG
P2124_16-03-13.JPG
P1826_14-03-13.JPG
P1050_27-03-13.JPG
P1138_28-03-13.JPG
P1051_27-03-13.JPG
P1822_20-03-13.JPG
P1939_23-03-13.JPG
P1326_24-03-13.JPG
P1455_20-03-13.JPG
P2043_23-03-13.JPG
P1953[01]_20-03-13.JPG
P1953_20-03-13.JPG
P1948_24-03-13.JPG
P1940[01]_23-03-13.JPG
P1744_25-03-13.JPG
P1851_25-03-13.JPG
P1500_26-03-13.JPG
P1049_27-03-13.JPG

Tools for this step:

Glue(cyanoacrylate glue for more strength), tweezers, toilet paper (to clean the excess glue).

To make the main parts of each leg, where the servos are subject I needed to glue 4 A pieces. Then, for each leg glue a piece B with C. And the last thing to be done is to glue two H pieces together.

*Be careful to align the holes well of certain pieces or can also be done is glue before and then do drills the holes.

Painting and Decorating

P1752_31-03-13.JPG
P1752[01]_31-03-13.JPG
P2031_31-03-13.JPG
P1249[01]_01-04-13.JPG
P1748_31-03-13.JPG
P1747_31-03-13.JPG
P1249_01-04-13.JPG
P1404_01-04-13.JPG
P2121_05-04-13.JPG

Materials and tools for this step:

EVA foam(red and black), glue, scissors, rule, pencil and black acrylic paint.

For a more professional finish I paint some of the pieces with black acrylic paint, and cover the body and legs with black and red EVA foam.

Attaching the Servos to the Legs and Body

P1209_01-04-13.JPG
P1800_31-03-13.JPG
P1911_02-04-13.JPG
P1923_02-04-13.JPG
P1923[01]_02-04-13.JPG
P2047_02-04-13.JPG
P2047[01]_02-04-13.JPG
P1820_03-04-13.JPG
P1821_03-04-13.JPG
P1822_03-04-13.JPG
P2110_02-04-13.JPG
P1829_03-04-13.JPG
P1840[01]_03-04-13.JPG
P1840[02]_03-04-13.JPG
P1840_03-04-13.JPG
P2115[01]_02-04-13.JPG
P2115_02-04-13.JPG
P1920[01]_03-04-13.JPG
P1920_03-04-13.JPG
P1949_03-04-13.JPG
P1808_04-04-13.JPG
P1908_04-04-13.JPG
P2150[01]_05-04-13.JPG
P2150_05-04-13.JPG
P2201[01]_05-04-13.JPG
P2201[02]_05-04-13.JPG
P2201[03]_05-04-13.JPG
P1937[02]_10-04-13.JPG
P1937_10-04-13.JPG
P2201_05-04-13.JPG
P2049[01]_25-07-13.JPG
P2049_25-07-13.JPG

Materials for this step:

A lot of screws, screwdriver and 12 SG-90 servos.

Add Electronics and Connect.

P1738_02-05-13.JPG
P1804_02-05-13.JPG
Captura.PNG
untitled22_zps0f8aaccc.png
Captura2.PNG
2014-03-23 18.19.53.jpg
2014-03-23 18.19.24.jpg
2013-09-27 13.58.58.jpg
2013-09-29 17.45.23.jpg
2013-09-29 17.45.15.jpg
2013-09-27 13.58.50.jpg
2013-10-04 11.33.55.jpg
2013-09-30 19.24.23.jpg
P1328_09-05-13.JPG
P1338_09-05-13.JPG
2013-10-06 11.42.10.jpg
P1803_04-05-13.JPG

Electronic:

An arduino. USC 16-channel servo controller, UBEC 8A hobbywing, lipo battery.

Power supply:

The servo controller needs two power supplies: servo power supply and chip power supply.

-Servo power supply (+): VS (left of the blue connecting terminal at Position 3 in the figure)
-Servo power supply (‐): GND (middle of the blue connecting terminal at Position 3 in the figure)

Servo power supply’s parameters depend on the parameters of the attached servo. For example, if the SG-90 servo has a power supply of 4V‐5V, the servo power supply can use the power source of 4‐5V.

-Chip power supply (+): VSS (right of the blue connecting terminal at Position 3 in the figure)

-Chip power supply (‐): GND (middle of the blue connecting terminal at Position 3 in the figure)

There is a VSS requirement of 6.5‐12V. If the chip power is input through the VSS port, the power supply has to range from 6.5 to 12V.

Connecting Arduino, USC and servos:

What is marked red in the figure are the servo’s connectors for signal wires (be careful about the direction when
connecting to the servo).

To connect the USC controller simply connect the rx of the USC to the tx of arduino and the tx pin with the rx pin of the USC. And connect GND pin of USC with arduino.


Programming

T2eC16ZUE9s3wDdZBRQtDhO5Gw60_57_zps44708a04.jpg
2014-03-23 18.20.12.jpg
Captura de pantalla 2014-03-31 19.53.14.png
2014-03-23 18.20.20.jpg

Software for this step:

Arduino IDE, USC sofware.

Before programming with arduino it's necessary to know the limits of all the servos and know the limits values. For example using the mouse to drag the slider in the servo panel (drag the servo panel corresponding to the channel with which the servo is connected). So connecting the USC inside the hexapod with the usb to the program I get all de max and min values of each servo.

Now is time to program the arduino to control the USC. The servo controller is a slave device, meaning that it can either accept commands or execute preset commands. It cannot think at all. Communication protocol: serial communication (TTL level), baud rate 9600, no check bit, 8 data bits, 1 stop bit To control the servo through the servo controller. The Command format are:

-Control one single servo:

#1P1500T100\r\n

Data 1 refers to the servo’s channel.

Data 1500 refers to the servo’ location, in the range 500‐2500.

Data 100 refers to the time of execution and represents the speed, in the range 100‐9999

-Control multiple servos:

#1P600#2P900#8P2500T100\r\n

Data 1, 2, and 8 refer to the servo’s channels

Data 600, 900, and 2500 refer to the locations of the servos that correspond to three channels

Data 100 refers to the time of execution and represents the speed of three servos. Regardless of the number of servos, there is only one time, or one T. The command is executed at the same time; that is, all servos operate simultaneously.

Within the limits of each servo is necessary to calculate the maximum range or "step" of all horizontal servos to find the smallest of them and convert it as the maximum of one step. And this variable enter into the equations of all movements. The same would have to make with the vertical servos.

*Sorry for the poor quality of the first three movies. I record them with an old mobile phone with poor video quality.

New video:

Adding Some Personality

P1813_11-04-13.JPG
P1800_12-04-13.JPG
Captura de pantalla 2014-03-31 20.19.07.png
P2057_23-04-13.JPG
P2142_23-04-13.JPG
P2205_23-04-13.JPG
P2231_23-04-13.JPG
P1903_25-04-13.JPG
P1904_25-04-13.JPG
P2010_29-04-13.JPG
P2010[01]_29-04-13.JPG
P1837_05-05-13.JPG
P1837[01]_05-05-13.JPG
P1911[01]_05-05-13.JPG
P1911_05-05-13.JPG
P1726[03]_08-05-13.JPG
P1726[02]_08-05-13.JPG
P1726_08-05-13.JPG
P1726[01]_08-05-13.JPG
P1609_17-05-13.JPG
20130825_163854.jpg
20130825_163843.jpg
P1725_27-05-13.JPG
P1727_27-05-13.JPG
P1746[01]_27-05-13.JPG
P1746_27-05-13.JPG
P1153_29-05-13.JPG
P1152[01]_29-05-13.JPG
P1152_29-05-13.JPG
P1522[01]_27-05-13.JPG
2013-09-17 19.22.11.jpg
2013-09-18 12.04.39.jpg
2013-09-20 20.12.44.jpg
2013-09-18 12.30.29.jpg
P1956_09-05-13.JPG
2013-09-20 15.19.19.jpg
2013-09-22 11.48.12.jpg

I was thinking about things I could add to my hexapod and one of the things that came to me were adding good eyes. I decided to add the eyes to hexapod to give more expression to the moves or express actions. I designed some sketches on paper of various shapes of eyes. In the end I decided on the design that you can see in the photos.

It's consists of a strip of 32 blue LEDs around the edge and a matrix of 5 rows and 9 columns of red LEDs. Thus the matrix can display various kinds of pupil and it's can move throughout the matrix.

Eyes Controller Board

20130903_102034.jpg
20130903_102042.jpg
20130904_165151.jpg
20130905_174221.jpg
20130905_180052.jpg
20130910_130617.jpg
20130910_130704.jpg
20130910_135258.jpg
20130910_154450.jpg
20130911_130431.jpg
20130911_130452.jpg
20130911_155354.jpg
20130911_155407.jpg
20130911_180658.jpg
20130912_105808.jpg
20130913_154912.jpg

To control both eyes I designed a simple first version control board using Inkscape. It's based on two atmega8 controlling both matrix directly. In future versions i will do an improved more effective board for complete control of the matrix and the strip of blue LEDs.

The first step is cut a piece of copper pcb the size of the design. Later cut the drilling template and place it in the copper pcb. This template marks the place where you have to make the holes for the components.
Now it's time to draw the tracks. I used a a sticker to mark the tracks. The next step is put the PCB in the acid and when done thoroughly clean the PCB. And the final step is solder the joystick and the resistor and put the decorative stickers.

*Sorry for the poor quality of this videos. I record them with an old mobile phone.

Adding a Jaw

P2138_16-07-13.JPG
P2139_16-07-13.JPG
P2139[01]_16-07-13.JPG
P2139[02]_16-07-13.JPG
P2140_16-07-13.JPG
P2140[01]_16-07-13.JPG
P1313_17-07-13.JPG
P1331_17-07-13.JPG
P1641_17-07-13.JPG
P2036_17-07-13.JPG
P2035_17-07-13.JPG
P1213_18-07-13.JPG
P1305_18-07-13.JPG
P1230[01]_20-07-13.JPG
P1230[02]_20-07-13.JPG
P1230_20-07-13.JPG
P1900_20-07-13.JPG
P1901_20-07-13.JPG
P1508_20-07-13.JPG
P2049[02]_25-07-13.JPG
P1246_28-07-13.JPG
P1246[01]_28-07-13.JPG
P1307[01]_28-07-13.JPG
P1307_28-07-13.JPG
P1935_01-08-13.JPG
P1934_01-08-13.JPG
P1943[01]_28-07-13.JPG
P1343_02-08-13.JPG
P1337_07-08-13.JPG
P1838[02]_08-08-13.JPG
P1838[01]_08-08-13.JPG
P1203_05-08-13.JPG
P1322_05-08-13.JPG
P1525[01]_05-08-13.JPG
P1525_05-08-13.JPG
P1756_05-08-13.JPG
P1757[01]_05-08-13.JPG
P1757_05-08-13.JPG
P1857[01]_08-08-13.JPG
P1857[02]_08-08-13.JPG
P1857_08-08-13.JPG
P1858_08-08-13.JPG
P1121_06-08-13.JPG
2013-11-15 13.13.45.jpg
20130810_174939.jpg
2013-09-30 18.08.31.jpg
2013-10-02 17.57.52.jpg
2013-10-06 11.41.37.jpg
2013-10-06 11.41.44.jpg

To make the jaw I did some previous designs in cardboard to find the most correct form for the hexapod. When I found the form, I made the jaw in a small block of aluminum from a heat sink. It is driven by two servos moving together. Later I added inside it a strip of rubber to increase it's grip, and paint and decorate as the same style of the hexapod.

Transport Box

P1112[01]_05-07-13.JPG
P1112_05-07-13.JPG
P0930_05-07-13.JPG
P2304_05-07-13.JPG
P2305_05-07-13.JPG
P1536_06-07-13.JPG
P1936_07-07-13.JPG
P1722_08-07-13.JPG
P1826[01]_09-07-13.JPG
P1826_09-07-13.JPG
P1041_10-07-13.JPG
20130812_130736.jpg
20130812_130746.jpg
20130813_135113.jpg
20130813_135103.jpg
20130812_121359.jpg
20130810_174907.jpg
20130811_134126.jpg
20130811_134134.jpg
20130812_121419.jpg
20130812_121432.jpg
20130813_142040.jpg
20130814_110347.jpg
20130814_110356.jpg
20130814_110452.jpg
20130814_134023.jpg
20130814_134041.jpg
P1110_14-07-13.JPG
P1112_14-07-13.JPG
P1530_13-07-13.JPG
P1722[01]_08-07-13.JPG
P2045_11-07-13.JPG
P1043[01]_10-07-13.JPG
P1043_10-07-13.JPG
20130811_135324.jpg
20130811_135318.jpg
20130814_134447.jpg
20130814_134456.jpg
20130811_134118.jpg

Final Result of the Hexapod

temp_596907643.jpg
temp_1916044631.jpg
temp_-367216001.jpg
temp_381408789.jpg
temp_560162641.jpg
temp_-811858118.jpg
temp_-784130926.jpg
temp_-1893288395.jpg
temp_-355960591.jpg

This is the final result of the hexapod. Now in the next step I will esplain how I mount the remote controller for Hexdrake. :)

Making the Joysticks Boards:

P1239_04-09-12.JPG
P1325_04-09-12.JPG
P1102_05-09-12.JPG
P1325[01]_04-09-12.JPG
P1128_05-09-12.JPG
P1700_11-09-12.JPG

Tools for this step:

Saw, lime. drill.

I designed these boards using Inkscape. These boards have the appropriate size for the original joysticks of the PS2 controllers. The main reason I designed these small boards is to simplify the connections between terminals of the potentiometers and the button incorporated with the arduino boards. The board includes a 10k ohm resistor, making the connection between the button and the arduino only needs a cable.

The first step is cut a piece of copper pcb the size of the design. Later cut the drilling template and place it in the copper pcb. This template marks the place where you have to make the holes for the components.

Now it's time to draw the tracks. I used a a sticker to mark the tracks. The next step is put the PCB in the acid and when done thoroughly clean the PCB. And the final step is solder the joystick and the resistor and put the decorative stickers.

The screw terminal blocks conections are:

GND ---> GND of arduino

Vin ------> 5V of arduino

X ------> The x-axis potentiometer to an analog pin of arduino(for example A0)

Y ------> The y-axis potentiometer to an analog pin of arduino(for example A1)

B ------> Connect the button to a digital pin of arduino.(For example D8)

How to Use the 2.4GHz Modules?:

images.jpg
Arduino uno con modulo 2.4_bb.jpg
2014-04-17 09.49.38.jpg
Arduino nano con modulo 2.4_bb.jpg
2014-04-17 09.46.35.jpg
2014-04-17 09.48.48.jpg
24L01Pinout-800.jpg

I use two nRF24L01 2.4GHz Radio/Wireless Transceivers to comunicate the two arduinos. The range of this modules are from 50 feet to 2000 feet distances. These 2.4 GHz Radio modules are based on the Nordic Semiconductor nRF24L01+ chip. The Nordic nRF24L01+ integrates a complete 2.4GHz RF transceiver, RF synthesizer, and baseband logic including the Enhanced ShockBurst hardware protocol accelerator supporting a high-speed SPI interface. These low-power short-range modude have a built-in Antenna.

These transcevers use the 2.4 GHz unlicensed band like many WiFi routers, some cordless phones etc.These module send and receive data in 'packets' of several bytes at a time. There is built-in error correction and resending, and it is possible to have one unit communicate with up to 6 other similar units at the same time. The pinout as shown in diagram tha you can see in the photos and a table with the coneections to diferent models of arduinos.

*IMPORTANT* :These modules VCC connection must go to 3.3V not 5.0V

I will show an example of transmit and receive software below for one joystick:

Transmiter:

<p>/* <br>- WHAT IT DOES: Reads Analog values on A0, A1 and transmits
them over a nRF24L01 Radio Link to another transceiver.
1 - GND
2 - VCC 3.3V !!! NOT 5V
3 - CE to Arduino pin 9
4 - CSN to Arduino pin 10
5 - SCK to Arduino pin 13
6 - MOSI to Arduino pin 11
7 - MISO to Arduino pin 12
8 - UNUSED
- Analog Joystick:</p><p>GND to Arduino GND<br>VCC to Arduino +5V
X Pot to Arduino A0
Y Pot to Arduino A1
*/
/*-----( Import needed libraries )-----*/
#include <SPI.h></p><p>#include <nRF24L01.h></p><p>#include <RF24.h></p><p>/*-----( Declare Constants and Pin Numbers )-----*/<br>#define CE_PIN 9
#define CSN_PIN 10
#define JOYSTICK_X A0
#define JOYSTICK_Y A1</p><p>
// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
<br></p><p>/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/*-----( Declare Variables )-----*/
int joystick[2]; // 2 element array holding Joystick readings</p><p>
void setup() /****** SETUP: RUNS ONCE ******/
{
     Serial.begin(9600);
     radio.begin();
      radio.openWritingPipe(pipe);
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
       joystick[0] = analogRead(JOYSTICK_X);
       joystick[1] = analogRead(JOYSTICK_Y);
       radio.write( joystick, sizeof(joystick) );
}//--(end main loop )--</p>

Receiver:

<p>/*<br>- WHAT IT DOES: Receives data from another transceiver with
2 Analog values from a Joystick
Displays received values on Serial Monitor
1 - GND
2 - VCC 3.3V !!! NOT 5V
3 - CE to Arduino pin 9
4 - CSN to Arduino pin 10
5 - SCK to Arduino pin 13
6 - MOSI to Arduino pin 11
7 - MISO to Arduino pin 12
8 - UNUSED</p><p>
/*-----( Import needed libraries )-----*/
#include <SPI.h></p><p>#include <nRF24L01.h></p><p>#include <RF24.h></p><p>/*-----( Declare Constants and Pin Numbers )-----*/<br>#define CE_PIN 9
#define CSN_PIN 10</p><p>
// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe</p><p>
/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio</p><p>
/*-----( Declare Variables )-----*/
int joystick[2]; // 2 element array holding Joystick readings</p><p>
void setup() /****** SETUP: RUNS ONCE ******/
{
    Serial.begin(9600);
    delay(1000);
    Serial.println("Nrf24L01 Receiver Starting");
    radio.begin();
    radio.openReadingPipe(1,pipe);
    radio.startListening();;
}//--(end setup )---</p><p>
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
   if ( radio.available() )
   { // Read the data payload until we've received everything
       bool done = false;
      while (!done)
      { // Fetch the data payload
           done = radio.read( joystick, sizeof(joystick) );
          Serial.print("X = ");
          Serial.print(joystick[0]);
          Serial.print(" Y = ");
          Serial.println(joystick[1]);
      }
  }
  else </p><p>  { </p><p>       Serial.println("No radio available");
  }
}//--(end main loop )---</p>

Connecting the Joystick and the Linear Potentiometer:

Mando sin el accelerometro_bb.jpg
2014-04-17 09.56.38.jpg
2014-04-17 09.57.19.jpg
2014-04-17 09.59.37.jpg
2014-04-17 11.13.18.jpg
2014-04-17 10.25.49.jpg
2014-04-17 11.26.23.jpg
2014-04-17 11.33.25.jpg
2014-04-17 11.26.29.jpg
2014-04-17 11.33.15.jpg

To make the prototype of the controller I use a breadboard to connect everything. I have attached the boards of the joysticks and the linear potentiometer elastic bands jaja. I first thought of making a prototype with all elements before modifying a PS2 controller adding them the accelerometer, linear potentiometer, etc..

Simply connect the x,y GND and Vin terminals of both joystick to de 5v, GND, A0 and A1 pins of arduino. And the linear pot in the same way.

How to Use the MMA7361 Accelerometer?:

Arduino_MMA7361L.jpg
2014-04-25 17.15.22.jpg
2014-04-25 17.15.32.jpg
2014-04-25 17.17.02.jpg
2014-04-25 17.16.56.jpg
2014-05-01 11.42.05.jpg
2014-05-01 11.43.11.jpg
Captura de pantalla 2014-05-01 11.42.55.png
Captura de pantalla 2014-05-01 11.43.22.png

It's a breakout board for Freescale’s MMA7361L three-axis analog MEMS accelerometer. The sensor requires a very low amount of power and has a g-select input which switches the accelerometer between ±1.5g and ±6g measurement ranges. Other features include a sleep mode, signal conditioning, a 1-pole low pass filter, temperature compensation, self test, and 0g-detect which detects linear freefall. Zero-g offset and sensitivity are factory set and require no external devices.

It's specifications are:

  • Supports 2.2V ~ 3.6V or 5V voltage input.
  • Two selectable measuring ranges (±1.5g, ±6g)
  • Breadboard friendly - 0.1" pitch header
  • Low current consumption: 400 µA
  • Sleep mode: 3 µA
  • Low voltage operation: 2.2 V - 3.6 V
  • High sensitivity (800 mV/g at 1.5g)
  • Fast turn on time (0.5 ms enable response time)
  • Self test for freefall detect diagnosis
  • 0g-Detect for freefall protection
  • Signal conditioning with low pass filter
  • Robust design, high shocks survivability

With the AcceleroMMA7361 library it's so easy to use this tiny module. The commands you can use with this library are:

  • void begin ()
  • void begin (int sleepPin, int selfTestPin, int zeroGPin, int gSelectPin, int xPin, int yPin, int zPin)
  • int getXRaw ()
    • getXRaw(): Returns the raw data from the X-axis analog I/O port of the Arduino as an integer
  • int getYRaw ()
    • getYRaw(): Returns the raw data from the Y-axis analog I/O port of the Arduino as an integer
  • int getZRaw ()
    • getZRaw(): Returns the raw data from the Z-axis analog I/O port of the Arduino as an integer
  • int getXVolt ()
    • getXVolt(): Returns the voltage in mV from the X-axis analog I/O port of the Arduino as a integer
  • int getYVolt ()
    • getYVolt(): Returns the voltage in mV from the Y-axis analog I/O port of the Arduino as a integer
  • int getZVolt ()
    • getZVolt(): Returns the voltage in mV from the Z-axis analog I/O port of the Arduino as a integer
  • int getXAccel ()
    • getXAccel(): Returns the acceleration of the X-axis as a int (1 G = 100.00)
  • int getYAccel ()
    • getYAccel(): Returns the acceleration of the Y-axis as a int (1 G = 100.00)
  • int getZAccel ()
    • getZAccel(): Returns the acceleration of the Z-axis as a int (1 G = 100.00)
  • void getAccelXYZ (int _XAxis, int _YAxis, int _ZAxis)
    • getAccelXYZ(int _XAxis, int _YAxis, int _ZAxis) returns all axis at once as pointers
  • int getTotalVector ()
    • getTotalVector returns the magnitude of the total acceleration vector as an integer
  • void setOffSets (int xOffSet, int yOffSet, int zOffSet)
  • void calibrate ()
  • void setARefVoltage (double _refV)
  • void setAveraging (int avg)
    • setAveraging(int avg): Sets how many samples have to be averaged in getAccel default is 10.
  • int getOrientation ()
  • void setSensitivity (boolean sensi)
    • setSensitivity sets the sensitivity to +/-1.5 G (HIGH) or +/-6 G (LOW) using a boolean HIGH (1.5 G) or LOW (6 G)
  • void sleep ()
    • sleep lets the device sleep (when device is sleeping already this does nothing)
  • void wake ()
    • wake enables the device after sleep (when device is not sleeping this does nothing) there is a 2 ms delay, due to enable response time (datasheet: typ 0.5 ms, max 2 ms)

The library have 3 simple examples. One gets the accelerations in each axis, the second gets the angle and the third the voltage. I used the "RawData" to get the angle of each axis othe controller to control the inclination:

<p>#include <AcceleroMMA7361.h></p><p>AcceleroMMA7361 accelero;
int x;
int y;
int z;
void setup()
{
    Serial.begin(9600);
    accelero.begin(8, 7, 6, 5, A5, A6, A7);
    accelero.setSensitivity(HIGH);//sets the sensitivity to +/-6G
    accelero.calibrate();
}</p><p>
void loop()
{
    x = accelero.getXRaw();
    y = accelero.getYRaw();
    z = accelero.getZRaw();
   Serial.print("\nx: ");
   Serial.print(x);
   Serial.print("\ty: ");
   Serial.print(y);
   Serial.print("\tz: ");
   Serial.print(z);
   delay(500); //(make it readable)
}</p>

Put All Together:

Mando conpleto_bb.jpg
2014-04-28 20.55.01.jpg
2014-04-27 11.52.45.jpg
2014-04-27 11.52.52.jpg
2014-04-28 20.54.41.jpg
2014-04-27 12.04.16.jpg
2014-04-28 20.54.49.jpg

All that remains is to place the accelerometer on the remote controller and connect it to the arduino nano as in the previous step.

Now it's time to program!!!

Programming the Remote Controller:

2014-04-27 11.26.00.jpg
2014-04-27 11.26.07.jpg
2014-03-23 18.20.20.jpg
Captura de pantalla 2014-05-01 12.20.58.png
Captura de pantalla 2014-05-01 12.21.20.png
Captura de pantalla 2014-05-01 12.21.36.png
Captura de pantalla 2014-05-01 12.21.37.png
Captura de pantalla 2014-05-01 12.21.39.png
Captura de pantalla 2014-05-01 12.21.41.png

Using all prior learning of each module only need to adapt the programs to the characteristics of the remote control by linking in two programs: one for the arduino remote control works as a transmitter and another program for arduino hexapod operates as a receiver.

According to the motion limits of the servos, that I got from my previous instructable, you must use the map command arduino to convert the values of the potentiometers and the accelerometer within the minimum limit range values of motion of the servos. Being as follows:

<p>values[0] = map(values[0], 23, 1000, 900, 1500); //Value from slider pot<br>values[1] = map(values[1], 23, 1000, 2100, 1540); //Value from slider pot
values[3] = map(values[3], 1, 1033, -295, 295); //Value from y-axis of right joystick
values[4] = map(values[4], 1, 1023, -295, 295); //Value from y-axis of left joystick
values[5] = map(values[5], 1, 1023, -360, 360); //Value from x-axis of left joystick
values[6] = map(values[6], 170, 500, -360, 360); //Value from x-axis of the accelerometer
values[7] = map(values[7], 170, 510, -360, 360); //Value from y-axis of the accelerometer</p>

Using one of the buttons on one of the joysticks I wanted to use the example shown on arduino page that consists in counting the number of times that a button is pressed to create various modes in which the hexapod will move.
http://arduino.cc/en/Tutorial/ButtonStateChange

<p>/* State change detection (edge detection)<br>This example shows how to detect when a button or button changes from off to on
and on to off.
*/
// this constant won't change:
const int buttonPin = 2; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to</p><p>// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button</p><p>void setup() {
   // initialize the button pin as a input:
   pinMode(buttonPin, INPUT);
   // initialize the LED as an output:
   pinMode(ledPin, OUTPUT);
   // initialize serial communication:
   Serial.begin(9600);
}</p><p>void loop() {
   // read the pushbutton input pin:
   buttonState = digitalRead(buttonPin);
   // compare the buttonState to its previous state
   if (buttonState != lastButtonState) {
   // if the state has changed, increment the counter
   if (buttonState == HIGH) {
   // if the current state is HIGH then the button
   // wend from off to on:
   buttonPushCounter++;
   Serial.println("on");
   Serial.print("number of button pushes: ");
   Serial.println(buttonPushCounter);
}
else {
   // if the current state is LOW then the button
   // wend from on to off:
   Serial.println("off");
 }
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (buttonPushCounter % 4 == 0) {
digitalWrite(ledPin, HIGH);
  } else {
   digitalWrite(ledPin, LOW);
  }
}</p>

I convert this example and adapt to my sketchs of the remote controller and to the receptor. So
So I create three modes of movements:

  • The first one allows the linear potentiometer and joysticks move the hexapod
  • The second allows joysticks, the potentiometer and accelerometer move the hexapod
  • And the last mode let move hte hexapod walk, walk backwards,etc moving the two joystick simultaneously