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 hashes)

Uploaded Source

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