Пример #1
0
    def activate(self):
        assert self.params['address']
        assert self.params['bus']
        if 'name' in self.params: self.name = self.params['name']+' %i:%s' % (self.params['bus'],hex(self.params['address']))
        if not 'driver' in self.params.keys(): self.params['driver']=None

        self.params['n_channels']=4
        if not 'channel_names' in self.config:
            self.config['channel_names']=['Temperature','Instantaneous reading','Running mean','Delta']

        self.params['raw_units']=['degC','','','']
        self.config['eng_units']=['degC','','','']
        self.config['scale']=np.ones(self.params['n_channels'],)
        self.config['offset']=np.zeros(self.params['n_channels'],)
        if ('untitled' in self.name.lower()) or (self.name==''):
            self.name = 'MAX30105 optical sensor I2C %i:%s' % (self.params['bus'],self.params['address'])

        self.max30105 = MAX30105()
        self.max30105.setup(leds_enable=3)

        self.max30105.set_led_pulse_amplitude(1, 0.0)
        self.max30105.set_led_pulse_amplitude(2, 0.0)
        self.max30105.set_led_pulse_amplitude(3, 12.5)

        self.max30105.set_slot_mode(1, 'red')
        self.max30105.set_slot_mode(2, 'ir')
        self.max30105.set_slot_mode(3, 'green')
        self.max30105.set_slot_mode(4, 'off')

        self.hr = HeartRate(self.max30105)

        return
Пример #2
0
    def setup_particle_sensor(self):
        self.MAX30105 = MAX30105()
        self.MAX30105.setup(leds_enable=3)
        self.MAX30105.set_led_pulse_amplitude(1, 0.0)
        self.MAX30105.set_led_pulse_amplitude(2, 0.0)
        self.MAX30105.set_led_pulse_amplitude(3, 12.5)

        self.MAX30105.set_slot_mode(1, "red")
        self.MAX30105.set_slot_mode(2, "ir")
        self.MAX30105.set_slot_mode(3, "green")
        self.MAX30105.set_slot_mode(4, "off")
        self.hr = HeartRate(self.MAX30105)
Пример #3
0
import datetime
from max30105 import MAX30105, HeartRate

max30105 = MAX30105()
max30105.setup(leds_enable=3)

max30105.set_led_pulse_amplitude(1, 0.0)
max30105.set_led_pulse_amplitude(2, 0.0)
max30105.set_led_pulse_amplitude(3, 12.5)

max30105.set_slot_mode(1, 'red')
max30105.set_slot_mode(2, 'ir')
max30105.set_slot_mode(3, 'green')
max30105.set_slot_mode(4, 'off')

hr = HeartRate(max30105)

# Smooths wobbly data. Increase to increase smoothing.
mean_size = 20

# Compares current smoothed value to smoothed value x
# readings ago. Decrease this to increase detection
# speed.
delta_size = 10

# The delta threshold at which a change is detected.
# Decrease to make the detection more sensitive to
# fluctuations, increase to make detection less
# sensitive to fluctuations.
threshold = 10
Пример #4
0
class Device():
    def __init__(self):
        self.humidity = []
        self.temperature = []
        self.smoke_level = []
        self.mean_size = 100
        self.identifier = "0,0"

    def setup_network(self):
        self.network = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        connected = False
        while not connected:
            try:
                self.network.connect(("192.168.88.167", 25565))
                connected = True
            except:
                a = 1

    def upload_data(self):
        network_string = (  #str(round(self.calculate_humidity_trend(),5)) + "," +
            str(round(self.humidity[-1].value, 5)) + "," +
            #str(round(self.calculate_temperature_trend(),5)) + "," +
            str(round(self.temperature[-1].value, 5)) + "," +
            #str(round(self.calculate_smoke_level_trend(),5)) + "," +
            str(round(self.smoke_level[-1].value, 5)) + "," +
            str(round(self.pressure.value, 5)) + "," + str(self.identifier))

        network_string = network_string.encode()
        self.network.sendall(network_string)

    def update(self):
        dev.get_smoke_data()
        dev.get_humi_temp_data()

    def setup_particle_sensor(self):
        self.MAX30105 = MAX30105()
        self.MAX30105.setup(leds_enable=3)
        self.MAX30105.set_led_pulse_amplitude(1, 0.0)
        self.MAX30105.set_led_pulse_amplitude(2, 0.0)
        self.MAX30105.set_led_pulse_amplitude(3, 12.5)

        self.MAX30105.set_slot_mode(1, "red")
        self.MAX30105.set_slot_mode(2, "ir")
        self.MAX30105.set_slot_mode(3, "green")
        self.MAX30105.set_slot_mode(4, "off")
        self.hr = HeartRate(self.MAX30105)

    def setup_temp_humi_sensor(self):
        bus = smbus.SMBus(1)
        self.bme280 = BME280(i2c_dev=bus)

    def setup_sensors(self):
        self.setup_particle_sensor()
        self.setup_temp_humi_sensor()

    def get_smoke_data(self):
        data = []
        for i in range(self.mean_size * 3 + 1):
            samples = self.MAX30105.get_samples()
            if samples is not None:
                for sample in samples:
                    r = samples[2] & 0xff
                    d = self.hr.low_pass_fir(r)
                    data.append(d)

        mean = sum(data) / (self.mean_size * 3)

        self.smoke_level.append(DataPoint(mean, time.time))

    def get_humi_temp_data(self):
        temp_data = []
        humi_data = []
        pres_data = []
        for i in range(self.mean_size):
            temp_data.append(self.bme280.get_temperature())
            humi_data.append(self.bme280.get_humidity())
            pres_data.append(self.bme280.get_pressure())

        mean_temp = sum(temp_data) / self.mean_size
        mean_humi = sum(humi_data) / self.mean_size
        mean_pres = sum(pres_data) / self.mean_size

        self.humidity.append(DataPoint(mean_humi, time.time()))
        self.temperature.append(DataPoint(mean_temp, time.time()))
        self.pressure = DataPoint(mean_pres, time.time())

    """def calculate_humidity_trend(self):
Пример #5
0
lsr_12 = ImageFont.truetype("fonts/LiberationSans-Regular.ttf", 12)

# Set up MAX30105 Breakout
max30105 = MAX30105()
max30105.setup(leds_enable=2)

max30105.set_led_pulse_amplitude(1, 0.2)
max30105.set_led_pulse_amplitude(2, 12.5)
max30105.set_led_pulse_amplitude(3, 0)

max30105.set_slot_mode(1, 'red')
max30105.set_slot_mode(2, 'ir')
max30105.set_slot_mode(3, 'off')
max30105.set_slot_mode(4, 'off')

hr = HeartRate(max30105)
data = []
running = True

bpm = 0
bpm_avg = 0
beat_detected = False
beat_status = False


def sample():
    """Function to thread heartbeat values separately to
 OLED drawing"""
    global bpm, bpm_avg, beat_detected, beat_status

    average_over = 5
Пример #6
0
class max30105Device(i2cDevice):

    """ Class providing support for __
        Specify I2C bus and address on initialisation.
    """

    # Establish connection to device
    def activate(self):
        assert self.params['address']
        assert self.params['bus']
        if 'name' in self.params: self.name = self.params['name']+' %i:%s' % (self.params['bus'],hex(self.params['address']))
        if not 'driver' in self.params.keys(): self.params['driver']=None

        self.params['n_channels']=4
        if not 'channel_names' in self.config:
            self.config['channel_names']=['Temperature','Instantaneous reading','Running mean','Delta']

        self.params['raw_units']=['degC','','','']
        self.config['eng_units']=['degC','','','']
        self.config['scale']=np.ones(self.params['n_channels'],)
        self.config['offset']=np.zeros(self.params['n_channels'],)
        if ('untitled' in self.name.lower()) or (self.name==''):
            self.name = 'MAX30105 optical sensor I2C %i:%s' % (self.params['bus'],self.params['address'])

        self.max30105 = MAX30105()
        self.max30105.setup(leds_enable=3)

        self.max30105.set_led_pulse_amplitude(1, 0.0)
        self.max30105.set_led_pulse_amplitude(2, 0.0)
        self.max30105.set_led_pulse_amplitude(3, 12.5)

        self.max30105.set_slot_mode(1, 'red')
        self.max30105.set_slot_mode(2, 'ir')
        self.max30105.set_slot_mode(3, 'green')
        self.max30105.set_slot_mode(4, 'off')

        self.hr = HeartRate(self.max30105)

        return

    # Apply configuration
    def apply_config(self):
        # Currently no configurable parameters.
        return

    # Update device with new value, update lastValue and lastValueTimestamp
    def query(self):

        data=[]
        means=[]
        mean_size=20; delta_size=10
        delta=0; deltas=[]
        while len(means)<mean_size+1:
            samples = self.max30105.get_samples()
            if samples is not None:
                if len(samples)>2:
                    r = samples[2] & 0xff
                    d = self.hr.low_pass_fir(r)
                    data.append(d)
                    if len(data) > mean_size:
                        data.pop(0)
                    mean = sum(data) / float(len(data))
                    means.append(mean)
                    if len(means) > delta_size:
                        delta = means[-1] - means[-delta_size]
                    else:
                        delta = 0
                    deltas.append(delta)
            time.sleep(0.01)


        self.lastValue = [self.max30105.get_temperature(),d,mean,np.mean(deltas)]

        self.updateTimestamp()

        self.lastScaled = np.array(self.lastValue) * self.config['scale'] + self.config['offset']
            
        return

    # End connection to device.
    def deactivate(self):
        self.max30105.soft_reset()
        del self.max30105
        del self.hr
Пример #7
0
max30105.set_led_pulse_amplitude(1, 0.2)
max30105.set_led_pulse_amplitude(2, 12.5)
max30105.set_led_pulse_amplitude(3, 0)

max30105.set_slot_mode(1, 'red')
max30105.set_slot_mode(2, 'ir')
max30105.set_slot_mode(3, 'off')
max30105.set_slot_mode(4, 'off')


def display_heartrate(beat, bpm, avg_bpm):
    print("{} BPM: {:.2f}  AVG: {:.2f}".format("<3" if beat else "  ",
          bpm, avg_bpm))


hr = HeartRate(max30105)

print("""
NOTE! This code should not be used for medical diagnosis. It's
for fun/novelty use only, so bear that in mind while using it.

This example shows a readout of your heart rate in BPM (beats per
minute) and heartbeats detected using a heart emoticon <3.

It's best to hold the sensor against your fingertip (the fleshy side)
using a piece of wire or a rubber band looped through the mounting
holes on the breakout, as the sensor is very sensitive to small
movements and it's hard to hold your finger against the sensor with
even pressure.

If you're using your MAX30105 Breakout with Breakout Garden, then