The story of a Parking Sensor in 10 minutes with GrovePi + Starter Kit

At the beginning

10 minutes is not exaggerated but true, the breakdown is about 5 minutes while looking at the sample program that seems to be related, and about 5 minutes to connect the parts and write the code (actually copy and paste), totaling 10 It was about a minute

GrovePi+ Starter Kit GrovePi + Starter Kit is Seeed's [Grove Sensor](http: //: // An expansion board GrovePi that enables you to use www.seeedstudio.com/depot/s/grovefamily.html on your Raspberry Pi, assorted several Grove sensors. It's a set at a reasonable price, so it's a Grove system starter kit for Raspberry Pi users (I can only explain what you can tell from the name ^^;)

In the Review section (P56) of MagPi's Issue 33, [GrovePi + Starter Kit](http://www.dexterindustries.com/GrovePi/ get-started-with-the-grovepi / grove-pi-starter-kit /) was featured in a review book __ If you're a python fan who wants to get started with electronics, it's a great choice __ I was worried. Until then, it's just __ you don't have to worry about electrical connections __ (I'm very grateful to a software shop like me who doesn't like electricity just to not worry about it). I thought, but it seems that it is not so, and you can use the very convenient Cleaver Script.

Impression that I read while running the sample program by connecting the sensor for the time being

It was hard to tell which program was the sample of which sensor, but I gradually realized that it was running for the time being. This sounds fun, and you can do anything by just connecting the lines and reading and writing with an Arduino sketch-like syntax. In particular, __LCD is very convenient, and it's as easy as setting the character string you want to display and the color of the backlight __, and it seems that you can pay for what you bought.

Parking Sensor Looking at the parts of the Kit, I felt like I could make the Parking Sensor that appeared on MagPi's issue 31. From here, it took about 10 minutes to complete. Anyway __ it's as easy as you think __ you don't have to think about anything __

material

Basically it's just RaspberryPi and GrovePi + Starter Kit

  1. Raspberry Pi (GrovePi has already been set on Raspbian. At that time, like this There was a problem, but Q & A is fast and safe)
  2. GrovePi+
  3. LCD (Connect to I2C because it can be any number)
  4. Ultrasonic distance sensor (Connected to D2, the eye-catcher of Pixcer's robot character)
  5. Green LED (connected to D5)
  6. Red LED (connected to D6)
  7. Buzzer (Connected to D8, the sound is so loud that you may be surprised, so you may close the hole with a toothpick)

The completed image looks like this

スクリーンショット 2015-06-14 18.54.44.png

I'm sorry ^^; I have an unrelated DHT (digital humidity thermometer, blue guy) in the picture ^^ ;;;; It was easy to send these measurements to M2X in the near future ...

specification

Measure the distance to the parking lot wall with an ultrasonic distance sensor

  1. Display the measured distance on the LCD
  2. When the distance is less than 1m, turn the LCD backlight green and turn on the green LED.
  3. When the distance is less than 30 cm, turn the LCD backlight red, turn on the red LED, and sound the buzzer.

Probably convenient for parking a car. Actually, I've never had a driver's license, so I'm not familiar with it ...

For the backlight, I tried to add the effect of fade-out by referring to the sample program (copy and paste). In the completed code, it is realized by changing the color of the backlight with a for loop.

Introductory video of the finished product

The operation of the finished product is like this

Referenced sample program and completed code

I first looked at the code below, it's just a short code that you can see at a glance

  1. LED on / off
  2. Distance Sensor (https://github.com/DexterInd/GrovePi/blob/master/Software/Python/grove_ultrasonic.py)
  3. Buzzer
  4. LCD This is a bit long, but the point is just to set the color and string is not it

The following code is completed by somehow sticking these together. What I'm doing is as simple as turning a loop, measuring the distance, and changing the display according to the distance, but that's because it's full of magic numbers and there aren't enough comments. I think it's the real reason I made it in 10 minutes ...

Completion code


import sys
sys.path.append("/home/pi/GrovePi/Software/Python/grove_rgb_lcd")

import time
from grovepi import *
from grove_rgb_lcd import *

# Connect the Grove Ultrasonic Ranger to digital port D4
# SIG,NC,VCC,GND
#ultrasonic_ranger = 4
ultrasonic_ranger = 2
led_green = 5
led_red   = 6
buzzer = 8

pinMode(buzzer,"OUTPUT")
pinMode(led_green,"OUTPUT")
pinMode(led_red,"OUTPUT")
time.sleep(1)

while True:
    try:
        # Read distance value from Ultrasonic
        distance = ultrasonicRead(ultrasonic_ranger)
        print distance
        dist = int(distance)
        if dist > 100:
        	# non
            digitalWrite(led_green,0)
            digitalWrite(led_red,0)
            setText("distance = "+str(dist))
            for c in range(0,255):
                setRGB(255-c,255-c,255-c)
                time.sleep(.0039)
        elif dist > 30:
        	# green
            digitalWrite(led_green,1)
            digitalWrite(led_red,0)
            setText("distance = "+str(dist))
            for c in range(0,255):
                setRGB(255-c,255,255-c)
                time.sleep(.0039)
        else:
        	# red, buzzer 1sec
            digitalWrite(led_green,0)
            digitalWrite(led_red,1)
            digitalWrite(buzzer,1)
            setText("distance = "+str(dist))
            for c in range(0,255):
                setRGB(255,255-c,255-c)
                time.sleep(.0039)
            digitalWrite(buzzer,0)



    except TypeError:
        print "Error"
    except IOError:
        print "Error"

Impressions

It's really easy.

  1. Of course no soldering is required
  2. No need to be aware of the sensor connection method (voltage is 5V or 3.3V, protocol is etc.), just connect the wire
  3. The software just calls the Python functions provided by GrovePi

I thought that the simplicity of being able to do something like electronic work with this alone was certainly __ ”a great choice” __ as MagPi said.

The remaining challenges

I feel that the measured value of the distance sensor is a little short. The ultrasonic distance sensor measures the distance by multiplying the speed of sound by the time it takes for the ultrasonic pulse wave to be reflected by the object and return, but the setting value of the speed of sound (a function of temperature and humidity) is a little too fast. It is presumed that (based on a hot and humid place?). Since there is no API to give the temperature and humidity for correction, it seems that correction on the application side is necessary to obtain the accurate distance.

Futur works Using GrovePi + to send dht11 greenhouse sensor readings to m2x in 10 minutes

Recommended Posts

The story of a Parking Sensor in 10 minutes with GrovePi + Starter Kit
The story of making a question box bot with discord.py
The story of participating in AtCoder
The story of the "hole" in the file
The story of writing a program
Process the contents of the file in order with a shell script
A story stuck with the installation of the machine learning library JAX
The story of making a standard driver for db with python.
The story of outputting the planetarium master in pdf format with Pycairo
The story of making a module that skips mail with python
The story of creating a bot that displays active members in a specific channel of slack with python
[Understanding in 3 minutes] The beginning of Linux
The story of an error in PyOCR
The story of blackjack A processing (python)
Try the Grove Pi + Starter Kit Sensor
A story that visualizes the present of Qiita with Qiita API + Elasticsearch + Kibana
The story of making a university 100 yen breakfast LINE bot with Python
The story of having a hard time introducing OpenCV with M1 MAC
Generate a list packed with the number of days in the current month.
Receive a list of the results of parallel processing in Python with starmap
The story of making a sound camera with Touch Designer and ReSpeaker
I made a mistake in fetching the hierarchy with MultiIndex of pandas
The story of doing deep learning with TPU
[Python] Get the files in a folder with Python
Feel free to write a test with nose (in the case of + gevent)
Get the caller of a function in Python
To output a value even in the middle of a cell with Jupyter Notebook
Make a copy of the list in Python
Find the number of days in a month
Build a Django environment with Vagrant in 5 minutes
The story of making a web application that records extensive reading with Django
The story of making a lie news generator
The story of finding the optimal n in N fist
The story of reading HSPICE data in Python
A story packed with absolute values in numpy.ndarray
Output in the form of a python array
The story of viewing media files in Django
The story of making a mel icon generator
The story that fits in with pip installation
How to get a list of files in the same directory with python
Realize a super IoT house by acquiring sensor data in the house with Raspberry Pi
Get the value of a specific key in a list from the dictionary type in the list with Python
How to identify the element with the smallest number of characters in a Python list?
A story about trying to introduce Linter in the middle of a Python (Flask) project
The story of launching a Minecraft server from Discord
A story that reduces the effort of operation / maintenance
The story of stopping the production service with the hostname command
The story of replacing Nvidia GTX 1650 with Linux Mint 20.1.
The story of building the fastest Linux environment in the world
The story of sharing the pyenv environment with multiple users
Take a screenshot of the LCD with Python-LEGO Mindstorms
The story of making a music generation neural network
The story of FileNotFound in Python open () mode ='w'
A story that struggled with the common set HTTP_PROXY = ~
Visualize the characteristic vocabulary of a document with D3.js
A story about changing the master name of BlueZ
Zip 4 Gbyte problem is a story of the past
A story that analyzed the delivery of Nico Nama.
A reminder about the implementation of recommendations in Python
Calculate the product of matrices with a character expression?
The story of sys.path.append ()