It would be good to have a reference and schematic for that red board. Were did you get it?
Presumably the port labeled "SIG" is connected to Pin 1 on the CD74HC4067. You don't appear to have it connected to your processor board. That will make reading its value quite difficult.
gfvalvo:
It would be good to have a reference and schematic for that red board. Were did you get it?
Presumably the port labeled "SIG" is connected to Pin 1 on the CD74HC4067. You don't appear to have it connected to your processor board. That will make reading its value quite difficult.
It is sparkfun. The data sheet was the same Texas Instruments one
Code has the below line - SIG connection to Nano's RX0 [ think also called D0]
#define PIN_A_MUX_SIG 0 // This pin will read the input from the mux.
krisferrari:
I did use D3 [ before], but didnt get what i expected
You never posted corrected code. Your first example tried to do an analog read of pin 3, which I tried to explain the folly of several times. I also did tell you what to use instead.
You also can't do an analog read of pin 0, and an analog read is generally not the correct way to read a digital signal (hence my reply #1 and #3).
So many questions and conversations back and forth...so wont defend
I dont know, if that is bad luck
Using pin D3 for SIG
int val = digitalRead(PIN_A_MUX_SIG);
now gives expected output. 0 or 1.
Thanks . I think I see switching between 1 and 0.
I did try using digitalRead instead of analogRead, but at that time...it was always 1... dont know why. But I did change code and used readMux function. The readMux thing works
for (byte i=0; i<MUX_CH_COUNT; i++) {
PORTB = (PORTB & B11110000) | i;
short val = analogRead(PIN_A_MUX_SIG);
// short val = digitalRead(PIN_A_MUX_SIG);
// "val" holds the value for input "i", so you can insert your custom code here.
Also the idea to use Rx0 was based on
Not just for reading
The CD74HC4067 is capable of more than reading analog signals. It can be uses in either direction. So you could connect SIG to 5v, and then be able to switch the 5v to one of 16 channel pins if you needed to control 16 [[relays]]. It also works with [[serial]]. So… if you had 16 [[RFID]] readers that output serial, you could connect the SIG pin of the CD74HC4067 to digital 0 on the arduino (Serial RX pin) and the serial out of an RFID reader to one of the channels and be able to read from all 16 RFID readers.
You're welcome. FYI, if you use the mux in reverse as you state above, you have to take into account that non-selected pins will be high impedance ("floating"). So if you have a relay board connected, 15 out of 16 relay inputs will always be effectively disconnected. You have to know for sure, the relay inputs have some kind of pull up or down to select a default state.