kurbatov / firmata4j Goto Github PK
View Code? Open in Web Editor NEWFirmata client written in Java.
License: MIT License
Firmata client written in Java.
License: MIT License
According to the Firmata documentation, the pin state response does not return the value of the pin, but:
"For input modes, typically the state is zero. However, for digital inputs, the state is the status of the pull-up resistor which is 1 if enabled, 0 if disabled."
Updating the pin value in onPinStateReceive leads to incorrect values being reported by Firmata4j
More information about the exception can be found here: https://sentry.io/share/issue/1514e52d4bdf4edc92daf4947bfd84b6/
Already fixed in PR #49 but getting totally ignored.
I've installed StandardFirmata on my Uno R3.
I also followed the temporal hack in #48 to avoid crash.
Now I try to connect to the device:
val device: IODevice = FirmataDevice(JSerialCommTransport("COM3")) // using the name of a port
device.start() // initiate communication to the device
device.ensureInitializationIsDone() // wait for initialization is done
device.pins.forEach { p ->
println(""+p.index +" -> "+p.supportedModes)
}
device.stop() // stop communication to the device
But the ensureInitializationIsDone
function throws time out exception. Also (though I think it is a consequence of the previous error), listing the pins returns empty set.
Is there any step I missed?
In FirmataDevice() an executor is created, but shutdown does not close/shutdown/stop this Executor properly, thus every construction of a FirmataDevice will leave the executor and a thread running.
Would be nice to properly shutdown the Executor in the FiniteStateMachine to not accumulate threads in use-cases where the connection is re-established form time to time.
Hi,
how can I set sampling interval or disable analog / digital pin value reporting? I see them in org.firmata4j.firmata.FirmataMessageFactory
, but I don't know how to call it.
And why sampling interval must be less than 100 ms? Why not 5 min or longer? When i open (serial) connection I think there is too much unnecessary traffic.
Hi i am new to eclipse and java can anyone guide me how to add this library to eclipse.
It took me a while to realize why Firmata4j was timing out when calling device.ensureInitializationIsDone()
. It turns out I needed to implement responses for the following queries (which isn't automatically implemented for you if you are using the arduino firmata library) CAPABILITY_QUERY
, PIN_STATE_QUERY
, ANALOG_MAPPING_QUERY
Some documentation or better yet an error message saying the required queries may help future users of the library.
What do you think about using a serial communication library that has better support?
As I see the library used had no releases for ages...
I would recommend https://github.com/Fazecast/jSerialComm .
Thanks for your contribution of so great project.
Most functions of the project is enough to control the Arduino device, and it work well.
Now, I need use the temperature sensor of DS18B20 which is working on the protocol of Onewire.
How can I implements this function? Would you add this function into this project?
i keep getting error this stack trace to be exact
java.io.IOException: Cannot start firmata device java.io.IOException: Cannot start firmata devi Caused by: jssc.SerialPortException: Port name - /dev/tty.usbmodem14501; Method name - openPort(); Exception type - Port busy.
heres my code
`
if (device == null) {
try {
device = new FirmataDevice(COM_PORT);
device.start();
device.ensureInitializationIsDone();
//initialize pin (just like how you initialize in Arduino IDE)
BUTTON_UP = device.getPin(2);
BUTTON_RIGHT = device.getPin(3);
BUTTON_DOWN = device.getPin(4);
BUTTON_LEFT = device.getPin(5);
BUTTON_E = device.getPin(6);
BUTTON_F = device.getPin(7);
Pin[] Buttonpins = {BUTTON_DOWN, BUTTON_LEFT, BUTTON_RIGHT, BUTTON_UP, BUTTON_E, BUTTON_F, JOYSTICK_BUTTON};
for (Pin pin : Buttonpins){
pin.setMode(Pin.Mode.INPUT);
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
I want to use this framework to communicate two computer via serial port, does it support?
I try to run follow demo:
IODevice device = new FirmataDevice("COM6");
device.addEventListener(new IODeviceEventListener() {
public void onStart(IOEvent event) {
System.out.println("Device is ready");
}
public void onStop(IOEvent event) {
System.out.println("Device has been stopped");
}
public void onPinChange(IOEvent event) {
Pin pin = event.getPin();
System.out.println(
String.format(
"Pin %d got a value of %d",
pin.getIndex(),
pin.getValue())
);
}
public void onMessageReceive(IOEvent event, String message) {
System.out.println(message);
}
});
device.sendMessage("aldjaklsdjaklsdjaklsdjklasd");
device.stop();
But i got this error:
Exception in thread "main" java.io.IOException: Cannot send message to device
at org.firmata4j.transport.SerialTransport.write(SerialTransport.java:87)
at org.firmata4j.firmata.FirmataDevice.sendMessage(FirmataDevice.java:226)
at org.firmata4j.firmata.FirmataDevice.sendMessage(FirmataDevice.java:215)
at Main.main(Main.java:37)
Caused by: jssc.SerialPortException: Port name - COM6; Method name - writeBytes(); Exception type - Port not opened.
at jssc.SerialPort.checkPortOpened(SerialPort.java:878)
at jssc.SerialPort.writeBytes(SerialPort.java:348)
at org.firmata4j.transport.SerialTransport.write(SerialTransport.java:85)
... 3 more
There's a numerical overflow in "ask" method of FirmataI2CDevice class. The type byte in Java is signed. So, when the AtomicInteger return a value greater than 127, the value of variable "reg" is negative, and that, provoke an array index bound exception
I'm sorry if I do something completely wrong. But the following code does not work for me:
`public static void main(String[] args) {
IODevice device = new FirmataDevice("COM8");
try {
device.start();
device.ensureInitializationIsDone();
device.stop();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}`
I know it should do nothing but connect to the Arduino anyway. But already the timer expires:
java.lang.InterruptedException: Connection timeout
at org.firmata4j.firmata.FirmataDevice.ensureInitializationIsDone(FirmataDevice.java:153)
at arduino4j.Testklasse.main(Testklasse.java:21)
It is easy to reproduce: calling org.firmata4j.IODevice.start()
always crashes the JVM:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000007110b5db, pid=12504, tid=6892
#
# JRE version: OpenJDK Runtime Environment GraalVM CE 20.1.0 (11.0.7+10) (build 11.0.7+10-jvmci-20.1-b02)
# Java VM: OpenJDK 64-Bit Server VM GraalVM CE 20.1.0 (11.0.7+10-jvmci-20.1-b02, mixed mode, sharing, tiered, jvmci, jvmci compiler, compressed oops, g1 gc, windows-amd64)
# Problematic frame:
# C [jSSC-2.8_x86_64.dll+0xb5db]
#
--------------- T H R E A D ---------------
Current thread (0x000002369e22a000): JavaThread "main" [_thread_in_native, id=6892, stack(0x000000e67c200000,0x000000e67c300000)]
Stack: [0x000000e67c200000,0x000000e67c300000], sp=0x000000e67c2fbfb0, free space=1007k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [jSSC-2.8_x86_64.dll+0xb5db]
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j jssc.SerialNativeInterface.openPort(Ljava/lang/String;Z)J+0
j jssc.SerialPort.openPort()Z+65
j org.firmata4j.transport.SerialTransport.start()V+14
j org.firmata4j.firmata.FirmataDevice.start()V+24
...
Hi,
First, I need to say that I've enjoyed Firmata4j immensely and have been using it with my students here at York University. Thank you for your work.
I'm testing out the 2.3.9 snapshot and it seems that the digital output setValue() method isn't working correctly. I've tried it in two scenarios:
I've got an LED attached to pin D4 on my Arduino board. Using the 2.3.8 release, it blinks fine. However, in the 2.3.9 snapshot the board connects but the LED doesn't blink.
I can confirm that the analog input seems to work on the A0 (pin 14) in the PinBoard example in the 2.3.9 snapshot, however.
James
Hi,
thanks for developing this library. While implementing IODeviceEventListener, I discovered that the onStop() method don't work. I think you have to change FirmataDevice.java line 149 with l.onStop(event) instead of l.onStart(event). Doing this the onStop() method will work correctly.
Bye.
I am using firmata4j on Windows 10 with OpenJDK 11 and I get the same errors as @centic9 #42 (comment)
I want to use JSerialCommTransport coded by @NorbertSandor here NorbertSandor@cd9cb59
However I am unable to import JSerialCommTransport with version 2.3.8.
Maybe a 2.3.9 version including the changes should be released? How can I use JSerialCommTransport in the meantime?
I think there should be a section in the readme that explain how to use each Transport Layer interface (and how to install optional dependencies when needed). I am not very good with maven.
I am happy to help and contribute if I can!
I am working on an assignment to create ultrasonic radar but facing issue, while using the Grove Ultrasonic sensor. I have connected the Ultrasonc sensor to D7 I/O port. But facing issue on how to use it, basically the sensor has to work as transmitter and receiver both, so it should work as input and output too. But i am not able to get how i can use the Firmata4J to transmt the pulse and then receive it. Can someone help on it? If its a limitation, any clue how to get rid of it?
when i send digital message to arduino setdititalpin 8 high its work but when i send setdititalpin 9 high
the pin 8 goes low.
The arduino resets its self before sending a new message.
When using PULLUP mode for pins, they don’t always report the right value. This occurs with a genuine Uno, a clone Uno, and a clone Mega. It occurs on Windows, CentOS and on the Raspberry Pi.
I am running 2.3.8, although with the JSerialComm transport pulled from Git. I’m using Java 11. The Arduinos are running the latest version of StandardFirmata.
I tried the same test using a Python Firmata library, and didn’t have the problem, so I believe this is an issue with Firmata4J, rather than with the firmware. This is easy to reproduce, as described below.
Basics
Test procedure
Test 1
PUT. 1 (**incorrect**)
OTHER. 1 (correct)
Test 2
PUT. 0 (correct)
OTHER. 1 (correct)
Test 3
PUT. 1 (**incorrect**)
OTHER. 1 (correct)
This method is called setDigitalPinValue
but it actually builds a DIGITAL_MESSAGE
message:
If you are using StandardFirmata.ino
this can result in the wrong pin being changed since SET_DIGITAL_PIN_VALUE
changes the value of a single pin where DIGITAL_MESSAGE
changes the value for all pins on a port.
DIGITAL_MESSAGE
https://github.com/firmata/arduino/blob/master/FirmataConstants.h#L38
SET_DIGITAL_VALUE
https://github.com/firmata/arduino/blob/master/FirmataConstants.h#L44
I am currently working on a project, I am using Firmata for my Groove Beginner kit. But I am having issue with getting value from the Temperature sensor.
Is there anyone to help me with this issue?
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000007110b5db, pid=17744, tid=17716
#
# JRE version: OpenJDK Runtime Environment (20.0.2+9) (build 20.0.2+9-78)
# Java VM: OpenJDK 64-Bit Server VM (20.0.2+9-78, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64)
# Problematic frame:
# C [jSSC-2.8_x86_64.dll+0xb5db]
#
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
# https://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
full avalible on https://text-host.ru/bez-zagolovka-9507
I`m using flatlaf:3.3 and github.kurbatov.firmata4j:2.3.8, Intellij idea 2023.1.5. Without firmata4j it worked fine.
StandardFirmata is uploaded on my arduino every thing is fine. but when i run the code eclipse shows
and the creates this .log file
hs_err_pid7000.log
Thanks for your contribution of so great project.
I want to implement a function below. The computer communicate to a arduino board with firmate4j. And the arduino board need to communicate to another chip with serial (rx-tx) . Generally, the communication among several boards could be implemented by SoftwareSerial Library (https://www.arduino.cc/en/Reference/softwareSerial).
Is there a implementation of "Software Serial" to control the main board communicate with another chip using firmate4j?
Working on a firmata implementation that would run on RP2040 wireless for an agriculture sensor project. Wrote a couple of i2c device support using firmata4j and everything works as expected.
Now need to add OneWire support to the Java client to take advantage of the low cost DS18B20 boards that are OneWire with temp probe for $3.
Initially only found a PHP and JavaScript client package that had OneWire support. Then found JonnyFive so should be doable.
Wanted to see if there was any reason Firmataj does not support OneWire as a client in that minimum worth adding for the low-cost DS18B20 temp sensor.
If the reason wasn't on the ask list wanted to get your take that it is easy to implement or it won't work for reason X, Y and Z. Assuming that if it will work in Node.js via Johnny-five then it should be portable to any programming language as a client.
In looking at the initial code can dig my way down to the message sending/reply framework and see that the Pin option as a notion of OneWire as a type. Didn't see where allocating the pin as OneWire sends that configuration to firmata client.
Also working on getting the Arducam camera working on RP2040 which uses SPI to grab still images as needed. Thoughts on the ability to extend firmata to handle larger data streams of a JPEG image?
We need a callback when mFirmata.sendMessage(REQUEST_CAPABILITY); finishes.
Or when the pin list gets filled.
Or did I miss it somewhere?
Kind Regards
Hello Oleg Kurbatov,
Actually the latest version of your library in the Central Maven Repository is 2.3.2, but this version not supports SERVO mode. I reviewed the current code in github and I see that SERVO mode is supported. I think that if the code in github is stable, You should release a new version on Central Repository.
Thanks by your work, Ferrás.
When using firmata4j with latest Firmata, we get a warning
WARNING: Current version of firmata protocol on device (2.5) differs from version supported by frimata4j (2.3). Though these are compatible you may experience some issues.
Would be nice to have the protocol updated to the latest version.
I tried to take a quick look but unfortunately I did not understand some of the changes mentioned in https://github.com/firmata/protocol/blob/master/revisions.md and https://github.com/firmata/protocol/blob/master/protocol.md
I have an Arduino connected via USB for some Button/Led interaction.
The device is connected for a long time and should stay connected across all types of system-events, e.g. when the machine resumes from sleep/hibernate or whenever there is a hickup on the USB ports.
But sometimes the device gets disconnected and firmata4j does not detect this, so I cannot build in code which automatically restarts the device.
Is there a way to detect that the device is still working, i.e. some ping/watchdog request/response functionality?
firmata/ConfigurableFirmata#47 is related somehow, but seems to be further out.
Currently I am doing something like the following, but it would be nice to have a "last receive timestamp" or even a "restart after x-seconds device inactivity" built into the library.
device = new FirmataDevice(comPort) {
// Firmata4j does not have a Watchdog functionality, so
// I use the timestamp of the last received event as indication
// that there was no update any more
@Override
protected void handleEvent(Event event) {
lastReceivedTimestamp = event.getTimestamp();
super.handleEvent(event);
}
};
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.