kurbatov / firmata4j

Firmata client written in Java.
MIT License
87 stars 45 forks source link

OneWire Support for DS18B20 temp sensor #60

Open willishf opened 1 year ago

willishf commented 1 year ago

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?

kurbatov commented 1 year ago

Hi @willishf,

I think implementation of OneWire support in firmata4j is doable. Unfortunately I don't have a OneWire device in my possession I could tinker with, understand how the protocol works and use for debugging. That's why it is hard for me to reason about details of implementation or implement it on my own. Although I've just submitted my vision of the interface firmata4j has to implement, I would love to see someone contributing OneWire support as a PR. For now I can only refer to the prior discussion on OneWire support #16 and summarize it here:

Firmata supports OneWire via sysex messages which are supported by firmata4j. Firmata definies OneWire messages here: https://github.com/firmata/protocol/blob/master/onewire.md The board should be flushed with ConfigurableFirmata which enables OneWire capability for the pins by default.

Here you can find the code that is responsible for sending a new pin mode message to the board. This method executes when OneWire mode is assigned to a pin.

I think it should be possible to extend Firmata for large data streams if not supported already. You can try to find an already existing feature that suits the task in the feature registry of Firmata or discuss your case there and propose a new feature. Newly proposed extension will probably require modification of the firmware though.

willishf commented 1 year ago

In the process of getting Johnny-five as a node.js client which appears to have extensive OneWire device support for firmata. This way I can do some end to end testing in that I am also wanting to run on rp2040 wireless.

I will plan on implementing OneWire in firmataj following the i2c example and will reach out if anything isn't obvious. Will do a pull request once I have things working.

For long term testing the DS18B20 boards are $5 on Amazon.

The arducam camera is SPI based and appears that SPI support in firmata is limited. Johnny-five based on reading GitHub issues has abstracted device support out so that you don't need to connect to firmata. Thinking camera support for image capture would be a virtual device addition to firmata. Write to an IO pin take a picture and load into memory. Consecutive reads of the pin would read image data based on max packet size. A hack but solves the problem now that rp2040 has enough memory and speed/pins to do these kind of things.

On Wed, Feb 8, 2023, 8:37 PM Oleg Kurbatov @.***> wrote:

Hi @willishf https://github.com/willishf,

I think implementation of OneWire support in firmata4j is doable. Unfortunately I don't have a OneWire device in my possession I could tinker with, understand how the protocol works and use for debugging. That's why it is hard for me to reason about details of implementation or implement it on my own. Although I've just submitted my vision of the interface https://github.com/kurbatov/firmata4j/blob/feat/one-wire/src/main/java/org/firmata4j/OneWireBus.java firmata4j has to implement, I would love to see someone contributing OneWire support as a PR. For now I can only refer to the prior discussion on OnWire support #16 https://github.com/kurbatov/firmata4j/issues/16 and summarize it here:

Firmata supports OneWire via sysex messages which are supported by firmata4j. Firmata definies OneWire messages here: https://github.com/firmata/protocol/blob/master/onewire.md The board should be flashed with ConfigurableFirmata https://github.com/firmata/ConfigurableFirmata/blob/master/examples/ConfigurableFirmata/ConfigurableFirmata.ino which enables OneWire capability for the pins by default.

Here https://github.com/kurbatov/firmata4j/blob/master/src/main/java/org/firmata4j/firmata/FirmataPin.java#L87 you can find the code that is responsible for sending new pin mode message to the board. This method executes when OneWire mode is assigned to a pin.

I think it should be possible to extend Firmata for large data streams if not supported already. You can try to find an already existing feature that suits the task in the feature registry https://github.com/firmata/protocol/blob/master/feature-registry.md of Firmata or discuss your case there and propose a new feature. Newly proposed extension will probably require modification of the firmware though.

— Reply to this email directly, view it on GitHub https://github.com/kurbatov/firmata4j/issues/60#issuecomment-1423486255, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA653HUSKOVIVL7ENITJDHDWWRC5VANCNFSM6AAAAAAUVNPKNI . You are receiving this because you were mentioned.Message ID: @.***>