Question regarding d12 pin as OUTPUT

Hi,

I'm complete newbie to the arduino as whole.

I'm currently trying to use d12 as a simple digital output but having little issue.

  1. all other digital I/O pins are being used.
  2. Using d11 as serial output port.
  3. need to use d12 as simple digital output.

when I run my sketch, and give command to output on d12, without any connection I read 5V. When I connect it to the component, (mini circuit digital attenuator) I read only 1V as output voltage.

Anyone experienced similar issue or have any suggestion?

Thank you.

Sounds to me you didn't set it as a output but without code (is it a state secret?) it's impossible to be sure. calling digitalWrite(pin, HIGH) on a pin that's a input (default) turns on the internal pull up. So did you make it a output by calling pinMode(pin, OUTPUT) first?

Hello Septillion,

Thank you for your response. Yes I did set the pin to be an output and set the output to be high.

So basically when there's no connection to pin 12, I read 5V, which is correct. but when I connect this to control component that needs digital input, and I tapped into the output of pin 12 and I read 1V instead of 5v.

Sounds like the component is trying to draw more current than the chip can supply. Stop trying to connect it like that immediately (until the issue is understood), before you damage your arduino.

What is the device?

DrAzzy:
What is the device?

And to add to that, because you missed my hint, post your code.

My bad, I thought it was hardware related problem so i didn’t post my code.


#include <SPI.h>

const int slaveSelectPin1 = 10;
const int slaveSelectPin2 = 12;
const int slaveSelectPin3 = 9;
const int sw1 = 2;
const int sw2 = 3;
const int sw3 = 4;
const int sw4 = 5;
const int sw5 = 6;
const int sw6 = 7;
const int sw7 = 8;

// the setup routine runs once when you press reset:
void setup() {
  Serial.begin(115200);
  // set the slaveSelectPin as an output:
  pinMode (slaveSelectPin1, OUTPUT);
  pinMode (slaveSelectPin2, OUTPUT);
  pinMode (slaveSelectPin3, OUTPUT);
  pinMode (sw1, OUTPUT);
  pinMode (sw2, OUTPUT);
  pinMode (sw3, OUTPUT);
  pinMode (sw4, OUTPUT);
  pinMode (sw5, OUTPUT);
  pinMode (sw6, OUTPUT);
  pinMode (sw7, OUTPUT);
  // initialize SPI:
  //SPI.begin(); 
  //make sure all select pins are low
  digitalWrite(slaveSelectPin1,LOW);
  digitalWrite(slaveSelectPin2,LOW);
  digitalWrite(slaveSelectPin3,LOW);
  //Set default switch states
  digitalWrite(sw1,LOW);
  digitalWrite(sw2,LOW);
  digitalWrite(sw3,LOW);
  digitalWrite(sw4,LOW);
  digitalWrite(sw5,LOW);
  digitalWrite(sw6,LOW);
  digitalWrite(sw7,LOW);
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV16); //UNO has 16MHz clock
  printPrompt();

}

// the loop routine runs over and over
void loop() {
  int input;
//  delay(2000);
  if (Serial.available() > 0) {

    // look for the next valid integer in the incoming serial stream:
    input = Serial.parseInt(); 
    Serial.println(input);
    if ((input >= 100) && (input < 132)){
      spiWrite(slaveSelectPin1,(input - 100)*2);
      Serial.print("attenuator 1 adjusted \n\n");
      printPrompt();
    }
    if ((input >= 200) && (input < 232)){
      spiWrite(slaveSelectPin2,(input - 200)*2);
      Serial.print("attenuator 2 adjusted \n\n");
      printPrompt();
    }
    if ((input >= 300) && (input < 332)){
      spiWrite(slaveSelectPin3,(input - 300)*2);
      Serial.print("attenuator 3 adjusted \n\n");
      printPrompt();
    }
    if ((input >= 10) && (input < 12)){
      digitalWrite(sw1,input-10);
      Serial.print("switch 1 written \n\n");
      printPrompt();
    }
    if ((input >= 20) && (input < 22)){
      digitalWrite(sw2,input-20);
      Serial.print("switch 2 written \n\n");
      printPrompt();
    }
    if ((input >= 30) && (input < 32)){
      digitalWrite(sw3,input-30);
      Serial.print("switch 3 written \n\n");
      printPrompt();
    }
    if ((input >= 40) && (input < 42)){
      digitalWrite(sw4,input-40);
      Serial.print("switch 4 written \n\n");
      printPrompt();
    }
    if ((input >= 50) && (input < 52)){
      digitalWrite(sw5,input-50);
      Serial.print("switch 5 written \n\n");
      printPrompt();
    }
    if ((input >= 60) && (input < 62)){
      digitalWrite(sw6,input-60);
      Serial.print("switch 6 written \n\n");
      printPrompt();
    }
    if ((input >= 70) && (input < 72)){
      digitalWrite(sw7,input-70);
      Serial.print("switch 7 written \n\n");
      printPrompt();
    }

  }
}

void printPrompt(){
  Serial.print("__________________________________________ \n");
  Serial.print("Enter Command \n");
  Serial.print("10 thru 71 to set one of 7 switches (10*sw# + state) \n");
  Serial.print("100 to 132 for attenuator1 (100 + gain) \n");
  Serial.print("200 to 232 for attenuator2 (200 + gain) \n");
  Serial.print("300 to 332 for attenuator3 (300 + gain) \n");
}

void spiWrite(int slave, int value) {
  //  send in the value via SPI to the shift register
  // initialize SPI:
  SPI.begin();
  byte value_b = byte(value); //convert to byte. no need to shift.2 bits will fall off automatically.
  SPI.transfer(value_b);
  // close SPI:
  SPI.end();
  // pulse the LE on slave to latch the data in the shift registers
  digitalWrite(slave,HIGH); 
  delay(100);
  digitalWrite(slave,LOW);
}

So as a result, I read some other post and it seems like initializing SPI changes pinmode of pin 12.
So I moved SPI.begin(); to where I actually send serial data.

component I’m using is mini circuit digital attenuator. (zx76-31r5-sp)
pin 12 is connected as “latch enable” to the digital attenuator.

After I moved SPI.begin() and end it after sending serial data, things work fine now.

However, I’m still open to any other suggestion or improvement.

Thank you.

Please post your code in code tags, click </> to add code tags to your message or [code]Place your code here[/code].

Doing SPI.begin() makes pin D12 a INPUT as it is a MISO(Master In Slave Out)
pin

You can’t use the same pin for different functions simultaneously
Which board are you using ??

SPI pins are fixed,you can’t define those pins in software like SoftwareSerial()

-Malhar