擅长:python、mysql、java
<p>你没有提到你使用的是什么类型的Arduino,我假设你使用的是Arduino Uno或是带有8位MCU的东西。对于带有8位MCU的Arduino来说,<code>double</code>就像<code>float</code>由4个字节组成,而不是32位MCU或Raspberry Pi中的8个字节</p>
<p>因此,要用Python解压RPI上的结构,我认为这就是您要寻找的:</p>
<pre><code>import struct
data = [0, 0, 228, 65, 154, 153, 65, 66]
bstr = bytearray(data)
result = struct.unpack("<ff", bstr)
print(result)
</code></pre>
<p>这将导致以下结果:</p>
<pre><code>(28.5, 48.400001525878906)
</code></pre>
<p>我想这是你通过Arduino发送的两个值</p>
<p><strong>更新</strong></p>
<p>如果您正在接收由多个数据结构组成的数据,则可以使用<code>iter_unpack()</code>方法:</p>
<pre><code>import struct
data = [0, 0, 228, 65, 154, 153, 65, 66, 0, 0, 228, 65, 154, 153, 65, 66, 0, 0, 228, 65, 154, 153, 65, 66]
bstr = bytearray(data)
results = struct.iter_unpack("<ff", bstr)
for result in results:
print(result)
</code></pre>
<p>我建议您更详细地阅读Python <a href="https://docs.python.org/3/library/struct.html" rel="nofollow noreferrer">struct</a>的文档,以充分利用该库</p>