Author Topic: Cannot get P3 to go low?  (Read 4825 times)

danowar

  • Newbie
  • *
  • Posts: 12
Cannot get P3 to go low?
« on: January 18, 2013, 03:59:09 pm »
Hello,

I am trying to make a simple device that will pan a camera.  The device will have 3 modes, which is determined by a digital signal on pins P2 and P3.  If both pins are LOW, the device is in "Manual" mode, and the momentary push buttons on pins P4 and P5 control rotation.  If P2 is HIGH, the device is in "Continuous" mode, and a momentary push in either direction will cause the motor to spin continuously, until the other direction is pushed, or the mode is changed.  If P3 is high, the motor will automatically pan back and forth, for a programmable amount of time in each direction.  I am using a 3 position switch, making it impossible for P2 and P3 to be HIGH.

The code at the bottom of the post is working for manual mode and continuous mode.  There is currently no code for pan mode because I cannot get P3 to sit at a low state.  I discovered this when trying to change continuous mode to P3 instead of P2.  I am using 10k resistors to ground on all 4 input pins, and P2, P4, and P5 all seem to working fine.

Any suggestions as to why P3 isn't going low.  I am using 4 "AAA" batteries for power, so my VCC voltage is a bit over 6 volt.  P3 sits are about 2.8 volt upon loading this code.  

Thanks in advance.


Code: [Select]
// Remote control for camera panning

// Define Pins
#define MOTOR_OUTPUT_A 0 // output to h-bridge to control motor
#define MOTOR_OUTPUT_B 1 // output to h-bridge to control motor
#define MODE_CONT 2 // pins 2 and 3 are wired to a 3 position switch with the middle position being
#define MODE_PAN 3  // off.  This is a "mode" switch, and the common has a HIGH signal
#define PUSHBUTTON_CW 4 // push button for clockwise rotation
#define PUSHBUTTON_CCW 5 // push button for counter-clockwise rotation
#define MOTOR_SPEED_CW 35 // my motor spins slightly faster CW than
#define MOTOR_SPEED_CCW 38 // it does CCW, hence 2 different speeds.

void setup() {
  // set pin modes
  pinMode(MOTOR_OUTPUT_A, OUTPUT);
  pinMode(MOTOR_OUTPUT_B, OUTPUT);
  pinMode(MODE_PAN, INPUT);
  pinMode(MODE_CONT, INPUT);
  pinMode(PUSHBUTTON_CW, INPUT);
  pinMode(PUSHBUTTON_CCW, INPUT);
 
  // set starting pin states
  digitalWrite(MOTOR_OUTPUT_A, LOW);
  digitalWrite(MOTOR_OUTPUT_B, LOW);
  digitalWrite(MODE_PAN, LOW);
  digitalWrite(MODE_CONT, LOW);
  digitalWrite(PUSHBUTTON_CW, LOW);
  digitalWrite(PUSHBUTTON_CCW, LOW);
}

void loop() {
  // check the directional pushbuttons, if one is pushed, start motor in that direction.
  if (digitalRead(PUSHBUTTON_CW) == HIGH) {
    spin_CW(MOTOR_SPEED_CW);
  }
  if (digitalRead(PUSHBUTTON_CCW) == HIGH) {
    spin_CCW(MOTOR_SPEED_CCW);
  }
 
  // check if pushbutton is released, and NOT in continous mode, if so, stop motor.
  if (digitalRead(PUSHBUTTON_CW) == LOW && digitalRead(PUSHBUTTON_CCW) == LOW && digitalRead(MODE_CONT) == LOW) {
    spin_STOP();
  }
}

// spin the motor clockwise
void spin_CW(int speed) {
    analogWrite(MOTOR_OUTPUT_B, speed);
    digitalWrite(MOTOR_OUTPUT_A, LOW);
}  

// spin the motor counter-clockwise
void spin_CCW(int speed) {
    analogWrite(MOTOR_OUTPUT_A, speed);
    digitalWrite(MOTOR_OUTPUT_B, LOW);
}  

// stop the motor
void spin_STOP() {
    digitalWrite(MOTOR_OUTPUT_A, LOW);
    digitalWrite(MOTOR_OUTPUT_B, LOW);
}
« Last Edit: January 18, 2013, 03:59:09 pm by danowar »

danowar

  • Newbie
  • *
  • Posts: 12
Cannot get P3 to go low?
« Reply #1 on: January 18, 2013, 03:59:49 pm »
apparently the [code] tags don\'t work on this forum.  What are the correct tags?

JeffRand

  • Newbie
  • *
  • Posts: 44
Cannot get P3 to go low?
« Reply #2 on: January 18, 2013, 05:33:07 pm »
Are you unplugging from the USB after programming it?  The USB port is connected to pins 3 and 4.

danowar

  • Newbie
  • *
  • Posts: 12
Cannot get P3 to go low?
« Reply #3 on: January 18, 2013, 05:53:52 pm »
Thanks for the reply.  Yes I am unplugging it.  

I was playing around with the pin assignments and changed P3 to an output, then it will sit low.  I need PWM though, so I cannot use P3 for one of my motor output.  But since you can still digitalRead on output, I left P3 as an output with my original wiring, and it seems to work now.  Odd

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Cannot get P3 to go low?
« Reply #4 on: January 18, 2013, 06:42:44 pm »
@danowar - pin 3 is a strange pin:

https://s3.amazonaws.com/digispark/DigisparkSchematicFinal.pdf

It has a 1.5k pull-up on it, which it has to have for the USB communication, so sometimes a circuit will need to keep this in mind/design around it - that said it should really be noted in our wiki - and I will add some notes on it in just a few minutes!