User Guide

179
wget http://www.vilros.com/vfiles/
smbusmodule.c
7. Run the following two commands:
python3 setup.py build
sudo python3 setup.py install
Using I2C from Python 3
At the top of your Python script, you need to import the module
smbus and create an instance of the SMBus class.
In the following example, the code sends the value 88 to the I2C
device that has the address 23:
import smbus
bus = smbus.SMBus(0)
bus.write_byte(23, 88)
To read from an I2C device, use the read_byte() method and
pass the device’s address as an argument. For example:
v = bus.read_byte(23)
7.9 Serial UARTs
A universal asynchronous receiver/transmitter (UART) is a chip
that translates the parallel data used by a microprocessor or
microcontroller to serial data for use with communications ports.
Serial ports are asynchronous, which means that you can send
data at the same time as receiving it, and both devices can
initiate connections and send data when they want to.
On the Pi, the GPIO header has two UART pins for making
connections to other devices using a traditional serial port.
These are pin 8 (UART_TXD) and pin 10 (UART_RXD). The TXD
pin of the Pi is connected to the RXD pin of the other device, and
the RXD pin of the Pi is connected to the TXD pin of the other
device. And to make electricity flow, you also need to connect a
wire between the ground of each device.