Bird
0
0
Raspberry Piprogramming~20 mins

Enabling I2C on Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
I2C Master on Raspberry Pi
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of the command to check I2C devices?
You have enabled I2C on your Raspberry Pi and connected a device. You run the command i2cdetect -y 1. What output do you expect if a device is connected at address 0x3C?
Raspberry Pi
sudo i2cdetect -y 1
AError: command not found
B
     0 1 2 3 4 5 6 7 8 9 a b c d e f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- 3c -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --
CNo devices found
DDevice detected at address 0x50
Attempts:
2 left
💡 Hint
Look for the hexadecimal address 3c in the output grid.
🧠 Conceptual
intermediate
1:30remaining
Which file enables I2C interface on Raspberry Pi?
To enable the I2C interface on Raspberry Pi, which configuration file do you edit?
A/boot/config.txt
B/etc/modules
C/etc/i2c.conf
D/boot/cmdline.txt
Attempts:
2 left
💡 Hint
This file contains boot-time settings for the Raspberry Pi.
🔧 Debug
advanced
2:00remaining
Why does this Python I2C code raise an error?
You run this Python code to communicate with an I2C device but get an error:
import smbus
bus = smbus.SMBus(0)
bus.write_byte(0x3c, 0x00)
What is the most likely cause of the error?
AThe smbus module is not installed
BThe device address 0x3c is invalid
Cwrite_byte requires three arguments
DBus number 0 is incorrect; Raspberry Pi uses bus 1 for I2C
Attempts:
2 left
💡 Hint
Check which I2C bus number Raspberry Pi uses by default.
📝 Syntax
advanced
1:30remaining
Which command correctly loads the I2C kernel module?
You want to load the I2C kernel module manually. Which command is correct?
Asudo modprobe i2c-dev
Bsudo loadmodule i2c-dev
Csudo insmod i2c-dev
Dsudo modload i2c-dev
Attempts:
2 left
💡 Hint
The command to add kernel modules is a common Linux utility.
🚀 Application
expert
3:00remaining
How to verify I2C is enabled and working on Raspberry Pi?
You want to confirm that I2C is enabled and working on your Raspberry Pi. Which sequence of commands will correctly verify this?
Aecho 'dtparam=i2c_arm=on' > /boot/config.txt → reboot → i2cdetect -y 0
Bsudo modprobe i2c_bcm2708 → i2cdetect -y 0 → reboot
Csudo raspi-config (enable I2C) → reboot → lsmod | grep i2c_dev → i2cdetect -y 1
Dsudo systemctl start i2c.service → i2cdetect -y 1 → ls /dev/i2c-1
Attempts:
2 left
💡 Hint
Use the Raspberry Pi configuration tool and check kernel modules and device scan.