Firmata protocol with Raspberry Pi and Arduino

Ot with raspberry p using JAVAFirmata is a protocol that is used to communicate with microcontrollers from any tablet/pc over the serial interface. There are implementations of this for other platforms too along with Arduino. You can find support for this if you are using any Arduino IDE released after 2008.Use of this protocol lets you access GPIO of Arduino from any host device natively without uploading the sketch each time you change the sketch. You can use Arduino as ADC for your Pi as it doesn’t have native ADC pins, you can also interface a whole lot of sensors by the additional GPIO that you will get after connecting the Arduino which eliminates uses of the port expander and ADC ICs to be interfaced with Pi.In this video, I have shown a basic example of blinking the onboard LED of Arduino from Raspberry Pi by using JAVA and for this, we are going to use the firmata4j library.

You can Subscribe on YouTube by clicking this link to show your support and be updated with the latest video on the channel like this.
Subscribe: bit.ly/2d8pHge

Video:
Links:
Related Videos:
Code:

 

package in.weargenius.main;

import org.firmata4j.IODevice;
import org.firmata4j.Pin;
import org.firmata4j.firmata.FirmataDevice;

public class MainClass {
 public static void main(String args[]) throws Exception{
   IODevice device = new FirmataDevice("/dev/ttyACM0"); // construct the Firmata device instance using the name of a port
  // subscribe to events using device.addEventListener(...);
  // and/or device.getPin(n).addEventListener(...);
  device.start(); // initiate communication to the device
  device.ensureInitializationIsDone(); // wait for initialization is done
  // sending commands to the board
  Pin pin = device.getPin(13);
  
  pin.setMode(Pin.Mode.OUTPUT); 
  while(true){
    pin.setValue(1);
    Thread.sleep(1000);
    pin.setValue(0);
    Thread.sleep(1000);
  }
  
  //device.stop(); // stop communication to the device
 }
}

 

Thanks for visiting our blog.

Bikash Panda
Catch Me On

Bikash Panda

Blogger / Embedded System Developer at WeArGenius
A techie, tinkerer and tech lover, who loves to blog and feels everyone can learn tech provided they have the right attitude towards learning and passion. By profession, I am an IOT developer working in Smart Home/ Smart Grid domain.
Bikash Panda
Catch Me On

Bikash Panda

A techie, tinkerer and tech lover, who loves to blog and feels everyone can learn tech provided they have the right attitude towards learning and passion. By profession, I am an IOT developer working in Smart Home/ Smart Grid domain.