Difference between revisions of "2010910 pi workshop notes"
(11 intermediate revisions by the same user not shown) | |||
Line 35: | Line 35: | ||
=First test= | =First test= | ||
+ | |||
+ | Connect to Pi computer using this command in the terminal: | ||
+ | |||
+ | ssh pi@JUPITER | ||
+ | |||
+ | Enter password: raspberry | ||
If we want to connect the LED on the GPIO4 port: <br> | If we want to connect the LED on the GPIO4 port: <br> | ||
Line 153: | Line 159: | ||
Makes pin 4 (here a LED) blink forever (while) | Makes pin 4 (here a LED) blink forever (while) | ||
− | + | =Networking= | |
− | to find IP address of Raspberry Pi: | + | To update anything: |
+ | |||
+ | sudo apt-get update NAME | ||
+ | |||
+ | To install anything: | ||
+ | |||
+ | sudo apt-get install NAME | ||
+ | |||
+ | to find IP address of Raspberry Pi (will retrieve the IP address): | ||
hostname -I | hostname -I | ||
− | + | To connect to the Pi via wifi | |
ssh pi@... (IP address) | ssh pi@... (IP address) | ||
+ | |||
+ | To get the IP address: | ||
#find a screen with HDMI cable | #find a screen with HDMI cable | ||
Line 169: | Line 185: | ||
top right corner, wifi signal, select the wifi network, type in password, write down IP address, then can be used to connect | top right corner, wifi signal, select the wifi network, type in password, write down IP address, then can be used to connect | ||
+ | |||
+ | For remote access to the files on the SD from a computer (to edit code for example), download [https://cyberduck.io Cyberduck] and use '''SFTP''' protocol (or any other similar interface). | ||
+ | |||
+ | '''VNC''' allows to use the virtual use interface via wifi (without cable and screen). | ||
+ | |||
+ | #Install tightvncserver using | ||
+ | |||
+ | sudo apt-get update tightvncserver | ||
+ | |||
+ | #run vncserver :1 on Pi | ||
+ | |||
+ | Choose password: | ||
+ | |||
+ | raspberry | ||
+ | |||
+ | Gives back this answer: | ||
+ | |||
+ | New 'X' desktop is jupiter:1 | ||
+ | Creating default startup script /home/pi/.vnc/xstartup | ||
+ | Starting applications specified in /home/pi/.vnc/xstartup | ||
+ | Log file is /home/pi/.vnc/jupiter:1.log | ||
+ | |||
+ | Download RealVNC [https://www.realvnc.com/download/viewer/ viewer]. | ||
+ | |||
+ | Log in using in this case, use this as username: JUPITER:5901 | ||
+ | |||
+ | ==RFID code== | ||
+ | |||
+ | Sam's code is [http://bit.ly/2bYJXwu here] | ||
+ | |||
+ | =Graphical coding using Node-Red= | ||
+ | |||
+ | [http://nodered.org Node-Red] is installed on the Raspberry Pi (needs to be enabled)<br> | ||
+ | |||
+ | Use [http://JUPITER:1880 this link] to code my device from the web browser | ||
+ | |||
+ | =Excercise= | ||
+ | |||
+ | Try to generate a sound using light signal from photodiode (CLIP) |
Latest revision as of 15:25, 10 September 2016
Intro
Raspberry Pi 3 computer
OS (Raspbian) loaded on SD card
All GPIO pins are flexible 3.3V OUT or IN (will generate floating voltage when not programmed)
GPIO can be programmed using gpio utility: http://wiring.com/the-gpio-utility/
UART pins carry data (RX=receive, TX=transmit), allows connection of devices (GPS), 3V->3V, GND->GDN, RX->TX, TX->RX
Sends text signals, each character encoded in 8bits ("packed" encapsulated into a "start bit" and a "stop bit")
Speed is 9600 Baud (1 Baud = 1 bit per sec)
To access this data, you can either use a Python script, or a software called "screen"
directory "/dev/ttyACM0 9600" contains a new file that represents the connexion to a device (arduino, printer, etc.)
I2C protocol
For example: BMP280 sensor temperature and pressure sensor (4pins=3V, GND, SDA, SCL)
On pi, up to 127 sensors can be connected to the SDA and SCL ports. Each device has a fix-programmed specific address.
i2c-tools is a program that allows to detect from all these sensors using the i2cdetect protocol.
"sudo raspi-config" to configure the pi computer
Step 1. Tell pin to be GPIO2
Step 2. Tell pin to be ON or OFF
2 ways of accessing the pins: GPIO# or pin#
"GPIO-g" flags to GPIO#
First test
Connect to Pi computer using this command in the terminal:
ssh pi@JUPITER
Enter password: raspberry
If we want to connect the LED on the GPIO4 port:
Controlling GPIO ports using Python:
Or using BASH (Shell) command line (UNIX language):
sudo -i
echo "4" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio4/direction
echo "1" > /sys/class/gpio/gpio4/value <-turns it on
echo "0" > /sys/class/gpio/gpio4/value <-turns it off
gpio -g mode 4 out
gpio -g write 4 1 <-turns it on
gpio -g write 4 0 <-turns it off
The Operating System
An OS is a piece of software that people wrote to use a computer in an easy and structured way.
Linus is the kernel (not an operating system), robust, versatile, stable.
Operating system is Raspian in our case.
Linux always has a BASH (Shell) terminal: type something, press enter, view output.
The terminal uses:
arrows
enter key (execute)
tab key (autocomplete)
Everything in Linux is either a FILE or a DIRECTORY
man
stands for manual and gives instructions on how to use commands, eg. "man cat"
pwd
shows the directory we're in
ls
lists all items in this directory
ls -ailh
give the size of all files in the directory
rm -r NAME
remove directory
rm NAME
remove file
mv FILENAME ..
moves file NAME into the upper directory
mv FILENAME DIRECTORY
moves FILENAME into any DIRECTORY
ctrl c
cancels all commands
ctrl l
cleans the screen
sudo -s
login as root
exit
leaves root mode
cat [FILE NAME] | less
-> the pipe character "|" will take the output of one command into the next command
Bash scripting
test1:
nano myfirstscript.txt
#! /bin/bash" echo Hello! echo World! whoami
chmod +x myfirstscript.txt
->makes the file executable -> into some program that you can run
./myfirstscript.txt
-> executes the file
test2:
nano mysecondscript.txt
--
#! /bin/bash echo Hello! echo World! whoami
mkdir woz touch woz/niak.txt
--
chmod +x mysecondscript.txt
./mysecondscript.txt
LEDBlink
#! /bin/bash
tells the terminal the langage of code (Bash here)
while true; do gpio -g write 4 1 sleep 0.5 gpio -g write 4 0 sleep 0.1 done
Makes pin 4 (here a LED) blink forever (while)
Networking
To update anything:
sudo apt-get update NAME
To install anything:
sudo apt-get install NAME
to find IP address of Raspberry Pi (will retrieve the IP address):
hostname -I
To connect to the Pi via wifi
ssh pi@... (IP address)
To get the IP address:
- find a screen with HDMI cable
- plug into Raspberry Pi
- plug mouse in the USB
- use the graphical user interface on the screen
top right corner, wifi signal, select the wifi network, type in password, write down IP address, then can be used to connect
For remote access to the files on the SD from a computer (to edit code for example), download Cyberduck and use SFTP protocol (or any other similar interface).
VNC allows to use the virtual use interface via wifi (without cable and screen).
- Install tightvncserver using
sudo apt-get update tightvncserver
- run vncserver :1 on Pi
Choose password:
raspberry
Gives back this answer:
New 'X' desktop is jupiter:1 Creating default startup script /home/pi/.vnc/xstartup Starting applications specified in /home/pi/.vnc/xstartup Log file is /home/pi/.vnc/jupiter:1.log
Download RealVNC viewer.
Log in using in this case, use this as username: JUPITER:5901
RFID code
Sam's code is here
Graphical coding using Node-Red
Node-Red is installed on the Raspberry Pi (needs to be enabled)
Use this link to code my device from the web browser
Excercise
Try to generate a sound using light signal from photodiode (CLIP)