OpenSprinkler Forums Comments, Suggestions, Requests Controlling valves in other languages

Tagged: , ,

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #39297


    I’m hoping this is the right bucket on the forum for this question, I didn’t see anything hobbyist specific.

    I’m trying to write my own application that would control the valves for a water feature. I bought the OSBo and have downloaded and tested the latest firmware (2.x) to validate that the zones will open and the device will function, everything worked great. Then I wrote my own code. I modeled it after the code found in the OpenSprinklerGen2/OpenSprinkler.cpp in the method OpenSprinkler::apply_all_station_bits(), a couple attempts and rewrites (it is pretty simple code), I have still been unable to get the valves to open. I have tried building this in both nodejs and python to no avail.

    I suspected some variation in hard ware, although shift registers tend to function the same. I took a step back and used a breadboard and pinned out leds and a shift register, I then tied the pins p9_11, p9_12, and p9_13 to the same pins they map to in the firmware. I was able to write a program in nodejs that would successfully turn leds on that were tied to the 8 IO pins of the shift register as I passed in an array of values (1-8). Seeing that I could control a shift register on the breadboard connected to 8 LEDs, I then transferred this same code to a test program to toggle the valves instead. I reconnected the BBB, powered it up, ran it as sudo, and it still didn’t work. I’m kind of stumped as I figured what would toggle leds connected to a shift register, would also toggle valves. The shift register I used I believe is different, it is a 74HC595, though that wouldn’t seem to be the issue.

    I know this is a different language, and arguably an unsupported case, I’m simply looking for suggestions or ideas as to what could be possible differences or points to consider. Looking through the C++ code and the simple crap I’ve written I can’t identify anything obvious that would prevent it from working. Any suggestions are appreciated.




    It’s likely that you have ignored the OE (output enable pin). On OSBo (and other OS versions too), the shift register OE pin needs to be set to LOW by the processor in order to enable the shift register output. This is defined in defines.h
    and this pin is set to LOW in the setup() function:
    and not in the apply_all_station_bits function. The reason to use this pin is to disable shift register output until the program has properly initialized.



    Ray, you are awesome, that was it! After wrestling with a lowercase ‘p’ in the string value on pin 14 for 30 minutes (face palm) I finally got it to work. I’m a little disappointed I didn’t figure this out as I was aware of the OE pin functionality, I just assumed enabled by default, that and it’s always late at night when I try to work on this. Appreciate your help!

    To document my solution, the following code leveraging the bonescript library in nodejs will open and close the valves on the OSBo. binaryZones is an Integer that has had bits set using JS bit manipulation library.

    function enableZones(binaryZones) {    //example if binaryZones == 9: binaryZones.toString(2) == 1001   This would enable zones 1 and 4
        bone.digitalWrite(outputEnabled,  bone.LOW);
        bone.digitalWrite(latch,  bone.LOW);
        for(var x = MAX_ZONES; x > 0; x--) {
            bone.digitalWrite(clock, bone.LOW);
            bone.digitalWrite(data, bone.LOW);
            if (binaryZones & (1 << x - 1))
                bone.digitalWrite(data, bone.HIGH);
            bone.digitalWrite(clock, bone.HIGH);
        bone.digitalWrite(latch,  bone.HIGH);
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

OpenSprinkler Forums Comments, Suggestions, Requests Controlling valves in other languages