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....