[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/diy/ - Do It Yourself

Search:


View post   

>> No.1768290 [View]
File: 27 KB, 1825x626, screenie.png [View same] [iqdb] [saucenao] [google]
1768290

I have a board set up with 4 CB4021Bs reading from 31 switches. I have an issue where it looks like the pin readings are offset by 1 on each chip. Pic related, it's a shot of 2 (zooming out to show all 4 gave shitty pic quality.)

So, with the following code it means that the switch on PI-1 (pin 7) should be the most significant bit 0x80, but it is read in as the second most significant bit 0x40. It also means that the switch on PI-8 (pin1) is supposed to be the least significant bit, but is read as the most significant bit on the next IC in the chain.

My first thought was an issue with clock speed, but it behaves the same way with only one of the ICs attached to the board. Otherwise, I have no idea what the issue is. Any thoughts?

Also, this is the same board as from >>1763570

<code>
int _CD4021B_dataPin = 5;
int _CD4021B_clockPin = 6;
int _CD4021B_latchPin = 7;

void setup() {
pinMode(_CD4021B_latchPin, OUTPUT);
pinMode(_CD4021B_clockPin, OUTPUT);
pinMode(_CD4021B_dataPin, INPUT);
Serial.begin(9600);
Serial.write("Starting...\n");
}

void loop() {
int data1 = 0;
int data2 = 0;
int data3 = 0;
int data4 = 0;

digitalWrite(_CD4021B_latchPin, LOW);
data1 = shiftIn(_CD4021B_dataPin, _CD4021B_clockPin, LSBFIRST);
data2 = shiftIn(_CD4021B_dataPin, _CD4021B_clockPin, LSBFIRST);
data3 = shiftIn(_CD4021B_dataPin, _CD4021B_clockPin, LSBFIRST);
data4 = shiftIn(_CD4021B_dataPin, _CD4021B_clockPin, LSBFIRST);
digitalWrite(_CD4021B_latchPin, HIGH);

if (data1 || data2 || data3 || data4) {
Serial.println(data1, BIN);
Serial.println(data2, BIN);
Serial.println(data3, BIN);
Serial.println(data4, BIN);
Serial.println("========");
delay (300);
}
}
</code>

Navigation
View posts[+24][+48][+96]