Tutorial :Python PyQt Timer Firmata


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 arduino up with an LED as a digital out
  • Set potentiometer to analog 0

  • Set PyQt timer up to update potentiometer position in

  • Set a threshold in PyQt to turn LED on (Analog in has 1024bit resolution, so say 800 as the

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?



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)  


Self didn't need to be passed. I have no clue why it failed the first time, or why self is included already.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »