Coder Social home page Coder Social logo

pymata-aio's Introduction

This repository has been archived.

The pymata-core API has been replaced with pymata-express, and the pymata3 API has been replaced with pymata4.

logo

pymata_aio is a high performance, non-blocking, Python asyncio client for the Firmata Protocol that supports the complete StandardFirmata protocol.

Join the chat at https://gitter.im/MrYsLab/pymata-aio

Major features

  • Python 3.5+ compatible for Linux and macOS.
    • Implements PEP 492
    • Applications developed with version 1.x of pymata_aio are backward compatible without modification.
  • Python 3.7+ compatible for Windows.
  • Implemented using the high efficiency Python asyncio library.
  • Choose From 3 Included APIs
    • pymata_core - a pure asyncio method call API.
    • pymata3 - a pymata_aio plugin implementing a method call API that acts as a proxy for pymata_core. It shields the user from the details of the asyncio library.
    • pymata_iot - a pymata_aio plugin API that implements Websocket server, and uses JSON messaging for application communication.
  • Implements 100% of the StandardFirmata Protocol (StandardFirmata 2.5.3).
  • Auto-detects Arduino COM ports.
  • FirmataPlus (enhanced StandardFirmata sketch) included with distribution. It adds support for:
    • HC-SR04 Ultrasonic Distance Sensors using a single pin.
    • Stepper Motors.
    • Piezo Tone Generation.
    • 2 Pin Rotary Encoder Support.
  • FirmataPlusRB (enhanced StandardFirmata sketch to control a SparkFun Redbot) is included with the distribution. It adds support for:
    • Piezo Tone Generation.
    • Wheel encoders.
    • RedBot Accelerometer.
    • Check out rbDashBoard for a web interface to the RedBot.
    • Check out rb4s, a Scratch Program to control the RedBot.
  • Ability to automatically capture and time-stamp user specified analog and digital transient input events on a per-pin basis.
  • All 3 APIs support callback as well as a polled interface.

Detailed package information can be found on the pymata_aio wiki.

Change log can be found here.

This project was developed with Pycharm logo

pymata-aio's People

Contributors

chrstphrchvz avatar daawesomep avatar dtheb avatar fisherds avatar gitter-badger avatar infinityis avatar leighandrewtm avatar mryslab avatar teamwildcards avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pymata-aio's Issues

Commands not sent when using a tkinter GUI

We're now working with simple GUIs to drive the RedBot. In this example we're using tkinter to make a simple button grid. Each button drives the Redbot wheels in a different direction. If you run the example below the command sent last (right PWM in this case) is not sent unless you press the button a second time. Same issue with using the arrow keys. All buttons and keys need to be pressed twice to work right. I'm guessing it's a related issues to some other things we've filed??? Any chance you can fix this one too. :) Thanks

    """
    Uses the tkinter/ttk graphics library that comes with Python to drive a RedBot.
    """

    import tkinter
    from tkinter import ttk
    from pymata_aio.pymata3 import PyMata3
    from pymata_aio.constants import Constants

    # RedBot motor pins from RedBot.h
    L_CTRL_1 = 2
    L_CTRL_2 = 4
    PWM_L = 5

    R_CTRL_1 = 7
    R_CTRL_2 = 8
    PWM_R = 6

    board = PyMata3()


    def main():
        print("tkinter GUI drive")
        board.set_pin_mode(L_CTRL_1, Constants.OUTPUT)
        board.set_pin_mode(L_CTRL_2, Constants.OUTPUT)
        board.set_pin_mode(PWM_L, Constants.PWM)
        board.set_pin_mode(R_CTRL_1, Constants.OUTPUT)
        board.set_pin_mode(R_CTRL_2, Constants.OUTPUT)
        board.set_pin_mode(PWM_R, Constants.PWM)

        root = tkinter.Tk()
        root.title("RedBot simple drive")

        main_frame = ttk.Frame(root, padding=30, relief="raised")
        main_frame.grid()

        button = ttk.Button(main_frame, text="Forward")
        button.grid(column=1, row=0)
        button["command"] = driveForward

        button = ttk.Button(main_frame, text="CCW Spin")
        button.grid(column=0, row=1)
        button["command"] = ccwSpin

        button = ttk.Button(main_frame, text="Stop")
        button.grid(column=1, row=1)
        button["command"] = stop

        button = ttk.Button(main_frame, text="CW Spin")
        button.grid(column=2, row=1)
        button["command"] = cwSpin

        button = ttk.Button(main_frame, text="Reverse")
        button.grid(column=1, row=2)
        button["command"] = driveReverse

        root.bind("<Up>", driveForward)
        root.bind("<Left>", cwSpin)
        root.bind("<space>", stop)
        root.bind("<Right>", ccwSpin)
        root.bind("<Down>", driveReverse)

        root.mainloop()


    def driveForward(event=None):
        print("Go forward")
        board.digital_write(L_CTRL_1, 1)
        board.digital_write(L_CTRL_2, 0)
        board.analog_write(PWM_L, 255)
        board.digital_write(R_CTRL_1, 1)
        board.digital_write(R_CTRL_2, 0)
        board.analog_write(PWM_R, 255)


    def ccwSpin(event=None):
        print("Spin counter clockwise")
        board.digital_write(L_CTRL_1, 0)
        board.digital_write(L_CTRL_2, 1)
        board.analog_write(PWM_L, 255)
        board.digital_write(R_CTRL_1, 1)
        board.digital_write(R_CTRL_2, 0)
        board.analog_write(PWM_R, 255)


    def stop(event=None):
        print("Stop")
        board.digital_write(L_CTRL_1, 1)
        board.digital_write(L_CTRL_2, 1)
        board.analog_write(PWM_L, 0)
        board.digital_write(R_CTRL_1, 1)
        board.digital_write(R_CTRL_2, 1)
        board.analog_write(PWM_R, 0)


    def cwSpin(event=None):
        print("Clockwise spin")
        board.digital_write(L_CTRL_1, 1)
        board.digital_write(L_CTRL_2, 0)
        board.analog_write(PWM_L, 255)
        board.digital_write(R_CTRL_1, 0)
        board.digital_write(R_CTRL_2, 1)
        board.analog_write(PWM_R, 255)


    def driveReverse(event=None):
        print("Go forward")
        board.digital_write(L_CTRL_1, 0)
        board.digital_write(L_CTRL_2, 1)
        board.analog_write(PWM_L, 255)
        board.digital_write(R_CTRL_1, 0)
        board.digital_write(R_CTRL_2, 1)
        board.analog_write(PWM_R, 255)


    main()

Error after initializing with the board

I am having this issue on my windows computer. I am running Windows 10 and PyCharm CE with the pymata-aio library. I also have the pymata library but it was not imported into the project. I have FirmataPlus loaded on the Arduino. However, I cannot get any python program to run. It will work on my Mac machine though... The error output from PyCharm is below.

C:\Users\tbaxt\AppData\Local\Programs\Python\Python35-32\python.exe C:/Users/tbaxt/Downloads/pymata-aio-master/pymata-aio-master/examples/blink.py

pymata_aio Version 2.16 Copyright (c) 2015-2016 Alan Yorinks All rights reserved.

Using COM Port:com6

Initializing Arduino - Please wait... Traceback (most recent call last):
File "C:/Users/tbaxt/Downloads/pymata-aio-master/pymata-aio-master/examples/blink.py", line 15, in
board = PyMata3()
File "C:\Users\tbaxt\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pymata_aio\pymata3.py", line 62, in init
self.core.start()
File "C:\Users\tbaxt\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pymata_aio\pymata_core.py", line 297, in start
print("\nArduino Firmware ID: " + firmware_version)
TypeError: Can't convert 'NoneType' object to str implicitly
Task was destroyed but it is pending!
task: <Task pending coro=<PymataCore._command_dispatcher() running at C:\Users\tbaxt\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pymata_aio\pymata_core.py:1301> wait_for=>

Process finished with exit code 1

Teensy 3.1 errors out with unhelpful error message (suggestion)

Teensy board throws the error "Initializing Arduino - Please wait... Cannot instantiate serial interface: /dev/tty.usbmodem958211", which is fixed by increasing arduino_wait - this isn't obvious to the end user as the needed step, suggesting that might be helpful :)

Lots of output

First of all, thanks for your work with this project. I've just begun to use it and I'm very hopeful to integrate it into my own projects. One issue that I have with it is that it is very chatty and produces lots of output to STDOUT. How about using the logging module so they can be suppressed? I'm happy to contribute, too. So if you'd like a RP for this or any other issues I raise let me know.

Analog Report Lagging

The analog report has been lagging, and I've got the updated values from analog pin only after 8-10 seconds. Tried the pymata with Python 2.7 and results are okay.

from pymata_aio.pymata3 import PyMata3
from pymata_aio.constants import Constants

board = PyMata3(arduino_wait=5)
board.set_pin_mode(1, Constants.ANALOG)

while True:
    value = board.analog_read(1)
    print (value)
    board.sleep(2)

I've tried both on UNO and Nano, and both are not working with results greatly lagging behind. Please help pinpoint what has been gone wrong.

Thanks.

Cutomize Serial object

Hi, while investigating my problem from #42, I've found that my USB-TTL converter requires _rtsState field of the Serial object to be set to 0 (by default it equals 1). This is done via Serial.setRTS(0) method.
To make this work in pymata I had to override start_aio method to only add single self.serial_port.my_serial.setRTS(0) string after PymataSerial object initialization.
Could you please suggest more elegant way to make such change? Maybe it is possible to init PymataSerial with my own pyserial object?
Thanks in advance.

pin mode issues

When adding pin modes not yet supported by Firmata I recommend either starting backwards from 0x7e or submitting a proposal to have a pin mode reserved in Firmata. Otherwise you will find it difficult when you update to newer Firmata protocol versions. For example, you have diverged from the pin modes that are (loosely) documented in the protocol: https://github.com/MrYsLab/pymata-aio/blob/master/pymata_aio/constants.py#L34-L37

According to the protocol however:

0x09 = ENCODER
0x0a = SERIAL
0x0b = INPUT_PULLUP

While there is not a strict requirement to follow this (anyone can use Firmata however they want and distribute their own "StandardFirmata" variant), following this will make updating easier if you add features such as SERIAL and INPUT_PULLUP at some point in the future, especially since I have been adding new features such as SERIAL as separate classes to help manage complexity.

Port manipulation with digital_write unclear

I'm trying to write to multiple output pins simultaneously by port manipulation.
It seems that pymata_core.digital_write can do this, but I'm not sure how to use it. The documentation says "Set the specified pin to the specified value" even though it's clear from digital_pin_write that it can write multiple pins.
I'd be happy to commit a documentation change if the developers can tell me how to use this :)

Compatibility and Python 3.6

Hello:

I'm new using firmata protocol, and looking a first steps guide...

pyMata was installed well aparantely in Python 3.6... is recommendable to use it on Python 3.6?

This library is compatible with all arduino boards?

Thank you

Analog data callback functions persist past shutdown and interfere with new board initialization

Hi,

I've noticed that since I implemented sensor callback functions for my arduino project, I'm having trouble initializing a new board even after the old one is terminated. The only real hint I have at the cause is that the TX indicator light on my arduino stays on for a few minutes after my arduino shuts down and my program ends completely.

I assume this has something to do with asyncio. I'm implementing my callback directly, like this:

def _record(self, data) -> None:
   if data[1] != self.previous_value:
   self.log_file.write('%s,%s,\n' % (data[1],datetime.datetime.now()))
      self.previous_value = data[1]

self._board.set_pin_mode(pin_number=5, pin_state=Constants.ANALOG, callback=_record, cb_type=Constants.CB_TYPE_DIRECT)

The arduino does eventually shut down completely, so it's not the highest impact bug for me. All the same, I'd like to hear your thoughts on how to avoid this problem altogether?

ping.py with HC-SR04 not printing values

Hi, I'm using FirmataPlus on an Arduino Uno and I am running the attached code on Windows 10, however I get the following message and nothing happens after that.

pymata_aio Version 2.16 Copyright (c) 2015-2016 Alan Yorinks All rights reserved.

Initializing Arduino - Please wait...
Arduino Firmware ID: 2.5 FirmataPlus.ino
Auto-discovery complete. Found 20 Digital Pins and 6 Analog Pins

I have connected the trigger and echo pins of the HC-SR04 sensor to pin 12 of the Uno and connected the 5V and GND as well. I tried connecting the trigger and echo pins to different Arduino pins but that didn't help.

I would like to add that sometimes I do get the sonar data printed but they are wrong, at other times the data would be correct but would not update for a long time (say 10 seconds or so). Any advice on what I could try?

Here is the code I am running.

`
from pymata_aio.pymata3 import PyMata3

ping callback function

def cb_ping(data):
print(str(data[1]) + ' centimeters')

#create a PyMata instance
#board = PyMata3(3)

board=PyMata3(arduino_wait=5, com_port='COM8')

configure 4 pins for 4 SONAR modules

board.sonar_config(12, 12, cb_ping)

while True:
board.sleep(.1)
board.shutdown()
`

_encoder_data() missing 1 required positional argument: 'data'

i keep getting errors like this with different method names _encoder_data() changes from run to run all from pymata core

using FirmataStandard on arduino mega

all i do is self.board.set_pin_mode(pin.number, pin.type, pin.callback) for bunch of analogs or digitals and wait.. i get callbacks data for a second then crash like that

Analog reporting issues?

I've been running into some issues with analog polling in aio that I don't see in pymata plain, namely delayed polling and strange (inaccurate?) values. Looks something like this:
0
0
0
0
0
0
0
0
392
0
392
1007
392
1007
392
1007
566
1007

(I'm reading off of two pins, the first is pulled down to 0V, the second is pulled up to 3.3V)

I'm getting similar strange readings on my mega, boarduino, trinket pro, and teensies so it isn't board related. I think I'm doing something dumb but not sure what. Program is:
import time
from pymata_aio_v9.pymata3 import PyMata3
from pymata_aio.constants import Constants

board = PyMata3(arduino_wait=10)
board.set_pin_mode(1, Constants.ANALOG)
board.set_pin_mode(2, Constants.ANALOG)

while(True):
print(board.analog_read(1))
print(board.analog_read(2))

time.sleep(10)

Ctrl-C to shutdown doesn't work with board.sleep

I'm not sure if it is supposed to or not, but in the old version of Pymata that used time.sleep you could hit Ctrl-C to get a reset (which is now called shutdown). If I hit Ctrl-C during a board.sleep the shutdown command it's actually doing a shutdown on the Arduino. Ctrl-C works to print messages and shutdown is called, but there is no actual reset happening on the Arduino.

Running the code below does this...

    davids-mbp:Projects fisherds$ python3 simple_drive.py 
    pymata_aio Version 1.4  Copyright (c) 2015 Alan Yorinks All rights reserved.
    Using COM Port:/dev/tty.usbserial-A601LFJ9
    Initializing Arduino - Please wait... Auto-discovery complete. Found 20 Digital Pins and 6 Analog Pins
    Simple drive
    Straight
    Left!
    ^C
    You pressed Ctrl+C
    Shutting down ...

But then the motors all keep running whatever the current state is. Is there a way to get back the Ctrl-C feature while using board.sleep? Here is the complete code...

    #!/usr/bin/env python3
    """
    Copyright (c) 2015 Alan Yorinks All rights reserved.
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU  General Public
    License as published by the Free Software Foundation; either
    version 3 of the License, or (at your option) any later version.
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
    You should have received a copy of the GNU General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    """

    import sys
    import signal
    import time

    from pymata_aio.pymata3 import PyMata3
    from pymata_aio.constants import Constants

    BOARD_LED = 13

    # RedBot motor pins (from RedBot.h)
    L_CTRL_1 = 2
    L_CTRL_2 = 4
    PWM_L = 5

    R_CTRL_1 = 7
    R_CTRL_2 = 8
    PWM_R = 6

    board = PyMata3()

    def signal_handler(sig, frame):
        print('\nYou pressed Ctrl+C')
        if board is not None:
            board.shutdown()
        sys.exit(0)

    signal.signal(signal.SIGINT, signal_handler) # Handle Ctrl-C to shutdown

    def setup():
        """Setup pins"""
        print("Simple drive")
        board.set_pin_mode(BOARD_LED, Constants.OUTPUT)
        board.set_pin_mode(L_CTRL_1, Constants.OUTPUT)
        board.set_pin_mode(L_CTRL_2, Constants.OUTPUT)
        board.set_pin_mode(PWM_L, Constants.PWM)
        board.set_pin_mode(R_CTRL_1, Constants.OUTPUT)
        board.set_pin_mode(R_CTRL_2, Constants.OUTPUT)
        board.set_pin_mode(PWM_R, Constants.PWM)

    def loop():
        print("Straight")
        board.digital_write(BOARD_LED, 1)
        board.digital_write(R_CTRL_1, 1)
        board.digital_write(R_CTRL_2, 0)
        board.analog_write(PWM_R, 245)
        board.digital_write(L_CTRL_1, 1)
        board.digital_write(L_CTRL_2, 0)
        board.analog_write(PWM_L, 245)
        board.sleep(2.0)

        print("Left!")
        board.digital_write(BOARD_LED, 0)
        board.digital_write(R_CTRL_1, 0)
        board.digital_write(R_CTRL_2, 1)
        board.analog_write(PWM_R, 245)
        board.digital_write(L_CTRL_1, 1)
        board.digital_write(L_CTRL_2, 0)
        board.analog_write(PWM_L, 245)
        board.sleep(2.0)

        print("Right")
        board.digital_write(BOARD_LED, 1)
        board.digital_write(R_CTRL_1, 1)
        board.digital_write(R_CTRL_2, 0)
        board.analog_write(PWM_R, 245)
        board.digital_write(L_CTRL_1, 0)
        board.digital_write(L_CTRL_2, 1)
        board.analog_write(PWM_L, 245)
        board.sleep(2.0)


        print("Stop")
        board.digital_write(BOARD_LED, 0)
        board.digital_write(R_CTRL_1, 1)
        board.digital_write(R_CTRL_2, 0)
        board.analog_write(PWM_R, 0)
        board.digital_write(L_CTRL_1, 1)
        board.digital_write(L_CTRL_2, 0)
        board.analog_write(PWM_L, 0)
        board.sleep(5.0)


    if __name__ == "__main__":
      setup()
      while True:
        loop()

Cannot start a board during asyncio loop

Currently a RuntimeError is raised when attempting to start a board when the event loop is already running. Will it be possible to start a board while when an event loop has already started?

Error message when execute in Arduino IDE

Hello,

When loading firmataplus generates a message and after that the compilation is completed. When I go to connect with Scratch, nothing happens. Can you help me? Thank you

The following error message:

/home/renato/sketchbook/libraries/FirmataPlus/examples/FirmataPlus/FirmataPlus.ino:39:1: warning: "/*" within comment [-Wcomment] /* ^ /home/renato/sketchbook/libraries/FirmataPlus/examples/FirmataPlus/FirmataPlus.ino:48:29: warning: extra tokens at end of #include directive #include <ooPinChangeInt.h> https://code.google.com/p/arduino-pinchangeint/downloads/detail?name=pinchangeint-v2.19beta.zip ^ /home/renato/sketchbook/libraries/FirmataPlus/examples/FirmataPlus/FirmataPlus.ino:49:25: warning: extra tokens at end of #include directive #include <AdaEncoder.h> https://code.google.com/p/adaencoder/downloads/detail?name=adaencoder-v0.7beta.zip ^ In file included from /home/renato/sketchbook/libraries/FirmataPlus/examples/FirmataPlus/FirmataPlus.ino:48:0: /home/renato/sketchbook/libraries/ooPinChangeInt/ooPinChangeInt.h: In constructor 'PCintPort::PCintPort(int, volatile uint8_t&)': /home/renato/sketchbook/libraries/ooPinChangeInt/ooPinChangeInt.h:200:12: warning: 'PCintPort::firstPin' will be initialized after [-Wreorder] PCintPin* firstPin; ^ /home/renato/sketchbook/libraries/ooPinChangeInt/ooPinChangeInt.h:196:19: warning: 'const uint8_t PCintPort::PCICRbit' [-Wreorder] const uint8_t PCICRbit; ^ /home/renato/sketchbook/libraries/ooPinChangeInt/ooPinChangeInt.h:164:2: warning: when initialized here [-Wreorder] PCintPort(int index,volatile uint8_t& maskReg) : ^ /home/renato/sketchbook/libraries/ooPinChangeInt/ooPinChangeInt.h: In member function 'void PCintPort::PCint()': /home/renato/sketchbook/libraries/ooPinChangeInt/ooPinChangeInt.h:381:10: warning: unused variable 'thisChangedPin' [-Wunused-variable] uint8_t thisChangedPin, changedPins; ^ /home/renato/sketchbook/libraries/FirmataPlus/examples/FirmataPlus/FirmataPlus.ino: In function 'void sysexCallback(byte, byte, byte*)': /home/renato/sketchbook/libraries/FirmataPlus/examples/FirmataPlus/FirmataPlus.ino:849:36: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings] printData("argc = ", argc) ; ^ /home/renato/sketchbook/libraries/FirmataPlus/examples/FirmataPlus/FirmataPlus.ino:767:23: warning: variable 'encoder' set but not used [-Wunused-but-set-variable] static AdaEncoder encoder = ^ /home/renato/sketchbook/libraries/FirmataPlus/examples/FirmataPlus/FirmataPlus.ino:545:8: warning: unused variable 'pin' [-Wunused-variable] byte pin ;// used for tone ^ /home/renato/sketchbook/libraries/FirmataPlus/examples/FirmataPlus/FirmataPlus.ino:546:7: warning: unused variable 'frequency' [-Wunused-variable] int frequency ; ^ /home/renato/sketchbook/libraries/FirmataPlus/examples/FirmataPlus/FirmataPlus.ino:547:7: warning: unused variable 'duration' [-Wunused-variable] int duration ; ^ /home/renato/sketchbook/libraries/ooPinChangeInt/ooPinChangeInt.h: In function 'attachInterrupt.constprop': /home/renato/sketchbook/libraries/ooPinChangeInt/ooPinChangeInt.h:319:18: warning: 'tmp' may be used uninitialized in this function [-Wmaybe-uninitialized] else tmp->next=p; ^ /home/renato/sketchbook/libraries/ooPinChangeInt/ooPinChangeInt.h:297:12: note: 'tmp' was declared here PCintPin* tmp; ^

FirmataPlus with Mega 2560 has some issues.

It appears that the included version of FirmataPlus cannot communicate with the Mega 2560.
A workaround is to either use StandardFirmata or the older version of FirmataPlus

The Uno and Leonardo does not exhibit these issues.

Error message when execute

When i execute 'pymata_aio_pymata3_example' with python 3.4, i receive this message from compiler:
Traceback (most recent call last):
File "pymata3_test1.py", line 4, in
from pymata_aio.pymata3 import PyMata3
File "/usr/local/lib/python3.4/dist-packages/pymata_aio/pymata3.py", line 23, in
from .pymata_core import PymataCore
File "/usr/local/lib/python3.4/dist-packages/pymata_aio/pymata_core.py", line 285
async def start_aio(self):
^
SyntaxError: invalid syntax
why this message from python3.4? the syntax seem correct, any suggestion ?
Tanks for your job and sinceres greatings.
Lionel

Compiling Error "Linking everything together..." FirmataPlus

Hello,

I am getting multiple error messages while trying to compile the FirmataPlus library onto my Arduino Uno. I am using the Arduino IED 1.6.12 on a Win 7 Pro system. The console gives me out the error during the part where it tries to link everything together:

Linking everything together... "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-gcc" -w -Os -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\Users\csc\AppData\Local\Temp\arduino_build_238763/FirmataPlus.ino.elf" "C:\Users\csc\AppData\Local\Temp\arduino_build_238763\sketch\FirmataPlus.ino.cpp.o" "C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\Servo\avr\Servo.cpp.o" "C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\Servo\sam\Servo.cpp.o" "C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\Servo\samd\Servo.cpp.o" "C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\Wire\Wire.cpp.o" "C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\Wire\utility\twi.c.o" "C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\FirmataPlus\FirmataPlus.cpp.o" "C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\NewPing\NewPing.cpp.o" "C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\Stepper\Stepper.cpp.o" "C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder (2).cpp.o" "C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder.cpp.o" "C:\Users\csc\AppData\Local\Temp\arduino_build_238763/core\core.a" "-LC:\Users\csc\AppData\Local\Temp\arduino_build_238763" -lm C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder.cpp.o (symbol from plugin): In function AdaEncoder::cbmethod()':

(.text+0x0): multiple definition of `AdaEncoder::cbmethod()'

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder.cpp.o (symbol from plugin): In function `AdaEncoder::cbmethod()':

(.text+0x0): multiple definition of `AdaEncoder::turnOffPWM(unsigned char)'

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder.cpp.o (symbol from plugin): In function `AdaEncoder::cbmethod()':

(.text+0x0): multiple definition of `AdaEncoder::getFirstEncoder()'

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder.cpp.o (symbol from plugin): In function `AdaEncoder::cbmethod()':

(.text+0x0): multiple definition of `firstEncoder'

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder.cpp.o (symbol from plugin): In function `AdaEncoder::cbmethod()':

(.text+0x0): multiple definition of `AdaEncoder::attachInterrupt(unsigned char, unsigned char)'

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder.cpp.o (symbol from plugin): In function `AdaEncoder::cbmethod()':

(.text+0x0): multiple definition of `AdaEncoder::addEncoder(char, unsigned char, unsigned char)'

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder.cpp.o (symbol from plugin): In function `AdaEncoder::cbmethod()':

(.text+0x0): multiple definition of `AdaEncoder::genie()'

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder.cpp.o (symbol from plugin): In function `AdaEncoder::cbmethod()':

(.text+0x0): multiple definition of `currentEncoder'

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder.cpp.o (symbol from plugin): In function `AdaEncoder::cbmethod()':

(.text+0x0): multiple definition of `AdaEncoder::getID()'

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder.cpp.o (symbol from plugin): In function `AdaEncoder::cbmethod()':

(.text+0x0): multiple definition of `AdaEncoder::getClicks()'

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder.cpp.o (symbol from plugin): In function `AdaEncoder::cbmethod()':

(.text+0x0): multiple definition of `AdaEncoder::query()'

C:\Users\csc\AppData\Local\Temp\arduino_build_238763\libraries\AdaEncoder\AdaEncoder (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

Using library Servo at version 1.1.2 in folder: C:\Program Files (x86)\Arduino\libraries\Servo
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire
Using library FirmataPlus in folder: C:\Users\csc\Documents\Arduino\libraries\FirmataPlus (legacy)
Using library NewPing in folder: C:\Users\csc\Documents\Arduino\libraries\NewPing (legacy)
Using library Stepper at version 1.1.3 in folder: C:\Program Files (x86)\Arduino\libraries\Stepper
Using library ooPinChangeInt in folder: C:\Users\csc\Documents\Arduino\libraries\ooPinChangeInt (legacy)
Using library AdaEncoder in folder: C:\Users\csc\Documents\Arduino\libraries\AdaEncoder (legacy)
exit status 1
Error compiling for board Arduino/Genuino Uno.
`

Hope you could help.
Thanks!

pymata3 losing messages if many are sent at once

If many messages are sent at once using pymata3 the later messages are not sent. For example I'm doing 2 digit writes then an analog write (done twice). I believe it's the first digital write after the analog write that never works. I'm getting around this by resending them in the code below, but obviously that isn't good. :)

Video showing the code below running.
http://youtu.be/J5gNZM6pQJA
Note I'm using an XBee in the video, but the issue is not with the XBee. Exact same behavior with the direct USB cable connection.

#!/usr/bin/env python3
"""
Copyright (c) 2015 Alan Yorinks All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU  General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
"""

import time
import sys
import signal

from pymata_aio.pymata3 import PyMata3
from pymata_aio.constants import Constants

BOARD_LED = 13

# RedBot motor pins (from RedBot.h)
L_CTRL_1 = 2
L_CTRL_2 = 4
PWM_L = 5

R_CTRL_1 = 7
R_CTRL_2 = 8
PWM_R = 6

board = PyMata3()

def signal_handler(sig, frame):
    print('\nYou pressed Ctrl+C')
    if board is not None:
        board.shutdown()
    sys.exit(0)

def setup():
    """Setup pins"""
    signal.signal(signal.SIGINT, signal_handler) # Handle Ctrl-C to shutdown
    print("Simple drive")
    board.set_pin_mode(BOARD_LED, Constants.OUTPUT)
    board.set_pin_mode(L_CTRL_1, Constants.OUTPUT)
    board.set_pin_mode(L_CTRL_2, Constants.OUTPUT)
    board.set_pin_mode(PWM_L, Constants.PWM)
    board.set_pin_mode(R_CTRL_1, Constants.OUTPUT)
    board.set_pin_mode(R_CTRL_2, Constants.OUTPUT)
    board.set_pin_mode(PWM_R, Constants.PWM)

def loop(use_resend_fallback_mechanism):
    if use_resend_fallback_mechanism:
        print("USING resend fallback mechanism.")
    else:
        print("Only send each command once")

    print("Straight")
    board.digital_write(BOARD_LED, 1)
    board.digital_write(R_CTRL_1, 1)
    board.digital_write(R_CTRL_2, 0)
    board.analog_write(PWM_R, 245)
    board.digital_write(L_CTRL_1, 1)
    board.digital_write(L_CTRL_2, 0)
    board.analog_write(PWM_L, 245)

    if use_resend_fallback_mechanism:
        time.sleep(0.1)
        # Resend to be sure messages sent second arrived.
        board.digital_write(L_CTRL_1, 1)
        board.digital_write(L_CTRL_2, 0)
        board.analog_write(PWM_L, 245)

    time.sleep(2.0)

    print("Left!")
    board.digital_write(BOARD_LED, 0)
    board.digital_write(R_CTRL_1, 0)
    board.digital_write(R_CTRL_2, 1)
    board.analog_write(PWM_R, 245)
    board.digital_write(L_CTRL_1, 1)
    board.digital_write(L_CTRL_2, 0)
    board.analog_write(PWM_L, 245)
    time.sleep(2.0)

    print("Right")
    board.digital_write(BOARD_LED, 1)
    board.digital_write(R_CTRL_1, 1)
    board.digital_write(R_CTRL_2, 0)
    board.analog_write(PWM_R, 245)
    board.digital_write(L_CTRL_1, 0)
    board.digital_write(L_CTRL_2, 1)
    board.analog_write(PWM_L, 245)
    time.sleep(2.0)


    print("Stop")
    board.digital_write(BOARD_LED, 0)
    board.digital_write(R_CTRL_1, 1)
    board.digital_write(R_CTRL_2, 0)
    board.analog_write(PWM_R, 0)
    board.digital_write(L_CTRL_1, 1)
    board.digital_write(L_CTRL_2, 0)
    board.analog_write(PWM_L, 0)

    if use_resend_fallback_mechanism:
        time.sleep(0.1)
        # Resend to be sure messages sent second arrived.
        board.digital_write(L_CTRL_1, 1)
        board.digital_write(L_CTRL_2, 0)
        board.analog_write(PWM_L, 0)

    time.sleep(5.0)


if __name__ == "__main__":
  setup()
  use_resend_fallback_mechanism = True
  while True:
    loop(use_resend_fallback_mechanism)
    use_resend_fallback_mechanism = not use_resend_fallback_mechanism

Problem with TKinter

Hello,

I've a problem with tkinter and pymata-aio:
I have a simpy window with two buttons. On one button i can switch a LED on and off, while the other detects a pressed button connected to the arduino and makes a windows with "pressed".
However if I press the arudino button, tkinter only creates the window "pressed", if I click on the LED button. I've noticed that there was a similar problem last year, but I'm not sure if it's a tkiner or pymata problem.

from pymata_aio.pymata3 import PyMata3
from pymata_aio.constants import Constants
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
import time

def on():
    board.digital_write(BOARD_LED, 1)
    button.configure(bg = '#00CC00', text = "Off", command=off)
    pressed.configure(text = "Pressed")


def off():
    board.digital_write(BOARD_LED, 0)
    button.configure(bg = '#FF0101', text = "On", command=on)

def press(data):
    messagebox.showinfo(message='Button pressed')


def latch_callback(data):
        print(str(data))
        print(time.ctime(int(data[2])))

value = {}
BOARD_LED = 9
BOARD_BUTTON = 8
board = PyMata3(com_port='COM7')

root = Tk()
root.title('LED On/Off')
mainframe = ttk.Frame(root, padding="2 2 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
button = Button(mainframe, text="On", command=on, background='red', width="30")
button.grid(column=2, row=1, sticky=W)
pressed = Button(mainframe, text="Not pressed", width = "30")
pressed.grid(column=2, row=2, sticky=W)


for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)
mainframe.focus()

def setup():
    board.set_pin_mode(BOARD_LED, Constants.OUTPUT)
    board.set_pin_mode(BOARD_BUTTON, Constants.INPUT, press)

if __name__ == "__main__":
    setup()
    root.mainloop()

different behaviour when running under VS code and from bash

Hi,

I'm new to pymata and trying to get working pymata-aio under Linux Mint (running in Virtualbox). Python 3.5.1. Using example (https://gist.github.com/MrYsLab/8b735813e413bf62b455).

When I run it in Visual studio code debugger it behaves better than when running from bash. See attached logs and scope captures (green - TX from PC, yellow RX to PC). It seems to me, that when running from bash the script does not wait for response and is transmitting commands too fast.

log.txt

VS code:
vs code

Bash:
bash

Thanks.
JC

suggestion for board initialization output

Hi, everyone. I want to say that I think this is a great tool. I am very happy at how easy it is to program my Arduino with Python. Believe it or not, my daughter actually thinks it is pretty cool too (whereas normally she is just like "Ehh, python.") I have one comment which is a matter of opinion, and perhaps there is a good reason why the developers choose to do this. I would be glad to hear the benefit/reasons for doing this.

So I used the library for the first time today and I think it's really cool. However I saw this upon initializing the board. Again, this is a matter of opinion and in the grand scheme probably a small issue. Stylistically speaking I do not like the output of initializing the board:

>>> board = PyMata3()

pymata_aio Version 2.1    Copyright (c) 2015 Alan Yorinks All rights reserved.

Using COM Port:/dev/ttyACM0

Initializing Arduino - Please wait... Auto-discovery complete. Found 20 Digital Pins and 6 Analog Pins

What I do not like about the output is the mention of the copyright. I feel that it takes away screen-space and distracts from the content relevant to programming. Personally I would just rely on the license in the project directory. I am basing this off of my use of the scipy stack. All of the packages I have used, do not mention copyright in the terminal. From what I can tell this is using GNU license, which I am sure at least some of the scipy stack uses.

Anyways, I am huge fan so far! Looking forward making more use of the tool! I look forward to hearing back on this issue.

incorrect order of values in sonar_pin_entry

The documentation describes that the sonar_pin_entries in active_sonar_map is [cb, cb_type, value]. This is reflected properly in the sonar_config() function.

The pymata3-core sonar_data_retrieve() function however assumes the sensor value is in sonar_pin_entry[1] instead of sonar_pin_entry[2]. The same issue occurs in the _sonar_data() function on lines 1568/1569.

Reconnecting, isConnected, or timeout exception?

Hi,

Is there any built-in way to detect board connection loss?

i'm building a datalogger, i need to know in case the board died for whatever reason, like powerloss, cables failure or the board goes on fire 🔥

i don't want to spam the board with read commands or framework version command

issues running from secondary thread

I am trying to run the pymata elements of my program in a separate thread as the main thread is utilised bu the GUI.

I have managed to get as far as getting the board to initialise and set initial pin states, after adding the following inside my thread:

loop = asyncio.new_event_loop() asyncio.set_event_loop(loop)

However, further calls to change the state of pins will not take affect and on terminating the application I get he following error:

Task was destroyed but it is pending!
task: <Task pending coro=<PymataCore._command_dispatcher() running at /home/deano/.local/lib/python3.5/site-packages/pymata_aio/pymata_core.py:1296> wait_for=>

This occurs both when the update call is made from within the thread and externally (from GUI thread).

Additionally when trying to call from GUI thread I get the following error:

File "AquariumMonitor.py", line 39, in update_IOput
self.backendController.ioputs[IOputName].setValue(IOValue)
File "/home/deano/PiAquarium/AqFirmataInput.py", line 47, in setValue
self.disable()
File "/home/deano/PiAquarium/AqFirmataInput.py", line 73, in disable
self.device.digital_write (self.pin, self.disable_state)
File "/home/deano/.local/lib/python3.5/site-packages/pymata_aio/pymata3.py", line 121, in digital_write
self.loop.run_until_complete(task)
File "/usr/lib/python3.5/asyncio/base_events.py", line 446, in run_until_complete
future = tasks.ensure_future(future, loop=self)
File "/usr/lib/python3.5/asyncio/tasks.py", line 555, in ensure_future
raise ValueError('loop argument must agree with Future')

and then the following on termination:

task: <Task pending coro=<PymataCore.digital_write() running at /home/deano/.local/lib/python3.5/site-packages/pymata_aio/pymata_core.py:541>>
Task was destroyed but it is pending!

wrapping the change state calls within a asyncio.ensure_future() clears the errors on calling from GUI, but the pin state never changes.

I suspect the issues is around the event loop, but I'm afraid I have run out of expertise!

V2.2 - v2.4 broke teensy3.x support

Error is:

Using COM Port:/dev/tty.usbmodem1053091

Initializing Arduino - Please wait... *** Analog map retrieval timed out. ***

Do you have Arduino connectivity and do you have a Firmata sketch uploaded to the board?

This is resolved by: specifying com_port, which promptly causes the following exception:
Traceback (most recent call last):

File "/Users/mnapolitano/PycharmProjects/michaels_random_py/test.py", line 5, in
board = PyMata3(arduino_wait=5, com_port='/dev/cu.usbmodem1053091')
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pymata_aio/pymata3.py", line 56, in init
com_port, ip_address, ip_port, ip_handshake)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pymata_aio/pymata_core.py", line 214, in init
self.ip_address + ':' + str(self.ip_port))
TypeError: Can't convert 'NoneType' object to str implicitly
)

Commenting out ip support in pymata_core start() and setting the first if clause to always false allows for proper recognition

I believe the underlying issue to be here:
else:
if self.log_output:
log_string = 'Using Ip Address/Port: ' + self.ip_address +
':' + str(ip_port)
logging.info(log_string)
else:
print('Using Ip Address/Port: ' +
self.ip_address + ':' + str(self.ip_port))
should probably be:
else:
if self.log_output:
log_string = 'Using Ip Address/Port: ' + self.ip_address +
':' + str(ip_port)
logging.info(log_string)
elif self.ip_address is not None:
print('Using Ip Address/Port: ' +
self.ip_address + ':' + str(self.ip_port))

to stop that particular exception from messing things up

Why this is only the case for teensy and not for any of the others I don't know. Maybe because it's cu.XXXX not tty.XXXX?

pymata fails with ping

Servo works great, but ping never has the callback called, this is true in both pymata and pymata-aio
Could it be the firmataplus??
(the arduino ping.ino works fine and shows correct values)

Console output (PC to genuine Uno)
c:\python363>python pingtest.py

pymata_aio Version 2.19 Copyright (c) 2015-2017 Alan Yorinks All rights reserved.
Using COM Port:com10
Initializing Arduino - Please wait...
Arduino Firmware ID: 2.5 StandardFirmataPlus.ino
Auto-discovery complete. Found 20 Digital Pins and 6 Analog Pins
(here I hit ctl-c)
Traceback (most recent call last):
File "pingtest.py", line 39, in
board.sleep(.1)
File "c:\python363\lib\site-packages\pymata_aio\pymata3.py", line 542, in sleep
self.loop.run_until_complete(task)
File "c:\python363\lib\asyncio\base_events.py", line 454, in run_until_complete
self.run_forever()
File "c:\python363\lib\asyncio\base_events.py", line 421, in run_forever
self._run_once()
File "c:\python363\lib\asyncio\base_events.py", line 1390, in _run_once
event_list = self._selector.select(timeout)
File "c:\python363\lib\selectors.py", line 323, in select
r, w, _ = self._select(self._readers, self._writers, [], timeout)
File "c:\python363\lib\selectors.py", line 314, in _select
r, w, x = select.select(r, w, w, timeout)
KeyboardInterrupt

code (directly from your site)
``
from pymata_aio.pymata3 import PyMata3
def cb_ping(data):
print(str(data[1]) + ' centimeters')

board = PyMata3(2)
board.sonar_config(12, 12, cb_ping)

while True:
board.sleep(.1)

board.shutdown()

`This code also fails:
import time

import sys
import signal
from PyMata.pymata import PyMata
def cb_ping(data):
print(str(data[2]) + ' centimeters')
board = PyMata("com10", verbose=True)
def signal_handler(sig, frame):
print('You pressed Ctrl+C!!!!')
if board is not None:
board.reset()
board.close()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
board.sonar_config(12, 12, cb_ping)
time.sleep(10)
board.close()
~`

FirmataPlus Arduino IDE Compilation Error

Hello,

My Arduino IDE is reporting some errors, aborting the compilation. I'm using version 2:1.0.5 of Arduino IDE. Here is the error:

FirmataPlus.ino: In function ‘void setPinModeCallback(byte, int)’:
FirmataPlus.ino:339:20: error: ‘disableI2CPins’ was not declared in this scope
FirmataPlus.ino:347:77: error: ‘reportAnalogCallback’ was not declared in this scope
FirmataPlus.ino: In function ‘void sysexCallback(byte, byte, byte*)’:
FirmataPlus.ino:680:23: error: ‘enableI2CPins’ was not declared in this scope
FirmataPlus.ino:871:36: error: ‘printData’ was not declared in this scope

Can you give me some advice? Thanks!

Unpin pyserial==2.7

PyMata-aio was pinned to use pyserial==2.7 due to issue #34 , however that has since been fixed.

Would it be possible to now remove the version pinning from setup.py, as pyserial 2.7 is not compatible with python 3.5+

how to invoke pymata_aio socket for web control?

A question from a newbie: I am getting "The socket has closed! Did you start the server?" when I try the example ( pymata-aio/examples/pwm_pin_example.html). what do I do to invoke the socket?

I am using Arch linux with newest version of everything as of now.

Thanks

Tony

i2c_read_request replies need to be reformatted.

Currently the values are being returned to the user in the firmata 2 byte format. Data needs to be recombined and returned in its "natural" state and not burden the user with firmata formats.

set_pin_mode was never awaited for sonar_config

Hi, sorry if this is not the right way or format to report an issue, I'm a rookie regarding git (and programming for that matter!)

I'm using the pymata3 class to try and initialize my HR-SR04 sensor and get the following warnings:

/usr/local/lib/python3.5/site-packages/pymata_aio/pymata_core.py:1098: RuntimeWarning: coroutine 'PymataCore.set_pin_mode' was never awaited
  self.set_pin_mode(trigger_pin, Constants.SONAR, Constants.INPUT)
/usr/local/lib/python3.5/site-packages/pymata_aio/pymata_core.py:1099: RuntimeWarning: coroutine 'PymataCore.set_pin_mode' was never awaited
  self.set_pin_mode(echo_pin, Constants.SONAR, Constants.INPUT)

Looking at pymata_core.py lines 1098/1099 it seems they are called as a normal function instead of a coroutine. I think these lines should be prepended with await (or yield from on python <=3.4)

Thanks,
Thiezn

APC220 compatibility

Hi, I'm trying to use pymata with radio module apc220 and it doesn't work. Console just prints the string "Initializing Arduino - Please wait..." and nothing happens, LEDs on the board are dead and I don't even get timout message or anything like that.
I've checked that the scheme I'm using is correct by aploading simple echo sketch and verifing that I see echoed strings at the PC.
Also I've found the similar issue described here: firmata/arduino#296
It was fixed by sending reset command to the Arduino, I've tried the same, but without any luck, think I was doing this wrong. Also I've tried to press little red button on the board itself.
Hope to get any help or clues at least.

pymata_core.get_analog_map() times out prematurely on some Arduino boards

I ran into a knock-off Arduino Mega 2560 board for which 2 seconds appears to be insufficient to transmit the entire analog pin map. Increasing timeout threshold appears to fix the issue.

async def get_analog_map(self):
       ...
            # wait for the report results to return for 2 seconds
            # if the timer expires, shutdown
            while self.query_reply_data.get(
                    PrivateConstants.ANALOG_MAPPING_RESPONSE) is None:
                elapsed_time = time.time()
                # This times out prematurely on some hardware, doubling it to 4 seems to fix the issue
                if elapsed_time - current_time > 4:
                    return None
                await asyncio.sleep(self.sleep_tune)
        return self.query_reply_data.get(
            PrivateConstants.ANALOG_MAPPING_RESPONSE)

latch example not working?

i was trying to use set_analog_latch, but its didn't work.. i took a copy/paste of the wiki example still no luck.

can anyone confirm the analog latch is working correctly ?

incompatible with pyserial==3.0

I have to pin the version of pyserial to 2.7. Otherwise, this error occurs:

Initializing Arduino - Please wait... Traceback (most recent call last):
  File "example.py", line 9, in <module>
    board = PyMata3()
  File "/Users/lukeorland/.virtualenvs/electron-sprints/lib/python3.5/site-packages/pymata_aio/pymata3.py", line 59, in __init__
    self.core.start()
  File "/Users/lukeorland/.virtualenvs/electron-sprints/lib/python3.5/site-packages/pymata_aio/pymata_core.py", line 268, in start
    self.log_output)
  File "/Users/lukeorland/.virtualenvs/electron-sprints/lib/python3.5/site-packages/pymata_aio/pymata_serial.py", line 50, in __init__
    writeTimeout=1)
TypeError: __init__() got an unexpected keyword argument 'writeTimeout'

pymata-aio version 2.8

how to install on raspberry pi?

Hi, I'm looking for a way to control an Arduino Uno from a Raspberry Pi using Python 3.

Firstly, is pymata-aio the right way to do this?

Secondly, how to get it working? I couldn't find any instructions so I tried the following:

git clone https://github.com/tino/pymata-aio
cd pymata-aio
sudo python setup.py build
sudo python setup.py install

It gave a ton of error messages.

Beginner instructions please.

Dropping commands after console input

We were trying to make a music example, but ran into more issues with dropped messages. In the code below after getting a character from the user (using either input or msvcrt.getwch()) we need to do 2 things to get a message to send to the board. We need to wait like 100ms and we have to send the command twice. If we send it once it gets killed before the command gets to the board. If we don't add a sleep then nothing ever sends to the board. Any thoughts on where the messages die. This is the same issue we had with the time.sleep() commands. I'm sure it's a complex event loop issue within asyncio, but with a little guidance I'm happy to help investigate. Anywhere here is the example code we were trying to add. The code below works totally fine, but I hate having to send a command twice and saying to students "that's just how you have to do it". Is there another way to get input from the console and not wreck the ship?

Hopefully you'll like this example btw...

    #!/usr/bin/python
    """
    Example of playing notes from the keyboard
    """

    from pymata_aio.pymata3 import PyMata3
    from pymata_aio.constants import Constants

    board = PyMata3()

    BUZZER_PIN = 9
    NOTE_C4 = 262
    NOTE_D4 = 294
    NOTE_E4 = 330
    NOTE_F4 = 349
    NOTE_G4 = 392
    NOTE_A4 = 440
    NOTE_B4 = 494
    NOTE_C5 = 523
    NOTE_D5 = 587
    NOTE_E5 = 659
    NOTE_F5 = 698


    def setup():
        board.set_pin_mode(BUZZER_PIN, Constants.OUTPUT)  # configures the buzzerPin as an OUTPUT


    def loop():
        key = input("Enter a key in the range asdfghjkl;' to play a note (Space to stop, x to exit) ")
        for i in range(2):  # Send the command twice
            board.sleep(0.1)  # Add a delay before each send
            if key == "a":
                board.play_tone(BUZZER_PIN, Constants.TONE_TONE, NOTE_C4, None)
            elif key == "s":
                board.play_tone(BUZZER_PIN,Constants.TONE_TONE, NOTE_D4, None)
            elif key == "d":
                board.play_tone(BUZZER_PIN,Constants.TONE_TONE, NOTE_E4, None)
            elif key == "f":
                board.play_tone(BUZZER_PIN,Constants.TONE_TONE, NOTE_F4, None)
            elif key == "g":
                board.play_tone(BUZZER_PIN,Constants.TONE_TONE, NOTE_G4, None)
            elif key == "h":
                board.play_tone(BUZZER_PIN,Constants.TONE_TONE, NOTE_A4, None)
            elif key == "j":
                board.play_tone(BUZZER_PIN,Constants.TONE_TONE, NOTE_B4, None)
            elif key == "k":
                board.play_tone(BUZZER_PIN,Constants.TONE_TONE, NOTE_C5, None)
            elif key == "l":
                board.play_tone(BUZZER_PIN,Constants.TONE_TONE, NOTE_D5, None)
            elif key == ";":
                board.play_tone(BUZZER_PIN,Constants.TONE_TONE, NOTE_E5, None)
            elif key == "'":
                board.play_tone(BUZZER_PIN,Constants.TONE_TONE, NOTE_F5, None)
            elif key == " ":
                board.play_tone(BUZZER_PIN,Constants.TONE_NO_TONE, 0, 0)
            elif key == "x":
                board.shutdown()
                exit(0)
            else:
                print("Unknown key")
                break

    if __name__ == "__main__":
        setup()
        while True:
            loop()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.