Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bring develop to master for DexterOS 2.0 #44

Merged
merged 15 commits into from
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Python/Examples/EasyDistanceSensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python
#
# https://www.dexterindustries.com
#
# Copyright (c) 2017 Dexter Industries
# Released under the MIT license (http://choosealicense.com/licenses/mit/).
# For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md
#
# Python example program for the Dexter Industries Distance Sensor

from __future__ import print_function
from __future__ import division

# import the modules
from di_sensors.easy_distance_sensor import EasyDistanceSensor
from time import sleep

# instantiate the distance object
my_sensor = EasyDistanceSensor()

# and read the sensor iteratively
while True:
read_distance = my_sensor.read()
print("distance from object: {} mm".format(read_distance))

sleep(0.1)
51 changes: 51 additions & 0 deletions Python/Examples/EasyDistanceSensorMutexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python
#
# https://www.dexterindustries.com
#
# Copyright (c) 2017 Dexter Industries
# Released under the MIT license (http://choosealicense.com/licenses/mit/).
# For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md
#
# Python example program for the Dexter Industries Temperature Humidity Pressure Sensor

from __future__ import print_function
from __future__ import division

# do the import stuff
from di_sensors.easy_distance_sensor import EasyDistanceSensor
from time import time, sleep
from threading import Thread, Event, get_ident

# instantiate the distance object
my_sensor = EasyDistanceSensor(use_mutex = True)
start_time = time()
runtime = 2.0
# create an event object for triggering the "shutdown" of each thread
stop_event = Event()

# target function for each thread
def readingSensor():
while not stop_event.is_set():
thread_id = get_ident()
distance = my_sensor.read()
print("Thread ID = {} with distance value = {}".format(thread_id, distance))
sleep(0.001)

# create an object for each thread
thread1 = Thread(target = readingSensor)
thread2 = Thread(target = readingSensor)

# and then start them
thread1.start()
thread2.start()

# let it run for [runtime] seconds
while time() - start_time <= runtime:
sleep(0.1)

# and then set the stop event variable
stop_event.set()

# and wait both threads to end
thread1.join()
thread2.join()
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
#!/usr/bin/env python
#
# https://www.dexterindustries.com
#
# Copyright (c) 2017 Dexter Industries
# Released under the MIT license (http://choosealicense.com/licenses/mit/).
# For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md
#
# Python example program for the Dexter Industries Light Color Sensor

from __future__ import print_function
from __future__ import division

import time
from di_sensors.light_color_sensor import LightColorSensor

print("Example program for reading a Dexter Industries Light Color Sensor on an I2C port.")

lcs = LightColorSensor(led_state = True)

while True:
# Read the R, G, B, C color values
red, green, blue, clear = lcs.get_raw_colors()

# Print the values
print("Red: {:5.3f} Green: {:5.3f} Blue: {:5.3f} Clear: {:5.3f}".format(red, green, blue, clear))

time.sleep(0.02)
#!/usr/bin/env python
#
# https://www.dexterindustries.com
#
# Copyright (c) 2017 Dexter Industries
# Released under the MIT license (http://choosealicense.com/licenses/mit/).
# For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md
#
# Python example program for the Dexter Industries Light Color Sensor
from __future__ import print_function
from __future__ import division
from time import sleep
from di_sensors.easy_light_color_sensor import EasyLightColorSensor
print("Example program for reading a Dexter Industries Light Color Sensor on an I2C port.")
my_lcs = EasyLightColorSensor(led_state = True)
while True:
# Read the R, G, B, C color values
red, green, blue, clear = my_lcs.safe_raw_colors()
# Print the values
print("Red: {:5.3f} Green: {:5.3f} Blue: {:5.3f} Clear: {:5.3f}".format(red, green, blue, clear))
sleep(0.02)
34 changes: 34 additions & 0 deletions Python/Examples/EasyTempHumPress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
#
# https://www.dexterindustries.com
#
# Copyright (c) 2017 Dexter Industries
# Released under the MIT license (http://choosealicense.com/licenses/mit/).
# For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md
#
# Python example program for the Dexter Industries Temperature Humidity Pressure Sensor

from __future__ import print_function
from __future__ import division

from time import sleep
from di_sensors.easy_temp_hum_press import EasyTHPSensor

print("Example program for reading a Dexter Industries Temperature Humidity Pressure Sensor on an I2C port.")

my_thp = EasyTHPSensor()

while True:
# Read the temperature
temp = my_thp.safe_celsius()

# Read the relative humidity
hum = my_thp.safe_humidity()

# Read the pressure
press = my_thp.safe_pressure()

# Print the values
print("Temperature: {:5.3f} Humidity: {:5.3f} Pressure: {:5.3f}".format(temp, hum, press))

sleep(0.02)
47 changes: 47 additions & 0 deletions Python/Examples/LineFollower.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python
#
# https://www.dexterindustries.com
#
# Copyright (c) 2017 Dexter Industries
# Released under the MIT license (http://choosealicense.com/licenses/mit/).
# For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md
#
# Python example program for the Dexter Industries Line Follower sensor

from __future__ import print_function
from __future__ import division

import time
from di_sensors import line_follower

print("Example program for reading a Dexter Industries Line Follower sensor on GPG3 AD1 port")

lf = line_follower.LineFollower(bus = "GPG3_AD1")

'''
cd ~/Dexter/DI_Sensors/Python
sudo python setup.py install

python ~/Dexter/DI_Sensors/Python/Examples/LineFollower.py

'''

print("Manufacturer : %s" % lf.get_manufacturer())
print("Name : %s" % lf.get_board())
print("Firmware Version : %d" % lf.get_version_firmware())

while True:
# Read the line sensors values
values = lf.read_sensors()
str = ""
for v in range(len(values)):
str += "%.3f " % values[v]
print(str)

values = lf.read_sensors(lf.BOTH)
str = ""
for v in range(len(values)):
str += "%.3f " % values[v]
print(str)

time.sleep(0.1)
58 changes: 29 additions & 29 deletions Python/di_sensors/BME280.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,53 +134,53 @@ def __init__(self, bus = "RPI_1", t_mode = OSAMPLE_1, h_mode = OSAMPLE_1, p_mode
def _load_calibration(self):
# Read calibration data

self.dig_T1 = self.i2c_bus.read_reg_16u(REG_DIG_T1)
self.dig_T2 = self.i2c_bus.read_reg_16s(REG_DIG_T2)
self.dig_T3 = self.i2c_bus.read_reg_16s(REG_DIG_T3)

self.dig_P1 = self.i2c_bus.read_reg_16u(REG_DIG_P1)
self.dig_P2 = self.i2c_bus.read_reg_16s(REG_DIG_P2)
self.dig_P3 = self.i2c_bus.read_reg_16s(REG_DIG_P3)
self.dig_P4 = self.i2c_bus.read_reg_16s(REG_DIG_P4)
self.dig_P5 = self.i2c_bus.read_reg_16s(REG_DIG_P5)
self.dig_P6 = self.i2c_bus.read_reg_16s(REG_DIG_P6)
self.dig_P7 = self.i2c_bus.read_reg_16s(REG_DIG_P7)
self.dig_P8 = self.i2c_bus.read_reg_16s(REG_DIG_P8)
self.dig_P9 = self.i2c_bus.read_reg_16s(REG_DIG_P9)

self.dig_H1 = self.i2c_bus.read_reg_8u(REG_DIG_H1)
self.dig_H2 = self.i2c_bus.read_reg_16s(REG_DIG_H2)
self.dig_H3 = self.i2c_bus.read_reg_8u(REG_DIG_H3)
self.dig_H6 = self.i2c_bus.read_reg_8s(REG_DIG_H7)

h4 = self.i2c_bus.read_reg_8s(REG_DIG_H4)
self.dig_T1 = self.i2c_bus.read_16(REG_DIG_T1)
self.dig_T2 = self.i2c_bus.read_16(REG_DIG_T2, signed = True)
self.dig_T3 = self.i2c_bus.read_16(REG_DIG_T3, signed = True)

self.dig_P1 = self.i2c_bus.read_16(REG_DIG_P1)
self.dig_P2 = self.i2c_bus.read_16(REG_DIG_P2, signed = True)
self.dig_P3 = self.i2c_bus.read_16(REG_DIG_P3, signed = True)
self.dig_P4 = self.i2c_bus.read_16(REG_DIG_P4, signed = True)
self.dig_P5 = self.i2c_bus.read_16(REG_DIG_P5, signed = True)
self.dig_P6 = self.i2c_bus.read_16(REG_DIG_P6, signed = True)
self.dig_P7 = self.i2c_bus.read_16(REG_DIG_P7, signed = True)
self.dig_P8 = self.i2c_bus.read_16(REG_DIG_P8, signed = True)
self.dig_P9 = self.i2c_bus.read_16(REG_DIG_P9, signed = True)

self.dig_H1 = self.i2c_bus.read_8(REG_DIG_H1)
self.dig_H2 = self.i2c_bus.read_16(REG_DIG_H2, signed = True)
self.dig_H3 = self.i2c_bus.read_8(REG_DIG_H3)
self.dig_H6 = self.i2c_bus.read_8(REG_DIG_H7, signed = True)

h4 = self.i2c_bus.read_8(REG_DIG_H4, signed = True)
h4 = (h4 << 4)
self.dig_H4 = h4 | (self.i2c_bus.read_reg_8u(REG_DIG_H5) & 0x0F)
self.dig_H4 = h4 | (self.i2c_bus.read_8(REG_DIG_H5) & 0x0F)

h5 = self.i2c_bus.read_reg_8s(REG_DIG_H6)
h5 = self.i2c_bus.read_8(REG_DIG_H6, signed = True)
h5 = (h5 << 4)
self.dig_H5 = h5 | (
self.i2c_bus.read_reg_8u(REG_DIG_H5) >> 4 & 0x0F)
self.i2c_bus.read_8(REG_DIG_H5) >> 4 & 0x0F)

def _read_raw_temp(self):
# read raw temperature data once it's available
while (self.i2c_bus.read_reg_8u(REG_STATUS) & 0x08):
while (self.i2c_bus.read_8(REG_STATUS) & 0x08):
time.sleep(0.002)
data = self.i2c_bus.read_reg_list(REG_TEMP_DATA, 3)
data = self.i2c_bus.read_list(REG_TEMP_DATA, 3)
return ((data[0] << 16) | (data[1] << 8) | data[2]) >> 4

def _read_raw_pressure(self):
# read raw pressure data once it's available
while (self.i2c_bus.read_reg_8u(REG_STATUS) & 0x08):
while (self.i2c_bus.read_8(REG_STATUS) & 0x08):
time.sleep(0.002)
data = self.i2c_bus.read_reg_list(REG_PRESSURE_DATA, 3)
data = self.i2c_bus.read_list(REG_PRESSURE_DATA, 3)
return ((data[0] << 16) | (data[1] << 8) | data[2]) >> 4

def _read_raw_humidity(self):
# read raw humidity data once it's available
while (self.i2c_bus.read_reg_8u(REG_STATUS) & 0x08):
while (self.i2c_bus.read_8(REG_STATUS) & 0x08):
time.sleep(0.002)
data = self.i2c_bus.read_reg_list(REG_HUMIDITY_DATA, 2)
data = self.i2c_bus.read_list(REG_HUMIDITY_DATA, 2)
return (data[0] << 8) | data[1]

def read_temperature(self):
Expand Down
Loading