Usage of Micropython Tpyboard i²c

Source: Internet
Author: User

First look at the basic usage:

 From pyb import i²ci²c = i²c (1) # Create on bus 1i²c = i²c (1, I²c. Master) # Create and Init as a masterI2c.init (i²c. Master, baudrate=20000) # init as a masterI2c.init (i²c. SLAVE, addr=0x42) # init as a SLAVE with given addressI2c.deinit () # Turn off the peripheralI2c.init (i²c. MASTER)i2c.send (' 123 ', 0x42) # Send 3 bytes to slave with address 0x42I2c.send (b ' 456 ', addr=0x42) # keyword for addressI2c.is_ready (0x42) # check if slave 0x42 is readyI2c.scan () # Scan for slaves on the bus, returning# A list of valid addressesI2c.mem_read (3, 0x42, 2) # Read 3 bytes from memory of slave 0x42,# starting at address 2 in the slavei2c.mem_write (' abc ', 0x42, 2, timeout=1000) # write ' abc ' (3 bytes) to memory of slave 0x42# starting at address 2 in the slave, timeout after 1 second   usage of i²c: class Pyb. I²c (bus, ...)serial number of the BUS,I2C busi2c.deinit (), remove the I²C definitioni2c.init (Mode, *, addr=0x12, baudrate=400000, Gencall=false), initializingmode, it can only be i²c. MASTER or I²c. SLAVEaddr,7-bit i²c addressbaudrate, Clock frequencyGencall, universal invocation modeI2c.is_ready (addr), detects if I²c device responds, only valid for main modei2c.mem_read (data, addr, memaddr, *, timeout=5000, addr_size=8), readingdata, Integer, or cacheaddr, device addressmemaddr, memory addressTimeout , read wait time-outthe size of the addr_size,memaddr. 8-bit or 16-biti2c.mem_write (data, addr, memaddr, *, timeout=5000, addr_size=8), write to, parameter meaning ibid .i2c.recv (recv, addr=0x00, *, timeout=5000), reading data from the busrecv, the amount of data that needs to be read, or the bufferADDR,I2C AddressTimeout , time-outi2c.send (send, addr=0x00, *, timeout=5000)send, Integer, or bufferADDR,I2C AddressTimeout , time-outI2c.scan (), search for devices on the I²c bus.

Usage of Micropython Tpyboard i²c

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.