5

I'm new to raspberry pi. I was wondering if it was possible to connect an android phone to raspberry pi so that Rpi can read the data from the phone's sensors. It could be a direct USB connection. Ideally I would like to use the phone for its 3g connectivity, gps and accelerometer. I'm going for this method, as the individual hardware meant for Rpi is quite expensive, and I have android phones just lying around.

Tauseef Latif
  • 213
  • 2
  • 4
  • 7

2 Answers2

4

You can try using this app. It sends data from the sensors in UDP. It would only give you the information from the Accelerometer from the list you wanted.

Sensor id:
3 - Accelerometer (m/s^2)
4 - Gyroscope (rad/s)
5 - Magnetometer (micro-Tesla uT)

Example UDP packet: 890.71558, 3, 0.076, 9.809, 0.565, 4, -0.559, 0.032, -0.134, 5, -21.660,-36.960,-28.140

Timestamp [sec], sensorid, x, y, z, sensorid, x, y, z, sensorid, x, y, z

There is a sample program in the description:

import socket, traceback

host = ''
port = 5555

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.bind((host, port))

while 1:
    try:
        message, address = s.recvfrom(8192)
        print message
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        traceback.print_exc()

The pi can run this program, since its python with only standard libraries.

Ghanima
  • 15,855
  • 15
  • 61
  • 119
GuySoft
  • 895
  • 2
  • 9
  • 25
1

If you install python on your phone it will help you accesses the sensors, i use qpython on my android tablet, the module that you want to use is androidhelper, it will contain the tools to read the sensors.

http://code.google.com/p/python-for-android/downloads/detail?name=androidhelper.py

But this link is all of the documentation that i have managed to find.

Another way would be to write a program using java that could read the sensors, this method will most likely give you the most options but it will be the most challenging.

kyle k
  • 208
  • 2
  • 8