UtamaDonny

csvsendarduino.py

Jul 29th, 2021
648
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # %%
  2. import time
  3. import struct
  4. import serial
  5. import csv
  6.  
  7. with open('Book1.csv',mode='r',newline='',encoding='utf-8-sig') as csvfile:
  8.     data = csv.reader(csvfile,delimiter=',')
  9.     ax,ay,az,gx,gy,gz,mx,my,mz=[],[],[],[],[],[],[],[],[]
  10.     for row in data:
  11.       ax.append(float(row[0]))
  12.       ay.append(float(row[1]))
  13.       az.append(float(row[2]))
  14.       gx.append(float(row[3]))
  15.       gy.append(float(row[4]))
  16.       gz.append(float(row[5]))
  17.       mx.append(float(row[6]))
  18.       my.append(float(row[7]))
  19.       mz.append(float(row[8]))
  20. # %%
  21. ser=serial.Serial('/dev/ttyUSB0',9600)
  22. time.sleep(2)
  23. # %%
  24. ser.write(struct.pack('>BBBBBBBBB',ax,ay,az,gx,gy,gz,mx,my,mz))
  25. # %%
RAW Paste Data