Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. ### TL;DR
  2.  
  3. ```
  4. # Turn i2c on
  5. sudo raspi-config nonint do_i2c 0
  6. # Turn i2c off
  7. sudo raspi-config nonint do_i2c 1
  8. ```
  9.  
  10. ### Console log to prove it works
  11.  
  12. ```
  13. $ # First see what it looks like with i2c turned off...
  14. $ dmesg | grep i2c
  15. [ 2.344954] i2c /dev entries driver
  16. $ lsmod | grep i2c
  17. i2c_dev 5859 0
  18. $ cat /boot/config.txt | grep i2c
  19. dtparam=i2c_arm=off
  20. $
  21. $ # Now turn it on like this...
  22. $ sudo raspi-config nonint do_i2c 0
  23. $
  24. $ # Check what changed...
  25. $ dmesg | grep i2c
  26. [ 2.344954] i2c /dev entries driver
  27. [ 231.274035] bcm2708_i2c 3f804000.i2c: BSC1 Controller at 0x3f804000 (irq 83) (baudrate 100000)
  28. $ cat /boot/config.txt | grep i2c
  29. dtparam=i2c_arm=on
  30. $ lsmod | grep i2c
  31. i2c_bcm2708 4834 0
  32. i2c_dev 5859 0
  33. $
  34. $ # Now turn it back off...
  35. $ sudo raspi-config nonint do_i2c 1
  36. $
  37. $ # and check what changed...
  38. $ dmesg | grep i2c
  39. [ 2.344954] i2c /dev entries driver
  40. [ 231.274035] bcm2708_i2c 3f804000.i2c: BSC1 Controller at 0x3f804000 (irq 83) (baudrate 100000)
  41. $ lsmod | grep i2c
  42. i2c_bcm2708 4834 0
  43. i2c_dev 5859 0
  44. $ cat /boot/config.txt | grep i2c
  45. dtparam=i2c_arm=off
  46. ```
  47.  
  48. ### Why it works
  49. raspi-config is a big bash script that lives at `/usr/bin/raspi-config`. Basically,
  50. if you start with the `nonint` flag, it will interpret additional arguments as calls
  51. to functions with the script. If you search the script for `do_interface_menu()`, it
  52. should give you an idea of what's possible.
  53.  
  54. The `0` and `1` values correspond to an `if` block in `do_i2c()` that's checking the
  55. value of `$RET`. When the the `do_i2c` sees that `$INTERACTIVE` is true, it grabs
  56. the next argument after `do_i2c` with `RET=$1`, then that gets used to decide if i2c
  57. should be enabled or disabled.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement