Looking for GPIO python example or tutorial
Hi,
I am new to the forum.
I am using the python wrapper library for my project using MetaWear CPro.
I want to connect a push button using GPIO pins to monitor state of the push button and frequency of changes.
I am looking for some python examples using GPIO to experiment with.
I am reusing the switch.py example to modify for using GPIO.
I'd greatly appreciate any example code, pointer, guidance or docs to start with.
Regards,
raj
I am new to the forum.
I am using the python wrapper library for my project using MetaWear CPro.
I want to connect a push button using GPIO pins to monitor state of the push button and frequency of changes.
I am looking for some python examples using GPIO to experiment with.
I am reusing the switch.py example to modify for using GPIO.
I'd greatly appreciate any example code, pointer, guidance or docs to start with.
Regards,
raj
This discussion has been closed.
Comments
I'm new to git.
I downloaded and tried to install in parallel with old.pymetawear-0.7.2.
Installation succeeded.
When I try to run the example scripts in the new installation the scripts fail.
pi@S-SquareBase:~/Downloads/pymetawear_ss/examples $ ls
accelerometer.py battery.py magnetometer.py switch.py two_clients.py
ambientlight.py gyroscope.py sensorfusion.py temperature.py
barometer.py led.py settings.py tev.py
pi@S-SquareBase:~/Downloads/pymetawear_ss/examples $ ls /home/pi/Downloads/pymetawear_ss/pymetawear/MetaWear-SDK-Cpp/bindings/python/mbientlab/metawear
cbindings.py __pycache__
pi@S-SquareBase:~/Downloads/pymetawear_ss/examples $ python3 temperature.py
Traceback (most recent call last):
File "temperature.py", line 19, in <module>
from pymetawear.discover import select_device
ImportError: No module named 'pymetawear'
pi@S-SquareBase: ~/Downloads/pymetawear_ss/examples $
Below is find.out of ~/Downloads/pymetawer_ss:
I greatly appreciate your help with gpio and python3.
raj
----------------------------x-------------------------------------
pi@S-SquareBase:~/Downloads/pymetawear_ss $ find ./ -type d -name "*" -print
./
./examples
./pymetawear
./pymetawear/modules
./pymetawear/modules/__pycache__
./pymetawear/MetaWear-SDK-Cpp
./pymetawear/MetaWear-SDK-Cpp/cppdocs
./pymetawear/MetaWear-SDK-Cpp/cppdocs/source
./pymetawear/MetaWear-SDK-Cpp/cppdocs/source/_templates
./pymetawear/MetaWear-SDK-Cpp/dist
./pymetawear/MetaWear-SDK-Cpp/dist/release
./pymetawear/MetaWear-SDK-Cpp/dist/release/lib
./pymetawear/MetaWear-SDK-Cpp/dist/release/lib/arm
./pymetawear/MetaWear-SDK-Cpp/src
./pymetawear/MetaWear-SDK-Cpp/src/metawear
./pymetawear/MetaWear-SDK-Cpp/src/metawear/dfu
./pymetawear/MetaWear-SDK-Cpp/src/metawear/dfu/cpp
./pymetawear/MetaWear-SDK-Cpp/src/metawear/core
./pymetawear/MetaWear-SDK-Cpp/src/metawear/core/cpp
./pymetawear/MetaWear-SDK-Cpp/src/metawear/platform
./pymetawear/MetaWear-SDK-Cpp/src/metawear/platform/cpp
./pymetawear/MetaWear-SDK-Cpp/src/metawear/sensor
./pymetawear/MetaWear-SDK-Cpp/src/metawear/sensor/cpp
./pymetawear/MetaWear-SDK-Cpp/src/metawear/impl
./pymetawear/MetaWear-SDK-Cpp/src/metawear/impl/cpp
./pymetawear/MetaWear-SDK-Cpp/src/metawear/peripheral
./pymetawear/MetaWear-SDK-Cpp/src/metawear/peripheral/cpp
./pymetawear/MetaWear-SDK-Cpp/src/metawear/processor
./pymetawear/MetaWear-SDK-Cpp/src/metawear/processor/cpp
./pymetawear/MetaWear-SDK-Cpp/test
./pymetawear/MetaWear-SDK-Cpp/test/__pycache__
./pymetawear/MetaWear-SDK-Cpp/build
./pymetawear/MetaWear-SDK-Cpp/build/arm
./pymetawear/MetaWear-SDK-Cpp/build/arm/release
./pymetawear/MetaWear-SDK-Cpp/build/arm/release/src
./pymetawear/MetaWear-SDK-Cpp/build/arm/release/src/metawear
./pymetawear/MetaWear-SDK-Cpp/build/arm/release/src/metawear/dfu
./pymetawear/MetaWear-SDK-Cpp/build/arm/release/src/metawear/dfu/cpp
./pymetawear/MetaWear-SDK-Cpp/build/arm/release/src/metawear/core
./pymetawear/MetaWear-SDK-Cpp/build/arm/release/src/metawear/core/cpp
./pymetawear/MetaWear-SDK-Cpp/build/arm/release/src/metawear/platform
./pymetawear/MetaWear-SDK-Cpp/build/arm/release/src/metawear/platform/cpp
./pymetawear/MetaWear-SDK-Cpp/build/arm/release/src/metawear/sensor
./pymetawear/MetaWear-SDK-Cpp/build/arm/release/src/metawear/sensor/cpp
./pymetawear/MetaWear-SDK-Cpp/build/arm/release/src/metawear/impl
./pymetawear/MetaWear-SDK-Cpp/build/arm/release/src/metawear/impl/cpp
./pymetawear/MetaWear-SDK-Cpp/build/arm/release/src/metawear/peripheral
./pymetawear/MetaWear-SDK-Cpp/build/arm/release/src/metawear/peripheral/cpp
./pymetawear/MetaWear-SDK-Cpp/build/arm/release/src/metawear/processor
./pymetawear/MetaWear-SDK-Cpp/build/arm/release/src/metawear/processor/cpp
./pymetawear/MetaWear-SDK-Cpp/bindings
./pymetawear/MetaWear-SDK-Cpp/bindings/javascript
./pymetawear/MetaWear-SDK-Cpp/bindings/python
./pymetawear/MetaWear-SDK-Cpp/bindings/python/mbientlab
./pymetawear/MetaWear-SDK-Cpp/bindings/python/mbientlab/metawear
./pymetawear/MetaWear-SDK-Cpp/bindings/python/mbientlab/metawear/__pycache__
./pymetawear/backends
./pymetawear/backends/__pycache__
./pymetawear/__pycache__
./pymetawear/mbientlab
./pymetawear/mbientlab/metawear
./pymetawear/mbientlab/metawear/__pycache__
./pymetawear/mbientlab/__pycache__
./tests
./build
./build/lib
./build/lib/pymetawear
./build/lib/pymetawear/modules
./build/lib/pymetawear/backends
./build/lib/pymetawear/mbientlab
./build/lib/pymetawear/mbientlab/metawear
./build/lib/old-examples
./build/lib/old-examples/raw
./pymetawear.egg-info
pi@S-SquareBase:~/Downloads/pymetawear_ss $
Now I restarted as you suggested.
Downloaded and installed from https://github.com/mbientlab-projects/pymetawear/tree/develop. Downloaded master branch https://github.com/mbientlab/MetaWear-SDK-Cpp.
Copied moved MetaWear-SDK-Cpp-master to ~/Downloads/pymetawear-develop/pymetawear/MetaWear-SDK-Cpp
Then I built using python3 setup.py.
I still have the same problem:
pi@S-SquareBase:~/Downloads/pymetawear-develop/examples $ python3 switch.py
Traceback (most recent call last):
File "switch.py", line 18, in <module>
from pymetawear.discover import select_device
ImportError: No module named 'pymetawear'
pi@S-SquareBase:~/Downloads/pymetawear-develop/examples $
------------------------X--------------------
How do I attach the build log?
If I run python3 -m site
pi@S-SquareBase:~/Downloads/pymetawear-develop/examples $ python3 -m site
sys.path = [
'/home/pi/Downloads/pymetawear-develop/examples',
'/usr/local/lib/python3.4/dist-packages/pip-9.0.1-py3.4.egg',
'/usr/lib/python3.4',
'/usr/lib/python3.4/plat-arm-linux-gnueabihf',
'/usr/lib/python3.4/lib-dynload',
'/usr/local/lib/python3.4/dist-packages',
'/usr/lib/python3/dist-packages',
]
USER_BASE: '/home/pi/.local' (exists)
USER_SITE: '/home/pi/.local/lib/python3.4/site-packages' (doesn't exist)
ENABLE_USER_SITE: True
lrwxrwxrwx 1 pi pi 18 Sep 28 12:28 pymetawear -> pymetawear-develop
drwxr-xr-x 7 pi pi 4096 Sep 28 13:13 pymetawear-develop
Please see the yellow highlighted text.
pi@S-SquareBase:~/Downloads/pymetawear $ python3 setup.py build
running build
running build_py
rm -Rf build dist bindings/javascript/libmetawear-path.js
mkdir -p build/arm/release/src/metawear/platform/cpp
mkdir -p build/arm/release/src/metawear/core/cpp
mkdir -p build/arm/release/src/metawear/peripheral/cpp
mkdir -p build/arm/release/src/metawear/processor/cpp
mkdir -p build/arm/release/src/metawear/sensor/cpp
mkdir -p build/arm/release/src/metawear/impl/cpp
mkdir -p build/arm/release/src/metawear/dfu/cpp
mkdir -p dist/release/lib/arm
g++ -MMD -MP -MF "build/arm/release/src/metawear/platform/cpp/async_creator.d" -c -o build/arm/release/src/metawear/platform/cpp/async_creator.o -std=c++11 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Werror -Isrc -DMETAWEAR_DLL -DMETAWEAR_DLL_EXPORTS -O3 -marm src/metawear/platform/cpp/async_creator.cpp
g++ -MMD -MP -MF "build/arm/release/src/metawear/platform/cpp/task.d" -c -o build/arm/release/src/metawear/platform/cpp/task.o -std=c++11 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Werror -Isrc -DMETAWEAR_DLL -DMETAWEAR_DLL_EXPORTS -O3 -marm src/metawear/platform/cpp/task.cpp
....................................
reading manifest file 'pymetawear.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*' under directory 'pymetawear/Metawear-CppAPI'
no previously-included directories found matching 'pymetawear/Metawear-CppAPI/.git'
no previously-included directories found matching 'pymetawear/Metawear-CppAPI/build'
no previously-included directories found matching 'pymetawear/Metawear-CppAPI/dist'
warning: no files found matching '*.rst' under directory 'docs'
warning: no files found matching 'conf.py' under directory 'docs'
warning: no files found matching 'Makefile' under directory 'docs'
warning: no files found matching 'make.bat' under directory 'docs'
warning: no files found matching '*.jpg' under directory 'docs'
warning: no files found matching '*.png' under directory 'docs'
warning: no files found matching '*.gif' under directory 'docs'
no previously-included directories found matching 'docs/build'
warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.py[co]' found under directory '*'
writing manifest file 'pymetawear.egg-info/SOURCES.txt'
copying pymetawear/libmetawear.so.0.10.0 -> build/lib/pymetawear
copying pymetawear/libmetawear.so -> build/lib/pymetawear
copying pymetawear/libmetawear.so.0 -> build/lib/pymetawear
pi@S-SquareBase:~/Downloads/pymetawear $ sudo python3 setup.py install
running install
Checking .pth file support in /usr/local/lib/python3.4/dist-packages/
/usr/bin/python3 -E -c pass
TEST PASSED: /usr/local/lib/python3.4/dist-packages/ appears to support .pth files
.......
reading manifest template 'MANIFEST.in'
warning: no files found matching '*' under directory 'pymetawear/Metawear-CppAPI'
no previously-included directories found matching 'pymetawear/Metawear-CppAPI/.git'
no previously-included directories found matching 'pymetawear/Metawear-CppAPI/build'
no previously-included directories found matching 'pymetawear/Metawear-CppAPI/dist'
warning: no files found matching '*.rst' under directory 'docs'
warning: no files found matching 'conf.py' under directory 'docs'
warning: no files found matching 'Makefile' under directory 'docs'
warning: no files found matching 'make.bat' under directory 'docs'
warning: no files found matching '*.jpg' under directory 'docs'
warning: no files found matching '*.png' under directory 'docs'
warning: no files found matching '*.gif' under directory 'docs'
no previously-included directories found matching 'docs/build'
warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.py[co]' found under directory '*'
writing manifest file 'pymetawear.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-armv7l/egg
running install_lib
running build_py
rm -Rf build dist bindings/javascript/libmetawear-path.js
mkdir -p build/arm/release/src/metawear/platform/cpp
.....
mkdir -p build/arm/release/src/metawear/dfu/cpp
mkdir -p dist/release/lib/arm
g++ -MMD -MP -MF "build/arm/release/src/metawear/platform/cpp/async_creator.d" -c -o build/arm/release/src/metawear/platform/cpp/async_creator.o -std=c++11 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Werror -Isrc -DMETAWEAR_DLL -DMETAWEAR_DLL_EXPORTS -O3 -marm src/metawear/platform/cpp/async_creator.cpp
.................
ln -sf libmetawear.so.0.10.0 dist/release/lib/arm/libmetawear.so.0
ln -sf libmetawear.so.0 dist/release/lib/arm/libmetawear.so
copying pymetawear/mbientlab/__init__.py -> build/lib/pymetawear/mbientlab
copying pymetawear/mbientlab/metawear/cbindings.py -> build/lib/pymetawear/mbientlab/metawear
copying pymetawear/mbientlab/metawear/__init__.py -> build/lib/pymetawear/mbientlab/metawear
copying pymetawear/libmetawear.so.0.10.0 -> build/lib/pymetawear
copying build/lib/pymetawear/mbientlab/metawear/__init__.py -> build/bdist.linux-armv7l/egg/pymetawear/mbientlab/metawear
copying build/lib/pymetawear/mbientlab/__init__.py -> build/bdist.linux-armv7l/egg/pymetawear/mbientlab
byte-compiling build/bdist.linux-armv7l/egg/pymetawear/version.py to version.cpython-34.pyc
........
byte-compiling build/bdist.linux-armv7l/egg/pymetawear/backends/pybluez.py to pybluez.cpython-34.pyc
byte-compiling build/bdist.linux-armv7l/egg/pymetawear/specs.py to specs.cpython-34.pyc
byte-compiling build/bdist.linux-armv7l/egg/pymetawear/mbientlab/metawear/cbindings.py to cbindings.cpython-34.pyc
byte-compiling build/bdist.linux-armv7l/egg/pymetawear/mbientlab/metawear/__init__.py to __init__.cpython-34.pyc
byte-compiling build/bdist.linux-armv7l/egg/pymetawear/mbientlab/__init__.py to __init__.cpython-34.pyc
creating build/bdist.linux-armv7l/egg/EGG-INFO
copying pymetawear.egg-info/PKG-INFO -> build/bdist.linux-armv7l/egg/EGG-INFO
copying pymetawear.egg-info/SOURCES.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying pymetawear.egg-info/dependency_links.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying pymetawear.egg-info/requires.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying pymetawear.egg-info/top_level.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
writing build/bdist.linux-armv7l/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
pymetawear.__pycache__.__init__.cpython-34: module references __file__
creating dist
creating 'dist/pymetawear-0.8.0-py3.4.egg' and adding 'build/bdist.linux-armv7l/egg' to it
removing 'build/bdist.linux-armv7l/egg' (and everything under it)
Processing pymetawear-0.8.0-py3.4.egg
removing '/usr/local/lib/python3.4/dist-packages/pymetawear-0.8.0-py3.4.egg' (and everything under it)
creating /usr/local/lib/python3.4/dist-packages/pymetawear-0.8.0-py3.4.egg
Extracting pymetawear-0.8.0-py3.4.egg to /usr/local/lib/python3.4/dist-packages
pymetawear 0.8.0 is already the active version in easy-install.pth
Installed /usr/local/lib/python3.4/dist-packages/pymetawear-0.8.0-py3.4.egg
Processing dependencies for pymetawear==0.8.0
Searching for pexpect==4.2.1
Best match: pexpect 4.2.1
pexpect 4.2.1 is already the active version in easy-install.pth
Using /usr/local/lib/python3.4/dist-packages
Searching for pygatt==3.1.1
Best match: pygatt 3.1.1
pygatt 3.1.1 is already the active version in easy-install.pth
Using /usr/local/lib/python3.4/dist-packages
Searching for ptyprocess==0.5.1
Best match: ptyprocess 0.5.1
ptyprocess 0.5.1 is already the active version in easy-install.pth
Using /usr/local/lib/python3.4/dist-packages
Searching for enum34==1.1.6
Best match: enum34 1.1.6
enum34 1.1.6 is already the active version in easy-install.pth
Using /usr/local/lib/python3.4/dist-packages
Searching for pyserial==2.6
Best match: pyserial 2.6
pyserial 2.6 is already the active version in easy-install.pth
Using /usr/lib/python3/dist-packages
Finished processing dependencies for pymetawear==0.8.0
I extracted the MetaWear-SDK-Cpp-master.zip in the ~/Downloads/pymetawear/pymetawear and renamed it to MetaWear-SDK-Cpp. But the build still looks for pymetawear/Metawear-CppAPI'. I don't understand why.
pi@S-SquareBase:~/Downloads/pymetawear $ ls
AUTHORS.rst examples MANIFEST.in README.rst tests
build HISTORY.rst MetaWear-SDK-Cpp-master.zip requirements.txt
cleanup LICENSE pymetawear setup.cfg
dist Makefile pymetawear.egg-info setup.py
pi@S-SquareBase:~/Downloads/pymetawear $ ls ./pymetawear
backends discover.py libmetawear.so mbientlab specs.py
client.py exceptions.py libmetawear.so.0 MetaWear-SDK-Cpp version.py
compat.py __init__.py libmetawear.so.0.10.0 modules
pi@S-SquareBase:~/Downloads/pymetawear $ ls ./pymetawear/MetaWear-SDK-Cpp
bindings cppdocs LICENSE.md MetaWear.WinRT.vcxproj src
build dist Makefile project_version.mk test
config.mk Doxyfile MetaWear.Win32.vcxproj README.md
pi@S-SquareBase:~/Downloads/pymetawear $
I greatly appreciate your help.
Regards,
Raj
I replaced the Metawear-CppAPI with MetaWear-SDK-Cpp in the
~/Downloads/pymetawear/MANIFEST.in.
So it builds with the previously highlighted warnings.
But now I aim getting the following errors:
pi@S-SquareBase:~/Downloads/pymetawear/examples $ python3 led.py
Traceback (most recent call last):
File "led.py", line 19, in <module>
from pymetawear.client import MetaWearClient
File "/usr/local/lib/python3.4/dist-packages/pymetawear-0.8.0-py3.4.egg/pymetawear/client.py", line 22, in <module>
from pymetawear.backends.pybluez import PyBluezBackend
File "/usr/local/lib/python3.4/dist-packages/pymetawear-0.8.0-py3.4.egg/pymetawear/backends/__init__.py", line 22, in <module>
from pymetawear.mbientlab.metawear.cbindings import BtleConnection, \
ImportError: cannot import name 'FnVoid_VoidP_GattCharP'
pi@S-SquareBase:~/Downloads/pymetawear/examples $
The file exists at correct location:
pi@S-SquareBase:~/Downloads/pymetawear/examples $ ls ~/Downloads/pymetawear/pymetawear/mbientlab/metawear
cbindings.py __init__.py
Here's the grep outpu:t
pi@S-SquareBase:~/Downloads/pymetawear/examples $ grep FnVoid_VoidP_GattCharP ~/Downloads/pymetawear/pymetawear/mbientlab/metawear/*.py
/home/pi/Downloads/pymetawear/pymetawear/mbientlab/metawear/cbindings.py:FnVoid_VoidP_GattCharP_FnIntVoidPtrArray = CFUNCTYPE(None, c_void_p, POINTER(GattChar), FnInt_VoidP_UByteP_UByte)
/home/pi/Downloads/pymetawear/pymetawear/mbientlab/metawear/cbindings.py:FnVoid_VoidP_GattCharP_FnIntVoidPtrArray_FnVoidVoidPtrInt = CFUNCTYPE(None, c_void_p, POINTER(GattChar), FnInt_VoidP_UByteP_UByte, FnVoid_VoidP_Int)
/home/pi/Downloads/pymetawear/pymetawear/mbientlab/metawear/cbindings.py: ("read_gatt_char" , FnVoid_VoidP_GattCharP_FnIntVoidPtrArray),
/home/pi/Downloads/pymetawear/pymetawear/mbientlab/metawear/cbindings.py: ("enable_notifications" , FnVoid_VoidP_GattCharP_FnIntVoidPtrArray_FnVoidVoidPtrInt),
pi@S-SquareBase:~/Downloads/pymetawear/examples $
Thanks for your continued support.
I'll start over. I'm not Git expert.
I'm logged in to my git account and in
https://github.com/mbientlab-projects/pymetawear/tree/develop.
I SSH'ed to RPI3 and I tried:
pi@S-SquareBase:~/newpymetawear $ git clone git@github.com:mbientlab-projects/pymetawear.git ./pymetawear
Cloning into './pymetawear'...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
pi@S-SquareBase:~/newpymetawear $
Got back from trip and now coding.
I got past through the installation using git using ssh and now to the main objective.
To monitor the GPIO pin 3 (pulling it high and grounding to pin 5), I modified the example python script according to documentation in https://mbientlab.com/cppdocs/latest/gpio.html#input-monitoring
When I ground the pin 3, I don't see and state change.
Here is the script debug out put.
Thank you for your help.
Raj
------------X------------------
pi@S-SquareBase:~/pymetawear/examples $ python3 GpioPin3.py
Found only one device: MetaWear: CA:0A:65:86:22:1B.
2017-10-07 05:09:47,275 DEBUG Added a <stdout> logging handler to logger: pymetawear
2017-10-07 05:09:47,276 INFO Creating MetaWearClient for CA:0A:65:86:22:1B...
2017-10-07 05:09:47,276 INFO PyGattBackend: Creating new GATTToolBackend and starting GATTtool process...
2017-10-07 05:09:47,277 INFO Backend starter with pygatt for device address CA:0A:65:86:22:1B with timeout 30...
2017-10-07 05:09:47,357 INFO PyGattBackend: Connecting to CA:0A:65:86:22:1B using GATTTool...
2017-10-07 05:09:51,070 DEBUG Subscribe 0x001f:
2017-10-07 05:09:51,370 DEBUG Write 0x001d: 01 80
2017-10-07 05:09:51,422 DEBUG Read 0x0014: 32
2017-10-07 05:09:51,423 DEBUG Read 0x001a: 31 2e 32 2e 35
2017-10-07 05:09:51,424 DEBUG Waiting for MetaWear board to be fully initialized...
2017-10-07 05:09:51,503 DEBUG Notify 0x001f: 01 80 00 00
2017-10-07 05:09:51,504 DEBUG Write 0x001d: 02 80
2017-10-07 05:09:51,638 DEBUG Notify 0x001f: 02 80 00 01 03 00
2017-10-07 05:09:51,639 DEBUG Write 0x001d: 03 80
2017-10-07 05:09:51,772 DEBUG Notify 0x001f: 03 80 01 01
2017-10-07 05:09:51,774 DEBUG Write 0x001d: 04 80
2017-10-07 05:09:51,908 DEBUG Notify 0x001f: 04 80 01 00 00 03 01 02
2017-10-07 05:09:51,909 DEBUG Write 0x001d: 05 80
2017-10-07 05:09:52,043 DEBUG Notify 0x001f: 05 80 00 02 03 03 03 03 01
2017-10-07 05:09:52,045 DEBUG Write 0x001d: 06 80
2017-10-07 05:09:52,177 DEBUG Notify 0x001f: 06 80 00 00
2017-10-07 05:09:52,178 DEBUG Write 0x001d: 07 80
2017-10-07 05:09:52,312 DEBUG Notify 0x001f: 07 80 00 00
2017-10-07 05:09:52,314 DEBUG Write 0x001d: 08 80
2017-10-07 05:09:52,447 DEBUG Notify 0x001f: 08 80 00 00
2017-10-07 05:09:52,448 DEBUG Write 0x001d: 09 80
2017-10-07 05:09:52,582 DEBUG Notify 0x001f: 09 80 00 00 1c
2017-10-07 05:09:52,584 DEBUG Write 0x001d: 0a 80
2017-10-07 05:09:52,717 DEBUG Notify 0x001f: 0a 80 00 00 1c
2017-10-07 05:09:52,719 DEBUG Write 0x001d: 0b 80
2017-10-07 05:09:52,853 DEBUG Notify 0x001f: 0b 80 00 02 08 80 29 00 00
2017-10-07 05:09:52,854 DEBUG Write 0x001d: 0c 80
2017-10-07 05:09:52,987 DEBUG Notify 0x001f: 0c 80 00 00 08
2017-10-07 05:09:52,989 DEBUG Write 0x001d: 0d 80
2017-10-07 05:09:53,122 DEBUG Notify 0x001f: 0d 80 00 01
2017-10-07 05:09:53,124 DEBUG Write 0x001d: 0f 80
2017-10-07 05:09:53,257 DEBUG Notify 0x001f: 0f 80 00 01 08
2017-10-07 05:09:53,259 DEBUG Write 0x001d: 10 80
2017-10-07 05:09:53,393 DEBUG Notify 0x001f: 10 80
2017-10-07 05:09:53,394 DEBUG Write 0x001d: 11 80
2017-10-07 05:09:53,527 DEBUG Notify 0x001f: 11 80 00 04
2017-10-07 05:09:53,529 DEBUG Write 0x001d: 12 80
2017-10-07 05:09:53,662 DEBUG Notify 0x001f: 12 80 00 00
2017-10-07 05:09:53,664 DEBUG Write 0x001d: 13 80
2017-10-07 05:09:53,798 DEBUG Notify 0x001f: 13 80 00 01
2017-10-07 05:09:53,799 DEBUG Write 0x001d: 14 80
2017-10-07 05:09:53,932 DEBUG Notify 0x001f: 14 80 00 00
2017-10-07 05:09:53,934 DEBUG Write 0x001d: 15 80
2017-10-07 05:09:54,067 DEBUG Notify 0x001f: 15 80 00 01
2017-10-07 05:09:54,069 DEBUG Write 0x001d: 16 80
2017-10-07 05:09:54,203 DEBUG Notify 0x001f: 16 80
2017-10-07 05:09:54,204 DEBUG Write 0x001d: 17 80
2017-10-07 05:09:54,337 DEBUG Notify 0x001f: 17 80
2017-10-07 05:09:54,339 DEBUG Write 0x001d: 18 80
2017-10-07 05:09:54,473 DEBUG Notify 0x001f: 18 80
2017-10-07 05:09:54,474 DEBUG Write 0x001d: 19 80
2017-10-07 05:09:54,607 DEBUG Notify 0x001f: 19 80
2017-10-07 05:09:54,609 DEBUG Write 0x001d: fe 80
2017-10-07 05:09:54,742 DEBUG Notify 0x001f: fe 80 00 01
2017-10-07 05:09:54,744 DEBUG Write 0x001d: 0b 84
2017-10-07 05:09:54,878 DEBUG Notify 0x001f: 0b 84 12 a1 01 00 07
2017-10-07 05:09:54,879 DEBUG PyGattBackend, CA:0A:65:86:22:1B initialized with status 0.
New client created: MetaWearClient, PyGattBackend, CA:0A:65:86:22:1B, Model: 2, Firmware: 1.2.5
2017-10-07 05:09:55,235 DEBUG Write 0x001d: 02 03 00 02 1f 00 00 00 32 00 00 00 f4 01 00 00 02
2017-10-07 05:09:55,288 DEBUG Subscribing to Switch changes. (Sig#: 1959809648)
2017-10-07 05:09:55,289 DEBUG Calling mbl_mw_datasignal_subscribe(1959809648, <CFunctionType object at 0x76313960>)
2017-10-07 05:09:55,293 DEBUG Write 0x001d: 01 01 01
Pin change type: 3 pull mode: 0 analog read mode: 0
{'Analog read mode': ['abs_ref', 'adc'], 'Pin change type': ['any', 'falling', 'rising'], 'Pull mode': ['down', 'none', 'up']}
c.gpio.set_settings(3, None, GpioPullMode.UP, GpioPinChangeType.FALLING )
Pin change type: 3 pull mode: 2 analog read mode: 0
Gpio
Subscribe to 3 Gpio notifications...
Calling super(GpioModule, self).notifications(sensor_data(callback))
Get pin3 data_signal: mbl_mw_gpio_get_pin_monitor_data_signal
2017-10-07 05:09:55,451 DEBUG Subscribing to Gpio changes. (Sig#: 11625048)
2017-10-07 05:09:55,453 DEBUG Calling mbl_mw_datasignal_subscribe(11625048, <CFunctionType object at 0x763138f0>)
2017-10-07 05:09:55,454 DEBUG Write 0x001d: 05 0a 01
self.set_pin_change(pin, GpioPinChangeType.FALLING)
2017-10-07 05:09:55,509 DEBUG Write 0x001d: 05 09 03 02
Switched pin 3 to active mode: mbl_mw_gpio_start_pin_monitoring
2017-10-07 05:09:55,565 DEBUG Write 0x001d: 05 0b 03 01
Set Notification for Pin 3 Changes
2017-10-07 05:09:55,623 DEBUG Write 0x001d: 02 01 01
^CTraceback (most recent call last):
File "GpioPin3.py", line 90, in <module>
time.sleep(60.0)
KeyboardInterrupt
pi@S-SquareBase:~/pymetawear/examples $
I have not connected any external sensor. Basically, I have wired pin 3 and pin 5 and want to detect switch open and switch close. I have not tested with any device. I am using RPI3 running Jessie.
I'm following: https://mbientlab.com/cppdocs/latest/gpio.html#input-monitoring.
Probably, the solution is simpler than what I'm doing to create an external switch.
Here is the modified "Try" block (from temperature.py example):
-------------X--------------
from pymetawear.modules.gpio import GpioModule
from pymetawear.mbientlab.metawear.cbindings import *
try:
address = select_device()
if (str(address) == str(ADDRESS_STRING)):
#{
c = MetaWearClient(address, 'pygatt', timeout=TIMEOUT, connect=False, debug=True)
print("New client created: {0}".format(c))
c.connect()
#print("Write Gpio settings...")
#print("Channels: {0} ".format(c.gpio.channels))
pattern = c.led.load_preset_pattern('blink', repeat_count=2)
c.led.write_pattern(pattern, 'g')
# Create subscription
c.switch.notifications(switch_callback)
print(c.gpio.get_current_settings())
print(c.gpio.get_possible_settings())
c.gpio.set_settings(3, None, GpioPullMode.UP, GpioPinChangeType.FALLING )
print("c.gpio.set_settings(3, None, GpioPullMode.UP, GpioPinChangeType.FALLING )")
print(c.gpio.get_current_settings())
print(c.gpio.module_name)
while(True):
time.sleep(0.1)
print("\n")
print("Subscribe to {0} Gpio notifications...".format(3))
c.gpio.notifications(gpio_callback)
c.led.play()
time.sleep(60.0)
#print("Trigger {0} gpio notification...".format(3))
#c.gpio.read_gpio(3)
#c.led.play()
#time.sleep(1.0)
print("Unsubscribe to gpio notifications...")
c.gpio.notifications(None)
c.led.play()
time.sleep(1.0)
Thanks for the clarification.
From https://mbientlab.com/docs/MetaWearCPSv0.5.pdf diagram on page 6, I am using physical pin number 3 in the APIs.
To avoid further confusion, I created GpioPin class in gpio.py. Then i am using GpioPin.PIN3_DIO1 when passing pin number argument to the GpioModule method calls:
class GpioPin:
#PIN1_HCD = 0
PIN2_DIO0 = 0
PIN3_DIO1 = 1
PIN4_DIO2 = 2
#PIN5_VGND = 1
#PIN6_V3V = 1
PIN7_DIO3 = 3
PIN8_DIO4 = 4
#PIN9_SDA = 1
#PIN10_SCL = 1
I still don't see state change notification when I ground the PIN3_DIO1.
Pin change type: 1 pull mode: 0 analog read mode: 0
{'Pull mode': ['down', 'none', 'up'], 'Analog read mode': ['abs_ref', 'adc'], 'Pin change type': ['any', 'falling', 'rising']}
c.gpio.set_settings(GpioPin.PIN3_DIO1, None, GpioPullMode.UP, GpioPinChangeType.FALLING )
Pin change type: 1 pull mode: 2 analog read mode: 0
Gpio
Subscribe to 3 Gpio notifications...
Calling super(GpioModule, self).notifications(sensor_data(callback))
Get GpioPin.PIN3_DIO1 data_signal: mbl_mw_gpio_get_pin_monitor_data_signal
2017-10-09 21:02:08,966 DEBUG Subscribing to Gpio changes. (Sig#: 26648768)
2017-10-09 21:02:08,967 DEBUG Calling mbl_mw_datasignal_subscribe(26648768, <CFunctionType object at 0x7630e9d0>)
2017-10-09 21:02:08,968 DEBUG Write 0x001d: 05 0a 01
self.set_pin_change(pin, GpioPinChangeType.FALLING)
2017-10-09 21:02:09,020 DEBUG Write 0x001d: 05 09 01 02
Switched pin GpioPin.PIN3_DIO1 to active mode: mbl_mw_gpio_start_pin_monitoring
2017-10-09 21:02:09,072 DEBUG Write 0x001d: 05 0b 01 01
Set Notification for Pin GpioPin.PIN3_DIO1 Changes
2017-10-09 21:02:09,124 DEBUG Write 0x001d: 02 01 01
Unsubscribe to gpio notifications...
Switched pin GpioPin.PIN3_DIO1 to standby mode: mbl_mw_gpio_stop_pin_monitoring
2017-10-09 21:03:09,237 DEBUG Write 0x001d: 05 0b 01 00
Get GpioPin.PIN3_DIO1 data_signal: mbl_mw_gpio_get_pin_monitor_data_signal
2017-10-09 21:03:09,289 DEBUG Unsubscribing to Gpio changes. (Sig#: 26648768)
Removed Notification for Pin GpioPin.PIN3_DIO1 Changes
2017-10-09 21:03:09,295 DEBUG Write 0x001d: 02 01 01
I would like to get notifications when the physical pin 3 voltage/state changes. I thought if I ground the pin pin3 state would change.
I prefer not to poll it. How do I configure it?
I greatly appreciate your help.
-raj
Here is the code change:
/usr/local/lib/python3.4/dist-packages/pymetawear-0.8.0-py3.4.egg/pymetawear/modules/gpio.py
def get_analog_stream(self, pin=None):
abs_ref_signal = libmetawear.mbl_mw_gpio_get_analog_input_data_signal(self.board, pin, GpioAnalogReadMode.ADC);
return abs_ref_signal
GpioPin3.py
.........
........
c.gpio.notifications(gpio_callback)
while(True):
c.led.play()
data = c.gpio.get_analog_stream(GpioPin.PIN3_DIO1)
print("Pin Value: {0}".format(data))
time.sleep(2.0)
............
Here is the debug output printing abs_ref_signal from libmetawear.mbl_mw_gpio_get_analog_input_data_signal() while I (un-)ground the pin.
Pin change type: 1 pull mode: 0 analog read mode: 0
{'Analog read mode': ['abs_ref', 'adc'], 'Pin change type': ['any', 'falling', 'rising'], 'Pull mode': ['down', 'none', 'up']}
2017-10-11 15:15:46,651 DEBUG Setting the Analog Read Mode to 1
c.gpio.set_settings(GpioPin.PIN3_DIO1, GpioAnalogReadMode.ADC, GpioPullMode.UP, GpioPinChangeType.FALLING )
Pin change type: 1 pull mode: 2 analog read mode: 0
Gpio
Subscribe to 3 Gpio notifications...
Calling super(GpioModule, self).notifications(sensor_data(callback))
Get self.current_pin data_signal: mbl_mw_gpio_get_ANALOG_INPUT_DATA_SIGNAL
2017-10-11 15:15:46,754 DEBUG Subscribing to Gpio changes. (Sig#: 37871896)
2017-10-11 15:15:46,755 DEBUG Calling mbl_mw_datasignal_subscribe(37871896, <CFunctionType object at 0x76301880>)
self.set_pin_change(pin, GpioPinChangeType.FALLING)
2017-10-11 15:15:46,756 DEBUG Write 0x001d: 05 09 01 02
Switched pin self.current_pin to active mode: mbl_mw_gpio_start_pin_monitoring
2017-10-11 15:15:46,807 DEBUG Write 0x001d: 05 0b 01 01
Set Notification for Pin self.current_pin Changes
2017-10-11 15:15:46,860 DEBUG Write 0x001d: 02 01 01
Pin Value: 37871896
2017-10-11 15:15:48,914 DEBUG Write 0x001d: 02 01 01
Pin Value: 37871896
2017-10-11 15:15:50,968 DEBUG Write 0x001d: 02 01 01
Pin Value: 37871896
2017-10-11 15:15:53,022 DEBUG Write 0x001d: 02 01 01
Pin Value: 37871896
2017-10-11 15:15:55,077 DEBUG Write 0x001d: 02 01 01
Pin Value: 37871896
2017-10-11 15:15:57,131 DEBUG Write 0x001d: 02 01 01
Pin Value: 37871896
2017-10-11 15:15:59,186 DEBUG Write 0x001d: 02 01 01
Pin Value: 37871896
2017-10-11 15:16:01,241 DEBUG Write 0x001d: 02 01 01
Pin Value: 37871896
2017-10-11 15:16:03,295 DEBUG Write 0x001d: 02 01 01
Pin Value: 37871896
2017-10-11 15:16:05,349 DEBUG Write 0x001d: 02 01 01
Pin Value: 37871896
^CTraceback (most recent call last):
File "GpioPin3.py", line 93, in <module>
time.sleep(2.0)
KeyboardInterrupt
You have to first subscribe to the data signal then issue read commands for each data sample.
Back on pymetawear after a long context switch.
My earlier install was not clean, I think.
So, I restarted installing on a clean Raspbian Stretch RPI3.
Switched to develop branch: https://github.com/hbldh/pymetawear/tree/develop.
How do I know that "git clone https://github.com/hbldh/pymetawear.git" would be from develop branch?
I installed using the following commands:
git clone https://github.com/hbldh/pymetawear.git
cd pymetawear
python setup.py build
cd ~/bin/pymetawear/pymetawear/MetaWear-SDK-Cpp
I had to remove -Werror from the CXXFLAGS in ~/bin/pymetawear/pymetawear/MetaWear-SDK-Cpp/config.mk, else the make would fail on src/metawear/dfu/cpp/miniz.c
make CXX=g++
...
...
...
pi@S-SquareBase:~/bin/pymetawear/pymetawear/MetaWear-SDK-Cpp $ ls dist/release/lib/arm/
libmetawear.so libmetawear.so.0 libmetawear.so.0.8.0
sudo make CXX=g++ install
install dist/release/lib/arm/libmetawear.so.0.8.0 /usr/local/lib/libmetawear.so
When I run the unit test scripts, I get bus error.
pi@S-SquareBase:~/bin/pymetawear/pymetawear/MetaWear-SDK-Cpp $ make test
python3 -m unittest discover -s test
...................................................................................
......................................................................
......................................................................................................
....................................................
........Makefile:107: recipe for target 'test' failed
make: *** [test] Bus error
Any guidance would be greatly appreciated.
Regards,
Raj
Thank you for clarification on switching to develop branch. That's what I was wondering when I asked, "How do I know that "git clone https://github.com/hbldh/pymetawear.git" would be from develop branch?"
git clone git@github.com:hbldh/pymetawear.git
cd pymetawear
git checkout develop
python3 setup.py build
Basic scripts work well. Now back on to marain target, GPIO access.
I noticed that client.py has commented the initialization of GPIO.
Do I need to uncomment it? Or I am missing something?
Agree, eventually I will need to switch to MbientLab's Python SDK.
Appreciate your kind support.
Regards,