Hack Notes CVA 090617
hacknotes 090617[edit]
An idea[edit]
Messing around with trying to fit two 595 power shift registers onto the next board design and with moving up to an 18-pin socket for the motors the following ocurred to me:
- Given that we only want to be able to turn on one motor at a time, having two 595's is quite redundant.
- An 18-pin socket is hella big.
- If we used one 595 plus a switch controlling two separate power rails, we save money and board space and, best of all, control up to 16 motors with a 10-pin socket (assuming that we swap the always-ground pin with the second power rail).
- The drawbacks of this design would be:
- It further complicates the already complicated construction of the pager motor array when needing more than 8 motors
- Using any arbitrary combination of multiple motors could only theoretically be done by switching really quickly between each half really quickly. Doing this with LEDs one would likely see the flickering, doing it with motors however may not be as noticeable?
Testing[edit]
I bread-boarded up a circuit with one 595 and two 2N2222 transistors (I don't know where to look for a single switch but I'm sure these exist). With the following code I was able to control 8 leds easily using only 4 sinks on the 595. I couldn't quite work out getting arbitrary combinations by rapid switching to work right.
Circuit[edit]
Code[edit]
// define the pins used to run the shift registers
int enable_low = 6; //STR
int serial_in = 2;
int ser_clear_low = 4;
int RCK = 5;
int SRCK = 7;
//define transistor pins
int T1 = 13;
int T2 = 9;
int count;
int i;
unsigned long serialTimer = millis();
void setup() {
pinMode(enable_low, OUTPUT); // set shift register pins as outputs
pinMode(serial_in, OUTPUT);
pinMode(ser_clear_low, OUTPUT);
pinMode(RCK, OUTPUT);
pinMode(SRCK, OUTPUT);
// use some serial for debugging
Serial.begin(115200);
Serial.println("Setting up board");
// make sure we start out all off
digitalWrite(enable_low, HIGH);
// this should wipe out the serial buffer on the shift register
digitalWrite(ser_clear_low, LOW);
delay(100); //delay in ms
// work on a rising edge, so make sure they're low to start.
digitalWrite(RCK, LOW);
digitalWrite(SRCK, LOW);
digitalWrite(ser_clear_low, HIGH); //we are now clear to write into the serial buffer
Serial.println("Board is setup");
}
void loop() {
Debug();
//promising, but doesn't quite work!
/* for(i=0;i<10000;i++){
analogWrite(T2, 0);
analogWrite(T1, 255);
shiftOut(serial_in, SRCK, LSBFIRST, 00100000);
delayMicroseconds(100);
digitalWrite(RCK, HIGH);
delayMicroseconds(100);
digitalWrite(RCK, LOW);
analogWrite(T1, 0);
analogWrite(T2, 255);
shiftOut(serial_in, SRCK, LSBFIRST, 10000000);
delayMicroseconds(100);
digitalWrite(RCK, HIGH);
delayMicroseconds(100);
digitalWrite(RCK, LOW);
}*/
}
//// FUNCTIONS
void Debug(){
for(count=1;count<9;count++){
TurnOnMotor(count);
delay(500);
}
}
void TurnOnMotor(int which){
// accept which from 1 to 8
// send message to shift register as appropiate
digitalWrite(enable_low, HIGH);
delayMicroseconds(100); //slow and steady
Serial.print("Motor ");
Serial.println(which); // print angle
switch(which){
case 1:
analogWrite(T2, 0);
analogWrite(T1, 255);
shiftOut(serial_in, SRCK, LSBFIRST, 00010000);
break;
case 2:
analogWrite(T2, 0);
analogWrite(T1, 255);
shiftOut(serial_in, SRCK, LSBFIRST, 00100000);
break;
case 3:
analogWrite(T2, 0);
analogWrite(T1, 255);
shiftOut(serial_in, SRCK, LSBFIRST, 01000000);
break;
analogWrite(T2, 0);
analogWrite(T1, 255);
case 4:
shiftOut(serial_in, SRCK, LSBFIRST, 10000000);
break;
case 5:
analogWrite(T1, 0);
analogWrite(T2, 255);
shiftOut(serial_in, SRCK, LSBFIRST, 00010000);
break;
case 6:
analogWrite(T1, 0);
analogWrite(T2, 255);
shiftOut(serial_in, SRCK, LSBFIRST, 00100000);
break;
case 7:
analogWrite(T1, 0);
analogWrite(T2, 255);
shiftOut(serial_in, SRCK, LSBFIRST, 01000000);
break;
case 8:
analogWrite(T1, 0);
analogWrite(T2, 255);
shiftOut(serial_in, SRCK, LSBFIRST, 10000000);
break;
case 0:
shiftOut(serial_in, SRCK, LSBFIRST, 0);
break;
default:
// turn them all off
shiftOut(serial_in, SRCK, LSBFIRST, 0);
}
//in all cases, pulse RCK to pop that into the outputs
delayMicroseconds(100);
digitalWrite(RCK, HIGH);
delayMicroseconds(100);
digitalWrite(RCK, LOW);
analogWrite(enable_low, 0);
}