def start_sensing(): measurements_list = [] A_sensor_list = [] #0 C_sensor_list = [] #1 time_list = [] time = 0 # seconds = int(seconds_entry.get()) samples = int(samples_entry.get()) period = 1000 // samples # gdx.start(period=period) # # for i in range(seconds*samples): measurements = gdx.read() if measurements == None: break print(measurements) measurements_list.append(measurements) # # for line in measurements_list: A_sensor_list.append(line[0]) C_sensor_list.append(line[1]) time_list.append(time) time += 1/samples # # ax.clear() # plt.title('Sensor Graphing ') plt.xlabel('Time (Seconds)') plt.ylabel('amu or something idk') # ax.plot(time_list, A_sensor_list, c='skyblue') ax.plot(time_list, C_sensor_list, c='lightgreen')
def start_recording(): seconds = int(seconds_entry.get()) samples = int(samples_entry.get()) axis = np.arange(0, seconds, 1 / samples) gdx.start(1000 // samples) red = [] green = [] blue = [] # fig, ax = plt.subplots(1,1) ax.cla() for _ in range(seconds * samples): # print(gdx.read()) vals = gdx.read() if vals == None: break r, g, b = vals red.append(r) green.append(g) blue.append(b) gdx.stop() print(axis) ax.plot(axis, red, color='r') ax.plot(axis, green, color='g') ax.grid() ax.plot(axis, blue, color='b') ax.legend(['r', 'g', 'b']) ax.set_title("Lights") ax.set_xlabel('Time (s)') ax.set_ylabel('lux')
def take_sample(): gdx.open_usb() gdx.select_sensors([5, 6, 7]) gdx.start(period=1) sample = gdx.read() print(sample) gdx.stop() gdx.close()
def start_reading(): seconds = int(seconds_field.get()) pers = int(samples_field.get()) print(seconds, pers) gdx.start(period=1000 // pers) red = [] green = [] blue = [] for i in range(seconds * pers): vals = gdx.read( ) #returns a list of measurements from the sensors selected. if vals == None: break red.append(vals[0]) green.append(vals[1]) blue.append(vals[2]) print(vals) graph_data(seconds, pers, red, green, blue)
def start_reading(): seconds = int(seconds_field.get()) samples = int(samples_field.get()) sound_a, sound_c = [], [] rate = 1000 // samples gdx.start(rate) interval = 1 / samples length = np.arange(0, seconds, interval) ax.cla() for i in range(samples * seconds): measure = gdx.read() sound_a.append(measure[0]) sound_c.append(measure[1]) if measure == None: break plt.yscale('linear') ax.plot(length, sound_a, c='red') ax.plot(length, sound_c, c='blue') plt.ylabel(ylabel='Sound(decibels)') plt.xlabel(xlabel='Time(seconds)') plt.show() gdx.stop()
gdx.device_info() gdx.enabled_sensor_info() gdx.sensor_info() gdx.discover_ble_devices() monitor_rssi() >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Below is a simple starter program. Note that this program does not pass any arguments in the functions. Go to the gdx_getting_started_2.py example to see how you can pass arguments to the open(), select sensors(), and start() functions, and avoid the prompts. **** This example assumes the Go Direct sensor is connected via USB. ''' import gdx #the gdx function calls are from a gdx.py file inside the gdx folder. gdx = gdx.gdx() gdx.open_usb() gdx.select_sensors() gdx.start() for i in range(0,5): measurements = gdx.read() #returns a list of measurements from the sensors selected. if measurements == None: break print(measurements) gdx.stop() gdx.close()
import gdx ''' In this example we are saving the data to a csv file to be opened with Excel. ''' from gdx import gdx gdx = gdx.gdx() import csv myFile = open('csvexample.csv', 'w', newline='') writer = csv.writer(myFile) gdx.open_usb() gdx.select_sensors([1, 2]) gdx.start(period=500) column_headers = gdx.enabled_sensor_info() writer.writerow(column_headers) for i in range(0, 5): measurements = gdx.read() if measurements == None: break writer.writerow(measurements) print(measurements) gdx.stop() gdx.close()
def read_data(): return gdx.read() screen.ontimer(read_data, 100)
import gdx, matplotlib.pyplot as plt gdx = gdx.gdx() samples = int(input('How many samples would you like to take?: ')) gdx.open_usb() gdx.select_sensors([2, 3]) gdx.start(period=100) sound_a, sound_c, time = [], [], [] count = 0 for i in range(samples): measure = gdx.read() sound_a.append(measure[0]) sound_c.append(measure[1]) time.append(count) count += 1 plt.ion() plt.gcf() plt.plot(sound_a, color='red') plt.plot(sound_c, color='green') plt.draw() plt.pause(.05) if measure == None: break #plots this data on one graph plt.plot(time, sound_a) #graphs the a sounds