r/learnjava • u/bwz3r • 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
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!
1
u/ab624 Jul 07 '19
Cool ! Can you show us the physical hardware as well..
2
u/bwz3r Jul 07 '19 edited Jul 07 '19
if you look in the wiki page of the git there are a few pictures
edit1: you know what my links are broken check back in a bit I'll fix soon
edit2: heres direct links to pix: https://imgur.com/eoq4T8X https://imgur.com/GOiGUvB https://imgur.com/mSOpL9d https://imgur.com/EOcHRBL
i'm fixing the gitwiki now
1
1
Jul 07 '19 edited Jul 07 '19
I had no idea Raspberry Pis could run java.. The reason why I haven't picked one up is because I CBA to learn Python.
Heads up - if you use eclipse/intelliJ, go to refactor and press format, makes it so much easier to read but looks like you've got the right thing going.
1
u/matemik Jul 07 '19
It can indeed. On raspbian, java 8 comes preinstalled as well.
1
u/do11abill Jul 08 '19
While yes, it can run a JVM, the JDK/JRE needed is a special kind. While in most cases (including this post's particular case) this is fine, if you were to use something that required x86 architecture, a Pi will not work for you. I wanted to setup a thing called Kubernetes using a cluster of 3 pis and then deploy to it but because the architecture's were ARM instead of x86, I could not use the same Docker image. So ALL development had to be done directly on a pi (something I didn't want to do. Just wanted to let you, and maybe others, know that while it is Java, the architecture's are not quite the same so just something to look out for.
1
u/bwz3r Jul 08 '19
so what you're saying is I have to hook my pi up to my TV and code on my tiny little battery powered keyboard and mouse?
2
1
u/AutoModerator Jul 07 '19
It seems that you possibly have a screenshot of code in your post My very first Java / Raspberry Pi project is almost complete! in /r/learnjava.
Screenshots of code instead of actual code text is against the Code posting rules of /r/learnjava as is outlined in the sidebar - Code posting.
No screenshots of code!
If you posted an image merely to illustrate something, kindly ignore this message and do not repost. Your post is still visible to others. I am a bot and cannot distinguish between code screenshots and other images.
If you indeed did this wrong, please edit the post so that it uses one of the approved means of posting code.
For small bits of code (less than 50 lines in total, single classes only),
the default code formatter is fine
(one blank line before the code, then 4 spaces before each line of code).Pastebin for programs that consist of a single class only
Gist for multi-class programs, or programs that require additional files
Github or Bitbucket repositories are also perfectly fine as are other dedicated source code hosting sites.
Ideone for executable code snippets that use only the console
Please do not reply to this message, because I am a bot.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
0
Jul 08 '19
[deleted]
1
u/bwz3r Jul 08 '19
about 2 months ago I started looking around YouTube for free programming videos and about one month ago I bought my first paid class and after that it was a wrap. I've always been interested in computers an I recently tore my ACL and meniscus so I've been living with my parents the last couple months doing nothing but advancing thought my Java courses.
5
u/Slickbock Jul 07 '19
I'd suggest using a build tool like maven. You can specify dependencies and compile them into a single jar file (just an example of the many things maven can do). On mobile so cant link the docs (sorry!) but its very easily found with google