AzuritBer Pi Firmware (English)

Aus www.wiki.ardumower.de
Version vom 18. Mai 2023, 11:09 Uhr von Bernard (Diskussion | Beiträge) (Raspberry Pi)

(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

Raspberry Pi

A Raspberry Pi is connected over : Due Native USB to arduino DUE or on USB port to AGCM4/Teensy

It is used to control Mower over WIFI from everywhere using PC,Tablet,Smartphone etc.....

All movement and message are saved on SDcard for each mowing run and you can check later exactly what append (Bump,Sonar,Perimeter trig etc....)

Setup

What you need

1 Raspberry PI 3B+ or PI4 (The Pizero W can work but very slowly and it's not the goal).Pi3 board.jpg

1 DC/DC voltage regulator to power the PI.Minumum 5A version from marotronicsDC DC 5A.jpg https://www.marotronics.de/5A-DC-DC-step-down-module-XL4015-with-heat-sink-eg-for-Arduino

Connect P17 to input of the DC/DC voltage regulator and connect a micro usb cable to output Warning.png(ADJUST the output voltage to 5V before plug the PI)

1 USB mouse,keyboard for setting.You can simply use a standard one for the setting and disconnect it after But it's also possible to use a small one like that to drive the mower remotely in manual mode.Small keyboard1.jpg

1 SD Card 32 GB class 10Sd card.jpg

1 PowerBank or DC/DC voltage regulator connected to PCB1.3 or power supply for the raspberry pi minimum 3A

1 HDMI cable to see the PI desktop on your TV or HDMI Screen.

1 TV or monitor with HDMI input to easily see the raspberry IP adress on the first boot.

Fast setup for Advanced user

If you already know how raspberry PI work with desktop ,You can read setup process locate into github under Txt File Setup_raspberry.rtf

Here the full setup process:

VNC is installed and you have copied all Piardumower data into Documents folder.

sudo apt-get install idle3
sudo pip3 install paho-mqtt
sudo apt-get install kst
sudo apt-get install dos2unix

Download and Install Arduino IDE and add Due board if you want to flash Due over WIFI

cd ~/Documents
sudo chown -R pi:pi PiArdumower
sudo chmod -R 755 PiArdumower
cd PiArdumower
mv mower.sh /home/pi/Desktop
cd ~/Documents/PiArdumower
dos2unix streamVideo320.py
dos2unix streamVideo640.py
dos2unix DueFlash.py
dos2unix PowerOff.py
dos2unix Restart.py
dos2unix testnet1.py
cd ~/Desktop
dos2unix mower.sh



If you never work with Raspberry simply follow the full WIKI and check all screen copy.

Build the SD Card

You need to first write the raspbian OS on the SD Card .

It's easy using the main raspberry.org site.

You can connect you Micro SD CARD to your laptop or PC using correct adaptor

No need to format at the point but All Data present on it will be destroyed.

Connect to : https://www.raspberrypi.org/


Buster001.png and select the Download page


Buster002.png Select Raspberry Pi Imager for Windows


Wait until the download is finish and launch the downloaded prog.


Buster003.png Select Choose OS


Buster004.png Use the recommended one with Desktop


Buster005.png Select Choose SD CARD


Buster006.png Select your SD CARD Be careful to select the correct one.


Buster007.png Select Write and wait until down (can take 15 to 60 Min according your internet speed).


Remove the SD CARD for your PC.


PI Initial boot with Desktop

Connect everything on the PI ; Here the Ethernet cable is used but it's also possible to use WIFI

USB Dongle for mouse.

HDMI cable from PI to TV or monitor. (Without TV or monitor is also possible : Search on Google and Youtube)

Ethernet cable if possible or WIFI (On first boot the PI need a good connection to the net for last update)

Power (5V if you use DC/DC voltage regulator) on Micro USB

Connecting.png



On first start you can see expand sd card,reboot and welcome message with the IP Address for Ethernet

First start 1.png


Select your language and location.

First start 02.png


Change password and remember it (we need it later to connect to PI over wifi) For easy wiki : Pass001 but use another one

First start 2.png


Setup screen, simply click next

First start 3.png


On the WIFI connecting page select the WIFI network that you want to use for all the setting duration (You can change it later for an outdoor one)

First start 4.png


Enter your wifi password and follow the next update step (can take again 10 to 30 minutes)

First start 5.png



REBOOT.

We need to activate VNC serveur to whare the desktop with your PC.

Using Start icon : Go to Préférence and Configuration du Raspberry

First start 10.png


In the Tab Interfaces Activate SSH and VNC

First start 11.png


Now on the upper right corner of the desktop a new icon show that VNC Serveur is running .

Move your mouse on the Ethernet or Wifi icon to see the IP adress of the ethernet and WIFI one.

The WIFI one is the most important (Here 10.0.0.29)

First start 12.png

Disconnect the ethernet cable and Reboot (Not Shutdown) All Using Start icon and Log Out.


First start 1201.png

First Remote PC connection over Wifi

PI SIDE

Pi is running and you can see the desktop

PC SIDE or Tablet / Phone

Remember that we set the Password to Pass001 and ip adress of the PI WIFI is 10.0.0.29
NOW WE WORK ON PC OR TABLET

You have many possiblity (SSH viewer, MobaXterm, Remote Desktop etc...) , In this case I use free real VNC Viewer (Not VNC Serveur) to connect to the PI over your network.

Go to https://www.realvnc.com/fr/connect/download/viewer/

And select the correct donwload according your platform.

First start 20.png



Instal the software and start it (VNC Viewer). In your case the tab is empty (No RL1000,Denna etc....)

First start 21.png


On upper left choose File / New Connection

First start 22.png


Into VNC Serveur : enter the IP of the raspberry (ethernet or WIFI adress) and give a name to the connection.

First start 23.png


It's possible that a new security box is shown on the screen Select Continue

First start 24.png



You can see the new Connection named Ardumower Double click on it.

UserName is pi and password is Pass001 or the one you choose on first start part.Check remember password

First start 25.png


The Clone of the Pi desktop is now on your PC and you can do everything exactly like if you use localy the raspberry ,But from your Sofa

First start 26.png


Pi Software part

NOW WE WORK ON THE PI USING VNC VIEWER ALL COMMAND NEED TO RESPECT THE CASE
DO NOT DISCONNECT THE SCREEN TO HAVE A CORRECT RESOLUTION (1024*768)

You need to send some command to the PI Terminal to install some software.

To see the terminal click on the >_ icon in the taskbar

Pi soft 10.png


Copy and past all the following command in the terminal after the $ for the rest of this wiki part

sudo apt-get update 

Pi soft 20.png


sudo apt-get upgrade

This download can take a lot of time , so be patient and answer Yes to upgrade

Pi soft 30.png

Python3 Idle

Piardu.py use Python3 , so we need to install the idle to have access to it and edit if needed (answer Yes for installing)

sudo apt-get install idle3

Pi soft 40.png


At the end of the Python idle installation you need to have a new icon into Start / Programing menu.

Pi soft 50.png

Pygame

It's possible to drive the mower in Manual mode with PS4 joystick but need pygame software (Maybe already include but it's better to do it)

sudo apt-get install python3-pygame

Pi soft 60.png


Paho Mqtt

It's possible to controle mower over mqtt and use Home Automation but need python3 paho software part.

sudo pip3 install paho-mqtt

Pi soft 70.png

Here a fast description of TOPIC

What you can send to mower

Topic Denna/COMMAND

payload : STOP to stop
payload : MOWPATTERN ;1 or 2 or3 according mowpattern
payload : START to start with the last mowpattern
payload : PAUSE;2 to stop auto start by timer for the next 2 hours
payload : HOME to go station
payload : STARTTIMER;1;1;0;25;2;50 it's to start from station 
          STARTTIMER;MowPattern;LaneNr;rollDir;WhereStart;areToGo;LaneLenght


What you receive from mower

Send only when value change

Topic Denna/STATUS
payload the mower status see robot.py list for possible value
Topic Denna/STATE
payload the mower state see robot.py list for possible value
Topic Denna/Battery
payload the bat voltage
Topic Denna/Temp
payload the mower temp
Topic Denna/Battery
payload the bat voltage


Send at fixed frequency see config.py (one per second for example)

Topic Denna/Idle
payload the loop per second of due

KST Plot

Piardu use software named KST to plot all the data

Seach KST Plot on Google for more info . Again copy and past this into the Pi terminal:

sudo apt-get install kst

Pi soft 80.png

DosToUnix

Some file need to be in unix format ,so a conversion is needed using DosToUnix

sudo apt-get install dos2unix

Pi soft 65.png

Arduino IDE

It's possible to update the due firmware from Piardu over WIFI but need the ARDUINO IDE in the raspberry.

The process is describe perfectly in this video

https://www.youtube.com/watch?v=ySyBNdndB58

You need to download file directly inside the raspberry.

So use the PI Internet browser named CHROMIUM.It's the world Icon on windows top left

Here screenshot of the 07/11/2020 download page for Arduino 1.8.13 version : Choose Linux ARM 32 bits

Pi soft 100.png Pi soft 101.png Pi soft 102.png



Go to file manager home / pi / Downloads and right click to the downloaded file ,select extract here (WAIT before you see something appear)

Pi soft 110.png


Now open again the terminal windows (>_ icon on upper left) and copy these command (it can take time)

Warning : folder arduino-1.8-13 can change over time for example arduino-1.8-15 , so use the correct name according your download in the next command.

cd Downloads/arduino-1.8.13
sudo ./install.sh

Pi soft 115.png

Do not take care about the error message.

You can see now the arduino icon into start / programming, start the prog to be sure everything is OK.

Pi soft 120.png


Add the ARDUINO DUE in the board list

Pi soft 125.png

Search for DUE : and select arduino SAM Boards

Pi soft 130.png

Again it can take time,so Wait until process finish.


Normaly arduino ide is not use and only a command line is used to update Due firmware but to be sure the folder name stay always the same  : Go to file Preferences and deactivate the Search for update.

Pi soft 135.png

PiArdu Software

You need to copy all the Github file locate into Piardumower folder inside the Raspberry PI home/pi/Documents folder.

Using VNC Viewer :

First initiate the correct location for file transfert

Click VNC Serveur icon on desktop upper right near Bluetooth icon

Click Menu icon on VNC CONNECT upper right page

Select File Transfert in the menu list

In bottom right of the next page select other folder and choose home/pi/Documents.

Pi soft 205.png


Now download all the file: Move your mouse in upper middle of the desktop to see the VNC transfert icon and select it Click on send file

Pi soft 200.png Pi soft 208.png



Navigate into your PC to find the github master downloaded file and select piardumower and validate using the FULL FOLDER in bottom right

Pi soft 210.png


If everything is OK you can see now the entire folder correctly locate in home/pi/Documents

Pi soft 215.png


Set permission to everyone for all the piardumower file

Open a terminal (>_ icon ondesktop) and send the 5 command

cd Documents
sudo chown -R pi:pi PiArdumower
sudo chmod -R 755 PiArdumower

Pi soft 220.png



Add start Piardu.py to desktop using a shell command:

cd PiArdumower
mv mower.sh /home/pi/Desktop

Pi soft 221.png

A new file is now present on desktop Mower.sh and can be use to start the Piardu.py


Change into config.py for the first start of Piardu (Deactivate momentary the DUE serial link to avoid error)

Start / Programming / Python3 IDLE

Pi soft 230.png



And into Python Shell select File Open home/pi/Documents/Piardumower/config.py

Pi soft 235.png



Now change DueconnectedOnPi from True to False

Pi soft 240.png

Save and close the config.py file but keep the shell open


Now from Python Shell select File Open home/pi/Documents/Piardumower/PiArdu.py and click on Run / Run Module or hit F5

Piardu need to start without error into Shell windows (No red Line)

Pi soft 250.png

And you can navigate inside all the menu with a fast response.



To work correctly some file need to be converted into Unix format:

Open the terminal and copy these command

cd Documents/PiArdumower
dos2unix streamVideo320.py
dos2unix streamVideo640.py
dos2unix DueFlash.py
dos2unix PowerOff.py
dos2unix Restart.py
dos2unix testnet1.py
cd ~/Desktop
dos2unix mower.sh

Pi soft 75.png


Automatic start on Power up:

In terminal use text editor named nano to start mower.sh each time the Pi is power up

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

and at the end of the file add the line below ,Be careful mouse don't work inside the editor,so paste the line at the correct location , error in this file can corrupt the PI starting process

@bash /home/pi/Desktop/mower.sh

Pi soft 237.png

Use Ctrl X to exit and save the change in autostart.

Reboot the PI ,Normally Piardu automatically start with some error if DUE is not plug in PCB1.3 or without error if PCB1.3 is used.

If you can't see the bottom red line with date time : check if you have activate raspberryPi to YES using Arduremote / Setting /raspberry

Go to Piardu auto page and click on OFF to reset all eventual error.

DUE Connection

If you can't remove Arduino DUE from PCB1.3 : you need to power the raspberry with the DC/DC voltage regulator under the same battery, or with standard PI power supply.

With DC/DC regulator Warning.pngFIRST ADJUST THE DC/DC TO 5V OUTPUT or you are going to destroy the raspberry

From PCB1.3 24V P17 -->IN DC/DC OUT--> 5V micro USB Raspberry PI


You can also connect Arduino Due without the PCB1.3 to PI using USB Cable Never use a charging cable only DATA cable (DUE is powered by the raspberry ,so it's very easy)

Pi soft 300.png


Change again into config.py to activate the DUE serial link.

Start / Programming / Python3 IDLE

Pi soft 230.png



And into Python Shell select File Open home/pi/Documents/Piardumower/config.py

Pi soft 235.png



Change DueconnectonPi from False to True

Also set UseDebugConsole to True


Pi soft 241.png

Save and close the config.py file but keep the shell open


Now from Python Shell select File Open home/pi/Documents/Piardumower/PiArdu.py and click on Run / Run Module or hit F5

Piardu need to start and you can navigate inside all the menu very slowly if there are no firmware in the arduino DUE so wait

Pi soft 250.png

FLASH DUE

You can upload the DUE firmware using your PC or directly from Piardu .

Warning.pngIf Raspberry is powered using PCB1.3 JUMPER JP8 NEED TO BE IN ALWAYS ON POSITION if you forget to change JP8 position. During the DUE flash, PCB can power off raspberry . In this case you need to upload again the sketch from your PC using DUE programming port

On PiArdu click Back icon and Setting icon

Pi soft 305.png

On setting main tab use Update the DUE Firmware button and click on Start Flash. Never use "(" or ")" in the mane of file or the flash crash.

Pi soft 310.png

Wait until DUE FLASHER window is closed

You can use your own file . Arduino IDE generate one file each time you compile your project (see the last line in debug view of arduino compiler. Simply copy the file in the raspberry into firmware folder be careful to avoid "("


CHECK COMMUNICATION

Firmware locate on GITHUB is build to work with or without raspberry.


If you test without PCB1.3 and don't have access to ARDUREMOTE you need to manualy set RaspberrypiUse to true. See into mower.cpp line 242:

RaspberryPIUse = false; // a raspberryPi is connected to USBNative port

change with:

RaspberryPIUse = true; // a raspberryPi is connected to USBNative port

Compile and upload again code into DUE.


If you have access to ARDUREMOTE simply go into arduremote / Setting / Raspberry to activate the communication.

When everything is OK, the RED Status line is present in AUTO page of Piardu and change every second.


Try to click Back icon and Setting icon and click on Reboot All

Raspberry and DUE need to reboot if communication,permission and unix format are OK


Optional Screen

For really easy working it's better to use a tactile screen ,directly connected on the Raspberry.

Piardu is write to use a 800*480 5 inch screen using HDMI connection.Avoid SPI screen because the processor can't manage everything faster.

Pi screen 2.png Pi screen 1.png Pi4 screen 1.png

Be carreful when you order : HDMI adaptor is not the same for PI4 (Right Picture) and PI3B+ (center and left Picture)


To setup the tactile and screen :

Go to terminal :copy and paste these command

git clone https://github.com/waveshare/LCD-show.git
cd LCD-show/
sudo ./LCD5-show

Pi screen 3.png

Wait and after reboot ,Resolution is automaticaly reset to screen one and tactile is working to control PiArdu.



To have PiArdu on total full Screen Right Click in the TaskBar near VNC SERVEUR to open a menu list and select 'Parameter tab de bord' (See picture from translation)

Pi screen 4.png

On the new windows select tab Advance and check Minimise (Again See picture from translation)

Pi screen 5.png


Optional Camera

Pi camera 1.png



Simply connect the camera to PI CSI port

Pi camera 3.png



Using Start icon : Go to Préférence and Configuration du Raspberry

In the new windows go into tab Interfaces

Check to Enable the Camera

Pi camera 2.png

Move windows or Hit Tabulation 10 times if you can't see Validate Button and press Enter (Reboot)

Expérimental AI Vision with Tensorflow

https://www.youtube.com/watch?v=e6udelf2v50


EVERYTHING IS HERE EXPERIMENTAL AND CAN'T REPLACE BUMPER OR SONAR.

Main part of detection code came from here and other site on web:

https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10

Only OK with Raspberry 4 at 2 frames per second without google coral accelerator,Note than a Fan is mandatory on the Pi because CPU can heat a lot.

Fast main setup description.

If they are not present copy folder from Github to PiArdumower folder using VNC Viewer:

core
data
protos
ssdlite_mobilenet_v2_coco_2018_05_09
utils
vision

Now in a new terminal :

sudo apt-get update
sudo apt-get upgrade

Install OPENCV

sudo apt install python3-opencv

Install Tensorflow

pip3 install tensorflow
sudo apt-get install libatlas-base-dev
sudo pip3 install pillow lxml jupyter matplotlib cython
sudo apt-get install python3-pil python3-pil.imagetk


Using python idle edit config.py and set Use Vision to true

visionDetectMinScore is used to create a first sort on what we want to explore in the screen.Each time something with score > 78 for example is detected a copy of Live Video is saved on SD Card and soft check if the object detected match with the setting and if we need to stop and reverse or continue to mow.

Piardu video 05.png


Using python idle open and start PiArdu519.py or later

Into setting you can see the tab Vision open it to set the threshold of what you want to avoid.

For each object you can set a minimum detection score and a minimum area (How many percent of the full image)

According the tensorflow model you need to set the correct object ID (name is according but you can change it) Here the .txt file list:

For example on COCO model the chair have ID 62 and we want to stop and reverse if detection score is > 75 and area > 12 % of the screen.

Piardu video 08.png


In Video menu, click on Start Vision and wait at least 40 seconds for tensorflow to load the model.

Piardu video 12.png


A new windows named 'Live Video' appear.

Piardu video 13.png


Now you can reduce Live Video windows and start to mow until something is detected

The big red box is replace with the last detection and a file is create into vision folder

Piardu video 15.png Piardu video 30.png


In Console you can see the result of detection.

Piardu video 40.png

Each time person or Dog etc.. is detected mower stop and reverse , a picture is take and store in the vision / date time folder

AGAIN IT'S EXPERIMENTAL AND ONLY FOR FUN so check in the python shell that no error occur and test to see if the detection is reliable !!


Backup SD CARD

After this very long setup it's time to create a backup of your SD Card into your PC.

Power OFF your raspberry using the correct command and move the SD CARD from the raspberry to your PC. Close windows message for format suggestion.

Using Win32DiskImager a free software you can create image file of your SD Card and save it into your PC.So it's easy to rebuild your card later if you damage it or if you want to build other one using the read and write button.

Image file size is the same as your SD CARD ,so need space on your PC

It's here https://win32diskimager.org/

Diskimager001.png

Download the soft and start it.Your SDCARD is normaly detected and you only need to select a backup folder and give a name to the file ,add .img at the end of your backup file

TO BACKUP

Click on read button to copy your sdcard to your PC.

Diskimager020.png


TO RESTORE

Insert a new SDCARD with minimum same size ,select your backup file and click on write button to create the new SDCARD

Diskimager030.png

Piardu Main Configuration

Inside folder : home/pi/Documents/Piardumower you can edit the config.py file to manage different option :


Piardu config 1.png Piardu config 2.png

PCB part:

Due ConnectedOnPi True for normal use , False to test Raspberry without PCB1.3 and DUE

GPS part:

Warning : GPS is not use by software,it's only a tracker version, All data are recorded and saved inside Piardumower/Gpsdata

GpsConnectedOnPi True or False : Old config with GPS directly connected on Raspberry Pi Serial GPIO.

GpsIsM6n True or False : Set to false is you use M8N module because NMEA sentence are not the same

Arduino Nano part.

NanoConnectedOnPi

It's possible to connect Arduino Nano on Pi USB to receive data and react according, It was build to test some laser beam VL53L0X sensor and rain sensor but without success

Battery part:

AutoRecordBatCharging

When charging start it's possible to record each minute voltage and battery sense to check later how everything work and adjust the max charging duration if necessary.

Debug part:

UseDebugConsole

If True ,you can see more message in the console page including all NMEA sentence received and send by Raspberry.

Sender part:

Sender1AdressIP Sender2AdressIP Sender3AdressIP

If you use the RFID option with multiple area it's the IP adress that Piardu use to communicate with other sender over WIFI.

Camera part:

myCamAngle

If camera in mount in particular orientation it's possible to adjust screen render here.

streamVideoOnPower

if set to True the video stream automatically start when pi is power up

Piardu Power ON / OFF video

Result after everything correctly set :


Power ON

https://youtu.be/Qhv8r2bD_Bk

Power OFF

https://youtu.be/4YJQ-zyLq-Q

Piardu MENU Description

Full description is here:

https://wiki.ardumower.de/index.php?title=AzuritBer_Pi_Explain_(English)