Pages: 1 2 [3] 4 5   Go Down
Author Topic: Centipede Shield - also a contest!  (Read 7028 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Logged

SF Bay Area
Offline Offline
Edison Member
*
Karma: 11
Posts: 1244
Arduino Ninja
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

To make it easier to understand what's going on, I created a simple library for the Centipede Shield. It could also be used as-is to control any MCP23017 chip. Right now it makes the Centipede I/O work like the normal Arduino I/O. More specialized functions are not implemented yet.

Download zipped library here


Example code using the Centipede library:
Code:
// Example code for Centipede Library
// Works with Centipede Shield or MCP23017 on Arduino I2C port

#include <Wire.h>
#include <Centipede.h>

/* Available commands
  .digitalWrite([0...63], [LOW...HIGH]) - Acts like normal digitalWrite
  .digitalRead([0...63]) - Acts like normal digitalRead
  .pinMode([0...63], [INPUT...OUTPUT]) - Acts like normal pinMode
  .portWrite([0...3], [0...65535]) - Writes 16-bit value to one port (device)
  .portRead([0...3]) - Reads 16-bit value from one port (device)
  .portMode([0...3], [0...65535]) - Write I/O mask to one port (device)
  .init() - Sets all register to initial values

  Examples
  CS.init();
  CS.pinMode(0,OUTPUT);
  CS.digitalWrite(0, HIGH);
  int recpin = CS.digitalRead(0);
  CS.portMode(0, 0b0111111001111110);
  CS.portWrite(0, 0b1000000110000001);
  int recport = CS.portRead(0);
*/

Centipede CS; // create Centipede object

void setup()
{
  Wire.begin(); // start I2C

  CS.initialize(); // set all register to default

  CS.portMode(0, 0b0000000000000000); // set all pins on port 0 to output

}


void loop()
{
  
  CS.digitalWrite(0, HIGH); // write A0 high
  CS.digitalWrite(15, LOW); // write B7 low
  delay(150);
  
  CS.digitalWrite(0, LOW); // write A0 low
  CS.digitalWrite(15, HIGH); // write B7 high
  delay(150);
  
}

Centipede.h:
Code:
// Centipede Shield Library
// Controls MCP23017 16-bit digital I/O chips

#ifndef Centipede_h
#define Centipede_h

#include "WProgram.h"

extern uint8_t CSDataArray[2];

class Centipede
{
      public:
                  Centipede();
            void pinMode(int pin, int mode);
            void digitalWrite(int pin, int level);
            int digitalRead(int pin);
            void portMode(int port, int value);
            void portWrite(int port, int value);
            int portRead(int port);
            void initialize();
      private:
            void WriteRegisters(int port, int startregister, int quantity);
            void ReadRegisters(int port, int startregister, int quantity);
            void WriteRegisterPin(int port, int regpin, int subregister, int level);
};

#endif

Centipede.cpp:
Code:
// Centipede Shield Library
// Controls MCP23017 16-bit digital I/O chips

#include "WProgram.h"
#include "Centipede.h"
#include <Wire.h>

uint8_t CSDataArray[2] = {0};

#define CSAddress 0b0100000


Centipede::Centipede()
{
  // no constructor tasks yet
}

// Set device to default values
void Centipede::initialize()
{

  for (int j = 0; j < 4; j++) {

    CSDataArray[0] = 255;
    CSDataArray[1] = 255;

    WriteRegisters(0, 0x00, 2);

    CSDataArray[0] = 0;
    CSDataArray[1] = 0;

    for (int k = 2; k < 0x15; k+=2) {
      WriteRegisters(j, k, 2);
    }

  }

}


void Centipede::WriteRegisters(int port, int startregister, int quantity) {

  Wire.beginTransmission(CSAddress + port);
    Wire.send(startregister);
    for (int i = 0; i < quantity; i++) {
      Wire.send(CSDataArray[i]);
    }
  Wire.endTransmission();

}

void Centipede::ReadRegisters(int port, int startregister, int quantity) {

  Wire.beginTransmission(CSAddress + port);
    Wire.send(startregister);
  Wire.endTransmission();
  Wire.requestFrom(CSAddress + port, quantity);
  for (int i = 0; i < quantity; i++) {
    CSDataArray[i] = Wire.receive();
  }

}


void Centipede::WriteRegisterPin(int port, int regpin, int subregister, int level) {

  ReadRegisters(port, subregister, 1);
  
  if (level == 0) {
    CSDataArray[0] &= ~(1 << regpin);
  }
  else {
    CSDataArray[0] |= (1 << regpin);
  }
  
  WriteRegisters(port, subregister, 1);
  
}

void Centipede::pinMode(int pin, int mode) {
  
  int port = pin >> 4;
  int subregister = (pin & 8) >> 3;

  int regpin = pin - ((port << 1) + subregister)*8;

  WriteRegisterPin(port, regpin, subregister, mode ^ 1);
  
}

void Centipede::digitalWrite(int pin, int level) {
  
  int port = pin >> 4;
  int subregister = (pin & 8) >> 3;

  int regpin = pin - ((port << 1) + subregister)*8;

  WriteRegisterPin(port, regpin, 0x12 + subregister, level);
  
}

int Centipede::digitalRead(int pin) {

  int port = pin >> 4;
  int subregister = (pin & 8) >> 3;

  ReadRegisters(port, 0x12 + subregister, 1);

  int returnval = (CSDataArray[0] >> (pin - ((port << 1) + subregister)*8)) & 1;

  return returnval;

}

void Centipede::portMode(int port, int value) {
  
  CSDataArray[0] = value;
  CSDataArray[1] = value>>8;
  
  WriteRegisters(port, 0x00, 2);
  
}

void Centipede::portWrite(int port, int value) {
  
  CSDataArray[0] = value;
  CSDataArray[1] = value>>8;
  
  WriteRegisters(port, 0x12, 2);
  
}

int Centipede::portRead(int port) {

  ReadRegisters(port, 0x12, 2);

  int receivedval = CSDataArray[0];
  receivedval |= CSDataArray[1] << 8;

  return receivedval;  

}
« Last Edit: November 12, 2009, 02:55:09 am by macegr » Logged

Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It does look very simple to control things with.

Now my project.

I am doing a visualiser with the lasers I recently bought off ebay and a load of solenoids.

The lasers are pointed in a line and hinged at one end so that they can move the laser point up and down. They are all sprung so they move back into a line if moved. When audio is inputted, it is analysed and causes solenoids to strike under the lasers, bouncing the laser up, creating an upwards series of lines on the wall/surface.

This will also be implemented with a number of pots (into arduino analog pins) and a load of push buttons for creating your own midi music and altering sounds, settings etc. and of course a load of LEDs for good measure. smiley-grin

And another project:

I am looking to sync a load of led bargraph modules (the ones with loads of led bars) for a number of projects, I would like to use some for a visualiser, displays for monitoring my pc (CPU usage, temp, hard drive usage, net download speed etc).

A giant led matrix is something everyone wants to do so I am looking to do one of those as well. Would I need transistors on each line? What is the max current on each pin?

I basically think it would be an infinitely useful board for a whole load of projects.

Mowcius
Logged

SF Bay Area
Offline Offline
Edison Member
*
Karma: 11
Posts: 1244
Arduino Ninja
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Liking a lot of the entries so far, but it's still anybody's game...you've got all day tomorrow to post your idea and possibly get a free Centipede Shield!
Logged

Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I now have another project I would like to use it for:

I am currently in the process of making an iron man suit for children in need (next friday). Due to not thinking of it sooner I am only currently doing the arc reactor and one arm with repulsor/fight stabiliser (lack of time to do more). Afterwards, I would like to make more of it, a second arm, the boots... (all of the internals, not the main body shell) but will run out of i/o pins of the arduino for solenoids/servos/leds etc.

I will be posting up pictures of the arm and arc reactor on the forums in the next week so keep a look out for them! smiley-grin

Mowcius
Logged

Norway
Offline Offline
Sr. Member
****
Karma: 0
Posts: 370
R-Doo-Inoo in the making :3
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

well just to elaborate on mine.

I plan to build a midi controller keyboard with more than one octave, probably a full set, and have controls on it like pitch and such on an analogue stick.

the main thing will be the inputs for all the keys, but also led playback on the keys from the pc.
Logged

B-dui in creation.

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Cheat !  ;D

The contest has finished now...

Who has won? smiley-grin

Mowcius
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok macegr,

i want to make a self balancing robotics platform.  something where i have two legs, sensors for input of gravity/force/tilt/intertia/IR/Vision/Encoder positioning and output motor control for servos or linear actuators.  With the arduino, it would be simple to load different libraries for 2 legs or 4 or hexapod walkers, but we would be able to add enough sensor IO for the system to co-ordinate and 'evolve' a better balance then could be programmed.  Same for walking gates. routines could be loaded and tuned from live sensor data.  Once this is done, it can become a small standarized system for robotics rollouts whether it be with wheels or legs or a virtual body.  they key is plenty of IO channels and some efficient slick coding.  I hope this expansion of details explains a little better what i want to do.
Logged

SF Bay Area
Offline Offline
Edison Member
*
Karma: 11
Posts: 1244
Arduino Ninja
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just an update: checking through all the entries and will be announcing the winners soon!
Logged

Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds good smiley-grin

Mowcius
Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

macegr, it seems that you got into some trouble, did you connect the ground?
Logged

SF Bay Area
Offline Offline
Edison Member
*
Karma: 11
Posts: 1244
Arduino Ninja
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This was really tough to judge...there were a lot of great project ideas! I really would have liked to give out more Centipede Shields, but I just don't have many prototypes yet. I'll send PMs to the winners asking for address information. They'll receive a Centipede Shield without the Arduino headers or 20-pin connectors soldered in place, but will have the headers available if they need them.

Winners:

Rupin
He didn't have as much to say about his project, but it's a pretty straightforward problem. A cable with 60 pins...how do you test each wire for continuity along the cable, and possible shorts between each conductor? A lot of time with a multimeter, or a device that can pass current through each of the 60 pins in turn, and watch all the others for suspicious activity. You need a LOT of general purpose I/O, which means the Centipede Shield is the perfect way to build a test rig for these cables.

_Sterling
The train project idea is great...lots of sensors and things to control, and model train layouts can change a lot over time. It's good to have a controller that can be reconfigured to any mix of inputs and outputs necessary. I'll keep an eye out for this project, sounds like a lot of fun!


Honorable Mention:

Giant Eye
kokuma
kyndal
mowcius

These users all had projects that made it hard to choose the two winners above...if I had more Centipede Shields to give out, you would all get one! Sorry you didn't make it...however, you can still use the Centipede Library above, and rig up something with the DIP version of the MCP23017 on a proto shield.

Thanks to everyone who participated! I may be running another couple contests for other prototypes very soon. One will be very interesting to you LED types, and another will give you wireless junkies the blues.
Logged

Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds good! I will be purchading one then as I unfortunately didn't win but they were good projects that made the top!

Mowcius
Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Congrats to the winners!
Logged

SF Bay Area
Offline Offline
Edison Member
*
Karma: 11
Posts: 1244
Arduino Ninja
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't yet received responses to my private message to the two winners. If you read this, please check your PMs and send me your shipping addresses!

If I don't hear back by November 27th I will select new winners from the existing entries.
Logged

Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

Pages: 1 2 [3] 4 5   Go Up
Jump to: