Raspberry Pi: Difference between revisions

From wikiluntti
 
(67 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Setting Up The Raspian ==
== Some of my Raspberries ==


Establish Wifi, Bluetooth.
* Raspeberry 1 (or perhaps 1B) with a camera module on a wood stick. 26 pins. UART.


Credentials are <code>pi@raspberrypi.local</code> and <code>raspberry</code>. [https://sw.kovidgoyal.net/kitty/ KiTTY] seems to be a good terminal.
== Simple things used in every Project ==


=== Set Up WiFi without Screen ===
=== Raspistill ===


Into root directory:
<syntaxhighlight lang="python">
* Add an empty file called <code>ssh</code>
raspistill -w 2592 -h 1944 -o name.jpg
* Add a file <code>wpa_supplicant.conf</code> which includes
<syntaxhighlight>
country=ee
update_config=1
ctrl_interface=/var/run/wpa_supplicant GROUP=netdev
network={
    scan_ssid=1
    ssid="YOUR_NETWORK_NAME"
    psk="YOUR_PASSWORD"
    key_mgmt=WPA-PSK
}
</syntaxhighlight>
</syntaxhighlight>
Note the (Notepad++: Edit) EOL conversion UNIX.
https://www.raspberrypi-spy.co.uk/2017/04/manually-setting-up-pi-wifi-using-wpa_supplicant-conf/




Take a photo and send it to an external server {{GithubDownload|torvalds|linux}}


=== USB cable // Perhaps requires Zero ===
<script src="https://emgithub.com/embed.js?target=https%3A%2F%2Fgithub.com%2Fpytorch%2Fpytorch%2Fblob%2Fmaster%2Ftorch%2Fnn%2Fcpp.py&style=github&showBorder=on&showLineNumbers=on&showFileMeta=on"></script>


Connect via usb to ''gadget'' mode. After flashing RaspianOS. The following files are at <code>boot</code>-directory
=== Crontab ===
* Modify <code>config.txt</code>: add <code>dtoverlay=dwc2</code>
* Add an empty file called <code>ssh</code>
* Edit <code>cmdline.txt</code>: Ensure that there exist <code>rootwait modules-load=dwc2,g_ether</code>.


Now you can <code>ssh pi@raspberrypi.local</code> if the usb cable is plugged in.
=== Sshpass ===


== Bluetooth on Raspi 3 ==
=== Server side ===


<syntaxhighlight>
=== Connect to the internet via Windows (tethering?) ===
sudo apt update
sudo apt upgrade
sudo apt-get install python-bluez
#sudo apt install bluetooth pi-bluetooth bluez blueman
</syntaxhighlight>


<code>sudo nano /etc/systemd/system/dbus-org.bluez.service</code>. Modify <code>ExecStart=/usr/lib/bluetooth/bluetoothd –C</code>
[[File:Windows allowTether.png|thumb|Allow other network users to connect]]


<code>sudo sdptool add SP</code>
Can connect from my computer on the fly, but to allow Raspberry Pi to connect to the external WWW, see the image.


<code>sudo reboot</code>
See https://raspberrypi.stackexchange.com/questions/11684/how-can-i-connect-my-pi-directly-to-my-pc-and-share-the-internet-connection
* Note that the outlook has changed a bit.


<syntaxhighlight>
=== Finding the IP address ===
sudo apt-get install bluetooth bluez libbluetooth-dev
sudo python3 -m pip install pybluez
</syntaxhighlight>


The SSH is disable by default after 2016. Below is show how to enable without using keyboard. This is useful also with QNAP NAS: to find it. Remember that booting it up takes a lot of time. The default port is 8080, thus use <code>p</code> tag: <code>nmap  -p 8080 192.168.8.*</code>


Use <code>nmap -F 192.168.8.1-254</code> to fast scan all devices in the local network. The default passwords are listed at [https://tutorials-raspberrypi.com/raspberry-pi-default-login-password/ Raspberry pi default login-password].


== Raspi and VIM ==
<code>nmap -sn 192.168.8.0/24</code> might work better, or without <code>-sn</code> option: <code>nmap 192.168.8.0/24</code>


<syntaxhighlight>
Try <code>ping raspberrypi.local</code>.
sudo apt install vim
sudo apt install vim-nox
#Vundle
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
</syntaxhighlight>


<code>vim ~/.vimrc</code>
Try <code>sudo nmap -sP 192.168.8.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'</code> with sudo.


Try <code>nmap -p 22 192.168.8.0/24</code> to find the SSH ports. Perhaps using sudo.
or <code>nmap -p 22 --open -sV 192.168.8.0/24</code>.


=== Enable ssh ===


<syntaxhighlight>
On another computer, mount the Raspian boot SD card, navigate to the boot folder <code>cd /Volumes/boot</code>, create a blank file called ''ssh'' <code>touch ssh</code>. That's all.
" Syntax highlight
syntax enable
" Tabs are spaces
set expandtab
" Number of spaces per tab
set tabstop=2
" Search as soon as characters are entered
set incsearch
" Highlight search results
set hlsearch


</syntaxhighlight>


https://stackoverflow.com/questions/18948491/running-python-code-in-vim
Using the Raspian GUI: Preferences -> Raspberry Pi Configuration -> Interfaces -> SSH.


https://scribles.net/enabling-python-autocomplete-in-vim-on-raspberry-pi/
Using the terminal: <code>sudo raspi-config</code> or use <code>systemctl</code>:


Bundle 'Valloric/YouCompleteMe'
<pre>
sudo systemctl enable ssh
sudo systemctl start ssh
</pre>


== Project Ideas ==


* [[Pimoroni Galactic Unicorn Hello World]]


*[[Bluetooth LE & Polar Heart Beat Monitor]]
*[[Camera piano]]
*[[Controlling CD Drive motor]]
*[[Info TV/ Dashboad]]
*[[Microscope and photo stacking]]
*[[Online thermometer with local backup]]
*[[Solar powered on/off line timelapse photography]]
*[[Sound spectrum]]
*[[Weather station --- Raspberry Pi]]
*[[Connect the APC220 radio module and submit the data to Internet]]


* https://www.weareteachers.com/raspberry-pi-projects/
** Airplay speaker https://www.hackster.io/fvdbosch/raspberry-pi-zero-airplay-speaker-d99feb
** Bug habitat https://allenheard.wordpress.com/2013/11/06/making-a-mini-beast-habitat-raspberry-pi-style/
** Drum set https://www.sciencebuddies.org/science-fair-projects/project-ideas/CompSci_p054/computer-science/electronic-drumset-raspberry-pi
** Light up Art https://www.sciencebuddies.org/science-fair-projects/project-ideas/CompSci_p057/computer-science/light-sensor-art-raspberry-pi
** Robot head https://www.sciencebuddies.org/science-fair-projects/project-ideas/CompSci_p058/computer-science/interactive-toy-raspberry-pi
** Greenhouse https://www.instructables.com/Automated-Greenhouse/
** Smart mirror
** Super computer cluster
** Traffic Lights
** Bird Box https://projects.raspberrypi.org/en/projects/infrared-bird-box
** Plants health https://projects.raspberrypi.org/en/projects/astropi-ndvi
** Ultrasonic Theremin https://www.hackster.io/kevinmcaleer/raspberry-pi-theremin-midi-project-254e7b
** Ja monta muuta.


== Raspi and Ev3-G ==  
== Peripherals ==


=== Error Messages so far ===
* Analog sensors https://www.rototron.info/raspberry-pi-analog-water-sensor-tutorial/
* Camera
* Dissolved oxygen meter https://www.instructables.com/Plotly-Atlas-Scientific-Graph-Real-Time-Dissolved-/ https://elexhub.com/product/gravity-analog-dissolved-oxygen-sensor-meter-kit/ https://how2electronics.com/dissolved-oxygen-sensor-arduino-interfacing-tutorial/ https://atlas-scientific.com/circuits/ezo-dissolved-oxygen-circuit/# https://atlas-scientific.com/probes/dissolved-oxygen-probe/
* Laptop Keyboard: https://raspberrypi.stackexchange.com/questions/5007/using-an-old-laptop-keyboard-with-raspberry-pi https://www.youtube.com/watch?v=AKWheG8wKxM
* Temperature, pH


raspberry pi device added succesfuly but failed to connect
== Sensors ==


Connection failed: _blueman.RFCOMMError: Failed to get rfcomm channel
* MG-811 MG811 CO2 Carbon Dioxide Sensor For Arduino UNO R3 Raspberry Pi
* CCS811 CO2 Carbon Dioxide Detector Air Quality Monitor Meter Sensor for Arduino
* MQ-2 Kohlenmonoxid Sensor CO Gas-Sensor, Rauch-Sensor, Raspberry Pi, Arduino
* CJMCU MICS 6814 Kohlenmonoxid Stickstoff Sauerstoff Sensor Co No2 Nh3 Arduino
* MH-Z19 IR infrared Carbon Dioxide Gas Sensor For Air CO2 Concentration Monitor
* Environment Sensor HAT für Raspberry Pi Zero 2 W WH A 3 Model B Plus 4 2GB 8GB
* [[Scd30 co2 sensor|CD30 Air Quality Sensors Module]] for CO2 and RH/T Measurements I2C PWM Modbus


Paired successfully but this device has no services which can be used with raspberry pi
== Bluetooth ==


[https://www.cod3v.info/index.php?title=Setting_up_the_Raspi Setting up the Raspberry Pi.]


=== Pairing ev3 and Raspi ===
[https://www.cod3v.info/index.php?title=Raspi_and_EV3-G Raspberry Pi and EV3-G]


Pairing and connecting is easy using X11.
[https://www.cod3v.info/index.php?title=Raspi_and_Ev3dev Raspberry Pi and Ev3Dev]


<code>bluetooth-agent</code> command do not exist on Jessie. Use <code>bluetoothctl</code> with the following script shown on [https://raspberrypi.stackexchange.com/questions/50496/automatically-accept-bluetooth-pairings Stackechange]:
== Erase the SD card ==


<syntaxhighlight>
Use camera to format the SD card, or see https://www.raspberrypi.org/forums/viewtopic.php?t=204167 .
sudo bluetoothctl <<EOF
power on
discoverable on
pairable on
agent NoInputNoOutput
default-agent
EOF
</syntaxhighlight>


== Bluetooth on Raspi 3 ==


<syntaxhighlight>
<syntaxhighlight>
bluetoothctl
sudo apt update
power on
sudo apt upgrade
discoverable on
sudo apt-get install python-bluez
scan on
#sudo apt install bluetooth pi-bluetooth bluez blueman
</syntaxhighlight>
</syntaxhighlight>


<syntaxhighlight>
<code>sudo nano /etc/systemd/system/dbus-org.bluez.service</code>. Modify <code>ExecStart=/usr/lib/bluetooth/bluetoothd –C</code>
trust <ev3 address>
pair <ev3 address>
agent on OR default-agent
devices
quit
</syntaxhighlight>


<syntaxhighlight>
<code>sudo sdptool add SP</code>
Device 24:71:89:BA:DA:61 ev3dev
Device 00:16:53:53:64:E1 EV3
</syntaxhighlight>


It helps to restart Ev3.
<code>sudo reboot</code>


The file <code>/etc/bluetooth/rfcomm.conf</code>
<syntaxhighlight>
<syntaxhighlight>
rfcomm0 {
sudo apt-get install bluetooth bluez libbluetooth-dev
  # Automatically bind the device at startup
sudo python3 -m pip install pybluez
  bind no;
  # Bluetooth address of the device
  device 00:16:53:53:64:E1 ;
  # RFCOMM channel for the connection
  channel 2;
  # Description of the connection
  comment "This is Device EV3's serial port.";
}
</syntaxhighlight>
</syntaxhighlight>




[[https://raspberrypi.stackexchange.com/questions/78155/using-dev-rfcomm0-in-raspberry-pi| To establish Bluetooth]] connection, need to create the serial device that binds to the paired Ev3 robot:
== Start script if Wifi is connected ==
<syntaxhighlight>
sudo rfcomm connect rfcomm0  00:16:53:53:64:E1
</syntaxhighlight>
or use
<syntaxhighlight>
sudo rfcomm bind /dev/rfcomm0  00:16:53:53:64:E1 1
</syntaxhighlight>
where the last number is the communication channel. It needs to be unique.


=== Some links ===


*http://www.geekdroppings.com/2018/01/21/raspberry-pi-and-the-lego-ev3-connected-by-bluetooth/
* Put your script in /etc/network/if-up.d and make it executable. It will be automatically run each time a network interface comes up. https://unix.stackexchange.com/questions/166473/debian-how-to-run-a-script-on-startup-as-soon-as-there-is-an-internet-connecti
*https://www.hackster.io/KKE/raspberry-pi-lego-mindstorms-ev3-bluetooth-communication-aa42e2
*https://siouxnetontrack.wordpress.com/2013/09/27/connecting-the-pc-to-our-ev3/
*https://gipprojects.wordpress.com/2013/11/29/using-python-and-raspberry-pi-to-communicate-with-lego-mindstorms-ev3/
*https://ev3lessons.com/en/ProgrammingLessons/beyond/EV3PiLight.pdf
*https://ev3lessons.com/en/ProgrammingLessons/beyond/EV3PiCommunicator.pdf
*http://www.abrowndesign.com/2018/10/25/sending-bluetooth-messages-from-raspberry-pi-to-lego-ev3-stock-firmware/
*https://github.com/lehoff/ev3bt/


* Add your script to /etc/network/if-up.d/. Name your script without a '.sh' extension.
Also after adding script run chmod +x /etc/network/if-up.d/yourscriptname to give necessary permission.
Make sure the network interface (e.g. wlan0 or eth0) that should trigger your script when turned on is mentioned in the file /etc/network/interfaces. https://askubuntu.com/questions/258580/how-to-run-a-script-depending-on-internet-connection


<gallery>
* To see only wifi status $ nmcli radio  wifi  https://askubuntu.com/questions/398581/is-there-a-terminal-command-to-verify-if-wifi-is-enabled#398602
MaksymShyte.png|Maksym Shyte @ http://www.geekdroppings.com/2018/01/21/raspberry-pi-and-the-lego-ev3-connected-by-bluetooth/
KoenKempeneers.png|Koen Kempeneers @ https://www.hackster.io/KKE/raspberry-pi-lego-mindstorms-ev3-bluetooth-communication-aa42e2
HansOdenthal.png|Hans Odenthal @ https://siouxnetontrack.wordpress.com/2013/09/27/connecting-the-pc-to-our-ev3/
</gallery>
 
=== Transmitting From EV3-G To Raspberry Pi ===
 
[[File:EV3BT sendTo|thumb|Two simple scripts to send data to Raspberry Pi.]]
 
<syntaxhighlight lang="python">
#hackster.io -> Raspberry Pi Lego Mindstorms ev3 bluetooth
import serial
import time
EV3 = serial.Serial('/dev/rfcomm0')
print("Listening to")
try:
    while True:
        n = EV3.inWaiting()
        if n != 0:
            s = EV3.read(n)
            print( s )
            for n in s:
                print( "x%02X" % (n), end=' ' )
                #print( chr( int(n) ) )
            print()
        time.sleep(0.5)
except KeyboardInterrupt:
    pass
EV3.close()
</syntaxhighlight>
 
=== Transmitting From Raspberry Pi To EV3-G ===
 
 
Run the following program on EV-g .
 
[[File:BT ev3g hello.png|thumb|One hello instead of multiple.]]
 
and the then start the Python script on the Raspi:
<syntaxhighlight lang="python">
#! /usr/bin/env/ python3
import serial
import time
import EV3BT
 
EV3 = serial.Serial('/dev/rfcomm0')
s = EV3BT.encodeMessage(EV3BT.MessageType.Text, 'abc', 'Have fun')
for i in range(10):
    print( EV3BT.printMessage(s) )
    EV3.write(s)
    time.sleep(1)
    print(i)
EV3.close()
</syntaxhighlight>
 
The brick says once ''Hello' and after that wants to connect to raspi. If the wrong password is given, the Python code will shutdown. The <code>update</code> in the EV3-G's Bluetooth command do not work.


== Raspi and Ev3Dev ==
* https://raspberrypi.stackexchange.com/questions/78991/running-a-script-after-an-internet-connection-is-established


* To run a script when the WiFi is connected you can use wpa_cli. In man wpa_cli you find for option -a: https://raspberrypi.stackexchange.com/questions/96050/run-a-script-when-wifi-is-connected-to-a-particular-wifi-network


== ==
* By the time the interface is up, it doesn't means that you have a connectivity at all. If the interface is configured to get IP from DHCP for example, few seconds are needed for the IP configurations. To check for Internet connectivity, you can query the IP of a known webpage with nslookup or dig. If you get a valid answer you can proceed. Otherwise, wait and repeat for a certain number of retries before aborting.  https://stackoverflow.com/questions/33086020/run-script-after-network-is-connected

Latest revision as of 18:22, 23 September 2024

Some of my Raspberries

  • Raspeberry 1 (or perhaps 1B) with a camera module on a wood stick. 26 pins. UART.

Simple things used in every Project

Raspistill

raspistill -w 2592 -h 1944 -o name.jpg


Take a photo and send it to an external server Template:GithubDownload

<script src="https://emgithub.com/embed.js?target=https%3A%2F%2Fgithub.com%2Fpytorch%2Fpytorch%2Fblob%2Fmaster%2Ftorch%2Fnn%2Fcpp.py&style=github&showBorder=on&showLineNumbers=on&showFileMeta=on"></script>

Crontab

Sshpass

Server side

Connect to the internet via Windows (tethering?)

Allow other network users to connect

Can connect from my computer on the fly, but to allow Raspberry Pi to connect to the external WWW, see the image.

See https://raspberrypi.stackexchange.com/questions/11684/how-can-i-connect-my-pi-directly-to-my-pc-and-share-the-internet-connection

  • Note that the outlook has changed a bit.

Finding the IP address

The SSH is disable by default after 2016. Below is show how to enable without using keyboard. This is useful also with QNAP NAS: to find it. Remember that booting it up takes a lot of time. The default port is 8080, thus use p tag: nmap -p 8080 192.168.8.*

Use nmap -F 192.168.8.1-254 to fast scan all devices in the local network. The default passwords are listed at Raspberry pi default login-password.

nmap -sn 192.168.8.0/24 might work better, or without -sn option: nmap 192.168.8.0/24

Try ping raspberrypi.local.

Try sudo nmap -sP 192.168.8.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}' with sudo.

Try nmap -p 22 192.168.8.0/24 to find the SSH ports. Perhaps using sudo. or nmap -p 22 --open -sV 192.168.8.0/24.

Enable ssh

On another computer, mount the Raspian boot SD card, navigate to the boot folder cd /Volumes/boot, create a blank file called ssh touch ssh. That's all.


Using the Raspian GUI: Preferences -> Raspberry Pi Configuration -> Interfaces -> SSH.

Using the terminal: sudo raspi-config or use systemctl:

sudo systemctl enable ssh
sudo systemctl start ssh

Project Ideas

Peripherals

Sensors

  • MG-811 MG811 CO2 Carbon Dioxide Sensor For Arduino UNO R3 Raspberry Pi
  • CCS811 CO2 Carbon Dioxide Detector Air Quality Monitor Meter Sensor for Arduino
  • MQ-2 Kohlenmonoxid Sensor CO Gas-Sensor, Rauch-Sensor, Raspberry Pi, Arduino
  • CJMCU MICS 6814 Kohlenmonoxid Stickstoff Sauerstoff Sensor Co No2 Nh3 Arduino
  • MH-Z19 IR infrared Carbon Dioxide Gas Sensor For Air CO2 Concentration Monitor
  • Environment Sensor HAT für Raspberry Pi Zero 2 W WH A 3 Model B Plus 4 2GB 8GB
  • CD30 Air Quality Sensors Module for CO2 and RH/T Measurements I2C PWM Modbus

Bluetooth

Setting up the Raspberry Pi.

Raspberry Pi and EV3-G

Raspberry Pi and Ev3Dev

Erase the SD card

Use camera to format the SD card, or see https://www.raspberrypi.org/forums/viewtopic.php?t=204167 .

Bluetooth on Raspi 3

sudo apt update
sudo apt upgrade
sudo apt-get install python-bluez
#sudo apt install bluetooth pi-bluetooth bluez blueman

sudo nano /etc/systemd/system/dbus-org.bluez.service. Modify ExecStart=/usr/lib/bluetooth/bluetoothd –C

sudo sdptool add SP

sudo reboot

sudo apt-get install bluetooth bluez libbluetooth-dev
sudo python3 -m pip install pybluez


Start script if Wifi is connected

  • Add your script to /etc/network/if-up.d/. Name your script without a '.sh' extension.

Also after adding script run chmod +x /etc/network/if-up.d/yourscriptname to give necessary permission. Make sure the network interface (e.g. wlan0 or eth0) that should trigger your script when turned on is mentioned in the file /etc/network/interfaces. https://askubuntu.com/questions/258580/how-to-run-a-script-depending-on-internet-connection

  • By the time the interface is up, it doesn't means that you have a connectivity at all. If the interface is configured to get IP from DHCP for example, few seconds are needed for the IP configurations. To check for Internet connectivity, you can query the IP of a known webpage with nslookup or dig. If you get a valid answer you can proceed. Otherwise, wait and repeat for a certain number of retries before aborting. https://stackoverflow.com/questions/33086020/run-script-after-network-is-connected