OpenSprinkler Forums OpenSprinkler Unified Firmware Need positive logic from the 74HC595 output

This topic contains 13 replies, has 5 voices, and was last updated by  liam1989 3 months, 1 week ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #39027

    mikek
    Participant

    Hello,

    I’m building my own hardware to use with the Pi version of the unified firmware. I have a serial to parallel IC (74HC595). The system is outputting negative logic(active low) and I need positve logic (active high). What area in the source code should I be looking at or is the a constant that chan be changed, etc?

    #39028

    Samer
    Keymaster

    These are the two files which interface with the GPIO pins on the Raspberry Pi:

    https://github.com/OpenSprinkler/OpenSprinkler-Firmware/blob/master/gpio.cpp#L107-127
    https://github.com/OpenSprinkler/OpenSprinkler-Firmware/blob/master/gpio.ch#L30-33

    That should help you get started modifying it to work with your hardware.

    #39030

    mikek
    Participant

    Thanks for the quick reply

    #39085

    David
    Participant

    i tried the same. But i used the 74hct240 Ic. This is an 8channel inverter. But to change the software is a quit better way.

    But i have no idea what i had to change in the code. should i change HIGH to LOW in the gpio.h and nothing happend… :/

    #39087

    mikek
    Participant

    I can’t seem to find a reference to the syntax of the write command.

    In line 120 of gpio.cpp

    if (1 != write(fd, &s_values_str[LOW == value ? 0 : 1], 1)) {

    To me it looks like fd is the io handle and &s_values_str[LOW == value ? 0 : 1] will be the address of either the “0” or the “1” in the s_values_str array, but what is the last peramiter for (the , 1)? Also why return the address of the string element why not just use a HIGH or LOW? Is this needed for the write function?

    I can’t seen to find the write function in the gcc stdio or any of cpp io functions

    • This reply was modified 4 years, 2 months ago by  mikek.
    #39089

    mikek
    Participant

    @david,

    I thought about using inverters but decided not to because you could have an instance with startup leaving all channels on if open sprinkler fails to run or the pi fails to boot. Unless your inverter uses an output enable, you could tie that to the OE of the 74hc595.

    • This reply was modified 4 years, 2 months ago by  mikek.
    #39094

    mikek
    Participant

    I did what I needed by changing the gpio.cpp file like this since I only wanted to effect the serial data to the 74hc595, however if anyone knows what the write function syntax pass it along.

    if (pin == 27) {
    if (1 != write(fd, &s_values_str[HIGH == value ? 0 : 1], 1)) {
    DEBUG_PRINTLN(“failed to write value”);
    DEBUG_PRINTLN(pin);
    return;
    }
    }
    else {
    if (1 != write(fd, &s_values_str[LOW == value ? 0 : 1], 1)) {
    DEBUG_PRINTLN(“failed to write value”);
    DEBUG_PRINTLN(pin);
    return;
    }
    }

    • This reply was modified 4 years, 2 months ago by  mikek.
    #39124

    David
    Participant

    does it work?

    #39138

    Ray
    Keymaster

    Instead of modifying the gpio functions, you can do it at a higher level by modifying the apply_all_station_bits function:
    https://github.com/OpenSprinkler/OpenSprinkler-Firmware/blob/master/OpenSprinkler.cpp#L574
    This is where the station bits are pushed to the shift register. Just switch the order of HIGH and LOW and you should get reverse logic.

    #39140

    Ray
    Keymaster

    Actually as I re-read the posts: you should NOT modify the gpio file at all, because that will reverse the logic for all gpio pins, not just to shift register. In fact, this won’t even work for shift register because what you are trying to accomplish is to reverse the logic on the shift register outputs, not on the inputs.

    #39145

    mikek
    Participant

    @david,

    Yes it works.

    @ray,

    I put a if else in the code to only effect the single serial data pin going to the shift register (pin 27 on the Pi)

    if (pin == 27) {
    modified code
    }
    else {
    unmodified code
    }

    As for reversing the logic on the input it will have (and does have) the same effect as reversing the output since the LSB of the input is the Q0 output and all the way to the MSB on the input is Q7 on the output.

    My solution works, however, I agree that it would be better and cleaner to change the apply_all_station_bits as you suggested. I was looking where Samer suggested.

    • This reply was modified 4 years, 2 months ago by  mikek.
    #42333

    mikek
    Participant

    UPDATE:If you are using this modification to get reverse logic you will not be able to update to firmware 2.1.6(1) OSPI-AC until you get rid of the changes. The git pull command will give you a warning and quit. If you want to update your firmware you will need to abandoned this mod and modify the apply_all_stations_bits as suggested by Ray (a better and easier way to do it anyway).

    To fix things do:
    cd OpenSprinklerGen2
    mv gpio.cpp gpio.old
    git pull
    nano OpenSprinkler.cpp

    Change line 669 in OpenSprinkler.cpp from

    digitalWrite(pin_sr_data, (sbits & ((byte)1<<(7-s))) ? HIGH : LOW );
    To
    digitalWrite(pin_sr_data, (sbits & ((byte)1<<(7-s))) ? LOW : HIGH );

    ctrl-x and y to save

    Then
    sudo ./build.sh ospi
    sudo /etc/init.d/OpenSprinkler.sh restart

    • This reply was modified 3 years, 4 months ago by  mikek.
    • This reply was modified 3 years, 4 months ago by  mikek.
    #42382

    David
    Participant

    @mikek
    thank you! this is great an so easy

    there should be a command in build.sh to generate a OS with inverted outputs.
    like: ./build.sh ospi -i -> invert the shiftregister out and GPIOs

    #61046

    liam1989
    Participant

    @mikek I know this is an old post now, however how did you get on building your own hardware? I’m trying to do the same as you I believe. I’m trying to understand how this works with shift registers and how you assign channels to it etc? Maybe I’m just missing the obvious 🙂
    Thanks

Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.

OpenSprinkler Forums OpenSprinkler Unified Firmware Need positive logic from the 74HC595 output