CS Forward

Category: Raspberry Pi Page 2 of 3

How to Backup/Restore Your Raspberry Pi SD Card on macOS

Steps for Backup

1. Mount your Raspberry Pi SD card to your Mac.

2. Find your SD card’s name:

diskutil list

3. and backup your diskX as myPiBackup.dmg:

sudo dd if=/dev/diskX of=~/myPiBackup.dmg

4. Enter your password when prompted.

5. Backup will take some time. If you want to see the process:

Control+T

6. Eject your SD card:

sudo diskutil eject /dev/rdiskX

 

Steps for Restoring

1. Mount your empty SD card to your Mac.

2. Find your SD card’s name:

diskutil list

3. Write your myPiBackup.dmg into your diskX.

diskutil unmountDisk /dev/diskX
sudo dd if=myPiBackup.dmg of=/dev/diskX

4. Enter your password when prompted.

5. Restoring will take some time. (31914983424 bytes transferred in 15260.841046 secs (2091299 bytes/sec)). If you want to see the process:

Control+T

6. Eject your SD card:

sudo diskutil eject /dev/rdiskX

 

Credits

https://howchoo.com/pi/create-a-backup-image-of-your-raspberry-pi-sd-card-in-mac-osx

Connect A Bluetooth Speaker to Raspberry Pi

Steps

1. Install PulseAudio and bluetooth module:

sudo apt-get install pulseaudio
sudo apt-get install pavucontrol paprefs
sudo apt-get install pulseaudio-module-bluetooth

 

2. Connect bluetooth speaker and configure:

bluetoothctl
power on
agent on
default-agent
quit
sudo killall bluealsa
pulseaudio -k
pulseaudio –start
pactl unload-module module-bluetooth-discover
pactl load-module module-bluetooth-discover

 

3. Turn your bluetooth speaker on and disconnect from other devices:

bluetoothctl
scan on

 

4. Wait until Raspberry Pi finds the target bluetooth speaker, and note the MAC address such as “XX:XX:XX:XX:XX:XX”:

scan off

 

5. Replace “XX:XX:XX:XX:XX:XX” with your address:

pair XX:XX:XX:XX:XX:XX
trust XX:XX:XX:XX:XX:XX
connect XX:XX:XX:XX:XX:XX

 

6. Confirm it is recognized as a sound device:

pacmd list-cards

 

7. You should see your device address like “XX:XX:XX:XX:XX:XX” somewhere:

pacmd set-card-profile bluez_card.XX_XX_XX_XX_XX_XX a2dp_sink
pacmd set-default-sink bluez_sink.XX_XX_XX_XX_XX_XX.a2dp_sink

 

8. Edit “start-pulseaudio-x11” script to connect bluetooth speaker on startup:

sudo nano /usr/bin/start-pulseaudio-x11

 

9. Find the block of commands below:

if [ x”$SESSION_MANAGER” != x ] ; then
/usr/bin/pactl load-module module-x11-xsmp “display=$DISPLAY session_manager=$SESSION_MANAGER” > /dev/null
fi

 

10. Add the following lines of commands right after it (this will let you get sound from your speaker):

/usr/bin/pactl unload-module module-bluetooth-discover
/usr/bin/pactl load-module module-bluetooth-discover
sudo killall bluealsa
pulseaudio –start
bluetoothctl << EOF
connect XX:XX:XX:XX:XX:XX
EOF

 

11. Save the file by pressing Ctrl + X then Y and finally ENTER.

12. Modify “.bashrc” file.

sudo nano ~/.bashrc

 

13. Add the following lines of commands at the bottom:

/usr/bin/pactl unload-module module-bluetooth-discover
/usr/bin/pactl load-module module-bluetooth-discover
sudo killall bluealsa
pulseaudio –start
bluetoothctl << EOF
connect XX:XX:XX:XX:XX:XX
EOF

 

14. Save the file by pressing Ctrl + X then Y and finally ENTER. Then restart the Raspberry Pi:

sudo reboot

 

Credits

https://www.funincomplete.com/how-to-make-raspberry-pi-speak/

How to Change the Repository Mirror on Raspbian

Steps

1. Begin modifying sources.list file by running the following command:

sudo nano /etc/apt/sources.list

 

2. Find the following:

http://raspbian.raspberrypi.org/raspbian/

 

3. Replace with:

http://mirror.aarnet.edu.au/pub/raspbian/raspbian

 

4. Once you have finished modifying the file, it should look something like the text we have below:

deb http://mirror.aarnet.edu.au/pub/raspbian/raspbian stretch main contrib non-free rpi

# Uncomment line below then ‘apt-get update’ to enable ‘apt-get source’

#deb-src http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi

 

5. Save the file by pressing Ctrl + X then Y and finally ENTER.

 

6. Now that we have updated the sources.list file we need to go ahead and run an update. This will update the local package list so that it will retrieve packages from the new repository:

sudo apt-get update

 

Credits

https://pimylifeup.com/raspbian-repository-mirror/

youtube-dl setup

Steps

0. Install vlc to play videos:

sudo apt install -y vlc

1. Run:

sudo apt install python3-pip

sudo pip3 install youtube-dl

 

2. After installation, you can search video and list formats:

youtube-dl –list-formats “ytsearch:videoname”

 

3. To download chosen video+audio and merge them, then rename the output:

youtube-dl -o “name.mp4” -f ‘videocode+audiocode’ “link or ytsearch:videoname”

 

4. To watch a video while downloading, first, create a Python script:

sudo nano hello.py

– Then type the following and Ctrl+X and Y and Enter:

import subprocess

import youtube_dl

player_run = False

p = None

def hook(status):

global player_run, p

if not player_run:

player_run = True

p = subprocess.Popen([‘vlc’, ‘-I ncurses’, status[‘filename’]])

opts = {

‘format’: ‘best’,

‘nopart’: True,

‘progress_hooks’: [hook],

‘verbose’: True,

}

with youtube_dl.YoutubeDL(opts) as ydl:

srch=input(“Search on YouTube: “)

ydl.download([‘ytsearch:’+srch])

p.wait()

 

5. Run the script:

python3 hello.py

 

6. If the version of youtube-dl is not the most recent version, you can change the repository mirror and do the following:

sudo apt-get install hello.py

7. To close the video:

Ctrl+C

8. To play live streams from youtube:

sudo apt-get install ffmpg

 

Credits

https://github.com/ytdl-org/youtube-dl

Screen Mirroring

Steps

0. You will possibly get an error about LIBPLIST in the upcoming steps, so first run:

sudo apt install libplist-dev

 

1. Then install git:

sudo apt install git

 

2. Then use these commands:

git clone https://github.com/FD-/RPiPlay.git

cd RPiPlay

 

3. For building on a fresh Raspbian install, these steps should be run:

sudo apt-get install cmake

sudo apt-get install libavahi-compat-libdnssd-dev

sudo apt-get install libssl-dev

mkdir build

cd build

cmake ..

make

 

4. At some point, if you get an error about GStreamer, run:

sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev

 

5. To Start mirroring:

cd RPiPlay

cd build

./rpiplay

 

6. To Stop it (this should bring up the login prompt):

Alt + PrtScr + k

 

7. And go to console:

Ctrl + Alt + F1

 

8. Raspberry Pi shut down:

sudo shutdown -h now

 

Credits

https://github.com/FD-/RPiPlay

https://github.com/FD-/RPiPlay/issues/145

https://stackoverflow.com/questions/37678324/compiling-opencv-with-gstreamer-cmake-not-finding-gstreamer

Page 2 of 3

Powered by WordPress & Theme by Anders Norén