/* Control the MCP42XXX series of digital potentiometers. */
class MCP42XXX
{ protected:
byte ss;
byte clk;
byte mosi;
void spi_transfer( byte val )
{ int i;
digitalWrite( this->clk, LOW );
for( i=1; i<=8; ++i )
{ if( val > 127 )
digitalWrite( this->mosi, HIGH );
else
digitalWrite( this->mosi, LOW );
digitalWrite( this->clk, HIGH );
val = val << 1;
digitalWrite( this->clk, LOW );
}
}
public:
/* Set the ss (Slave Select), clk (clock) and
mosi (Master Output Slave Input) pins. */
MCP42XXX( byte ss, byte clk, byte mosi )
{ this->ss = ss;
this->clk = clk;
this->mosi = mosi;
pinMode( this->ss, OUTPUT );
pinMode( this->clk, OUTPUT );
pinMode( this->mosi, OUTPUT );
digitalWrite( this->ss, HIGH );
digitalWrite( this->clk, HIGH );
this->set( 2, 127 );
}
/* Select the potentiometer to control and set the value.
If pot = 0 set value for potentiometer 0, if pot = 1 set
value for potentiometer 1, if pot = 2 set value for both
potentiometers.
val can go from 0 to 255. */
void set( byte pot, byte val )
{ byte pot_code;
switch( pot )
{ case 0: pot_code = B00010001;
break;
case 1: pot_code = B00010010;
break;
case 2: pot_code = B00010011;
break;
default:
return;
};
digitalWrite( this->ss, LOW );
this->spi_transfer( pot_code );
this->spi_transfer( val );
digitalWrite( this->ss, HIGH );
}
};
Friday, September 4, 2009
MCP42XXX digital potentiometer
It took me a while to figure out how to use the MCP42100 digital pot ic chips to work. Here is the code I use.
Tuesday, August 18, 2009
Laziness
Well it's been a while since I posted, if I'm going to bugger off after only 6 posts I'm probably going to end up doing it again at some point. Anyways! have been working on projects even if I haven't been updating on them.
So hexapod is on hold until I can get some beefier servos but have managed to get a hold of a power wheelchair at long last (I have been after one of these for a while). It's an old one so it doesn't have a 2nd joystick port on it so to get it controlable from an arduino/pc took some work.

The control box is there on the left hand side, it was an old Dynamic which died shortly after I got it so I'm not going into the control system I tried to use since I can only assume I managed to kill the it.
I managed to get a replacement though (don't know who made it). The problem with this new one was that the arduino wasn't able to simulate the output from the joystick on its own.

You can see that the joystick is just two potentiometers at right angles to each other, the difference with this 2nd setup is that the pots are positioned 45 degrees off the direction of travel. It means that each pot is in direct control of one of the motors, from my point of view it makes the code a lot easier. But the way that the rest of the control box uses the current flowing through the joystick means that the arduino can't do it on its own. In the end I decided to use a MCP42100 digital potentiometer ic to simulate the two potentiometers, that only left the problem of controlling the MCP.
The MCP code was pretty easy once I got my head round it. It's an SPI bus device. Credit to http://little-scale.blogspot.com/2008/05/four-midi-controlled-digital-pots-via.html and http://www.arduino.cc/en/Tutorial/SPIDigitalPot.
But here is the code.
#define SS 2
#define CLK 4
#define MOSI 3
byte pot0 = B00010001; // write to pot 0
byte pot1 = B00010010; // write to pot 1
byte pots = B00010011; // write to both
void setup()
{ Serial.begin( 9600 );
pinMode( SS, OUTPUT );
pinMode( CLK, OUTPUT );
pinMode( MOSI, OUTPUT );
digitalWrite( SS, HIGH );
digitalWrite( CLK, HIGH );
set_mcp_pot( pots, potval );
}
void loop()
{ set_mcp_pot( pot0, 255 );
delay( 3000 );
set_mcp_pot( pot1, 255 );
delay( 3000 );
set_mcp_pot( pots, 0 );
delay( 3000 );
}
void set_mcp_pot( byte pot, byte val )
{ digitalWrite( SS, LOW );
spi_transfer( pot );
spi_transfer( val );
digitalWrite( SS, HIGH );
}
void spi_transfer( byte working )
{ int i;
digitalWrite( CLK, LOW );
for( i=1; i<=8; ++i ) { if( working > 127 )
digitalWrite( MOSI, HIGH );
else
digitalWrite( MOSI, LOW );
digitalWrite( CLK, HIGH );
working = working << 1;
digitalWrite( CLK, LOW );
}
}
I have also managed to get it working with the digital compass to do the heading following that I wanted. I'll post that code later once I've checked the wheelchair batteries, I think they are having issues now....
So hexapod is on hold until I can get some beefier servos but have managed to get a hold of a power wheelchair at long last (I have been after one of these for a while). It's an old one so it doesn't have a 2nd joystick port on it so to get it controlable from an arduino/pc took some work.
The control box is there on the left hand side, it was an old Dynamic which died shortly after I got it so I'm not going into the control system I tried to use since I can only assume I managed to kill the it.
I managed to get a replacement though (don't know who made it). The problem with this new one was that the arduino wasn't able to simulate the output from the joystick on its own.
The MCP code was pretty easy once I got my head round it. It's an SPI bus device. Credit to http://little-scale.blogspot.com/2008/05/four-midi-controlled-digital-pots-via.html and http://www.arduino.cc/en/Tutorial/SPIDigitalPot.
But here is the code.
#define SS 2
#define CLK 4
#define MOSI 3
byte pot0 = B00010001; // write to pot 0
byte pot1 = B00010010; // write to pot 1
byte pots = B00010011; // write to both
void setup()
{ Serial.begin( 9600 );
pinMode( SS, OUTPUT );
pinMode( CLK, OUTPUT );
pinMode( MOSI, OUTPUT );
digitalWrite( SS, HIGH );
digitalWrite( CLK, HIGH );
set_mcp_pot( pots, potval );
}
void loop()
{ set_mcp_pot( pot0, 255 );
delay( 3000 );
set_mcp_pot( pot1, 255 );
delay( 3000 );
set_mcp_pot( pots, 0 );
delay( 3000 );
}
void set_mcp_pot( byte pot, byte val )
{ digitalWrite( SS, LOW );
spi_transfer( pot );
spi_transfer( val );
digitalWrite( SS, HIGH );
}
void spi_transfer( byte working )
{ int i;
digitalWrite( CLK, LOW );
for( i=1; i<=8; ++i ) { if( working > 127 )
digitalWrite( MOSI, HIGH );
else
digitalWrite( MOSI, LOW );
digitalWrite( CLK, HIGH );
working = working << 1;
digitalWrite( CLK, LOW );
}
}
I have also managed to get it working with the digital compass to do the heading following that I wanted. I'll post that code later once I've checked the wheelchair batteries, I think they are having issues now....
Wednesday, June 17, 2009
So little time....
I'm going to get around to posting the laser plans for the hexapod and posting updates info on the compass project I swear but I have been having job interviews and visiting universities and just generally running around.
Trust me driving to Plymouth from Brighton for an open day is not fun. Plymouth uni is doing some seriously scary cool stuff with robotics though, if you ever get a chance to check out their department, do.
Trust me driving to Plymouth from Brighton for an open day is not fun. Plymouth uni is doing some seriously scary cool stuff with robotics though, if you ever get a chance to check out their department, do.
Tuesday, June 2, 2009
Charlotte's Web
So I finally got the parts to put the hexapod together, need to get some beefier servos to replace the lifting ones on this since these can only just manage it. Besides that one hicup it's going well. I need to tweek the design just the tiniest little bit and then I can post the files. The controller works fine too, I'm using a roboduino nano and that's hooked up to Texas Instruments TLC5940. The tlc5940 is a 16 channel pwn chip, mainly used for leds but it can run servos too, there is even a software library http://www.arduino.cc/playground/Learning/TLC5940.
Saturday, May 23, 2009
As the crow flies
This is another one of the small projects that I have going at the moment (very, very early stages). In the picture is a Devantech CMPS03 on an arduino board. This is for my work with electric wheelchairs. I know some kids with severe physical disabilities, and the control interface for the wheelchairs leaves a lot to be desired. It is a one button interface, the wheelchair can only travel in certain pre-set directions. Since this control system doesn't allow you to correct for drift in the same way that the joystick does trying to travel in a straight line is impossible which is really annoying if you want to get anywhere.
The idea is that I can use the digital compass to keep the wheelchair on a straight heading. I really want this to be something that I can just plug in between joystick and the motor driver, if the values coming from the joystick for the left and right motors are the same then the compass will correct for any drift.
I'm using the wiring library from here http://www.grapelabs.de/index.php?id=52
Tuesday, May 19, 2009
Hexapod leg
So after I had the rough plan for the legs done in the sintra board I got the first version of the design laser cut in 3mm arcylic. I was living near Brighton at this point so I used http://www.heritageinlay.com/
The design wasn't quite right at this point, some of the pieces were too tight and the angle of the leg was off.
I changed the design a bit and v2 of the leg should be ready soon.
Each one of these legs is supposed to be 2DOF and have a ground contact sensor in the foot.



The design wasn't quite right at this point, some of the pieces were too tight and the angle of the leg was off.
I changed the design a bit and v2 of the leg should be ready soon.
Each one of these legs is supposed to be 2DOF and have a ground contact sensor in the foot.
Monday, May 18, 2009
Hexapod
I've had quite a lot of free time recently so I decided to try and build a hexapod. Now I could have gone and bought a kit but that's cheating.
I've been drawing the design in adobe illustrator.
This first prototype was made out of 3mm pvc foamboard (also called sintra board). The bolts being used here are mainly m4 size and the servos are some cheap Accoms AS-17's that I got in bulk off ebay.
My plan was to use an arduino and the software servo library to control a total of 13 servos. That gives me 6x 2DOF (Degrees Of Freedom) legs and a panning head for the ultrasonic distance sensor that I mean to use. As it turns out that plan sucked but more on that in later posts.


I've been drawing the design in adobe illustrator.
This first prototype was made out of 3mm pvc foamboard (also called sintra board). The bolts being used here are mainly m4 size and the servos are some cheap Accoms AS-17's that I got in bulk off ebay.
My plan was to use an arduino and the software servo library to control a total of 13 servos. That gives me 6x 2DOF (Degrees Of Freedom) legs and a panning head for the ultrasonic distance sensor that I mean to use. As it turns out that plan sucked but more on that in later posts.
In the beginning
This is really just a test posting, I plan to start posting details of my various electronics, programming and robotics projects in the future.
Subscribe to:
Posts (Atom)