GithubHelp home page GithubHelp logo

learning-raspi's Introduction

Learning-Raspi

Learning electronic and programming with Raspberry Pi

Raspberry setup

The easiest way to run with raspberry is installing NOOBS in a FAT32 SD. Other OS like Ubuntu Mate, Raspbian, or Chromium are valid too. PD: At present, all OS are 32 bits.

First step must be change default password, for security reasons, like ssh access. Use “sudo passwd” command. Username: pi Password: raspberry

Later, update the system:
sudo apt-get update
sudo apt-get upgrade

If raspbian freezes, disconnect usbs and HDMi can help. Disconnect supply could corrupt system files. Use ctrl+alt+f1 to switch to kernel, and use sudo reboot. To return to GUI, use ctrl+alt+f7.

For Arduino installation:
sudo apt-get install arduino

For Opencv installation:

`sudo apt-get install libhdf5-dev libhdf5-serial-dev`  
`sudo apt-get install libqtwebkit4 libqt4-test`   
`sudo pip install opencv-contrib-python`   

GPIO control

With GPIO pins, two different numerations can be used: BOARD (with the numerical position for each pin), and BCM, the special numeration of broadcom. But this last form is not the same for every raspberry model.

When program finish, using a keyboard interruption or execution ends, ports used to remain in their last state, and that can be problem. These lines cleans all ports used before. Because of that, don’t use it at the beginning.

`def main():`  
    `while True:`  
        `...`
`if __name__ == '__main__':`  
    `try:`
        `main()`  
    `except KeyboardInterrupt:`  
        `...`  
    `finally:`  
        `GPIO.cleanup()`  

Run programs at startup

Run a script with rc.local or cron.

sudo nano /etc/rc.local

At the end of the file, but before the exit 0, put the command that must be run during start, with absolute paths: python3 /home/pi/example.py &

If the command runs continuously or is likely not to exit, you must be sure to fork the process by adding an ampersand to the end of the command, &. Otherwise, the script will not end and the Pi will not boot. The ampersand allows the command to run in a separate process and continue booting with the process running.

First, enable ssh access on Interfaces.
Obtain the Raspberry IP, or make it static:
hostname -I
Access throught PC terminal with ssh:
ssh pi@<IP>
If you want to use GUI programs:
ssh -Y pi@<IP>
Now you can, for example:
idle3 &

For file transfer between machines, use scp:
scp "name with spaces.txt" pi@<IP>:

With VNC, Don’t use :1 when raspberry uses desktop interface, it will appear a grey screen. Use :2.

Watchdog config

SD cards tend to get corrupted easily, for problems with supply during writing commands. Because of that, use the raspberry in read-only mode. The script includes a reboot for kernel panics, but these are not the only problems that can freeze the raspi. Because of that, activate the watchdog. The timer limit is 15 s.

modprobe bcm2835_wdt
echo "bcm2835_wdt" | sudo tee -a /etc/modules

apt-get install watchdog
update-rc.d watchdog defaults

nano /etc/watchdog.conf

Uncomment:

#watchdog-device
#max-load-1

Add:

watchdog-timeout = 15

Save, reboot, test by command:

:(){ :|:& };:

Read only mode config

Temporary files are stored in RAM rather than on the SD card. Optionally, you can use a jumper or switch to boot the system into normal read/write mode to install new software or data. And, as normal, you still have easy access to the /boot partition if the SD card is mounted on another computer.

  • This does not work with the X11 desktop / PIXEL. It's strictly for Raspbian Lite right now. Graphical applications are still possible using SDL, Pygame and so forth, just not X11 at the moment.
  • Setting up read-only mode should be the very last step before deploying a project. THIS SEQUENCE IS IRREVERSIBLE. There is no uninstall script. There’s an option to boot into read/write mode, but nothing to back out all these changes.And back up the contents of your SD card first.

Install and Run

Pi should be booted and on the network… like mentioned above, everything already configured and fully functional (and backed up) before taking this step.

From a command line prompt:
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/read-only-fs.sh
sudo bash read-only-fs.sh

The script will repeat all these stern warnings and make you verify at several steps whether to continue. Along the way you’ll be presented with a few options:

Enable boot-time read/write jumper? [y/N]

This gives you the option to run the system in read/write mode by inserting a jumper across two pins. If you answer yes to this question, you’ll also be asked for a GPIO pin number. When there’s a jumper between this pin and ground, the system will boot into read/write mode and you can make changes (but remember to do a proper shutdown). Make sure the pin isn’t used by anything else. GPIO21 is easy to remember because it’s right at the end of the header. If you’re using I2S audio though, that requires GPIO21 for its own use, so you’ll want to pick another.

Install GPIO-halt utility? [y/N]

This installs a utility that initiates a proper shutdown when another GPIO pin is touched to ground. For a read-only system, you probably don’t need this… but if you have the system booted in read/write mode, this provides an option if you can’t log in and run a manual shutdown. This likewise will ask for a GPIO pin number like GPIO16.

You’re Not Finished Yet. Test the modified system to make sure that the system boots and your application runs as intended. Try a pass with the read/write jumper and/or the gpio-halt button, if you’ve enabled either of those options.

3G dongle configuration

First we have to increase max output current through USBs to avoid hubs like in the picture.

Add the following line to the bottom of /boot/config.txt
max_usb_current=1

Now install usb mode switch to change the dongle function
apt-get install usb-modeswitch usb-modeswitch-data

Create /etc/udev/rules.d/70-usb-modeswitch.rules with the following content:
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1f01", RUN+="/usr/sbin/usb_modeswitch -v 0x12d1 -p 0x1f01 -V 0x12d1 -P 0x1405 -J"

This line is for Huawei E3372 and E3531 models. Others dongle may need different IDs. Now then raspi should detects a eth connection.

  • lsusb before udev rule:
    root@raspberrypi:~# lsusb
    Bus 001 Device 003: ID 12d1:1f01 Huawei Technologies Co., Ltd.
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

  • lsusb after udev rule:
    root@raspberrypi:~# lsusb
    Bus 001 Device 003: ID 12d1:14dc Huawei Technologies Co., Ltd.
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

To avoid wifi connections during boot, we have to set down the wlan, editing rc.local:
sudo nano /etc/rc.local
sudo ifconfig wlan0 down

Code examples

Cool projects TODO

References

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.