├── .gitignore ├── Csharp └── README.md ├── Install ├── README.md ├── update_functions.sh └── update_sensors.sh ├── LICENSE.md ├── NodeJS ├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .gitignore ├── .travis.yml ├── .vscode │ └── settings.json ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── examples │ └── tempHumPress.js ├── package.json ├── src │ ├── DHT_drivers │ │ ├── .gitignore │ │ ├── LICENSE │ │ ├── README.md │ │ ├── bbb_dht_read.cpp │ │ ├── bbb_dht_read.h │ │ ├── bbb_mmio.cpp │ │ ├── bbb_mmio.h │ │ ├── binding.gyp │ │ ├── common_dht_read.cpp │ │ ├── common_dht_read.h │ │ ├── dht_sensor.cpp │ │ ├── index.js │ │ ├── package.json │ │ ├── pi_2_dht_read.cpp │ │ ├── pi_2_dht_read.h │ │ ├── pi_2_mmio.cpp │ │ ├── pi_2_mmio.h │ │ ├── pi_dht_read.cpp │ │ ├── pi_dht_read.h │ │ ├── pi_mmio.cpp │ │ └── pi_mmio.h │ ├── index.js │ └── sensors │ │ ├── BME280.js │ │ ├── BNO055.js │ │ ├── DHT.js │ │ ├── PCA9570.js │ │ ├── TCS34725.js │ │ ├── VL53L0X.js │ │ ├── base │ │ └── sensor.js │ │ ├── dexterI2c.js │ │ ├── distanceSensor.js │ │ ├── groveRgbLcd.js │ │ ├── inertialMeasurementUnit.js │ │ ├── lightColorSensor.js │ │ └── tempHumPress.js └── test │ └── index.js ├── Python ├── Examples │ ├── DistanceSensorContinuous.py │ ├── DistanceSensorSingleShot.py │ ├── EasyDistanceSensor.py │ ├── EasyDistanceSensorMutexes.py │ ├── EasyLightColorSensor.py │ ├── EasyTempHumPress.py │ ├── IMUSensor.py │ ├── LineFollower.py │ └── TempHumPress.py ├── di_sensors │ ├── BME280.py │ ├── BNO055.py │ ├── DHT.py │ ├── DHT_Sensor │ │ ├── .gitignore │ │ ├── Adafruit_DHT │ │ │ ├── Beaglebone_Black.py │ │ │ ├── Raspberry_Pi.py │ │ │ ├── Raspberry_Pi_2.py │ │ │ ├── Test.py │ │ │ ├── __init__.py │ │ │ ├── common.py │ │ │ └── platform_detect.py │ │ ├── LICENSE │ │ ├── README.md │ │ ├── examples │ │ │ ├── AdafruitDHT.py │ │ │ ├── google_spreadsheet.py │ │ │ └── simpletest.py │ │ ├── ez_setup.py │ │ ├── setup.py │ │ └── source │ │ │ ├── Beaglebone_Black │ │ │ ├── bbb_dht_read.c │ │ │ ├── bbb_dht_read.h │ │ │ ├── bbb_mmio.c │ │ │ └── bbb_mmio.h │ │ │ ├── Raspberry_Pi │ │ │ ├── pi_dht_read.c │ │ │ ├── pi_dht_read.h │ │ │ ├── pi_mmio.c │ │ │ └── pi_mmio.h │ │ │ ├── Raspberry_Pi_2 │ │ │ ├── pi_2_dht_read.c │ │ │ ├── pi_2_dht_read.h │ │ │ ├── pi_2_mmio.c │ │ │ └── pi_2_mmio.h │ │ │ ├── Test │ │ │ ├── test_dht_read.c │ │ │ └── test_dht_read.h │ │ │ ├── _Beaglebone_Black_Driver.c │ │ │ ├── _Raspberry_Pi_2_Driver.c │ │ │ ├── _Raspberry_Pi_Driver.c │ │ │ ├── _Test_Driver.c │ │ │ ├── common_dht_read.c │ │ │ └── common_dht_read.h │ ├── PCA9570.py │ ├── TCS34725.py │ ├── VL53L0X.py │ ├── __init__.py │ ├── dexter_i2c.py │ ├── distance_sensor.py │ ├── easy_distance_sensor.py │ ├── easy_inertial_measurement_unit.py │ ├── easy_light_color_sensor.py │ ├── easy_line_follower.py │ ├── easy_mutex.py │ ├── easy_temp_hum_press.py │ ├── grove_rgb_lcd │ │ ├── __init__.py │ │ ├── example.py │ │ ├── example2.py │ │ ├── example3.py │ │ └── grove_rgb_lcd.py │ ├── inertial_measurement_unit.py │ ├── light_color_sensor.py │ ├── line_follower.py │ ├── line_follower_calibration │ │ ├── line_follower_calibration.desktop │ │ ├── line_sensor_calibration_gui.py │ │ ├── obconf.png │ │ └── obconf.xpm │ ├── red_line_follower │ │ ├── line_follower │ │ │ ├── README.md │ │ │ ├── __init__.py │ │ │ ├── basic_example.py │ │ │ ├── black_line.txt │ │ │ ├── check_line_sensor.py │ │ │ ├── line_follow.desktop │ │ │ ├── line_follow.py │ │ │ ├── line_follow1.py │ │ │ ├── line_position.py │ │ │ ├── line_sensor.py │ │ │ ├── line_sensor_gui.py │ │ │ ├── line_threshold_set.py │ │ │ ├── obconf.xpm │ │ │ ├── range_line.txt │ │ │ ├── scratch_line.py │ │ │ └── white_line.txt │ │ └── setup.py │ └── temp_hum_press.py ├── package_description.rst └── setup.py ├── README.md ├── Scratch ├── diSensorsScratch.py └── di_sensorscommands.png ├── docs ├── Makefile ├── make.bat └── source │ ├── about.rst │ ├── api-advanced.rst │ ├── api-basic.rst │ ├── conf.py │ ├── devguide.rst │ ├── examples │ ├── basic_lf.rst │ ├── dist_sensor.rst │ ├── imu.rst │ ├── index.rst │ ├── light_color.rst │ ├── mutexes.rst │ └── temp_hum.rst │ ├── faq.rst │ ├── images │ ├── dexterlogo_big.jpg │ ├── dexterlogo_small.jpg │ ├── quickstart1.png │ └── quickstart2.jpg │ ├── index.rst │ ├── quickstart.rst │ └── structure.rst ├── environment.yml └── readthedocs.yml /.gitignore: -------------------------------------------------------------------------------- 1 | docs/build/* 2 | *.pyc 3 | *.json 4 | .vscode/.ropeproject/config.py 5 | .vscode/.ropeproject/objectdb 6 | -------------------------------------------------------------------------------- /Csharp/README.md: -------------------------------------------------------------------------------- 1 | # .NET Core IoT implementation for Dexter Industries Sensors 2 | 3 | You will find a full implantation of Dexter Industries Sensors on [.NET Core IoT repository](https://github.com/dotnet/iot). You will be able to program GoPiGo, GrovePi, and BrickPi using C#. The full documentation and example is located into the main repository. 4 | 5 | .NET Core is open source. .NET Core is best thought of as 'agile .NET'. Generally speaking it is the same as the Desktop .NET Framework distributed as part of the Windows operating system, but it is a cross platform (Windows, Linux, macOS) and cross architecture (x86, x64, ARM) subset that can be deployed as part of the application (if desired), and thus can be updated quickly to fix bugs or add features. It is a perfect fit for boards like Raspberry running Raspbian. Check the [.NET Core IoT documentation](https://github.com/dotnet/iot/tree/master/Documentation) if you are not familiar with .NET Core. 6 | 7 | Compatibility 8 | ------------- 9 | 10 | The following Grove compatible devices are supported in .NET Core IoT: 11 | 12 | * Dexter Industries: 13 | * **[Distance Sensor](https://www.dexterindustries.com/shop/distance-sensor/)** - Distance Sensor for the GoPiGo, GrovePi, and BrickPi. The distance sensor can be mounted to the GoPiGo Raspberry Pi robot with or without the servo package to enable rotation. The sensor detects distances from obstacles and objects, giving your robot the ability to navigate. You will find this code under [VL53L0X implementation](https://github.com/dotnet/iot/tree/master/src/devices/Vl53L0X). A [full sample](https://github.com/dotnet/iot/tree/master/src/devices/Vl53L0X/samples) is provided as well. 14 | 15 | * **[Inertial Measurement Unit Sensor](https://www.dexterindustries.com/shop/imu-sensor/)** - The IMU Sensor attaches to the GrovePi, GoPiGo and BrickPi to detect motion, orientation, and position of your robot. It has a compass, accelerometer, and gyroscope and allows you to build a BalanceBot. You will find this code under [BNO055 implementation](https://github.com/dotnet/iot/tree/master/src/devices/Bno055). A [full sample](https://github.com/dotnet/iot/tree/master/src/devices/Bno055/samples) is provided as well. 16 | 17 | * **[Light Color Sensor](https://www.dexterindustries.com/shop/light-color-sensor/)** - The Light & Color Sensor attaches to the GrovePi, GoPiGo and BrickPi to measure light levels and detect different colors. It can be used to build projects like a rubiks cube solver, weather station, or plant monitoring station. You will find this code under [Bmx280 implementation](https://github.com/dotnet/iot/tree/master/src/devices/Bmx280). A [full sample](https://github.com/dotnet/iot/tree/master/src/devices/Bmx280/samples) is provided as well. Please make sure you will use the BME280 implemnation. Usage is describe in the [example here](https://github.com/dotnet/iot/tree/master/src/devices/Bmx280/samples/Bme280.sample.cs). 18 | 19 | * **[Temperature Humidity Pressure Sensor](https://www.dexterindustries.com/shop/temperature-humidity-pressure-sensor/)**- The Temperature Humidity and Pressure Sensor attaches to the GrovePi, GoPiGo and BrickPi to measure environmental conditions. It can be used to build projects like a classroom weather station or plant monitoring station. You will find this code under [BNO055 implementation](https://github.com/dotnet/iot/tree/master/src/devices/Bno055). A [full sample](https://github.com/dotnet/iot/tree/master/src/devices/Bno055/samples) is provided as well. 20 | -------------------------------------------------------------------------------- /Install/README.md: -------------------------------------------------------------------------------- 1 | ## Installing 2 | 3 | You need internet access for the following step(s). 4 | 5 | The quickest way for installing the DI_Sensors is to enter the following command: 6 | ``` 7 | curl -kL dexterindustries.com/update_sensors | bash 8 | ``` 9 | 10 | By default, the DI_Sensors package is installed system-wide and [script_tools](https://github.com/DexterInd/script_tools) and [RFR_Tools](https://github.com/DexterInd/RFR_Tools) are updated each time the script is ran. 11 | 12 | An example using options appended to the command can be: 13 | ``` 14 | curl -kL dexterindustries.com/update_sensors | bash -s --user-local --no-update-aptget --no-dependencies 15 | ``` 16 | 17 | ## Command Options 18 | 19 | The options that can be appended to this command are: 20 | 21 | 22 | * `--no-update-aptget` - to skip using `sudo apt-get update` before installing dependencies. For this to be useful, `--no-dependencies` has to be not used. Applies to RFR_Tools and the DI-Sensors. 23 | * `--bypass-rfrtools` - skips installing RFR_Tools completely. 24 | * `--bypass-python-rfrtools` - skips installing/updating the python package for [RFR_Tools](https://github.com/DexterInd/RFR_Tools). 25 | * `--bypass-gui-installation` - skips installing the GUI packages/dependencies from [RFR_Tools](https://github.com/DexterInd/RFR_Tools). 26 | * `--no-dependencies` - skip installing any dependencies for the DI-Sensors. It's supposed to be used on each consecutive update after the initial install has gone through. 27 | * `--user-local` - install the python package for the DI-Sensors in the home directory of the user. This doesn't require any special read/write permissions: the actual command used is (`python setup.py install --force --user`). 28 | * `--env-local` - install the python package for the DI-Sensors within the given environment without elevated privileges: the actual command used is (`python setup.py install --force`). 29 | * `--system-wide` - install the python package for the DI-Sensors within the sytem-wide environment with `sudo`: the actual command used is (`sudo python setup.py install --force`). 30 | 31 | Important to remember is that `--user-local`, `--env-local` and `--system-wide` options are all mutually-exclusive - they cannot be used together. 32 | As a last thing, different versions of it can be pulled by appending a corresponding branch name or tag. 33 | 34 | ## Minimal Installation 35 | 36 | Now, if you only want the absolute minimum in order to get going with the DI-Sensors, you can run this command: 37 | ```bash 38 | curl -kL dexterindustries.com/update_sensors | bash -s -- --bypass-gui-installation 39 | ``` 40 | 41 | This will only get you installed the DI-Sensors dependencies and nothing else. You still can use options such as `--user-local` or `--env-local` if you are working with a different kind of environment. Keep in mind that `--system-wide` is selected by default. 42 | 43 | ## Subsequent Updates 44 | 45 | If the DI-Sensors has been installed either by using the full command or the one for the minimal installation, this means you have all the packages installed already and all dependencies put in. Therefore, on subsequent installation, you can skip installing any dependency and instead just reinstall the python package of the DI-Sensors. To do this, you can run this command: 46 | ```bash 47 | curl -kL dexterindustries.com/update_sensors | bash -s -- --bypass-rfrtools --no-dependencies 48 | ``` 49 | 50 | Or if this is too complex, you can always stick to the command meant for the full installation or the minimal one. 51 | -------------------------------------------------------------------------------- /Install/update_functions.sh: -------------------------------------------------------------------------------- 1 | PIHOME=/home/pi 2 | DEXTER=Dexter 3 | DEXTER_PATH=$PIHOME/$DEXTER 4 | SCRIPT_TOOLS=$DEXTER_PATH/lib/Dexter/script_tools 5 | 6 | source $SCRIPT_TOOLS/functions_library.sh 7 | 8 | configure_line_follower(){ 9 | # Install Line Follower Calibration 10 | if [ -d /home/pi/Desktop ]; then 11 | delete_file $PIHOME/Desktop/line_follow.desktop 12 | delete_file $PIHOME/Desktop/line_follower_calibration.desktop 13 | sudo cp $PIHOME/$DEXTER/DI_Sensors/Python/di_sensors/line_follower_calibration/line_follower_calibration.desktop $PIHOME/Desktop/ 14 | sudo chmod +x $PIHOME/Desktop/line_follower_calibration.desktop 15 | sudo chmod +x $PIHOME/Dexter/DI_Sensors/Python/di_sensors/line_follower_calibration/line_sensor_calibration_gui.py 16 | fi 17 | 18 | # if the configuration files exist in the home directory 19 | # then move them to their new place 20 | # otherwise create new ones 21 | if file_exists "$PIHOME/black_line.txt" 22 | then 23 | sudo mv $PIHOME/black_line.txt $PIHOME/Dexter/black_line.txt 24 | else 25 | sudo cp $PIHOME/Dexter/DI_Sensors/Python/di_sensors/red_line_follower/line_follower/black_line.txt $PIHOME/Dexter/black_line.txt 26 | fi 27 | 28 | if file_exists "$PIHOME/white_line.txt" 29 | then 30 | sudo mv $PIHOME/white_line.txt $PIHOME/Dexter/white_line.txt 31 | else 32 | sudo cp $PIHOME/Dexter/DI_Sensors/Python/di_sensors/red_line_follower/line_follower/white_line.txt $PIHOME/Dexter/white_line.txt 33 | fi 34 | if file_exists "$PIHOME/range_line.txt" 35 | then 36 | sudo mv $PIHOME/range_line.txt $PIHOME/Dexter/range_line.txt 37 | else 38 | sudo cp $PIHOME/Dexter/DI_Sensors/Python/di_sensors/red_line_follower/line_follower/range_line.txt $PIHOME/Dexter/range_line.txt 39 | fi 40 | 41 | sudo chmod 666 $PIHOME/Dexter/*line.txt 42 | } 43 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | License Information 2 | =================== 3 | 4 | Software License 5 | ---------------- 6 | 7 | **All code (including all scripts, firmware, drivers, examples, and any other 8 | software) is released under the [MIT License].** 9 | 10 | [MIT License]: http://choosealicense.com/licenses/mit/ 11 | 12 | MIT License 13 | 14 | Copyright (c) 2019 Dexter Industries 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in all 24 | copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 | SOFTWARE. 33 | 34 | 35 | Hardware License 36 | ---------------- 37 | 38 | **Any hardware schematics released are released under the [Creative Commons Attribution 39 | NonCommercial ShareAlike 4.0 License][CC4].** 40 | 41 | [CC4]: https://creativecommons.org/licenses/by-nc-sa/4.0/ 42 | -------------------------------------------------------------------------------- /NodeJS/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["stage-2", "es2015"], 3 | "plugins": [ 4 | "add-module-exports", 5 | "transform-class-properties" 6 | ] 7 | } -------------------------------------------------------------------------------- /NodeJS/.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain 2 | # consistent coding styles between different editors and IDEs. 3 | 4 | root = true 5 | 6 | [*] 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | indent_style = space 12 | indent_size = 4 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /NodeJS/.eslintignore: -------------------------------------------------------------------------------- 1 | test 2 | src/DHT_drivers 3 | -------------------------------------------------------------------------------- /NodeJS/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "extends": "airbnb", 4 | "env": { 5 | "mocha": true 6 | }, 7 | "rules": { 8 | "indent": [ 9 | "error", 10 | 4 11 | ], 12 | "quote-props": ["error", "consistent"], 13 | "no-param-reassign": 0, 14 | "comma-dangle": 0, 15 | "no-plusplus": 0, 16 | "no-underscore-dangle": 0, 17 | "no-continue": 0, 18 | "no-multi-spaces": 0, 19 | "no-bitwise": 0, 20 | "no-self-compare": 0, 21 | "class-methods-use-this": 0, 22 | "no-mixed-operators": 0, 23 | "max-len": 0 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /NodeJS/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | 39 | # Editors 40 | .idea 41 | 42 | # Lib 43 | lib 44 | -------------------------------------------------------------------------------- /NodeJS/.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "6" 4 | script: 5 | - npm run lint 6 | - npm run test 7 | - npm run build 8 | - npm run test:examples 9 | branches: 10 | only: 11 | - master 12 | -------------------------------------------------------------------------------- /NodeJS/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "system_error": "cpp", 4 | "*.tcc": "cpp" 5 | } 6 | } -------------------------------------------------------------------------------- /NodeJS/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # TBD: DexterInd contributing policy -------------------------------------------------------------------------------- /NodeJS/LICENSE.md: -------------------------------------------------------------------------------- 1 | License Information 2 | =================== 3 | 4 | Software License 5 | ---------------- 6 | 7 | **All code (including all scripts, firmware, drivers, examples, and any other 8 | software) is released under the [MIT License].** 9 | 10 | [MIT License]: http://choosealicense.com/licenses/mit/ 11 | 12 | MIT License 13 | 14 | Copyright (c) 2017 Dexter Industries 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in all 24 | copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 | SOFTWARE. 33 | 34 | 35 | Hardware License 36 | ---------------- 37 | 38 | **Any hardware schematics released are released under the [Creative Commons Attribution 39 | NonCommercial ShareAlike 4.0 License][CC4].** 40 | 41 | [CC4]: https://creativecommons.org/licenses/by-nc-sa/4.0/ 42 | -------------------------------------------------------------------------------- /NodeJS/README.md: -------------------------------------------------------------------------------- 1 | Node.js DI_Sensors 2 | ============ 3 | Dexter Industries Sensors 4 | 5 | Compatibility 6 | ------------- 7 | 8 | The following Grove compatible devices are supported: 9 | 10 | * Dexter Industries: 11 | * Distance Sensor 12 | * Inertial Measurement Unit Sensor 13 | * Light Color Sensor 14 | * Temperature Humidity Pressure Sensor 15 | * Grove: 16 | * RGB LCD 17 | 18 | Notes for developers 19 | ======= 20 | 21 | # Features 22 | * Build with [Babel](https://babeljs.io). (ES6 -> ES5) 23 | * Test with [mocha](https://mochajs.org). 24 | * Cover with [istanbul](https://github.com/gotwarlost/istanbul). 25 | * Check with [eslint](eslint.org). 26 | * Deploy with [Travis](travis-ci.org). 27 | 28 | # Commands 29 | - `npm run clean` - Remove `lib/` directory 30 | - `npm test` - Run tests. Tests can be written with ES6 (WOW!) 31 | - `npm test:watch` - You can even re-run tests on file changes! 32 | - `npm run cover` - Yes. You can even cover ES6 code. 33 | - `npm run lint` - We recommend using [airbnb-config](https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb). It's fantastic. 34 | - `npm run test:examples` - We recommend writing examples on pure JS for better understanding module usage. 35 | - `npm run build` - Do some magic with ES6 to create ES5 code. 36 | - `npm run prepublish` - Hook for npm. Do all the checks before publishing you module. 37 | 38 | License 39 | ------- 40 | 41 | Please review the [LICENSE.md] file for license information. 42 | 43 | [LICENSE.md]: ./LICENSE.md 44 | -------------------------------------------------------------------------------- /NodeJS/examples/tempHumPress.js: -------------------------------------------------------------------------------- 1 | const TempHumPress = require('../lib').TempHumPress; 2 | 3 | const sensor = new TempHumPress('RPI_1'); 4 | 5 | console.log('BME280 values', 6 | 'Temp', 7 | sensor.getTemperatureCelsius(), 8 | 'Press', 9 | sensor.getPressure(), 10 | 'Hum', 11 | sensor.getHumidity() 12 | ); 13 | -------------------------------------------------------------------------------- /NodeJS/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "di-sensors", 3 | "version": "0.0.3", 4 | "description": "Drivers and examples for using DI_Sensors in Node.js", 5 | "scripts": { 6 | "clean": "rimraf lib", 7 | "test": "cross-env BABEL_ENV=commonjs mocha --compilers js:babel-register --recursive", 8 | "test:watch": "npm test -- --watch", 9 | "test:examples": "node examples/", 10 | "cover": "cross-env BABEL_ENV=commonjs istanbul cover _mocha -- --compilers js:babel-register --recursive", 11 | "lint": "eslint src test", 12 | "build": "cross-env BABEL_ENV=commonjs babel src --out-dir lib", 13 | "prepublish": "npm run clean && npm run lint && npm run build && npm run test" 14 | }, 15 | "main": "lib/index.js", 16 | "files": [ 17 | "lib", 18 | "src" 19 | ], 20 | "repository": { 21 | "type": "git", 22 | "url": "git+https://github.com/marcellobarile/DI_Sensors.git" 23 | }, 24 | "keywords": [ 25 | "Dexter", 26 | "Distance Sensor", 27 | "Inertial Measurement Unit", 28 | "IMU", 29 | "Light Color Sensor", 30 | "Temperature Humidity Pressure Sensor", 31 | "RGB LCD", 32 | "DHT Sensor" 33 | ], 34 | "author": "Marcello Barile (http://www.barile.eu)", 35 | "license": "MIT", 36 | "bugs": { 37 | "url": "https://github.com/marcellobarile/DI_Sensors/issues" 38 | }, 39 | "homepage": "https://github.com/marcellobarile/DI_Sensors#readme", 40 | "devDependencies": { 41 | "babel": "^6.5.2", 42 | "babel-cli": "^6.14.0", 43 | "babel-eslint": "^7.0.0", 44 | "babel-plugin-add-module-exports": "^0.2.1", 45 | "babel-plugin-transform-class-properties": "^6.24.1", 46 | "babel-preset-es2015": "^6.14.0", 47 | "babel-preset-stage-2": "^6.13.0", 48 | "chai": "^3.5.0", 49 | "cross-env": "^3.0.0", 50 | "eslint": "^3.6.0", 51 | "eslint-config-airbnb": "^13.0.0", 52 | "eslint-plugin-import": "^2.0.0", 53 | "eslint-plugin-jsx-a11y": "^2.2.2", 54 | "eslint-plugin-react": "^6.3.0", 55 | "istanbul": "^1.0.0-alpha", 56 | "mocha": "^3.0.2", 57 | "rimraf": "^2.5.4" 58 | }, 59 | "dependencies": { 60 | "spi-device": "^0.2.6", 61 | "i2c-bus": "^1.2.2", 62 | "sleep": "^5.1.1", 63 | "mathjs": ">=7.5.1", 64 | "lodash": "^4.17.4", 65 | "lock-me": "^1.0.2", 66 | "dht-drivers": "^0.0.2" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | build -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/LICENSE: -------------------------------------------------------------------------------- 1 | License Information 2 | =================== 3 | 4 | Software License 5 | ---------------- 6 | 7 | **All code (including all scripts, firmware, drivers, examples, and any other 8 | software) is released under the [MIT License].** 9 | 10 | [MIT License]: http://choosealicense.com/licenses/mit/ 11 | 12 | MIT License 13 | 14 | Copyright (c) 2017 Dexter Industries 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in all 24 | copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 | SOFTWARE. 33 | 34 | 35 | Hardware License 36 | ---------------- 37 | 38 | **Any hardware schematics released are released under the [Creative Commons Attribution 39 | NonCommercial ShareAlike 4.0 License][CC4].** 40 | 41 | [CC4]: https://creativecommons.org/licenses/by-nc-sa/4.0/ 42 | -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/README.md: -------------------------------------------------------------------------------- 1 | # dht-drivers 2 | node.js module to read the DHT series of humidity and temperature sensors. 3 | 4 | ### Example 5 | ``` javascript 6 | const dht = require('dht-drivers'); 7 | const current = dht.read(2, 11, 15); // 2: RaspberryPi (platform ID), 11: DHT11 (module type), 15: (pin) 8 | 9 | console.log(current.humidity); 10 | console.log(current.temperature); 11 | ``` 12 | ### Reference 13 | https://github.com/adafruit/Adafruit_Python_DHT 14 | -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/bbb_dht_read.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #ifndef BBB_DHT_READ_H 22 | #define BBB_DHT_READ_H 23 | 24 | #include "common_dht_read.h" 25 | 26 | // Read DHT sensor connected to GPIO bin GPIO_, for example P8_11 is GPIO1_13 with 27 | // base = 1 and number = 13. Humidity and temperature will be returned in the provided parameters. 28 | // If a successfull reading could be made a value of 0 (DHT_SUCCESS) will be returned. If there 29 | // was an error reading the sensor a negative value will be returned. Some errors can be ignored 30 | // and retried, specifically DHT_ERROR_TIMEOUT or DHT_ERROR_CHECKSUM. 31 | extern "C" { 32 | int bbb_dht_read(int type, int gpio_base, int gpio_number, float* humidity, float* temperature); 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/bbb_mmio.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "bbb_mmio.h" 29 | 30 | #define GPIO_LENGTH 4096 31 | #define GPIO0_ADDR 0x44E07000 32 | #define GPIO1_ADDR 0x4804C000 33 | #define GPIO2_ADDR 0x481AC000 34 | #define GPIO3_ADDR 0x481AF000 35 | 36 | // Store mapping of GPIO base number to GPIO address. 37 | static uint32_t gpio_addresses[4] = { GPIO0_ADDR, GPIO1_ADDR, GPIO2_ADDR, GPIO3_ADDR }; 38 | 39 | // Cache memory-mapped GPIO addresses. 40 | static volatile uint32_t* gpio_base[4] = { NULL }; 41 | 42 | int bbb_mmio_get_gpio(int base, int number, gpio_t* gpio) { 43 | // Validate input parameters. 44 | if (gpio == NULL) { 45 | return MMIO_ERROR_ARGUMENT; 46 | } 47 | if (base < 0 || base > 3) { 48 | return MMIO_ERROR_ARGUMENT; 49 | } 50 | if (number < 0 || number > 31) { 51 | return MMIO_ERROR_ARGUMENT; 52 | } 53 | // Map GPIO memory if its hasn't been mapped already. 54 | if (gpio_base[base] == NULL) { 55 | int fd = open("/dev/mem", O_RDWR | O_SYNC); 56 | if (fd == -1) { 57 | // Error opening /dev/mem. Probably not running as root. 58 | return MMIO_ERROR_DEVMEM; 59 | } 60 | // Map GPIO memory to location in process space. 61 | gpio_base[base] = (uint32_t*)mmap(NULL, GPIO_LENGTH, PROT_READ | PROT_WRITE, MAP_SHARED, fd, gpio_addresses[base]); 62 | if (gpio_base[base] == MAP_FAILED) { 63 | // Don't save the result if the memory mapping failed. 64 | gpio_base[base] = NULL; 65 | return MMIO_ERROR_MMAP; 66 | } 67 | } 68 | // Initialize and set GPIO fields. 69 | memset(gpio, 0, sizeof(gpio)); 70 | gpio->base = gpio_base[base]; 71 | gpio->number = number; 72 | return MMIO_SUCCESS; 73 | } 74 | -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/bbb_mmio.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | 22 | // Simple fast memory-mapped GPIO library for the Beaglebone Black. 23 | // Allows reading and writing GPIO at very high speeds, up to ~2.6mhz! 24 | 25 | /* 26 | // Example usage: 27 | 28 | #include 29 | #include "bbb_mmio.h" 30 | 31 | int main(int argc, char* argv[]) { 32 | // Get GPIO pin. 33 | // See the giant table of of pins in the system reference manual for details 34 | // on the base and number for a given GPIO: 35 | // https://github.com/CircuitCo/BeagleBone-Black/blob/master/BBB_SRM.pdf?raw=true 36 | // Section 7 Connectors, table 12 shows P8_11 maps to GPIO1_13, so 1 is the 37 | // gpio base and 13 is the gpio number. 38 | gpio_t p8_11; 39 | if (bbb_mmio_get_gpio(1, 13, &p8_11) < 0) { 40 | printf("Couldn't get requested GPIO pin!\n"); 41 | return 1; 42 | } 43 | // Set pin as output. 44 | bbb_mmio_set_output(p8_11); 45 | // Toggle the pin high and low as fast as possible. 46 | // This generates a signal at about 2.6mhz in my tests. 47 | // Each pulse high/low is only about 200 nanoseconds long! 48 | while (1) { 49 | bbb_mmio_set_high(p8_11); 50 | bbb_mmio_set_low(p8_11); 51 | } 52 | return 0; 53 | } 54 | 55 | */ 56 | 57 | #ifndef BBB_MMIO_H 58 | #define BBB_MMIO_H 59 | 60 | #include 61 | 62 | #define MMIO_SUCCESS 0 63 | #define MMIO_ERROR_ARGUMENT -1 64 | #define MMIO_ERROR_DEVMEM -2 65 | #define MMIO_ERROR_MMAP -3 66 | 67 | #define MMIO_OE_ADDR 0x134 68 | #define MMIO_GPIO_DATAOUT 0x13C 69 | #define MMIO_GPIO_DATAIN 0x138 70 | #define MMIO_GPIO_CLEARDATAOUT 0x190 71 | #define MMIO_GPIO_SETDATAOUT 0x194 72 | 73 | // Define struct to represent a GPIO pin based on its base memory address and number. 74 | typedef struct { 75 | volatile uint32_t* base; 76 | int number; 77 | } gpio_t; 78 | 79 | extern "C" { 80 | int bbb_mmio_get_gpio(int base, int number, gpio_t* gpio); 81 | } 82 | 83 | extern "C" { 84 | static inline void bbb_mmio_set_output(gpio_t gpio) { 85 | gpio.base[MMIO_OE_ADDR/4] &= (0xFFFFFFFF ^ (1 << gpio.number)); 86 | } 87 | } 88 | 89 | extern "C" { 90 | static inline void bbb_mmio_set_input(gpio_t gpio) { 91 | gpio.base[MMIO_OE_ADDR/4] |= (1 << gpio.number); 92 | } 93 | } 94 | 95 | extern "C" { 96 | static inline void bbb_mmio_set_high(gpio_t gpio) { 97 | gpio.base[MMIO_GPIO_SETDATAOUT/4] = 1 << gpio.number; 98 | } 99 | } 100 | 101 | extern "C" { 102 | static inline void bbb_mmio_set_low(gpio_t gpio) { 103 | gpio.base[MMIO_GPIO_CLEARDATAOUT/4] = 1 << gpio.number; 104 | } 105 | } 106 | 107 | extern "C" { 108 | static inline uint32_t bbb_mmio_input(gpio_t gpio) { 109 | return gpio.base[MMIO_GPIO_DATAIN/4] & (1 << gpio.number); 110 | } 111 | } 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | "target_name": "dht-sensor", 5 | "sources": [ 6 | "dht_sensor.cpp", 7 | "common_dht_read.cpp", 8 | "pi_2_dht_read.cpp", 9 | "pi_2_mmio.cpp", 10 | "pi_dht_read.cpp", 11 | "pi_mmio.cpp", 12 | "bbb_dht_read.cpp", 13 | "bbb_mmio.cpp" 14 | ] 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/common_dht_read.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "common_dht_read.h" 28 | 29 | void busy_wait_milliseconds(uint32_t millis) { 30 | // Set delay time period. 31 | struct timeval deltatime; 32 | deltatime.tv_sec = millis / 1000; 33 | deltatime.tv_usec = (millis % 1000) * 1000; 34 | struct timeval walltime; 35 | // Get current time and add delay to find end time. 36 | gettimeofday(&walltime, NULL); 37 | struct timeval endtime; 38 | timeradd(&walltime, &deltatime, &endtime); 39 | // Tight loop to waste time (and CPU) until enough time as elapsed. 40 | while (timercmp(&walltime, &endtime, <)) { 41 | gettimeofday(&walltime, NULL); 42 | } 43 | } 44 | 45 | void sleep_milliseconds(uint32_t millis) { 46 | struct timespec sleep; 47 | sleep.tv_sec = millis / 1000; 48 | sleep.tv_nsec = (millis % 1000) * 1000000L; 49 | while (clock_nanosleep(CLOCK_MONOTONIC, 0, &sleep, &sleep) && errno == EINTR); 50 | } 51 | 52 | void set_max_priority(void) { 53 | struct sched_param sched; 54 | memset(&sched, 0, sizeof(sched)); 55 | // Use FIFO scheduler with highest priority for the lowest chance of the kernel context switching. 56 | sched.sched_priority = sched_get_priority_max(SCHED_FIFO); 57 | sched_setscheduler(0, SCHED_FIFO, &sched); 58 | } 59 | 60 | void set_default_priority(void) { 61 | struct sched_param sched; 62 | memset(&sched, 0, sizeof(sched)); 63 | // Go back to default scheduler with default 0 priority. 64 | sched.sched_priority = 0; 65 | sched_setscheduler(0, SCHED_OTHER, &sched); 66 | } 67 | -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/common_dht_read.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #ifndef COMMON_DHT_READ_H 22 | #define COMMON_DHT_READ_H 23 | 24 | #include 25 | 26 | // Define errors and return values. 27 | #define DHT_ERROR_TIMEOUT -1 28 | #define DHT_ERROR_CHECKSUM -2 29 | #define DHT_ERROR_ARGUMENT -3 30 | #define DHT_ERROR_GPIO -4 31 | #define DHT_SUCCESS 0 32 | 33 | // Define sensor types. 34 | #define DHT11 11 35 | #define DHT22 22 36 | #define AM2302 22 37 | 38 | // Busy wait delay for most accurate timing, but high CPU usage. 39 | // Only use this for short periods of time (a few hundred milliseconds at most)! 40 | extern "C" { 41 | void busy_wait_milliseconds(uint32_t millis); 42 | } 43 | 44 | // General delay that sleeps so CPU usage is low, but accuracy is potentially bad. 45 | extern "C" { 46 | void sleep_milliseconds(uint32_t millis); 47 | } 48 | 49 | // Increase scheduling priority and algorithm to try to get 'real time' results. 50 | extern "C" { 51 | void set_max_priority(void); 52 | } 53 | 54 | // Drop scheduling priority back to normal/default. 55 | extern "C" { 56 | void set_default_priority(void); 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/dht_sensor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pi_2_dht_read.h" 3 | #include "pi_dht_read.h" 4 | #include "bbb_dht_read.h" 5 | 6 | namespace dht { 7 | 8 | using v8::FunctionCallbackInfo; 9 | using v8::Isolate; 10 | using v8::Local; 11 | using v8::Object; 12 | using v8::String; 13 | using v8::Value; 14 | using v8::Number; 15 | using v8::Exception; 16 | 17 | void Method(const FunctionCallbackInfo& args) { 18 | Isolate* isolate = args.GetIsolate(); 19 | 20 | int platform = args[0]->IntegerValue(); 21 | int sensor = args[1]->IntegerValue(); 22 | int pin = args[2]->IntegerValue(); 23 | int gpio_number = args[3]->IntegerValue(); 24 | 25 | float humidity; 26 | float temperature; 27 | 28 | int errorCode = 0; 29 | if (platform == 0) { 30 | // pin is gpio_base in this case 31 | errorCode = bbb_dht_read(sensor, pin, gpio_number, &humidity, &temperature); 32 | } else if (platform == 1) { 33 | errorCode = pi_dht_read(sensor, pin, &humidity, &temperature); 34 | } else if (platform == 2) { 35 | errorCode = pi_2_dht_read(sensor, pin, &humidity, &temperature); 36 | } 37 | 38 | if (errorCode == DHT_ERROR_GPIO) { 39 | isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Error accessing GPIO."))); 40 | return; 41 | } 42 | else if (errorCode != DHT_SUCCESS) { 43 | isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Could not read data from DHT sensor."))); 44 | return; 45 | } 46 | 47 | Local obj = Object::New(isolate); 48 | obj->Set(String::NewFromUtf8(isolate, "humidity"), Number::New(isolate, humidity)); 49 | obj->Set(String::NewFromUtf8(isolate, "temperature"), Number::New(isolate, temperature)); 50 | args.GetReturnValue().Set(obj); 51 | } 52 | 53 | void init(Local exports) { 54 | NODE_SET_METHOD(exports, "read", Method); 55 | } 56 | 57 | NODE_MODULE(addon, init) 58 | 59 | } // namespace demo 60 | -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/index.js: -------------------------------------------------------------------------------- 1 | var dht = require('bindings')('dht-sensor'); 2 | 3 | // read(platform, sensor, pin | gpio_base, gpio_number?) 4 | // platform: 0 = Beaglebone, 1 = RaspberryPi, 2 = RaspberryPi2 5 | // sensor: 11 = DHT11, 22 = DHT22, 22 = AM2302 6 | // pin | gpio_base: whatever :) 7 | // gpio_number: only for BBB 8 | exports.read = dht.read; 9 | -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dht-drivers", 3 | "version": "0.0.2", 4 | "description": "Node.js module to read the DHT series of humidity and temperature sensors on a Raspberry Pi.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "gypfile": true, 10 | "dependencies": { 11 | "bindings": "~1.2.1" 12 | }, 13 | "keywords": [ 14 | "dht" 15 | ], 16 | "author": "Marcello Barile ", 17 | "license": "MIT" 18 | } 19 | -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/pi_2_dht_read.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #ifndef PI_2_DHT_READ_H 22 | #define PI_2_DHT_READ_H 23 | 24 | #include "common_dht_read.h" 25 | 26 | // Read DHT sensor connected to GPIO pin (using BCM numbering). Humidity and temperature will be 27 | // returned in the provided parameters. If a successfull reading could be made a value of 0 28 | // (DHT_SUCCESS) will be returned. If there was an error reading the sensor a negative value will 29 | // be returned. Some errors can be ignored and retried, specifically DHT_ERROR_TIMEOUT or DHT_ERROR_CHECKSUM. 30 | extern "C" { 31 | int pi_2_dht_read(int sensor, int pin, float* humidity, float* temperature); 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/pi_2_mmio.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | // Based on code from Gert van Loo & Dom: http://elinux.org/RPi_Low-level_peripherals#GPIO_Code_examples 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "pi_2_mmio.h" 32 | 33 | #define GPIO_BASE_OFFSET 0x200000 34 | #define GPIO_LENGTH 4096 35 | 36 | volatile uint32_t* pi_2_mmio_gpio = NULL; 37 | 38 | int pi_2_mmio_init(void) { 39 | if (pi_2_mmio_gpio == NULL) { 40 | // Check for GPIO and peripheral addresses from device tree. 41 | // Adapted from code in the RPi.GPIO library at: 42 | // http://sourceforge.net/p/raspberry-gpio-python/ 43 | FILE *fp = fopen("/proc/device-tree/soc/ranges", "rb"); 44 | if (fp == NULL) { 45 | return MMIO_ERROR_OFFSET; 46 | } 47 | fseek(fp, 4, SEEK_SET); 48 | unsigned char buf[4]; 49 | if (fread(buf, 1, sizeof(buf), fp) != sizeof(buf)) { 50 | return MMIO_ERROR_OFFSET; 51 | } 52 | uint32_t peri_base = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0; 53 | uint32_t gpio_base = peri_base + GPIO_BASE_OFFSET; 54 | fclose(fp); 55 | 56 | int fd = open("/dev/gpiomem", O_RDWR | O_SYNC); 57 | if (fd == -1) { 58 | // Error opening /dev/gpiomem. 59 | return MMIO_ERROR_DEVMEM; 60 | } 61 | // Map GPIO memory to location in process space. 62 | pi_2_mmio_gpio = (uint32_t*)mmap(NULL, GPIO_LENGTH, PROT_READ | PROT_WRITE, MAP_SHARED, fd, gpio_base); 63 | close(fd); 64 | if (pi_2_mmio_gpio == MAP_FAILED) { 65 | // Don't save the result if the memory mapping failed. 66 | pi_2_mmio_gpio = NULL; 67 | return MMIO_ERROR_MMAP; 68 | } 69 | } 70 | return MMIO_SUCCESS; 71 | } 72 | -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/pi_2_mmio.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | // Based on code from Gert van Loo & Dom: http://elinux.org/RPi_Low-level_peripherals#GPIO_Code_examples 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // Simple fast memory-mapped GPIO library for the Raspberry Pi. 24 | #ifndef PI_2_MMIO_H 25 | #define PI_2_MMIO_H 26 | 27 | #include 28 | 29 | #define MMIO_SUCCESS 0 30 | #define MMIO_ERROR_DEVMEM -1 31 | #define MMIO_ERROR_MMAP -2 32 | #define MMIO_ERROR_OFFSET -3 33 | 34 | extern volatile uint32_t* pi_2_mmio_gpio; 35 | 36 | extern "C" { 37 | int pi_2_mmio_init(void); 38 | } 39 | 40 | extern "C" { 41 | static inline void pi_2_mmio_set_input(const int gpio_number) { 42 | // Set GPIO register to 000 for specified GPIO number. 43 | *(pi_2_mmio_gpio+((gpio_number)/10)) &= ~(7<<(((gpio_number)%10)*3)); 44 | } 45 | } 46 | 47 | extern "C" { 48 | static inline void pi_2_mmio_set_output(const int gpio_number) { 49 | // First set to 000 using input function. 50 | pi_2_mmio_set_input(gpio_number); 51 | // Next set bit 0 to 1 to set output. 52 | *(pi_2_mmio_gpio+((gpio_number)/10)) |= (1<<(((gpio_number)%10)*3)); 53 | } 54 | } 55 | 56 | extern "C" { 57 | static inline void pi_2_mmio_set_high(const int gpio_number) { 58 | *(pi_2_mmio_gpio+7) = 1 << gpio_number; 59 | } 60 | } 61 | 62 | extern "C" { 63 | static inline void pi_2_mmio_set_low(const int gpio_number) { 64 | *(pi_2_mmio_gpio+10) = 1 << gpio_number; 65 | } 66 | } 67 | 68 | static inline uint32_t pi_2_mmio_input(const int gpio_number) { 69 | return *(pi_2_mmio_gpio+13) & (1 << gpio_number); 70 | } 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/pi_dht_read.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #ifndef PI_DHT_READ_H 22 | #define PI_DHT_READ_H 23 | 24 | #include "common_dht_read.h" 25 | 26 | // Read DHT sensor connected to GPIO pin (using BCM numbering). Humidity and temperature will be 27 | // returned in the provided parameters. If a successfull reading could be made a value of 0 28 | // (DHT_SUCCESS) will be returned. If there was an error reading the sensor a negative value will 29 | // be returned. Some errors can be ignored and retried, specifically DHT_ERROR_TIMEOUT or DHT_ERROR_CHECKSUM. 30 | extern "C" { 31 | int pi_dht_read(int sensor, int pin, float* humidity, float* temperature); 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/pi_mmio.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | // Based on code from Gert van Loo & Dom: http://elinux.org/RPi_Low-level_peripherals#GPIO_Code_examples 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "pi_mmio.h" 31 | 32 | #define BASE 0x20000000 33 | #define GPIO_BASE (BASE + 0x200000) 34 | #define GPIO_LENGTH 4096 35 | 36 | volatile uint32_t* pi_mmio_gpio = NULL; 37 | 38 | int pi_mmio_init(void) { 39 | if (pi_mmio_gpio == NULL) { 40 | int fd; 41 | 42 | // On older kernels user readable /dev/gpiomem might not exists. 43 | // Falls back to root-only /dev/mem. 44 | if( access( "/dev/gpiomem", F_OK ) != -1 ) { 45 | fd = open("/dev/gpiomem", O_RDWR | O_SYNC); 46 | } else { 47 | fd = open("/dev/mem", O_RDWR | O_SYNC); 48 | } 49 | if (fd == -1) { 50 | // Error opening /dev/gpiomem. 51 | return MMIO_ERROR_DEVMEM; 52 | } 53 | // Map GPIO memory to location in process space. 54 | pi_mmio_gpio = (uint32_t*)mmap(NULL, GPIO_LENGTH, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO_BASE); 55 | close(fd); 56 | if (pi_mmio_gpio == MAP_FAILED) { 57 | // Don't save the result if the memory mapping failed. 58 | pi_mmio_gpio = NULL; 59 | return MMIO_ERROR_MMAP; 60 | } 61 | } 62 | return MMIO_SUCCESS; 63 | } 64 | -------------------------------------------------------------------------------- /NodeJS/src/DHT_drivers/pi_mmio.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | // Based on code from Gert van Loo & Dom: http://elinux.org/RPi_Low-level_peripherals#GPIO_Code_examples 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // Simple fast memory-mapped GPIO library for the Raspberry Pi. 24 | #ifndef PI_MMIO_H 25 | #define PI_MMIO_H 26 | 27 | #include 28 | 29 | #define MMIO_SUCCESS 0 30 | #define MMIO_ERROR_DEVMEM -1 31 | #define MMIO_ERROR_MMAP -2 32 | 33 | extern volatile uint32_t* pi_mmio_gpio; 34 | 35 | extern "C" { 36 | int pi_mmio_init(void); 37 | } 38 | 39 | extern "C" { 40 | static inline void pi_mmio_set_input(const int gpio_number) { 41 | // Set GPIO register to 000 for specified GPIO number. 42 | *(pi_mmio_gpio+((gpio_number)/10)) &= ~(7<<(((gpio_number)%10)*3)); 43 | } 44 | } 45 | 46 | extern "C" { 47 | static inline void pi_mmio_set_output(const int gpio_number) { 48 | // First set to 000 using input function. 49 | pi_mmio_set_input(gpio_number); 50 | // Next set bit 0 to 1 to set output. 51 | *(pi_mmio_gpio+((gpio_number)/10)) |= (1<<(((gpio_number)%10)*3)); 52 | } 53 | } 54 | 55 | extern "C" { 56 | static inline void pi_mmio_set_high(const int gpio_number) { 57 | *(pi_mmio_gpio+7) = 1 << gpio_number; 58 | } 59 | } 60 | 61 | extern "C" { 62 | static inline void pi_mmio_set_low(const int gpio_number) { 63 | *(pi_mmio_gpio+10) = 1 << gpio_number; 64 | } 65 | } 66 | 67 | extern "C" { 68 | static inline uint32_t pi_mmio_input(const int gpio_number) { 69 | return *(pi_mmio_gpio+13) & (1 << gpio_number); 70 | } 71 | } 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /NodeJS/src/index.js: -------------------------------------------------------------------------------- 1 | // https://www.dexterindustries.com/GoPiGo/ 2 | // https://github.com/DexterInd/DI_Sensors 3 | // 4 | // Copyright (c) 2017 Dexter Industries 5 | // Released under the MIT license (http://choosealicense.com/licenses/mit/). 6 | // For more information see https://github.com/DexterInd/GoPiGo3/blob/master/LICENSE.md 7 | 8 | const DHT = require('./sensors/DHT'); 9 | const RgbLcd = require('./sensors/groveRgbLcd'); 10 | const BME280 = require('./sensors/BME280'); 11 | const BNO055 = require('./sensors/BNO055'); 12 | const DistanceSensor = require('./sensors/distanceSensor'); 13 | const InertialMeasurementUnit = require('./sensors/inertialMeasurementUnit'); 14 | const LightColorSensor = require('./sensors/lightColorSensor'); 15 | const PCA9570 = require('./sensors/PCA9570'); 16 | const TCS34725 = require('./sensors/TCS34725'); 17 | const TempHumPress = require('./sensors/tempHumPress'); 18 | const VL53L0X = require('./sensors/VL53L0X'); 19 | 20 | const sensors = { 21 | 'DHT': DHT, 22 | 'RgbLcd': RgbLcd, 23 | 'BME280': BME280, 24 | 'BNO055': BNO055, 25 | 'DistanceSensor': DistanceSensor, 26 | 'InertialMeasurementUnit': InertialMeasurementUnit, 27 | 'LightColorSensor': LightColorSensor, 28 | 'PCA9570': PCA9570, 29 | 'TCS34725': TCS34725, 30 | 'TempHumPress': TempHumPress, 31 | 'VL53L0X': VL53L0X 32 | }; 33 | 34 | module.exports = sensors; 35 | -------------------------------------------------------------------------------- /NodeJS/src/sensors/DHT.js: -------------------------------------------------------------------------------- 1 | // https://www.dexterindustries.com/GoPiGo/ 2 | // https://github.com/DexterInd/DI_Sensors 3 | // 4 | // Copyright (c) 2017 Dexter Industries 5 | // Released under the MIT license (http://choosealicense.com/licenses/mit/). 6 | // For more information see https://github.com/DexterInd/GoPiGo3/blob/master/LICENSE.md 7 | 8 | const DHTDevice = require('dht-drivers'); 9 | 10 | class DHT { 11 | static DHT11 = 11; 12 | static DHT22 = 22; 13 | static AM2302 = 22; 14 | static SCALE_C = 'c'; 15 | static SCALE_F = 'f'; 16 | 17 | constructor(moduleType = DHT.DHT11, scale = DHT.SCALE_C) { 18 | this.moduleType = moduleType; 19 | this.scale = scale; 20 | } 21 | 22 | convertCtoF(temp) { 23 | return (temp * 1.8) + 32; 24 | } 25 | 26 | convertFtoC(temp) { 27 | return (temp - 32) / 1.8; 28 | } 29 | 30 | getHeatIndex(temp, hum, scale) { 31 | // http://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml 32 | const needsConversion = typeof scale === 'undefined' || scale === DHT.SCALE_C; 33 | 34 | temp = needsConversion ? this.convertCtoF(temp) : temp; 35 | 36 | // Steadman's result 37 | let heatIndex = 0.5 * (temp + 61 + (temp - 68) * 1.2 + hum * 0.094); 38 | 39 | // regression equation of Rothfusz is appropriate 40 | if (temp >= 80) { 41 | const heatIndexBase = (-42.379 + 42 | 2.04901523 * temp + 43 | 10.14333127 * hum + 44 | -0.22475541 * temp * hum + 45 | -0.00683783 * temp * temp + 46 | -0.05481717 * hum * hum + 47 | 0.00122874 * temp * temp * hum + 48 | 0.00085282 * temp * hum * hum + 49 | -0.00000199 * temp * temp * hum * hum); 50 | // adjustment 51 | if (hum < 13 && temp <= 112) { 52 | heatIndex = heatIndexBase - (13 - hum) / 4 * Math.sqrt((17 - Math.abs(temp - 95)) / 17); 53 | } else if (hum > 85 && temp <= 87) { 54 | heatIndex = heatIndexBase + ((hum - 85) / 10) * ((87 - temp) / 5); 55 | } else { 56 | heatIndex = heatIndexBase; 57 | } 58 | } 59 | 60 | return needsConversion ? this.convertFtoC(heatIndex) : heatIndex; 61 | } 62 | 63 | read() { 64 | // 2 = RapsberryPi platform ID 65 | // 15 = Serial PIN 66 | const data = DHTDevice.read(2, this.moduleType, 15); 67 | let temp = +(Number(parseFloat(data.temperature).toFixed(2))); 68 | const hum = +(Number(parseFloat(data.humidity).toFixed(2))); 69 | 70 | if (this.scale === DHT.SCALE_F) { 71 | temp = this.convertCtoF(temp); 72 | } 73 | 74 | const heatIndex = +(Number(parseFloat(this.getHeatIndex(temp, hum, this.scale)).toFixed(2))); 75 | return [temp, hum, heatIndex]; 76 | } 77 | } 78 | 79 | module.exports = DHT; 80 | -------------------------------------------------------------------------------- /NodeJS/src/sensors/PCA9570.js: -------------------------------------------------------------------------------- 1 | // https://www.dexterindustries.com/GoPiGo/ 2 | // https://github.com/DexterInd/DI_Sensors 3 | // 4 | // Copyright (c) 2017 Dexter Industries 5 | // Released under the MIT license (http://choosealicense.com/licenses/mit/). 6 | // For more information see https://github.com/DexterInd/GoPiGo3/blob/master/LICENSE.md 7 | 8 | const Sensor = require('./base/sensor'); 9 | 10 | class PCA9570 extends Sensor { 11 | static ADDRESS = 0x24; 12 | 13 | constructor(bus = 'RPI_1') { 14 | super(bus, PCA9570.ADDRESS); 15 | } 16 | 17 | setPins(value) { 18 | this.i2c.write8((value & 0x0F)); 19 | } 20 | 21 | getPins() { 22 | return this.i2c.read8u() & 0x0F; 23 | } 24 | } 25 | 26 | module.exports = PCA9570; 27 | -------------------------------------------------------------------------------- /NodeJS/src/sensors/base/sensor.js: -------------------------------------------------------------------------------- 1 | // https://www.dexterindustries.com/GoPiGo/ 2 | // https://github.com/DexterInd/DI_Sensors 3 | // 4 | // Copyright (c) 2017 Dexter Industries 5 | // Released under the MIT license (http://choosealicense.com/licenses/mit/). 6 | // For more information see https://github.com/DexterInd/GoPiGo3/blob/master/LICENSE.md 7 | 8 | const _ = require('lodash'); 9 | 10 | const EventEmitter = require('events'); 11 | const DexterI2C = require('../dexterI2c'); 12 | 13 | class Sensor extends EventEmitter { 14 | static WATCH_DELAY = 100; 15 | // ms 16 | static STREAM_DELAY = 100; 17 | // ms 18 | 19 | constructor(bus, address, opts) { 20 | super(); 21 | 22 | this.i2c = new DexterI2C(bus, address, opts); 23 | this.lastValue = 0; 24 | this.currentValue = 0; 25 | this.streamInterval = this.watchInterval = undefined; 26 | this.watchDelay = Sensor.WATCH_DELAY; 27 | this.streamDelay = Sensor.STREAM_DELAY; 28 | } 29 | 30 | read() {} 31 | write() {} 32 | stream(delay = this.streamDelay, callBack) { 33 | const _this = this; 34 | 35 | this.stopStream(); 36 | this.streamInterval = setInterval(() => { 37 | const res = _this.read(); 38 | callBack(res); 39 | }, delay); 40 | } 41 | stopStream() { 42 | clearInterval(this.streamInterval); 43 | } 44 | watch(delay = this.watchDelay) { 45 | const _this = this; 46 | 47 | this.stopWatch(); 48 | this.watchInterval = setInterval(() => { 49 | const res = _this.read(); 50 | 51 | _this.lastValue = _this.currentValue; 52 | this.currentValue = res; 53 | 54 | if (!_.isEqual(_this.currentValue, _this.lastValue)) { 55 | _this.emit('change', _this.currentValue); 56 | } 57 | }, delay); 58 | } 59 | stopWatch() { 60 | clearInterval(this.watchInterval); 61 | } 62 | } 63 | 64 | module.exports = Sensor; 65 | -------------------------------------------------------------------------------- /NodeJS/src/sensors/distanceSensor.js: -------------------------------------------------------------------------------- 1 | // https://www.dexterindustries.com/GoPiGo/ 2 | // https://github.com/DexterInd/DI_Sensors 3 | // 4 | // Copyright (c) 2017 Dexter Industries 5 | // Released under the MIT license (http://choosealicense.com/licenses/mit/). 6 | // For more information see https://github.com/DexterInd/GoPiGo3/blob/master/LICENSE.md 7 | 8 | const VL53L0X = require('./VL53L0X'); 9 | 10 | class DistanceSensor { 11 | constructor(bus = 'RPI_1') { 12 | this.sensor = new VL53L0X(bus); 13 | this.sensor.setSignalRateLimit(0.1); 14 | this.sensor.setVcselPulsePeriod(this.sensor.VcselPeriodPreRange, 18); 15 | this.sensor.setVcselPulsePeriod(this.sensor.VcselPeriodFinalRange, 14); 16 | } 17 | 18 | startContinuous(periodMs = 0) { 19 | this.startContinuous.startContinuous(periodMs); 20 | } 21 | 22 | readRangeContinuous() { 23 | return this.sensor.readRangeContinuousMillimiters(); 24 | } 25 | 26 | readRangeSingle() { 27 | return this.sensor.readRangeSingleMillimiters(); 28 | } 29 | 30 | timeoutOccurred() { 31 | return this.sensor.timeoutOccurred(); 32 | } 33 | } 34 | 35 | module.exports = DistanceSensor; 36 | -------------------------------------------------------------------------------- /NodeJS/src/sensors/groveRgbLcd.js: -------------------------------------------------------------------------------- 1 | // https://www.dexterindustries.com/GoPiGo/ 2 | // https://github.com/DexterInd/DI_Sensors 3 | // 4 | // Copyright (c) 2017 Dexter Industries 5 | // Released under the MIT license (http://choosealicense.com/licenses/mit/). 6 | // For more information see https://github.com/DexterInd/GoPiGo3/blob/master/LICENSE.md 7 | 8 | const Sensor = require('./base/sensor'); 9 | 10 | class RgbLcd { 11 | constructor() { 12 | this.rgbDevice = new Sensor('RPI_1', 0x62); 13 | this.txtDevice = new Sensor('RPI_1', 0x3e); 14 | } 15 | 16 | setRGB(r, g, b) { 17 | this.rgbDevice.i2c.writeReg8(0, 0); 18 | this.rgbDevice.i2c.writeReg8(1, 0); 19 | this.rgbDevice.i2c.writeReg8(0x08, 0xaa); 20 | this.rgbDevice.i2c.writeReg8(4, r); 21 | this.rgbDevice.i2c.writeReg8(3, g); 22 | this.rgbDevice.i2c.writeReg8(2, b); 23 | } 24 | 25 | textCommand(cmd) { 26 | this.txtDevice.i2c.writeReg8(0x80, cmd); 27 | } 28 | 29 | setText(text, noRefresh = false) { 30 | const refreshCmd = !noRefresh ? 0x01 : 0x02; 31 | 32 | this.textCommand(refreshCmd); // clear or no-refresh 33 | this.txtDevice.i2c.mwait(5); 34 | this.textCommand(0x08 | 0x04); // display on, no cursor 35 | this.textCommand(0x28); // 2 lines 36 | this.txtDevice.mwait(5); 37 | let count = 0; 38 | let row = 0; 39 | for (let i = 0, len = text.length; i < len; i++) { 40 | const c = text[i]; 41 | if (c === '\n' || count === 16) { 42 | count = 0; 43 | row += 1; 44 | if (row === 2) { 45 | break; 46 | } 47 | this.textCommand(0xc0); 48 | if (c === '\n') { 49 | break; 50 | } 51 | } 52 | count++; 53 | this.txtDevice.i2c.writeReg8(0x40, c.charCodeAt()); 54 | } 55 | } 56 | 57 | setTextNoRefresh(text) { 58 | this.setText(text, true); 59 | } 60 | } 61 | 62 | module.exports = RgbLcd; 63 | -------------------------------------------------------------------------------- /NodeJS/src/sensors/inertialMeasurementUnit.js: -------------------------------------------------------------------------------- 1 | // https://www.dexterindustries.com/GoPiGo/ 2 | // https://github.com/DexterInd/DI_Sensors 3 | // 4 | // Copyright (c) 2017 Dexter Industries 5 | // Released under the MIT license (http://choosealicense.com/licenses/mit/). 6 | // For more information see https://github.com/DexterInd/GoPiGo3/blob/master/LICENSE.md 7 | 8 | const BNO055 = require('./BNO055'); 9 | 10 | class InertialMeasurementUnit { 11 | constructor(bus = 'RPI_1') { 12 | this.sensor = new BNO055(bus); 13 | } 14 | 15 | readEuler() { 16 | return this.sensor.readEuler(); 17 | } 18 | 19 | readMagnetometer() { 20 | return this.sensor.readMagnetometer(); 21 | } 22 | 23 | readGyroscope() { 24 | return this.sensor.readGyroscope(); 25 | } 26 | 27 | readAccelerometer() { 28 | return this.sensor.readAccelerometer(); 29 | } 30 | 31 | readLinearAcceleration() { 32 | return this.sensor.readLinearAcceleration(); 33 | } 34 | 35 | readGravity() { 36 | return this.sensor.readGravity(); 37 | } 38 | 39 | readQuaternion() { 40 | return this.readQuaternion(); 41 | } 42 | 43 | readTemperature() { 44 | return this.sensor.readTemp(); 45 | } 46 | } 47 | 48 | module.exports = InertialMeasurementUnit; 49 | -------------------------------------------------------------------------------- /NodeJS/src/sensors/lightColorSensor.js: -------------------------------------------------------------------------------- 1 | // https://www.dexterindustries.com/GoPiGo/ 2 | // https://github.com/DexterInd/DI_Sensors 3 | // 4 | // Copyright (c) 2017 Dexter Industries 5 | // Released under the MIT license (http://choosealicense.com/licenses/mit/). 6 | // For more information see https://github.com/DexterInd/GoPiGo3/blob/master/LICENSE.md 7 | 8 | const TCS34725 = require('./TCS34725'); 9 | const PCA9570 = require('./PCA9570'); 10 | 11 | class LightColorSensor { 12 | constructor( 13 | sensorIntegrationTime = 0.0048, 14 | sensorGain = TCS34725.GAIN_16X, 15 | ledState = false, 16 | bus = 'RPI_1', 17 | useLightColorSensorBoard = false 18 | ) { 19 | this.lightColorDevice = new TCS34725(sensorIntegrationTime, sensorGain, bus); 20 | this.useLightColorSensorBoard = useLightColorSensorBoard; 21 | 22 | if (useLightColorSensorBoard) { 23 | this.colorSensorBoard = new PCA9570(bus); 24 | } 25 | 26 | this.setLed(ledState); 27 | } 28 | 29 | setLed(value, delay = true) { 30 | if (this.useLightColorSensorBoard) { 31 | if (value) { 32 | this.colorSensorBoard.setPins(0x00); 33 | } else { 34 | this.colorSensorBoard.setPins(0x01); 35 | } 36 | } else { 37 | this.lightColorDevice.setInterrupt(value); 38 | } 39 | 40 | if (delay) { 41 | this.lightColorDevice.i2c.mwait( 42 | (((256 - this.lightColorDevice.integrationTimeVal) * 24) * 2) 43 | ); 44 | } 45 | } 46 | 47 | getRawColors(delay = true) { 48 | return this.lightColorDevice.getRawData(delay); 49 | } 50 | } 51 | 52 | module.exports = LightColorSensor; 53 | -------------------------------------------------------------------------------- /NodeJS/src/sensors/tempHumPress.js: -------------------------------------------------------------------------------- 1 | // https://www.dexterindustries.com/GoPiGo/ 2 | // https://github.com/DexterInd/DI_Sensors 3 | // 4 | // Copyright (c) 2017 Dexter Industries 5 | // Released under the MIT license (http://choosealicense.com/licenses/mit/). 6 | // For more information see https://github.com/DexterInd/GoPiGo3/blob/master/LICENSE.md 7 | 8 | const BME280 = require('./BME280'); 9 | 10 | class TempHumPress { 11 | constructor(bus = 'RPI_1') { 12 | this.sensor = new BME280(bus, BME280.OSAMPLE_2, BME280.OSAMPLE_4, BME280.OSAMPLE_4, BME280.STANDBY_10, BME280.FILTER_8); 13 | } 14 | 15 | getTemperatureCelsius() { 16 | return this.sensor.readTemperature(); 17 | } 18 | 19 | getTemperatureFahrenheit() { 20 | return this.sensor.readTemperatureF(); 21 | } 22 | 23 | getPressure() { 24 | return this.sensor.readPressure(); 25 | } 26 | 27 | getHumidity() { 28 | return this.sensor.readHumidity(); 29 | } 30 | } 31 | 32 | module.exports = TempHumPress; 33 | -------------------------------------------------------------------------------- /NodeJS/test/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DexterInd/DI_Sensors/9f8d8cc57e06eb9c154af712490c41b34624a943/NodeJS/test/index.js -------------------------------------------------------------------------------- /Python/Examples/DistanceSensorContinuous.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # https://www.dexterindustries.com 4 | # 5 | # Copyright (c) 2017 Dexter Industries 6 | # Released under the MIT license (http://choosealicense.com/licenses/mit/). 7 | # For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md 8 | # 9 | # Python example program for the Dexter Industries Distance Sensor 10 | 11 | from __future__ import print_function 12 | from __future__ import division 13 | 14 | import time 15 | from di_sensors.distance_sensor import DistanceSensor 16 | 17 | print("Example program for reading a Dexter Industries Distance Sensor on an I2C port.") 18 | 19 | # establish communication with the DistanceSensor 20 | ds = DistanceSensor() 21 | 22 | # set the sensor in fast-polling-mode 23 | ds.start_continuous() 24 | 25 | while True: 26 | # read the distance in millimeters 27 | read_distance = ds.read_range_continuous() 28 | print("distance from object: {} mm".format(read_distance)) 29 | -------------------------------------------------------------------------------- /Python/Examples/DistanceSensorSingleShot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # https://www.dexterindustries.com/ 4 | # 5 | # Copyright (c) 2017 Dexter Industries 6 | # Released under the MIT license (http://choosealicense.com/licenses/mit/). 7 | # For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md 8 | # 9 | # Python example program for the Dexter Industries Distance Sensor 10 | 11 | from __future__ import print_function 12 | from __future__ import division 13 | 14 | import time 15 | from di_sensors.distance_sensor import DistanceSensor 16 | 17 | print("Example program for reading a Dexter Industries Distance Sensor on an I2C port.") 18 | 19 | ds = DistanceSensor() 20 | 21 | while True: 22 | # read the distance as a single-shot sample 23 | read_distance = ds.read_range_single() 24 | print("distance from object: {} mm".format(read_distance)) 25 | -------------------------------------------------------------------------------- /Python/Examples/EasyDistanceSensor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # https://www.dexterindustries.com 4 | # 5 | # Copyright (c) 2017 Dexter Industries 6 | # Released under the MIT license (http://choosealicense.com/licenses/mit/). 7 | # For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md 8 | # 9 | # Python example program for the Dexter Industries Distance Sensor 10 | 11 | from __future__ import print_function 12 | from __future__ import division 13 | 14 | # import the modules 15 | from di_sensors.easy_distance_sensor import EasyDistanceSensor 16 | from time import sleep 17 | 18 | # instantiate the distance object 19 | my_sensor = EasyDistanceSensor() 20 | 21 | # and read the sensor iteratively 22 | while True: 23 | read_distance = my_sensor.read() 24 | print("distance from object: {} cm".format(read_distance)) 25 | 26 | sleep(0.1) 27 | -------------------------------------------------------------------------------- /Python/Examples/EasyDistanceSensorMutexes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # https://www.dexterindustries.com 4 | # 5 | # Copyright (c) 2017 Dexter Industries 6 | # Released under the MIT license (http://choosealicense.com/licenses/mit/). 7 | # For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md 8 | # 9 | # Python example program for the Dexter Industries Temperature Humidity Pressure Sensor 10 | 11 | from __future__ import print_function 12 | from __future__ import division 13 | 14 | # do the import stuff 15 | from di_sensors.easy_distance_sensor import EasyDistanceSensor 16 | from time import time, sleep 17 | from threading import Thread, Event, get_ident 18 | 19 | # instantiate the distance object 20 | my_sensor = EasyDistanceSensor(use_mutex = True) 21 | start_time = time() 22 | runtime = 2.0 23 | # create an event object for triggering the "shutdown" of each thread 24 | stop_event = Event() 25 | 26 | # target function for each thread 27 | def readingSensor(): 28 | while not stop_event.is_set(): 29 | thread_id = get_ident() 30 | distance = my_sensor.read() 31 | print("Thread ID = {} with distance value = {}".format(thread_id, distance)) 32 | sleep(0.001) 33 | 34 | # create an object for each thread 35 | thread1 = Thread(target = readingSensor) 36 | thread2 = Thread(target = readingSensor) 37 | 38 | # and then start them 39 | thread1.start() 40 | thread2.start() 41 | 42 | # let it run for [runtime] seconds 43 | while time() - start_time <= runtime: 44 | sleep(0.1) 45 | 46 | # and then set the stop event variable 47 | stop_event.set() 48 | 49 | # and wait both threads to end 50 | thread1.join() 51 | thread2.join() 52 | -------------------------------------------------------------------------------- /Python/Examples/EasyLightColorSensor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # https://www.dexterindustries.com 4 | # 5 | # Copyright (c) 2017 Dexter Industries 6 | # Released under the MIT license (http://choosealicense.com/licenses/mit/). 7 | # For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md 8 | # 9 | # Python example program for the Dexter Industries Light Color Sensor 10 | 11 | from __future__ import print_function 12 | from __future__ import division 13 | 14 | from time import sleep 15 | from di_sensors.easy_light_color_sensor import EasyLightColorSensor 16 | 17 | print("Example program for reading a Dexter Industries Light Color Sensor on an I2C port.") 18 | 19 | my_lcs = EasyLightColorSensor(led_state = True) 20 | 21 | while True: 22 | # Read the R, G, B, C color values 23 | red, green, blue, clear = my_lcs.safe_raw_colors() 24 | 25 | # Print the values 26 | print("Red: {:5.3f} Green: {:5.3f} Blue: {:5.3f} Clear: {:5.3f}".format(red, green, blue, clear)) 27 | 28 | sleep(0.02) 29 | -------------------------------------------------------------------------------- /Python/Examples/EasyTempHumPress.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # https://www.dexterindustries.com 4 | # 5 | # Copyright (c) 2017 Dexter Industries 6 | # Released under the MIT license (http://choosealicense.com/licenses/mit/). 7 | # For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md 8 | # 9 | # Python example program for the Dexter Industries Temperature Humidity Pressure Sensor 10 | 11 | from __future__ import print_function 12 | from __future__ import division 13 | 14 | from time import sleep 15 | from di_sensors.easy_temp_hum_press import EasyTHPSensor 16 | 17 | print("Example program for reading a Dexter Industries Temperature Humidity Pressure Sensor on an I2C port.") 18 | 19 | my_thp = EasyTHPSensor() 20 | 21 | while True: 22 | # Read the temperature 23 | temp = my_thp.safe_celsius() 24 | 25 | # Read the relative humidity 26 | hum = my_thp.safe_humidity() 27 | 28 | # Read the pressure 29 | press = my_thp.safe_pressure() 30 | 31 | # Print the values 32 | print("Temperature: {:5.3f} Humidity: {:5.3f} Pressure: {:5.3f}".format(temp, hum, press)) 33 | 34 | sleep(0.02) 35 | -------------------------------------------------------------------------------- /Python/Examples/IMUSensor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # https://www.dexterindustries.com 4 | # 5 | # Copyright (c) 2017 Dexter Industries 6 | # Released under the MIT license (http://choosealicense.com/licenses/mit/). 7 | # For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md 8 | # 9 | # Python example program for the Dexter Industries IMU Sensor 10 | 11 | from __future__ import print_function 12 | from __future__ import division 13 | 14 | import time 15 | from di_sensors.inertial_measurement_unit import InertialMeasurementUnit 16 | 17 | print("Example program for reading a Dexter Industries IMU Sensor on a GoPiGo3 AD1 port.") 18 | 19 | imu = InertialMeasurementUnit(bus = "GPG3_AD1") 20 | 21 | while True: 22 | # Read the magnetometer, gyroscope, accelerometer, euler, and temperature values 23 | mag = imu.read_magnetometer() 24 | gyro = imu.read_gyroscope() 25 | accel = imu.read_accelerometer() 26 | euler = imu.read_euler() 27 | temp = imu.read_temperature() 28 | 29 | string_to_print = "Magnetometer X: {:.1f} Y: {:.1f} Z: {:.1f} " \ 30 | "Gyroscope X: {:.1f} Y: {:.1f} Z: {:.1f} " \ 31 | "Accelerometer X: {:.1f} Y: {:.1f} Z: {:.1f} " \ 32 | "Euler Heading: {:.1f} Roll: {:.1f} Pitch: {:.1f} " \ 33 | "Temperature: {:.1f}C".format(mag[0], mag[1], mag[2], 34 | gyro[0], gyro[1], gyro[2], 35 | accel[0], accel[1], accel[2], 36 | euler[0], euler[1], euler[2], 37 | temp) 38 | print(string_to_print) 39 | 40 | time.sleep(0.1) 41 | -------------------------------------------------------------------------------- /Python/Examples/LineFollower.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # https://www.dexterindustries.com 4 | # 5 | # Copyright (c) 2019 Dexter Industries 6 | # Released under the MIT license (http://choosealicense.com/licenses/mit/). 7 | # For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md 8 | # 9 | # Python example program for the Dexter Industries Line Follower sensor 10 | 11 | from __future__ import print_function 12 | from __future__ import division 13 | 14 | import time 15 | from di_sensors import line_follower 16 | 17 | print("Example program for reading a Dexter Industries Line Follower sensor on GPG3 AD1 port") 18 | 19 | lf = line_follower.LineFollower(bus = "GPG3_AD1") 20 | 21 | ''' 22 | cd ~/Dexter/DI_Sensors/Python 23 | sudo python setup.py install 24 | 25 | python ~/Dexter/DI_Sensors/Python/Examples/LineFollower.py 26 | 27 | ''' 28 | 29 | print("Manufacturer : %s" % lf.get_manufacturer()) 30 | print("Name : %s" % lf.get_board()) 31 | print("Firmware Version : %d" % lf.get_version_firmware()) 32 | 33 | while True: 34 | # Read the line sensors values 35 | values = lf.read_sensors() 36 | str = "" 37 | for v in range(len(values)): 38 | str += "%.3f " % values[v] 39 | print(str) 40 | 41 | time.sleep(0.1) 42 | -------------------------------------------------------------------------------- /Python/Examples/TempHumPress.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # https://www.dexterindustries.com 4 | # 5 | # Copyright (c) 2017 Dexter Industries 6 | # Released under the MIT license (http://choosealicense.com/licenses/mit/). 7 | # For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md 8 | # 9 | # Python example program for the Dexter Industries Temperature Humidity Pressure Sensor 10 | 11 | from __future__ import print_function 12 | from __future__ import division 13 | 14 | import time 15 | from di_sensors.temp_hum_press import TempHumPress 16 | 17 | print("Example program for reading a Dexter Industries Temperature Humidity Pressure Sensor on an I2C port.") 18 | 19 | thp = TempHumPress() 20 | 21 | while True: 22 | # Read the temperature 23 | temp = thp.get_temperature_celsius() 24 | 25 | # Read the relative humidity 26 | hum = thp.get_humidity() 27 | 28 | # Read the pressure 29 | press = thp.get_pressure() 30 | 31 | # Print the values 32 | print("Temperature: {:5.3f} Humidity: {:5.3f} Pressure: {:5.3f}".format(temp, hum, press)) 33 | 34 | time.sleep(0.02) 35 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | def dht(sensor_type=0): 3 | try: 4 | import Adafruit_DHT 5 | if sensor_type==0: #blue sensor 6 | sensor = Adafruit_DHT.DHT11 7 | elif sensor_type==1: #white sensor 8 | sensor = Adafruit_DHT.DHT22 9 | pin = 15 #connected to the serial port on the GoPiGo, RX pin 10 | humidity, temperature = Adafruit_DHT.read_retry(sensor, pin,retries=3,delay_seconds=.1) 11 | if humidity is not None and temperature is not None: 12 | return [temperature,humidity] 13 | else: 14 | return [-2.0,-2.0] 15 | except RuntimeError: 16 | return [-3.0,-3.0] 17 | 18 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *.egg-info 3 | *.pyc 4 | setuptools-* 5 | *.so 6 | 7 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/Adafruit_DHT/Raspberry_Pi.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014 Adafruit Industries 2 | # Author: Tony DiCola 3 | 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | from . import common 22 | from . import Raspberry_Pi_Driver as driver 23 | 24 | def read(sensor, pin): 25 | # Validate pin is a valid GPIO. 26 | if pin is None or int(pin) < 0 or int(pin) > 31: 27 | raise ValueError('Pin must be a valid GPIO number 0 to 31.') 28 | # Get a reading from C driver code. 29 | result, humidity, temp = driver.read(sensor, int(pin)) 30 | if result in common.TRANSIENT_ERRORS: 31 | # Signal no result could be obtained, but the caller can retry. 32 | return (None, None) 33 | elif result == common.DHT_ERROR_GPIO: 34 | raise RuntimeError( 35 | 'Error accessing GPIO. If `/dev/gpiomem` does not exist ' 36 | 'run this program as root or sudo.') 37 | elif result != common.DHT_SUCCESS: 38 | # Some kind of error occured. 39 | raise RuntimeError('Error calling DHT test driver read: {0}'.format(result)) 40 | return (humidity, temp) 41 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/Adafruit_DHT/Raspberry_Pi_2.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014 Adafruit Industries 2 | # Author: Tony DiCola 3 | 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | from . import common 22 | from . import Raspberry_Pi_2_Driver as driver 23 | 24 | def read(sensor, pin): 25 | # Validate pin is a valid GPIO. 26 | if pin is None or int(pin) < 0 or int(pin) > 31: 27 | raise ValueError('Pin must be a valid GPIO number 0 to 31.') 28 | # Get a reading from C driver code. 29 | result, humidity, temp = driver.read(sensor, int(pin)) 30 | if result in common.TRANSIENT_ERRORS: 31 | # Signal no result could be obtained, but the caller can retry. 32 | return (None, None) 33 | elif result == common.DHT_ERROR_GPIO: 34 | raise RuntimeError('Error accessing GPIO.') 35 | elif result != common.DHT_SUCCESS: 36 | # Some kind of error occured. 37 | raise RuntimeError('Error calling DHT test driver read: {0}'.format(result)) 38 | return (humidity, temp) 39 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/Adafruit_DHT/Test.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014 Adafruit Industries 2 | # Author: Tony DiCola 3 | 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | from . import common 22 | from . import Test_Driver as driver 23 | 24 | def read(sensor, pin): 25 | # Get a reading from C driver code. 26 | result, humidity, temp = driver.read(sensor, pin) 27 | if result in common.TRANSIENT_ERRORS: 28 | # Signal no result could be obtained, but the caller can retry. 29 | return (None, None) 30 | elif result != common.DHT_SUCCESS: 31 | # Some kind of error occured. 32 | raise RuntimeError('Error calling DHT test driver read: {0}'.format(result)) 33 | return (humidity, temp) 34 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/Adafruit_DHT/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014 Adafruit Industries 2 | # Author: Tony DiCola 3 | 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | from .common import DHT11, DHT22, AM2302, read, read_retry 22 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/Adafruit_DHT/common.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014 Adafruit Industries 2 | # Author: Tony DiCola 3 | 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | import time 22 | 23 | from . import platform_detect 24 | 25 | 26 | # Define error constants. 27 | DHT_SUCCESS = 0 28 | DHT_ERROR_TIMEOUT = -1 29 | DHT_ERROR_CHECKSUM = -2 30 | DHT_ERROR_ARGUMENT = -3 31 | DHT_ERROR_GPIO = -4 32 | TRANSIENT_ERRORS = [DHT_ERROR_CHECKSUM, DHT_ERROR_TIMEOUT] 33 | 34 | # Define sensor type constants. 35 | DHT11 = 11 36 | DHT22 = 22 37 | AM2302 = 22 38 | SENSORS = [DHT11, DHT22, AM2302] 39 | 40 | 41 | def get_platform(): 42 | """Return a DHT platform interface for the currently detected platform.""" 43 | plat = platform_detect.platform_detect() 44 | if plat == platform_detect.RASPBERRY_PI: 45 | # Check for version 1 or 2 of the pi. 46 | version = platform_detect.pi_version() 47 | if version == 1: 48 | from . import Raspberry_Pi 49 | return Raspberry_Pi 50 | elif version == 2: 51 | from . import Raspberry_Pi_2 52 | return Raspberry_Pi_2 53 | elif version == 3: 54 | """Use Pi 2 driver even though running on Pi 3""" 55 | from . import Raspberry_Pi_2 56 | return Raspberry_Pi_2 57 | else: 58 | raise RuntimeError('No driver for detected Raspberry Pi version available!') 59 | elif plat == platform_detect.BEAGLEBONE_BLACK: 60 | from . import Beaglebone_Black 61 | return Beaglebone_Black 62 | else: 63 | raise RuntimeError('Unknown platform.') 64 | 65 | def read(sensor, pin, platform=None): 66 | """Read DHT sensor of specified sensor type (DHT11, DHT22, or AM2302) on 67 | specified pin and return a tuple of humidity (as a floating point value 68 | in percent) and temperature (as a floating point value in Celsius). Note that 69 | because the sensor requires strict timing to read and Linux is not a real 70 | time OS, a result is not guaranteed to be returned! In some cases this will 71 | return the tuple (None, None) which indicates the function should be retried. 72 | Also note the DHT sensor cannot be read faster than about once every 2 seconds. 73 | Platform is an optional parameter which allows you to override the detected 74 | platform interface--ignore this parameter unless you receive unknown platform 75 | errors and want to override the detection. 76 | """ 77 | if sensor not in SENSORS: 78 | raise ValueError('Expected DHT11, DHT22, or AM2302 sensor value.') 79 | if platform is None: 80 | platform = get_platform() 81 | return platform.read(sensor, pin) 82 | 83 | def read_retry(sensor, pin, retries=15, delay_seconds=2, platform=None): 84 | """Read DHT sensor of specified sensor type (DHT11, DHT22, or AM2302) on 85 | specified pin and return a tuple of humidity (as a floating point value 86 | in percent) and temperature (as a floating point value in Celsius). 87 | Unlike the read function, this read_retry function will attempt to read 88 | multiple times (up to the specified max retries) until a good reading can be 89 | found. If a good reading cannot be found after the amount of retries, a tuple 90 | of (None, None) is returned. The delay between retries is by default 2 91 | seconds, but can be overridden. 92 | """ 93 | for i in range(retries): 94 | humidity, temperature = read(sensor, pin, platform) 95 | if humidity is not None and temperature is not None: 96 | return (humidity, temperature) 97 | time.sleep(delay_seconds) 98 | return (None, None) 99 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Adafruit Industries 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/README.md: -------------------------------------------------------------------------------- 1 | Adafruit Python DHT Sensor Library 2 | ================================== 3 | 4 | Python library to read the DHT series of humidity and temperature sensors on a Raspberry Pi or Beaglebone Black. 5 | 6 | Designed specifically to work with the Adafruit DHT series sensors ----> https://www.adafruit.com/products/385 7 | 8 | Currently the library is only tested with Python 2.6/2.7. 9 | 10 | For all platforms (Raspberry Pi and Beaglebone Black) make sure your system is able to compile Python extensions. On Raspbian or Beaglebone Black's Debian/Ubuntu image you can ensure your system is ready by executing: 11 | 12 | ```` 13 | sudo apt-get update 14 | sudo apt-get install build-essential python-dev 15 | ```` 16 | 17 | Install the library by downloading with the download link on the right, unzipping the archive, and executing: 18 | 19 | ```` 20 | sudo python setup.py install 21 | ```` 22 | You can ommit the sudo if you use raspberry pi. 23 | 24 | See example of usage in the examples folder. 25 | 26 | Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! 27 | 28 | Written by Tony DiCola for Adafruit Industries. 29 | 30 | MIT license, all text above must be included in any redistribution 31 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/examples/AdafruitDHT.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Copyright (c) 2014 Adafruit Industries 3 | # Author: Tony DiCola 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | import sys 23 | 24 | import Adafruit_DHT 25 | 26 | 27 | # Parse command line parameters. 28 | sensor_args = { '11': Adafruit_DHT.DHT11, 29 | '22': Adafruit_DHT.DHT22, 30 | '2302': Adafruit_DHT.AM2302 } 31 | if len(sys.argv) == 3 and sys.argv[1] in sensor_args: 32 | sensor = sensor_args[sys.argv[1]] 33 | pin = sys.argv[2] 34 | else: 35 | print('usage: sudo ./Adafruit_DHT.py [11|22|2302] GPIOpin#') 36 | print('example: sudo ./Adafruit_DHT.py 2302 4 - Read from an AM2302 connected to GPIO #4') 37 | sys.exit(1) 38 | 39 | # Try to grab a sensor reading. Use the read_retry method which will retry up 40 | # to 15 times to get a sensor reading (waiting 2 seconds between each retry). 41 | humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) 42 | 43 | # Un-comment the line below to convert the temperature to Fahrenheit. 44 | # temperature = temperature * 9/5.0 + 32 45 | 46 | # Note that sometimes you won't get a reading and 47 | # the results will be null (because Linux can't 48 | # guarantee the timing of calls to read the sensor). 49 | # If this happens try again! 50 | if humidity is not None and temperature is not None: 51 | print('Temp={0:0.1f}* Humidity={1:0.1f}%'.format(temperature, humidity)) 52 | else: 53 | print('Failed to get reading. Try again!') 54 | sys.exit(1) 55 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/examples/simpletest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright (c) 2014 Adafruit Industries 4 | # Author: Tony DiCola 5 | 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | import Adafruit_DHT 24 | 25 | # Sensor should be set to Adafruit_DHT.DHT11, 26 | # Adafruit_DHT.DHT22, or Adafruit_DHT.AM2302. 27 | sensor = Adafruit_DHT.DHT22 28 | 29 | # Example using a Beaglebone Black with DHT sensor 30 | # connected to pin P8_11. 31 | pin = 'P8_11' 32 | 33 | # Example using a Raspberry Pi with DHT sensor 34 | # connected to GPIO23. 35 | #pin = 23 36 | 37 | # Try to grab a sensor reading. Use the read_retry method which will retry up 38 | # to 15 times to get a sensor reading (waiting 2 seconds between each retry). 39 | humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) 40 | 41 | # Note that sometimes you won't get a reading and 42 | # the results will be null (because Linux can't 43 | # guarantee the timing of calls to read the sensor). 44 | # If this happens try again! 45 | if humidity is not None and temperature is not None: 46 | print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity)) 47 | else: 48 | print('Failed to get reading. Try again!') 49 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/source/Beaglebone_Black/bbb_dht_read.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #ifndef BBB_DHT_READ_H 22 | #define BBB_DHT_READ_H 23 | 24 | #include "../common_dht_read.h" 25 | 26 | // Read DHT sensor connected to GPIO bin GPIO_, for example P8_11 is GPIO1_13 with 27 | // base = 1 and number = 13. Humidity and temperature will be returned in the provided parameters. 28 | // If a successfull reading could be made a value of 0 (DHT_SUCCESS) will be returned. If there 29 | // was an error reading the sensor a negative value will be returned. Some errors can be ignored 30 | // and retried, specifically DHT_ERROR_TIMEOUT or DHT_ERROR_CHECKSUM. 31 | int bbb_dht_read(int type, int gpio_base, int gpio_number, float* humidity, float* temperature); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/source/Beaglebone_Black/bbb_mmio.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "bbb_mmio.h" 29 | 30 | #define GPIO_LENGTH 4096 31 | #define GPIO0_ADDR 0x44E07000 32 | #define GPIO1_ADDR 0x4804C000 33 | #define GPIO2_ADDR 0x481AC000 34 | #define GPIO3_ADDR 0x481AF000 35 | 36 | // Store mapping of GPIO base number to GPIO address. 37 | static uint32_t gpio_addresses[4] = { GPIO0_ADDR, GPIO1_ADDR, GPIO2_ADDR, GPIO3_ADDR }; 38 | 39 | // Cache memory-mapped GPIO addresses. 40 | static volatile uint32_t* gpio_base[4] = { NULL }; 41 | 42 | int bbb_mmio_get_gpio(int base, int number, gpio_t* gpio) { 43 | // Validate input parameters. 44 | if (gpio == NULL) { 45 | return MMIO_ERROR_ARGUMENT; 46 | } 47 | if (base < 0 || base > 3) { 48 | return MMIO_ERROR_ARGUMENT; 49 | } 50 | if (number < 0 || number > 31) { 51 | return MMIO_ERROR_ARGUMENT; 52 | } 53 | // Map GPIO memory if its hasn't been mapped already. 54 | if (gpio_base[base] == NULL) { 55 | int fd = open("/dev/mem", O_RDWR | O_SYNC); 56 | if (fd == -1) { 57 | // Error opening /dev/mem. Probably not running as root. 58 | return MMIO_ERROR_DEVMEM; 59 | } 60 | // Map GPIO memory to location in process space. 61 | gpio_base[base] = (uint32_t*)mmap(NULL, GPIO_LENGTH, PROT_READ | PROT_WRITE, MAP_SHARED, fd, gpio_addresses[base]); 62 | if (gpio_base[base] == MAP_FAILED) { 63 | // Don't save the result if the memory mapping failed. 64 | gpio_base[base] = NULL; 65 | return MMIO_ERROR_MMAP; 66 | } 67 | } 68 | // Initialize and set GPIO fields. 69 | memset(gpio, 0, sizeof(gpio)); 70 | gpio->base = gpio_base[base]; 71 | gpio->number = number; 72 | return MMIO_SUCCESS; 73 | } 74 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/source/Beaglebone_Black/bbb_mmio.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | 22 | // Simple fast memory-mapped GPIO library for the Beaglebone Black. 23 | // Allows reading and writing GPIO at very high speeds, up to ~2.6mhz! 24 | 25 | /* 26 | // Example usage: 27 | 28 | #include 29 | #include "bbb_mmio.h" 30 | 31 | int main(int argc, char* argv[]) { 32 | // Get GPIO pin. 33 | // See the giant table of of pins in the system reference manual for details 34 | // on the base and number for a given GPIO: 35 | // https://github.com/CircuitCo/BeagleBone-Black/blob/master/BBB_SRM.pdf?raw=true 36 | // Section 7 Connectors, table 12 shows P8_11 maps to GPIO1_13, so 1 is the 37 | // gpio base and 13 is the gpio number. 38 | gpio_t p8_11; 39 | if (bbb_mmio_get_gpio(1, 13, &p8_11) < 0) { 40 | printf("Couldn't get requested GPIO pin!\n"); 41 | return 1; 42 | } 43 | // Set pin as output. 44 | bbb_mmio_set_output(p8_11); 45 | // Toggle the pin high and low as fast as possible. 46 | // This generates a signal at about 2.6mhz in my tests. 47 | // Each pulse high/low is only about 200 nanoseconds long! 48 | while (1) { 49 | bbb_mmio_set_high(p8_11); 50 | bbb_mmio_set_low(p8_11); 51 | } 52 | return 0; 53 | } 54 | 55 | */ 56 | 57 | #ifndef BBB_MMIO_H 58 | #define BBB_MMIO_H 59 | 60 | #include 61 | 62 | #define MMIO_SUCCESS 0 63 | #define MMIO_ERROR_ARGUMENT -1 64 | #define MMIO_ERROR_DEVMEM -2 65 | #define MMIO_ERROR_MMAP -3 66 | 67 | #define MMIO_OE_ADDR 0x134 68 | #define MMIO_GPIO_DATAOUT 0x13C 69 | #define MMIO_GPIO_DATAIN 0x138 70 | #define MMIO_GPIO_CLEARDATAOUT 0x190 71 | #define MMIO_GPIO_SETDATAOUT 0x194 72 | 73 | // Define struct to represent a GPIO pin based on its base memory address and number. 74 | typedef struct { 75 | volatile uint32_t* base; 76 | int number; 77 | } gpio_t; 78 | 79 | int bbb_mmio_get_gpio(int base, int number, gpio_t* gpio); 80 | 81 | static inline void bbb_mmio_set_output(gpio_t gpio) { 82 | gpio.base[MMIO_OE_ADDR/4] &= (0xFFFFFFFF ^ (1 << gpio.number)); 83 | } 84 | 85 | static inline void bbb_mmio_set_input(gpio_t gpio) { 86 | gpio.base[MMIO_OE_ADDR/4] |= (1 << gpio.number); 87 | } 88 | 89 | static inline void bbb_mmio_set_high(gpio_t gpio) { 90 | gpio.base[MMIO_GPIO_SETDATAOUT/4] = 1 << gpio.number; 91 | } 92 | 93 | static inline void bbb_mmio_set_low(gpio_t gpio) { 94 | gpio.base[MMIO_GPIO_CLEARDATAOUT/4] = 1 << gpio.number; 95 | } 96 | 97 | static inline uint32_t bbb_mmio_input(gpio_t gpio) { 98 | return gpio.base[MMIO_GPIO_DATAIN/4] & (1 << gpio.number); 99 | } 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/source/Raspberry_Pi/pi_dht_read.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #ifndef PI_DHT_READ_H 22 | #define PI_DHT_READ_H 23 | 24 | #include "../common_dht_read.h" 25 | 26 | // Read DHT sensor connected to GPIO pin (using BCM numbering). Humidity and temperature will be 27 | // returned in the provided parameters. If a successfull reading could be made a value of 0 28 | // (DHT_SUCCESS) will be returned. If there was an error reading the sensor a negative value will 29 | // be returned. Some errors can be ignored and retried, specifically DHT_ERROR_TIMEOUT or DHT_ERROR_CHECKSUM. 30 | int pi_dht_read(int sensor, int pin, float* humidity, float* temperature); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/source/Raspberry_Pi/pi_mmio.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | // Based on code from Gert van Loo & Dom: http://elinux.org/RPi_Low-level_peripherals#GPIO_Code_examples 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "pi_mmio.h" 31 | 32 | #define BASE 0x20000000 33 | #define GPIO_BASE (BASE + 0x200000) 34 | #define GPIO_LENGTH 4096 35 | 36 | volatile uint32_t* pi_mmio_gpio = NULL; 37 | 38 | int pi_mmio_init(void) { 39 | if (pi_mmio_gpio == NULL) { 40 | int fd; 41 | 42 | // On older kernels user readable /dev/gpiomem might not exists. 43 | // Falls back to root-only /dev/mem. 44 | if( access( "/dev/gpiomem", F_OK ) != -1 ) { 45 | fd = open("/dev/gpiomem", O_RDWR | O_SYNC); 46 | } else { 47 | fd = open("/dev/mem", O_RDWR | O_SYNC); 48 | } 49 | if (fd == -1) { 50 | // Error opening /dev/gpiomem. 51 | return MMIO_ERROR_DEVMEM; 52 | } 53 | // Map GPIO memory to location in process space. 54 | pi_mmio_gpio = (uint32_t*)mmap(NULL, GPIO_LENGTH, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO_BASE); 55 | close(fd); 56 | if (pi_mmio_gpio == MAP_FAILED) { 57 | // Don't save the result if the memory mapping failed. 58 | pi_mmio_gpio = NULL; 59 | return MMIO_ERROR_MMAP; 60 | } 61 | } 62 | return MMIO_SUCCESS; 63 | } 64 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/source/Raspberry_Pi/pi_mmio.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | // Based on code from Gert van Loo & Dom: http://elinux.org/RPi_Low-level_peripherals#GPIO_Code_examples 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // Simple fast memory-mapped GPIO library for the Raspberry Pi. 24 | #ifndef PI_MMIO_H 25 | #define PI_MMIO_H 26 | 27 | #include 28 | 29 | #define MMIO_SUCCESS 0 30 | #define MMIO_ERROR_DEVMEM -1 31 | #define MMIO_ERROR_MMAP -2 32 | 33 | extern volatile uint32_t* pi_mmio_gpio; 34 | 35 | int pi_mmio_init(void); 36 | 37 | static inline void pi_mmio_set_input(const int gpio_number) { 38 | // Set GPIO register to 000 for specified GPIO number. 39 | *(pi_mmio_gpio+((gpio_number)/10)) &= ~(7<<(((gpio_number)%10)*3)); 40 | } 41 | 42 | static inline void pi_mmio_set_output(const int gpio_number) { 43 | // First set to 000 using input function. 44 | pi_mmio_set_input(gpio_number); 45 | // Next set bit 0 to 1 to set output. 46 | *(pi_mmio_gpio+((gpio_number)/10)) |= (1<<(((gpio_number)%10)*3)); 47 | } 48 | 49 | static inline void pi_mmio_set_high(const int gpio_number) { 50 | *(pi_mmio_gpio+7) = 1 << gpio_number; 51 | } 52 | 53 | static inline void pi_mmio_set_low(const int gpio_number) { 54 | *(pi_mmio_gpio+10) = 1 << gpio_number; 55 | } 56 | 57 | static inline uint32_t pi_mmio_input(const int gpio_number) { 58 | return *(pi_mmio_gpio+13) & (1 << gpio_number); 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/source/Raspberry_Pi_2/pi_2_dht_read.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #ifndef PI_2_DHT_READ_H 22 | #define PI_2_DHT_READ_H 23 | 24 | #include "../common_dht_read.h" 25 | 26 | // Read DHT sensor connected to GPIO pin (using BCM numbering). Humidity and temperature will be 27 | // returned in the provided parameters. If a successfull reading could be made a value of 0 28 | // (DHT_SUCCESS) will be returned. If there was an error reading the sensor a negative value will 29 | // be returned. Some errors can be ignored and retried, specifically DHT_ERROR_TIMEOUT or DHT_ERROR_CHECKSUM. 30 | int pi_2_dht_read(int sensor, int pin, float* humidity, float* temperature); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/source/Raspberry_Pi_2/pi_2_mmio.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | // Based on code from Gert van Loo & Dom: http://elinux.org/RPi_Low-level_peripherals#GPIO_Code_examples 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "pi_2_mmio.h" 32 | 33 | #define GPIO_BASE_OFFSET 0x200000 34 | #define GPIO_LENGTH 4096 35 | 36 | volatile uint32_t* pi_2_mmio_gpio = NULL; 37 | 38 | int pi_2_mmio_init(void) { 39 | if (pi_2_mmio_gpio == NULL) { 40 | // Check for GPIO and peripheral addresses from device tree. 41 | // Adapted from code in the RPi.GPIO library at: 42 | // http://sourceforge.net/p/raspberry-gpio-python/ 43 | FILE *fp = fopen("/proc/device-tree/soc/ranges", "rb"); 44 | if (fp == NULL) { 45 | return MMIO_ERROR_OFFSET; 46 | } 47 | fseek(fp, 4, SEEK_SET); 48 | unsigned char buf[4]; 49 | if (fread(buf, 1, sizeof(buf), fp) != sizeof(buf)) { 50 | return MMIO_ERROR_OFFSET; 51 | } 52 | uint32_t peri_base = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0; 53 | uint32_t gpio_base = peri_base + GPIO_BASE_OFFSET; 54 | fclose(fp); 55 | 56 | int fd = open("/dev/gpiomem", O_RDWR | O_SYNC); 57 | if (fd == -1) { 58 | // Error opening /dev/gpiomem. 59 | return MMIO_ERROR_DEVMEM; 60 | } 61 | // Map GPIO memory to location in process space. 62 | pi_2_mmio_gpio = (uint32_t*)mmap(NULL, GPIO_LENGTH, PROT_READ | PROT_WRITE, MAP_SHARED, fd, gpio_base); 63 | close(fd); 64 | if (pi_2_mmio_gpio == MAP_FAILED) { 65 | // Don't save the result if the memory mapping failed. 66 | pi_2_mmio_gpio = NULL; 67 | return MMIO_ERROR_MMAP; 68 | } 69 | } 70 | return MMIO_SUCCESS; 71 | } 72 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/source/Raspberry_Pi_2/pi_2_mmio.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | // Based on code from Gert van Loo & Dom: http://elinux.org/RPi_Low-level_peripherals#GPIO_Code_examples 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // Simple fast memory-mapped GPIO library for the Raspberry Pi. 24 | #ifndef PI_2_MMIO_H 25 | #define PI_2_MMIO_H 26 | 27 | #include 28 | 29 | #define MMIO_SUCCESS 0 30 | #define MMIO_ERROR_DEVMEM -1 31 | #define MMIO_ERROR_MMAP -2 32 | #define MMIO_ERROR_OFFSET -3 33 | 34 | extern volatile uint32_t* pi_2_mmio_gpio; 35 | 36 | int pi_2_mmio_init(void); 37 | 38 | static inline void pi_2_mmio_set_input(const int gpio_number) { 39 | // Set GPIO register to 000 for specified GPIO number. 40 | *(pi_2_mmio_gpio+((gpio_number)/10)) &= ~(7<<(((gpio_number)%10)*3)); 41 | } 42 | 43 | static inline void pi_2_mmio_set_output(const int gpio_number) { 44 | // First set to 000 using input function. 45 | pi_2_mmio_set_input(gpio_number); 46 | // Next set bit 0 to 1 to set output. 47 | *(pi_2_mmio_gpio+((gpio_number)/10)) |= (1<<(((gpio_number)%10)*3)); 48 | } 49 | 50 | static inline void pi_2_mmio_set_high(const int gpio_number) { 51 | *(pi_2_mmio_gpio+7) = 1 << gpio_number; 52 | } 53 | 54 | static inline void pi_2_mmio_set_low(const int gpio_number) { 55 | *(pi_2_mmio_gpio+10) = 1 << gpio_number; 56 | } 57 | 58 | static inline uint32_t pi_2_mmio_input(const int gpio_number) { 59 | return *(pi_2_mmio_gpio+13) & (1 << gpio_number); 60 | } 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/source/Test/test_dht_read.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #include 22 | 23 | #include "test_dht_read.h" 24 | 25 | int test_dht_read(int type, int pin, float* humidity, float* temperature) { 26 | // Validate humidity and temperature arguments and set them to zero. 27 | if (humidity == NULL || temperature == NULL) { 28 | return -1; 29 | } 30 | *temperature = 42.0f; 31 | *humidity = 50.0f; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/source/Test/test_dht_read.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #ifndef TEST_DHT_READ_H 22 | #define TEST_DHT_READ_H 23 | 24 | int test_dht_read(int sensor, int pin, float* humidity, float* temperature); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/source/_Beaglebone_Black_Driver.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #include 22 | 23 | #include "Beaglebone_Black/bbb_dht_read.h" 24 | 25 | // Wrap calling dht_read function and expose it as a DHT.read Python module & function. 26 | static PyObject* Beaglebone_Black_Driver_read(PyObject *self, PyObject *args) 27 | { 28 | // Parse sensor and pin integer arguments. 29 | int sensor, base, number; 30 | if (!PyArg_ParseTuple(args, "iii", &sensor, &base, &number)) { 31 | return NULL; 32 | } 33 | // Call dht_read and return result code, humidity, and temperature. 34 | float humidity = 0, temperature = 0; 35 | int result = bbb_dht_read(sensor, base, number, &humidity, &temperature); 36 | return Py_BuildValue("iff", result, humidity, temperature); 37 | } 38 | 39 | // Boilerplate python module method list and initialization functions below. 40 | 41 | static PyMethodDef module_methods[] = { 42 | {"read", Beaglebone_Black_Driver_read, METH_VARARGS, "Read DHT sensor value on a Beaglebone Black."}, 43 | {NULL, NULL, 0, NULL} 44 | }; 45 | 46 | #if PY_MAJOR_VERSION > 2 47 | static struct PyModuleDef bbb_dht_module = { 48 | PyModuleDef_HEAD_INIT, 49 | "Beaglebone_Black_Driver", // name of module 50 | NULL, // module documentation, may be NULL 51 | -1, // size of per-interpreter state of the module, or -1 if the module keeps state in global variables. 52 | module_methods 53 | }; 54 | #endif 55 | 56 | #if PY_MAJOR_VERSION > 2 57 | PyMODINIT_FUNC PyInit_Beaglebone_Black_Driver(void) 58 | #else 59 | PyMODINIT_FUNC initBeaglebone_Black_Driver(void) 60 | #endif 61 | { 62 | #if PY_MAJOR_VERSION > 2 63 | PyObject* module = PyModule_Create(&bbb_dht_module); 64 | #else 65 | Py_InitModule("Beaglebone_Black_Driver", module_methods); 66 | #endif 67 | 68 | #if PY_MAJOR_VERSION > 2 69 | return module; 70 | #else 71 | return; 72 | #endif 73 | } 74 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/source/_Raspberry_Pi_2_Driver.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #include 22 | 23 | #include "Raspberry_Pi_2/pi_2_dht_read.h" 24 | 25 | // Wrap calling dht_read function and expose it as a DHT.read Python module & function. 26 | static PyObject* Raspberry_Pi_2_Driver_read(PyObject *self, PyObject *args) 27 | { 28 | // Parse sensor and pin integer arguments. 29 | int sensor, pin; 30 | if (!PyArg_ParseTuple(args, "ii", &sensor, &pin)) { 31 | return NULL; 32 | } 33 | // Call dht_read and return result code, humidity, and temperature. 34 | float humidity = 0, temperature = 0; 35 | int result = pi_2_dht_read(sensor, pin, &humidity, &temperature); 36 | return Py_BuildValue("iff", result, humidity, temperature); 37 | } 38 | 39 | // Boilerplate python module method list and initialization functions below. 40 | 41 | static PyMethodDef module_methods[] = { 42 | {"read", Raspberry_Pi_2_Driver_read, METH_VARARGS, "Read DHT sensor value on a Raspberry Pi 2."}, 43 | {NULL, NULL, 0, NULL} 44 | }; 45 | 46 | #if PY_MAJOR_VERSION > 2 47 | static struct PyModuleDef pi2_dht_module = { 48 | PyModuleDef_HEAD_INIT, 49 | "Raspberry_Pi_2_Driver", // name of module 50 | NULL, // module documentation, may be NULL 51 | -1, // size of per-interpreter state of the module, or -1 if the module keeps state in global variables. 52 | module_methods 53 | }; 54 | #endif 55 | 56 | #if PY_MAJOR_VERSION > 2 57 | PyMODINIT_FUNC PyInit_Raspberry_Pi_2_Driver(void) 58 | #else 59 | PyMODINIT_FUNC initRaspberry_Pi_2_Driver(void) 60 | #endif 61 | { 62 | #if PY_MAJOR_VERSION > 2 63 | PyObject* module = PyModule_Create(&pi2_dht_module); 64 | #else 65 | Py_InitModule("Raspberry_Pi_2_Driver", module_methods); 66 | #endif 67 | 68 | #if PY_MAJOR_VERSION > 2 69 | return module; 70 | #else 71 | return; 72 | #endif 73 | } 74 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/source/_Raspberry_Pi_Driver.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #include 22 | 23 | #include "Raspberry_Pi/pi_dht_read.h" 24 | 25 | // Wrap calling dht_read function and expose it as a DHT.read Python module & function. 26 | static PyObject* Raspberry_Pi_Driver_read(PyObject *self, PyObject *args) 27 | { 28 | // Parse sensor and pin integer arguments. 29 | int sensor, pin; 30 | if (!PyArg_ParseTuple(args, "ii", &sensor, &pin)) { 31 | return NULL; 32 | } 33 | // Call dht_read and return result code, humidity, and temperature. 34 | float humidity = 0, temperature = 0; 35 | int result = pi_dht_read(sensor, pin, &humidity, &temperature); 36 | return Py_BuildValue("iff", result, humidity, temperature); 37 | } 38 | 39 | // Boilerplate python module method list and initialization functions below. 40 | 41 | static PyMethodDef module_methods[] = { 42 | {"read", Raspberry_Pi_Driver_read, METH_VARARGS, "Read DHT sensor value on a Raspberry Pi."}, 43 | {NULL, NULL, 0, NULL} 44 | }; 45 | 46 | #if PY_MAJOR_VERSION > 2 47 | static struct PyModuleDef pi_dht_module = { 48 | PyModuleDef_HEAD_INIT, 49 | "Raspberry_Pi_Driver", // name of module 50 | NULL, // module documentation, may be NULL 51 | -1, // size of per-interpreter state of the module, or -1 if the module keeps state in global variables. 52 | module_methods 53 | }; 54 | #endif 55 | 56 | #if PY_MAJOR_VERSION > 2 57 | PyMODINIT_FUNC PyInit_Raspberry_Pi_Driver(void) 58 | #else 59 | PyMODINIT_FUNC initRaspberry_Pi_Driver(void) 60 | #endif 61 | { 62 | #if PY_MAJOR_VERSION > 2 63 | PyObject* module = PyModule_Create(&pi_dht_module); 64 | #else 65 | Py_InitModule("Raspberry_Pi_Driver", module_methods); 66 | #endif 67 | 68 | #if PY_MAJOR_VERSION > 2 69 | return module; 70 | #else 71 | return; 72 | #endif 73 | } 74 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/source/_Test_Driver.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #include 22 | 23 | #include "Test/test_dht_read.h" 24 | 25 | // Wrap calling dht_read function and expose it as a DHT.read Python module & function. 26 | static PyObject* Test_Driver_read(PyObject *self, PyObject *args) 27 | { 28 | // Parse sensor and pin integer arguments. 29 | int sensor, pin; 30 | if (!PyArg_ParseTuple(args, "ii", &sensor, &pin)) { 31 | return NULL; 32 | } 33 | // Call dht_read and return result code, humidity, and temperature. 34 | float humidity = 0, temperature = 0; 35 | int result = test_dht_read(sensor, pin, &humidity, &temperature); 36 | return Py_BuildValue("iff", result, humidity, temperature); 37 | } 38 | 39 | // Boilerplate python module method list and initialization functions below. 40 | 41 | static PyMethodDef module_methods[] = { 42 | {"read", Test_Driver_read, METH_VARARGS, "Mock DHT read function."}, 43 | {NULL, NULL, 0, NULL} 44 | }; 45 | 46 | #if PY_MAJOR_VERSION > 2 47 | static struct PyModuleDef test_dht_module = { 48 | PyModuleDef_HEAD_INIT, 49 | "Test_Driver", // name of module 50 | NULL, // module documentation, may be NULL 51 | -1, // size of per-interpreter state of the module, or -1 if the module keeps state in global variables. 52 | module_methods 53 | }; 54 | #endif 55 | 56 | #if PY_MAJOR_VERSION > 2 57 | PyMODINIT_FUNC PyInit_Test_Driver(void) 58 | #else 59 | PyMODINIT_FUNC initTest_Driver(void) 60 | #endif 61 | { 62 | #if PY_MAJOR_VERSION > 2 63 | PyObject* module = PyModule_Create(&test_dht_module); 64 | #else 65 | Py_InitModule("Test_Driver", module_methods); 66 | #endif 67 | 68 | #if PY_MAJOR_VERSION > 2 69 | return module; 70 | #else 71 | return; 72 | #endif 73 | } 74 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/source/common_dht_read.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "common_dht_read.h" 28 | 29 | void busy_wait_milliseconds(uint32_t millis) { 30 | // Set delay time period. 31 | struct timeval deltatime; 32 | deltatime.tv_sec = millis / 1000; 33 | deltatime.tv_usec = (millis % 1000) * 1000; 34 | struct timeval walltime; 35 | // Get current time and add delay to find end time. 36 | gettimeofday(&walltime, NULL); 37 | struct timeval endtime; 38 | timeradd(&walltime, &deltatime, &endtime); 39 | // Tight loop to waste time (and CPU) until enough time as elapsed. 40 | while (timercmp(&walltime, &endtime, <)) { 41 | gettimeofday(&walltime, NULL); 42 | } 43 | } 44 | 45 | void sleep_milliseconds(uint32_t millis) { 46 | struct timespec sleep; 47 | sleep.tv_sec = millis / 1000; 48 | sleep.tv_nsec = (millis % 1000) * 1000000L; 49 | while (clock_nanosleep(CLOCK_MONOTONIC, 0, &sleep, &sleep) && errno == EINTR); 50 | } 51 | 52 | void set_max_priority(void) { 53 | struct sched_param sched; 54 | memset(&sched, 0, sizeof(sched)); 55 | // Use FIFO scheduler with highest priority for the lowest chance of the kernel context switching. 56 | sched.sched_priority = sched_get_priority_max(SCHED_FIFO); 57 | sched_setscheduler(0, SCHED_FIFO, &sched); 58 | } 59 | 60 | void set_default_priority(void) { 61 | struct sched_param sched; 62 | memset(&sched, 0, sizeof(sched)); 63 | // Go back to default scheduler with default 0 priority. 64 | sched.sched_priority = 0; 65 | sched_setscheduler(0, SCHED_OTHER, &sched); 66 | } 67 | -------------------------------------------------------------------------------- /Python/di_sensors/DHT_Sensor/source/common_dht_read.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Adafruit Industries 2 | // Author: Tony DiCola 3 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #ifndef COMMON_DHT_READ_H 22 | #define COMMON_DHT_READ_H 23 | 24 | #include 25 | 26 | // Define errors and return values. 27 | #define DHT_ERROR_TIMEOUT -1 28 | #define DHT_ERROR_CHECKSUM -2 29 | #define DHT_ERROR_ARGUMENT -3 30 | #define DHT_ERROR_GPIO -4 31 | #define DHT_SUCCESS 0 32 | 33 | // Define sensor types. 34 | #define DHT11 11 35 | #define DHT22 22 36 | #define AM2302 22 37 | 38 | // Busy wait delay for most accurate timing, but high CPU usage. 39 | // Only use this for short periods of time (a few hundred milliseconds at most)! 40 | void busy_wait_milliseconds(uint32_t millis); 41 | 42 | // General delay that sleeps so CPU usage is low, but accuracy is potentially bad. 43 | void sleep_milliseconds(uint32_t millis); 44 | 45 | // Increase scheduling priority and algorithm to try to get 'real time' results. 46 | void set_max_priority(void); 47 | 48 | // Drop scheduling priority back to normal/default. 49 | void set_default_priority(void); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Python/di_sensors/PCA9570.py: -------------------------------------------------------------------------------- 1 | # https://www.dexterindustries.com 2 | # 3 | # Copyright (c) 2017 Dexter Industries 4 | # Released under the MIT license (http://choosealicense.com/licenses/mit/). 5 | # For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md 6 | # 7 | # Python drivers for the PCA9570 I2C output expander 8 | 9 | from __future__ import print_function 10 | from __future__ import division 11 | 12 | import di_i2c 13 | 14 | # Constants 15 | ADDRESS = 0x24 16 | 17 | 18 | class PCA9570(object): 19 | """Drivers for PCA9570 I2C output expander""" 20 | 21 | def __init__(self, bus = "RPI_1SW"): 22 | """Initialize the I2C output expander 23 | 24 | Keyword arguments: 25 | bus (default RPI_1SW) -- The I2C bus""" 26 | self.i2c_bus = di_i2c.DI_I2C(bus = bus, address = ADDRESS) 27 | 28 | def set_pins(self, value): 29 | """Set the output pin states 30 | 31 | Keyword arguments: 32 | value -- The bit values for the 4 outputs""" 33 | self.i2c_bus.write_8((value & 0x0F)) 34 | 35 | def get_pins(self): 36 | """Get the output pin states 37 | 38 | Returns the bit values for the 4 outputs""" 39 | return (self.i2c_bus.read_8() & 0x0F) 40 | -------------------------------------------------------------------------------- /Python/di_sensors/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DexterInd/DI_Sensors/9f8d8cc57e06eb9c154af712490c41b34624a943/Python/di_sensors/__init__.py -------------------------------------------------------------------------------- /Python/di_sensors/easy_mutex.py: -------------------------------------------------------------------------------- 1 | ''' 2 | MUTEX HANDLING 3 | ''' 4 | import I2C_mutex 5 | mutex = I2C_mutex.Mutex(debug = False) 6 | 7 | def ifMutexAcquire(mutex_enabled = False): 8 | """ 9 | Acquires the I2C if the ``use_mutex`` parameter of the constructor was set to ``True``. 10 | Always acquires if system-wide mutex has been set. 11 | 12 | """ 13 | if mutex_enabled or mutex.overall_mutex()==True: 14 | mutex.acquire() 15 | 16 | def ifMutexRelease(mutex_enabled = False): 17 | """ 18 | Releases the I2C if the ``use_mutex`` parameter of the constructor was set to ``True``. 19 | 20 | """ 21 | if mutex_enabled or mutex.overall_mutex()==True: 22 | mutex.release() -------------------------------------------------------------------------------- /Python/di_sensors/easy_temp_hum_press.py: -------------------------------------------------------------------------------- 1 | # https://www.dexterindustries.com 2 | # 3 | # Copyright (c) 2018 Dexter Industries 4 | # Released under the MIT license (http://choosealicense.com/licenses/mit/). 5 | # For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md 6 | # 7 | 8 | # EASIER WRAPPERS FOR: 9 | # IMU SENSOR, 10 | # LIGHT AND COLOR SENSOR 11 | # TEMPERATURE, HUMIDITY and PRESSURE SENSOR 12 | 13 | # MUTEX SUPPORT WHEN NEEDED 14 | 15 | 16 | from di_sensors import temp_hum_press 17 | from time import sleep 18 | 19 | from di_sensors.easy_mutex import ifMutexAcquire, ifMutexRelease 20 | 21 | ''' 22 | PORT TRANSLATION 23 | ''' 24 | ports = { 25 | "AD1": "GPG3_AD1", 26 | "AD2": "GPG3_AD2" 27 | } 28 | 29 | class EasyTHPSensor(temp_hum_press.TempHumPress): 30 | """ 31 | Class for interfacing with the `Temperature Humidity Pressure Sensor`_. 32 | 33 | This class compared to :py:class:`~di_sensors.temp_hum_press.TempHumPress` uses mutexes that allows a given 34 | object to be accessed simultaneously from multiple threads/processes. 35 | Apart from this difference, there may 36 | also be functions that are more user-friendly than the latter. 37 | 38 | """ 39 | 40 | def __init__(self, port="I2C", use_mutex=False): 41 | """ 42 | Constructor for initializing link with the `Temperature Humidity Pressure Sensor`_. 43 | 44 | :param str port = "I2C": The port to which the THP sensor is connected to. Can also be connected to ports ``"AD1"`` or ``"AD2"`` of the `GoPiGo3`_. If you're passing an **invalid port**, then the sensor resorts to an ``"I2C"`` connection. Check the :ref:`hardware specs ` for more information about the ports. 45 | :param bool use_mutex = False: When using multiple threads/processes that access the same resource/device, mutexes should be enabled. 46 | :raises ~exceptions.OSError: When the sensor cannot be reached. 47 | 48 | """ 49 | self.use_mutex = use_mutex 50 | 51 | try: 52 | bus = ports[port] 53 | except KeyError: 54 | bus = "RPI_1SW" 55 | 56 | ifMutexAcquire(self.use_mutex) 57 | try: 58 | super(self.__class__, self).__init__(bus = bus) 59 | except Exception as e: 60 | raise 61 | finally: 62 | ifMutexRelease(self.use_mutex) 63 | 64 | def safe_celsius(self): 65 | """ 66 | Read temperature in Celsius degrees. 67 | 68 | :returns: Temperature in Celsius degrees. 69 | :rtype: float 70 | :raises ~exceptions.OSError: When the sensor cannot be reached. 71 | 72 | """ 73 | ifMutexAcquire(self.use_mutex) 74 | try: 75 | temp = self.get_temperature_celsius() 76 | except Exception as e: 77 | raise 78 | finally: 79 | ifMutexRelease(self.use_mutex) 80 | 81 | return round(temp,0) 82 | 83 | def safe_fahrenheit(self): 84 | """ 85 | Read temperature in Fahrenheit degrees. 86 | 87 | :returns: Temperature in Fahrenheit degrees. 88 | :rtype: float 89 | :raises ~exceptions.OSError: When the sensor cannot be reached. 90 | 91 | """ 92 | ifMutexAcquire(self.use_mutex) 93 | try: 94 | temp = self.get_temperature_fahrenheit() 95 | except Exception as e: 96 | raise 97 | finally: 98 | ifMutexRelease(self.use_mutex) 99 | 100 | return round(temp,0) 101 | 102 | def safe_pressure(self): 103 | """ 104 | Read the air pressure in pascals. 105 | 106 | :returns: The air pressure in pascals. 107 | :rtype: float 108 | :raises ~exceptions.OSError: When the sensor cannot be reached. 109 | 110 | """ 111 | ifMutexAcquire(self.use_mutex) 112 | try: 113 | pressure = self.get_pressure() 114 | except Exception as e: 115 | raise 116 | finally: 117 | ifMutexRelease(self.use_mutex) 118 | 119 | return round(pressure,0) 120 | 121 | def safe_humidity(self): 122 | """ 123 | Read the relative humidity as a percentage. 124 | 125 | :returns: Percentage of the relative humidity. 126 | :rtype: float 127 | :raises ~exceptions.OSError: When the sensor cannot be reached. 128 | 129 | """ 130 | ifMutexAcquire(self.use_mutex) 131 | try: 132 | humidity = self.get_humidity() 133 | except Exception as e: 134 | raise 135 | finally: 136 | ifMutexRelease(self.use_mutex) 137 | 138 | return round(humidity,0) 139 | -------------------------------------------------------------------------------- /Python/di_sensors/grove_rgb_lcd/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DexterInd/DI_Sensors/9f8d8cc57e06eb9c154af712490c41b34624a943/Python/di_sensors/grove_rgb_lcd/__init__.py -------------------------------------------------------------------------------- /Python/di_sensors/grove_rgb_lcd/example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # GrovePi Example for using the Grove - LCD RGB Backlight (http://www.seeedstudio.com/wiki/Grove_-_LCD_RGB_Backlight) 4 | # 5 | # The GrovePi connects the Raspberry Pi and Grove sensors. You can learn more about GrovePi here: http://www.dexterindustries.com/GrovePi 6 | # 7 | # Have a question about this example? Ask on the forums here: http://forum.dexterindustries.com/c/grovepi 8 | # 9 | ''' 10 | ## License 11 | 12 | The MIT License (MIT) 13 | 14 | GrovePi for the Raspberry Pi: an open source platform for connecting Grove Sensors to the Raspberry Pi. 15 | Copyright (C) 2017 Dexter Industries 16 | 17 | Permission is hereby granted, free of charge, to any person obtaining a copy 18 | of this software and associated documentation files (the "Software"), to deal 19 | in the Software without restriction, including without limitation the rights 20 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 21 | copies of the Software, and to permit persons to whom the Software is 22 | furnished to do so, subject to the following conditions: 23 | 24 | The above copyright notice and this permission notice shall be included in 25 | all copies or substantial portions of the Software. 26 | 27 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 30 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 31 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 32 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 33 | THE SOFTWARE. 34 | ''' 35 | 36 | from grove_rgb_lcd import * 37 | 38 | setText("Hello world\nLCD test") 39 | setRGB(0,128,64) 40 | 41 | # Slowly change the colors every 0.01 seconds. 42 | for c in range(0,255): 43 | setRGB(c,255-c,0) 44 | time.sleep(0.01) 45 | 46 | setRGB(0,255,0) 47 | setText("Bye bye, this should wrap") 48 | -------------------------------------------------------------------------------- /Python/di_sensors/grove_rgb_lcd/example3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # GrovePi Example for using the Grove - LCD RGB Backlight without erasing the screen(http://www.seeedstudio.com/wiki/Grove_-_LCD_RGB_Backlight) 4 | # 5 | # The GrovePi connects the Raspberry Pi and Grove sensors. You can learn more about GrovePi here: http://www.dexterindustries.com/GrovePi 6 | # 7 | # Have a question about this example? Ask on the forums here: http://forum.dexterindustries.com/c/grovepi 8 | # 9 | ''' 10 | ## License 11 | 12 | The MIT License (MIT) 13 | 14 | GrovePi for the Raspberry Pi: an open source platform for connecting Grove Sensors to the Raspberry Pi. 15 | Copyright (C) 2017 Dexter Industries 16 | 17 | Permission is hereby granted, free of charge, to any person obtaining a copy 18 | of this software and associated documentation files (the "Software"), to deal 19 | in the Software without restriction, including without limitation the rights 20 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 21 | copies of the Software, and to permit persons to whom the Software is 22 | furnished to do so, subject to the following conditions: 23 | 24 | The above copyright notice and this permission notice shall be included in 25 | all copies or substantial portions of the Software. 26 | 27 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 30 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 31 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 32 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 33 | THE SOFTWARE. 34 | ''' 35 | from grove_rgb_lcd import * 36 | import time 37 | 38 | setRGB(0,255,0) 39 | buf=list("Grove -Update without erase") 40 | setText("".join(buf)) 41 | time.sleep(1) 42 | 43 | for i in range(len(buf)): 44 | buf[i]="." 45 | setText_norefresh("".join(buf)) 46 | time.sleep(.1) 47 | -------------------------------------------------------------------------------- /Python/di_sensors/light_color_sensor.py: -------------------------------------------------------------------------------- 1 | # https://www.dexterindustries.com 2 | # 3 | # Copyright (c) 2017 Dexter Industries 4 | # Released under the MIT license (http://choosealicense.com/licenses/mit/). 5 | # For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md 6 | # 7 | # Python drivers for the Dexter Industries Light Color Sensor 8 | 9 | from __future__ import print_function 10 | from __future__ import division 11 | 12 | from di_sensors import TCS34725 13 | import time 14 | 15 | PCA9570LED = False # set to True for Light Color Sensor boards v1.1.0 and earlier for the PCA9570 to control the LED 16 | if PCA9570LED: 17 | from di_sensors import PCA9570 18 | 19 | 20 | class LightColorSensor(object): 21 | """ 22 | Class for interfacing with the `Light Color Sensor`_. 23 | """ 24 | 25 | def __init__(self, sensor_integration_time = 0.0048, sensor_gain = TCS34725.GAIN_16X, led_state = False, bus = "RPI_1SW"): 26 | """ 27 | Constructor for initializing a link to the `Light Color Sensor`_. 28 | 29 | :param float sensor_integration_time = 0.0048: Time in seconds for each sample (aka the time needed to take a sample). Range is between 0.0024 and 0.6144 seconds. Use increments of 2.4 ms. 30 | :param int sensor_gain = di_sensors.TCS34725.GAIN_16X: The gain constant of the sensor. Valid values are :py:const:`di_sensors.TCS34725.GAIN_1X`, :py:const:`di_sensors.TCS34725.GAIN_4X`, :py:const:`di_sensors.TCS34725.GAIN_16X` or :py:const:`di_sensors.TCS34725.GAIN_60X`. 31 | :param bool led_state = False: The LED state. If it's set to ``True``, then the LED will turn on, otherwise the LED will stay off. By default, the LED is turned on. 32 | :param str bus = "RPI_1SW": The bus to which the distance sensor is connected to. By default, it's set to bus ``"RPI_1SW"``. Check the :ref:`hardware specs ` for more information about the ports. 33 | :raises ~exceptions.OSError: When the `Light Color Sensor`_ is not reachable. 34 | :raises ~exceptions.RuntimeError: When the chip ID is incorrect. This happens when we have a device pointing to the same address, but it's not a `Light Color Sensor`_. 35 | 36 | """ 37 | self.TCS34725 = TCS34725.TCS34725(sensor_integration_time, sensor_gain, bus) 38 | if PCA9570LED: 39 | self.PCA9570 = PCA9570.PCA9570(bus) 40 | self.set_led(led_state) 41 | 42 | # set the state of the LED 43 | def set_led(self, value, delay = True): 44 | """ 45 | Set the LED state. 46 | 47 | :param bool value: If set to ``True``, then the LED turns on, otherwise it stays off. 48 | :param bool delay = True: When it's set to ``True``, the LED turns on after *2 * time_to_take_sample* seconds have passed. This ensures that the next read following the LED change will be correct. 49 | :raises ~exceptions.OSError: When the `Light Color Sensor`_ is not reachable. 50 | 51 | """ 52 | if PCA9570LED: 53 | if value: 54 | self.PCA9570.set_pins(0x00) 55 | else: 56 | self.PCA9570.set_pins(0x01) 57 | else: 58 | self.TCS34725.set_interrupt(value) 59 | 60 | if delay: 61 | # Delay for twice the integration time to ensure the LED state change has taken effect and a full sample has been made before the next reading. 62 | time.sleep((((256 - self.TCS34725.integration_time_val) * 0.0024) * 2)) 63 | 64 | def get_raw_colors(self, delay = True): 65 | """ 66 | Read the sensor values. 67 | 68 | :param bool delay = True: Delay for the time it takes to sample. If the delay is set to be added, then we are ensured to get fresh values on every call. Used in conjuction with the :py:meth:`~di_sensors.light_color_sensor.set_led` method. 69 | :returns: The RGBA values from the sensor. RGBA = Red, Green, Blue, Alpha (or Clear). 70 | :rtype: (float,float,float,float) where the range of each element is between 0 and 1. 71 | :raises ~exceptions.OSError: If the `Light Color Sensor`_ can't be reached. 72 | 73 | """ 74 | 75 | return self.TCS34725.get_raw_data(delay) 76 | -------------------------------------------------------------------------------- /Python/di_sensors/line_follower_calibration/line_follower_calibration.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Encoding=UTF-8 3 | Type=Application 4 | Name=Line Follower Calibration 5 | Comment=Line Follower Calibration 6 | Icon=/home/pi/Dexter/DI_Sensors/Python/di_sensors/line_follower_calibration/obconf.png 7 | Exec=python /home/pi/Dexter/DI_Sensors/Python/di_sensors/line_follower_calibration/line_sensor_calibration_gui.py 8 | NoDisplay=true 9 | -------------------------------------------------------------------------------- /Python/di_sensors/line_follower_calibration/obconf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DexterInd/DI_Sensors/9f8d8cc57e06eb9c154af712490c41b34624a943/Python/di_sensors/line_follower_calibration/obconf.png -------------------------------------------------------------------------------- /Python/di_sensors/red_line_follower/line_follower/README.md: -------------------------------------------------------------------------------- 1 | # GoPiGo Line Follower 2 | 3 | This Python library is for the [GoPiGo Line follower](http://www.dexterindustries.com/shop/line-follower-for-gopigo/). 4 | 5 | ## Files 6 | 7 | ###Calibration and Utilities 8 | - line_threshold_set.py: Use this program to set the black/white values. Run once. 9 | - black_line.txt: Holds the black line values. 10 | - white_line.txt: Holds the white line values. 11 | - range_line.txt: Holds the range of values. 12 | - line_sensor.py: Library for the line sensor. 13 | - line_follow.py: Basic GoPiGo example to use the line sensor. 14 | 15 | ###Examples 16 | - basic_example.py: This example shows a basic example to read sensor data from the line sensor. 17 | - check_line_sensor.py: Checks the I2C bus for the line follower. 18 | - line_follow.py: A very basic example using bang-bang control. 19 | - line_follow1.py: An advanced example of line following using arrays and proportional response. 20 | - line_position.py: This example reads the position of the line the sensor is positioned over. 21 | 22 | ###Scratch 23 | - scratch_line.py: Runs the sensor in Scratch in the background. 24 | - line_sensor_gui.py: The GUI program for calibration. A visual form of the line_threshold_set.py program. 25 | 26 | 27 | ## See Also 28 | 29 | - [Dexter Industries] (http://www.dexterindustries.com/GoPiGo) 30 | - [Raspberry Pi] (http://www.raspberrypi.org/) 31 | 32 | ![ GoPiGo ](https://raw.githubusercontent.com/DexterInd/GoPiGo/master/GoPiGo_Chassis-300.jpg) 33 | 34 | This repository contains source code, firmware and design materials for the GoPiGo. 35 | 36 | ![ GoPiGo ](https://raw.githubusercontent.com/DexterInd/GoPiGo/master/GoPiGo_Front_Facing_Camera300.jpg) 37 | 38 | ## License 39 | GoPiGo for the Raspberry Pi: an open source robotics platform for the Raspberry Pi. 40 | Copyright (C) 2015 Dexter Industries 41 | 42 | This program is free software: you can redistribute it and/or modify 43 | it under the terms of the GNU General Public License as published by 44 | the Free Software Foundation, either version 3 of the License, or 45 | (at your option) any later version. 46 | 47 | This program is distributed in the hope that it will be useful, 48 | but WITHOUT ANY WARRANTY; without even the implied warranty of 49 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 50 | GNU General Public License for more details. 51 | 52 | You should have received a copy of the GNU General Public License 53 | along with this program. If not, see . 54 | -------------------------------------------------------------------------------- /Python/di_sensors/red_line_follower/line_follower/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DexterInd/DI_Sensors/9f8d8cc57e06eb9c154af712490c41b34624a943/Python/di_sensors/red_line_follower/line_follower/__init__.py -------------------------------------------------------------------------------- /Python/di_sensors/red_line_follower/line_follower/basic_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Dexter Industries line sensor basic example 3 | # 4 | # This example shows a basic example to read sensor data from the line sensor. Most basic example prints out the data from the 5 sensors on the line follower. 5 | # 6 | # Have a question about this example? Ask on the forums here: http://www.dexterindustries.com/forum/?forum=gopigo 7 | # 8 | # 9 | # Initial Date: 13 Dec 2015 Karan Nayan 10 | # Last Updated: 16 Feb 2016 John Cole 11 | # http://www.dexterindustries.com/ 12 | ''' 13 | ## License 14 | Copyright (C) 2017 Dexter Industries 15 | 16 | This program is free software: you can redistribute it and/or modify 17 | it under the terms of the GNU General Public License as published by 18 | the Free Software Foundation, either version 3 of the License, or 19 | (at your option) any later version. 20 | 21 | This program is distributed in the hope that it will be useful, 22 | but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | GNU General Public License for more details. 25 | 26 | You should have received a copy of the GNU General Public License 27 | along with this program. If not, see . 28 | ''' 29 | from __future__ import print_function 30 | from __future__ import division 31 | from builtins import input 32 | # the above lines are meant for Python3 compatibility. 33 | # they force the use of Python3 functionality for print(), 34 | # the integer division and input() 35 | # mind your parentheses! 36 | 37 | import line_sensor 38 | import time 39 | 40 | def get_sensorval(): 41 | while True: 42 | val=line_sensor.read_sensor() 43 | if val[0]!=-1: 44 | return val 45 | #else: 46 | #Read once more to clear buffer and remove junk values 47 | # val=line_sensor.read_sensor() 48 | while True: 49 | l0,l1,l2,l3,l4=get_sensorval() 50 | print (l0,l1,l2,l3,l4) 51 | #time.sleep(.05) 52 | -------------------------------------------------------------------------------- /Python/di_sensors/red_line_follower/line_follower/black_line.txt: -------------------------------------------------------------------------------- 1 | (I987 2 | I1010 3 | I1004 4 | I996 5 | I986 6 | tp0 7 | . -------------------------------------------------------------------------------- /Python/di_sensors/red_line_follower/line_follower/check_line_sensor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Dexter Industries line sensor check script 3 | # 4 | # This program checks the I2C bus for the line follower and also makes a read to make sure that the line sesnor is working properly 5 | # 6 | # Have a question about this example? Ask on the forums here: http://www.dexterindustries.com/forum/?forum=grovepi 7 | # 8 | # Karan Nayan 9 | # Initial Date: 13 Dec 2015 10 | # Last Updated: 13 Dec 2015 11 | # http://www.dexterindustries.com/ 12 | ''' 13 | ## License 14 | Copyright (C) 2017 Dexter Industries 15 | 16 | This program is free software: you can redistribute it and/or modify 17 | it under the terms of the GNU General Public License as published by 18 | the Free Software Foundation, either version 3 of the License, or 19 | (at your option) any later version. 20 | 21 | This program is distributed in the hope that it will be useful, 22 | but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | GNU General Public License for more details. 25 | 26 | You should have received a copy of the GNU General Public License 27 | along with this program. If not, see . 28 | ''' 29 | import line_sensor 30 | import time 31 | import subprocess 32 | from timeit import default_timer as timer 33 | 34 | debug=0 35 | 36 | def get_sensorval(): 37 | while True: 38 | val=line_sensor.read_sensor() 39 | if val[0]<>-1: 40 | return val 41 | #else: 42 | #Read once more to clear buffer and remove junk values 43 | # val=line_sensor.read_sensor() 44 | 45 | def check_line_sensor(): 46 | output = subprocess.check_output(['i2cdetect', '-y','1']) 47 | if output.find('06') >=0: 48 | print "--> Line sensor found\n" 49 | if debug: 50 | print output 51 | else: 52 | print "--> Line sensor not found" 53 | print output 54 | print "" 55 | 56 | check_line_sensor() 57 | start=timer() 58 | l0,l1,l2,l3,l4=get_sensorval() 59 | end=timer() 60 | print "Time:\t%.4f s" %(end-start) 61 | print "IR1:\t%d /1023 " %(l0) 62 | print "IR2:\t%d /1023 " %(l1) 63 | print "IR3:\t%d /1023 " %(l2) 64 | print "IR4:\t%d /1023 " %(l3) 65 | print "IR5:\t%d /1023 " %(l4) 66 | -------------------------------------------------------------------------------- /Python/di_sensors/red_line_follower/line_follower/line_follow.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Encoding=UTF-8 3 | Type=Application 4 | Name=Line Follower Calibration 5 | Comment=Line Follower Calibration 6 | Icon=/home/pi/Dexter/DI_Sensors/Python/di_sensors/red_line_follower/line_follower/obconf.xpm 7 | Exec=python /home/pi/Dexter/DI_Sensors/Python/di_sensors/red_line_follower/line_follower/line_sensor_gui.py 8 | NoDisplay=true 9 | -------------------------------------------------------------------------------- /Python/di_sensors/red_line_follower/line_follower/line_follow.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Dexter Industries Line sensor Python Library 3 | # 4 | # This is and example to make the GoPiGo follow the line using the Dexter Industries Line follower. 5 | # 6 | # Have a question about this example? Ask on the forums here: http://www.dexterindustries.com/forum/ 7 | # 8 | # http://www.dexterindustries.com/ 9 | 10 | from __future__ import print_function 11 | from __future__ import division 12 | from builtins import input 13 | # the above lines are meant for Python3 compatibility. 14 | # they force the use of Python3 functionality for print(), 15 | # the integer division and input() 16 | # mind your parentheses! 17 | 18 | import line_sensor 19 | import time 20 | import operator 21 | import gopigo 22 | import atexit 23 | 24 | atexit.register(gopigo.stop) # Stop the motors when the program is over. 25 | 26 | #Get a value which does have -1 27 | def get_sensorval(): 28 | while True: 29 | val=line_sensor.read_sensor() 30 | if val[0]!=-1: 31 | return val 32 | else: 33 | #Read once more to clear buffer and remove junk values 34 | val=line_sensor.read_sensor() 35 | 36 | 37 | #Add a multipler to each sensor 38 | multp=[-100,-50,0,50,100] 39 | 40 | #TRAIN for the first time 41 | #reading when all sensors are at white 42 | white=[767,815,859,710,700] 43 | #reading when all sensors are black 44 | black=[1012,1013,1015,1003,1004] 45 | #difference between black and white 46 | range_col=list(map(operator.sub, black, white)) 47 | 48 | #Calibrate at first run 49 | gopigo.set_speed(150) 50 | 51 | gpg_en=1 52 | while True: 53 | curr=get_sensorval() 54 | #Get current difference bwtween white and line 55 | diff_val=list(map(operator.sub, curr, white)) 56 | 57 | #find how much black line each sensor is able to get 58 | #find the position of the bot 59 | # -10000 -> extreme left 60 | # 0 -> centre 61 | # 10000 -> extreme right 62 | curr_pos=0 63 | percent_black_line=[0]*5 64 | for i in range(5): 65 | percent_black_line[i]=diff_val[i]*100/range_col[i] 66 | curr_pos+=percent_black_line[i]*multp[i] 67 | print(curr_pos) 68 | 69 | if curr_pos <-2500: 70 | print("r") 71 | if gpg_en: 72 | gopigo.set_speed(85) 73 | gopigo.right() 74 | elif curr_pos >2500: 75 | print("l") 76 | if gpg_en: 77 | gopigo.set_speed(125) 78 | gopigo.left() 79 | else: 80 | print("f") 81 | if gpg_en: 82 | gopigo.set_speed(80) 83 | gopigo.fwd() 84 | #time.sleep(.01) 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /Python/di_sensors/red_line_follower/line_follower/line_position.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Dexter Industries line sensor basic example 3 | # 4 | # This example shows a basic example of how to read sensor data from the line sensor. 5 | # 6 | # Have a question about this example? Ask on the forums here: http://www.dexterindustries.com/forum/?forum=grovepi 7 | # 8 | # 9 | # Initial Date: 13 Dec 2015 Karan Nayan 10 | # Last Updated: 16 Feb 2016 John Cole 11 | # http://www.dexterindustries.com/ 12 | ''' 13 | ## License 14 | Copyright (C) 2017 Dexter Industries 15 | 16 | This program is free software: you can redistribute it and/or modify 17 | it under the terms of the GNU General Public License as published by 18 | the Free Software Foundation, either version 3 of the License, or 19 | (at your option) any later version. 20 | 21 | This program is distributed in the hope that it will be useful, 22 | but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | GNU General Public License for more details. 25 | 26 | You should have received a copy of the GNU General Public License 27 | along with this program. If not, see . 28 | ''' 29 | 30 | from __future__ import print_function 31 | from __future__ import division 32 | from builtins import input 33 | # the above lines are meant for Python3 compatibility. 34 | # they force the use of Python3 functionality for print(), 35 | # the integer division and input() 36 | # mind your parentheses! 37 | 38 | import line_sensor 39 | import time 40 | 41 | line_pos=[0]*5 42 | white_line=line_sensor.get_white_line() 43 | black_line=line_sensor.get_black_line() 44 | range_sensor= line_sensor.get_range() 45 | threshold=[a+b/2 for a,b in zip(white_line,range_sensor)] 46 | 47 | # print white_line 48 | # print black_line 49 | # print range 50 | # print threshold 51 | 52 | while True: 53 | raw_vals=line_sensor.get_sensorval() 54 | for i in range(5): 55 | if raw_vals[i]>threshold[i]: 56 | line_pos[i]=1 57 | else: 58 | line_pos[i]=0 59 | print(line_pos) 60 | 61 | 62 | -------------------------------------------------------------------------------- /Python/di_sensors/red_line_follower/line_follower/line_threshold_set.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Dexter Industries line sensor basic example 3 | # 4 | # This program is used to set the white and black threshold that we are going to use for the line sensor. 5 | # 6 | # Have a question about this example? Ask on the forums here: http://www.dexterindustries.com/forum/?forum=grovepi 7 | # 8 | # Karan Nayan 9 | # Initial Date: 13 Dec 2015 10 | # Last Updated: 13 Dec 2015 11 | # http://www.dexterindustries.com/ 12 | ''' 13 | ## License 14 | Copyright (C) 2017 Dexter Industries 15 | 16 | This program is free software: you can redistribute it and/or modify 17 | it under the terms of the GNU General Public License as published by 18 | the Free Software Foundation, either version 3 of the License, or 19 | (at your option) any later version. 20 | 21 | This program is distributed in the hope that it will be useful, 22 | but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | GNU General Public License for more details. 25 | 26 | You should have received a copy of the GNU General Public License 27 | along with this program. If not, see . 28 | ''' 29 | 30 | import line_sensor 31 | import time 32 | 33 | def get_sensorval(): 34 | while True: 35 | val=line_sensor.read_sensor() 36 | if val[0]<>-1: 37 | return val 38 | #else: 39 | #Read once more to clear buffer and remove junk values 40 | # val=line_sensor.read_sensor() 41 | 42 | print "WHITE LINE SETUP" 43 | while True: 44 | print "\nKeep all the sensors over a white strip and press ENTER", 45 | raw_input() 46 | print "--> Line sensor readings: ", 47 | get_sensorval() 48 | print get_sensorval() 49 | print "If the reading look good, press 'y' and Enter to continue, any other key to read again" 50 | inp=raw_input() 51 | if inp=='y': 52 | line_sensor.set_white_line() 53 | break 54 | print "White Line values set:", 55 | print line_sensor.get_white_line() 56 | 57 | print "BLACK LINE SETUP" 58 | while True: 59 | print "\nKeep all the sensors over a black strip and press ENTER", 60 | raw_input() 61 | print "--> Line sensor readings: ", 62 | get_sensorval() 63 | print get_sensorval() 64 | print "If the reading look good, press 'y' and Enter to continue, any other key to read again" 65 | inp=raw_input() 66 | if inp=='y': 67 | line_sensor.set_black_line() 68 | break 69 | print "Black Line values set:", 70 | print line_sensor.get_black_line() 71 | 72 | -------------------------------------------------------------------------------- /Python/di_sensors/red_line_follower/line_follower/range_line.txt: -------------------------------------------------------------------------------- 1 | (lp0 2 | I698 3 | aI654 4 | aI572 5 | aI937 6 | aI938 7 | a. -------------------------------------------------------------------------------- /Python/di_sensors/red_line_follower/line_follower/scratch_line.py: -------------------------------------------------------------------------------- 1 | # Scratch_Line. This file adapts the line follower to Scratch. 2 | 3 | from line_follower import line_sensor 4 | import time 5 | import pickle 6 | 7 | poll_time=0.01 8 | 9 | # Calibration Files. These are fixed positions because we assume 10 | # The user is using Raspbian for Robots. 11 | dir_path="/home/pi/Dexter/" 12 | file_b=dir_path+"black_line.txt" 13 | file_w=dir_path+"white_line.txt" 14 | file_r=dir_path+"range_line.txt" 15 | 16 | last_val=[0]*5 17 | curr=[0]*5 18 | 19 | #Enable messages on screen 20 | msg_en=1 21 | 22 | #Get line parameters 23 | line_pos=[0]*5 24 | 25 | #Position to take action on 26 | mid =[0,0,1,0,0] 27 | mid1 =[0,1,1,1,0] 28 | small_l =[0,1,1,0,0] 29 | small_l1=[0,1,0,0,0] 30 | small_r =[0,0,1,1,0] 31 | small_r1=[0,0,0,1,0] 32 | left =[1,1,0,0,0] 33 | left1 =[1,0,0,0,0] 34 | right =[0,0,0,1,1] 35 | right1 =[0,0,0,0,1] 36 | stop =[1,1,1,1,1] 37 | stop1 =[0,0,0,0,0] 38 | 39 | def get_black_line(): 40 | global black_line 41 | #load default values from files 42 | try: 43 | with open(file_b, 'rb') as f: 44 | black_line = pickle.load(f) 45 | except Exception as e: 46 | # print e 47 | black_line=[0]*5 48 | return black_line 49 | 50 | def get_white_line(): 51 | global white_line 52 | #load default values from files 53 | try: 54 | with open(file_w, 'rb') as f: 55 | white_line = pickle.load(f) 56 | except Exception as e: 57 | # print e 58 | white_line=[0]*5 59 | return white_line 60 | 61 | def get_range(): 62 | global range_col 63 | #load default values from files 64 | try: 65 | with open(file_r, 'rb') as f: 66 | range_col = pickle.load(f) 67 | except Exception as e: 68 | # print e 69 | range_col=[0]*5 70 | return range_col 71 | 72 | #Converts the raw values to absolute 0 and 1 depending on the threshold set 73 | def absolute_line_pos(): 74 | 75 | # line_pos=[0]*5 76 | # white_line=line_sensor.get_white_line() 77 | white_line = get_white_line() 78 | # print "White: " + str(white_line) 79 | black_line=get_black_line() 80 | # print "Black: " + str(black_line) 81 | range_sensor= get_range() 82 | # print "Range: " + str(range_sensor) 83 | threshold=[a+b/2 for a,b in zip(white_line,range_sensor)] 84 | 85 | # print "Threshold:" + str(threshold) 86 | 87 | raw_vals=line_sensor.get_sensorval() 88 | # print (raw_vals) 89 | 90 | # updated to handle the case where the line follower is not answering 91 | for i in range(5): 92 | if raw_vals[i] == -1: 93 | line_pos[i] = -1 94 | elif raw_vals[i]>threshold[i]: 95 | line_pos[i]=1 96 | else: 97 | line_pos[i]=0 98 | 99 | # print line_pos 100 | return line_pos 101 | 102 | 103 | #Action to run when a line is detected 104 | def line_sensor_val_scratch(): 105 | # Values returned for the positions in scratch 106 | # [0,0,1,0,0] 0 # Center 107 | # [0,1,1,1,0] 0 # Center 108 | # [0,1,1,0,0] -1 # Going right 109 | # [0,1,0,0,0] -2 110 | # [1,1,0,0,0] -3 111 | # [1,0,0,0,0] -4 # Completely right 112 | # [0,0,1,1,0] 1 # Going left 113 | # [0,0,0,1,0] 2 114 | # [0,0,0,1,1] 3 115 | # [0,0,0,0,1] 4 # Completely left 116 | # [1,1,1,1,1] 5 # All sensors reading black (stopping point) 117 | # [0,0,0,0,0] 6 # All sensors reading white (has veered off course) 118 | # 7 # Any thing else (erratic reading) 119 | curr=absolute_line_pos() 120 | 121 | if curr== mid or curr == mid1: 122 | return 0 123 | elif curr == small_l: 124 | return -1 125 | elif curr == small_l1: 126 | return -2 127 | elif curr == left: 128 | return -3 129 | elif curr == left1: 130 | return -4 131 | elif curr == small_r: 132 | return 1 133 | elif curr == small_r1: 134 | return 2 135 | elif curr == right: 136 | return 3 137 | elif curr == right1: 138 | return 4 139 | elif curr == stop: 140 | return 5 141 | elif curr == stop1: 142 | return 6 143 | else: 144 | return 7 145 | 146 | def line_sensor_vals(): 147 | #if the line is in the middle, keep moving straight 148 | #if the line is slightly left of right, keep moving straight 149 | curr=absolute_line_pos() 150 | if curr==small_r or curr==small_l or curr==mid or curr==mid1: 151 | return '0' 152 | 153 | #If the line is towards the sligh left, turn slight right 154 | elif curr==small_l1: 155 | return '-1' 156 | elif curr==left or curr==left1: 157 | return '-2' 158 | 159 | #If the line is towards the sligh right, turn slight left 160 | elif curr==small_r1: 161 | return '1' 162 | elif curr==right or curr==right1: 163 | return '2' 164 | elif curr==stop: 165 | return '3' 166 | else: 167 | return '4' 168 | 169 | 170 | if __name__ == "__main__": 171 | while True: 172 | print(line_sensor_vals()) 173 | time.sleep(poll_time) 174 | -------------------------------------------------------------------------------- /Python/di_sensors/red_line_follower/line_follower/white_line.txt: -------------------------------------------------------------------------------- 1 | (I289 2 | I356 3 | I432 4 | I59 5 | I48 6 | tp0 7 | . -------------------------------------------------------------------------------- /Python/di_sensors/red_line_follower/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | ''' 4 | ## License 5 | GoPiGo for the Raspberry Pi: an open source robotics platform for the Raspberry Pi. 6 | Copyright (C) 2017 Dexter Industries 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | ''' 21 | 22 | import setuptools 23 | setuptools.setup( 24 | name="Line Follower", 25 | version = "1.0.0", 26 | description="Drivers for the red line follower", 27 | author="Dexter Industries", 28 | url="http://www.dexterindustries.com/GoPiGo/", 29 | py_modules=['line_follower.line_sensor', 'line_follower.scratch_line'], 30 | install_requires = ['python-periphery'] 31 | ) 32 | -------------------------------------------------------------------------------- /Python/di_sensors/temp_hum_press.py: -------------------------------------------------------------------------------- 1 | # https://www.dexterindustries.com 2 | # 3 | # Copyright (c) 2017 Dexter Industries 4 | # Released under the MIT license (http://choosealicense.com/licenses/mit/). 5 | # For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md 6 | # 7 | # Python drivers for the Dexter Industries Temperature Humidity Pressure Sensor 8 | 9 | from __future__ import print_function 10 | from __future__ import division 11 | 12 | from di_sensors import BME280 13 | 14 | 15 | class TempHumPress(object): 16 | """ 17 | Class for interfacing with the `Temperature Humidity Pressure Sensor`_. 18 | """ 19 | 20 | def __init__(self, bus = "RPI_1SW"): 21 | """ 22 | Constructor for initializing link with the `Temperature Humidity Pressure Sensor`_. 23 | 24 | :param str bus = "RPI_1SW": The bus to which the THP sensor is connected to. By default, it's set to bus ``"RPI_1SW"``. Check the :ref:`hardware specs ` for more information about the ports. 25 | :raises ~exceptions.OSError: When the sensor cannot be reached. 26 | 27 | """ 28 | self.BME280 = BME280.BME280(bus = bus, t_mode = BME280.OSAMPLE_2, p_mode = BME280.OSAMPLE_4, h_mode = BME280.OSAMPLE_4, standby = BME280.STANDBY_10, filter = BME280.FILTER_8) 29 | 30 | def get_temperature_celsius(self): 31 | """ 32 | Read temperature in Celsius degrees. 33 | 34 | :returns: Temperature in Celsius degrees. 35 | :rtype: float 36 | :raises ~exceptions.OSError: When the sensor cannot be reached. 37 | 38 | """ 39 | return self.BME280.read_temperature() 40 | 41 | def get_temperature_fahrenheit(self): 42 | """ 43 | Read temperature in Fahrenheit degrees. 44 | 45 | :returns: Temperature in Fahrenheit degrees. 46 | :rtype: float 47 | :raises ~exceptions.OSError: When the sensor cannot be reached. 48 | 49 | """ 50 | return self.BME280.read_temperature_f() 51 | 52 | 53 | def get_pressure(self): 54 | """ 55 | Read the air pressure in pascals. 56 | 57 | :returns: The air pressure in pascals. 58 | :rtype: float 59 | :raises ~exceptions.OSError: When the sensor cannot be reached. 60 | 61 | """ 62 | return self.BME280.read_pressure() 63 | 64 | def get_humidity(self): 65 | """ 66 | Read the relative humidity as a percentage. 67 | 68 | :returns: Percentage of the relative humidity. 69 | :rtype: float 70 | :raises ~exceptions.OSError: When the sensor cannot be reached. 71 | 72 | """ 73 | return self.BME280.read_humidity() 74 | -------------------------------------------------------------------------------- /Python/package_description.rst: -------------------------------------------------------------------------------- 1 | This package contains the drivers for the following Grove compatible devices: 2 | 3 | * Dexter Industries 4 | 5 | * `Distance Sensor `_ 6 | * `Inertial Measurement Unit Sensor `_ 7 | * Light Color Sensor 8 | * Temperature Humidity Pressure Sensor 9 | 10 | * Grove: 11 | 12 | * `RGB LCD `_ 13 | 14 | More details can be found on our `github repo folder `_ 15 | -------------------------------------------------------------------------------- /Python/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # https://GoPiGo.io/ 4 | # https://github.com/DexterInd/DI_Sensors 5 | # 6 | # Copyright (c) 2022 Modular Robotics 7 | # Released under the MIT license (http://choosealicense.com/licenses/mit/). 8 | # For more information see https://github.com/DexterInd/GoPiGo3/blob/master/LICENSE.md 9 | 10 | try: 11 | with open('package_description.rst', 'r') as file_description: 12 | description = file_description.read() 13 | 14 | except IOError: 15 | print(str(IOError)) 16 | print("make sure you have [package_description.rst] file in the same directory as [setup.py]") 17 | 18 | from setuptools import setup, find_packages 19 | setup( 20 | name = "DI_Sensors", 21 | version = "1.0.0", 22 | 23 | description = "Drivers and examples for using DI_Sensors in Python", 24 | long_description = description, 25 | 26 | author = "Modular Robotics", 27 | author_email = "info@modrobotics.com", 28 | 29 | license = "MIT", 30 | classifiers = [ 31 | 'Development Status :: 5 - Production/Stable', 32 | 'Intended Audience :: Developers', 33 | 'Intended Audience :: Education', 34 | 'License :: OSI Approved :: MIT License', 35 | 'Operating System :: POSIX :: Linux', 36 | 'Programming Language :: Python :: 2', 37 | 'Programming Language :: Python :: 3', 38 | 'Topic :: Software Development :: Embedded Systems', 39 | 'Topic :: Software Development :: Libraries :: Python Modules', 40 | ], 41 | url = "https://github.com/DexterInd/DI_Sensors", 42 | 43 | keywords = [ 44 | "Modular Robotics", 45 | "Distance Sensor", 46 | "Inertial Measurement Unit", 47 | "IMU", 48 | "Light Color Sensor", 49 | "Temperature Humidity Pressure Sensor", 50 | "RGB LCD", 51 | "DHT Sensor", 52 | ], 53 | packages = find_packages(), 54 | install_requires = ["python-periphery"] 55 | ) 56 | 57 | #install_requires=open('requirements.txt').readlines(), 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DI_Sensors [![Documentation Status](http://readthedocs.org/projects/di-sensors/badge/?version=master)](http://di-sensors.readthedocs.io/en/master/?badge=master) 2 | ============ 3 | Dexter Industries Sensors 4 | 5 | Compatibility 6 | ------------- 7 | 8 | The following Grove compatible devices are supported in Python: 9 | 10 | * Dexter Industries: 11 | * **[Distance Sensor](https://www.dexterindustries.com/shop/distance-sensor/)** - Distance Sensor for the GoPiGo, GrovePi, and BrickPi. The distance sensor can be mounted to the GoPiGo Raspberry Pi robot with or without the servo package to enable rotation. The sensor detects distances from obstacles and objects, giving your robot the ability to navigate. 12 | 13 | * **[Inertial Measurement Unit Sensor](https://www.dexterindustries.com/shop/imu-sensor/)** - The IMU Sensor attaches to the GrovePi, GoPiGo and BrickPi to detect motion, orientation, and position of your robot. It has a compass, accelerometer, and gyroscope and allows you to build a BalanceBot. 14 | 15 | * **[Light Color Sensor](https://www.dexterindustries.com/shop/light-color-sensor/)** - The Light & Color Sensor attaches to the GrovePi, GoPiGo and BrickPi to measure light levels and detect different colors. It can be used to build projects like a rubiks cube solver, weather station, or plant monitoring station. 16 | 17 | * **[Temperature Humidity Pressure Sensor](https://www.dexterindustries.com/shop/temperature-humidity-pressure-sensor/)**- The Temperature Humidity and Pressure Sensor attaches to the GrovePi, GoPiGo and BrickPi to measure environmental conditions. It can be used to build projects like a classroom weather station or plant monitoring station. 18 | 19 | * Grove: 20 | * **[RGB LCD](https://www.seeedstudio.com/Grove-LCD-RGB-Backlight-p-1643.html)**. 21 | 22 | 23 | Installation 24 | ------------ 25 | 26 | In order to quick install the `DI_Sensors` repository, open up a terminal and type following command: 27 | ``` 28 | curl -kL dexterindustries.com/update_sensors | bash 29 | ``` 30 | 31 | The same command can be used for updating the `DI_Sensors` to the latest version. 32 | 33 | License 34 | ------- 35 | 36 | Please review the [LICENSE.md] file for license information. 37 | 38 | [LICENSE.md]: ./LICENSE.md 39 | -------------------------------------------------------------------------------- /Scratch/di_sensorscommands.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DexterInd/DI_Sensors/9f8d8cc57e06eb9c154af712490c41b34624a943/Scratch/di_sensorscommands.png -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = python -msphinx 7 | SPHINXPROJ = DI-Sensors 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=python -msphinx 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | set SPHINXPROJ=DI-Sensors 13 | 14 | if "%1" == "" goto help 15 | 16 | %SPHINXBUILD% >NUL 2>NUL 17 | if errorlevel 9009 ( 18 | echo. 19 | echo.The Sphinx module was not found. Make sure you have Sphinx installed, 20 | echo.then set the SPHINXBUILD environment variable to point to the full 21 | echo.path of the 'sphinx-build' executable. Alternatively you may add the 22 | echo.Sphinx directory to PATH. 23 | echo. 24 | echo.If you don't have Sphinx installed, grab it from 25 | echo.http://sphinx-doc.org/ 26 | exit /b 1 27 | ) 28 | 29 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 30 | goto end 31 | 32 | :help 33 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 34 | 35 | :end 36 | popd 37 | -------------------------------------------------------------------------------- /docs/source/about.rst: -------------------------------------------------------------------------------- 1 | .. _about-chapter: 2 | 3 | ################ 4 | About DI-Sensors 5 | ################ 6 | 7 | ************************** 8 | Who we are and what we do. 9 | ************************** 10 | 11 | .. the image size was extracted from the image manually 12 | .. without the image size, the scale cannot be set 13 | .. image:: images/dexterlogo_big.jpg 14 | :scale: 100 15 | :width: 1695 16 | :height: 300 17 | 18 | `Dexter Industries`_ is an American educational robotics company that develops robot kits that make programming accessible for everyone. 19 | 20 | ******************************** 21 | What's this documentation about. 22 | ******************************** 23 | 24 | The documentation details how to use the sensors that `Dexter Industries`_ produces and maintains - that's where the **DI** acronym comes from. All the source code for these sensors has been written in Python. 25 | Within this documentation, you will find instructions on: 26 | 27 | * How to get started with the DI-Sensors - in general it refers to how to install them on your Raspberry Pi. 28 | * How to get going with the examples found in our repository. In the `DI_Sensors repository`_, you can find all the source code for our sensors and example programs. 29 | * How to use our DI-Sensors - we offer a thorough API on the sensors we have. 30 | 31 | 32 | .. _di_sensors repository: https://github.com/DexterInd/DI_Sensors.git 33 | .. _dexter industries: https://www.dexterindustries.com 34 | -------------------------------------------------------------------------------- /docs/source/api-advanced.rst: -------------------------------------------------------------------------------- 1 | ########################################### 2 | API DI-Sensors - Advanced 3 | ########################################### 4 | 5 | ============== 6 | DistanceSensor 7 | ============== 8 | 9 | .. autoclass:: di_sensors.distance_sensor.DistanceSensor 10 | :members: 11 | :show-inheritance: 12 | :special-members: 13 | :exclude-members: __weakref__ 14 | 15 | ================ 16 | LightColorSensor 17 | ================ 18 | 19 | .. autoclass:: di_sensors.light_color_sensor.LightColorSensor 20 | :members: 21 | :show-inheritance: 22 | :special-members: 23 | :exclude-members: __weakref__ 24 | 25 | ======================= 26 | InertialMeasurementUnit 27 | ======================= 28 | 29 | .. autoclass:: di_sensors.inertial_measurement_unit.InertialMeasurementUnit 30 | :members: 31 | :show-inheritance: 32 | :special-members: 33 | :exclude-members: __weakref__ 34 | 35 | .. automethod:: di_sensors.BNO055.BNO055.get_calibration_status 36 | 37 | ============ 38 | TempHumPress 39 | ============ 40 | 41 | .. autoclass:: di_sensors.temp_hum_press.TempHumPress 42 | :members: 43 | :show-inheritance: 44 | :special-members: 45 | :exclude-members: __weakref__ 46 | 47 | ============ 48 | LineFollower 49 | ============ 50 | 51 | .. autoclass:: di_sensors.line_follower.LineFollower 52 | :members: 53 | :show-inheritance: 54 | :special-members: 55 | :exclude-members: __weakref__ 56 | 57 | .. autoclass:: di_sensors.line_follower.LineFollowerRed 58 | :members: 59 | :show-inheritance: 60 | :special-members: 61 | :exclude-members: __weakref__ 62 | 63 | ======== 64 | More ... 65 | ======== 66 | 67 | If you wish to have a more granular control over the sensors' functionalities, then you should check the following submodules of the ``DI-Sensors`` package: 68 | 69 | * `di_sensors.BME280 `_ - submodule for interfacing with the `Temperature Humidity Pressure Sensor`_. 70 | * `di_sensors.BNO055 `_ - submodule for interfacing with the `InertialMeasurementUnit Sensor`_. 71 | * `di_sensors.TCS34725 `_ - submodule for interfacing with the `Light Color Sensor`_. 72 | * `di_sensors.VL53L0X `_ - submodule for interfacing with the `Distance Sensor`_. 73 | 74 | All these submodules that are being referenced in this section were used for creating the :py:class:`~di_sensors.distance_sensor.DistanceSensor`, 75 | :py:class:`~di_sensors.light_color_sensor.LightColorSensor`, :py:class:`~di_sensors.temp_hum_press.TempHumPress` and the :py:class:`~di_sensors.inertial_measurement_unit.InertialMeasurementUnit` classes. 76 | 77 | 78 | .. _distance sensor: https://www.dexterindustries.com/shop/distance-sensor/ 79 | .. _light color sensor: https://www.dexterindustries.com/shop/light-color-sensor/ 80 | .. _temperature humidity pressure sensor: https://www.dexterindustries.com/shop/temperature-humidity-pressure-sensor/ 81 | .. _inertialmeasurementunit sensor: https://www.dexterindustries.com/shop/imu-sensor/ 82 | .. _line follower sensor (black board): https://www.dexterindustries.com/shop/line-follower-sensor/ 83 | .. _line follower sensor (red board): https://www.dexterindustries.com/product/line-follower-for-gopigo/ 84 | .. _github repo: https://github.com/DexterInd/DI_Sensors 85 | -------------------------------------------------------------------------------- /docs/source/api-basic.rst: -------------------------------------------------------------------------------- 1 | .. _api-chapter: 2 | 3 | ########################################### 4 | API DI-Sensors - Basic 5 | ########################################### 6 | 7 | ================== 8 | EasyDistanceSensor 9 | ================== 10 | 11 | .. autoclass:: di_sensors.easy_distance_sensor.EasyDistanceSensor 12 | :members: 13 | :show-inheritance: 14 | :special-members: 15 | :exclude-members: __weakref__ 16 | 17 | ==================== 18 | EasyLightColorSensor 19 | ==================== 20 | 21 | .. autoclass:: di_sensors.easy_light_color_sensor.EasyLightColorSensor 22 | :members: 23 | :show-inheritance: 24 | :special-members: 25 | :exclude-members: __weakref__ 26 | 27 | ============= 28 | EasyIMUSensor 29 | ============= 30 | 31 | .. autoclass:: di_sensors.easy_inertial_measurement_unit.EasyIMUSensor 32 | :members: 33 | :show-inheritance: 34 | :special-members: 35 | :exclude-members: __weakref__ 36 | 37 | ============== 38 | EasyTHPSsensor 39 | ============== 40 | 41 | .. autoclass:: di_sensors.easy_temp_hum_press.EasyTHPSensor 42 | :members: 43 | :show-inheritance: 44 | :special-members: 45 | :exclude-members: __weakref__ 46 | 47 | ================ 48 | EasyLineFollower 49 | ================ 50 | 51 | .. autoclass:: di_sensors.easy_line_follower.EasyLineFollower 52 | :members: 53 | :show-inheritance: 54 | :special-members: 55 | :exclude-members: __weakref__ 56 | 57 | .. warning:: 58 | 59 | The Line Follower class was originally held in :py:mod:`easysensors` module of the GoPiGo3 library, but has been moved here. 60 | The :py:meth:`easygopigo3.EasyGoPiGo3.init_line_follower` method now returns an object of the 61 | :py:class:`~di_sensors.easy_line_follower.EasyLineFollower` class instead of instantiating the original Line Follower class from 62 | :py:mod:`easysensors` module. 63 | 64 | In order to prevent breaking others' code, we kept the support for the older methods that are soon-to-be-deprecated in :py:class:`~di_sensors.easy_line_follower.EasyLineFollower` class. 65 | The mapping between the old methods and the new ones is as follows: 66 | 67 | 1. :py:meth:`~di_sensors.easy_line_follower.EasyLineFollower.read_raw_sensors` <=> :py:meth:`~di_sensors.easy_line_follower.EasyLineFollower.read` 68 | 2. :py:meth:`~di_sensors.easy_line_follower.EasyLineFollower.read_binary` <=> :py:meth:`~di_sensors.easy_line_follower.EasyLineFollower.position_01` 69 | 3. :py:meth:`~di_sensors.easy_line_follower.EasyLineFollower.read_position` <=> :py:meth:`~di_sensors.easy_line_follower.EasyLineFollower.position` 70 | 4. :py:meth:`~di_sensors.easy_line_follower.EasyLineFollower.read_position_str` <=> :py:meth:`~di_sensors.easy_line_follower.EasyLineFollower.position_bw` 71 | 5. :py:meth:`~di_sensors.easy_line_follower.EasyLineFollower.get_white_calibration` <=> :py:meth:`~di_sensors.easy_line_follower.EasyLineFollower.set_calibration` ``("white")`` 72 | 6. :py:meth:`~di_sensors.easy_line_follower.EasyLineFollower.get_black_calibration` <=> :py:meth:`~di_sensors.easy_line_follower.EasyLineFollower.set_calibration` ``("black")`` 73 | 74 | .. _distance sensor: https://www.dexterindustries.com/shop/distance-sensor/ 75 | .. _light color sensor: https://www.dexterindustries.com/shop/light-color-sensor/ 76 | .. _temperature humidity pressure sensor: https://www.dexterindustries.com/shop/temperature-humidity-pressure-sensor/ 77 | .. _inertialmeasurementunit sensor: https://www.dexterindustries.com/shop/imu-sensor/ 78 | .. _github repo: https://github.com/DexterInd/DI_Sensors 79 | .. _gopigo3: https://www.dexterindustries.com/shop/gopigo3-robot-base-kit/ 80 | -------------------------------------------------------------------------------- /docs/source/devguide.rst: -------------------------------------------------------------------------------- 1 | .. _devguide-chapter: 2 | 3 | ################# 4 | Developer's Guide 5 | ################# 6 | 7 | ***************** 8 | Our collaborators 9 | ***************** 10 | 11 | The following collaborators are ordered alphabetically: 12 | 13 | * John Cole - `Github Account `__. 14 | * Karan Nayan - `Github Account `__. 15 | * Matt Richardson - `Github Account `__. 16 | * Nicole Parrot - `Github Account `__. 17 | * Robert Lucian Chiriac - `Github Account `__. 18 | * Shoban Narayan - `Github account `__. 19 | -------------------------------------------------------------------------------- /docs/source/examples/dist_sensor.rst: -------------------------------------------------------------------------------- 1 | .. _examples-distance-sensor: 2 | 3 | ######################### 4 | Using the Distance Sensor 5 | ######################### 6 | 7 | ************* 8 | Basic Example 9 | ************* 10 | 11 | Before going to the more advanced example program of using the `Distance Sensor`_, we're going to give an example of the easiest way to read from the sensor. 12 | 13 | The following code snippet reads values off of the `Distance Sensor`_ and prints them iteratively in the console. As you'll see, this is far easier than the 14 | following examples, which are more complex to use, but have a more granular control over the device. 15 | 16 | In this example program, connect the `Distance Sensor`_ to an I2C port on whichever platform (`GoPiGo3`_, `GrovePi`_ or `BrickPi3`_) 17 | and then run the following script. 18 | 19 | .. literalinclude:: ../../../Python/Examples/EasyDistanceSensor.py 20 | :language: python 21 | :lines: 14- 22 | 23 | The source file for this example program can be found `here on github `__ 24 | 25 | *************** 26 | Continuous-mode 27 | *************** 28 | 29 | Again, just like in the previous example program, connect the `Distance Sensor`_ to an I2C port on whichever platform before running the following script. 30 | 31 | The advantage of this script over the ones in the following and previous sections is that the time taken for reading the distance 32 | can be fine-tuned by the user - for instance, it can be made to run as fast as possible (to see how fast it can read see the API of :py:class:`~di_sensors.distance_sensor.DistanceSensor`) or it can be made to go very slow. 33 | Each fine-tune has its benefits and disadvantages, so the user has to experiment with the sensor and determine what setting suits him best. 34 | 35 | .. literalinclude:: ../../../Python/Examples/DistanceSensorContinuous.py 36 | :language: python 37 | :lines: 14- 38 | 39 | The source code for this example program can be found `here on github `__. 40 | 41 | *********** 42 | Single-mode 43 | *********** 44 | 45 | In this third example, we have the same physical arrangement as in the second one, the only difference being in how we communicate with the sensor. 46 | This time, we take single-shot readings, which for the user is simpler than having to tune the distance sensor first and then read off of it. The only disadvantage is that 47 | there's no fine-control over how fast the sensor is making the readings. 48 | 49 | .. literalinclude:: ../../../Python/Examples/DistanceSensorSingleShot.py 50 | :language: python 51 | :lines: 14- 52 | 53 | The source code for this example program can be found `here on github `__. 54 | 55 | ************** 56 | Console Output 57 | ************** 58 | 59 | All 3 example scripts described in this chapter should have a console output similar to what we have next. 60 | 61 | .. code-block:: bash 62 | 63 | distance from object: 419 mm 64 | distance from object: 454 mm 65 | distance from object: 452 mm 66 | distance from object: 490 mm 67 | distance from object: 501 mm 68 | distance from object: 8190 mm 69 | distance from object: 1650 mm 70 | distance from object: 1678 mm 71 | distance from object: 1638 mm 72 | distance from object: 1600 mm 73 | 74 | .. _distance sensor: https://www.dexterindustries.com/shop/distance-sensor/ 75 | .. _gopigo3: https://www.dexterindustries.com/gopigo3/ 76 | .. _grovepi: https://www.dexterindustries.com/grovepi/ 77 | .. _brickpi3: https://www.dexterindustries.com/brickpi/ 78 | -------------------------------------------------------------------------------- /docs/source/examples/imu.rst: -------------------------------------------------------------------------------- 1 | .. _examples-imu-sensor: 2 | 3 | #################### 4 | Using the IMU Sensor 5 | #################### 6 | 7 | In order to run this example program, we need to have a `GoPiGo3`_ because bus ``"GPG3_AD1"`` is used in this case and it's specific to the `GoPiGo3`_ platform. 8 | The ``"GPG3_AD1"`` bus translates to port ``"AD1"`` on the GoPiGo3, so the `IMU Sensor`_ has to be connected to port ``"AD1"``. 9 | 10 | We could have gone with the default ``"RPI_1SW"`` bus so it can be used on any platform, but since this is an example, we might as-well show how it's being done with a `GoPiGo3`_. 11 | 12 | The source file for this example program can be found `here on github `__. 13 | 14 | .. literalinclude:: ../../../Python/Examples/IMUSensor.py 15 | :language: python 16 | :lines: 14- 17 | 18 | The console output of this script should look like: 19 | 20 | .. code-block:: bash 21 | 22 | Example program for reading a Dexter Industries IMU Sensor on a GoPiGo3 AD1 port. 23 | Magnetometer X: 0.0 Y: 0.0 Z: 0.0 Gyroscope X: 54.9 Y: -25.4 Z: 8.8 Accelerometer X: 9.8 Y: 9.5 Z: -3.5 Euler Heading: 0.0 Roll: 0.0 Pitch: 0.0 Temperature: 31.0C 24 | Magnetometer X: -44.2 Y: 12.2 Z: 15.8 Gyroscope X: -38.6 Y: 12.4 Z: -116.7 Accelerometer X: -1.2 Y: 4.0 Z: -7.4 Euler Heading: 354.7 Roll: 6.3 Pitch: 13.6 Temperature: 31.0C 25 | Magnetometer X: -44.6 Y: 15.2 Z: 18.6 Gyroscope X: -11.7 Y: 5.0 Z: 18.5 Accelerometer X: 6.5 Y: 7.0 Z: -1.4 Euler Heading: 354.2 Roll: 6.2 Pitch: 12.6 Temperature: 31.0C 26 | Magnetometer X: -47.9 Y: 14.5 Z: 17.8 Gyroscope X: 17.1 Y: -23.1 Z: 43.0 Accelerometer X: 6.6 Y: 7.1 Z: -2.2 Euler Heading: 350.6 Roll: 8.3 Pitch: 13.2 Temperature: 31.0C 27 | Magnetometer X: -30.5 Y: 11.0 Z: 13.0 Gyroscope X: -8.6 Y: -2.1 Z: -0.1 Accelerometer X: 6.2 Y: 5.7 Z: -3.5 Euler Heading: 2.7 Roll: 8.8 Pitch: 12.6 Temperature: 31.0C 28 | Magnetometer X: -33.2 Y: 10.4 Z: 15.2 Gyroscope X: -87.0 Y: -29.6 Z: 141.0 Accelerometer X: 9.1 Y: 4.8 Z: -1.9 Euler Heading: 332.2 Roll: 15.8 Pitch: 2.1 Temperature: 31.0C 29 | 30 | 31 | .. _imu sensor: https://www.dexterindustries.com/shop/imu-sensor/ 32 | .. _gopigo3: https://www.dexterindustries.com/gopigo3/ 33 | .. _grovepi: https://www.dexterindustries.com/grovepi/ 34 | .. _brickpi3: https://www.dexterindustries.com/brickpi/ 35 | -------------------------------------------------------------------------------- /docs/source/examples/index.rst: -------------------------------------------------------------------------------- 1 | .. _examples-chapter: 2 | 3 | ######## 4 | Examples 5 | ######## 6 | 7 | This chapter revolves around the following python classes: 8 | 9 | * :py:class:`di_sensors.inertial_measurement_unit.InertialMeasurementUnit` 10 | * :py:class:`di_sensors.easy_light_color_sensor.EasyLightColorSensor` 11 | * :py:class:`di_sensors.easy_temp_hum_press.EasyTHPSensor` 12 | * :py:class:`di_sensors.distance_sensor.DistanceSensor` 13 | * :py:class:`di_sensors.easy_distance_sensor.EasyDistanceSensor` 14 | 15 | Please make sure you have followed all the instructions found in :ref:`Getting Started ` before jumping into these example programs. 16 | In all these examples, you will be required to use one of the 4 documented sensors and optionally, a `GoPiGo3`_. 17 | 18 | .. toctree:: 19 | :maxdepth: 1 20 | :caption: Contents: 21 | 22 | dist_sensor 23 | light_color 24 | temp_hum 25 | imu 26 | basic_lf 27 | mutexes 28 | 29 | .. _gopigo3: https://www.dexterindustries.com/shop/gopigo-advanced-starter-kit/ 30 | -------------------------------------------------------------------------------- /docs/source/examples/light_color.rst: -------------------------------------------------------------------------------- 1 | .. _examples-lightcolor-sensor: 2 | 3 | ################################ 4 | Using the Light and Color Sensor 5 | ################################ 6 | 7 | In this short section, we get to see how one can read data off of the `Light and Color Sensor`_ without having to fine-tune the sensor or to deal with hard-to-understand concepts. 8 | Before anything else, connect the `Light and Color Sensor`_ to an I2C port on whichever platform (be it a `GoPiGo3`_, `GrovePi`_ or a `BrickPi3`_) and then run the following script. 9 | 10 | The source file for this example program can be found `here on github `__. 11 | 12 | .. literalinclude:: ../../../Python/Examples/EasyLightColorSensor.py 13 | :language: python 14 | :lines: 14- 15 | 16 | Here's how the output of the script should look like: 17 | 18 | .. code-block:: bash 19 | 20 | Example program for reading a Dexter Industries Light Color Sensor on an I2C port. 21 | Red: 0.004 Green: 0.004 Blue: 0.004 Clear: 0.013 22 | Red: 0.005 Green: 0.004 Blue: 0.004 Clear: 0.013 23 | Red: 0.005 Green: 0.005 Blue: 0.004 Clear: 0.014 24 | Red: 0.005 Green: 0.005 Blue: 0.004 Clear: 0.015 25 | Red: 0.005 Green: 0.005 Blue: 0.004 Clear: 0.014 26 | Red: 0.005 Green: 0.005 Blue: 0.004 Clear: 0.014 27 | Red: 0.006 Green: 0.005 Blue: 0.005 Clear: 0.015 28 | 29 | .. _light and color sensor: https://www.dexterindustries.com/shop/light-color-sensor/ 30 | .. _gopigo3: https://www.dexterindustries.com/gopigo3/ 31 | .. _grovepi: https://www.dexterindustries.com/grovepi/ 32 | .. _brickpi3: https://www.dexterindustries.com/brickpi/ 33 | -------------------------------------------------------------------------------- /docs/source/examples/mutexes.rst: -------------------------------------------------------------------------------- 1 | ############# 2 | Using Mutexes 3 | ############# 4 | 5 | In this section, we are showing how handy mutexes are when we're trying to access the same resource (a device, for instance a `Distance Sensor`_) 6 | simultaneously from multiple threads. All :ref:`Easy classes ` are thread-safe - what one has to do is to activate the use of mutexes by passing a boolean 7 | parameter to each of the classes' constructor. 8 | 9 | In the following example program, 2 threads are accessing the resource of an :py:class:`~di_sensors.easy_distance_sensor.EasyDistanceSensor` object. 10 | ``use_mutex`` parameter is set to ``True`` so that the resource can be accessed from multiple threads/processes (this is what we would call a thread-safe class). 11 | Each of these 2 threads run for ``runtime`` seconds - we didn't make it so one can stop the program while it's running, because that would have been more complex. 12 | 13 | Without the mutex mechanism, accessing the same resource from multiple processes/threads would not be possible. 14 | 15 | .. literalinclude:: ../../../Python/Examples/EasyDistanceSensorMutexes.py 16 | :language: python 17 | :lines: 14- 18 | 19 | .. important:: 20 | 21 | There was no need to use mutexes in the above example, but for the sake of an example, it is a good thing. The idea is that CPython's implementation 22 | has what it's called a **GIL** (*Global Interpreter Lock*) and this only allows one thread to run at once, which is a skewed way of envisioning how threads work, 23 | but it's the reality in Python still. Ideally, a thread can run concurrently with another one. You can read more on the :term:`Global Interpreter Lock here`. 24 | 25 | Still, the implementation we have with mutexes proves to be useful when one wants to launch multiple processes at a time - at that moment, we can talk of true concurrency. 26 | This can happen when multiple instances of Python scripts are launched and when each process tries to access the same resource as the other one. 27 | 28 | The output on the console should look like this - the thread IDs don't mean anything and they are merely just a number used to identify threads. 29 | 30 | .. code-block:: bash 31 | 32 | Thread ID = 1883501680 with distance value = 44 33 | Thread ID = 1873802352 with distance value = 44 34 | Thread ID = 1873802352 with distance value = 44 35 | Thread ID = 1883501680 with distance value = 44 36 | Thread ID = 1873802352 with distance value = 46 37 | Thread ID = 1883501680 with distance value = 46 38 | Thread ID = 1873802352 with distance value = 45 39 | Thread ID = 1883501680 with distance value = 45 40 | Thread ID = 1883501680 with distance value = 44 41 | Thread ID = 1873802352 with distance value = 44 42 | Thread ID = 1883501680 with distance value = 45 43 | Thread ID = 1873802352 with distance value = 45 44 | 45 | .. _distance sensor: https://www.dexterindustries.com/shop/distance-sensor/ 46 | -------------------------------------------------------------------------------- /docs/source/examples/temp_hum.rst: -------------------------------------------------------------------------------- 1 | .. _examples-temphumpress-sensor: 2 | 3 | ######################################## 4 | Temperature Humidity and Pressure Sensor 5 | ######################################## 6 | 7 | In order to run this example program, connect the `Temperature Humidity and Pressure Sensor`_ to an I2C port on whichever platform (`GoPiGo3`_, `GrovePi`_ or `BrickPi3`_) 8 | and then run the following script. 9 | 10 | The source file for this example program can be found `here on github `__. 11 | 12 | .. literalinclude:: ../../../Python/Examples/EasyTempHumPress.py 13 | :language: python 14 | :lines: 14- 15 | 16 | The console output of this script should look like: 17 | 18 | .. code-block:: bash 19 | 20 | Example program for reading a Dexter Industries Temperature Humidity Pressure Sensor on an I2C port. 21 | Temperature: 28.139 Humidity: 48.687 Pressure: 101122.691 22 | Temperature: 28.141 Humidity: 48.698 Pressure: 101122.840 23 | Temperature: 28.145 Humidity: 48.385 Pressure: 101122.900 24 | Temperature: 28.151 Humidity: 48.715 Pressure: 101122.889 25 | Temperature: 28.157 Humidity: 48.436 Pressure: 101122.607 26 | Temperature: 28.163 Humidity: 48.464 Pressure: 101122.836 27 | Temperature: 28.171 Humidity: 48.674 Pressure: 101123.085 28 | Temperature: 28.180 Humidity: 48.120 Pressure: 101123.114 29 | 30 | .. _temperature humidity and pressure sensor: https://www.dexterindustries.com/shop/temperature-humidity-pressure-sensor/ 31 | .. _gopigo3: https://www.dexterindustries.com/gopigo3/ 32 | .. _grovepi: https://www.dexterindustries.com/grovepi/ 33 | .. _brickpi3: https://www.dexterindustries.com/brickpi/ 34 | -------------------------------------------------------------------------------- /docs/source/faq.rst: -------------------------------------------------------------------------------- 1 | .. _faq-chapter: 2 | 3 | ########################## 4 | Frequently Asked Questions 5 | ########################## 6 | 7 | For more questions, please head over to our Dexter Industries `forum`_. 8 | 9 | 10 | .. _forum: http://forum.dexterindustries.com/categories 11 | -------------------------------------------------------------------------------- /docs/source/images/dexterlogo_big.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DexterInd/DI_Sensors/9f8d8cc57e06eb9c154af712490c41b34624a943/docs/source/images/dexterlogo_big.jpg -------------------------------------------------------------------------------- /docs/source/images/dexterlogo_small.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DexterInd/DI_Sensors/9f8d8cc57e06eb9c154af712490c41b34624a943/docs/source/images/dexterlogo_small.jpg -------------------------------------------------------------------------------- /docs/source/images/quickstart1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DexterInd/DI_Sensors/9f8d8cc57e06eb9c154af712490c41b34624a943/docs/source/images/quickstart1.png -------------------------------------------------------------------------------- /docs/source/images/quickstart2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DexterInd/DI_Sensors/9f8d8cc57e06eb9c154af712490c41b34624a943/docs/source/images/quickstart2.jpg -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. DI-Sensors documentation master file, created by 2 | sphinx-quickstart on Thu Sep 28 21:00:03 2017. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | ########################################### 7 | Dexter Industries DI-Sensors Documentation! 8 | ########################################### 9 | 10 | .. image:: images/dexterlogo_small.jpg 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | :numbered: 15 | :caption: Contents: 16 | 17 | about 18 | quickstart 19 | examples/index 20 | structure 21 | api-basic 22 | api-advanced 23 | devguide 24 | faq 25 | 26 | Indices and tables 27 | ================== 28 | 29 | * :ref:`genindex` 30 | * :ref:`modindex` 31 | * :ref:`search` 32 | -------------------------------------------------------------------------------- /docs/source/quickstart.rst: -------------------------------------------------------------------------------- 1 | .. _getting-started-chapter: 2 | 3 | ############### 4 | Getting Started 5 | ############### 6 | 7 | ****************** 8 | Buying our sensors 9 | ****************** 10 | 11 | In order to run code found in this documentation, you need to head over to our online `shop`_ and get yourself one of the following sensors: 12 | 13 | * The DI `IMU Sensor`_. 14 | * The DI `Light and Color Sensor`_. 15 | * The DI `Temperature Humidity Pressure Sensor`_. 16 | * The DI `Distance Sensor`_. 17 | * The DI `Line Follower Sensor`_, aka the *black line follower*. 18 | 19 | .. image:: images/quickstart1.png 20 | 21 | Also, apart from these sensors, the red line follower is also supported. It is the predecessor to the `Line Follower Sensor`_. This is what it looks like: 22 | 23 | .. image:: images/quickstart2.jpg 24 | 25 | ******************************* 26 | What I can use the sensors with 27 | ******************************* 28 | 29 | All these sensors can be used along the following platforms: 30 | 31 | * The `BrickPi3`_. 32 | 33 | * Github project `here `__. 34 | 35 | * The `GoPiGo3`_. 36 | 37 | * Github project `here `__. 38 | * Documentation for the `GoPiGo3`_ can be found `here `_. 39 | 40 | * The GoPiGo. 41 | 42 | * Github project `here `__. 43 | * Predecessor of the `GoPiGo3`_. 44 | 45 | * The `GrovePi`_. 46 | 47 | * Github project `here `__. 48 | * Platform for collecting data from the environment through the use of sensors. 49 | 50 | * The `PivotPi`_. 51 | 52 | * Github project `here `__. 53 | * Board to connect to a bunch of servos. 54 | 55 | 56 | ***************************** 57 | How to install the DI-Sensors 58 | ***************************** 59 | 60 | In order to install the DI-Sensors package you need to open up a terminal on your Raspberry Pi and type in the following command: 61 | 62 | .. code-block:: bash 63 | 64 | curl -kL dexterindustries.com/update_sensors | bash 65 | 66 | Enter the command and follow the instructions given, if provided. 67 | This command can also be used for updating the package with the latest changes. 68 | 69 | To find more about our source code, please visit the `DI_Sensors repository`_ on GitHub. 70 | 71 | .. _shop: https://www.dexterindustries.com/shop/ 72 | .. _distance sensor: https://www.dexterindustries.com/shop/distance-sensor/ 73 | .. _imu sensor: https://www.dexterindustries.com/shop/imu-sensor/ 74 | .. _light and color sensor: https://www.dexterindustries.com/shop/light-color-sensor/ 75 | .. _temperature humidity pressure sensor: https://www.dexterindustries.com/shop/temperature-humidity-pressure-sensor/ 76 | .. _line follower sensor: https://www.dexterindustries.com/shop/line-follower-sensor/ 77 | .. _brickpi3: https://www.dexterindustries.com/shop/brickpi-starter-kit/ 78 | .. _gopigo3: https://www.dexterindustries.com/shop/gopigo3-robot-base-kit/ 79 | .. _grovepi: https://www.dexterindustries.com/shop/grovepi-starter-kit-raspberry-pi/ 80 | .. _di_sensors repository: https://github.com/DexterInd/DI_Sensors.git 81 | .. _pivotpi: https://www.dexterindustries.com/product/pivotpi-board/ 82 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: readthedocs 2 | dependencies: 3 | - python=3 4 | - pip 5 | - graphviz 6 | - mock 7 | - six 8 | - sphinx 9 | - sphinx_rtd_theme 10 | -------------------------------------------------------------------------------- /readthedocs.yml: -------------------------------------------------------------------------------- 1 | conda: 2 | file: environment.yml 3 | --------------------------------------------------------------------------------