Hello
It might be a problem with the code, so I’m unsure if this thread is placed wrongly in the hardware section. But the issue we’ve got might as well be related to our poor understanding of the shift register we’re working with (74HC595D).
We’re using the ShiftRegister class from the jane examples on a slight modification og the Jane board, and have also tried with a simple breakout version of the setup. It seems we can’t figure out how to turn on pin 7(QH).
The code below should turn every pin on and off from 1-8, but the last pin remain low. What could be the problem here? Is there some pin 7 specific conditions we’ve missed?
See circuit below. Thanks!
`class ShiftRegister {
spi = null; // SPI interface for shift register
sr_output_en_l = null; // output enable for shift register
channelStates = 0x00; // Byte to store current state of sprinkler channels
constructor(_spi, _sr_output_en_l) {
this.spi = _spi;
this.sr_output_en_l = _sr_output_en_l;
}
function setChannel(channel, state) {
if ((channel < 0) || channel > 8) return;
if (state) {
this.channelStates = this.channelStates | (0x01 << channel);
} else {
this.channelStates = this.channelStates & ~(0x01 << channel);
}
// dispable the output and write the data out to the shift register
this.sr_output_en_l.write(1);
this.spi.write(format("%c",this.channelStates));
// enable the output
this.sr_output_en_l.write(0);
}
function stopAllChannels() {
this.channelStates = 0x00;
// dispable the output and write the data out to the shift register
this.sr_output_en_l.write(1);
this.spi.write(format("%c",channelStates));
// enable the output
this.sr_output_en_l.write(0);
}
}
spi_ifc <- hardware.spi257;
sr_output_en_l_pin <- hardware.pin2;
spi_ifc.configure(SIMPLEX_TX | MSB_FIRST | CLOCK_IDLE_HIGH, 4000);
local state = 0;
sr_output_en_l_pin.configure(DIGITAL_OUT);
sr_output_en_l_pin.write(1);
function test_pins() {
state = 1-state;
for(local i = 1; i <= 8; i++) {
server.log(i + " state: " + state);
valve.setChannel(i, state);
imp.sleep(2);
}
imp.wakeup(3, test_pins);
}
test_pins();`