Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
test_RX_i2c_device_template
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fischertechnik examples
RX Controller
test_RX_i2c_device_template
Commits
71dfe4e7
Commit
71dfe4e7
authored
2 weeks ago
by
ft-Demo
Browse files
Options
Downloads
Patches
Plain Diff
commit by robo pro coding
parent
b74393af
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test_RX_i2c_device_template.blockly
+66
-17
66 additions, 17 deletions
test_RX_i2c_device_template.blockly
test_RX_i2c_device_template.py
+11
-9
11 additions, 9 deletions
test_RX_i2c_device_template.py
with
77 additions
and
26 deletions
test_RX_i2c_device_template.blockly
+
66
−
17
View file @
71dfe4e7
...
...
@@ -5,32 +5,81 @@
<variable id="XG0}H+Qa?Eq+T/-f$.Ig">read_length</variable>
<variable id="xif@_y%QFAVZ:W*vU}(`">i2cList</variable>
<variable id=":]ae2S[%IC#[WPCgbx%(">read_buffer</variable>
<variable id="23Gm;p4d6U2774x`[4kr">addr</variable>
</variables>
<block type="util_python_imports" id="BuNdg{crGi4?b.2~{7~v" x="0" y="0">
<field name="value">import board&#10;import busio&#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="147">
<statement name="statement">
<block type="util_python" id="h9BK3DENhX`}qv`{TWOi">
<field name="value">global I2C_ADDRESS, I2C_FREQ&#10;I2C_ADDRESS = 0x39&#10;I2C_FREQ = 400000</field>
<block type="variables_set" id="GA5Xsw0+Mxs`x#b*,L(,">
<field name="VAR" id="xif@_y%QFAVZ:W*vU}(`">i2cList</field>
<value name="VALUE">
<block type="procedures_callreturn" id="ZgcacQbNpYur`7@%+$*b">
<mutation name="i2cScan"/>
</block>
</value>
<next>
<block type="variables_set" id="GA5Xsw0+Mxs`x#b*,L(,">
<field name="VAR" id="xif@_y%QFAVZ:W*vU}(`">i2cList</field>
<value name="VALUE">
<block type="procedures_callreturn" id="ZgcacQbNpYur`7@%+$*b">
<mutation name="i2cScan"/>
</block>
<block type="text_print" id="EFp(Rj)M1f[Xr8bv]+,j">
<value name="TEXT">
<shadow type="text" id="_ond3L(ix$o0FD`|we,]">
<field name="TEXT">I2C addresses found:</field>
</shadow>
</value>
<next>
<block type="text_print" id="mEMZn#djI|v}b+HEq3Dk">
<value name="TEXT">
<shadow type="text" id="Qo5E;81`j$rlyO7S;OGQ">
<field name="TEXT"/>
</shadow>
<block type="controls_forEach" id="?5#~fIN!ZY!}4)=n-a6l">
<field name="VAR" id="23Gm;p4d6U2774x`[4kr">addr</field>
<value name="LIST">
<block type="variables_get" id="xw]EJ535~-ww0}9u7n_Z">
<field name="VAR" id="xif@_y%QFAVZ:W*vU}(`">i2cList</field>
</block>
</value>
<statement name="DO">
<block type="controls_if" id="k1(ttYLlr(oqQ77K}c:K">
<value name="IF0">
<block type="logic_compare" id="[@ADBOshhBL]#LS/9mK6">
<field name="OP">NEQ</field>
<value name="A">
<block type="variables_get" id="^qtIIL?h9h#W3WBl6|/7">
<field name="VAR" id="23Gm;p4d6U2774x`[4kr">addr</field>
</block>
</value>
<value name="B">
<block type="math_number" id="RtI*x3p1I(A%%ln@VY1Q">
<field name="NUM">8</field>
</block>
</value>
</block>
</value>
<statement name="DO0">
<block type="text_print" id="mEMZn#djI|v}b+HEq3Dk">
<value name="TEXT">
<shadow type="text" id="Qo5E;81`j$rlyO7S;OGQ">
<field name="TEXT"/>
</shadow>
<block type="text_format" id="4;*yQKs35@9`|c,D?-..">
<mutation items="2"/>
<value name="value">
<shadow type="text" id="ej4Zb@zJH]3,uL,xvWQ-">
<field name="TEXT"> 0x{:02X} ({})</field>
</shadow>
</value>
<value name="ADD0">
<block type="variables_get" id="Syf$Jy7goS80*Xev+AQD">
<field name="VAR" id="23Gm;p4d6U2774x`[4kr">addr</field>
</block>
</value>
<value name="ADD1">
<block type="variables_get" id="%B9mn@J_9wUE0pB=M[IK">
<field name="VAR" id="23Gm;p4d6U2774x`[4kr">addr</field>
</block>
</value>
</block>
</value>
</block>
</statement>
</block>
</statement>
<next>
<block type="loop_endless" id="^x^S51cswn:O`*PQ]4y`"/>
</next>
...
...
@@ -41,7 +90,7 @@
</block>
</statement>
</block>
<block type="procedures_defreturn" id="ecAbK;fN,?_e`Xaqdpv," x="0" y="
458
">
<block type="procedures_defreturn" id="ecAbK;fN,?_e`Xaqdpv," x="0" y="
533
">
<field name="NAME">i2cScan</field>
<statement name="STACK">
<block type="util_python" id="Si.f-UPynZ9}TvQbdhT%">
...
...
@@ -54,7 +103,7 @@
</block>
</value>
</block>
<block type="procedures_defnoreturn" id="b9}aT{G=Qe~2BTS;I{/K" inline="false" x="0" y="8
21
">
<block type="procedures_defnoreturn" id="b9}aT{G=Qe~2BTS;I{/K" inline="false" x="0" y="8
96
">
<mutation>
<arg name="i2cAdr" varid="[HKS4(#X?SYWL^J5h6g_" argid="NWOx%:B*R@5qS{hwu}*6"/>
<arg name="write_buffer" varid="i}2@Lo4Jj6^=z5w)nF#P" argid="*^1{:*NQ;a~JjR]tLC0["/>
...
...
@@ -68,7 +117,7 @@
</block>
</statement>
</block>
<block type="procedures_defreturn" id="}UjMG~j-oVgtEs3.*C*p" x="0" y="1
069
">
<block type="procedures_defreturn" id="}UjMG~j-oVgtEs3.*C*p" x="0" y="1
144
">
<mutation>
<arg name="i2cAdr" varid="[HKS4(#X?SYWL^J5h6g_" argid="RlPBDL2._vnl$hOf*e_y"/>
<arg name="read_length" varid="XG0}H+Qa?Eq+T/-f$.Ig" argid=";l@;|?3O8#{w#P1a+uc@"/>
...
...
@@ -87,7 +136,7 @@
</block>
</value>
</block>
<block type="procedures_defreturn" id="IQ-R}v]5bMHD39iwQF+|" x="0" y="1
358
">
<block type="procedures_defreturn" id="IQ-R}v]5bMHD39iwQF+|" x="0" y="1
433
">
<mutation>
<arg name="i2cAdr" varid="[HKS4(#X?SYWL^J5h6g_" argid="O.Le#]tX01s*mD=s2?cY"/>
<arg name="write_buffer" varid="i}2@Lo4Jj6^=z5w)nF#P" argid=",PWC!Et~WNrW[igor[qw"/>
...
...
This diff is collapsed.
Click to expand it.
test_RX_i2c_device_template.py
+
11
−
9
View file @
71dfe4e7
...
...
@@ -10,10 +10,11 @@ write_buffer = None
read_length
=
None
i2cList
=
None
read_buffer
=
None
addr
=
None
async
def
i2cScan
():
global
i2cAdr
,
write_buffer
,
read_length
,
i2cList
,
read_buffer
global
i2cAdr
,
write_buffer
,
read_length
,
i2cList
,
read_buffer
,
addr
#https://learn.adafruit.com/circuitpython-essentials/circuitpython-i2c
i2c
=
busio
.
I2C
(
board
.
SCL1
,
board
.
SDA1
,
frequency
=
400000
)
while
not
i2c
.
try_lock
():
...
...
@@ -28,14 +29,14 @@ async def i2cScan():
async
def
i2cWriteBuffer
(
i2cAdr
,
write_buffer
):
global
read_length
,
i2cList
,
read_buffer
global
read_length
,
i2cList
,
read_buffer
,
addr
with
busio
.
I2C
(
board
.
SCL1
,
board
.
SDA1
,
frequency
=
400000
)
as
i2c
:
with
I2CDevice
(
i2c
,
i2cAdr
)
as
device
:
device
.
write
(
write_buffer
)
async
def
i2cReadBuffer
(
i2cAdr
,
read_length
):
global
write_buffer
,
i2cList
,
read_buffer
global
write_buffer
,
i2cList
,
read_buffer
,
addr
read_buffer
=
bytearray
(
read_length
)
with
busio
.
I2C
(
board
.
SCL1
,
board
.
SDA1
,
frequency
=
400000
)
as
i2c
:
with
I2CDevice
(
i2c
,
i2cAdr
)
as
device
:
...
...
@@ -44,7 +45,7 @@ async def i2cReadBuffer(i2cAdr, read_length):
async
def
i2cWriteReadBuffer
(
i2cAdr
,
write_buffer
,
read_length
):
global
i2cList
,
read_buffer
global
i2cList
,
read_buffer
,
addr
read_buffer
=
bytearray
(
read_length
)
with
busio
.
I2C
(
board
.
SCL1
,
board
.
SDA1
,
frequency
=
400000
)
as
i2c
:
with
I2CDevice
(
i2c
,
i2cAdr
)
as
device
:
...
...
@@ -53,12 +54,13 @@ async def i2cWriteReadBuffer(i2cAdr, write_buffer, read_length):
async
def
run
(
instance
):
global
i2cAdr
,
write_buffer
,
read_length
,
i2cList
,
read_buffer
global
i2cAdr
,
write_buffer
,
read_length
,
i2cList
,
read_buffer
,
addr
await
controller
.
init
(
instance
)
global
I2C_ADDRESS
,
I2C_FREQ
I2C_ADDRESS
=
0x39
I2C_FREQ
=
400000
i2cList
=
await
i2cScan
()
print
(
i2cList
)
print
(
'
I2C addresses found:
'
)
for
addr
in
i2cList
:
if
addr
!=
8
:
print
(
'
0x{:02X} ({})
'
.
format
(
addr
,
addr
))
await
asyncio
.
sleep
(
0.01
)
while
True
:
await
asyncio
.
sleep
(
0.01
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment