IanHarvey / bluepy

Python interface to Bluetooth LE on Linux
Other
1.6k stars 490 forks source link

No Data out of accelerometer, magnetometer, gyroscope #336

Closed OgLocGreen closed 5 years ago

OgLocGreen commented 5 years ago

My Question is why do i have to Read more Senors on the Ti-CC2650 board to get the right data for the accelerometer, magnetometer, gyroscope. If i only read Accelormeter i wont get any data. If got two Sensor to Test with. Below is my Code and Output i get. Im happy if someone has some suggestion for improvements. Greetings Green

My Code:

import time
import datetime
import sensortag

#Sensor1 Init
tag = sensortag.SensorTag("CC:78:AB:7F:88:03")
sensors = [tag.accelerometer,tag.magnetometer,tag.gyroscope]
[s.enable() for s in sensors ]

#Sensor2 Init
tag2 = sensortag.SensorTag("B0:91:22:F6:84:84")
sensors2 = [tag2.humidity,tag2.IRtemperature,tag2.accelerometer,tag2.magnetometer,tag2.gyroscope]
[s.enable() for s in sensors2 ]

while True:
    timestamp = time.time()
    timestring = datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')

    #Sensor1
    [ s.enable() for s in sensors ]
    accel, magnet,gyro = [ s.read() for s in sensors]
    time.sleep(1.1)
    accel,magnet,gyro = [ s.read() for s in sensors ]
    [ s.disable() for s in sensors ]
    #print timestring, "accel",accel,"magnet",magnet,"gyro",gyro

    #Sensor2
    [ s.enable() for s in sensors2 ]
    hum2,IRtemp2, accel2, magnet2,gyro2 = [ s.read() for s in sensors2]
    time.sleep(1.1)
    hum2,IRtemp2, accel2,magnet2,gyro2 = [ s.read() for s in sensors2 ]
    [ s.disable() for s in sensors2 ]
    #print timestring, "accel2",accel,"magnet2",magnet,"gyro2",gyro

    #Printing Sensordata
    print timestring, "accel",accel,"magnet",magnet,"gyro",gyro
    print timestring, "accel2",accel2,"magnet2",magnet2,"gyro2",gyro2

    date = datetime.datetime.now()
tag.disconnect()

My Output:

2019-01-13 16:53:08 accel (0.0, 0.0, 0.0) magnet (0.0, 0.0, 0.0) gyro (0.0, 0.0, 0.0)
2019-01-13 16:53:08 accel2 (0.003173828125, -0.0478515625, 1.014892578125) magnet2 (-62.52454212454212, -25.489621489621488, 29.987789987789988) gyro2 (1.42669677734375, -3.39508056640625, -4.99725341796875)
2019-01-13 16:53:12 accel (0.0, 0.0, 0.0) magnet (0.0, 0.0, 0.0) gyro (0.0, 0.0, 0.0)
2019-01-13 16:53:12 accel2 (0.008544921875, 0.00439453125, 1.0615234375) magnet2 (-61.774847374847376, -26.83907203907204, 28.188522588522588) gyro2 (-0.0152587890625, -9.0179443359375, -4.547119140625)
2019-01-13 16:53:16 accel (0.0, 0.0, 0.0) magnet (0.0, 0.0, 0.0) gyro (0.0, 0.0, 0.0)
2019-01-13 16:53:16 accel2 (0.028564453125, 0.000244140625, 1.08642578125) magnet2 (-62.52454212454212, -25.03980463980464, 29.987789987789988) gyro2 (0.08392333984375, -8.331298828125, -4.95147705078125)
2019-01-13 16:53:20 accel (0.0, 0.0, 0.0) magnet (0.0, 0.0, 0.0) gyro (0.0, 0.0, 0.0)
2019-01-13 16:53:20 accel2 (0.010986328125, -0.025390625, 1.088134765625) magnet2 (-63.873992673992674, -27.288888888888888, 27.88864468864469) gyro2 (-0.81634521484375, -4.2572021484375, -3.97491455078125)

thanks for the time.

PrzemoF commented 5 years ago

I'd start with cleaning up the code. You don't use data variable and you do strange things with enabling sensors twice? Then you read them twice with a short break between - why? If you ask for help try to provide minimum working (or not working code) - remove your commented out debug prints and so on. Do you need to enable/disable sensors all the time? It's a genuine question - I'm not familiar with that hardware. Also you doesn't seem to disconnect tag2? P.S. A good idea is to use code checker (flake8, pylint)