I have a 6 DoF sensor that outputs various data into a text file. Currently the text output looks like
14:46:25,22.835882352941177,"(-0.020917304775809907, 0.041168453348568536, -0.03810413481453269)"
And I would like it to output
14:46:25,22.835882352941177, -0.020917304775809907, 0.041168453348568536, -0.03810413481453269
The problem lies in how mpu.acceleration outputs into the file
My attempt so far is as follows:
def timec():
now = datetime.now().time()
current_time = now.strftime("%H:%M:%S")
return current_time
def MPU():
i2c = board.I2C() # uses board.SCL and board.SDA
mpu = adafruit_mpu6050.MPU6050(i2c)
while True:
print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (mpu.acceleration))
print("Gyro X:%.2f, Y: %.2f, Z: %.2f rad/s" % (mpu.gyro))
print("Temperature: %.2f C" % mpu.temperature)
print("")
time.sleep(1)
temp = mpu.temperature
gy = mpu.gyro
accel = mpu.acceleration
return temp, gy, accel
if __name__ == '__main__':
with open('Text FILE72', 'a', newline='') as f:
write = csv.writer(f)
while True:
ctime = timec()
temp, gy, accel = MPU()
alt = BMP390()
# something something = BNO055()
# something something = solarcircuit1()
Rows = (ctime, temp, gy) # add other variables such as bno055 and circuit
write.writerow(Rows)
f.flush()
time.sleep(1)
Is there a way to dissect the output of acceleration into individual integers without parenthesis and quotes?