Then i get a lot of random characters as shown in the picture. I read that you had to use the mavgen.py to use the data of random characters, but how do I do that?
You are receiving this random characters because a second process is using the serial port, probably is the companion mavproxy that creates a bridge between /dev/ACM0 to udp:192.168.2.1:14550 for QGC.
If you want to get information from the mavlink protocol, you can use the QGC .tlog files, usually they are in Documents/QGroundControl/Telemetry.
An example of how to use the .tlog files to get an accessible information:
This program is designed to run on the surface computer. The ip address that it connects to is not the same as the ip on the Pi, that is the problem.
You need to change it to mavutil.mavlink_connection('/dev/serial/by-id/usb-3D_Robotics_PX4_FMU_v2.x_0-if00'). Remember that you need to disable the existing process that is talking to the pixhawk: screen -XS mavproxy quit.