Skip to main content

Python API for phyphox phone application

Project description

phyphox-py

Use phyphox-py package to get experimental data from your phyphox mobile app.

This library allows you to access sensor data from the Phyphox app (see www.phyphox.org) directly in Python.

What is Phyphox?

Phyphox is an open-source mobile application developed by RWTH Aachen University. Available on both Android and iOS, it provides access to the phone’s internal sensors for use in physics experiments.

Installation

To install phyphox-py, run the following command in your terminal:

python3 -m pip install phyphox-py

or in Windows

python -m pip install phyphox-py

Usage

Basic Example

import phyphox
import time

my_phone = phyphox.PhyphoxLogger("192.168.0.12", 8080)
my_phone.get_meta()
print(my_phone)

Sample output (truncated):

accelerometer    Name : ICM20602 Accelerometer
Vendor : InvenSense
Range : 78.45346
Resolution : 0.0011901855
MinDelay : 5000
MaxDelay : 1000000
Power : 0.325
Version : 20170509
...

version : 1.2.0
build : 1020009
fileFormat : 1.19
...
camera2api : [{"id":"0","facing":"LENS_FACING_BACK","hardwareLevel":"HARDWARE_LEVEL_3","capabilities":["CAPABILIT ...
camera2apiFull : [{"id":"0","facing":"LENS_FACING_BACK","hardwareLevel":"HARDWARE_LEVEL_3","capabilities":["CAPABILIT ...

Getting Experiment Configuration

my_phone.get_config()
print(my_phone)

Sample output (truncated):

crc32 : 44c5dc97
title : Gyroscope (rotation rate)
localTitle : Gyroscope (vitesse angulaire)
category : Raw Sensors
localCategory : Capteurs
buffers : [{'name': 'gyrX', 'size': 0}, {'name': 'gyrY', 'size': 0}, {'name': 'gyrZ', 'size': 0}, {'name': 'gyr', 'size': 0}, {'name': 'gyr_time', 'size': 0}]
inputs : [{'source': 'gyroscope', 'outputs': [{'x': 'gyrX'}, {'y': 'gyrY'}, {'z': 'gyrZ'}, {'abs': 'gyr'}, {'t': 'gyr_time'}]}]
export : [{'set': 'Raw Data', 'sources': [{'label': 'Time (s)', 'buffer': 'gyr_time'}, {'label': 'Gyroscope x (rad/s)', 'buffer': 'gyrX'}, {'label': 'Gyroscope y (rad/s)', 'buffer': 'gyrY'}, {'label': 'Gyroscope z (rad/s)', 'buffer': 'gyrZ'}, {'label': 'Absolute (rad/s)', 'buffer': 'gyr'}]}]

accelerometer    Name : ICM20602 Accelerometer
...
camera2api : [{"id":"0","facing":"LENS_FACING_BACK","hardwareLevel":"HARDWARE_LEVEL_3","capabilities":["CAPABILIT ...
camera2apiFull : [{"id":"0","facing":"LENS_FACING_BACK","hardwareLevel":"HARDWARE_LEVEL_3","capabilities":["CAPABILIT ...

Selecting Buffers for an Experiment

Buffer order is based on the export key. To select gyr_time, gyrZ, and gyrX:

my_phone.buffer_needed([(0, (0, 3, 1))])

To check buffer selection:

my_phone.print_select_buffer()

Expected output:

Buffer  gyr_time
Buffer  gyrZ
Buffer  gyrX

Reading mobile sensor Data

Clear all buffer data, start data acquisition, wait for 2 seconds, then retrieve any data in a list:

my_phone.clear_data()
my_phone.start()
time.sleep(2)
my_phone.read_buffers(mode_data=phyphox.BufferMode.FULL)
last_tab = my_phone.get_last_buffer_read()
te=(-last_tab1[0][0][0]+ last_tab1[0][0][-1])/(len(last_tab1[0][1])-1)
print("data length {0} from Time {1} to {2}".format(len(last_tab1[0][1]), last_tab1[0][0][0], last_tab1[0][0][-1]))
print("Hope next time {0}.".format(last_tab1[0][0][-1]+te))

Now wait 0.5 seconds and retrieve any new data:

time.sleep(0.5)
my_phone.read_buffers()
last_tab1 = my_phone.get_last_buffer_read()
print("data length {0} from Time {1} to {2}".format(len(last_tab1[0][1]), last_tab1[0][0][0], last_tab1[0][0][-1]))
print("Hope next time {0}.".format(last_tab1[0][0][-1]+te))

Stop sampling

my_phone.stop()

Sample output

data length 380 from Time 0.095016596 to 1.9895734
Hope next time 1.9945722306174143.
data length 127 from Time 1.9945783 to 2.6244306
Hope next time 2.6294294306174146.

Credits

This library was developed by Laurent Berger with the help from phyphox forum and github issues.

Licence

This library is released under the GNU Lesser General Public Licence v3.0.

Contact

If you have questions or issues, feel free to open an issue on the GitHub repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

phyphox_py-0.0.6.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

phyphox_py-0.0.6-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

Details for the file phyphox_py-0.0.6.tar.gz.

File metadata

  • Download URL: phyphox_py-0.0.6.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for phyphox_py-0.0.6.tar.gz
Algorithm Hash digest
SHA256 5bea31243f536c60fbfd8cac2dbbaa2c15d11d12cb6c201235b6f111fcd68c6b
MD5 d3eb83d25bd503f41e3fbe1c99f85f90
BLAKE2b-256 12e27dd1571b59bb75d051c799792151f9fa1b55e14d89e8c34ad5f459ea92bf

See more details on using hashes here.

File details

Details for the file phyphox_py-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: phyphox_py-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 20.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for phyphox_py-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 151e16486a77110d8679ba9ab249098c80325cc7b173a5fdc07fde31640eb16a
MD5 064290fdbea957f7c587b470d5bc7ac3
BLAKE2b-256 42ca3ed81929b57e321c87b6c881a60725201d7a7555f40a75c7d8611aaaefba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page