Bajdi electronics

Hobby electronics website

Browse: Page 17

Building another hexapod: Bajdupod 996R

By Bajdi on January 27, 2013

Hexapod chassis kit

Hexapod chassis kit

I’ve started building my second hexapod, Bajdupod 996R. The 996R part of the name comes from the servos I’m using, I bought 30 Towardpro MG996R servos on Ebay many months ago. I only need 18 for this hexapod so I have some spare servos. Always a good idea, I destroyed several servos while building my previous hexapod.
I was originally planning on designing the hexapod myself. But then I found a Chinese made hexapod kit on Ebay, I couldn’t make the parts for the price of the kit so…
The kit only included the parts shown in the picture above. All the parts are made from low quality aluminum. I was a bit surprised when the kit arrived. The chassis was a bit smaller then I expected. But maybe that’s not so bad, the bigger/heavier the hexapod the more strain on the servos. My first hexapod was a bit problematic in that regard. This time I have chosen to use some more powerful servos, the MG996R servos have +10kg/cm of torque. I hope they are strong enough.

Towardpro mg996R servos

Towardpro mg996R servos

To power 18 MG996R servos you need a strong battery. So I bought a big 3S 3000mAh Lipo battery. The servos work at a maximum voltage of 6-7V so I needed a big voltage regulator, I chose to use 2 8A UBECs. These UBECs use switching regulators and they seem to work better at higher voltages. That’s why I chose a 3S Lipo instead of a 2S. I soldered some connectors and a fuse to a big switch (bought from Tayda Electronics) to hook up the UBECs and Lipo battery. This is the result:

UBEC

UBEC

To connect the power from the 2 UBECs to the servos I have designed a small PCB (50mm x 50mm). I had it made by Seeed Studio. I has enough pins to connect 24 servos. And it has some spare pins so I can use also power other things from the board. The power traces on the board are very wide (100mils) as 18 servos will draw quite a bit of current. I put 2 big electrolytic caps (2200ยตF) and 4 0,1ยตF ceramic capacitors on the board. UBECs can produce quite a bit of electric noise. I hope the capacitors will minimize that.

Servo board

Servo board

After getting all the parts it was time to put them together. I needed a lot of M3 screws to connect all the brackets and servos. Luckily I have a big stock of M3 screws in various lengths. It took me several hours to put all the parts together.

Hexapod bajdupod 996R

Hexapod bajdupod 996R

I have currently mounted an Arduino Mega 2560 with a sensor shield on the top chassis plate. I’ve connected all the servos to my servo board. Then I used a strip of flat cable with Dupont connectors to connect the servo board with the Arduino Mega 2560. The Mega has its own power supply, a small 2S lipo battery. You can control 48 servos with the Arduino servo library on an Arduino Mega. I may change the Arduino Mega for one of my self designed boards and use my Torobot 32 channel serial servo controller.
My goal is to program the robot using inverse kinematics. I found a good explanation on this website. It’s the best information I have found so far. Still it will be quite a challenge to program the hexapod and make a smooth walking gait for it. I hope to remote control it through a couple of wireless nRF24L01 modules.

Posted in Bajdupod 996R | Tagged hexapod, robot | 8 Responses

MAG3110 magnetometer and Arduino

By Bajdi on January 15, 2013

mag3110 magnetometer

mag3110 magnetometer

I got this MAG3110 magnetometer on Ebay, it came on a small break out board. This is not a sensor you want to solder by hand, it comes in a tiny 10 pin DFN package.
The MAG3110 is a three axis digital magnetometer made by Freescale. The readings of a magnetometer can be used to calculate the heading, so we have a digital compass. These devices used to be expensive and a lot bigger then they are now. Lots of smart-phones and tablets are now fitted with magnetometers, these sensors are now produced by the millions meaning that you now can find them on Ebay at affordable prices.
The MAG3110 uses the I2C bus to communicate with a micro controller. It works at voltages between 1.95 and 3.6V. The SDA and SCL lines must be between -0.3 and +0.3 of the input voltage according to the datasheet. I connected the sensor to my Bajduino Mega 3A board, it has an ATmega1284P-PU running at 5V and a logic level converter for the I2C bus. The logic level converter shifts the 5V I2C bus of the ATmega to 3.3V. Do not connect the sensor to a 5V Arduino I2C bus, it might work but for how long is another question.
After receiving the sensor I started searching for an Arduino library. Unfortunately I could not find one. The only thing I did find was an example sketch to get the raw readings of the sensor on the sparkfun website. I copied the sketch and tried to compile it. The compiler did not like it, it gave a bunch of errors that I had seen before. The sketch is a couple of years old and has not been updated for the revised Arduino Wire (I2C) library. Since Arduino 1.0 some changes were made to the Wire library so the sketch was not compatible any more. I quickly made some changes to make it work with the latest Arduino IDE. I’m using Arduino 1.0.3.
You can download the sketch here: MAG3110 sketch

The above sketch is useful to check if your sensor works but it will not give you a compass heading. The sketch only prints the raw values of the sensor. To calculate the heading you first need to calibrate the sensor. This is done by determining the sensor offsets for every axis. The sensor offsets must be sent to the sensor over the I2C bus. After this is done the sensor will take the offset values in to account. Then we can read from the sensor and calculate the heading using the scale factors (which are calculated from the offsets).

My goal was to write a sketch to do this using the Arduino Wire library but so far I have not succeeded in doing that ๐Ÿ™

After browsing lots of web pages I found an Arduino sketch to calibrate the MAG3110 and determine the heading on this blog. One problem, the sketch does not use the Arduino Wire library, the person who made the sketch has written his own I2C Arduino library. Hats off ๐Ÿ™‚
You can download the library here: http://users.soe.ucsc.edu/~karplus/Arduino/libraries/i2c/
The sketch I found also included code for an accelerometer. I copied the sketch and deleted all the code for the accelerometer. I was then able to calibrate the sensor and calculate the heading. Woohoo ๐Ÿ™‚
You can download the sketch here: MAG3110 calibration.
I then wrote a simpler sketch that uses the offsets which I measured during the calibrating and calculates the heading.
So now I have a working piece of compass code which I can use in my robot sketches ๐Ÿ™‚ I will take another shot at rewriting the sketch with the Arduino Wire library at a later time.
Here is the sketch:

// http://www.bajdi.com
// MAG3110 Compass sketch
// Used code found here: http://users.soe.ucsc.edu/~karplus/Arduino/accel_magnet/
// This sketch will print the heading calculated from the readings of a MAG3110 sensor

#include <i2c.h> // Use I2C library found here: http://users.soe.ucsc.edu/~karplus/Arduino/libraries/i2c/

#define degrees_per_radian  (180./3.14159265358979)

// minimum and maximum values seen during calibration time
int16_t mag_low_x = 2411; 
int16_t mag_high_x = 3254;
int16_t mag_low_y = -3201;
int16_t mag_high_y = -2227;
int16_t mag_low_z = -581;
int16_t mag_high_z = 189;

// I2C 7-bit address of the magnetometer
#define MAG_3110_I2C  0x0E

// registers on the magnetometer
#define MAG_3110_DR_STATUS 0x00

// add 1 for LSB
#define MAG_3110_OUT_X_MSB 0x01
#define MAG_3110_OUT_Y_MSB 0x03
#define MAG_3110_OUT_Z_MSB 0x05

// add 1 for LSB  // user offset
#define MAG_3110_OFF_X_MSB 0x09
#define MAG_3110_OFF_Y_MSB 0x0B
#define MAG_3110_OFF_Z_MSB 0x0D

#define MAG_3110_CTRL_REG1 0x10
#define MAG_3110_CTRL_REG2 0x11

// Fields in registers
// CTRL_REG1: dr2,dr1,dr0  os1,os0  fr tm ac

// Sampling rate 80Hz 
#define MAG_3110_SAMPLE80 0

// How many samples to average (lowers data rate)
#define MAG_3110_OVERSAMPLE1 0
#define MAG_3110_OVERSAMPLE2 0x08
#define MAG_3110_OVERSAMPLE3 0x10
#define MAG_3110_OVERSAMPLE4 0x18

// put in active mode
#define MAG_3110_ACTIVE 0x01  

// CTRL_REG2: AUTO_MRST_EN  _ RAW MAG_RST _ _ _ _ _
// reset sensor after each reading
#define MAG_3110_AUTO_MRST_EN 0x80

// DR_STATUS Register ZYXOW ZOW YOW XOW ZYXDR ZDR YDR XDR
#define MAG_3110_ZYXDR	0x08

#define mag_write_reg(r,v)   (i2cWriteRegister(MAG_3110_I2C,r,v))
#define mag_read_reg(r)      (i2cReadRegister(MAG_3110_I2C,r))

inline uint8_t mag_data_ready(void)
{   return mag_read_reg(MAG_3110_DR_STATUS) & MAG_3110_ZYXDR;
}

void mag_read_xyz(int16_t&x, int16_t&y, int16_t&z)
{
    while (!mag_data_ready()) {} // wait for new set of data
    
    static uint8_t data[6];
    i2cReadRegisters(MAG_3110_I2C, MAG_3110_OUT_X_MSB, 6, data);
    x = (data[0]<<8) + data[1];
    y = (data[2]<<8) + data[3];
    z = (data[4]<<8) + data[5];
}

void mag_set_offsets(void)
{  
    int16_t mag_x_offset = (mag_low_x+mag_high_x)/2;
    int16_t mag_y_offset = (mag_low_y+mag_high_y)/2;
    int16_t mag_z_offset = (mag_low_z+mag_high_z)/2;
    static uint8_t data[6];
     
    data[0]=mag_x_offset>>7;    data[1]=(mag_x_offset<<1)& 0xFF;
    data[2]=mag_y_offset>>7;    data[3]=(mag_y_offset<<1)& 0xFF;
    data[4]=mag_z_offset>>7;    data[5]=(mag_z_offset<<1)& 0xFF;
     
    i2cWriteRegisters(MAG_3110_I2C, MAG_3110_OFF_X_MSB, 6, data);
}

void print_heading(int16_t x, int16_t y, int16_t z)
{     
  float mag_x_scale = 1.0/(mag_high_x-mag_low_x);
  float mag_y_scale = 1.0/(mag_high_y-mag_low_y);
  
  
  float heading = atan2(-y*mag_y_scale,x*mag_x_scale);  
  if(heading < 0)
  {
  heading += 2*PI;  // correct for when the heading is negative
  }
  float headingDegrees = heading * degrees_per_radian;  // convert to degrees
 
        Serial.print("headingDegrees = " );
        Serial.print(headingDegrees);
        Serial.println();
}

void mag_setup(void)  
{      
    mag_write_reg(MAG_3110_CTRL_REG2, MAG_3110_AUTO_MRST_EN);
    mag_write_reg(MAG_3110_CTRL_REG1, MAG_3110_SAMPLE80+MAG_3110_OVERSAMPLE1+MAG_3110_ACTIVE);
    mag_set_offsets();
}

void setup(void)
{
    Serial.begin(115200);

    i2cInit();
    i2cSetBitrate(100);  // try 100kHz
    delay(20);
    mag_setup();   
    delay(50);
}

void loop(void)
{
    int mag_x,mag_y,mag_z;   
    mag_read_xyz(mag_x,mag_y,mag_z);  // read from sensor
    print_heading(mag_x,mag_y,mag_z);  // print the heading
}

Download it here: MAG3110 compass sketch

The sketch works but will only give an accurate heading when the sensor is level. For this reason magnetometers are used in combination with an accelerometer to measure the tilt angle and compensate the reading of the magnetometer. That way you can still get an accurate heading when the sensor is not level.
This is the second magnetometer that I have bought. I already own a board with 3 sensors including a HMC5883L magnetometer and a ADXL345 accelerometer. The HMC5883L is more popular in the Arduino community and cheaper. I have used the board on my Rover 5 and even made a video of it.

Posted in Arduino sketches | Tagged I2C | 18 Responses

Made some lipo to robot connectors

By Bajdi on January 14, 2013

Lipo battery to screw terminal with switch

Lipo battery to screw terminal with switch

All the robots I have built so far have been powered by Lipo batteries. I chose Lipo batteries because they are very powerful (they can discharge very fast) and pretty compact for their capacity. That’s why lipo batteries are used in remote controlled scale helicopters, airplanes, cars, …

Lipos don’t cost that much any more, you can find small 2S batteries for less then 10$ on Ebay. They are strong enough to power a small robot. I have bought a whole bunch of 2S and 3S batteries last year.
Because of their low internal resistance lipos can provide a very high discharge current. So it’s best not to short cut them. You run the risk of damaging the battery and they could explode. Search youtube for “lipo explosion” to see some sensational videos ๐Ÿ˜€

So its best to treat them carefully. Only charge them with a charger suited for lipo batteries. Don’t discharge them to low, minimal cell voltage should be kept above 3V. I usually charge them a bit sooner just to be safe. On all my robots I have used a voltage divider to monitor the battery voltage.

The PCB’s I’ve designed until now have screw terminals to connect a power supply. All my Lipo batteries have male connectors, so I first bought some female connectors and soldered some wires to them. Disconnecting the XT60 or JST connectors all the time to turn of the robot is not very handy. So I added a switch and a fuse to connect the lipos to my robots. My small lipo batteries have JST connectors, the bigger ones have XT60 connectors. I soldered female connectors to short pieces of wire. I added a switch which I bought from Tayda Electronics. To protect the battery I also added a fuse in the positive wire. I bought some small in line fuses at Tayda Electronics and some mini blade fuses on Ebay. I use a 10A fuse on my Rover 5, my small hexapod uses a 5A fuse.

Posted in Buying parts | Tagged robot | Leave a response

« PreviousNext »

Recent Posts

  • 3D Printer extruders
  • Mearm forked
  • Arduino time lapse – camera pan device
  • Bought a 199$* Prusa I3 3D printer
  • Simple DIY lab power supply
  • Bajduino
    • Bajduino 1284
    • Bajduino 328
  • Stepper robot arm

Recent Comments

  1. 200+ Arduino Projects List For Final Year Students - He Loves Math on Obstacle avoiding robot made from cheap parts
  2. MP3 Alarm Clock: Crafting Customized wake-Up tunes with Arduino on Arduino MP3 alarm clock
  3. Bas on L9110 H-bridge module
  4. Victor on L9110 H-bridge module
  5. WAQAR AHMED on Dimming led with IR remote control

Archives

  • June 2016
  • August 2015
  • May 2015
  • January 2015
  • December 2014
  • November 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011

Categories

  • 3D printing
  • Arduino
  • Arduino sketches
  • Bajdupod 996R
  • Bajdupod 9G
  • Bob the biped
  • Buying parts
  • Dagu Rover 5
  • Dagu service droid
  • Gentoo
  • Insectbot
  • Line following robot
  • Raspberry Pi
  • Self balancing bot
  • Bajduino
    • Bajduino 1284
    • Bajduino 328
  • Stepper robot arm

Copyright © 2026 Bajdi electronics.

Powered by WordPress and Hybrid by Bajdi.