Hello again @sridhar_p0266. I see there is a bug in the "M4_BME280_RPC" sketch that is included in the "python-sensor-rpc
" ZIP package from the download link in that tutorial. If we look at the Python script that runs on the Portenta X8's Linux machine, we see this:
rpc_client = RpcClient(rpc_address)
temperature = rpc_client.call('temperature')
rpc_client = RpcClient(rpc_address)
humidity = rpc_client.call('humidity')
rpc_client = RpcClient(rpc_address)
pressure = rpc_client.call('pressure')
rpc_client = RpcClient(rpc_address)
gas = rpc_client.call('gas')
rpc_client = RpcClient(rpc_address)
altitude = rpc_client.call('altitude')
Meanwhile the M4_BME280_RPC sketch binds the following RPC messages:
status
temperature
humidity
pressure
Note that the sketch does not bind a gas
or altitude
message. When the Python script calls the missing messages, it causes a RpcError.TimeoutError
exception to be raised, and thus you get this "Unable to retrive data from the M4.
" [sic] message from the Python script instead of the expected sensor data.
I have reported this bug to the Arduino documentation team. I apologize for any inconvenience this has caused.
There are a couple of different options for how you can resolve this problem:
Option A: Use BMP680 Sensor
The Python script is actually written for use with the BMP680 sensor. Unlike M4_BME280_RPC sketch, the "M4_BME680_RPC" sketch that is included in the tutorial's "python-sensor-rpc
" ZIP package does provide all the RPC messages that are called by the Python script.
So if you happen to have a BMP680 sensor on hand, then the easiest solution would be to switch to using that sensor instead of the BMP280. I'll provide instructions you can follow to do that:
- Unplug the USB cable and any other power sources from the Portenta X8 board.
- Disconnect the BMP280 sensor from the Portenta X8.
- Connect the BMP680 sensor to the Portenta X8.
- Connect the USB cable of the Portenta X8 board.
- Use Arduino Cloud Editor to upload the M4_BME680_RPC sketch from the tutorial's "
python-sensor-rpc
" ZIP package to the Portenta X8 board.
- Wait for the sketch to upload successfully.
After doing that, you should see the expected output from the Python script, something like this
python-sensor-rpc_1 | Temperature: 25.904266357421875
python-sensor-rpc_1 | Humidity: 25.564695358276367
python-sensor-rpc_1 | Pressure: 976.4400024414062
python-sensor-rpc_1 | Gas: 136.496
python-sensor-rpc_1 | Altitude: 311.0769348144531
(you don't need to take any action at all in the Portenta X8's Linux machine as long as the Python script is still running)
Option B: Remove Calls to Missing RPC Messages
Since the BMP280 sensor does provide altitude data, it would be possible to add the missing altitude
message to the M4_BME280_RPC sketch. However, unlike the BMP680, the BMP280 does not have a VOC sensing capability, so it is not possible to add a gas
message to the sketch that would return meaningful data.
For this reason, I think the most appropriate path forward with the BMP280 sensor would be to remove the calls to the missing RPC messages from the Python script. I'll provide instructions you can follow to do that:
- Start any text editor application.
ⓘ You can use a text editor like VIM on the Portenta X8's Linux machine if you like, but since it is generally more convenient to do development work on your PC, I'll assume you are using your PC for the rest of these instructions.
- Use the text editor to open the
src/m4_to_python.py
file from the folder extracted from the tutorial's "python-sensor-rpc
" ZIP package.
- Change line 47 in the script from this:
data = temperature, humidity, pressure, gas, altitude
to this: data = temperature, humidity, pressure
- Delete lines 41-45 from the script:
rpc_client = RpcClient(rpc_address)
gas = rpc_client.call('gas')
rpc_client = RpcClient(rpc_address)
altitude = rpc_client.call('altitude')
- Delete these lines from the script:
print("Gas: ", data[3])
print("Altitude: ", data[4])
- Save the file.
- If the original Python script is running on the Portenta X8's Linux machine, press the Ctrl+C keyboard shortcut in its shell window, then wait until it exits from the container:
^CGracefully stopping... (press Ctrl+C again to force)
Aborting on container exit...
[+] Stopping 1/1
✔ Container python-sensor-rpc-python-sensor-rpc-1 Stopped
10.4s
canceled
fio@portenta-x8-2a0fca09dab6fad9:/var/rootdirs/home/fio/python-sensor-rpc$
- Follow the instructions from the tutorial to upload the
python-sensor-rpc
folder that contains the modified Python script to the Portenta X8's Linux machine (adb push ...
), build the container (docker build ...
), and run the container (docker compose up
), just the same as you did before:
https://docs.arduino.cc/tutorials/portenta-x8/python-arduino-data-exchange/#the-python-application
After doing that, you should see the expected output from the Python script, something like this
python-sensor-rpc_1 | Temperature: 25.904266357421875
python-sensor-rpc_1 | Humidity: 25.564695358276367
python-sensor-rpc_1 | Pressure: 976.4400024414062
Please let me know if you have any questions or problems while following those instructions.