Raspberry Pi: Difference between revisions

From wikiluntti
Line 100: Line 100:
=== Pairing ev3 and Raspi ===
=== Pairing ev3 and Raspi ===


<code>bluetooth-agent</code> command do not exist on Jessie. Use <code>bluetoothctl</code>.
<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]:


<syntaxhighlight>
<syntaxhighlight>
Line 123: Line 123:
trust <ev3 address>
trust <ev3 address>
pair <ev3 address>
pair <ev3 address>
agent on OR default-agent
devices
devices
quit
quit

Revision as of 15:12, 1 November 2020

Setting Up The Raspian

Establish Wifi, Bluetooth.

Credentials are pi@raspberrypi.local and raspberry. KiTTY seems to be a good terminal.

Set Up WiFi without Screen

Into root directory:

  • Add an empty file called ssh
  • Add a file wpa_supplicant.conf which includes
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
}

Note the (Notepad++: Edit) EOL conversion UNIX.

https://www.raspberrypi-spy.co.uk/2017/04/manually-setting-up-pi-wifi-using-wpa_supplicant-conf/


USB cable // Perhaps requires Zero

Connect via usb to gadget mode. After flashing RaspianOS. The following files are at boot-directory

  • Modify config.txt: add dtoverlay=dwc2
  • Add an empty file called ssh
  • Edit cmdline.txt: Ensure that there exist rootwait modules-load=dwc2,g_ether.

Now you can ssh pi@raspberrypi.local if the usb cable is plugged in.

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


Raspi and VIM

sudo apt install vim
sudo apt install vim-nox
#Vundle
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

vim ~/.vimrc


" 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

https://stackoverflow.com/questions/18948491/running-python-code-in-vim

https://scribles.net/enabling-python-autocomplete-in-vim-on-raspberry-pi/

Bundle 'Valloric/YouCompleteMe'



Raspi and Ev3-G

Pairing ev3 and Raspi

bluetooth-agent command do not exist on Jessie. Use bluetoothctl with the following script shown on Stackechange:

sudo bluetoothctl <<EOF
power on
discoverable on
pairable on
agent NoInputNoOutput
default-agent 
EOF


bluetoothctl
power on
discoverable on
scan on
trust <ev3 address>
pair <ev3 address>
agent on OR default-agent
devices
quit
Device 24:71:89:BA:DA:61 ev3dev
Device 00:16:53:53:64:E1 EV3

It helps to restart Ev3.

The file /etc/bluetooth/rfcomm.conf

rfcomm0 {
  # Automatically bind the device at startup
  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.";
}


[To establish Bluetooth] connection, need to create the serial device that binds to the paired Ev3 robot:

sudo rfcomm connect rfcomm0  00:16:53:53:64:E1

or use

sudo rfcomm bind /dev/rfcomm0  00:16:53:53:64:E1 1

where the last number is the communication channel. It needs to be unique.

Some links


First Attempt (ev3BT)

Run the following program on EV-g .

One hello instead of multiple.

and the then start the Python script on the Raspi:

#! /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()

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 update in the EV3-G's Bluetooth command do not work.

Raspi and Ev3Dev