Go Down

Topic: Is there an alternative to JArduino? (Read 1 time) previous topic - next topic

mirouhml

Hello,
I am new to Arduino here, so I've been trying to do a project for Smart Lighting, where the lights turn on themselves when there is a movement going on, using a PIR Sensor for detecting motion, and a light sensor TSL2561, before I got TSL2561 I really didn't know a thing about sensors and so on, till lately, I figured out that I need to use Wire.h library to read the data from the TSL2561 because it has something to do with the I2C, I know there are libraries out there to read data from this sensor but they are all in C++, I really need to use Java in this, I know I can use Arduino IDE and then retrieve data using java but that doesn't work out for me because I need to switch between several sketches, for that, I used JArduino (I had a different light sensor than this it worked out fine then but now I needed to switch sensors so I don't know what to do with this)
So to sum it up I need a Java library that can read I2C data, as long as I know JArduino doesn't support that, so is there anything you can suggest for me to look for?
(if I wasn't clear in anything please ask me to clarify)

Juraj

the Arduino language is not so very different from Java. with what do you have a problem?

Robin2

#2
Feb 17, 2020, 12:29 pm Last Edit: Feb 17, 2020, 12:32 pm by Robin2
From a brief read of this Github JArduino page my guess is that JArduino is very similar in concept to Firmata.
Quote
Before using JArduino, please make sure your Arduino board contains the JArduino firmware:
In other words it there is a regular Arduino program running on the Arduino that can respond to certain instructions sent from a Java program. That sort of thing can work fine as long as you are content with the range of instructions it can respond to.

To my mind you will have a much richer Arduino experience if you take the trouble to program the Arduino directly.

And another option is to use your Arduino programming knowledge to extend the capabilities of JArduino - I presume the source code is available.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

mirouhml

the Arduino language is not so very different from Java. with what do you have a problem?
for starters, I need to switch between two sketches automatically without the need to use Arduino IDE that's where I have the problem, also I need to use java because I am going to deploy some web services to use sensors I have, in this app I have 2 modes, first, the Automatic mode, where the pir sensor and the light sensor come to play when I detect movement and there isn't enough light in the room, we need to turn the light on else nothing happens, then there is the Manual mode I guess it's obvious, the manual mode is when u stop the arduino from detecting mouvement and light this manual mode has two options, you can either turn the light on or turn it off. for now everything worked perfectly because I used JArduino but when I got the new light sensor I figured that I need some libraries like Wire.h and SparkFun and those aren't available for java so I can't extract the data from the sensor I have.

mirouhml

From a brief read of this Github JArduino page my guess is that JArduino is very similar in concept to Firmata.
In other words it there is a regular Arduino program running on the Arduino that can respond to certain instructions sent from a Java program. That sort of thing can work fine as long as you are content with the range of instructions it can respond to.

To my mind you will have a much richer Arduino experience if you take the trouble to program the Arduino directly.

And another option is to use your Arduino programming knowledge to extend the capabilities of JArduino - I presume the source code is available.

...R
I took the trouble to program the Arduino directly but I honestly didn't know how to do the features I want, because I want to give the user the ability to turn the Automatic mode on where the light can be smart, and to turn it off where the user needs to turn the light on and off by himself, I searched a lot of how to do this but sadly I am a bit in a tight place now couldn't find anything useful to what I want to do, I know that there must be a way to do this but I just need guidance on where to start or look and I can figure out the rest on my own hopefully.

Robin2

I took the trouble to program the Arduino directly but I honestly didn't know how to do the features I want, because I want to give the user the ability to turn the Automatic mode on where the light can be smart, and to turn it off where the user needs to turn the light on and off by himself,
Please post the program that represents your best attempt and we will try to help.

Also tell us in detail what it actually does and what you want it to do that is different. It will make it much easier to focus on the parts you need help with rather than wasting time on things that you can do.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

mirouhml

Please post the program that represents your best attempt and we will try to help.

Also tell us in detail what it actually does and what you want it to do that is different. It will make it much easier to focus on the parts you need help with rather than wasting time on things that you can do.

...R
the problem isn't in the program itself it's in how to switch between two programs, since I can upload only once using Arduino IDE how can I change the behavior of the arduino using Java as I said I have a program for Automatic Mode, for example, this: (it's in Java using JArduino it's similar to the Arduino IDE code, just a simple attempt)
Code: [Select]

        private DigitalPin lightSensorPin = DigitalPin.A_0; // Light Sensor Pin
private DigitalPin pirSensorPin = DigitalPin.PIN_3; // PIR Sensor Pin
private DigitalPin LED = DigitalPin.PIN_12; // LED
@Override
protected void setup() throws InvalidPinTypeException{

pinMode(lightSensorPin, PinMode.INPUT);
pinMode(pirSensorPin, PinMode.INPUT);
pinMode(LED, PinMode.OUTPUT);

}
@Override
protected void loop() throws InvalidPinTypeException{
// if there is movement and there is no light in the room do..
if (digitalRead(lightSensorPin) == DigitalState.HIGH && digitalRead(pirSensorPin) == DigitalState.HIGH) {
digitalWrite(LED, DigitalState.HIGH);
delay(5000);
digitalWrite(LED, DigitalState.LOW);

}
delay(1);
}


that was the first program, the second one has only one job no need to post it, it turns the light on when the user wants it to, he clicks on his app "Turn On" and the light goes on, this program should stop the first program before turning the light on, because if it doesn't, problems will occur especially the ComPort problem so I need to close the Serial Port, then reopen it and upload a new command or program to the Arduino Board, I can do this only using JArduino I don't know of any way to use Arduino IDE to do this, because I need to manually each time upload a program of the two programs I mentioned, so if there is a way for the Arduino IDE to listen for what the java code sends then I need to have two separate codes when the IDE receives info that the user wants to stop the Automatic mode, it should be stopped
I hope this is clear enough

Juraj

#7
Feb 18, 2020, 09:49 pm Last Edit: Feb 18, 2020, 09:53 pm by Juraj
so you program a computer to switch the light with PIR?
you know you can put all the logic in the microcontroller?

mirouhml

so you program a computer to switch the light with PIR?
you know you can put all the logic in the microcontroller?
not just switch it with pir either switch it with pir or manually that's the problem I am facing

Robin2

the problem isn't in the program itself it's in how to switch between two programs, since I can upload only once using Arduino IDE
The simplest way is to have what amounts to both programs in the Arduino at the same time in the form of different functions. Then your Java program can send a message to the Arduino telling it which function should be used.

If you really want to use a Java program to upload a different program to an Arduino then you should be able to implement the same system as in my Python program to compile and upload code using the Arduino IDE command line

However I would strongly recommend the first approach if the intention is to create a system that can be used by someone who is not familiar with Arduino programming.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

mirouhml

The simplest way is to have what amounts to both programs in the Arduino at the same time in the form of different functions. Then your Java program can send a message to the Arduino telling it which function should be used.

If you really want to use a Java program to upload a different program to an Arduino then you should be able to implement the same system as in my Python program to compile and upload code using the Arduino IDE command line

However I would strongly recommend the first approach if the intention is to create a system that can be used by someone who is not familiar with Arduino programming.

...R
I like the first approach how would I start doing that?

Robin2

I like the first approach how would I start doing that?
You have not told us what your programming experience is. I have been assuming that you are a competent Java programmer and I would expect such a person to have little difficulty with Arduino programming.

Maybe have a look at Planning and Implementing a Program

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

mirouhml

You have not told us what your programming experience is. I have been assuming that you are a competent Java programmer and I would expect such a person to have little difficulty with Arduino programming.

Maybe have a look at Planning and Implementing a Program

...R

don't worry about the programming side I can handle myself I am a master's degree student in Software Engineering so I can handle C++ easily, arduino programming is based on that if I am not wrong, so just direct me where to start and I will handle the rest.

Robin2

so just direct me where to start and I will handle the rest.
I don't know what you don't know. What exactly do you want advice about?

A Java programmer will be very familiar with programs with multiple functions and I would expect the suggestion I made in the first paragraph in Reply #9 would have been a sufficient pointer to the solution. Did you study the link I gave in Reply #11 ?

I wonder if you are over-thinking the problem?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

mirouhml

I don't know what you don't know. What exactly do you want advice about?

A Java programmer will be very familiar with programs with multiple functions and I would expect the suggestion I made in the first paragraph in Reply #9 would have been a sufficient pointer to the solution. Did you study the link I gave in Reply #11 ?

I wonder if you are over-thinking the problem?

...R
I will go through the link you sent me in #11 and I will see what I am still lacking thank you very much for your kind help!

Go Up