aarushi_mittal
Posts: 40
Joined: Wed Jul 05, 2017 10:16 am
Location: Delhi, India

Sending data from Uno to Pi to a Java application on Pi

Wed Jul 05, 2017 10:24 am

Hello All,

I have a sensor on Arduino Uno that is communicating serially with my raspberry pi 3 .
I will be running an Edgent Application on the pi that will be sending data to Watson IoT Platform.

I am trying to fetch the data coming from the arduino to my pi into the Edgent Application .
Since the Edgent Application is a Java application , how can this be done ?
Is it possible.

I have a moisture sensor on the arduino .
i want to read and use real time readings it sends to my pi in the Edgent Application .

P.s: the Edgent here , is Apache Edgent -> an incubating project for Edgent Computing

I have to complete it by 7th july 2017

Thanks,
Aarushi :)

User avatar
Douglas6
Posts: 4809
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Sending data from Uno to Pi to a Java application on Pi

Wed Jul 05, 2017 2:55 pm

I don't know anything about Edgent, but the Arduino will appear to the Pi as a serial device, so any Java library for serial communication should work.

mattlewis
Posts: 113
Joined: Sat Jan 12, 2013 3:05 pm
Location: UK
Contact: Website

Re: Sending data from Uno to Pi to a Java application on Pi

Wed Jul 05, 2017 9:01 pm

Alternatively you could use Firmata4j and control the Arduino directly from Java. I have integrated this as a provider for my diozero library.

Matt
http://www.diozero.com/

aarushi_mittal
Posts: 40
Joined: Wed Jul 05, 2017 10:16 am
Location: Delhi, India

Re: Sending data from Uno to Pi to a Java application on Pi

Thu Jul 06, 2017 11:22 am

Douglas6 wrote:I don't know anything about Edgent, but the Arduino will appear to the Pi as a serial device, so any Java library for serial communication should work.
Hi thanks for a quick response.
your approach seems easier, as i have already deployed the entire java app considering the application to be running on pi3 and simulating the hardware side; so it will be lesser work to read data from arduino to pi and then use it in my java application.

I tried searching for some solutions today.
Its a bit confusing.

If you have time, please guide me with the most suitable one.

i have a rpi3 , and of what I have read it has serial port enabled by default, i.e., enable_uart=1 by default.
So, i dont think i need to do any other modifications to its configuration.

How do I code the java application.?

The Java lib you suggested ; can it be Pi4J linke this link: http://pi4j.com/example/serial.html ? or this link: http://www.java-samples.com/showtutoria ... orialid=11.

please guide . The code seems confusing.
Also , if you have done this before could you share a tutorial with me.

Thanks,
Aarushi

mattlewis
Posts: 113
Joined: Sat Jan 12, 2013 3:05 pm
Location: UK
Contact: Website

Re: Sending data from Uno to Pi to a Java application on Pi

Thu Jul 06, 2017 12:01 pm

jssc is a good Java serial library.

Have you written the Arduino code for interacting with the moisture sensor? If you haven't written than code yet then I strongly recommend you investigate firmata4j. It requires the StandardFirmata firmware to be installed on the Arduino; once that is running all logic to interact with the devices connected to the Arduino can then be written in Java.
Internaly Firmata4j uses jssc for serial connection to the Arduino.
As I mentioned I have incorporated this into my diozero library so that you can run a simple program with code like:

Code: Select all

try (LED led = new LED(pin)) {
	led.on();
	led.off();
	led.toggle();
	led.toggle();
}
via:

Code: Select all

java -cp tinylog-1.2.jar:diozero-core-0.10.jar:diozero-sampleapps-0.10.jar:diozero-provider-firmata4j-0.10.jar:firmata4j-2.3.5.jar:jssc-2.8.0.jar com.diozero.sampleapps.LEDTest 12
Matt
http://www.diozero.com/

aarushi_mittal
Posts: 40
Joined: Wed Jul 05, 2017 10:16 am
Location: Delhi, India

Re: Sending data from Uno to Pi to a Java application on Pi

Tue Jul 11, 2017 10:52 am

Hi Matt,

Do you think Arduino would be able to process so much ?
The pi is a mini computer , but arduino is only a micro processer.

Shouldnt i use arduino only for things like sensing and actuating ?

Aarushi

mattlewis
Posts: 113
Joined: Sat Jan 12, 2013 3:05 pm
Location: UK
Contact: Website

Re: Sending data from Uno to Pi to a Java application on Pi

Tue Jul 11, 2017 2:02 pm

That's the great thing abut this approach - the Arduino is simply a proxy to the sensors; all of the actual control logic runs on the Pi (or any other controller).

If you look at the Standard Firmata library it is simply an application that you run on the Arduino that allows you to connect remotely to control GPIO / I2C / SPI devices that are connected to the Arduino. Firmata has a protocol for the remote communication.

Matt
http://www.diozero.com/

Return to “Advanced users”