Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
python_test_scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
python_test_scripts
Merge requests
!2
Modified the scripts to run on Raspberry Pi.
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Merged
Modified the scripts to run on Raspberry Pi.
Work_Gijs
into
master
Overview
1
Commits
46
Pipelines
0
Changes
1
Merged
Modified the scripts to run on Raspberry Pi.
Gijs Schoonderbeek
requested to merge
Work_Gijs
into
master
May 28, 2021
Overview
1
Commits
46
Pipelines
0
Changes
1
Script will check if it is run on a PI, in that case a different I2C serial library is used.
0
0
Merge request reports
Viewing commit
5c8a9709
Prev
Next
Show latest version
1 file
+
87
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
5c8a9709
Added I2C_serial_pi.py to use the Raspberry Pi I2C bus instead of the Laptop/I2C box.
· 5c8a9709
Gijs Schoonderbeek
authored
Jan 6, 2021
I2C_serial_pi.py
0 → 100644
+
87
−
0
View file @ 5c8a9709
Edit in single-file editor
Open in Web IDE
'''
Copyright 2021 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
ASTRON Netherlands Institute for Radio Astronomy
Licensed under the Apache License, Version 2.0 (the
"
License
"
);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an
"
AS IS
"
BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
I2C_serial_Pi
Started by Gijs
Class for using the I2C bus of the I2C. This class is used for the
basic I2C scripts to read and write the RCU2, PCC etc.
'''
import
smbus
import
sys
from
time
import
*
DEBUG
=
False
BUS_NR
=
1
class
I2C
:
def
__init__
(
self
,
ADDRESS
=
'
040
'
):
self
.
I2C_Address
=
ADDRESS
bus
=
smbus
.
SMBus
(
BUS_NR
)
def
read_bytes
(
self
,
register
,
bytes_to_read
=
2
):
try
:
ret_value
=
bus
.
read_i2c_block_data
(
self
.
I2C_Address
,
register
,
bytes_to_read
)
ret_ack
=
1
except
IOError
,
err
:
ret_ack
=
0
ret_value
=
0
if
DEBUG
:
print
(
"
Reading error
"
)
return
ret_ack
,
ret_value
def
read_last_reg
(
self
,
bytes_to_read
):
ret_value
=
[]
for
cnt
in
bytes_to_read
:
try
:
ret_value
.
append
(
bus
.
read_byte
(
self
.
I2C_Address
))
ret_ack
=
1
except
IOError
,
err
:
ret_ack
=
0
ret_value
=
0
if
DEBUG
:
print
(
"
Reading error
"
)
return
ret_ack
,
ret_value
def
write_bytes
(
self
,
register
,
data
):
try
:
bus
.
write_i2c_block_data
(
self
.
I2C_Address
,
register
,
data
)
ret_ack
=
1
except
IOError
,
err
:
ret_ack
=
0
ret_value
=
0
if
DEBUG
:
print
(
"
Reading error
"
)
return
ret_ack
def
write_pointer
(
self
,
register
):
try
:
ret_value
=
bus
.
read_i2c_block_data
(
self
.
I2C_Address
,
register
,
1
)
ret_ack
=
1
except
IOError
,
err
:
ret_ack
=
0
ret_value
=
0
if
DEBUG
:
print
(
"
Reading error
"
)
return
ret_ack
if
__name__
==
"
__main__
"
:
I2C_Device
=
I2C
(
0x40
)
I2C_Device
.
write_bytes
(
0x00
,
0x00
)
ret_ack
,
ret_value
=
I2C_Device
.
read_bytes
(
0x8C
,
2
)
print
(
ret_value
)
Loading