I am pretty new to python and working with firmata I am trying to play around with an arduino .
Here is what I want to happen:
Set potentiometer to analog 0
Set PyQt timer up to update
potentiometer position in
application
Set a threshold in PyQt to turn
LED on (Analog in has 1024bit
resolution, so say 800 as the
threshold)
I am using this firmata library : Link
Here is the code that I am having trouble with:
import sys from PyQt4 import QtCore, QtGui from firmata import *
# Arduino setup
self.a = Arduino('COM3')
self.a.pin_mode(13, firmata.OUTPUT)
# Create timer
self.appTimer = QtCore.QTimer(self)
self.appTimer.start(100)
self.appTimer.event(self.updateAppTimer())
def updateAppTimer(self):
self.analogPosition = self.a.analog_read(self, 0)
self.ui.lblPositionValue.setNum()
I am getting the error message:
Traceback (most recent call last): File "D:\Programming\Eclipse\IO Demo\src\control.py", line 138, in myapp = MainWindow() File "D:\Programming\Eclipse\IO Demo\src\control.py", line 56, in init self.appTimer.event(self.updateAppTimer()) File "D:\Programming\Eclipse\IO Demo\src\control.py", line 60, in updateAppTimer self.analogPosition = self.a.analog_read(self, 0) TypeError: analog_read() takes exactly 2 arguments (3 given)
If I take 'self' out I get the same error message but that only 1 argument is given
What is python doing implicitly that I am not aware of?
Blockquote
In your code 'a' is the class instance, so all methods, bound to it, already have self pointers passed as first params. Welcome to python, someday you'd like it :)
In contra, you can call any method as unbound (and I'm sure you do it in every constructor of any derived class). Syntax is:
instance = Type()
#bound method.
instance.methodName(params)
#unbound method call, 'instance' is the instance of some object, pointer to witch
#you want to pass to method. These calls are similar.
Type.methodName(instance, params)