def __init__(self, config="/etc/cellularmonitor.json"):
     print('Init DBUS')
     dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
     print('Init temperature sensor')
     self.sensor_temp = adt7410.ADT7410(smbus.SMBus(I2C_BUS), 0x48)
     print('Init range sensor')
     self.sensor_range = vl53l0x.VL53L0X(smbus.SMBus(I2C_BUS), 0x29)
     print('Init sms manager')
     self.sms = smsmanager.SMSManager(self.sms_callback)
     print('Load config')
     self.conf_file = config
     self.load_config()
示例#2
0
	def calculate():
		try:
			i2c = I2C(-1, Pin(5), Pin(4))
			tof = vl53l0x.VL53L0X(i2c)
			while len(distance_list) < 10:
				tof.start()
				tof.read()
				print(tof.read())
				distance=(tof.read())/10
				tof.stop()
				time.sleep(0.1)
				print('Distance: {}cm'.format(distance))
				if distance > 0.5:
					distance_list.append(distance)
		except:
			print("Nekaj je narobe pri calculate()")
示例#3
0
#
#

# imports needed
from machine import I2C, Pin
import vl53l0x
import time
import socket
import network

dist1Unit = 'mm'
dist1ID = '05001'

# Setup i2c to talk to sensor
i2c = I2C(-1, Pin(5), Pin(4))
sensor = vl53l0x.VL53L0X(i2c)

# set up socket
# Get local IP address
wlan = network.WLAN(network.STA_IF)
hostip = wlan.ifconfig()[0]
port = 10000

# Open a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = (hostip, port)
sock.bind(server_address)

# Main loop
#
# The main loop waits for a packet to arrive and then takes action
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import time
import vl53l0x

# Create a VL53L0X object for device on TCA9548A bus 1
tof1 = vl53l0x.VL53L0X(tca9548a_num=1, tca9548a_addr=0x70)
# Create a VL53L0X object for device on TCA9548A bus 2
tof2 = vl53l0x.VL53L0X(tca9548a_num=2, tca9548a_addr=0x70)
tof1.connect()
tof2.connect()

# Start ranging on TCA9548A bus 1
tof1.start_ranging(vl53l0x.Vl53l0xAccuracyMode.BETTER)
# Start ranging on TCA9548A bus 2
tof2.start_ranging(vl53l0x.Vl53l0xAccuracyMode.BETTER)

timing = tof1.get_timing()
if timing < 20000:
    timing = 20000
print("Timing %d ms" % (timing / 1000))
示例#5
0
import config
import machine
import utils
import vl53l0x

utils.printLog("NODEMCU", "radar boot up")

i2c = machine.I2C(scl=machine.Pin(config.D2), sda=machine.Pin(config.D1), freq=400000)

distanceSensor = vl53l0x.VL53L0X(i2c, 0x29)

def timeout100ms(timer):
    utils.printLog("RADAR", distanceSensor.read())

tim1 = machine.Timer(0)
tim1.init(period=100, mode=machine.Timer.PERIODIC, callback=timeout100ms)
示例#6
0
        if prev_angle <= 0 and curr_angle < prev_angle:
            if head_swing_side == 'neutral' or head_swing_side == 'left':
                if head_swing_side == 'left':
                    left_swing_count = left_swing_count + 1
                    print("left food distance=", min(left_ping_distances))
                head_swing_side = 'right'
            if (right_swing_count % ping_stride) == 0:
                for i in range(right_ping_angles_len):
                    ping_angle = right_ping_angles[i]
                    curr_angle_delta = abs(curr_angle - ping_angle)
                    if abs(prev_angle -
                           ping_angle) >= curr_angle_delta and abs(
                               next_angle - ping_angle) >= curr_angle_delta:
                        sleep(ping_before_pause)  ###
                        I2C_sensor_bus = I2C(0, speed=100000, sda=32, scl=33)
                        distance_sensor = vl53l0x.VL53L0X(I2C_sensor_bus)
                        sleep(ping_before_pause)
                        try:
                            right_ping_distances[i] = distance_sensor.read()
                        except:
                            print("error sensing distance")
                        I2C_sensor_bus.deinit()
                        print("ping: angle=", curr_angle, "distance=",
                              right_ping_distances[i])  ###
                        if right_ping_distances[i] > max_valid_food_distance:
                            right_ping_distances[
                                i] = max_valid_food_distance + 1
                        sleep(ping_after_pause)

        # Check left food distance.
        if prev_angle >= 0 and curr_angle > prev_angle:
示例#7
0
import time
import vl53l0x

tof = vl53l0x.VL53L0X(tca9548a_num=1, tca9548a_addr=0x70)
tof.connect()
tof.start_ranging(vl53l0x.Vl53l0xAccuracyMode.BEST)

tic = time.time()
while True:
    try:
        if tof.data_ready:
            print(
                f"\rDistance = {tof.get_data()};"
                f"Time = {time.time() - tic}",
                end="")
            tic = time.time()
    except KeyboardInterrupt:
        break

tof.stop_ranging()
tof.disconnect()
示例#8
0
# Simple demo of the VL53L0X distance sensor.
# Will print the sensed range/distance every second.
import time
import machine
import vl53l0x

# Initialize I2C bus and sensor.
i2c = machine.I2C(1, freq=400000)
vl53 = vl53l0x.VL53L0X(i2c)

# Optionally adjust the measurement timing budget to change speed and accuracy.
# See the example here for more details:
#   https://github.com/pololu/vl53l0x-arduino/blob/master/examples/Single/Single.ino
# For example a higher speed but less accurate timing budget of 20ms:
# vl53.measurement_timing_budget = 20000
# Or a slower but more accurate timing budget of 200ms:
# vl53.measurement_timing_budget = 200000
# The default timing budget is 33ms, a good compromise of speed and accuracy.

# Main loop will read the range and print it every second.
while True:
    print("Range: {0}mm".format(vl53.range))
    time.sleep(1.0)