Raspberry_PI_Cookbook
Screensavers
feh is an image displayer/slide_show'er
sudo apt-get install feh
show pics in this folder
feh -FD5 /home/pi/Pictures
show pics in this folder
feh -FD5 /home/pi/Pictures
or this one below
sudo apt-get install xscreensaver
Then find it under start menu preferencessudo apt-get install xscreensaver xscreensaver-data-extra xscreensaver-gl-extra
curl "http://sitecdn.wthr.com/weather/Web_7dy.JPG" -o test.jpg
screenshots? use scrot or ...
sudo apt install gnome-screenshotMenu > Accessories > ScreenshotWhere dev is my USB?
pi@raspberrypi:/dev $ mount | grep sda/dev/sda1 on /media/pi/ESD-USB type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2)
also lsusb may be a useful command
Burn ISO to usb
sudo dd if=/path/to/my.ISO of=/dev/sd1 bs=4M status=progress; sync
for example
sudo dd if=
/home/pi/Downloads
/
ubuntu-18.04-desktop-amd64.iso
of=/dev/sd
1
bs=4M status=progress; sync
Models:
Pi B+’s Broadcom BCM2835 ARMv6 system on 700MHz single core chip.Pi 2 Model B quad-core 900MHz Broadcom BCM2836 ARM v7 processor,
Pi 2 runs on the same systems as the Model B+,
so everything you have for the Model B+, and older Pi boards,
will work without issue on the Pi 2.
You can now push 1.2 Amp to the Pi 2’s 4 USB 2.0 ports
so you can connect power-hungry devices.
requiring 2 Amp Micro USB power supply
(instead of usual 1.8A 5V USB B power source)
Nice GUI-web-based GPIO image/interface
http://thethingbox.io/#packagestable
Robots
http://www.dexterindustries.
Power
http://www.amazon.com/MiTab-
Very high quality 800 ma charger
Input: 12-24VDC, the devise will plug perfectly into your car with full connnectivity to your cable and device
Output: DC 5V
Browser
Chrome
sudo apt-get install chromium
FireFox
sudo apt-get install iceWeezel
(fxos is a mozilla os for the pi)
Initial setup
install/copy noobs zip contents to micro sd card
insert card, connect power, keyboard, display, and boot
set password
startx
setup wifi (if wifi usb dongle inserted) via gui
sudo apt-get update
sudo passwd root ...set the su (super user password)
...or boot behavior can autostart the startx gui
---------------------------
auto login as pi user.
sudo nano /etc/inittab
#comment out getty:
#1:2345:respawn:/sbin/getty 115200 tty1
Add login program w/pi user (w/o authentication):
1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1
Reboot pi
auto run a script
sudo nano /etc/profile, add:
. /home/pi/your_script.sh
Auto Start the Desktop (LXDE)
sudo raspi-config -> Enable Boot to Desktop/Scratch from the menu and press Enter
Select Desktop Login as user pi at the Graphical Desktop.
advanced split mem gpu to128
add to /etc/profile
alias f='sudo find / -type f | grep'
sudo apt-get install putty
putty -serial /dev/ttyACM0 ...connect to USB connected arduino
install scrot screenshot utility
$ sudo apt-get install scrot
$ sudo scrot ...stores timestamp.png in curdir
$ sudo scrot -d10 ...screenshot after 10-second delay
$ sudo scrot -h ...help
Install eclipse
sudo apt-get install eclipse
remote desktop
sudo passwd root ...set the su (super user password)
Tweak/Customize System
sudo raspi-config (allows overclocking, etc)...or boot behavior can autostart the startx gui
---------------------------
auto login as pi user.
sudo nano /etc/inittab
#comment out getty:
#1:2345:respawn:/sbin/getty 115200 tty1
Add login program w/pi user (w/o authentication):
1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1
Reboot pi
auto run a script
sudo nano /etc/profile, add:
. /home/pi/your_script.sh
Auto Start the Desktop (LXDE)
sudo raspi-config -> Enable Boot to Desktop/Scratch from the menu and press Enter
Select Desktop Login as user pi at the Graphical Desktop.
advanced split mem gpu to128
add to /etc/profile
alias f='sudo find / -type f | grep'
sudo apt-get install putty
putty -serial /dev/ttyACM0 ...connect to USB connected arduino
Screenshots and paint
sudo apt-get install kolourpaint4 ...tons of dependency pkgs :-(install scrot screenshot utility
$ sudo apt-get install scrot
$ sudo scrot ...stores timestamp.png in curdir
$ sudo scrot -d10 ...screenshot after 10-second delay
$ sudo scrot -h ...help
setup printing?
sudo apt-get install cups
sudo usermod -a -G lpadmin pi
http://127.0.0.1:631
Install eclipse
sudo apt-get install eclipse
upgrade java
sudo apt-get update && \ sudo apt-get install oracle-java7-jdk
sudo nana ~/.profile
export PATH=/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/bin:$PATH
also export JAVA_HOME=... in /etc/profile
update the sudo version of java also
root@raspi1:~# sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-6-openjdk-armhf/jre/bin/java 1057 auto mode
1 /usr/lib/jvm/java-6-openjdk-armhf/jre/bin/java 1057 manual mode
2 /usr/lib/jvm/jdk-7-oracle-armhf/jre/bin/java 317 manual mode
3 /usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/jre/bin/java 318 manual mode
Press enter to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/jre/bin/java to provide /usr/bin/java (java) in manual mode
root@raspi1:~# sudo java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) Client VM (build 25.0-b70, mixed mode)
pi@raspi1 ~/workspace/test/bin2 $ sudo java -classpath .:/opt/pi4j/lib/'*' test.GPIO1
RDCsudo apt-get install Remminaremote desktop
Aruduino (includes sketch IDE)
sudo apt-get install arduino ...and arduino-core
USB webcam
sudo apt-get install fswebcam
capture an image
fswebcam image.jpg
sudo apt-get install motion
sudo nano /etc/motion/motion.conf
Daemon = OFF to ON
webcam_localhost = ON to OFF
sudo nano /etc/default/motion
“start_motion_daemon=no” to “yes”
ctrl-W searches (like notepad ctrl-F find)
sudo service motion start
http://192.168.0.100:8081
Keyboard to US
sudo nano /etc/default/keyboard
XKBLAYOUT=”gb”
Change the gb (which is great brittain uk) to us
tomcat7 webserver
sudo apt-get install tomcat7
server.xml and configs here /var/lib/tomcat7
logs to here /var/logs/tomcat7 ...see cataline to ensure port is happy
tomcat7 webserver
sudo apt-get install tomcat7
server.xml and configs here /var/lib/tomcat7
logs to here /var/logs/tomcat7 ...see cataline to ensure port is happy
find files...
sudo find / -type f | grep tomcat7 | grep log
install deb debian files
sudo dpkg -i debfile
GPIO
Gen purpose I/O ports (26 pins on end of card. numbered left to right)Connect breadboards w/Jumper Wires! Start simple, blink and LED!
7 types (broadcom numbers don't match pi port numbers)
- power src
- ground
- dnc - reserved do not connect
- gpio7 on/off switch (high/low signal)
- I2C SDA and SCL
- TX
- RX
- SP10 CE0 & CE1 n
7 general
1 pwm pulse wave control speed, etc
2 I2C --slow but multiple peripherals
5 SPI Serial Peripheral Interface bus for synchronous comms (to/fro microcontrollers, sensors shift registers, etc...)
2 UART --standard/conventional serial
CMOS 3.3V
MAX232 convert between 5 and 3
digital 0=0v 1=3.3v (2+ allo comm protocol)
analog 0v=0 3.3v=1023
pwm control power/speed
Free Video Classes
http://blog.globalcode.com.br/2014/03/oracle-internet-of-things-developer.html
We are proud to announce the IoT Developer Challenge sponsored by Oracle Technology Network and organized by Globalcode.IoT Developer Challenge is your big chance to develop a criative IoT solution with Java SE Embedded or Java ME Embedded Platform and your preffered board, like Raspberry Pi, Beagle Bone Black, Gemalto Concept Board and many other!
Put your creativity to work, improve your knowledge with free webnars, video-classes, technical blog, download and also forum support. The prize is a Java Developer Dream: JavaOne pass + flight + hotel!
cd /sys/class/gpio ...gets into virtual/temp file system
============================================================
output on/off
echo 4 > export ...opens port 4 n creates gpio4 dir w/direction + value
echo out > gpio4/direction ...output mode
echo 1 > gpio4/value ...turn on pin 3.3v
... or in a single command ....
echo high > gpio4/direction'
echo 0 > gpio4/value ...turn off
echo 4 > unexport ...close port n del gpio4 dir
=============================================================
input - setting/reading interrupts via edge file (none, falling, rising, or both)
echo 0 > /sys/class/gpio/gpio4/value
echo in > /sys/class/gpio/gpio4/direction
echo falling > /sys/class/gpio/gpio4/edge
cat gpio4/value in some code elsewhere
setup for both reading and writing so high == 0 and low == 1
echo 1 > gpio4/active_low ...revert write 0
============================================
simple bash script
#!/bin/bash
cd /sys/class/gpio
echo “Opening port” 4
echo 4 > export
echo “And making it an output”
echo out > gpio4/direction
for I in {1..5}
do
echo “Setting value to 1”
echo 1 > gpio4/value
sleep 1
echo “Setting value to 0”
echo 0 > gpio4/value
sleep 1
done
echo “Closing port” 4
echo 4 > unexport
cd /home/pi
Save as ledcheck and Make executable, run as root
$ sudo su
# chmod +x ledcheck
# ./ledcheck
============================================
non root permissions
By default, only root can export and unexport files and write to the gpio pin files.
The linux device manager called udev provides rules controling permissions on device files it creates.
/sys/class/gpio are owned by user root and group root. Only root user has read/write permissions.
Soooo created udev rule file /etc/udev/rules.d allowing group 'gpio':
KERNEL=="gpio*", SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="/usr/local/bin/hipi-expin gpio /sys%p"
The KERNEL, SUBSYSTEM and ACTION settings define 'matches' that udev should check
to determine which device driver and action the rule applies to
while the PROGRAM setting provides the path of a program that should be run.
The Perl script /usr/local/bin/hipi-expin receives the group name
and file paths the device driver has created.
The script changes the group of the files to the group passed in ( gpio )
and changes the permissions mode of the files to 0660
With this rule users that are members of the gpio group
will be able to read and write from the gpio device files.
Install software to use/drive the GPIO pins
sudo mkdir gpiogethub quick2wire
or python lib rpi.goui-02.tar.gz
winscp to copy to ur new dir
sudo tar -zxvf rpi.goui-02.tar.gz
sudo python setup.py install
write blink.py script!
from time import sleepimport RPi.GPIO as GPIO
GPIO.setup(13, GPIO.OUT)
while 1:
GPIO.output(13, False)
sleep(1)
if GPIO.input(11):
GPIO.output(13, False)
else:
GPIO.output(13, True)
Run script:
sudo python blink.py
GPIO via webbrowser/python
wget http://webiopio.googlecode.com/files/WebIOPi.tar.gztar -zxvf WebIOPi.tar.gz
cd WebIOPi
sudo ./setup.sh
sudo python -m webiopi
http://localhost:8000/webiopi
webiopi raspberrry
GPIO cmd-line control "wiring pi"
installsudo app-get install gitcore
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
usage (blink LED on port 4)
port for designated for writing/output
sudo gpio -g mode 4 output
turn it on
sudo gpio -g write 4 1
turn it off
sudo gpio -g write 4 0
GPIO browser control
download webiopiuncompress
sudo ./setup.sh
sudo /etc/init.d/webiopi start
Java GPIO
Pi for Java! (http://pi4j.com)GPIO java API via pi4J java lib
curl -s get.pi4j.com | sudo bash
get the pi4j-core.jar
This installs Pi4J libraries and example source files to:
/opt/pi4j/lib
/opt/pi4j/examples
compile/run ...include Pi4J lib dir:
javac -d . g1.java -classpath .:/opt/pi4j/lib/'*' sudo java -classpath .:/opt/pi4j/lib/'*' g1
compile examples:
/opt/pi4j/examples/build
u gotta map virtual pin numbers to pins/ports
GpioPinDitigalOutput myLED=new GpioPinDitigalOutput(1)
GpiController ctl=GpioFactory.getInstance();
myLed=gpio.provisionDigitalOutputPin(RaspiPin.GPIO_07)
myLED.setState(true);
sudo java -jar myJar.jar
Dockery Example (blink)
package test;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;
/**
* perform simple state control of a GPIO pin on the Raspberry Pi.
*/
class GPIO1 {
public static void main(String[] args) throws InterruptedException {
System.out.println("<--Pi4J--> GPIO Control Example ... started.");
final GpioController gpio = GpioFactory.getInstance(); //create gpio controller
System.out.println("got controller.");
// provision gpio pin as an output pin and turn on
final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_07, "MyLED", PinState.HIGH);
System.out.println("Got pin."); //GPIO_7 is actually GPIO4 7 is the pin#
System.out.println("--> GPIO state should be: ON");
Thread.sleep(5000);
pin.low(); //turn off
System.out.println("--> GPIO state should be: OFF");
Thread.sleep(5000);
pin.toggle(); //toggle should turn pin on
System.out.println("--> GPIO state should be: ON");
Thread.sleep(5000);
pin.toggle(); //toggle again should be off
System.out.println("--> GPIO state should be: OFF");
Thread.sleep(5000);
System.out.println("--> GPIO state should be: ON for only 1 second then off");
pin.pulse(1000, true); // 'true' use a blocking call
pin.high(); //turn on
// stop all GPIO activity/threads by shutting down the GPIO controller
// (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
gpio.shutdown();
}
}
Another example the Pi4J java Lib:
//config/init GPIO Pins as input or outputGpioController gpio = GpioFactory.getInstance();
GpioPinDigitalOutput led = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_06); //Pin6 LED out
GpioPinDigitalInput sensor = gpio.provisionDigitalInputPin(RaspiPin.GPIO_01, PinPullResistance.PULL_DOWN); //Pin1 input from photoconductive cell
//Event Handling - When pin state changes
//inputs current state via event.getState()
//outputs set via led.low() or high()
sensor.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(final GpioPinDigitalStateChangeEvent event) {
handleSensorInput(led, event);
}
private void handleSensorInput(final GpioPinDigitalOutput led, final GpioPinDigitalStateChangeEvent event) {
if (event.getState().isLow()) {
notifyLightsOff(led);
} else {
notifyLightsOn(led);
}
}
private void notifyLightsOn(final GpioPinDigitalOutput led) {led.low();}
private void notifyLightsOff(final GpioPinDigitalOutput led) {led.high();}
//wait until user exits app
gpio.shutdown();
Java
All future Raspbian images will ship with Oracle Java by default!!Existing users can install it by typing:
sudo apt-get update && sudo apt-get install oracle-java7-jdk
Thanks to Oracle for their hard work in making this possible!
The VM would/should also allow
dev in ruby, scala, groovy, php and perhaps JavaFx. I believe the
lightweight/fast WAS (websphere app svr) liberty profile has been run on the
pi. (I am a several years away from WAS, but it is a minimal servlet
container, which you can simply addin/plugin more features as needed).
JavaFX2 with JDK7u6 or JDK8!
Piget JDK1.8 for ARM, install in opt dir
sudo tar jdk-8.tar.gz -C /opt
/opt/jdk1.8/bin/java -version
sudo nano /etc/profile
export JAVA_HOME=/opt/jdk1.8
or in my case this i think
export JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt
PATH=/opt/jdk1.8/bin:$PATH
sudo reboot
/opt/jdk1.8/bin/java -version
JavaFX support!
sudo nano /boot/config.txt
framebuffer_width=1280
framebuffer_width=720
sudo raspi-config
overclock to 900MHZ for better perf
advanced a3 split mem 128
netbeans transfer/run sample javaFX desktop app to pi!
xWindows
MobaXterm 6.5 Personal/Free edition xWindows gui works on the pi!http://mobaxterm.mobatek.net/download-home-edition.html
After install on pc enter
Remote I/P of pi
Advanced SSH tab-> Remote Env Select LXDE (light weight X11 DeskEnv)
SSH
sudo mv /boot/boot_enable_ssh.rc /boot/boot.rc
LCD screen
yes a small one which can play videos go for $30, and sit directly on top!Microphone
Pi has on-board basic audio jack,for sound effects/speech via PWM output (w/minimal filtering)
This USB audio card/adapter improves sound quality and volume.
http://www.adafruit.com/product/1475
or use another USB mic
Arduino
The Arduino IDE is available for the Raspberry Pi (most newer Arduino cards):
$ sudo apt-get update $ sudo apt-get install arduino
The Arduino IDE connects to the Raspberry Pi through its USB cable to program it.(you may need to disable the console port).
Connect Arduino to Pi. (Tools menu, select Board - Arduino Uno. -> Serial Port:dev/ttyACM0.
Upload test LED blink program (File -> “Examples, Basic,” click Blink, click toolbar right-arrow to compile/upload). You may need to sudo reboot to see the serial port.
FTP
yes, you could use fileZilla as a client.Yes, simple camara can be controlled to take pics and store file
Using Java Micro Edition (cldc/meep)
with the Device IO API and Configuration API
http://docs.oracle.com/javame/8.0/api/dio/api/index.html
public class GPIOPinTest implements PinListener, AutoCloseable {
//friendly Port names
int LED1_ID=1;
int Button_Pin=0;
GPIOPin led1;
GPIOPin button1;
public void start() throws IOException {
led1 = DeviceManager.open(LED1_ID); // Open the LED pin (Output)
// button trigger on a rising edge (from low to high)
GPIOPinConfig config1 = new GPIOPinConfig(DeviceConfig.DEFAULT,
Button_Pin,
GPIOPinConfig.DIR_INPUT_ONLY,
DeviceConfig.DEFAULT,
GPIOPinConfig.TRIGGER_RISING_EDGE,
false);
button1 = DeviceManager.open(config1); // Open the BUTTON pin (Input)
button1.setInputListener(this); // this class as pin listener to the buttons
// TEST-Turn LED on 1 sec then off
led1.setValue(true);
try {Thread.sleep(1000);}catch(InterruptedException ex) {}
led1.setValue(false);
}
@Override
public void close() { //close resources
try {
if (led1 != null) {
led1.setValue(false);
led1.close();
}
if (button1 != null) {
button1.close();
}
} catch (IOException ex) {
System.out.println("Exception closing resources: " + ex);
}
}
@Override //state of the input pin changes.
//the button config invokes when button changes state from low to high (rising trigger).
public void valueChanged(PinEvent event) {
// Simple one button = one LED
try {
System.out.println("setting led1");
led1.setValue(!led1.getValue()); // Toggle the value of the led
} catch (IOException ex) {
System.out.println("IOException: " + ex);
}
}
A standard Java GPIO example
http://docs.oracle.com/javame/8.0/me-dev-guide/gpio.htm
Other Programmable cards
http://www.espruino.com/https://tessel.io/
http://www.structure.io/
login/startup script options:
2 solutions for 2 very different things:Add something to /etc/rc.local to execute every time Pi is booted (adds to boot "sequence")
Add something to ~/.bashrc to execute every time a specific user logs in.
.bash_profile is for login shells (runs upon login)
.bashrc is for non login shells (upon opening terminal windows)
It depends if you want cmd executed before or after the user enters username/password
On Pi, they are often the same (only 1 user)
Pi may have /boot/boot.rc (on the FAT partition) which performs the same function as /etc/rc.local.
but is safer because you can edit this partition from any computer.
------------------------------------------------------
start myScript upon Pi boot:
1) sudo vi /etc/inittab YMMV
2) find:
1:2345:respawn:/sbin/getty 115200 tty1
3) replace it with
1:2345:respawn:/bin/login -f USERNAME tty1 </dev/tty1 >/dev/tty1 2>&1
(where username =your login username)
...which autologin's on tty1 [the 1st terminal]
then edit .bashrc on that user
and right at the end put something like :-
if [ $(tty) == /dev/tty1 ]; then
./myScript
fi
Comments
Post a Comment