battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.

battle programmers allianceLog in

the LivinGrimoire Artificial General Intelligence software design pattern forum

descriptionRaspberry Pi grimoire EmptyRaspberry Pi grimoire

more_horiz

initial setup



a raspberry PI is a small exposed computer.

list of materials:
  1. Raspberry Pi 4 board (2GB version and it works perfectly fine for most projects)
  2. Power supply for the Pi. For Raspberry Pi 4 you’ll need to power your board with an USB-C connector. For Raspberry Pi 2-3 you’ll need a micro-USB connector. Important: do not power on your Pi directly from your computer. This may seem to work, but the delivered current will be too low. Use a proper power supply, for example a smartphone power supply. So: - For Raspberry Pi 4, try using a power supply which can deliver 5V - 3.0A min - For Raspberry Pi 2 and 3: 5V - 2.5A min. If you can’t get those values, the minimum you should aim for is 5V - 2.0A
  3. micro SD card 2 important criterions here: the class and the storage capacity. For the class, choose at least class 10. You should see a “10” inside a circle on the card. Some new cards are even more powerful, if you see a “3” inside a U shape it’s even better. If the class of your SD card is too low then it won’t be fast enough for the Raspberry Pi OS to run properly. For the storage capacity, choose at least 8GB, so you have enough space for the operating system and some additional files. 16/32GB is better especially if you plan on installing more software and store image/video files. You can go with more than 32GB but it might require some formatting from your side. In this course I personally use a 16GB micro SD card.

Hardware components
- 1* breadboard
- Set of wires: male-male, male-female, and female-female
- Set of resistors: 1kOhm, 10kOhm (if not available, resistors between 330Ohm and 20kOhm will do)
- 3* LEDs (any color)
- 1* push button (4 legs)

Note: for this list, usually you can find kits that include all those hardware components (search for “breadboard kit”). :s33:

Last edited by Moti Barski on Wed Mar 29, 2023 11:09 am; edited 1 time in total

descriptionRaspberry Pi grimoire EmptyRe: Raspberry Pi grimoire

more_horiz

warning



when manipulating Raspberry Pi, always:
1 shutdown the Pi from the desktop
2 wait 20 seconds and remove the power cable
:s19:

descriptionRaspberry Pi grimoire EmptyRe: Raspberry Pi grimoire

more_horiz

Pi OS installation aka SD card flashing


1 https://www.raspberrypi.com/software/

Download and install Raspberry Pi Imager to a computer with an SD card reader.
Put the SD card you'll use with your Raspberry Pi into the reader and run Raspberry Pi
Imager.

this software will flash the raspberry OS into your SD card.
the software should be at least 1.7.2 for pi 4

2 connect the SD card to your computer, click choose Operating System and pick the
latest one.
click choose storage, and it should detect your SD card.

click setting and configure:
check enable SSH, use password auth.
(this will enable to access remotly (using the terminal) to the Pi,
without an external monitor)

and set a username and password.

on "configure wireless LAN": add the name and pass for your WiFi network
(internet router)

on "set local settings": set your timezone and keybouard language.

click on save

3 click on write, yes.
licky

descriptionRaspberry Pi grimoire EmptyRe: Raspberry Pi grimoire

more_horiz

booting the Pi


make sure the power is off and no cables are connected.

plug in the SD card into the Pi.
connect the Pi to a power supply (not computer USB cable)

the green LED should blink randomly, meaning the Pi is booting.
a few seconds later the Pi will have connected to the WiFi network. dab

descriptionRaspberry Pi grimoire EmptyRe: Raspberry Pi grimoire

more_horiz

finding the Pi IP address



[URL unfurl="true"]https://angryip.org/[/URL]

go to downloads and choose your computers OS.
install angry IP scanner.

assuming your computer is connected to the same WiFi network,
in the angry IP scanner:
click on the icon next to start and add MAC vendor.

click IP and find a line that has wifi 192.168 or 10.0 and click it
so the IP range shows something like
192.168.31.0 to 192.168.31.255
edit the final numbers to 0 and 255 if they aren't set that way already.

click start, and wait about a minute.
if fire wall pops up, click allow.
clcik ping, sort by ping.
the blue circles mark findings, red mark no findings
you should see a blue dot and raspberry pi.local under host name, and the pi IP address.
where

descriptionRaspberry Pi grimoire EmptyRe: Raspberry Pi grimoire

more_horiz

connecting to the Pi via SSH


use mac terminal or

cmd on windows to SSH

or puTTy on windows:
[URL unfurl="true"]https://www.putty.org/[/URL]

ssh user_name(specified on the SD card flash stage by you)@IPaddress found by angry IP scanner
ssh pi@192.168.31.70

press enter. yes.
enter pi password you set up on flashing stage.

now you are in the Pi
pi@raspberrypi:~ $

descriptionRaspberry Pi grimoire EmptyRe: Raspberry Pi grimoire

more_horiz

VNC


it enables work with the Pi after SSH connection has been established from the computer.
on terminal after ssh pi@ip_address

sudo raspi-config
choose interface options, VNC, would you like VNC to be enabled?, yes
finish.

back on the terminal reboot the Pi:
sudo reboot

should say connection reset
wait 1 minute

ssh pi@ip_address
sudo raspi-config

system options, boot / auto login, desktop autologin, finish, reboot now? yes

should say connection reset on the terminal
wait 1 minute

ssh pi@ip_address
sudo raspi-config

display options, VNC resolution, chose the resolution of your computer screen
1920x1080 for full HD, finish, reboot now? yes.

get VNC at
[URL unfurl="true"]https://www.realvnc.com/en/connect/download/viewer/[/URL]
choose your computer OS

on VNC:
file, new connection,
VNC server : ip address of the Pi
name : does not matter
click ok, click Raspberry Pi, configure, enter the user name and pass of the PI
from the SD flash stage.

nervous

on VNC configurations


APPEARANCE:
raspberry Pi icon, preferences, appearance settings, task bar, very large,
system, font, set font size.

raspberry Pi icon, preferences, raspberry Pi configurations:
system, password : you can change the password, than reboot to apply.

on display you can change the resolution on VNC.

interfaces: from here you can enable SSH, VNC

localization: set timezone and keyboard language.

from the tool bar you can change wifi network, but than you will need to
find the new IP address on your computer that should be connected to the new wifi network.
than connect via SSH or VNC to the Pi.

click the update icon left of the bluetooth icon to update the Pi software, install updates.

powering off the Pi

menu (upper tool bar), Pi symbol, shutdown, wait a minute, now you can remove the power supply.

to power on make sure the SD card is in, then connect the power supply cable.

descriptionRaspberry Pi grimoire EmptyRe: Raspberry Pi grimoire

more_horiz

change Pi wifi settings

spellcaster

assuming your computer now uses a different wifi network
than the one in thePi settings.

power of the Pi, connect the SD card to your computer.
the SD card should have the name boot.

add a new file to config the wifi:

new text document, wpa_supplicant.conf

file contents:

country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
scan_ssid=1
ssid="your_wifi_ssid"
psk="your_wifi_password"
}

ssid will be the wifi network name
psk will be the wifi network password

connect the SD card to the off powered Pi, turn on the Pi, wait a minute
open angry IP scanner to find the new Pi IP.
VNC, right click Raspberry PI, properties, update the new IP address, double click to connect.

descriptionRaspberry Pi grimoire EmptyRe: Raspberry Pi grimoire

more_horiz

hello world


on VNC
click raspberry Pi symbol, thonny python IDE, python IDE for beginners.
switch to regular mode, close the program and reopen it.

the view btn has a python shell option
>>> print("hello world")

above the shell there is a text editor for writting programs.
running the program prompts a save window, save as : hello_world.py
without spaces

:s24:

descriptionRaspberry Pi grimoire EmptyRe: Raspberry Pi grimoire

more_horiz

GPIO


warnings

1. always turn off the Pi before changing a circuit
2. when power on, don't touch the Pi (static discharge (ESD))
3. start the circuit with GRD
4. don't use 5V on a GPIO pin (3.3V max)
crying

descriptionRaspberry Pi grimoire EmptyRe: Raspberry Pi grimoire

more_horiz
Raspberry Pi grimoire Resistor-calc

Raspberry Pi grimoire Pi-pin-layout

descriptionRaspberry Pi grimoire EmptyGPIO output

more_horiz

LED blink program

pin output

Code:

# import GPIO jutsu with the alias GPIO
import RPi.GPIO as GPIO
import time

LED_PIN = 17

GPIO.setmode(GPIO.BCM)
# the pins are assigned numbers as in the picture
GPIO.setup(LED_PIN, GPIO.OUT)
# GPIO has been set as an output pin

state = int(input("Enter 0 to power off the LED, 1 to power on the LED: "))

if state == 0:
    GPIO.output(LED_PIN, GPIO.LOW)
elif state == 1:
    GPIO.output(LED_PIN, GPIO.HIGH)
else:
    print("Wrong state value : " + str(state))
    GPIO.cleanup()
    # exit the program:
    exit

time.sleep(2)
# set GPIO mode and state to default
GPIO.cleanup()

descriptionRaspberry Pi grimoire EmptyRe: Raspberry Pi grimoire

more_horiz

GPIO Input pin


python code: fez

Code:

# import GPIO jutsu with the alias GPIO
import RPi.GPIO as GPIO
import time

BTN_PIN = 26

GPIO.setmode(GPIO.BCM)
# the pins are assigned numbers as in the picture
GPIO.setup(BTN_PIN, GPIO.IN)
# GPIO has been set as an input pin
print(GPIO.input(BTN_PIN))

# set GPIO mode and state to default
GPIO.cleanup()


Raspberry Pi grimoire Rpi-push-button

descriptionRaspberry Pi grimoire EmptyRe: Raspberry Pi grimoire

more_horiz

PIR sensor


PIR sensor

Raspberry Pi grimoire PIR-Senso-l51

Passive InfraRed Sensor. it is a motion detector.

model used: HC-SR501

PIR setup

the PIR jumper should be set to high

the left potentiometer sets the detection range. turn counter clock wise
to decrease the range (3 meters) or clock wise up to (7 meters).

the right potentiometer sets the detection time, (how long a detection signal is sent).
minimum is counter clock wise.

max detection time lingers for 5 minutes, minimum lingers for 5 seconds

Raspberry Pi grimoire Rpi-pir-sensor

the sensor takes a minute to warm up after the Pi is powered on.

Code:

import RPi.GPIO as GPIO
import time

LED_PIN = 17
PIR_PIN = 4

GPIO.setmode(GPIO.BCM)
GPIO.setup(PIR_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
# the pull down resistor makes sure the values are 0 or 1
# an internal Pi resistor is used here
GPIO.setup(LED_PIN, GPIO.OUT)
GPIO.output(LED_PIN, GPIO.LOW)

while True:
    time.sleep(0.01) # this code prevents over usage of the cpu core
    if GPIO.input(PIR_PIN) == GPIO.HIGH:
        GPIO.output(LED_PIN, GPIO.HIGH)
    else:
        GPIO.output(LED_PIN, GPIO.LOW)

GPIO.cleanup()

observing

descriptionRaspberry Pi grimoire EmptyPi OS task manager

more_horiz

Pi OS task manager


Pi symbol, accessories, task manager
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply