OpenSprinkler › Forums › OpenSprinkler Unified Firmware › Need positive logic from the 74HC595 output
- This topic has 13 replies, 5 voices, and was last updated 5 years, 3 months ago by liam1989.
-
AuthorPosts
-
July 4, 2015 at 7:07 pm #39027
mikekParticipantHello,
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?
July 4, 2015 at 7:14 pm #39028
SamerKeymasterThese 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-33That should help you get started modifying it to work with your hardware.
July 4, 2015 at 8:16 pm #39030
mikekParticipantThanks for the quick reply
July 6, 2015 at 3:38 pm #39085
DavidParticipanti 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… :/
July 6, 2015 at 5:06 pm #39087
mikekParticipantI 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
July 6, 2015 at 5:14 pm #39089
mikekParticipantI 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.
July 6, 2015 at 7:23 pm #39094
mikekParticipantI 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;
}
}July 8, 2015 at 9:23 am #39124
DavidParticipantdoes it work?
July 8, 2015 at 4:50 pm #39138
RayKeymasterInstead 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.July 8, 2015 at 4:54 pm #39140
RayKeymasterActually 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.
July 9, 2015 at 1:00 am #39145
mikekParticipantYes 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.
May 6, 2016 at 12:15 am #42333
mikekParticipantUPDATE: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
May 9, 2016 at 3:06 pm #42382
DavidParticipant@mikek
thank you! this is great an so easythere should be a command in build.sh to generate a OS with inverted outputs.
like: ./build.sh ospi -i -> invert the shiftregister out and GPIOsJune 12, 2019 at 3:36 pm #61046
liam1989Participant@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 -
AuthorPosts
- You must be logged in to reply to this topic.
OpenSprinkler › Forums › OpenSprinkler Unified Firmware › Need positive logic from the 74HC595 output