Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

SPI (wiringPiSPIDataRW) needs byte array argument #29

Closed
savageautomate opened this issue Jan 8, 2013 · 4 comments
Closed

SPI (wiringPiSPIDataRW) needs byte array argument #29

savageautomate opened this issue Jan 8, 2013 · 4 comments
Assignees
Milestone

Comments

@savageautomate
Copy link
Member

@rlsutton1

For when you get around to implementing it... I've been using the Spi class, I currently see a significant issue with the exposed method Spi.wiringPiSPIDataRW in that it takes a string as the data to send.

The device I'm using needs to receive binary data, converting a byte array to a string doesn't really work in java - unicode and all. Also I don't think too many devices will take kindly to receiving unicode strings.

After much testing, the unicode issue is a big problem - a single byte becomes 1 or more bytes depending on the value. I've tried various encoding techniques to get around this without any luck. Also it's not possible to pass 0's as they are either being omitted or are terminating the string (not sure which).

@savageautomate
Copy link
Member Author

I have attempted to fix this in the latest 0.0.5-SNAPSHOT.
Please download the latest build and test this out.
(Note: I don't have an SPI device on hand to test with, so it may be a bit of a shot in the dark.)

https://github.com/Pi4J/pi4j/blob/c5fa25e7d91099827b7953f8566e3347a1e487e4/pi4j-core/src/main/java/com/pi4j/wiringpi/Spi.java#L140

@rlsutton1
Copy link
Contributor

Working beautifully.

On a side note, I bought a tlc5940 to provide 16pwm outputs which uses SPI. I've decided not to use it as it requires level shifters, ties up a lot of gpio pins as well as using clock cycles to reset it's counter 1000 times a second ( the clock resetting could also be achieved by sacrificing one of the tlc5940 outputs and using a pi4j interrupt - still uses clock cycles though).

The code I wrote includes a (possibly) generically useful piece of code to produce a byte array representing n x 12 bit values MSB first as required by the tlc5490.

The question is should I just throw the code I wrote for it or would you be interested in me wrapping up the code in a "Provider" to be included in pi4j?

Adafruit's PCA9685 board is so much a better option for pwm, as it's i2c and has it's own clock. - Which is perhaps a good reason not to implement code for the tlc5490.

If your interested let me know.

anyway good work on the fix for the JNI SPI Byte[].

@savageautomate
Copy link
Member Author

If you think your code could benefit others, then by all means a GPIO provider impl class would be awesome. The project does not currently have any GPIO providers for PWM expansion.

@savageautomate
Copy link
Member Author

Fixed in 0.0.5-SNAPSHOT, issue closed.

savageautomate added a commit that referenced this issue Mar 18, 2013
savageautomate added a commit that referenced this issue Mar 18, 2013
mheath pushed a commit to mheath/pi4j that referenced this issue Feb 16, 2021
FIX: Issue Pi4J#27; I2CRegister.write ignores length value

Received confirmation from @hackerjimbo the fix is working as expected.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants