= RaspberryPi =
 * https://www.raspberrypi.org/
 * https://en.wikipedia.org/wiki/Raspberry_Pi
 * Kit in https://www.chiptec.net/pcs-e-mobilidade/computadores/raspberrypi/kit-raspberry-pi-3-modelo-b-noobs-caixa-carregador-preto.html (Kit Raspberry Pi 3 Modelo B+(NOOBS+Caixa+Carregador) Preto)
 * Raspberry Pi 3 Model B Plus Rev 1.3
{{{
Processador	
  Broadcom BCM2837B0, Cortex-A53 (ARMv8) 64-bit SoC @ 1.4GHz
Memória RAM	
  1GB LPDDR2 SDRAM
Armazenamento	
  Cartão MicroSD 32GB com NOOBS
Wi-Fi e Bluetooth	
  2.4GHz e 5GHz IEEE 802.11.b/g/n/ac wireless LAN, Bluetooth 4.2, BLE
LAN	
  Gigabit Ethernet em USB 2.0 (saída máxima 300 Mbps)
Expansão	
  Extended 40-pin GPIO header
  CSI camera port
  DSI display port
  4-pole stereo output e composite video port
Portas	
  HDMI 
  USB 2.0 (4) 
  Micro-SD
Alimentação	
  Entrada 5V/2.5A DC
Prazo de Garantia	
  2 Anos
}}}
 * Access GPIO https://elinux.org/RPi_GPIO_Code_Samples#C
 * https://elinux.org/RPi_GPIO_Code_Samples#sysfs
 * https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up
 * https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up/print

== BCM2835 ==
 * Timers
 * Interrupt controller
 * GPIO
 * USB
 * PCM / I2S
 * DMA controller
 * I2C master
 * I2C / SPI slave
 * SPI0, SPI1, SPI2
 * PWM
 * UART0, UART1

== Install and configure screensaver and lock screen ==
 * sudo apt-get install xscreensaver
 * Preferences, Screen saver
 * Auto lock after 2 minutes
 * Create new menu item (Preferences, Main menu editor)
  * Menu item name Lock
  * Command: xscreensaver-comand -lock
  * Icon: /usr/share/lxpanel/images/ns-lock.png

== Info ==
{{{
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 9.4 (stretch)
Release:	9.4
Codename:	stretch

$ uname -a
Linux raspberrypi 4.14.71-v7+ #1145 SMP Fri Sep 21 15:38:35 BST 2018 armv7l GNU/Linux
}}}

== Install eclipse ==
 * apt-get install eclipse-platform

== Blink led port 26 ==
 * https://www.raspberrypi.org/documentation/usage/gpio/python/README.md
 * https://gpiozero.readthedocs.io/en/stable/
 *  python drive_gpio26.py
{{{#!highlight python
# drive_gpio26.py
from gpiozero import LED
from time import sleep

led = LED(26)

while True:
    led.on()
    sleep(1)
    led.off()
    sleep(1)
}}}

== Install python 3.8.5 in raspberry py ==
{{{#!highlight bash
tar xvzf Python-3.8.5.tgz 
cd Python-3.8.5/
./configure 
make clean
make
make install
sudo make install
/usr/local/bin/python3.8 -v
/usr/local/bin/pip3.8 install cherrypy
pip3.8 install jinja2
}}}

== Enable X11 forwarding ==
{{{#!highlight bash
# Raspberry pi side
sudo nano /etc/ssh/sshd_config
# add line X11Forwarding yes
service ssh restart
# client side
ssh -X -Y userx@192.168.2.3
echo $DISPLAY
leafpad & # text editor
pcmanfm & # file explorer
}}}

== Blink led service ==
Starts automatically after boot.

=== /home/pi/Documents/drive_gpio26.py ===
{{{#!highlight python
from gpiozero import LED
from time import sleep
import os

f = open('/tmp/drive_gpio26.pid','wb')
f.write(str(os.getpid()))
f.close()

led = LED(26)

while True:
    led.on()
    sleep(1)
    led.off()
    sleep(1)
}}}

=== /etc/init.d/drive_gpio26 ===
{{{#!highlight bash
#! /bin/sh
### BEGIN INIT INFO
# Provides:          drive_gpio26
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Blinks a led
# Description:       Blinks a led
### END INIT INFO
touch /var/lock/drive_gpio26
# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting script drive_gpio26 "
    su pi -c "nohup /usr/bin/python /home/pi/Documents/drive_gpio26.py >> /tmp/drive_gpio26.log 2>&1  &"
    ;;
  stop)
    echo "Stopping script drive_gpio26"
    kill $(cat  /tmp/drive_gpio26.pid)
    ;;
  *)
    echo "Usage: /etc/init.d/drive_gpio26 {start|stop}"
    exit 1
    ;;
esac

exit 0
}}}

{{{#!highlight bash
update-rc.d drive_gpio26 defaults # insert links in /etc/rc*d
update-rc.d drive_gpio26 defaults 20 80
update-rc.d drive_gpio26 enable
service drive_gpio26 status 
reboot 
}}}

== Install MariaDB raspbian ==
{{{#!highlight bash
sudo bash
apt install mariadb-server
mysql_secure_installation
# define root pass
mysql
GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY '????????' WITH GRANT OPTION;
FLUSH PRIVILEGES;
create database testdb;
show databases;
use testdb
CREATE TABLE locations ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, lat VARCHAR(30) NOT NULL, lon VARCHAR(30) NOT NULL);
exit
mysql -u admin -p
sudo pip3.8 install mysql-connector-python
#
python 3.8
import mysql.connector
mysql.connector.connect(host='localhost',database='testdb',user='admin',password='xxxxxxxx')
}}}

=== test_mariadb.py  ===
{{{#!highlight python
import mysql.connector
conn = mysql.connector.connect(
  host='localhost',
  database='testdb',
  user='admin',
  password='xxxxxxxx'
)
cursor=conn.cursor()
cursor.execute("Insert into locations (lat,lon) values(%s,%s)" , ("aaa","bbb") )
conn.commit()
print(cursor.rowcount, "record inserted.")
}}}

== Install Squid Web Proxy ==
{{{#!highlight bash
sudo bash 
apt update 
apt install squid
cd /etc/squid/
cp squid.conf squid.conf.ORIG
cat squid.conf.ORIG | egrep -v -e '^[[:blank:]]*#|^$' > squid.conf
nano squid.conf 
acl localnet src 192.168.111.0/24
http_access allow Localnet 
# comment http_access deny all 
service squid reload
#firefox manual proxy 
#IP rpi: 192.168.111.222   Port: 3128
#also for ftp and https
}}}

== Raspberry Pi Pico ==
 * https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html#technical-specification
 * https://datasheets.raspberrypi.com/picow/pico-w-datasheet.pdf
 * https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf
Raspberry Pi Pico is a low-cost, high-performance microcontroller board with flexible digital interfaces.


=== Connect with micro-usb ===
{{{#!highlight sh
sudo dmesg
# [ 3570.065996] usb 1-4.3: Product: RP2 Boot
# [ 3570.066006] usb 1-4.3: Manufacturer: Raspberry Pi
# [ 3570.066016] usb 1-4.3: SerialNumber: E0C9xxxxxxxx
# [ 3570.163372] usb-storage 1-4.3:1.0: USB Mass Storage device detected
# [ 3570.164049] scsi host2: usb-storage 1-4.3:1.0
# [ 3570.164381] usbcore: registered new interface driver usb-storage
# [ 3570.180142] usbcore: registered new interface driver uas
# [ 3571.192940] scsi 2:0:0:0: Direct-Access     RPI      RP2              3    PQ: 0 ANSI: 2
# [ 3571.194468] sd 2:0:0:0: Attached scsi generic sg1 type 0
# [ 3571.195164] sd 2:0:0:0: [sdb] 262144 512-byte logical blocks: (134 MB/128 MiB)
# [ 3571.195818] sd 2:0:0:0: [sdb] Write Protect is off
# [ 3571.195830] sd 2:0:0:0: [sdb] Mode Sense: 03 00 00 00
# [ 3571.196325] sd 2:0:0:0: [sdb] No Caching mode page found
# [ 3571.196335] sd 2:0:0:0: [sdb] Assuming drive cache: write through
# [ 3571.217448]  sdb: sdb1
# [ 3571.237585] sd 2:0:0:0: [sdb] Attached SCSI removable disk
}}}

== Update apt source ==
Set for '''/etc/apt/sources.list''' and '''/etc/apt/sources.list.d/raspi.list'''
{{{
deb http://legacy.raspbian.org/raspbian/ stretch main contrib non-free rpi
}}}

== Swap 512 MB ==
{{{#!highlight sh
dd if=/dev/zero of=/var/swap1 bs=1024 count=524288
chown root:root /var/swap1 
chmod 0600 /var/swap1 
mkswap /var/swap1
swapon /var/swap1
free -m
vi /etc/fstab
# /var/swap1 none swap sw 0 0
free -m
htop
}}}