Working with ShiftIn

I'm trying to follow this tutorial: https://www.arduino.cc/en/Tutorial/ShiftIn to get an understanding of using shift registers to make projects with more inputs. The problem is I believe I've followed the wiring diagrams correctly, and I've just copied and pasted the code the 'Hello World' project to get it working, but all I get for an output is a string of 1's no matter what position any switch is in. The only difference between the projects I can see is I'm using a NTE4014B instead of a CD4014B but the diagrams are the same. 12v power to the arduino. Any help would be amazing.

I'm having a similar issue and I believe my only difference with the ShiftIn tutorial is that I also have the NTE4014B vs the CD4014B. If anybody has any advice or resources or if you've figured it out, I would appreciate any help.

My circuit I believe also matches the diagram from ShiftIn Tutorial. The code I'm using is the Hello World code here: Hello World Code.

When I looked at the two datasheets for CD4014B and NTE4014B, I noticed the pin diagrams were the same. CD4014B Datasheet and NTE4014B Datasheet. Are there any other major differences between these two chips that I should take into account? My guess was the difference was in manufacturer.

I resolved the issue it seems. The only thing I had to change when compared to the tutorial for CD4014B was that it seems the NTE4014B requires that you pulse the clock pin while in parallel input mode before then switching to serial mode in order to read the bits in. (Sorry if this isn't the correct explanation (still new), but it did get it working for me)

Here is my code for reference, but mainly look at the added lines labeled by the comment.

#define LATCH_PIN 8
#define DATA_PIN 9
#define CLOCK_PIN 7

byte readRegisters() {
  byte data = 0;
  // Input bits into shift register in parallel input mode
  digitalWrite(LATCH_PIN, HIGH);
  // ADDED LINES
  for (int i = 7; i >= 0; i--) {
    digitalWrite(CLOCK_PIN, LOW);
    delayMicroseconds(.2);
    digitalWrite(CLOCK_PIN, HIGH);
  }
  // ADDED LINES

  // Read in the bits through serial
  digitalWrite(LATCH_PIN, LOW);
  for (int i = 7; i >= 0; i--) {
    digitalWrite(CLOCK_PIN, LOW);
    delayMicroseconds(.2);
    if (digitalRead(DATA_PIN))
      data = data | (1 << i);
    digitalWrite(CLOCK_PIN, HIGH);
  }

  return data;
}

void setup() {
  Serial.begin(9600);
  // Setup the pins
  pinMode(LATCH_PIN, OUTPUT);
  pinMode(CLOCK_PIN, OUTPUT);
  pinMode(DATA_PIN, INPUT);
}

void loop() {
  Serial.println(readRegisters(), BIN);
  delay(500);
}

Hi, @HollowMan
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Are you using 10K pull down resistors?
What are you using as switches?
Do you have a DMM to measure some voltages?
Are you using the monitor screen to see what the code is doing?

Thanks.. Tom.. :slight_smile:
PS I'm at work a the moment but I'll check later if you have posted the code you are using.

delayMicroseconds(.2);

No. That command takes an unsigned long, not a float that evaluates to 0.

If you want a 3 cycle delay then code in three NOP instructions as included assembly language.
How to include assembly language? I forgot! Look it up!

HollowMan:
The only difference between the projects I can see is I'm using a NTE4014B instead of a CD4014B but the diagrams are the same. 12v power to the arduino. Any help would be amazing.

They are different internally and as @LamoreauxAj has pointed out the input and logic around the parallel/serial input pin.
Tom... :slight_smile:

It was the clock issue. Thank you very much.

And sorry Tom, I'll make sure to follow the guidelines in the future!