Installing Jessie

Kamino base

This is my routine for getting a fresh Jessie installation up and running. It includes a section on how to install the Arduino IDE as well.  Originally used the 9-24-2015 image of Jessie, it has now been updated for the 3-18-2016 version and I am using a Raspberry Pi 3.  Since this is a set of tasks I run on all of my RPis, I have an image with all of these changes already in place so I can rapidly generate a “fresh” install.  If you don’t know why I refer to this image as Kamino base, you need to freshen up on your Star Wars factoids.

First, follow the installation guide for downloading and installing the disk image.  I use Win32 Disk Imager on a Windows 10 computer to do this part.

On initial boot, the Pi starts X.  Press F2 and type lxterminal to get the terminal.

raspi-config

The first step is to do some basic system configuration using raspi-config.  Type sudo raspi-config  in the terminal.  I use the following order:

  • Expand filesystem
  • Set boot options (only if you don’t want to boot to X)
  • Set Internationalization options
    • Here you should update the keyboard, timezone, local and wifi internationalization (which is a recent addition to raspi-config).
    • Reboot now to ensure these changes are in effect, then go back to raspi-config
  • Set password
  • Set hostname
  • Enable SSH
  • Set Serial to no (if setting up Arduino, for example)
  • Set overclock if desired (No overclocking on the RPi3)

Set up wireless

Your experience may be different here.  I have had some recent problems with a set of WiFi adapters using the Realtek chipset and I am pretty sure, although not certain, that the problem is the hardware.  

Assuming the RPi has an Edimax WiFi adapter, turn off power management by creating a file /etc/modprobe.d/8192cu.conf with the following text:

# Disable power management

options 8192cu rtw_power_mgnt=0 rtw_enusbss=0

 

It is best to check if the wifi applet in X works for you, as it requires no effort.  If you are on the command line, then sudo iwlist wlan0 scan  will find available WiFi networks.  Then edit “/etc/wpa_supplicant/wpa_supplicant.conf” to include the appropriate SSID and psk information

network={ ssid=" " psk=" " }

On some of my RPis I need to explicitly load the WiFi module by adding 8192cu to the end of /etc/modules.  I’m not really sure why this would be the case (or if it is even true at this time).

Reboot.

Packages to install

This is a set of packages that I use frequently enough to have on a base system.  Before installing packages, it is always good to start with sudo apt-get update && sudo apt-get upgrade.

Always

Helpful

  • These are no longer necessary now that raspi-config takes care of the problem.
    • wireless-regdb
    • iw crda *deals with the CRDA problem*
  • wicd wicd-curses *console programs for network configurations*
  • mysql-client mysql-server
  • minicom
  • x11vnc
    • update I now use these instructions for setting up x11vnc to run automatically.  If truly headless (I have one Pi connected to a monitor, so I haven’t altered config.txt for that one) I refer to eLinux.org for the correct/desired HDMI modes.
      • Summary of this process:
        • Add x11vnc -bg -nevershared -forever -tightfilexfer -usepw -display :0  to “~/.xsessrionrc”
        • Execute chmod 775 ~/.xsessionrc
        • Modify “/boot/config.txt” by setting hdmi_force_hotplug=1 and setting the mode parameters (hdmi_group and hdmi_mode) to the appropriate values.
    • I prefer over other vnc servers as it allows you to control the same X session currently running on the RPi.  See this forum for some configuration options that I have not yet tried.
    • If running headless, then starting x11vnc may give a very low resolution screen by default.  I used this post to fix the issue, which involves setting hdmi_group=2 and hdmi_mode=35 in /boot/config.txt.
    • I’m starting to like xfce4 which benefits from xcompmgr

Minicom config

I use minicom to talk to AMA0 and that requires:

sudo adduser pi tty

Create file /etc/minicom/minirc.ama0:

# Machine-generated file - use "minicom -s" to change parameters.
pu port /dev/ttyAMA0
pu baudrate 9600
pu bits 8
pu parity N
pu stopbits 1
pu minit
pu mreset
pu rtscts No

Also remember that for simple operations echo -n " " > /dev/ttyAMA0 works as well.

Grab custom config files

git clone https://github.com/bobthechemist/dotfiles
cp dotfiles/.* .
sudo rm -r dotfiles

This is the end of Kamino base.  Below are additions I make to RPis that will be used for physical computing (which is many, but not all of them).

Arduino

It looks like there is some decent activity on maintaining a 1.6.5 version that works on the RPi. These instructions install that version.

wget https://github.com/arduino/Arduino/archive/1.6.5.tar.gz
tar xf 1.6.5.tar.gz cd Arduino-1.6.5
git clone https://github.com/ShorTie8/Arduino_IDE
ln -s Arduino_IDE/debian debian
dpkg-buildpackage -uc -b -tc
cd ..
dpkg -i arduino-core_1.6.5_all.deb arduino_1.6.5_all.deb

There will be many unmet dependencies, and the dpkg-buildpackage command will highlight them. Add them with:

sudo apt-get install debhelper javahelper default-jdk default-jre libastylej-jni libjssc-java libjna-java libjsch-java libjmdns-java libcommons-logging-java libcommons-httpclient-java libcommons-exec-java ant astyle extra-xdg-menus avr-libc avrdude gcc-avr bossa-cli gcc-arm-none-eabi

The dpkg-buildpackage command takes a while. Once completed, arduino should work. Set up a ATMega328p for testing. At this point, gpio programming still needs to be set up. Need the patched version of avrdude, first remove the currently installed one and replace it with the one from drogon

wget http://project-downloads.drogon.net/gertboard/avrdude_5.10-4_armhf.deb
sudo dpkg -i avrdude-doc_5.10-4_all.deb avrdude_5.10-4_armhf.deb
sudo chmod 4755 /usr/bin/avrdude

Sub section below may not be necessary, since I’m not interested in the IDE

 


Configuring IDE

Now configure the gpio programmer by adding the following two lines to /usr/share/arduino/hardware/arduino/avr/programmers.txt (I’d like to find out if this can go into a user-owned directory; [edit] looks like I can put something in ~/Arduino/hardware/dirname/avr/{programmers,boards}.txte)

gpio.name=Raspberry Pi GPIO >gpio.protocol=gpio

(* May not be terribly interested in getting the IDE to work better, as it appears to crash over SSH, and it’s slow anyway *)


 

Get Arduino-Makefile and place it in an accessible directory. Create a simple makefile in the sketch directory containing variables with location of Arduino, this makefile and a command to actually include the makefile.

ARDUINO_DIR=/usr/share/arduino ARDMK_DIR=/home/pi/Arduino-Makefile
AVR_TOOLS_DIR=/usr
BOARD_TAG=uno
ARDUINO_PORT=/dev/ttyAMA0
ARDUINO_LIBS=
#Need to specify location of avrdude.conf
AVRDUDE_CONF=/etc/avrdude.conf
include $(ARDMK_DIR)/Arduino.mk

Configuring bare ATMega328

Right now, I don’t know of any method other than to modify /usr/share/arduino/hardware/arduino/avr/boards.txt

bare.name=Bare ATMega328p
bare.upload.tool=avrdude
bare.upload.protocol=gpio
bare.upload.maximum_size=32256
bare.upload.maximum_data_size=2048
bare.upload.speed=115200
bare.bootloader.tool=avrdude
bare.bootloader.low_fuses=0xE2
bare.bootloader.high_fuses=0xD9
bare.bootloader.extended_fuses=0xFF
bare.bootloader.unlock_bits=0x3F
bare.bootloader.lock_bits=0x0F
bare.bootloader.file=optiboot/optiboot_atmega328.hex
bare.build.mcu=atmega328p
bare.build.f_cpu=8000000L
bare.build.board=AVR_BARE
bare.build.core=arduino
bare.build.variant=standard

At this point, the ATMega328p can be programmed. To get make upload to work reliably, I had to force flash erase (no -D flag in avrdude) which was hardcoded into Arduino.mk around line 1313. Search for BTC to find comments to my changes. A serial monitor can be created using minicom ama0 As far as I can tell, programming the ATMega328p is complete.

Configuring the ATTiny85

First get the files from github:

#In a temporary directory
wget https://github.com/damellis/attiny/archive/ide-1.6.x.zip
uncompress ide-1.6.x.zip cd attiny-ide-1.6.x
#Create the hardware subdirectory if you haven't already
mv attiny ~/Arduino/hardware

The makefile requires a few extra components: first indicate that an alternate core is being used, then add the sub tag and specify the CPU frequency.

ARDUINO_DIR=/usr/share/arduino
ARDMK_DIR=/home/pi/Arduino-Makefile
AVR_TOOLS_DIR=/usr
ALTERNATE_CORE = attiny
BOARD_TAG=attiny
BOARD_SUB=attiny85
F_CPU=8000000L
ARDUINO_PORT=/dev/ttyAMA0
ARDUINO_LIBS=
#Override location of avrdude.conf
AVRDUDE_CONF=/etc/avrdude.conf
include $(ARDMK_DIR)/Arduino.mk

Compiling throws a bunch of warnings (BIN already defined) but it doesn’t seem to stop the compile from completing. To get make upload to function properly, two lines need to be added to the tiny boards.txt.

attiny.upload.protocol=gpio
attiny.upload.speed=115200

At this point, it looks like I can successfully program ATTiny85 chips.

When playing with RF transmitter/receivers, I had problems with the above attiny code; however this variant seems to work much better.

References Some possibly useful links and why

  • Adafruit has some general instructions that apply to non-Raspberry Pi installations. Good tutorial info.
  • RPi forum entry on the approach I am using here. – This github repository has some good background information. It is what I followed when I tried to upgrade Wheezy. Ultimately, it worked for an ATMega328p but I had problems trying to program an ATTiny85 and gave up at that point. After completing the fresh install, I learned that the original problem here was the lack of additional variables (e.g. BOARD_SUB) in the makefile. I suspect the original plan was going to work.
  • Installing the patched version of avrdude. Here’s where the correct chmod command is found. I noticed that I may be able to avoid a custom avrdude but I have not yet explored this option.
  • The reference for custom board specifications. – Setting up Arduino from the command line can be found here and here.
  • Instructions used to set up ATTiny programming