Skip to content
Snippets Groups Projects
Commit 88f731a6 authored by ft-Demo's avatar ft-Demo
Browse files

commit by robo pro coding

parents
No related branches found
No related tags found
No related merge requests found
{"uuid":"0a76a88f-4cdb-4f9d-8a94-da94e842a34b","name":"test_RX_i2c_device_apds9960","mode":"ADVANCED","version":"1.0","controller":"RX"}
\ No newline at end of file
<xml version="16"/>
\ No newline at end of file
<xml xmlns="https://developers.google.com/blockly/xml" version="16">
<block type="util_python_imports" id="BuNdg{crGi4?b.2~{7~v" x="0" y="0">
<field name="value">import board&amp;#10;import busio&amp;#10;from adafruit_bus_device.i2c_device import I2CDevice</field>
</block>
<block type="start_block" id="7s|$pr*xo|Z,AfuHs:~," deletable="false" x="0" y="143">
<statement name="statement">
<block type="procedures_callnoreturn" id="crzWC5CXWlbK^p5G]#,a">
<mutation name="i2c_init"/>
<next>
<block type="procedures_callnoreturn" id="e$BLx-`|mVa3,^Uv$:lu">
<mutation name="i2c_scan"/>
<next>
<block type="util_python" id="1Ih*vWYKj$v__eB9t[Fm" inline="true">
<field name="value">device = I2CDevice(i2c, 0x39)&amp;#10;with device:&amp;#10; device.write(bytes([0x80,0x07]))</field>
<next>
<block type="loop_endless" id="^x^S51cswn:O`*PQ]4y`">
<statement name="DO">
<block type="util_python" id="||FIP;f:l$]7l1hJl*?#" inline="true">
<field name="value">with device:&amp;#10; device.write(bytes([0x94]))&amp;#10; result = bytearray(2)&amp;#10; device.readinto(result)&amp;#10; print(result)</field>
<next>
<block type="util_wait_for" id="LOxBp4_n{-EMeuwk)[rN">
<field name="format">s</field>
<value name="value">
<shadow type="math_number" id="#SjCO!ZSK2es)nXW0(-B">
<field name="NUM">1</field>
</shadow>
</value>
</block>
</next>
</block>
</statement>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</statement>
</block>
<block type="procedures_defnoreturn" id="Su;!2aN^UiUr2iaXX;R;" x="0" y="544">
<field name="NAME">i2c_init</field>
<statement name="STACK">
<block type="util_python" id=")px9GxFT)zf|]UgfXzO{" inline="true">
<field name="value">#https://learn.adafruit.com/circuitpython-essentials/circuitpython-i2c&amp;#10;i2c = busio.I2C(board.SCL1, board.SDA1)</field>
</block>
</statement>
</block>
<block type="procedures_defnoreturn" id="TfZ3.Sj$25j_S7bIjpY)" x="0" y="680">
<field name="NAME">i2c_scan</field>
<statement name="STACK">
<block type="util_python" id="PA6U?60_eWc?*acT.2%4" inline="true">
<field name="value">while not i2c.try_lock():&amp;#10; pass&amp;#10;try:&amp;#10; print("I2C addresses found:", [hex(device_address) for device_address in i2c.scan()],)&amp;#10;finally: # unlock the i2c bus&amp;#10; i2c.unlock()</field>
</block>
</statement>
</block>
</xml>
\ No newline at end of file
import asyncio
import board
import busio
from adafruit_bus_device.i2c_device import I2CDevice
from fischertechnik.logging import log as print
async def i2c_init():
#https://learn.adafruit.com/circuitpython-essentials/circuitpython-i2c
i2c = busio.I2C(board.SCL1, board.SDA1)
async def i2c_scan():
while not i2c.try_lock():
pass
try:
print("I2C addresses found:", [hex(device_address) for device_address in i2c.scan()],)
finally: # unlock the i2c bus
i2c.unlock()
async def run(instance):
await i2c_init()
await i2c_scan()
device = I2CDevice(i2c, 0x39)
with device:
device.write(bytes([0x80,0x07]))
while True:
with device:
device.write(bytes([0x94]))
result = bytearray(2)
device.readinto(result)
print(result)
await asyncio.sleep(1)
await asyncio.sleep(0.01)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment