mryslab / pymata-express Goto Github PK
View Code? Open in Web Editor NEWA Pure Python Asyncio Arduino Firmata Client
Home Page: https://mryslab.github.io/pymata-express/
License: GNU Affero General Public License v3.0
A Pure Python Asyncio Arduino Firmata Client
Home Page: https://mryslab.github.io/pymata-express/
License: GNU Affero General Public License v3.0
Hi again,
Whilst waiting for firmata, I've been playing around with firmata express on the mega, and I'm quite impressed. Wondered, if adapting it for the due would be doable as well as firmataplus?
I wonder whether the faster clock on the atmel would make firmataexpress even "expresser".
Second typo on https://mryslab.github.io/pymata-express/examples/
you wrote retrieve_capbaility_report
edit: I would also include an example for the polling function as it is not clear how to implement. for instance in the sonar example. How to poll the sonar, instead of have it stream
I installed pymata-express on my iMac in a virtual env. I installed the Arduino firmware onto an Arduino Mega2560 (R3) and tried running an example.
$ python retrieve_capability_report.py
This didn't work as expected.
The documentation states:
By accepting the defaults, PymataExpress will attempt its auto-discovery procedures to locate and connect to an Arduino. This assumes that you have the FirmataExpress sketch uploaded to the Arduino.
when I run the example program I get:
$ python pymata-express/examples/retrieve_capability_report.py
Pymata Express Version 1.00
Copyright (c) 2018-2019 Alan Yorinks All rights reserved.
Opening all potential serial ports...
/dev/cu.usbserial-AH06VXD3
/dev/cu.usbmodem146701
Waiting 4 seconds(arduino_wait) for Arduino devices to reset...
Searching for an Arduino configured with an arduino_instance = 1
and it just hangs there so I have to kill the program with Ctrl+C.
I added the com_port parameter to the initialization and it worked just fine:
# instantiate pymata_express
board = PymataExpress(com_port='/dev/cu.usbmodem146701')
Something in the default initialization is not working on macOS.
Thanks for all the work on the pymata libraries.
Let me know if you need me to test anything.
DHT22 support works without issue, but there may be an issue for the DHT11. This is under investigation.
Hi,
I 've found a litte bug...
The timestamp for analog_read() is wrong.
line: self.digital_pins[pin].event_time = time_stamp
should be: self.analog_pins[pin].event_time = time_stamp
at
async def _analog_message(self, data):
"""
This is a private message handler method.
It is a message handler for analog messages.
:param data: message data
"""
pin = data[0]
value = (data[PrivateConstants.MSB] << 7) + data[PrivateConstants.LSB]
# only report when there is a change in value
differential = abs(value - self.analog_pins[pin].current_value)
if differential >= self.analog_pins[pin].differential:
self.analog_pins[pin].current_value = value
time_stamp = time.time()
self.digital_pins[pin].event_time = time_stamp
# append pin number, pin value, and pin type to return value and return as a list
message = [pin, value, PrivateConstants.ANALOG, time_stamp]
Hello again.
I am at point of the developement where I need to test parts of my code without a physical device connected to it.
I would like to be able to instantiate the PymataExpress class without starting it.
I found the autostart=False option, but in the classes init, it will try to connect to the USB port.
I have moved that part out of init and implemented the same mechanism as you used for the , autostart=False
I was wondering if this can become a standard part of the library, or if you have some other better ideas of what I need to do.
Thank you again for the great library and for you time.
Hi, me again,
I'm back working on my little robot and had a question regarding the difference between digital_output & digital_pin_ouput.
If you have time, you should detail the example page
https://mryslab.github.io/pymata-express/examples/
detailing the different commands. I know it's quite some work, but looking at the api is not enough to understand the difference between these two option for instance.
Thanks in advance
W
In the documentation, I think there's a typo https://mryslab.github.io/pymata-express/install_pymata_express/
You've typed pip install python-express
instead of pip install pymata-express
Ping time needs to be adjusted to a longer delay.
Me again, this is just a feature that could be helpful. Basically, a loop that checks if the arduino is connect and reconnects if it has been disconnected. I'll try to integrate this feature, but you know your code better than I do.
Hello again,
Have a question. Say I set some pins as digital outputs and some others as digital inputs.
Is there a way to retirieve what pin is set how?
Tried to search the API documentation but the only solution I can think is to loop get_pin_state with all ports.
Let me know is something else is available or can be easily implemented?
Thank you.
Hi,
Maybe I doing something wrong, but when trying to compile I got:
Board Mega2560
IDE 1.8.12
firmataexpress version 1.1.1
/var/folders/q0/0j0022zd5l94lxs6r282q1t80000gn/T//ccP9Lor6.ltrans0.ltrans.o: In function
sysexCallback(unsigned char, unsigned char, unsigned char*)':
:(.text+0x2b4e): undefined reference to operator new(unsigned int)' <artificial>:(.text+0x2bec): undefined reference to
operator new(unsigned int)'
:(.text+0x2c64): undefined reference to operator new(unsigned int)' collect2: error: ld returned 1 exit status exit status 1 Error compiling for board Arduino Mega or Mega 2560.
The code needs to be made compatible with FirmataExpress version 1.2
Apologies, I opened this by mistake and cannot delete it.
Hello.
I have some problem with a few functions of this library.
By example, if I want to do something as trivial as getting the state of a button.
Initializing the pin like that with DPIN_BUTTON = 2 and arduino_button_pressed(data) as the callback function:
await board.set_pin_mode_digital_input(DPIN_BUTTON, callback = arduino_button_pressed)
Executing the code and pushing the button never execute the callback function.
Then if I try to read the pin directly with await board.digital_read(DPIN_BUTTON)
, the value is always 0.
And finally if I try to get the state of the button to know if it is configured as an INPUT with state = await board.get_pin_state(DPIN_BUTTON)
, the execution freezes on that instruction...
Maybe I'm doing something wrong, but I don't know what. So your help is more than welcome. Thank you.
ps : I'm using FirmataExpress 1.1.4 on an Arduino UNO and pymata-express 1.18 on Python 3.8.5
Hi,
first, I hope you don't mind I included your component for Home Assistant Gentoo Overlay.
I don't use your component myself, just noticed an error during regular compiliation tests, so I just wanted you to know that in Pypi's SDIST some files, at least one, are/is missing:
* Package: dev-python/pymata-express-1.17
* Repository: HomeAssistantRepository
* Maintainer: [email protected]
* Upstream: [email protected]
* USE: abi_x86_64 amd64 elibc_glibc kernel_linux python_targets_python3_8 test userland_GNU
* FEATURES: network-sandbox preserve-libs sandbox userpriv usersandbox
>>> Unpacking source...
>>> Unpacking pymata-express-1.17.tar.gz to /var/tmp/portage/dev-python/pymata-express-1.17/work
>>> Source unpacked in /var/tmp/portage/dev-python/pymata-express-1.17/work
>>> Preparing source in /var/tmp/portage/dev-python/pymata-express-1.17/work/pymata-express-1.17 ...
>>> Source prepared.
>>> Configuring source in /var/tmp/portage/dev-python/pymata-express-1.17/work/pymata-express-1.17 ...
>>> Source configured.
>>> Compiling source in /var/tmp/portage/dev-python/pymata-express-1.17/work/pymata-express-1.17 ...
* python3_8: running distutils-r1_run_phase distutils-r1_python_compile
python3.8 setup.py build -j 10
Traceback (most recent call last):
File "setup.py", line 3, in <module>
with open('pypi_desc.md', "r") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'pypi_desc.md'
* ERROR: dev-python/pymata-express-1.17::HomeAssistantRepository failed (compile phase):
* (no error message)
*
The github archive compiles fine, for now I changed the SRC_URI to Github.
Perhpas this should be fixed.
Thanks a lot.
Is there any chance to read 1-wire-sensors like Dallas DS18B20 or other compatible sensors ?
DHT is very special an not multi sensor (serial bus system with multiple sensors)
Examples will be modified to have the same set as pymata4
Hello,
Please consider the following code:
import asyncio
from pymata_express.pymata_express import PymataExpress
async def setup(board):
await board.set_pin_mode_digital_input_pullup(5,callback=my_callback)
await board.set_pin_mode_digital_input_pullup(9,callback=my_callback)
await board.set_pin_mode_digital_input_pullup(8,callback=my_callback)
await board.set_pin_mode_digital_input_pullup(7,callback=my_callback)
async def my_callback(data):
mode, pin_number,pin_state,timestamp=data
print("-------------------------")
print(mode,pin_number,pin_state,timestamp)
print("-------------------------")
if __name__ == "__main__":
board = PymataExpress()
loop = asyncio.get_event_loop()
loop.create_task(setup(board))
loop.run_forever()
When I run this code and short the pins to ground nothing happens.
If I change the pins to actual digital pins, the code works as expected.
I know it's common to use the analog pins as digital but the arduino allows for it and in the current application this cannot be avoided.
If I run a similar code direcltly on arduino it works as expeced.
I have used the latest firmata-express firmware and pymata-express lib at the time of this writting.
Please adivse if a workaround can be done.
Thank you.
In the documentation we speak of milliseconds while we should speak of microseconds.
How to have 540ms in a cycle of 20ms (50Hz) ;-) ?
https://htmlpreview.github.io/?https://github.com/MrYsLab/pymata-express/blob/master/html/pymata_express/index.html#pymata_express.pymata_express.PymataExpress.set_pin_mode_servo
If the keep alive method is invoked, it remains in a loop and does not exit. This fieature should not be used until this issue is resolved.
Is there any chance to detect the board hardware, where pymata express is running ?
e.g. Robot Hat MM1, Arduino UNO, Arduino NANO, Arduino Micro
I'm searching for an identifier to select automatic name to pin mapping :-)
First of all, I need to say how great this project is. Thank you for all your good work.
I would like to report an issue I am having.
Please consider the following code:
import asyncio
from pymata_express.pymata_express import PymataExpress
async def enableLed(data):
print("-------------------------")
print(data)
print("-------------------------")
async def setup(board):
await board.set_pin_mode_digital_input_pullup(40,enableLed)
await board.set_pin_mode_digital_input_pullup(41,enableLed)
await board.set_pin_mode_digital_input_pullup(42,enableLed)
await board.set_pin_mode_digital_input_pullup(43,enableLed)
await board.set_pin_mode_digital_input_pullup(44,enableLed)
await board.set_pin_mode_digital_input_pullup(45,enableLed)
await board.set_pin_mode_digital_input_pullup(46,enableLed)
await board.set_pin_mode_digital_input_pullup(47,enableLed)
board = PymataExpress(com_port="COM9",arduino_wait=1)
loop=asyncio.get_event_loop()
loop.create_task(setup(board))
loop.run_forever()
This is the output of the callback when manipulating only one input (#41):
Pymata Express Version 1.11
Copyright (c) 2018-2019 Alan Yorinks All rights reserved.
Opening COM9 ...
Waiting 1 seconds for the Arduino To Reset.
Arduino found and connected to COM9
Retrieving Arduino Firmware ID...
Arduino Firmware ID: 2.5 FirmataExpress.ino
Auto-discovery complete. Found 70 Digital Pins and 16 Analog Pins
-------------------------
[0, 40, 1, 1586976240.831113]
-------------------------
-------------------------
[0, 40, 1, 1586976240.8779788]
-------------------------
-------------------------
[0, 41, 1, 1586976240.8779788]
-------------------------
-------------------------
[0, 40, 1, 1586976240.8779788]
-------------------------
-------------------------
[0, 41, 1, 1586976240.8779788]
-------------------------
-------------------------
[0, 40, 1, 1586976240.9319274]
-------------------------
-------------------------
[0, 41, 1, 1586976240.9319274]
-------------------------
-------------------------
[0, 42, 1, 1586976240.9319274]
-------------------------
-------------------------
[0, 40, 1, 1586976240.9319274]
-------------------------
-------------------------
[0, 41, 1, 1586976240.9319274]
-------------------------
-------------------------
[0, 42, 1, 1586976240.9319274]
-------------------------
-------------------------
[0, 40, 1, 1586976240.9788237]
-------------------------
-------------------------
[0, 41, 1, 1586976240.9788237]
-------------------------
-------------------------
[0, 42, 1, 1586976240.9788237]
-------------------------
-------------------------
[0, 43, 1, 1586976240.9788237]
-------------------------
-------------------------
[0, 40, 1, 1586976240.9788237]
-------------------------
-------------------------
[0, 41, 1, 1586976240.9788237]
-------------------------
-------------------------
[0, 42, 1, 1586976240.9788237]
-------------------------
-------------------------
[0, 43, 1, 1586976240.9788237]
-------------------------
-------------------------
[0, 40, 1, 1586976241.0320945]
-------------------------
-------------------------
[0, 41, 1, 1586976241.0320945]
-------------------------
-------------------------
[0, 42, 1, 1586976241.0320945]
-------------------------
-------------------------
[0, 43, 1, 1586976241.0320945]
-------------------------
-------------------------
[0, 44, 1, 1586976241.0320945]
-------------------------
-------------------------
[0, 40, 1, 1586976241.0320945]
-------------------------
-------------------------
[0, 41, 1, 1586976241.0320945]
-------------------------
-------------------------
[0, 42, 1, 1586976241.0320945]
-------------------------
-------------------------
[0, 43, 1, 1586976241.0320945]
-------------------------
-------------------------
[0, 44, 1, 1586976241.0320945]
-------------------------
-------------------------
[0, 40, 1, 1586976241.0632772]
-------------------------
-------------------------
[0, 41, 1, 1586976241.0632772]
-------------------------
-------------------------
[0, 42, 1, 1586976241.0632772]
-------------------------
-------------------------
[0, 43, 1, 1586976241.0632772]
-------------------------
-------------------------
[0, 44, 1, 1586976241.0632772]
-------------------------
-------------------------
[0, 45, 1, 1586976241.0632772]
-------------------------
-------------------------
[0, 40, 1, 1586976241.0632772]
-------------------------
-------------------------
[0, 41, 1, 1586976241.0632772]
-------------------------
-------------------------
[0, 42, 1, 1586976241.0632772]
-------------------------
-------------------------
[0, 43, 1, 1586976241.0632772]
-------------------------
-------------------------
[0, 44, 1, 1586976241.0632772]
-------------------------
-------------------------
[0, 45, 1, 1586976241.0632772]
-------------------------
-------------------------
[0, 40, 1, 1586976241.0979123]
-------------------------
-------------------------
[0, 41, 1, 1586976241.0979123]
-------------------------
-------------------------
[0, 42, 1, 1586976241.0979123]
-------------------------
-------------------------
[0, 43, 1, 1586976241.0979123]
-------------------------
-------------------------
[0, 44, 1, 1586976241.0979123]
-------------------------
-------------------------
[0, 45, 1, 1586976241.0979123]
-------------------------
-------------------------
[0, 46, 1, 1586976241.0979123]
-------------------------
-------------------------
[0, 40, 1, 1586976241.0979123]
-------------------------
-------------------------
[0, 41, 1, 1586976241.0979123]
-------------------------
-------------------------
[0, 42, 1, 1586976241.0979123]
-------------------------
-------------------------
[0, 43, 1, 1586976241.0979123]
-------------------------
-------------------------
[0, 44, 1, 1586976241.0979123]
-------------------------
-------------------------
[0, 45, 1, 1586976241.0979123]
-------------------------
-------------------------
[0, 46, 1, 1586976241.0979123]
-------------------------
-------------------------
[0, 40, 1, 1586976241.144719]
-------------------------
-------------------------
[0, 41, 1, 1586976241.144719]
-------------------------
-------------------------
[0, 42, 1, 1586976241.144719]
-------------------------
-------------------------
[0, 43, 1, 1586976241.145777]
-------------------------
-------------------------
[0, 44, 1, 1586976241.145777]
-------------------------
-------------------------
[0, 45, 1, 1586976241.145777]
-------------------------
-------------------------
[0, 46, 1, 1586976241.145777]
-------------------------
-------------------------
[0, 47, 1, 1586976241.145777]
-------------------------
-------------------------
[0, 40, 1, 1586976241.145777]
-------------------------
-------------------------
[0, 41, 1, 1586976241.1467254]
-------------------------
-------------------------
[0, 42, 1, 1586976241.1467254]
-------------------------
-------------------------
[0, 43, 1, 1586976241.1467254]
-------------------------
-------------------------
[0, 44, 1, 1586976241.1467254]
-------------------------
-------------------------
[0, 45, 1, 1586976241.1467254]
-------------------------
-------------------------
[0, 46, 1, 1586976241.1467254]
-------------------------
-------------------------
[0, 47, 1, 1586976241.1467254]
-------------------------
-------------------------
[0, 40, 1, 1586976252.4558365]
-------------------------
-------------------------
[0, 41, 0, 1586976252.4558365]
-------------------------
-------------------------
[0, 42, 1, 1586976252.4558365]
-------------------------
-------------------------
[0, 43, 1, 1586976252.4558365]
-------------------------
-------------------------
[0, 44, 1, 1586976252.4558365]
-------------------------
-------------------------
[0, 45, 1, 1586976252.4558365]
-------------------------
-------------------------
[0, 46, 1, 1586976252.4558365]
-------------------------
-------------------------
[0, 47, 1, 1586976252.4558365]
-------------------------
-------------------------
[0, 40, 1, 1586976252.5561347]
-------------------------
-------------------------
[0, 41, 1, 1586976252.5561347]
-------------------------
-------------------------
[0, 42, 1, 1586976252.5561347]
-------------------------
-------------------------
[0, 43, 1, 1586976252.5561347]
-------------------------
-------------------------
[0, 44, 1, 1586976252.5561347]
-------------------------
-------------------------
[0, 45, 1, 1586976252.5561347]
-------------------------
-------------------------
[0, 46, 1, 1586976252.5561347]
-------------------------
-------------------------
[0, 47, 1, 1586976252.5561347]
-------------------------
-------------------------
[0, 40, 1, 1586976255.0847926]
-------------------------
-------------------------
[0, 41, 0, 1586976255.0847926]
-------------------------
-------------------------
[0, 42, 1, 1586976255.0847926]
-------------------------
-------------------------
[0, 43, 1, 1586976255.0847926]
-------------------------
-------------------------
[0, 44, 1, 1586976255.0847926]
-------------------------
-------------------------
[0, 45, 1, 1586976255.0847926]
-------------------------
-------------------------
[0, 46, 1, 1586976255.0854497]
-------------------------
-------------------------
[0, 47, 1, 1586976255.0854497]
-------------------------
-------------------------
[0, 40, 1, 1586976263.5176861]
-------------------------
-------------------------
[0, 41, 1, 1586976263.5176861]
-------------------------
-------------------------
[0, 42, 1, 1586976263.5176861]
-------------------------
-------------------------
[0, 43, 1, 1586976263.5176861]
-------------------------
-------------------------
[0, 44, 1, 1586976263.5176861]
-------------------------
-------------------------
[0, 45, 1, 1586976263.5176861]
-------------------------
-------------------------
[0, 46, 1, 1586976263.5176861]
-------------------------
-------------------------
[0, 47, 1, 1586976263.5176861]
-------------------------
-------------------------
[0, 40, 1, 1586976265.5717053]
-------------------------
-------------------------
[0, 41, 0, 1586976265.5717053]
-------------------------
-------------------------
[0, 42, 1, 1586976265.5717053]
-------------------------
-------------------------
[0, 43, 1, 1586976265.5717053]
-------------------------
-------------------------
[0, 44, 1, 1586976265.5717053]
-------------------------
-------------------------
[0, 45, 1, 1586976265.5717053]
-------------------------
-------------------------
[0, 46, 1, 1586976265.5717053]
-------------------------
-------------------------
[0, 47, 1, 1586976265.5717053]
-------------------------
-------------------------
[0, 40, 1, 1586976266.9294171]
-------------------------
-------------------------
[0, 41, 1, 1586976266.9294171]
-------------------------
-------------------------
[0, 42, 1, 1586976266.9294171]
-------------------------
-------------------------
[0, 43, 1, 1586976266.9294171]
-------------------------
-------------------------
[0, 44, 1, 1586976266.9294171]
-------------------------
-------------------------
[0, 45, 1, 1586976266.9294171]
-------------------------
-------------------------
[0, 46, 1, 1586976266.9294171]
-------------------------
-------------------------
[0, 47, 1, 1586976266.9294171]
-------------------------
-------------------------
[0, 40, 1, 1586976267.58003]
-------------------------
-------------------------
[0, 41, 0, 1586976267.58003]
-------------------------
-------------------------
[0, 42, 1, 1586976267.58003]
-------------------------
-------------------------
[0, 43, 1, 1586976267.58003]
-------------------------
-------------------------
[0, 44, 1, 1586976267.58003]
-------------------------
-------------------------
[0, 45, 1, 1586976267.58003]
-------------------------
-------------------------
[0, 46, 1, 1586976267.58003]
-------------------------
-------------------------
[0, 47, 1, 1586976267.58003]
-------------------------
-------------------------
[0, 40, 1, 1586976268.8140144]
-------------------------
-------------------------
[0, 41, 1, 1586976268.8140144]
-------------------------
-------------------------
[0, 42, 1, 1586976268.8140144]
-------------------------
-------------------------
[0, 43, 1, 1586976268.8150232]
-------------------------
-------------------------
[0, 44, 1, 1586976268.8150232]
-------------------------
-------------------------
[0, 45, 1, 1586976268.8150232]
-------------------------
-------------------------
[0, 46, 1, 1586976268.8150232]
-------------------------
-------------------------
[0, 47, 1, 1586976268.8150232]
-------------------------
-------------------------
[0, 40, 1, 1586976269.2891953]
-------------------------
-------------------------
[0, 41, 0, 1586976269.2891953]
-------------------------
-------------------------
[0, 42, 1, 1586976269.2891953]
-------------------------
-------------------------
[0, 43, 1, 1586976269.2891953]
-------------------------
-------------------------
[0, 44, 1, 1586976269.2891953]
-------------------------
-------------------------
[0, 45, 1, 1586976269.2901437]
-------------------------
-------------------------
[0, 46, 1, 1586976269.2901437]
-------------------------
-------------------------
[0, 47, 1, 1586976269.2901437]
-------------------------
-------------------------
[0, 40, 1, 1586976269.8172002]
-------------------------
-------------------------
[0, 41, 1, 1586976269.8172002]
-------------------------
-------------------------
[0, 42, 1, 1586976269.8172002]
-------------------------
-------------------------
[0, 43, 1, 1586976269.8172002]
-------------------------
-------------------------
[0, 44, 1, 1586976269.8172002]
-------------------------
-------------------------
[0, 45, 1, 1586976269.8172002]
-------------------------
-------------------------
[0, 46, 1, 1586976269.8172002]
-------------------------
-------------------------
[0, 47, 1, 1586976269.8172002]
-------------------------
-------------------------
[0, 40, 1, 1586976270.215533]
-------------------------
-------------------------
[0, 41, 0, 1586976270.215533]
-------------------------
-------------------------
[0, 42, 1, 1586976270.215533]
-------------------------
-------------------------
[0, 43, 1, 1586976270.215533]
-------------------------
-------------------------
[0, 44, 1, 1586976270.215533]
-------------------------
-------------------------
[0, 45, 1, 1586976270.215533]
-------------------------
-------------------------
[0, 46, 1, 1586976270.215533]
-------------------------
-------------------------
[0, 47, 1, 1586976270.215533]
-------------------------
-------------------------
[0, 40, 1, 1586976270.6044936]
-------------------------
-------------------------
[0, 41, 1, 1586976270.6044936]
-------------------------
-------------------------
[0, 42, 1, 1586976270.6044936]
-------------------------
-------------------------
[0, 43, 1, 1586976270.6044936]
-------------------------
-------------------------
[0, 44, 1, 1586976270.6044936]
-------------------------
-------------------------
[0, 45, 1, 1586976270.6044936]
-------------------------
-------------------------
[0, 46, 1, 1586976270.6044936]
-------------------------
-------------------------
[0, 47, 1, 1586976270.6044936]
-------------------------
-------------------------
[0, 40, 1, 1586976270.92138]
-------------------------
-------------------------
[0, 41, 0, 1586976270.92138]
-------------------------
-------------------------
[0, 42, 1, 1586976270.92138]
-------------------------
-------------------------
[0, 43, 1, 1586976270.92138]
-------------------------
-------------------------
[0, 44, 1, 1586976270.92138]
-------------------------
-------------------------
[0, 45, 1, 1586976270.92138]
-------------------------
-------------------------
[0, 46, 1, 1586976270.92138]
-------------------------
-------------------------
[0, 47, 1, 1586976270.92138]
-------------------------
-------------------------
[0, 40, 1, 1586976271.2975526]
-------------------------
-------------------------
[0, 41, 1, 1586976271.2975526]
-------------------------
-------------------------
[0, 42, 1, 1586976271.2985504]
-------------------------
-------------------------
[0, 43, 1, 1586976271.2985504]
-------------------------
-------------------------
[0, 44, 1, 1586976271.2985504]
-------------------------
-------------------------
[0, 45, 1, 1586976271.2985504]
-------------------------
-------------------------
[0, 46, 1, 1586976271.2985504]
-------------------------
-------------------------
[0, 47, 1, 1586976271.2985504]
-------------------------
-------------------------
[0, 40, 1, 1586976271.6232586]
-------------------------
-------------------------
[0, 41, 0, 1586976271.6232586]
-------------------------
-------------------------
[0, 42, 1, 1586976271.6232586]
-------------------------
-------------------------
[0, 43, 1, 1586976271.6232586]
-------------------------
-------------------------
[0, 44, 1, 1586976271.6232586]
-------------------------
-------------------------
[0, 45, 1, 1586976271.6232586]
-------------------------
-------------------------
[0, 46, 1, 1586976271.6232586]
-------------------------
-------------------------
[0, 47, 1, 1586976271.6232586]
-------------------------
-------------------------
[0, 40, 1, 1586976272.0951483]
-------------------------
-------------------------
[0, 41, 1, 1586976272.0951483]
-------------------------
-------------------------
[0, 42, 1, 1586976272.0951483]
-------------------------
-------------------------
[0, 43, 1, 1586976272.0951483]
-------------------------
-------------------------
[0, 44, 1, 1586976272.096143]
-------------------------
-------------------------
[0, 45, 1, 1586976272.096143]
-------------------------
-------------------------
[0, 46, 1, 1586976272.096143]
-------------------------
-------------------------
[0, 47, 1, 1586976272.096143]
-------------------------
-------------------------
[0, 40, 1, 1586976272.4087172]
-------------------------
-------------------------
[0, 41, 0, 1586976272.4087172]
-------------------------
-------------------------
[0, 42, 1, 1586976272.4087172]
-------------------------
-------------------------
[0, 43, 1, 1586976272.4087172]
-------------------------
-------------------------
[0, 44, 1, 1586976272.4087172]
-------------------------
-------------------------
[0, 45, 1, 1586976272.4087172]
-------------------------
-------------------------
[0, 46, 1, 1586976272.4087172]
-------------------------
-------------------------
[0, 47, 1, 1586976272.4087172]
-------------------------
-------------------------
[0, 40, 1, 1586976272.8241725]
-------------------------
-------------------------
[0, 41, 1, 1586976272.8241725]
-------------------------
-------------------------
[0, 42, 1, 1586976272.8241725]
-------------------------
-------------------------
[0, 43, 1, 1586976272.8241725]
-------------------------
-------------------------
[0, 44, 1, 1586976272.8241725]
-------------------------
-------------------------
[0, 45, 1, 1586976272.8241725]
-------------------------
-------------------------
[0, 46, 1, 1586976272.8241725]
-------------------------
-------------------------
[0, 47, 1, 1586976272.8241725]
-------------------------
-------------------------
[0, 40, 1, 1586976273.6146002]
-------------------------
-------------------------
[0, 41, 0, 1586976273.6146002]
-------------------------
-------------------------
[0, 42, 1, 1586976273.6154034]
-------------------------
-------------------------
[0, 43, 1, 1586976273.6154034]
-------------------------
-------------------------
[0, 44, 1, 1586976273.6154034]
-------------------------
-------------------------
[0, 45, 1, 1586976273.6154034]
-------------------------
-------------------------
[0, 46, 1, 1586976273.6154034]
-------------------------
-------------------------
[0, 47, 1, 1586976273.6154034]
-------------------------
-------------------------
[0, 40, 1, 1586976275.9383821]
-------------------------
-------------------------
[0, 41, 1, 1586976275.9383821]
-------------------------
-------------------------
[0, 42, 1, 1586976275.9383821]
-------------------------
-------------------------
[0, 43, 1, 1586976275.9383821]
-------------------------
-------------------------
[0, 44, 1, 1586976275.9383821]
-------------------------
-------------------------
[0, 45, 1, 1586976275.9383821]
-------------------------
-------------------------
[0, 46, 1, 1586976275.9383821]
-------------------------
-------------------------
[0, 47, 1, 1586976275.9383821]
-------------------------
As seen in the above output although the pins are reported correctly (only pin #41 is changing), all of them trigger the callback. Also the pin is reported as a digital inpt (0) instead of digital input pullup (11).
Thank you again for your time and efforts.
I don't know how to connect to the motor, and what is the relationship between the pin parameter in the set_pin_mode_stepper function and the motor connection?
thanks!
I just want to be sure I'm not missing something here.
I'm trying to drive two step motors directly from pymata-express, using a single arduino mega-pro, connected over a serial-usb port
I'm using the StandardFirmata to digital write step pulses directly, without step-motor extensions.
The step-motor driver is set to 400 steps per revolution. It takes me ~2000 ms to perform 2000 steps (5 revolutions, implying 1ms per step) when driving a single motor, each step consisting of 2 digital writes (LOW and HIGH). However driving two motors doubles the time it takes to complete the revolution, very much to my surprise.
The reason I'm surprised is that I expected digital writes should, given an 8 core core-i7 10875H CPU, quickly yield once the write was sent to the Arduino, meaning my the code should be able to allow the other digital writes (to the other step motor) to at least partially execute, as local execution time are expected to be much faster than over-the-(serial)-wire communication
So my questions are
I'm guessing there's a real constraint that's preventing concurrently accessing the same serial port, but I didn't expect a 2X slowdown as a result of trying to drive 2 step motors.
Sample code:
import asyncio
import datetime
import logging
from pymata_express.pymata_express import PymataExpress
__MOTOR_1_POWER_PIN = 27
__MOTOR_1_DIRECTION_PIN = 29
__MOTOR_1_STEP_PIN = 31
__MOTOR_2_POWER_PIN = 17
__MOTOR_2_DIRECTION_PIN = 19
__MOTOR_2_STEP_PIN = 21
__LOW = 0
__HIGH = 1
__STEPS = 400 * 5
__ITERATIONS = 3
logging.basicConfig(level=logging.DEBUG)
async def setup_motor_pins(board: PymataExpress, power: int, direction: int, step: int) -> None:
for pin in [power, direction, step]:
await board.set_pin_mode_digital_output(pin)
for pin in [direction, power]:
await board.digital_pin_write(pin, __HIGH)
async def drive_motors(board: PymataExpress, step1: int, step2: int):
for step in range(0, __STEPS):
t1 = asyncio.create_task(motor_step(board, step1))
t2 = asyncio.create_task(motor_step(board, step2))
await asyncio.gather(t1, t2)
async def motor_step(board: PymataExpress, pin: int) -> None:
await board.digital_pin_write(pin, __LOW)
await board.digital_pin_write(pin, __HIGH)
async def main(board: PymataExpress) -> None:
await setup_motor_pins(board, __MOTOR_1_POWER_PIN, __MOTOR_1_DIRECTION_PIN, __MOTOR_1_STEP_PIN)
await setup_motor_pins(board, __MOTOR_2_POWER_PIN, __MOTOR_2_DIRECTION_PIN, __MOTOR_2_STEP_PIN)
for iteration in range(0, __ITERATIONS):
start = datetime.datetime.now().timestamp()
await drive_motors(board, __MOTOR_1_STEP_PIN, __MOTOR_2_STEP_PIN)
end = datetime.datetime.now().timestamp()
print(f"{__STEPS} steps took {(end - start)} seconds to complete")
if __name__ == '__main__':
board: PymataExpress = PymataExpress(com_port='/dev/ttyUSB1', baud_rate=57600)
asyncio.run(main(board), debug=True)
Hello,
do we have to define each function all the time to program something. I thought that all those functions were still programmed when we import pymata-express at the top of a program. !! ??? Can we use also the way that we program with python3 ? Excuse me but I'm a newbee with python. I tried to use pymata because I was not able to program to read a distance sensor (Ultrasonic). If I want to put a condition (if) to brighten a led ex: on digital port 13 , how can I transfer the value of the data received (I mean the distance) if I want to activate something if the distance in cm is equal or shorter than 4 cm ? A help should be very appreciate. Thank you in advance!
distance_sensor.py.txt
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.