Package: atlas-i2c
AtlasI2C: A Python package to communicate with Atlas Scientific devices in I2C mode.This package provides functionality that is based on theexample codefrom Atlas Scientific. It has the following goals:Provide a simple and clean codebase with test coverageReduce code duplication by making the codebase available from PyPiProvide comprehensive support for Atlas Scientific EZO sensorsOverviewThis package provides the following modules:atlas_i2ccommandsconstantssensorsmodule: atlas_i2cTheatlas_i2cmodule can be thought of as the client that talks to the server, similar to how an HTTP client talks to an HTTP server. The server in this scenario is the Atlas Scientfic EZO sensor. Instead of talking over TCP using HTTP, however, it talks to the server over the I2C bus, using Linux device files (e.g./dev/i2c-1).The module uses the following protocol to communicate with a sensor:Open the device file for reading and writingSend a command string (e.g. "R") to the device by writing it to the device fileWait for N milliseconds for the sensor to process the commandRead the resulting data from the device fileAt the lowest level, this module'sread()andwrite()methods can be combined withtime.sleep()to communicate with a sensor:In[1]:fromatlas_i2cimportatlas_i2cIn[2]:sensor_address=102In[3]:dev=atlas_i2c.AtlasI2C()In[4]:dev.set_i2c_address(sensor_address)In[5]:dev.write("R")In[6]:time.sleep(1.5)In[15]:result=dev.read("R")In[16]:result.status_codeOut[16]:1In[17]:result.dataOut[17]:b'0.922'In[18]:result.original_cmdOut[18]:'R'The module also provides aquery()method to conveniently wrap the above protocol into a single method:In[19]:result=dev.query("R",processing_delay=1500)In[20]:result.status_codeOut[20]:1In[21]:result.dataOut[21]:b'0.926'In[22]:result.original_cmdOut[22]:'R'The result of calling theread()andquery()methods in the above code snippets is aCommandReponseobject. Here is an example of creating aCommandResponseobject manually and populating it:In[1]:fromatlas_i2cimportatlas_i2cIn[2]:response=atlas_i2c.CommandResponse()In[3]:responseOut[3]:<atlas_i2c.atlas_i2c.CommandResponseat0x7fbd40f48370>In[6]:response.sensor_address=10In[7]:response.sensor_address=102In[8]:response.original_cmd="R"In[9]:response.response_type="str"In[10]:response.status_code=raw_data[0]module: commandsThecommandsmodule provides encapsulations intended to simplify interactions with sensors. Command attributes and methods can be accessed at the class level, thus it's not necessary to instantiate a command.The module defines constants for each command class:In[19]:fromatlas_i2cimportcommands# To find the arguments a command supports:In[24]:commands.BAUD.argumentsOut[24]:(300,1200,2400,9600,19200,38400,57600,115200)# To get a formatted command string:In[25]:commands.BAUD.format_command(300)Out[25]:'Baud,300'# A command may not support any arguments:In[24]:commands.READ.argumentsIn[25]:Not all commands have been implemented. Theformat_commandmethod on unimplemented commands will raise aNotImplementedErrorexception.module: sensorsThesensorsmodule provides a higher-level encapsulation of a sensor in the form of theSensorclass. The intention is that theSensorclass is used as the primary means of communication; it uses the lower-levelAtlasI2Cclass to perform all functions, such as reading data from a sensor.In[25]:fromatlas_i2cimportsensorsIn[26]:sensor=sensors.Sensor("Temperature",102)In[27]:sensor.connect()In[28]:response=sensor.query(commands.READ)In[29]:response.status_codeOut[29]:1In[30]:response.dataOut[30]:b'0.923'In[31]:response.original_cmdOut[31]:'R'Supported Python VersionsThis module requires Python >= 3.6.Testsatlas_i2cuses Tox for test automation, which includes linting, formatting and static type checking. To run Tox:>tox[outputtruncated]py38:commandssucceeded
py37:commandssucceeded
py36:commandssucceeded
mypy:commandssucceeded
lint:commandssucceeded
format:commandssucceeded
congratulations:)InstallationFrom PyPiInstallation can be done using Pip:>pipinstallatlas-i2cFrom source>pythonsetup.pybdist_wheel
>pipinstalldist/atlas_i2c-$version-py3-none-any.whlAtlas Scientific Sensor DatasheetspHtemporpdoecco2flo