Writebyte and Readbyte esp QMC5883 on Python (Beaglebone Black) appear Errno 110 - python

I could not find the suitable code for this BBB Python as many source codes would express more on Raspberry Pi and Arduino. I am using VMware and Ubuntu_18 to run the linux terminal in order to run my BBB.
This are my starting few lines code to try test on QMC5883 magnetometer that I'm trying to translate Arduino into Python version.
import Adafruit_GPIO.I2C as I2C
import math
QMC5883 = I2C.Device(0x0D, 1)
QMC5883.write8(0x0b,0x01)
However, the error keep appearing as following especially the writebyte and readbyte on the terminal BBB
root#beaglebone:~/user_python# python compass1.py
Traceback (most recent call last):
File "compass1.py", line 5, in <module>
QMC5883.write8(0x0b,0x01)
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 116, in write8
File "build/bdist.linux-armv7l/egg/Adafruit_PureIO/smbus.py", line 256, in write_byte_data
IOError: [Errno 110] Connection timed out]
The link that I'm following that to call the function is from this Adafruit_GPIO/I2C.py
Even using the smbus library the error still the same
import smbus
Anyone here know how to solve this Errno110 time out connection?
I am looking forward for anyone to guide me throughout for BBB Python getting on QMC5883 magnetometer to function.

Finally is one month plus and I found the solution for Beaglebone Black. Make some changes in the library code if possible to change in the library itself. Change the bus number from 1 to 2.
This GitHub link might help you https://github.com/RigacciOrg/py-qmc5883l to get your bearing degree (yaw rotation) in no time.

Related

How to fix "RuntimeError: Unable to setup ADC system. Possible..." when calling ADC.setup()

I am trying to read the voltage from one of the analog input ports and my code is throwing an error. The error happens when calling ADC.setup() (Adafruit_BBIO). The error is as follows:
Traceback (most recent call last):
File "print_voltage", line 3, in
ADC.setup()
RuntimeError: Unable to set up ADC system. Possible causes are:
- A cape with a conflicting pin mapping is loaded
- A device tree object is loaded that uses the same name for a fragment: helper
I have tried reinstalling Adafruit_BBIO as mentioned here: Error using python Adafruit_BBIO GPIO and ADC and BeagleBone Black in ubuntu 14.04
Here is my code for the program.
import Adafruit_BBIO.ADC as ADC
from time import sleep
ADC.setup()
while i in range(0,100):
scale = ADC.read("P9_40")
print(scale*1.8)
sleep(.1)

OpenCV Error: Bad argument in ERClassifierNM1

I run opencv 3.2.0, ubuntu 14.04, and latest opencv_contrib.
I run examine:
https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/textdetection.py
But it have show err:
$ python textdetection.py scenetext_word01.jpg
textdetection.py
A demo script of the Extremal Region Filter algorithm described in:
Neumann L., Matas J.: Real-Time Scene Text Localization and Recognition, CVPR 2012
Extracting Class Specific Extremal Regions from 9 channels ...
(...) this may take a while (...)
OpenCV Error: Bad argument (Default classifier file not found!) in ERClassifierNM1, file /home/vietnam/opencv_and_contri/opencv_contrib/modules/text/src/erfilter.cpp, line 1022
Traceback (most recent call last):
File "textdetection.py", line 38, in <module>
erc1 = cv2.text.loadClassifierNM1(pathname+'/trained_classifierNM1.xml')
cv2.error: /home/vietnam/opencv_and_contri/opencv_contrib/modules/text/src/erfilter.cpp:1022: error: (-5) Default classifier file not found! in function ERClassifierNM1
How to solve this?
Try using relative paths in the parameters for cv2.text.loadClassifierNM1() and cv2.text.loadClassifierNM2()
So now that part of the code looks like this:
erc1 = cv2.text.loadClassifierNM1('./trained_classifierNM1.xml')
er1 = cv2.text.createERFilterNM1(erc1,16,0.00015,0.13,0.2,True,0.1)
erc2 = cv2.text.loadClassifierNM2('./trained_classifierNM2.xml')
er2 = cv2.text.createERFilterNM2(erc2,0.5)
I'm not sure why this works (it did for me), but I tried this after looking at a solution posted for a similar problem in VS2015 here: https://github.com/cesardelgadof/OpenCVBinaries/issues/1
Hope this helps.
Trying with absolute path e.g. "/usr/lib/opencv-3.2.0/opencv_contrib-3.2.0/modules/text/samples/trained_classifierNM1.xml" worked in my case for Ubuntu 16.04, C++

raspberry pi PWM on GPIO pins

I'm trying to change the brightness of a led (as simulator for a motor) by means of PWM on a GPIO pin of my raspberry pi (3B). But whenever i try to run my code, it gives the error
'RPi.GPIO.PWM' Object has no attribute 'changeDutyCycle'
However, this is proven wrong by both
the documentation
and
this code that gets an iteratable list of all methods of an object. I copy-pasted the method to be sure to have no spelling errors, but it still doesn't work.
The code i use is:
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3, GPIO.OUT)
p = GPIO.PWM(3, 50)
p.start(5)
time.sleep(0.5)
p.changeDutyCycle(95)
time.sleep(0.5)
The code crashes on line 9 (The second last line). The code above is only the relevant piece of the code so the resource cleanup is omitted.
I'm wondering what the error is caused by. Is it something i'm doing wrong in python, or should I look for the cause in one of my Raspberry Pi configurations?
Edit 1
Traceback, as kindly requested by jojo:
Traceback (most recent call last):
File "~/Documents/test.py", line 9, in <module>
p.changeDutyCycle(95)
AttributeError: 'RPi.GPIO.PWM' object has no attribute 'changeDutyCycle'
original answer from comments:
The function uses capital c, so p.ChangeDutyCycle(95) should do the trick.

Python Import Error + DLL load failed + sys.path

in Python 2.7.10 Anaconda 2.3.0 (64-bit), if I write
sys.path.append('C:\\Anaconda\\sms-tools-master\\software\\models\\utilFunctions_C\\')
print sys.path
I get
C:\Anaconda\sms-tools-master\workspace\A1>python A1Part1.py
['C:\Anaconda\sms-tools-master\workspace\A1', 'C:\Anaconda\python27.zip',
'C:\Anaconda\DLLs', 'C:\Anaconda\lib', 'C:\Anaconda\lib\plat-win', 'C:\A
naconda\lib\lib-tk', 'C:\Anaconda', 'C:\Anaconda\lib\site-packages', 'C:\
Anaconda\lib\site-packages\Sphinx-1.3.1-py2.7.egg', 'C:\Anaconda\lib\site-
packages\cryptography-0.9.1-py2.7-win-amd64.egg', 'C:\Anaconda\lib\site-pack
ages\win32', 'C:\Anaconda\lib\site-packages\win32\lib', 'C:\Anaconda\lib
\site-packages\Pythonwin', 'C:\Anaconda\lib\site-packages\setuptools-17.1.
1-py2.7.egg', 'C:\Anaconda\sms-tools-master\software\models\utilFunctions_C
\']
Is this absolute way of adding to sys.path correct? Is there a relative way?
In the next line of python code I wrote
from utilFunctions_C import wavread
I instantly get
ImportError: cannot import name wavread
if I run the code in cmd but if I run the code inside IDLE I get:
['C:\Anaconda\sms-tools-master\workspace\A1',
'C:\Python27\Lib\idlelib', 'C:\Windows\system32\python27.zip',
'C:\Python27\DLLs', 'C:\Python27\lib',
'C:\Python27\lib\plat-win', 'C:\Python27\lib\lib-tk',
'C:\Python27', 'C:\Python27\lib\site-packages',
'C:\Anaconda\sms-tools-master\software\models\utilFunctions_C\']
Traceback (most recent call last): File
"C:\Anaconda\sms-tools-master\workspace\A1\A1Part1.py", line 8, in
from utilFunctions_C import wavread ImportError: DLL load failed: %1 is not a valid Win32 application.
So why there is a difference and how to tackle this issue? Thnx!
I commented
from utilFunctions_C import wavread
and used
from scipy.io.wavfile import read
Now my code is okay. I found that
utiLFunctions.wavread() is a wrapper that uses scipy.io.wavfile.read()
and scales the data to floating point between -1 and 1. If you open up
utilFunctions.py you will see that.
You can use scipy.io.wavfile.read as well, as long you scale the data
correctly looking at the datatype in the wav file. Due to scaling, for
wav files that store samples as int16, you will see that
scipy.io.wavfile.read returns values will be 32767 times the values
returned by utilFunctions.wavread
Lectures used the function to explain the process more explicitly.
Once you have got it, you can use the wrapper utilFunctions.wavread
for the rest of the course and in practical applications.
Scroll in
https://class.coursera.org/audio-002/forum/search?q=Cannot+import+name+wavread#15-state-query=wavread&15-state-page_num=1
for more details.

RuntimeError: No access to /dev/mem

I have been trying to use the Python GPIO PWM to control a set of LEDs connected to my RPi. When I run the Python script, I get the following error:
Traceback (most recent call last):
File "cycle.py", line 12, in <module>
r = GPIO.PWM(f, RED)
RuntimeError: No access to /dev/mem. Try running as root!
I have tried running the script as root (both with sudo and with actually logging in as root). All of the other GPIO functions work correctly and I have tried doing an update and uninstalling/reinstalling python-rpi.gpio through apt. Here is the code I have been running.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
RED = 11
f = 100
r = GPIO.PWM(RED, f) <== Where it crashes
r.start(0)
try:
while 1:
for dc in range(0, 101, 5):
r.ChangeDutyCycle(dc)
time.sleep(0.1)
for dc in range(100, -1, 5):
r.ChangeDutyCycle(dc)
time.sleep(0.1)
except:
pass
r.stop()
GPIO.cleanup()
It is based off of the example found here, but there could still be bugs. I have been struggling with this for quite a bit now so any help provided would be greatly appreciated. Thanks!
The problem is with the code above is that I forgot to set RED to at output before trying to use it. The error message did not help resolve this problem. Next time, I need to remember to setup PWM pins as outputs before trying to use them.

Categories

Resources