Initial settings for using GrovePi + starter kit and camera on Raspberry Pi

Overview

At the hackathon, I decided to utilize the Raspberry Pi and camera, Grove Pi + starter kit, and kintone, and investigated the setup and initial settings of the Raspberry Pi. As a result, although there was a problem with the setting to use OpenCV with Python 3 and the Grove Pi + setting, I was able to set the Raspberry Pi and camera, Grove Pi + starter kit, and Python library to access kintone.

About the equipment to be used (2020/01/03 Surveyed by Amazon)

The latest Raspberry Pi 4 is not included in Grove Pi support, so I'm using Raspberry Pi 3 this time. The Raspberry Pi 4 is expensive in the first place, so you won't need that much specs for this application.

Equipment used in this survey (including some equivalent products)

You can buy them all on Amazon and try them for around 20,408 yen.

Raspberry Pi3 Model B Board & Case Set 3ple Decker Compatible (Clear)-Physical Computing Lab (6,100 yen) https://www.amazon.co.jp/dp/B01CSFZ4JG/ SanDisk microSDHC ULTRA 16GB 80MB / s SDSQUNS-016G Class10 (465 yen) https://www.amazon.co.jp/dp/B074B4P7KD/ __Grove Pi + Starter Kit Raspberry Pi A +, B, B + & 2,3 applicable for beginners CE certification __ (6,100 yen) https://www.amazon.co.jp/dp/B07H9PFWHW/ __US Power Adapter On / Off Switch Cable 5V 2.5A Compatible with Raspberry Pi 3 Lightweight and convenient to carry __ (464 yen) https://www.amazon.co.jp/dp/B07CYNGG4C/ __Camera module Photosensitive chip OV5647 Sensor 5M pixel Raspberry Pi 1 2 3 Model B B A + compatible __ (780 yen) https://www.amazon.co.jp/dp/B07G572B3R/

Raspberry Pi settings

OS setup

I downloaded the latest OS from the following. https://www.raspberrypi.org/downloads/raspbian/

The OS image used is as follows. Raspbian Buster with desktop ・ Version: September 2019 ・ Release date: 2019-09-26 -Kernel version: 4.19

The method of setting up the OS on the SD card is omitted. If you want to know more, please refer to the following.

__Raspberry Pi Initial setting Windows (@ sigma7641) __ https://qiita.com/sigma7641/items/995c7bb07eab408b9d0e __Raspberry Pi Initial setting Mac (@skkojiko) __ https://qiita.com/skkojiko/items/a7e342a8ab53b409fe6a

About command line text editor

Work is done on the command line, connecting with ssh. The command line text editor is explained in nano, but see below for how to use it.

__GNU nano mastery (@snct_hu) __ https://qiita.com/snct_hu/items/971d512c26dd8b3a3b3c

Fixed IP settings

First of all, set a fixed IP to make it easier to connect with ssh.

$ sudo nano /etc/dhcpcd.conf
(Change the IP address to an appropriate content and add the following settings)
interface eth0
static ip_address=192.168.0.111/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1 8.8.8.8

Refer to the following for wireless LAN settings. __ Raspberry Pi wireless LAN settings on the command line (@mym) __ https://qiita.com/mym/items/468d2cdb30d756b6df24

OS basic settings

Basic OS settings are made using raspi-config.

$ sudo raspi-config

This time, the following is set.

1 Change User Password

4 Localisation Options -> I1 Change Locale -> ja_JP.UTF-8 UTF-8 -> I2 Change Timezone -> Asia -> Tokyo -> I3 Change Keyboard Layout-> Appropriate -> I4 Change Wi-fi Country -> JP Japan

5 Interfacing Options -> P1 Camera -> Enable -> P4 SPI -> Enable -> P5 I2C -> Enable

8 Update

After setting, update the OS to the latest state.

$ sudo apt-get update
$ sudo apt-get upgrade

Raspberry Pi camera settings

See below for Raspberry Pi camera settings.

__Raspberry Pi Take photos and videos with your camera __ https://iotdiyclub.net/raspberry-pi-using-camera-1/

After completing the basic settings, configure the settings for Python's OpenCV (image editing library).

$ sudo modprobe bcm2835-v4l2
$ sudo nano /etc/modules

bcm2835-v4l2

$ sudo apt-get install libopencv-dev python-opencv

See below for more information on OpenCV.

OpenCV https://opencv.org/ __ Python version of OpenCV basics __ https://cvtech.cc/py-opencv/ __ Image processing introductory course: Image processing starting with OpenCV and Python __ https://postd.cc/image-processing-101/

When using Python3, make the following settings.

$ sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-103
$ sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5
$ sudo apt-get install libatlas-base-dev
$ sudo apt-get install libjasper-dev
$ pip3 install opencv-python

If you use OpenCV as it is in Python3, an error will occur in import cv2. To avoid this error, add the library to load.

$ nano .bashrc

export LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libatomic.so.1

$ source .bashrc

Grove Pi + settings

Please refer to the following for installing Grove Pi + on Raspberry Pi. GrovePi+ https://www.switch-science.com/catalog/2129/

Refer to the following for setting the Grove Pi + software. Setting Up The Software https://www.dexterindustries.com/GrovePi/get-started-with-the-grovepi/setting-software/

$ curl -kL dexterindustries.com/update_grovepi | bash
$ sudo reboot
$ cd /home/pi/Dexter
$ git clone https://github.com/DexterInd/GrovePi
$ cd /home/pi/Dexter/GrovePi/Script
$ sudo chmod +x install.sh
$ sudo ./install.sh

If there is no problem after installation, you can check the I2C port 04 as shown below with the i2c detect command.

$ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- 04 -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

After setting GrovePi +, apt-get upgrade, which updates the OS and installed software, causes a problem with the package dependency and causes an error. To avoid this error, do the following:

$ sudo apt-get --fix-broken upgrade

To test if it works, wire the included Grove LED to the Grove Pi + D4 port as shown below. http://wiki.seeedstudio.com/Grove-Red_LED/#play-with-raspberry-pi-with-grovepi_plus sensor06.png

After wiring, test the following version display and LED blinking to see if there are any problems.

$ python /home/pi/Dexter/GrovePi/Software/Python/grovepi.py
library supports this fw versions: 1.3.0

$ python /home/pi/Dexter/GrovePi/Software/Python/grove_led_blink.py
This example will blink a Grove LED connected to the GrovePi+ on the port labeled D4.
If you're having trouble seeing the LED blink, be sure to check the LED connection and the port number.
You may also try reversing the direction of the LED on the sensor.

Connect the LED to the port labele D4!
LED ON!
LED OFF!
LED ON!
LED OFF!
LED ON!
LED OFF!

Grove Pi + library bug

As of 02/02/2020, there is a problem with the following Grove Pi + library 1.3.0 files, and many samples do not work. /home/pi/Dexter/GrovePi/Software/Python/grovepi.py https://github.com/DexterInd/GrovePi/blob/master/Software/Python/grovepi.py

For example, grove_button.py is a program that displays button OFF with 0 and button ON with 1, but when executed, the display will be as follows.

$ python /home/pi/Dexter/GrovePi/Software/Python/grove_button.py
255
255
255
255
255
255

There is a problem in the I2C reading part of __grovepi.py and it needs to be fixed. __ The modified part of grovepi.py is explained below.

Line 227 read_identified_i2c_block () Deleted because the while statement loops forever

grovepi.py


def read_identified_i2c_block(read_command_id, no_bytes):
	data = [-1]
	data = read_i2c_block(no_bytes + 1)
	return data

Line 246 Corrected the number array element number of analogRead ()

grovepi.py


# Read analog value from Pin
def analogRead(pin):
	write_i2c_block(aRead_cmd + [pin, unused, unused])
	number = read_identified_i2c_block(aRead_cmd, no_bytes = 2)
	return number[1] * 256 + number[2]

Line 284 UltrasonicRead () number Correct array element number

grovepi.py


# Read value from Grove Ultrasonic
def ultrasonicRead(pin):
	write_i2c_block(uRead_cmd + [pin, unused, unused])
	number = read_identified_i2c_block(uRead_cmd, no_bytes = 2)
	return (number[1] * 256 + number[2])

Line 320 Corrected number array element number and no_bytes variable value of dht ()

grovepi.py


# Read and return temperature and humidity from Grove DHT Pro
def dht(pin, module_type):
	write_i2c_block(dht_temp_cmd + [pin, module_type, unused])
	number = read_identified_i2c_block(dht_temp_cmd, no_bytes = 9)
	
	if p_version==2:
		h=''
		for element in (number[1:5]):
			h+=chr(element)
		
		t_val=struct.unpack('f', h)
		t = round(t_val[0], 2)

		h = ''
		for element in (number[5:9]):
			h+=chr(element)
		
		hum_val=struct.unpack('f',h)
		hum = round(hum_val[0], 2)
	else:
		t_val=bytearray(number[1:5])
		h_val=bytearray(number[5:9])
		t=round(struct.unpack('f',t_val)[0],2)
		hum=round(struct.unpack('f',h_val)[0],2)
	if t > -100.0 and t <150.0 and hum >= 0.0 and hum<=100.0:
		return [t, hum]
	else:
		return [float('nan'),float('nan')]

After the above fix, I did the following and got the expected results.

$ python /home/pi/Dexter/GrovePi/Software/Python/grove_button.py
0
0
1
1
1
0
0

Python library to access kintone settings

$ pip install pykintone
$ pip3 install pykintone

node-red settings (only if necessary)

Set node-red as follows.

$ sudo apt-get install nodered
$ npm install node-red-grovepi-nodes
$ npm install node-red-contrib-kintone
$ sudo systemctl enable nodered.service
$ sudo service nodered start

You can use node-red by accessing http: // Raspberry Pi IP address: 1880 / with a browser. nodered.png See below for details. __Node-RED Run on Raspberry Pi __ https://nodered.jp/docs/getting-started/raspberrypi

Remote Desktop Settings (only if needed)

Set the remote desktop as follows.

$ sudo apt-get install xrdp
$ cd /etc/xrdp/
$ sudo wget http://w.vmeta.jp/temp/km-0411.ini
$ sudo ln -s km-0411.ini km-e0010411.ini
$ sudo ln -s km-0411.ini km-e0200411.ini
$ sudo ln -s km-0411.ini km-e0210411.ini
$ sudo service xrdp restart

You can connect to the remote desktop with the IP address of the Raspberry Pi as follows. RaspberryPi04.png See below for details. __ Connect to raspberry pi3 from a Windows computer with remote desktop (@ t114) __ https://qiita.com/t114/items/bfac508504b9a6b7570d

reference

I got an error when I put opencv in python3 with Raspberry Pi [Countermeasure](@ XM03) https://qiita.com/XM03/items/48463fd910470b226f22

Raspberry Pi Projects for the GrovePi. https://www.dexterindustries.com/GrovePi/projects-for-the-raspberry-pi/ https://www.dexterindustries.com/GrovePi/get-started-with-the-grovepi/setting-software/

Grove - LED https://www.seeedstudio.com/Grove-Green-LED.html http://wiki.seeedstudio.com/Grove-Red_LED/#play-with-raspberry-pi-with-grovepi_plus

Grove --Button https://www.seeedstudio.com/Grove-Button.html http://wiki.seeedstudio.com/Grove-Button/#play-with-raspberry-piwith-grovepi_plus

Run on Node-RED Raspberry Pi https://nodered.jp/docs/getting-started/raspberrypi

Connect to raspberry pi3 from a Windows computer with remote desktop (@ t114) https://qiita.com/t114/items/bfac508504b9a6b7570d

GitHub icoxfog417/pykintone https://github.com/icoxfog417/pykintone

Fixed a bug in __grovepi.py (after line 227) __ There is a correction in the description part of (Y.K Bug fixes)

grovepi.py


(Omitted)

# Read I2C block from the GrovePi
def read_i2c_block(no_bytes = max_recv_size):
	data = data_not_available_cmd
	counter = 0
	while data[0] in [data_not_available_cmd[0], 255] and counter < 3:
		try:
			data = i2c.read_list(reg = None, len = no_bytes)
			time.sleep(0.002 + additional_waiting)
			if counter > 0:
				counter = 0
		except:
			counter += 1
			time.sleep(0.003)
			
	return data

# (Y.K Bug fixes)
def read_identified_i2c_block(read_command_id, no_bytes):
	data = [-1]
	data = read_i2c_block(no_bytes + 1)
	return data

# Arduino Digital Read
def digitalRead(pin):
	write_i2c_block(dRead_cmd + [pin, unused, unused])
	data = read_identified_i2c_block( dRead_cmd, no_bytes = 1)[0]
	return data

# Arduino Digital Write
def digitalWrite(pin, value):
	write_i2c_block(dWrite_cmd + [pin, value, unused])
	read_i2c_block(no_bytes = 1)
	return 1

# Read analog value from Pin (Y.K Bug fixes)
def analogRead(pin):
	write_i2c_block(aRead_cmd + [pin, unused, unused])
	number = read_identified_i2c_block(aRead_cmd, no_bytes = 2)
	return number[1] * 256 + number[2]


# Write PWM
def analogWrite(pin, value):
	write_i2c_block(aWrite_cmd + [pin, value, unused])
	read_i2c_block(no_bytes = 1)
	return 1

# Setting Up Pin mode on Arduino
def pinMode(pin, mode):
	if mode == "OUTPUT":
		write_i2c_block(pMode_cmd + [pin, 1, unused])
	elif mode == "INPUT":
		write_i2c_block(pMode_cmd + [pin, 0, unused])
	read_i2c_block(no_bytes = 1)
	return 1


# Read temp in Celsius from Grove Temperature Sensor
def temp(pin, model = '1.0'):
	# each of the sensor revisions use different thermistors, each with their own B value constant
	if model == '1.2':
		bValue = 4250  # sensor v1.2 uses thermistor ??? (assuming NCP18WF104F03RC until SeeedStudio clarifies)
	elif model == '1.1':
		bValue = 4250  # sensor v1.1 uses thermistor NCP18WF104F03RC
	else:
		bValue = 3975  # sensor v1.0 uses thermistor TTC3A103*39H
	a = analogRead(pin)
	resistance = (float)(1023 - a) * 10000 / a
	t = (float)(1 / (math.log(resistance / 10000) / bValue + 1 / 298.15) - 273.15)
	return t


# Read value from Grove Ultrasonic (Y.K Bug fixes)
def ultrasonicRead(pin):
	write_i2c_block(uRead_cmd + [pin, unused, unused])
	number = read_identified_i2c_block(uRead_cmd, no_bytes = 2)
	return (number[1] * 256 + number[2])


# Read the firmware version
def version():
	write_i2c_block(version_cmd + [unused, unused, unused])
	number = read_identified_i2c_block(version_cmd, no_bytes = 3)
	return "%s.%s.%s" % (number[0], number[1], number[2])


# Read Grove Accelerometer (+/- 1.5g) XYZ value
# Need to investigate why this reports what was read with the previous command
# Doesn't look to be implemented on the GrovePi
def acc_xyz():
	write_i2c_block(acc_xyz_cmd + [unused, unused, unused])
	number = read_identified_i2c_block(acc_xyz_cmd, no_bytes = 3)
	if number[1] > 32:
		number[1] = - (number[1] - 224)
	if number[2] > 32:
		number[2] = - (number[2] - 224)
	if number[3] > 32:
		number[3] = - (number[3] - 224)
	return (number[0], number[1], number[2])


# Read from Grove RTC
# Doesn't look to be implemented on the GrovePi
def rtc_getTime():
	write_i2c_block(rtc_getTime_cmd + [unused, unused, unused])
	number = read_i2c_block()
	return number

# Read and return temperature and humidity from Grove DHT Pro (Y.K Bug fixes)
def dht(pin, module_type):
	write_i2c_block(dht_temp_cmd + [pin, module_type, unused])
	number = read_identified_i2c_block(dht_temp_cmd, no_bytes = 9)
	
	if p_version==2:
		h=''
		for element in (number[1:5]):
			h+=chr(element)
		
		t_val=struct.unpack('f', h)
		t = round(t_val[0], 2)

		h = ''
		for element in (number[5:9]):
			h+=chr(element)
		
		hum_val=struct.unpack('f',h)
		hum = round(hum_val[0], 2)
	else:
		t_val=bytearray(number[1:5])
		h_val=bytearray(number[5:9])
		t=round(struct.unpack('f',t_val)[0],2)
		hum=round(struct.unpack('f',h_val)[0],2)
	if t > -100.0 and t <150.0 and hum >= 0.0 and hum<=100.0:
		return [t, hum]
	else:
		return [float('nan'),float('nan')]

(Omitted)

Recommended Posts

Initial settings for using GrovePi + starter kit and camera on Raspberry Pi
Create a color sensor using a Raspberry Pi and a camera
Raspbian initial settings (Raspberry Pi 4)
Install PyCall on Raspberry PI and try using GPIO's library for Python from Ruby
Access google spreadsheet using python on raspberry pi (for myself)
MQTT on Raspberry Pi and Mac
Raspberry pi initial setting (for myself)
Try using ArUco on Raspberry Pi
Weighing instrument using raspberry pi and hx711 (GUI display on Tkinter)
Detect "brightness" using python on Raspberry Pi 3!
Run servomotor on Raspberry Pi 3 using python
Detect temperature using python on Raspberry Pi 3!
Detect slide switches using python on Raspberry Pi 3!
Try using a QR code on a Raspberry Pi
Detect magnet switches using python on Raspberry Pi 3!
I tried running Flask on Raspberry Pi 3 Model B + using Nginx and uWSGI
Beginning cross-compilation for Raspberry Pi Zero on Ubuntu
Sound the buzzer using python on Raspberry Pi 3!
Record temperature and humidity with systemd on Raspberry Pi
Build an OpenCV4 environment on Raspberry Pi using Poetry
Try using the temperature sensor (LM75B) on the Raspberry Pi.
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Installation of Docker on Raspberry Pi and L Chika
Install pyenv on Raspberry Pi and version control Python
Output to "7-segment LED" using python on Raspberry Pi 3!
Troubleshoot with installing OpenCV on Raspberry Pi and capturing
Raspberry Pi video camera
Cython on Raspberry Pi
Input and output display images directly using the frame buffer (/ dev / fb0) on Raspberry Pi
Create your own IoT platform using raspberry pi and ESP32 (Part 3) ~ ESP32 settings Analog temperature sensor
I tried using the Pi Console I / F of the Raspberry Pi IoT starter kit "anyPi" from Mechatrax.
Run AWS IoT Device SDK for Python on Raspberry Pi
Create a web surveillance camera with Raspberry Pi and OpenCV
Detect "temperature (using A / D converter)" using python on Raspberry Pi 3!
Construction of Cortex-M development environment for TOPPERS using Raspberry Pi
Get the weather using the API and let the Raspberry Pi speak!
Indoor monitoring using Raspberry Pi
Anaconda 4.4.0 Initial Settings for Windows
Introduced pyenv on Raspberry Pi
Use NeoPixel on Raspberry Pi
Install OpenCV4 on Raspberry Pi 3
Install TensorFlow 1.15.0 on Raspberry Pi
Control the motor with a motor driver using python on Raspberry Pi 3!
Make a simple CO2 incubator using Raspberry PI and CO2 sensor (MH-Z14A)
Cross-compile for Raspberry Pi Zero on Debian-Create your own shared library
Create your own IoT platform using raspberry pi and ESP32 (Part 1)
Phone notification when surveillance camera motion is detected on Raspberry Pi