Raspberry Pi SPI and I2C Tutorial
Troubleshooting
If you've gone through raspi-config and enabled the SPI/I2c from 'Advanced Options', yet the devices are not in the device tree, don't lose hope. There are two files that should be examined. We found that somtimes the raspi-config utility doesn't solve the problem, depending on what version of Pi, where raspbian was sourced from, and when the last update has occurred.
Check /boot/config.txt
Sometimes the raspi-config tool will incorrectly edit /boot/config.txt while selecting the advanced settings. What happens is an erroneous control-char is placed in the file.
hdmi_force_hotplug=1
config_hdmi_boost=4
overscan_left=24
overscan_right=24
overscan_top=16
overscan_bottom=16
disable_overscan=0^Mdtparam=spi=on
dtparam=i2c_arm=on
^M
character. Fix the line breaking in the file so it looks something like this:
hdmi_force_hotplug=1
config_hdmi_boost=4
overscan_left=24
overscan_right=24
overscan_top=16
overscan_bottom=16
disable_overscan=0
dtparam=spi=on
dtparam=i2c_arm=on
Check /etc/modules
If they are not present, add the following to the end of /etc/modules
i2c-dev
Reboot the System
After checking the files, reboot by issuing sudo reboot
or sudo shutdown -r now
.