Hi,
I am trying to connect a ST M74HC4094B1 shift out register to my project. I looked at the tutorial on this web site and at the datasheet of this device but I am not 100% sure of my wiring.
HEre is the datasheet: http://www.st.com/stonline/books/pdf/docs/1972.pdf
Here is my wiring:
1->digital 8
2->digital 11
3->digital 12
4->led1
5->led2
6->led3
7->X
8->Gnd
9->X
10->X
11->X
12->X
13->led4
14->led5
15->Gnd
16->+5V
Yep, where I put LED, this is a led with a 220R. I think the issue is somewhere else, but thanks.
Here is the code is use:
...
powerShiftPin(0,HIGH);
powerShiftPin(1,HIGH);
void powerShiftPin(int p, int state) {
/* defines a local variable */
int pin;
/* start with the pin = 1 so that if 0 is passed to this
* function pin 0 will light.
*/
pin = 1;
for (int x = 0; x < p; x++) {
pin = pin * 2;
}
/* ground PIN_LATCH and hold low for as long as you are transmitting */
digitalWrite(PIN_LATCH, LOW);
/* move 'em out */
shiftOut(PIN_DATA, PIN_CLOCK, MSBFIRST, pin);
/* return the latch pin high to signal chip that it
* no longer needs to listen for information
*/
digitalWrite(PIN_LATCH, state);
}
My only issue now, is that all the output are set to HIGH when the arduino runs the setup() function. What is the trick to put them down since it is supposed to drive relay input.
The trick is to make the OE line driven by an arduino output pin and pulled down by a resistor.
That way when it starts up your outputs are not enabled until you shift out all zeros (or ones) and enable the outputs, in the setUp()
Ok, I will try.
Does the code seem correct to you. Since it does not seem to me that putting HIGH or LOW to the powerShiftPin function changes something. I am not able to have the LED ON or OFF.... it just blinks ON/OFF then OFF forever...
Any idea?
Thanks
It seems that I do not understand which call makes the light ON and which one make it OFF in the tutorial lightShiftPinB function. CAn someone explains it to me?
Thanks
Youpi!
I have found the solution. Here is the code:
void getWaterLevel() {
/* read analog input: */
//int val = analogRead(PIN_IR);
int val = 0;
/* Calculate linear slope of reading (thanks, Acroname!):*/
waterDistance = (2914 / (val + 5)) - 1;
}
void powerShiftPin(int p, int state) {
switch(p) {
case 0:
if (state == HIGH)
relay_state |= B10000000;
else relay_state &=B01111111;
break;
case 1:
if (state == HIGH)
relay_state |= B01000000;
else relay_state &= B10111111;
break;
case 2:
if (state == HIGH)
relay_state |= B00100000;
else relay_state &= B11011111;
break;
case 3:
if (state == HIGH)
relay_state |= B00010000;
else relay_state &= B11101111;
break;
case 4:
if (state == HIGH)
relay_state |= B00001000;
else
relay_state &= B11110111;
break;
case 5:
if (state == HIGH)
relay_state |= B00000100;
else relay_state &= B11111011;
break;
case 6:
if (state == HIGH)
relay_state |= B00000010;
else relay_state &= B11111101;
break;
case 7:
if (state == HIGH)
relay_state |= B00000001;
else relay_state &= B11111110;
break;
}
/* ground PIN_LATCH and hold low for as long as you are transmitting */
digitalWrite(PIN_LATCH, LOW);
/* move 'em out */
shiftOut(PIN_DATA, PIN_CLOCK, LSBFIRST, relay_state);
/* return the latch pin high to signal chip that it
* no longer needs to listen for information
*/
digitalWrite(PIN_LATCH, HIGH);
}
Code someone provide me a better code for that ... I would like to save some code space !! :
Moreover I tried to put the OE pin to the arduino with a pull-down resistor (10kR) like that:
Pin OE -> 10KR -> Gnd
Pin OE -> digital 9
It does not help the initialization to 0 of all the shift registers to 0 during the arduino initialization process. Any idea?
Thanks
The whole case statement can be replaced by:-
p = 7-p;
if (state == HIGH) bitSet(relay_state,p); else bitClear(relay_state,p);
It does not help the initialization to 0 of all the shift registers
No but it disables the outputs allowing you to pull the outputs to the required values. When you have set up you shift register you then enable the outputs and they go initially in the same way as you have pulled them.
Hi,
So finally I figured out how I can make it work.
OE -> 10kR -> Ground
OE -> pin 9 Arduino
Then I do a pinMode to LOW. Then, I force all the output of the shift-register to LOW. When I am ready, then, I move to HIGH the needed output. Thanks Grumpy_Mike.