Skip to main content

Change TOF10120 address device by usb. Get data from TOF10120 device by i2c

Project description

Rangefinders-i2c Platforms Language IDE adam package

License PyPI version License PyPI version Wheel Version Format Status Activity LastStatus CodeSize CodeSize

What the library can do?

  1. Change TOF10120 address device by usb.
  2. Get data from TOF10120 device by i2c

How install

pip install rangefinders-i2c

Change address

To change the address, a usb programmer is needed. After connecting the programmer, you can find out the address using the following code

if your programmer is the only device (connect to /dev/ttyUSB0)

from rangefinders_i2c.SensorManagment import SensorManagment

managment = SensorManagment()

if there is more than one device, then you can find it using the following code

print(SensorManagment.GetUsbDeviceList())

and by selecting a device, you can specify it when initializing an instance of the class

managment = SensorManagment('/dev/ttyUSB1')

the second parameter is the port speed, by default it is 9600. To change the speed, use the second parameter when initializing the class instance

managment = SensorManagment('/dev/ttyUSB1', 4800).

After that, you should call the function setAddress

managment = SensorManagment()
managment.setAddress(48)

for all rangefinders, we use constant values: 48, 50, 52, 54, 56, 58.

Calling the set Address() function with a value other than the specified constants will result in an error: ValueError('Address must be 48, 50, 52, 54, 56, 58')

Get Data from TOF10120

In order to get the values, you should initialize an instance of the class

from rangefinders_i2c.ReadSensor import ReadSensor

sensor = ReadSensor(1)

where 1 is the smbus bus number.

You can also enable verbose mode (log error to console) using the following code

sensor = ReadSensor(1, True)

After that, you can get the value from the device by passing it the address as a parameter

address = 0x18
distance = sensor.GetDistance(address)
print("address:", address, "distance:", distance)

or

address = 24
distance = sensor.GetDistance(address)
print("address:", address, "distance:", distance)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rangefinders-i2c-0.0.4.tar.gz (4.2 kB view details)

Uploaded Source

File details

Details for the file rangefinders-i2c-0.0.4.tar.gz.

File metadata

  • Download URL: rangefinders-i2c-0.0.4.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for rangefinders-i2c-0.0.4.tar.gz
Algorithm Hash digest
SHA256 14c26954a273b53d631d892662e4e7f640cc7f67d6acf0f656ef1b4a536d2c7a
MD5 681090cf8149c88f8d218db850ec0f49
BLAKE2b-256 a8165a6b33c358e7d7c6b7fd0fb64d55d30afc8604aa98fd30921cdb5c592218

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page