Visualize event congestion in public space with a laser rangefinder

Overview

【reference】 About area management (Ministry of Land, Infrastructure, Transport and Tourism)  https://www.mlit.go.jp/common/001059393.pdf Regional Revitalization Town Development --Area Management- (Cabinet Secretariat Town / People / Work Creation Headquarters Secretariat)  https://www.kantei.go.jp/jp/singi/sousei/about/areamanagement/areamanagement_panf.pdf

What to prepare

IMG_0131.JPG IMG_0197.JPG

Preparation

assembly

programming

distance.py


#!/usr/bin/env python

import time
import sys
import signal

import VL53L1X

import ambient
import datetime
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.OUT) #For LED blinking
from time import sleep


print("""distance.py

Display the distance read from the sensor.

Uses the "Short Range" timing budget by default.

Press Ctrl+C to exit.

""")

ambi = ambient.Ambient(xxxxx, 'xxxxxxxxxxxxxxxx') #← ambient channel ID and light key
count = 0
sndcnt = 0

# Open and start the VL53L1X sensor.
# If you've previously used change-address.py then you
# should use the new i2c address here.
# If you're using a software i2c bus (ie: HyperPixel4) then
# you should `ls /dev/i2c-*` and use the relevant bus number.
tof = VL53L1X.VL53L1X(i2c_bus=1, i2c_address=0x29)
tof.open()

# Optionally set an explicit timing budget
# These values are measurement time in microseconds,
# and inter-measurement time in milliseconds.
# If you uncomment the line below to set a budget you
# should use `tof.start_ranging(0)`
tof.set_timing(66000, 70)

tof.start_ranging(0)  # Start ranging
                      # 0 = Unchanged
                      # 1 = Short Range
                      # 2 = Medium Range
                      # 3 = Long Range

running = True


def exit_handler(signal, frame):
    global running
    running = False
    tof.stop_ranging()
    print()
    sys.exit(0)


# Attach a signal handler to catch SIGINT (Ctrl+C) and exit gracefully
signal.signal(signal.SIGINT, exit_handler)

while running:
    distance_in_mm = tof.get_distance()
    print("Distance: {}mm".format(distance_in_mm))

    now = datetime.datetime.now()
    minute = '{0:%M}'.format(now)
    second = '{0:%S}'.format(now)

    print(minute)
    print(second)

    if distance_in_mm < 1300:  #Threshold for counting or not(mm)

        count += 1
        GPIO.output(25, GPIO.HIGH)  #LED blinking
        sleep(0.5)
        GPIO.output(25, GPIO.LOW)
        sleep(0.5)

    if int(minute) % 5 == 0 and int(second) == 0:

        if sndcnt < 1:

            r = ambi.send({'d1': count})
            if r.status_code != 200:
                continue

            print(count)
            print("***sended***\n")

            count = 0

        sndcnt += 1

    else:

        sndcnt = 0

    time.sleep(0.1)

State of installation on site

IMG_0138.JPG IMG_0139.JPG IMG_0140.JPG

result

Bug content

For the future

Recommended Posts

Visualize event congestion in public space with a laser rangefinder
[In one line] Visualize like a lawn with just Pandas
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
Draw a heart in Ruby with PyCall