diff --git a/README.md b/README.md index 6ac36320..9c0fbfe9 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,10 @@ Just upload the default firmata sketch into your Arduino and you are all set. pyFirmata2 is an updated version of pyFirmata which *replaces loops with callbacks*. Instead of unreliable "sleep" commands in a loop the Python application registers callbacks which are then called -every time after new data has arrived. +every time after new data has arrived. This means for the analogue +channels the callbacks are called at the specified sampling rate +while the the digital ports call the callback functions after +a state change has happened (from 0 to 1 or 1 to 0). This API has been used in the Digital Signal Processing (DSP) class to practise realtime filtering of analogue sensor @@ -138,13 +141,12 @@ number, and the mode: - 'o' for output - 'p' for pwm - 's' for servo. -All seperated by `:`. Eg. `a:0:i` for analog 0 as input or `d:3:p` for -digital pin 3 as pwm: +All seperated by `:`, for example: ``` - analog_0 = board.get_pin('a:0:i') - analog_0.read() - pin3 = board.get_pin('d:3:p') - pin3.write(0.6) + digital_0 = board.get_pin('d:0:i') + v = digital_0.read() + pin3 = board.get_pin('d:3:o') + pin3.write(True) ``` ### Closing the board diff --git a/examples/README.md b/examples/README.md index a415c1e2..56939901 100644 --- a/examples/README.md +++ b/examples/README.md @@ -5,4 +5,4 @@ - Realtime oscilloscope. This script shows how to process data at a given sampling rate. - Printing data on the screen using an event handler - Digital in reads from a digital pin using an event handler - - Flashing LED using a loop + - Flashing LED using a timer diff --git a/examples/realtime_two_channel_scope.py b/examples/realtime_two_channel_scope.py index a5233c58..5ead21e4 100755 --- a/examples/realtime_two_channel_scope.py +++ b/examples/realtime_two_channel_scope.py @@ -58,17 +58,18 @@ def addData(self,d): # called for every new sample at channel 0 which has arrived from the Arduino # "data" contains the new sample -def callBack(data): +def callBack1(data): # filter your channel 0 samples here: # data = self.filter_of_channel0.dofilter(data) # send the sample to the plotwindow qtPanningPlot1.addData(data) - ch1 = board.analog[1].read() - # 1st sample of 2nd channel might arrive later so need to check - if ch1: - # filter your channel 1 samples here: - # ch1 = self.filter_of_channel1.dofilter(ch1) - qtPanningPlot2.addData(ch1) + +def callBack2(data): + # filter your channel 0 samples here: + # data = self.filter_of_channel0.dofilter(data) + # send the sample to the plotwindow + qtPanningPlot2.addData(data) + # Get the Ardunio board. board = Arduino(PORT) @@ -79,7 +80,8 @@ def callBack(data): # Register the callback which adds the data to the animated plot # The function "callback" (see above) is called when data has # arrived on channel 0. -board.analog[0].register_callback(callBack) +board.analog[0].register_callback(callBack1) +board.analog[1].register_callback(callBack2) # Enable the callback board.analog[0].enable_reporting()