Josh wrote[quote='Josh' pid='565' dateline='1528312412']
Hi Travis,
In our latest state machine (r2), there is one digital Arduino pin per valve, so it would have been simpler - but on your model (0.7) the valves are driven by a shift register, which accepts instructions via the SPI bus. You'll need to mod the valveWrite() function from the firmware (use ctrl-F to search for it, here). The gist of the function you'll need to create starting with valveWrite() is to initialize a byte to 0, then use a call to bitSet() for each valve you want to turn on, then call SPI.transfer(your byte), then flip the chip select line high and low.
I hope this helps!
Hi Josh, your suggestion worked!! With this code I can turn solenoid 1 on or off:
int valve_val = 1;
byte value = 0;
int i = 18; /* Solenoid 1 */
bitSet(value, valve_val);
SPI.transfer(value);
digitalWriteDirect(valveCSChannel, HIGH);
digitalWriteDirect(valveCSChannel, LOW);
Now to what I thought was the easy part, but is turning out to be a harder part. I assumed the Wire terminal inputs would read in just like an arduino digital channel. From the channel mapping I found that Wire terminal 1+ = 31, so I wrote this code as a gateway to turning the valve on or off:
int val = digitalRead(31);
int valve_val = 0;
if (val, HIGH) {
valve_val = 1;
}
I send a TTL to wire terminal 1+, but nothing happens so here's my question to you: are the wire terminal channels handled just like arduino digital channels, ie reading from them would then result in a HIGH or LOW answer. I noticed they are defined with 'byte' up above and didn't know if this changed anything.
Soooo close!!!! I feel like the hardest part is past. Additionally, I'm thinking of using wire terminal 1- as an input channel, rather than a ground. It looks like it's connected to arduino channel 32, so I could use 31, 32, 33 for my 3 input channels to control solenoids 1, 2, 3.
T