ruggedBOARD
Tutorial Using Python
Tutorial Using Python
  • Overview
  • Quick Start with RB
    • Pre-Requisite
      • Required Hardware and Software Components
      • Host Setup
      • Linux Commands
    • Power Up your RB
    • Fiddle with RB Command-line
  • Lib-Mraa & UPM Sensor Libraries (Python)
    • First Python Program
    • Know Your Libraries
      • LibMRAA
        • Python Programming using MRAA (SPI)
        • Python Programming using MRAA (PWM)
        • Python Programming using MRAA (gpio_blink)
        • Python Programming using MRAA (Aio)
      • LibUPM
    • Example Programs for Sensors
      • Procedure to interface phyNODE with RB
      • Accelerometer
      • Temperature Sensor
      • Pressure Sensor
      • Humidity Sensor
      • Magnetometer
      • PIR Sensor
      • Ultrasonic Sensor
      • Gas Sensor (MQ5)
    • mikroBUS UPM Sensor
    • Example programs for Communication Protocols
      • GPIO
      • I2C
      • UART
  • Hello World in C language
    • Setting up Environment
    • Transferring Files from Host to Board
    • Write your first C program
  • IoT Implementation
    • What is IoT?
    • IoT Protocols
    • MQTT Setup
  • Peripherals Functionality Testing using C Language
    • Interfaces
      • GPIO(General purpose Input/Output):
      • UART(Universal Asynchronous Receiver-Transmitter)
      • RS232
      • RS485
      • CAN
      • MikroBUS
      • mPCIe
  • Advance RB
    • Preparing SD card in case of OS failure
Powered by GitBook
On this page

Was this helpful?

  1. Lib-Mraa & UPM Sensor Libraries (Python)
  2. Example programs for Communication Protocols

I2C

To interface an I2C bus. The I2c module module has a number of different ways of interacting with the i2c bus

x = m.I2c(0)
x.address(0x77)

# initialise device
if x.readReg(0xd0) != 0x55:
  print("error")

# we want to read temperature so write 0x2e into control reg
x.writeReg(0xf4, 0x2e)

# read a 16bit reg, obviously it's uncalibrated so mostly a useless value :)
print(str(x.readWordReg(0xf6)))

# and we can do the same thing with the read()/write() calls if we wished
# thought I'd really not recommend it!

x.write(bytearray(b'0xf40x2e'))

x.writeByte(0xf6)
d = x.read(2)

# WARNING: python 3.2+ call
print(str(d))
print(int.from_bytes(d, byteorder='little'))
PreviousGPIONextUART

Last updated 6 years ago

Was this helpful?