I am currently working with the Arduino Portenta X8 and am trying to get the serial communication to work.
I tried using the py-serialrpc to forward the Serial.println output so I can debug the Arduino script. That didnt work at all and was telling me that certain files are missing.
This person had the same issue:
I used the suggested solution provided in that thread to at least have the docker up and running with your provided python code.
While it is running now, it does not forward any serial output.
Then I tried to get the serialrpc connection running following the tutorial:
https://docs.arduino.cc/tutorials/portenta-x8/python-arduino-data-exchange/
I used the provided python script here aswell, and followed the tutorial thoroughly to push it over to the x8, build the docker and start it. The only change I made to the python script was limit the number of data fields it fetches to 1, the temperature.
On the M4 I run a small sketch, with
RPC.bind("temperature", []{ return getTemperature(); });
in the setup and a small function:
float getTemperature(){
return 5;
}
Now when I load up everything and start it, the python script only tells me:
python-sensor-rpc-python-sensor-rpc-1 |
python-sensor-rpc-python-sensor-rpc-1 | ============================================
python-sensor-rpc-python-sensor-rpc-1 | == Portenta X8 Sensor reading ==
python-sensor-rpc-python-sensor-rpc-1 | ============================================
python-sensor-rpc-python-sensor-rpc-1 |
python-sensor-rpc-python-sensor-rpc-1 | Unable to retrive data from the M4.
python-sensor-rpc-python-sensor-rpc-1 | Unable to retrive data from the M4.
python-sensor-rpc-python-sensor-rpc-1 | Unable to retrive data from the M4.
I tried flashing the device completely with the newest provided image and set it up again from scratch, but nothing helped.
Does anyone have an idea what i'm doing wrong?
The scripts I'm using:
On the M4:
#include <RPC.h>
#include <SerialRPC.h>
void setup(){
pinMode(LED_BUILTIN ,OUTPUT);
Serial.begin(115200);
RPC.bind("temperature", []{ return getTemperature(); });
}
void loop(){
digitalWrite(LED_BUILTIN , HIGH);
Serial.println("led on");
delay(1000);
digitalWrite(LED_BUILTIN , LOW);
Serial.println("led off");
delay(1000);
}
float getTemperature(){
return 5;
}
Python on the Linux system:
import time
from msgpackrpc import Address as RpcAddress, Client as RpcClient, error as RpcError
Fixed configuration parameters
port = 8884
publishinterval = 5
The M4 Proxy address needs to be mapped via Docker's extra hosts
m4_proxy_address = 'm4-proxy'
m4_proxy_port = 5001
def get_data_from_m4():
"""Get data from the M4 via RPC (MessagePack-RPC)
The Arduino sketch on the M4 must implement the following methods
returning the suitable values from the attached sensor:
temperature
humidity
pressure
gas
altitude
"""
rpc_address = RpcAddress(m4_proxy_address, m4_proxy_port)
data = ()
try:
print("Trying to fetch data")
rpc_client = RpcClient(rpc_address)
temperature = rpc_client.call('temperature')
print("temp: ")
print(temperature)
data = temperature
except RpcError.TimeoutError:
print("Unable to retrive data from the M4.")
return data
if __name == '__main':
print()
print("============================================")
print("== Portenta X8 Sensor reading ==")
print("============================================")
print()
try:
while True:
data = get_data_from_m4()
if len(data) > 0:
print("Temperature: ", data[0])
time.sleep(publish_interval)
except KeyboardInterrupt:
print('Stopped.')