owned this note
owned this note
Published
Linked with GitHub
# Installation Guide for Smart Weighing Scale
## CONFIGURE PROJECT DEPENDENCIES ON THE RASPBERRY PI
By: Team 07
Based on [pyimagesearch](https://www.pyimagesearch.com/2019/04/08/openvino-opencv-and-movidius-ncs-on-the-raspberry-pi/)
## 10 STEPS TO INSTALL & CONFIGURE OPENVINO ON RASPBERRY PI
### Step 1: Install Raspberry Pi
<div style="text-align: justify">
Download Raspberry Pi (OS with desktop and recommended software)
<a href="https://ibb.co/Lx4wTV6"><img src="https://i.ibb.co/tqyf0Vc/1.png" alt="1" border="0"></a>
From there, use [balenaEtcher](https://www.balena.io/etcher/) (or a suitable alternative) to flash the card.
Once you’re ready, insert the microSD card into your Raspberry Pi and boot it up.
Enter your WIFI credentials and enable SSH, VNC, and the camera interface.
From here you will need one of the following:
- Physical access to your Raspberry Pi so that you can open up a terminal and execute commands
- Remote access via SSH or VNC
</div>
<br>
### Step 2: Expand filesystem on your Raspberry Pi
<div style="text-align: justify">
To check your disk space usage, execute the following command in your terminal:
- df-h
If there is enough available disk space, proceed to open the raspberry pi configuration in your terminal
Enter the command in the terminal:
- sudo raspi-config
Select the "**Advanced Options**" menu item
Followed by selecting "**Expand filesystem**" and hit Enter on your keyboard, arrow down to the "**<Finish>**" button
Reboot your Pi
Run the following command again to check that your file system is expanded:
- df -h
</div>
<br>
### Step 3: Reclaim space on your Raspberry Pi
<div style="text-align: justify">
To get more space on your Raspberry Pi, delete both <b>LibreOffice</b> and <b>Wolfram engine</b> to free up some space.
The command line to uninstall the application are as followed:
- sudo apt-get purge wolfram-engine
- sudo apt-get purge libreoffice*
- sudo apt-get clean
- sudo apt-get autoremove
After removing the **Wolfram Negine** and **LibreOffice**, you can reclaim almost 1GB.
</div>
<br>
### Step 4: Install OpenVino + OpenCV dependencies on your Pi
<div style="text-align: justify">
Enter the command in the terminal to update the raspberry pi’s system:
- sudo apt-get update && sudo apt-get upgrade
Then install the developer tools including CMake with the command:
- sudo apt-get install build-essential cmake unzip pkg-config
Next, install a selection of image and video libraries with the following command:
- sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
- sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
- sudo apt-get install libxvidcore-dev libx264-dev
Next install GTK for GUI backend:
- sudo apt-get install libgtk-3-dev
Install a package which may help to reduce GTK warnings:
- sudo apt-get install libcanberra-gtk*
<b>Asterisk ensures we will grab the ARM-specific GTK</b>
Now we need two packages which contain numerical optimizations for OpenCV
</div>
<br>
### Step 5: Download and unpack OpenVINO in your Raspberry Pi
<div style="text-align: justify">
Navigate to home folder and create a new directory with the command:
- cd~
Grab the OpenVINO Toolkit via wget with the following commands:
- wget https://download.01.org/opencv/2020/openvinotoolkit/2020.1/l_openvino_toolkit_runtime_raspbian_p_
Grab the OpenVINO Toolkit via wget with the following commands:
- tar -xf l_openvino_toolkit_runtime_raspbian_p_2020.1.023.tgz
- mv l_openvino_toolkit_runtime_raspbian_p_2020.1.023 openvino
</div>
<br>
### Step 6: Configure OpenVINO on your Raspberry Pi
<div style="text-align: justify">
Add a line to load OpenVino’s setupvars.sh each time you invoke a Pi terminal
- nano ~/.bashrc
Scroll to the bottom of the file and add the following lines:
- source ~/openvino/bin/setupvars.sh
Save and exit from the nano text editor
Then go ahead and source your ~/.bashrc file:
- source ~/.bashrc
</div>
<br>
### Step 7: Configure USB rules for your Movidius NCS and OpenVINO on Raspberry Pi
<div style="text-align: justify">
Enter the following command to add the current user to the Raspbian “users”
- sudo usermod -a -G users “$(whoami)”
Log out and log back in. If on SSH, type exit and then re-establish your SSH connection.
Rebooting is also an option:
- sudo reboot now
Once you’re back at the terminal, run the following script to set the USB rules:
- cd ~
- sh openvino/install_dependencies/install_NCS_udev_rules.sh
</div>
<br>
### Step 8: Create an OpenVINO virtual environment on Raspberry Pi
<div style="text-align: justify">
Install pip, a Python Package Manager.
To install pip, simply enter
- wget https://bootstrap.pypa.io/get-pip.py
- sudo python3 get-pip.py
To install virtualenv and virtualenvwrapper
- sudo pip install virtualenv virtualenvwrapper
- sudo rm -rf ~/get-pip.py ~/.cache/pip
Update ~/.bashrc
- nano ~/.bashrc
- export WORKON_HOME=$HOME/.virtualenvs
- export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 nano
- source /usr/local/bin/virtualenvwrapper.sh
- VIRTUALENVWRAPPER_ENV_BIN_DIR=bin
<a href="https://ibb.co/qDW9hBg"><img src="https://i.ibb.co/BfrjvL6/2.png" alt="2" border="0"></a>
Alternatively, you can append the lines directly via bash commands:
- echo -e "\n# virtualenv and virtualenvwrapper" >> ~/.bashrc
- echo "export WORKON_HOME=$HOME/.virtualenvs" >> ~/.bashrc
- echo "export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3" >> ~/.bashrc
- echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
- echo "VIRTUALENVWRAPPER_ENV_BIN_DIR=bin" >> ~/.bashrc
Source the ~/.basrc profile
- source ~/.bashrc
Create a virtual environment to hold OpenVINO, OpenCV and related packages:
- mkvirtualenv openvino -p python3
</div>
<br>
### Step 9: Install Packages into your OpenVINO environment
<div style="text-align: justify">
We would need to install a handful of packages required.
They are only available in the openvino environment
- workon openvino
- pip install numpy
- pip install "picamera[array]"
- pip install imutils
</div>
<br>
### Step 10: Test your OpenVINO install on your Raspberry Pi
<div style="text-align: justify">
The first command activates our OpenVINO virtual environment.
- workon openvino
The second command sets up the Movidus NCS with OpenVINO and is very important.
- source ~/openvino/bin/setupvars.sh
From there we will fire up the Python 3 binary in the environment and import OpenCV.
- python
- import cv2
- cv2.__version__
- '4.2.0-openvino'
- exit()
</div>
<br>
## 1 STEP TO CONFIGURE MQTT
### Step 1: Pip install dependencies for MQTT
<div style="text-align: justify">
We will create the necessary dependencies for MQTT
- pip3 install tb-mqtt-client
</div>
<br>
## 3 STEPS TO START SCRIPT FOR FRUIT/VEGETABLE RECOGNITION
### Step 1: Navigate to the directory that contains classify_ncs_realtime.py
<div style="text-align: justify">
The folder that has the classify_ncs_realtime.py file
- cd Desktop/fruit-ml
</div>
<br>
### Step 2: Setting OpenVINO-OpenCV path by executing the following command
<div style="text-align: justify">
Run the openvino setup for the movidus NCS stick
- source ~/openvino/bin/setupvars.sh
</div>
<br>
### Step 3: Run the script classify_ncs_realtime.py
<div style="text-align: justify">
Run the file and pass in the config filepath
- python classify_ncs_realtime.py --conf config/config.json
</div>
<br>
## 3 STEPS TO CONNECTING RASPBERRY PI TO WEIGHING SCALE
### Step 1: Connect RS232 to Digital Weighing Scale
<div style="text-align: justify">
- Connect the RS232 end to the digital weighing scale as shown below:
<a href="https://imgbb.com/"><img src="https://i.ibb.co/NTqskBF/4.png" alt="4" border="0"></a>
</div>
<br>
### Step 2: Connect USB to Digital Weighing Scale
<div style="text-align: justify">
- Connect the USB end to the Raspberry PI as shown below:
<a href="https://imgbb.com/"><img src="https://i.ibb.co/wRdVRKn/5.png" alt="5" border="0"></a>
</div>
<br>
### Step 3: Start up Digital Weighing Scale
<div style="text-align: justify">
- Power up the Weighing Scale as shown below:
<a href="https://imgbb.com/"><img src="https://i.ibb.co/NCkCvMg/6.png" alt="6" border="0"></a>
</div>
<br>
## 2 STEPS TO CONFIGURE RS232 TO USB PORT NUMBER
### Step 1: Locating file for port number
<div style="text-align: justify">
To identify your port number, open file explorer and navigate to the following:
- File Explorer -> /dev
Scroll down to locate the file for port number
- ttyUSB? (? = 0, 1, 2, 3 [depending on which port you inserted the cable]
- e.g. ttyUSB0, ttyUSB1, ttyUSB2, ttyUSB3
</div>
<br>
### Step 2: Edit and configure port number
<div style="text-align: justify">
Open the file weigh_tb.py
At line no. 8, locate the following:
- ser = serial.Serial(‘/dev/ttyUSB0’)
Change the line of code according to the port number identified at Step 1
</div>
<br>
## 2 STEPS TO CONFIGURE AND START WEIGHING SCALE SCRIPT
### Step 1: Install Dependencies for Digital Weighing Scale
<div style="text-align: justify">
We will create the necessary dependencies for the weighing scale. Open the terminal window, enter the following command:
- pip3 install pyserial
</div>
<br>
### Step 2: Start the python script for Weighing Scale
<div style="text-align: justify">
Using the same terminal window, enter the following command:
- python3 weigh_tb.py
</div>
<br>
## 3 STEPS TO CONFIGURE THE RC522 RFID MODULE
<div style="text-align: justify">
### Step 1: Connect the RC522 RFID Module to the Raspberry Pi
Follow the schematic diagram to connect the RFID Module:
<a href="https://ibb.co/HDBTvRq"><img src="https://i.ibb.co/gMmZ1QJ/3.png" alt="3" border="0"></a>
### Step 2: Enable SPI (Serial Peripheral Interface)
Serial Peripheral Interface is required for the RC522 RFID Module. Run the following command in the terminal:
- sudo raspi-config
- Navigate to <b>"5 Interfacing Options"</b> using the arrow keys and press Enter.
- Select <b>Yes</b> when prompted whether to enable the SPI Interface.
- Navigate to <b>"P4 SPI"</b> using the arrow keys and press Enter.
- When prompted, <b>reboot the Raspberry Pi</b>.
### Step 3: Pip install dependencies for RFID MODULE
We will create the necessary dependencies for the RFID Module. Run the following command in the terminal:
- sudo apt-get install python3-dev python3-pip
- sudo pip3 install spidev
- sudo pip3 install mfrc52
</div>
## 1 STEPS TO START RFID SCRIPT
### Step 1: Navigate to the directory that contains the rfid_reader_realtime.py
<div style="text-align: justify">
- python3 rfid_reader_realtime.py
</div>