Skip to content

Commit

Permalink
Sonar enable/disable
Browse files Browse the repository at this point in the history
  • Loading branch information
MrYsLab committed Sep 24, 2023
1 parent 77b50be commit 904e8a8
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 189 deletions.
111 changes: 111 additions & 0 deletions examples/spi_adxl345_accelerometer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
"""
Copyright (c) 2023 Alan Yorinks All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
Version 3 as published by the Free Software Foundation; either
or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""

import asyncio
import sys
from telemetrix_aio import telemetrix_aio


"""
This program reads x, y, and z registers of an ADXL345 using 4 Wire SPI interface
"""


async def the_callback(data):
"""
:param data: [pin_type, chip select pin, device read register, x data pair,
y data pair, z data pair, time stamp]
"""
report_type = data[0]
chip_select_pin = data[1]
device_read_register = data[2] & 0x3f # strip off read command bits
number_bytes_read = data[3]
x_msb = data[4]
x_lsb = data[5]
y_msb = data[6]
y_lsb = data[7]
z_msb = data[8]
z_lsb = data[9]

x_data = (x_msb << 8) + x_lsb
y_data = (y_msb << 8) + y_lsb
z_data = (z_msb << 8) + z_lsb

# test report type for SPI report
if report_type == 13:
print(f'SPI Report: CS Pin: {chip_select_pin} SPI Register: '
f'{device_read_register} Number Of Bytes Read: {number_bytes_read} x: '
f'{x_data} y: {y_data} z: {z_data}')
else:
print(f'unexpected report type: {report_type}')


async def adxl345(my_board):
"""
:type my_board: object
"""
# initialize spi mode for chipselect on pin 10
await my_board.set_pin_mode_spi([10])
await asyncio.sleep(.3)

# set the SPI format
# spi speed is FPU frequency divided by 4
# data order is MSB
# mode is MODE3
await my_board.spi_set_format(4, 1, 0x0c)
await asyncio.sleep(.3)

# set up power and control register
await my_board.spi_write_blocking(10, [45, 0])
await asyncio.sleep(.3)

await my_board.spi_write_blocking(10, [45, 8])
await asyncio.sleep(.3)

# set up data format register for 4 wire spi
await my_board.spi_write_blocking(10, [49, 0])
await asyncio.sleep(.3)

# read 6 bytes from the data register
# for a multibyte read, we need to OR in a 0x40 into the register value
while True:
# read 6 bytes from the data register
try:
await my_board.spi_read_blocking(10, 50 | 0x40, 6, the_callback)

await asyncio.sleep(.5)

except (KeyboardInterrupt, RuntimeError):
await my_board.shutdown()
sys.exit(0)


# get the event loop
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

# instantiate telemetrix_aio
board = telemetrix_aio.TelemetrixAIO()

try:
# start the main function
loop.run_until_complete(adxl345(board))
except KeyboardInterrupt:
loop.run_until_complete(board.shutdown())
sys.exit(0)
155 changes: 0 additions & 155 deletions examples/spi_mpu9250.py

This file was deleted.

36 changes: 21 additions & 15 deletions examples/stepper_continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DHT support courtesy of Martyn Wheeler
Based on the DHTNew library - https://github.com/RobTillaart/DHTNew
"""
import asyncio
import time
Expand All @@ -30,26 +29,33 @@

async def step_continuous(the_board):
# create an accelstepper instance for a TB6600 motor driver
motor = await the_board.set_pin_mode_stepper(interface=2, pin1=8, pin2=9)
motor = await the_board.set_pin_mode_stepper(interface=1, pin1=8, pin2=9)

# if you are using a 28BYJ-48 Stepper Motor with ULN2003
# comment out the line above and uncomment out the line below.
# motor = await the_board.set_pin_mode_stepper(interface=4, pin1=5, pin2=4, pin3=14,
# pin4=12)

# set the max speed and speed
await the_board.stepper_set_max_speed(motor, 900)
await the_board.stepper_set_speed(motor, 800)
# run the motor
await the_board.stepper_run_speed(motor)

# keep application running
while True:
try:
await asyncio.sleep(.0002)
except KeyboardInterrupt:
await the_board.shutdown()
sys.exit(0)
# set the max speed and speed
await the_board.stepper_set_max_speed(motor, 900)
await the_board.stepper_set_speed(motor, 200)
# run the motor
await the_board.stepper_run_speed(motor)
await asyncio.sleep(5)

await the_board.stepper_stop(motor)
await asyncio.sleep(2)

# change direction
await the_board.stepper_set_max_speed(motor, 900)
await the_board.stepper_set_speed(motor, -200)
# run the motor
await the_board.stepper_run_speed(motor)
await asyncio.sleep(5)

await the_board.stepper_stop(motor)
await asyncio.sleep(2)

# get the event loop
loop = asyncio.new_event_loop()
Expand Down
2 changes: 1 addition & 1 deletion examples/wifi/blink_wifi.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def blink(my_board, pin):
asyncio.set_event_loop(loop)

# instantiate telemetrix_aio
board = telemetrix_aio.TelemetrixAIO(ip_address='192.168.2.220')
board = telemetrix_aio.TelemetrixAIO(ip_address='192.168.2.168')

try:
# start the main function
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
packages=['telemetrix_aio'],
install_requires=['pyserial'],

version='1.12',
version='1.20',

description="Remotely Control And Monitor Arduino-Core devices",
long_description=long_description,
Expand Down
2 changes: 1 addition & 1 deletion telemetrix_aio/private_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class PrivateConstants:

DEBUG_PRINT = 99

TELEMETRIX_AIO_VERSION = "1.12"
TELEMETRIX_AIO_VERSION = "1.20"

# reporting control
REPORTING_DISABLE_ALL = 0
Expand Down
Loading

0 comments on commit 904e8a8

Please sign in to comment.