@@ -55,25 +55,60 @@ Do not power 3.3V devices from the EV3 5V VCC if your device does not support it
5555
5656 .. automethod :: write
5757
58- **Example: Read and write to an I2C device **
58+ Examples
59+ -------------------
5960
60- .. literalinclude :: ../../../examples/ev3/i2c_basics/main.py
61+ Reading a custom I2C sensor
62+ ***************************
63+
64+ This example uses the NXT Temperature Sensor as if it were a custom I2C
65+ device. It sets the resolution once, and then reads the temperature in a loop.
66+
67+ .. literalinclude ::
68+ ../../../examples/pup/iodevices_i2cdevice/temperature_basics.py
69+
70+ Making your own sensor class
71+ ****************************
72+
73+ This is the same example, but now wrapped in a class. The ``map `` argument
74+ converts the raw bytes to degrees Celsius, so ``temperature() `` returns the
75+ value you are interested in. The ``temperature() `` method can then also be used
76+ with `await ` when multitasking.
77+
78+ .. literalinclude ::
79+ ../../../examples/pup/iodevices_i2cdevice/temperature_class.py
80+
81+ Using a Qwiic device
82+ ********************
83+
84+ This example shows text on a SparkFun SerLCD display, connected using the
85+ Qwiic convention. It also shows how to choose a custom I2C frequency.
86+
87+ .. literalinclude ::
88+ ../../../examples/pup/iodevices_i2cdevice/qwiic_display.py
89+
90+ Overview of all I2C options
91+ ***************************
92+
93+ This example does not represent a real device. It shows all the ways you
94+ can read and write data. Some rudimentary devices do not require a register
95+ argument or even any data, as shown below.
96+
97+ .. literalinclude ::
98+ ../../../examples/pup/iodevices_i2cdevice/api_overview.py
99+
100+ Some devices use 16-bit register addresses. Use ``reg_len=2 `` for these, and
101+ then use registers as usual.
102+
103+ .. literalinclude ::
104+ ../../../examples/pup/iodevices_i2cdevice/api_overview_reg16.py
61105
62106.. _i2caddress :
63107
64108I2C Addresses
65109---------------
66- I2C addresses are 7-bit values. However, most vendors who make LEGO compatible
110+ I2C addresses are 7-bit values. However, some vendors who make LEGO compatible
67111sensors provide an 8-bit address in their documentation.
68112To use those addresses, you must shift them by 1 bit.
69113For example, if the documented address is ``0xD2 ``, you can do
70114``address = 0xD2 >> 1 ``.
71-
72- Advanced I2C Commands
73- ---------------------
74- Some rudimentary I2C devices do not require a register argument or even any
75- data. You can achieve this behavior as shown in the examples below.
76-
77- **Example: Advanced I2C read and write techniques **
78-
79- .. literalinclude :: ../../../examples/ev3/i2c_extra/main.py
0 commit comments