Booting
A big difference between normal desktop Linux and Raspbian is that the
Pi does ont seem to use GRUB. Things are configured in
/boot/config.txt
. (Which sounds like an improvement!)
What is vcgencmd
? Seems to be a Raspberry Pi specific thing that
does general interaction/configuration to the "VideoCore".
Hardware Problems
If the Pi is restarting repeatedly and/or you see the little yellow lightning bolt icon in the upper right of the display, that generally means its not happy with the power supply. I think the Pi is pretty lax about power but HDMI monitors and USB peripherals may not be. You can (and should) test the voltage by checking pin 1(+5) and 3(GND) for +5VDC; pin 1 is the one closest to the corner of the board, or, looking down on the header with it at the top of the board, 1, 2 (tied to 1 for +5DC BTW), and three are the first left to right 3 on the top (close to edge) row.
If it really doesn’t want to boot even with a good power supply, there may be a real hardware error. Check the pin on the far left second (non-edge) row to see if it has 3.3VDC to the ground shields. If it is 0, then this is bad.
Here is a good troubleshooting list.
WARNING
This makes me think I may have shorted the two pins farthest away from the USB ports on a Pi 3+ turning it into an adorable tiny brick. I would recommend covering the headers with an unconnected jumper block and taping the back. Super annoying!!!
WARNING 2
It also turns out that if you’re thinking of using some GPIO pins to read the state of a switch, you need to be careful. If you are changing configurations of a pin from outputting, say blinking a light, to reading a switch state, then you really should reboot the Pi. At the very least, do some serious software clearing of that GPIO pin so that you do not just short two pins that are getting power, thereby burning out the pin and/or more.
Firmware
You can (and maybe should) update firmware with this.
sudo rpi-update
GPIO Pins
Good detailed information about the GPIO electrical properties.
Note that there are two numbering systems. You must tell your software
which numbering system you’d like to use with the
GPIO.setmode(<mode>)
function. Here mode can be one of these:
-
GPIO.BCM
- As numbered functionally. -
GPIO.BOARD
- As arranged on the board physically.
For example, BCM pin 4 (i.e. GPIO4) is BOARD pin 7 (i.e. 7th physical pin from top left counting by scanning right then next row, etc.).
Switch Detection
How can your software find out what the state of buttons connected to the GPIO are? Here’s an example.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(18,GPIO.IN,pull_up_down=GPIO.PUD_UP) # Normal (open) is high.
while time.sleep(0.2):
if not GPIO.input(18):
print('Voltage dropped low to ground on 18 by switch.')
LED Indications
How can your software control the state of an indicator LED?
LED Polarity
It’s very easy to mess up positive and negative with LEDs so first get the hardware polarities right.
The negative side, the cathode, of the LED is the one with the flat spot on its lens and the shorter lead leg. The anode is the positive side and has the longer lead and round lens shell.
A bonus way to tell is that the anode (+) usually has the more pointy piece of metal inside the lens package, called the "post"; it is usually — but not always — smaller but it will often have a sharp triangular flag bit. The other side inside the lens case is called the "anvil" and if it is somewhat pointy, its entire shape is pointy with no special pointy subregions.
And to really be complete here, when diagramming an LED, there is an in-line triangle pointing to a perpendicular line which is the negative cathode. Don’t forget to distinguish between a regular diode with two arrows coming off the triangle’s top face, toward negative at 45 degrees, for the emitted light.
I have also seen LEDs set in plastic holders with equal length legs — these have a dot on one side which I believe is negative. I think this is consistent with regular diodes which have a single stripe or band on them marking the negative cathode side.
LED Control
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM) # Which pin naming convention to use.
GPIO.setup(16,GPIO.OUT) # Configure pin for output.
GPIO.output(16,GPIO.HIGH) # Energize.
time.sleep(.5)
GPIO.output(16,GPIO.LOW) # Turn off again.
Locale Issues
Raspberry Pi is a British thing but my keyboards are not.
The main place to start for curing such problems is raspi-config
.
Look for "Set up language and regional settings to match your
location."
Default Password
Username: pi
Password: raspberry
To change the autologin behavior of the display manager, try
looking into /etc/lightdm/lightdm.conf
. Also raspi-config
may be
able to change that behavior.
Date And Time
The Pi has no offline battery-powered hardware clock and so when it wakes up, it has no idea what time it is. The normal situation is that it grabs on to the configured network and reaches out to an ntpd server and gets the base time. From there it can actively use its internal clock to accurately keep time.
But what if you don’t have an internet connection yet you want to keep many Pis synchronized? The answer is "orphan mode" in ntp. Here is a description of it and tips for applying it to Pis.
Capslock
Solution described at: http://xed.ch/h/capslock#pi
SSH
The Pi comes with SSH but it is turned off. To turn it on:
sudo raspi-config
Then choose Interfacing Options from the menu. Then enable SSH.
Note that if you’re using the default user (pi) without a password, that probably won’t be sufficient for SSH activity. You’ll need to select "Change user password" in raspi-config. Or better yet, make some proper accounts.
Removing Cruft
The most serious way to get rid of cruft is to just take out the entire GUI. Don’t even let X start up at all.
This is done in the raspi-config
#3 "Boot Options" → "Desktop/CLI".
I like "B2" for auto login console for most no-security work.
Make one of these files to keep bluetooth kernel modules from loading.
blacklist btbcm
blacklist hci_uart
And then disable the bluetooth related service.
sudo systemctl disable bluetooth
sudo systemctl stop bluetooth
Did you know Lennart Poettering had something to do with Avahi? True! So best get rid of it on a Pi.
systemctl disable avahi-daemon
systemctl stop avahi-daemon
Serial Interface
I’m quite at home dealing with computers that are far away. The correct way to do this is generally with SSH (my notes). However, sometimes you need to tinker with a computer when SSH or networking isn’t quite ready. Compound this with maybe having an embedded situation where there is no traditional keyboard and display and it becomes useful to have another way.
While you can rustle up a monitor and a keyboard (like a crash cart in a server room), the Pi actually makes it pretty easy to use another technique that’s just as good for fundamental interaction. There are serial pins that you can connect to using a serial to USB adaptor (e.g. the USB end goes into a laptop whose screen and keyboard you can use).
Serial Baud Speed Limits
One very disappointing limitation I ran into with the Pi Zero was that its ability to read data off a USB serial port was unacceptably slow. I didn’t test this, but here is a link for configuring the Pi UART for high-speed serial communication.
This involves recompiling a kernel but is in theory possible. For some reason the default maximum baud is 187500, probably to comfortably support the normal default 115200; it can actually do 5x faster.
Camera
There are two versions and only V2 works on the Jetson Nano. There is a little black retaining clip on the ribbon cable connector — they can break off. So if it seems like something is missing that could properly hold down the ribbon cable, it probably is.
To enable camera peripherals, go to
sudo raspi-config
Select #5, "Interfacing Options". Then select "P1 Camera" and enable it. It may be essential to reboot the device after setting this.
Here are some official hints on how to use the camera.
Detecting
vcgencmd get_camera
Look for "supported=1 detected=1".
Still
To take a static still image, do something like this.
raspistill -o /tmp/ok2.png
Note that this can take up to 6 seconds. This seems to help.
raspistill -t 100 -o /tmp/ok2.png
Video
The normal command to capture video with the pi camera is raspivid
.
The documentation is mostly
here
and most of the details can be found here
here.
Here is a typical record command.
$ raspivid -n -t 60000 -o pivid-$(date '+%y%m%d%H%M%S').h264
The -n
prevents a preview window. Find other options with --help
(not -h
which is height).
-
-?
,--help
-
-v
,--verbose
-
-w
,--width
- Set image width <size>. -
-h
,--height
- Set image height <size>. -
-t
,--timeout
- Time (in ms) to capture for. Default is 5000, i.e. 5s. 0 for no timeout. -
-fps
,--framerate
- Frame rate.. -
-b
,--bitrate
: Set bit rate. Use bits per second (e.g. 10MBits/s would be -b 10000000). -
-o
,--output
- Output filename <filename> (to write to stdout, use -o -). If not specified, none saved. -
-cs
,--camselect
- Select camera <number>. Default 0. -
‘-p
, `--preview
- Preview window settings <'x,y,w,h’>. -
-f
,--fullscreen
- Full screen preview mode. -
-n
,--nopreview
- Do not display a preview window. -
-vs
,--vstab
- Turn on video stabilisation. -
-rot
,--rotation
- Set image rotation (0-359). -
-set
,--settings
- Show camera settings. Don’t know how to make that just report once. -
-vf
,--vflip
- vertical flip for cameras mounted upside down. -
-hf
,--hflip
- Upside down cameras using-vf
might need to be paired with this to be fully correct. -
-roi
,--roi
- Set region of interest (x,y,w,d as normalised coordinates [0.0-1.0]).
The Pi camera using raspivid
seems to only dump a raw h264 formatted
stream. This is really pretty useless without further post processing.
You can play it with ffplay
and specifying the format.
ffplay -f h264 video.h264
If you want to record a lot of video it could be reasonable to do something like this.
while true; do raspivid -n -t 300000 -o pivid-$(date '+%y%m%d%H%M%S').h264 ; done
Or use a raspivid native option.
raspivid -n -t 0 -sg 300000 -o pivid-$(date '+%y%m%d%H%M%S')-%03d.h264
raspivid -t 0 -vf -sg 3000 -fps 30 -o /tmp/tests%03d.h264
This should record raw 5 minute files which will be timestamped. The
-n
is to prevent a preview window. The -t
time option is in
milliseconds (300,000 ms shown) .
Post Processing
I was able to pack that into a container by doing this.
ffmpeg -f h264 -i video.h264 propervidfile.mp4
I believe this must be done on a different computer. I tried converting a short clip on a Pi Zero and it stumbled to a halt.
That technique re-encoded it. On a 3m30s sample, it took 5 minutes and 34 seconds to convert it. The size was reduced from 349MB to 129MB. To just keep the video as recorded but pack it into a container, this works much more quickly keeping the encoding as is.
ffmpeg -i video.h264 -codec copy proper2.mp4
This only took 7 seconds to convert but kept the full size of the original. This seems like the best way to preserve all data that was captured, especially if you have plenty of storage.
OpenCV On Pi
On Pi Zero from source. Not happening at this time.
Wifi
To enable.
sudo raspi-config
Could be a good time to disable bluetooth too if you won’t be using it. Considerations for choosing the correct radio profile: wifi is 14x faster, 75% of latency — though wifi consumes ~30x power.
You can try setting the network details directly by editing
/etc/wpa_supplicant/wpa_supplicant.conf
.
It needs to have a section that looks like this.
network={
ssid="MyAccessPointName"
psk="ThePassword!"
}
These lines can be generated (along with less public PSK hashes) with
the wpa_passphrase
command.
Also in that file you might want to change the country=GB
to US
if you’re
a US person.
Details and weird cases can be researched here. This may also maybe relevant.
AP Wifi Hotspot
Can two Pis talk without a third "router" host? Should be possible.
Look into hostapd. Here are some good tips describing the process.
RaspAP is some kind of GUI "Wifi Configuration Portal" for managing such things.
GPIO Control
-
total supply maximum of 51mA on all GPIO pins (3.3 and 5v)
-
each 5v pin has maximum of 16mA
Run with ./gpio_ctl 1
to turn on and ./gpio_ctl 0
to turn off.
#!/usr/bin/python import RPi.GPIO as GPIO import sys #GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(23,GPIO.OUT) if sys.argv[1] == "1": print("Turning on pin.") GPIO.setup(23,True) else: print("Turning off pin.") GPIO.setup(23,False)
Jetson Nano
Power
The Jetson Nano lives right on the edge of what is doable in a small form factor. It has different power modes for different applications. If you want to really use the serious machine learning power of the GPU, you’ll have to go above the 10W mode. This is 2A at the Jetson’s 5V. This is all you’re likely to get with a USB power supply. To go bigger you’ll need a much bigger power supply. I bought an Alitove JC0515 75W supply that seems to fit.
Note that, as this guy points out, the barrel jack could fit in any number of devices which may not use 5V. It is strongly recommended to enhance the labeling of this device to avoid any smokey mistakes.
To use this supply, you must first short jumper 48 which is located right behind the barrel jack. It is labeled "ADD JUMPER TO DISABLE USB PWR" so keep that in mind if you’re switching back.
This little beast gets quite hot and I bought this Noctua NF-A4x20 5V PWM fan. I didn’t use their inappropriate mounting hardware but just used micro zip ties and it seems fine. Very quiet.
Setup
Here’s a decently clear outline of a strategy that uses conda. Not sure if this would work but noting it.
Adrian seems to have a good process worked out. I’m already running into trouble with versions and details that have changed since I first tried this a couple of days ago. Most of my procedure is based on this.
First thing to do is to turn off all Idiot-Ubuntu screensavers. Make
sure you find the thing that locks you out if the screensaver triggers
and kill that. This installation can take an absurdly long time and
coming back to a machine that is too bogged down to let you log back
in is a strong possibility. I even like to have an htop (_ apt
install htop
) running where I can see it so I can know that the
process hasn’t just locked up.
$ sudo apt install git cmake libatlas-base-dev gfortran libhdf5-serial-dev hdf5-tools python3-dev
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python3 get-pip.py
$ rm get-pip.py # Optionally
$ sudo pip install virtualenv virtualenvwrapper
I don’t know where /home/dev/.cache/pip
got owned by root:root, but
this might be a good time to fix that stupid situation — use -R
.
There’s also a pip --no-cache-dir
FWIW.
Add this to ~/.bashrc
.
# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
Resource shell environment and continue in this environment. Less sudo now.
$ . ~/.bashrc
$ mkvirtualenv deep_learning -p python3
$ pip install numpy
Things get dodgy here. I used this to go off piste with a slight variant of Adrian’s procedure that actually worked.
$ pip3 install --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v42 tensorflow-gpu==1.13.1+nv19.4
$ pip install scipy
$ pip install keras
$ git clone https://github.com/dusty-nv/jetson-inference
$ cd jetson-inference
$ git submodule update --init
$ mkdir build
$ cd build
$ cmake .. # Wait for credentials..
$ make
$ sudo make install