Skip to content
Advertisement

How to exchange data between Teensy4.1 and RaspberryPi 4 using serial interface

I need to exchange data (roughly 100 bytes 10 times a second) between Teensy4.1 and RaspberyPi 4. I decided to do this via serial interface. There is Teensy code:

JavaScript

I have hard-coded 191.699997 for test purposes.

Please find below RaspberryPi Java part:

JavaScript

The output of the above code is the shown bellow:

JavaScript

I understand why is the difference but have no idea how to make it working (by working I mean how to get 191.699997 on the Raspberry Pi side.

Thanks in advance for your hints.

Advertisement

Answer

You have two issues: the ByteBuffer advances position after “getting” and Java is big endian by default:

This code should demonstrate:

JavaScript

Prints:

JavaScript

And looking further the integer 1128248115 (as printed from Java ) in hex :

JavaScript

And the integer 867385155 your code displayed (from Java on PI side) in hex :

JavaScript

Note that you can change the byte-order of a ByteBuffer by something like:

JavaScript

And then your code works (again with the getFloat(0)!:

JavaScript

Prints

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement