Code Monkey home page Code Monkey logo

firmata4j's People

Contributors

alizelzele avatar centic9 avatar dependabot[bot] avatar drjrkuhn avatar guydriesen avatar kurbatov avatar leconon avatar mattjlewis avatar norbertsandor avatar primosk avatar secretagent-yt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

firmata4j's Issues

onPinStateReceive should not update pin value

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

Can't connect correctly to Uno

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?

Executor is not stopped during FirmataDevice.shutdown() causing threads to leak

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.

Missing documentation for pin reporting

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.

Document what queries are required for Firmata Device

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.

Onewire function is needed

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?

Cannot start the firmata device because the port is 'busy' stack trace

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();
        }
    } 

Does firmata4j support COM ports?

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

array index bound exception

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

Arduino Mega gets input buffer overflown with initial pin state requests

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)

JRE crash with GraalVM 20.1.0

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

...

setValue in v2.3.9 not setting digital output correctly.

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:

  1. The PinBoard example
  2. My own example (https://www.yorku.ca/professor/drsmith/2022/02/25/easy-java-arduino-with-firmata/#BlinkingLED)

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

IODeviceEventListener onStop() never triggered

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.

Document how to use JSerialComm Transport Layer

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.
image

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!

Using Firmata4j with Grove Beginner Kit to make Ultrasonic Radar

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?

Arduino resets the previous state

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.

Incorrect values reported when using PULLUP mode

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

  • All tests are performed with two pins in PULLUP mode, and the other pins left with their default settings.
  • The pin-under-test (PUT) is connected directly to a ground pin. Its value should therefore always be zero.
  • No other pins have wires connected to them
  • The second pin is called OTHER. As it is not connected, it should always report one.
  • The results described here apply to pins 2 - 13. While this was tested on both an Uno and a Mega, no extensive testing was done on pins above 13.

Test procedure

  • Call start()
  • Call ensureInitializationIsDone()
  • Set the mode of PUT and OTHER to PULLUP. Note: The order in which this is done matters.
  • Wait 100 ms
  • Get the values of the pins

Test 1

  • Pin mode to set first: OTHER
  • Constraints: . This should work using any two pins from 2 to 13
  • Result
  •  PUT. 1 (**incorrect**)
    
  •  OTHER. 1 (correct)
    

Test 2

  • Pin mode to set first: PUT
  • Constraints: If PUT <= 7 then OTHER <= 7. If PUT >=8 then OTHER >= 8
  • Result
  • PUT. 0 (correct)
    
  • OTHER. 1 (correct)
    

Test 3

  • Pin mode to set first: PUT
  • Constraints: If PUT <= 7 then OTHER >= 8. If PUT >=8 then OTHER <= 7
  • Result
  • PUT. 1 (**incorrect**)
    
  • OTHER. 1 (correct)
    

`setDigitalPinValue` method creates a `DIGITAL_MESSAGE` message instead of a `SET_DIGITAL_PIN_VALUE` message

This method is called setDigitalPinValue but it actually builds a DIGITAL_MESSAGE message:

https://github.com/kurbatov/firmata4j/blob/master/src/main/java/org/firmata4j/firmata/FirmataMessageFactory.java#L226

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

JVM crash

#
# 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.

Is there a implementation of "Software Serial" using firmate4j?

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?

OneWire Support for DS18B20 temp sensor

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?

OnCapabilitiesRecieved Missing

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

Central Maven Repository is not updated

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.

Update protocol to latest version

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

Cannot detect if device is still connected

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);
            }
        };

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.