r/learnjava • • Jul 07 '19

My very first Java / Raspberry Pi project is almost complete!

Been learning Java for a month now and I almost have my first project completed. It's an automatic plant watering system using a Raspberry Pi with a relay controlled water pump and a soil moisture sensor. The README.md in the git explains more. I'm just having a couple small problems with getting the pi4j library integrated into my project - a serious noob problem I know, but hence, I am a noob - any help here would grant you much karma.

here is a link to my github: https://github.com/jayJavaGGDev/autoWaterPlantSystem0.git

any help would be greatly appreciated.

edit:

&& pix or it didnt happen

https://imgur.com/eoq4T8X

https://imgur.com/GOiGUvB

https://imgur.com/mSOpL9d

https://imgur.com/EOcHRBL

edit 2:

if you're wondering I was able to use Runetime.getRuntime().exec("path to bashfile"); to point my java timer program to a bash file that runs sudo python turnOn.py and one for turnOff, which are just 4 line scripts that turn on and off the pins except I think my relay might have been damaged because it's not turning on at all! of course this method isn't going to work to get input from my moisture sensors...

edit 3:

july, 8 11:52 am.

after a day of debugging my code and wiring i discovered that i hadn't shorted out my relay after all. somewhere along the lines i had set my pinout to bcm and not updated my relay pin code from board... highly embarassing!

So I've gotten my java code to run on my pi and call a bash script that runs the python script to turn on and off the pins. but the problem is i have two separate python scripts for on and off and when my java code executes the powerOn.py file, the gpio gets turned on but the program stays running forever then pumpOff.py is executed and they both run simultaneously and the pin just gets turned on and off again until i reset the Pi.. help plz!

47 Upvotes

42 comments sorted by

View all comments

Show parent comments

1

u/AnEmortalKid Jul 08 '19

Sort of. It’s a way to specify which libraries you depend on within your project. Then anyone can build the project and run it. So we’d probably use maven to get that pi4java dependency and use that in your project.

1

u/bwz3r Jul 08 '19

oh okay cool. do u know anything about pi gamehat? I just got one and I want to write games to work with the hat. I'm learning libgdx right now if it will run that

1

u/AnEmortalKid Jul 08 '19

No :(

1

u/bwz3r Jul 08 '19

:(

2

u/AnEmortalKid Jul 12 '19

1

u/bwz3r Jul 12 '19 edited Jul 12 '19

<3 thank u do you know if I got this on my desktop how will it work moving it to my pi after development

1

u/AnEmortalKid Jul 12 '19

Umm, I was considering you could make a runnable jar (a jar with everything you need) and that would be copied over to your PI. Then you would use java to interact with it.

How do you run your java code today?

1

u/bwz3r Jul 12 '19

Right now I just mostly run my stuff through intellij and Android studio but I discovered how to make artifacts and jars but someone said in a previous comment that I'd have to compile it on my pi due to the pins

1

u/AnEmortalKid Jul 12 '19

Ah , would you be able to run maven on your PI

1

u/bwz3r Jul 12 '19

I don't see why not should I build the project on the pi with Maven and then export to my desktop? also pi4j depends on wiring pi, which is written in c. how would that effect the transfer?