All Projects → kurbatov → Firmata4j

kurbatov / Firmata4j

Licence: mit
Firmata client written in Java.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Firmata4j

Cylon
JavaScript framework for robotics, drones, and the Internet of Things (IoT)
Stars: ✭ 3,862 (+5664.18%)
Mutual labels:  robotics, arduino, internet-of-things
Waterius
Передача показаний воды по Wi-Fi. Watermeter Wi-Fi transmitter.
Stars: ✭ 295 (+340.3%)
Mutual labels:  arduino, internet-of-things
Blynk Library
Blynk library for embedded hardware. Works with Arduino, ESP8266, Raspberry Pi, Intel Edison/Galileo, LinkIt ONE, Particle Core/Photon, Energia, ARM mbed, etc.
Stars: ✭ 3,305 (+4832.84%)
Mutual labels:  arduino, internet-of-things
Gort
Command Line Interface (CLI) for RobotOps
Stars: ✭ 425 (+534.33%)
Mutual labels:  robotics, arduino
Espway
Segway-like robot implemented on ESP8266
Stars: ✭ 109 (+62.69%)
Mutual labels:  robotics, arduino
Openbot
OpenBot leverages smartphones as brains for low-cost robots. We have designed a small electric vehicle that costs about $50 and serves as a robot body. Our software stack for Android smartphones supports advanced robotics workloads such as person following and real-time autonomous navigation.
Stars: ✭ 2,025 (+2922.39%)
Mutual labels:  robotics, arduino
Freedomotic
Open IoT Framework
Stars: ✭ 354 (+428.36%)
Mutual labels:  arduino, internet-of-things
Make
📖📖📖📖📖 写给软件工程师看的硬件编程指南
Stars: ✭ 170 (+153.73%)
Mutual labels:  arduino, internet-of-things
Sitewhere
SiteWhere is an industrial strength open-source application enablement platform for the Internet of Things (IoT). It provides a multi-tenant microservice-based infrastructure that includes device/asset management, data ingestion, big-data storage, and integration through a modern, scalable architecture. SiteWhere provides REST APIs for all system functionality. SiteWhere provides SDKs for many common device platforms including Android, iOS, Arduino, and any Java-capable platform such as Raspberry Pi rapidly accelerating the speed of innovation.
Stars: ✭ 788 (+1076.12%)
Mutual labels:  arduino, internet-of-things
Coapnet
CoAPnet is a high performance .NET library for CoAP based communication. It provides a CoAP client and a CoAP server. It also has DTLS support out of the box.
Stars: ✭ 23 (-65.67%)
Mutual labels:  arduino, internet-of-things
Simplebot
SimpleBot is a very basic robot designed for learning about NodeBots.
Stars: ✭ 65 (-2.99%)
Mutual labels:  robotics, arduino
Mabel
MABEL is a feature-packed, open-source, legged balancing robot based off of the Boston Dynamics Handle robot.
Stars: ✭ 72 (+7.46%)
Mutual labels:  robotics, arduino
Pjon
PJON (Padded Jittering Operative Network) is an experimental, arduino-compatible, multi-master, multi-media network protocol.
Stars: ✭ 2,615 (+3802.99%)
Mutual labels:  arduino, internet-of-things
Johnny Five
JavaScript Robotics and IoT programming framework, developed at Bocoup.
Stars: ✭ 12,498 (+18553.73%)
Mutual labels:  robotics, arduino
Blynk Server
Blynk is an Internet of Things Platform aimed to simplify building mobile and web applications for the Internet of Things. Easily connect 400+ hardware models like Arduino, ESP8266, ESP32, Raspberry Pi and similar MCUs and drag-n-drop IOT mobile apps for iOS and Android in 5 minutes
Stars: ✭ 8 (-88.06%)
Mutual labels:  arduino, internet-of-things
Darm
A desktop arm that can write and draw.
Stars: ✭ 38 (-43.28%)
Mutual labels:  robotics, arduino
Mycontroller V1 Legacy
The Open Source Controller
Stars: ✭ 135 (+101.49%)
Mutual labels:  arduino, internet-of-things
Arduino Device Lib
Arduino Library for TTN Devices
Stars: ✭ 155 (+131.34%)
Mutual labels:  arduino, internet-of-things
Esphome Core
🚨 No longer used 🚨 - The C++ framework behind ESPHome
Stars: ✭ 545 (+713.43%)
Mutual labels:  arduino, internet-of-things
Roboticarmandroid
💪 + 📱 It's a simple project where you'll learn how to create a Robotic Arm with Arduino board, controlled by a Android smartphone using Bluetooth. (PT-BR: Um projeto simples onde você irá aprender como criar um braço robótico utilizando Arduino, e controlar ele via Bluetooth através de um aplicativo Android)
Stars: ✭ 14 (-79.1%)
Mutual labels:  robotics, arduino

Get help on Codementor

firmata4j

firmata4j is a client library of Firmata written in Java. The library allows controlling Arduino (or another board) which runs Firmata protocol from your java program.

Capabilities

  • Interaction with a board and its pins in object-oriented style
  • Communication over serial port, network or custom transport layer
  • Abstraction over details of the protocol
  • Provides an UI component that visualize the current state of every pin and allows changing their mode and state
  • Allows communicating with I2C devices

Installation

Maven

Add the following dependency to pom.xml of your project:

<dependency>
    <groupId>com.github.kurbatov</groupId>
    <artifactId>firmata4j</artifactId>
    <version>2.3.8</version>
</dependency>

Usage

General scenario of usage is following:

// construct a Firmata device instance
IODevice device = new FirmataDevice("/dev/ttyUSB0"); // using the name of a port
// IODevice device = new FirmataDevice(new NetworkTransport("192.168.1.18:4334")); // using a network address
// 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
device.stop(); // stop communication to the device

Sending commands to the board may cause the device to emit events. Registered listeners process the events asynchronously. You can add and remove listeners along the way.

You can subscribe to events of the device or its pin.

device.addEventListener(new IODeviceEventListener() {
    @Override
    public void onStart(IOEvent event) {
        // since this moment we are sure that the device is initialized
        // so we can hide initialization spinners and begin doing cool stuff
        System.out.println("Device is ready");
    }

    @Override
    public void onStop(IOEvent event) {
        // since this moment we are sure that the device is properly shut down
        System.out.println("Device has been stopped");
    }

    @Override
    public void onPinChange(IOEvent event) {
        // here we react to changes of pins' state
        Pin pin = event.getPin();
        System.out.println(
                String.format(
                    "Pin %d got a value of %d",
                    pin.getIndex(),
                    pin.getValue())
            );
    }

    @Override
    public void onMessageReceive(IOEvent event, String message) {
        // here we react to receiving a text message from the device
        System.out.println(message);
    }
});

To obtain more fine grained control you can subscribe to events of a particular pin.

Pin pin = device.getPin(2);
pin.addEventListener(new PinEventListener() {
    @Override
    public void onModeChange(IOEvent event) {
        System.out.println("Mode of the pin has been changed");
    }

    @Override
    public void onValueChange(IOEvent event) {
        System.out.println("Value of the pin has been changed");
    }
});

You can change the mode and value of a pin:

pin.setMode(Pin.Mode.OUTPUT); // our listeners will get event about this change
pin.setValue(1); // and then about this change

I2C

firmata4j supports working with I2C devices. You can obtain a reference to an I2C device in this way:

IODevice device = new FirmataDevice(port);
...
byte i2cAddress = 0x3C;
I2CDevice i2cDevice = device.getI2CDevice(i2cAddress);

You may find convenient writing a wrapper for I2CDevice class to facilitate communication with I2C device. Consider SSD1306 and I2CExample classes as an example of that approach.

Low-Level Messages and Events

firmata4j allows sending an arbitrary binary message to the device. For example, setting sampling intervall using a low-level message:

device.sendMessage(FirmataMessageFactory.setSamplingInterval(12));

Low-level event handlers are supported as well. Those may be useful for debugging or processing custom messages from a device with modified protocol implementation.

device.addProtocolMessageHandler(FirmataEventType.SYSEX_CUSTOM_MESSAGE, new Consumer<Event>() {
    @Override
    public void accept(Event evt) {
        byte[] message = (byte[]) evt.getBodyItem(FirmataEventType.SYSEX_CUSTOM_MESSAGE);
        byte messageType = message[0];
        // and so on
    }
});

Watchdog

Low-level event handlers allow regestering a watchdog:

IODevice device = new FirmataDevice(port);
//...
FirmataWatchdog watchdog = new FirmataWatchdog(3000, new Runnable() {
    @Override
    public void run() {
        // do something when there were no low-level events during 3000 milliseconds
    }
});
device.addProtocolMessageHandler(FirmataEventType.ANY, watchdog);
//...
device.start();

This watchdog implementation gets activated by the first received message since it subscribed. That's why it should be registered before communication starts.

Visualization

You can get visual representation of device's pins using JPinboard Swing component.

JPinboard pinboard = new JPinboard(device);
JFrame frame = new JFrame("Pinboard Example");
frame.add(pinboard);
frame.pack();
frame.setVisible(true);

JPinboard allows setting the pin's mode by choosing one from a context menu of the pin. State of the output pin can be changed by double clicking on it.

An example of JPinboard usage can be found in org.firmata4j.Example class.

Versions

firmata4j sticks to Firmata protocol versions. The first available version of firmata4j is 2.3.1.

firmata4j-2.3.x will work well with Fimata v. 2.3.x. Actually it should work with Firmata v. 2.x.x but not necessarily support all of the protocol features. The first digits of versions must be equal because those stand for incompatible changes of the protocol.

Uploading Firmata To Arduino

Arduino IDE is shipped with an implementation of Firmata protocol. You can upload it as follows:

  • Plug your Arduino to the computer
  • Launch Arduino IDE
  • Select File -> Examples -> Firmata -> StandardFirmata in IDE's menu
  • Select your board in Tools -> Board
  • Select the port in Tools -> Port (it is already selected if you have uploaded something to your Arduino)
  • Click on Upload button

Note that firmata4j is focused to be client for the StandardFirmata firmware. Although there are several other firmwares that support Firmata protocol, those may implement only a featured subset of the protocol. A firmware has to respond to the following requests in order for firmata4j to initialize properly:

  • REPORT_FIRMWARE
  • CAPABILITY_QUERY
  • PIN_STATE_QUERY
  • ANALOG_MAPPING_QUERY

Cases

Contributing

Contributions are welcome. If you discover a bug or would like to propose a new feature, please, open a new issue.

If you have an improvement to share, please, do the following:

  1. Fork this repository
  2. Clone your own fork to your machine (git clone https://github.com/<your_username>/firmata4j.git)
  3. Create a feature branch (git checkout -b my-new-feature)
  4. Change the code
  5. Commit the changes (git commit -am 'Adds some feature')
  6. Push to the branch (git push origin my-new-feature)
  7. Create new Pull Request

License

firmata4j is distributed under the terms of the MIT License. See the LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].