Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### TL;DR
- ```
- # Turn i2c on
- sudo raspi-config nonint do_i2c 0
- # Turn i2c off
- sudo raspi-config nonint do_i2c 1
- ```
- ### Console log to prove it works
- ```
- $ # First see what it looks like with i2c turned off...
- $ dmesg | grep i2c
- [ 2.344954] i2c /dev entries driver
- $ lsmod | grep i2c
- i2c_dev 5859 0
- $ cat /boot/config.txt | grep i2c
- dtparam=i2c_arm=off
- $
- $ # Now turn it on like this...
- $ sudo raspi-config nonint do_i2c 0
- $
- $ # Check what changed...
- $ dmesg | grep i2c
- [ 2.344954] i2c /dev entries driver
- [ 231.274035] bcm2708_i2c 3f804000.i2c: BSC1 Controller at 0x3f804000 (irq 83) (baudrate 100000)
- $ cat /boot/config.txt | grep i2c
- dtparam=i2c_arm=on
- $ lsmod | grep i2c
- i2c_bcm2708 4834 0
- i2c_dev 5859 0
- $
- $ # Now turn it back off...
- $ sudo raspi-config nonint do_i2c 1
- $
- $ # and check what changed...
- $ dmesg | grep i2c
- [ 2.344954] i2c /dev entries driver
- [ 231.274035] bcm2708_i2c 3f804000.i2c: BSC1 Controller at 0x3f804000 (irq 83) (baudrate 100000)
- $ lsmod | grep i2c
- i2c_bcm2708 4834 0
- i2c_dev 5859 0
- $ cat /boot/config.txt | grep i2c
- dtparam=i2c_arm=off
- ```
- ### Why it works
- raspi-config is a big bash script that lives at `/usr/bin/raspi-config`. Basically,
- if you start with the `nonint` flag, it will interpret additional arguments as calls
- to functions with the script. If you search the script for `do_interface_menu()`, it
- should give you an idea of what's possible.
- The `0` and `1` values correspond to an `if` block in `do_i2c()` that's checking the
- value of `$RET`. When the the `do_i2c` sees that `$INTERACTIVE` is true, it grabs
- the next argument after `do_i2c` with `RET=$1`, then that gets used to decide if i2c
- should be enabled or disabled.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement