-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
完善Arduino插件 #16
Comments
开发引导前端Scratch插件CodeLab Adapter extension |
为了完善的Arduino插件,我们需要一下几点(有遗漏,欢迎补充):
|
这样就清楚了 |
@bilikyar 关于第三点,我觉得使用英文就行了,英语在印度使用广泛。 |
好的,那现在的主要问题就是自动烧录固件了。 |
@wwj718 我在ubuntu 18.04 上使用下面的方式启动插件的时候,adapter直接崩溃,你在打包pymata_aio 的时候进行测试过吗? import zmq
import subprocess
import pathlib
import platform
import time
import threading
from time import sleep
from codelab_adapter import settings
from codelab_adapter.core_extension import Extension
from pymata_aio.pymata3 import PyMata3
from pymata_aio.constants import Constants
class arduinoExtension(Extension):
def __init__(self):
name = type(self).__name__
super().__init__(name)
board = PyMata3() |
Ubuntu上自动烧录固件功能已完成,现在需要跟之前的插件进行整合。 |
@bilikyar 我到ubuntu下测试一下,我在mac和windows下测试过 |
@bilikyar 我刚在ubuhntu16.04 64bit下测试,
是正常的 board = PyMata3()触发了错误:
你可以在adapter之外先测试 |
adapter之外運行是沒問題的 |
@bilikyar 我在adapter之外运行也是一样的错误呢 |
现在的问题说明: 1.这是我目前的插件测试代码 import zmq
import subprocess
import pathlib
import platform
import time
import threading
import os
from time import sleep
from pymata_aio.pymata3 import PyMata3
from pymata_aio.constants import Constants
from codelab_adapter.utils import ui_error
from codelab_adapter.core_extension import Extension
from codelab_adapter import settings
def get_python3_path():
# If it is not working, Please replace python3_path with your local python3 path. shell: which python3
if (platform.system() == "Darwin"):
# which python3
# 不如用PATH python
# 不确定
path = "/usr/local/bin/python3"
if platform.system() == "Windows":
path = "python3"
if platform.system() == "Linux":
path = "/usr/bin/python3"
return path
python3_path = get_python3_path()
class arduinoExtension(Extension):
def __init__(self):
name = type(self).__name__
super().__init__(name)
board = PyMata3()
BOARD_LED = 13
board.set_pin_mode(BOARD_LED, Constants.OUTPUT)
print("LED On")
board.digital_write(BOARD_LED, 1)
board.sleep(1.0)
print("LED Off")
board.digital_write(BOARD_LED, 0)
board.sleep(1.0)
def run(self):
pass
while self._running:
pass
export = arduinoExtension 2.通过命令行的方式运行adapter在ubuntu第一次启动插件,能运行成功,以下是成功信息: pymata_aio Version 2.30 Copyright (c) 2015-2018 Alan Yorinks All rights reserved.
Using COM Port:/dev/ttyACM0
Initializing Arduino - Please wait... 2019-05-29 14:49:28,756 - INFO - [socketio_server.py:293:background_task2] - - sub: arduinoExtension-30871
Arduino Firmware ID: 2.5 StandardFirmataPlus.ino
Auto-discovery complete. Found 20 Digital Pins and 6 Analog Pins
LED On
LED Off
2019-05-29 14:49:38,050 - DEBUG - [gui.py:380:_handle_extension_checkbox] - - extension checkbox:extension_arduino_nano is clicked; value:0
2019-05-29 14:49:38,050 - DEBUG - [core_extension.py:65:publish] - - publish: {'topic': '__control', 'payload': 'terminate', 'type': 'adapter'}
2019-05-29 14:49:38,051 - DEBUG - [socketio_server.py:253:background_task] - - sensor_sub recv: {'topic': '__control', 'payload': 'terminate', 'type': 'adapter'}
3.关闭插件,重开就会报以下错误,adapter自动关闭: pymata_aio Version 2.30 Copyright (c) 2015-2018 Alan Yorinks All rights reserved.
Using COM Port:/dev/ttyACM0
Initializing Arduino - Please wait... 2019-05-29 14:49:41,896 - INFO - [socketio_server.py:293:background_task2] - - sub: arduinoExtension-30825
_report_firmware() missing 1 required positional argument: 'sysex_data'
Shutting down ...
|
@bilikyar 比力 我猜和插件的加载机制有关,看起来是资源没有释放,我看看插件加载机制,稍后给你反馈 |
@zhouF96 你看下这个问题 |
@bilikyar 我刚才梳理过了插件的生命周期 : 勾选插件:
取消勾选: 将self.__running设置为false |
init(self):方法中应该只包含插件的基本信息,不占用端口资源等,与外界交互的逻辑部分/或有资源释放的部分应该写在run(self):方法下,run方法中,gui界面打勾的话,调用插件的run方法,并且将插件的self._running设置为true,不打勾的话,跳出self._running的循环,在循环后释放资源。 |
import zmq
import subprocess
import pathlib
import platform
import time
import threading
import os
from time import sleep
from pymata_aio.pymata3 import PyMata3
from pymata_aio.constants import Constants
from codelab_adapter.utils import ui_error
from codelab_adapter.core_extension import Extension
from codelab_adapter import settings
def get_python3_path():
# If it is not working, Please replace python3_path with your local python3 path. shell: which python3
if (platform.system() == "Darwin"):
# which python3
# 不如用PATH python
# 不确定
path = "/usr/local/bin/python3"
if platform.system() == "Windows":
path = "python3"
if platform.system() == "Linux":
path = "/usr/bin/python3"
return path
python3_path = get_python3_path()
class arduinoExtension(Extension):
def __init__(self):
name = type(self).__name__
super().__init__(name)
def run(self):
board = PyMata3()
BOARD_LED = 13
board.set_pin_mode(BOARD_LED, Constants.OUTPUT)
while self._running:
print("LED On")
board.digital_write(BOARD_LED, 1)
board.sleep(1.0)
print("LED Off")
board.digital_write(BOARD_LED, 0)
board.sleep(1.0)
export = arduinoExtension |
@zhouF96 Exception in thread 1559120970.4316733:
Traceback (most recent call last):
File "threading.py", line 916, in _bootstrap_inner
File "threading.py", line 864, in run
File "codelab_adapter/core_extension.py", line 92, in start_as_thread
File "/home/bilikyar/codelab_adapter/extensions/extension_arduino_nano.py", line 45, in run
board = PyMata3()
File "site-packages/pymata_aio/pymata3.py", line 67, in __init__
File "asyncio/events.py", line 694, in get_event_loop
File "asyncio/events.py", line 602, in get_event_loop
RuntimeError: There is no current event loop in thread '1559120970.4316733'.
2019-05-29 17:09:30,840 - INFO - [socketio_server.py:293:background_task2] - - sub: arduinoExtension-30843
|
@bilikyar 这样改的话就OK了,测试没问题,注意调用board.shutdown()方法解除对tty的占用并结束线程 import zmq
import subprocess
import pathlib
import platform
import time
import threading
import os
import asyncio
from time import sleep
from pymata_aio.pymata3 import PyMata3
from pymata_aio.constants import Constants
from codelab_adapter.utils import ui_error
from codelab_adapter.core_extension import Extension
from codelab_adapter import settings
from codelab_adapter.utils import threaded
def get_python3_path():
# If it is not working, Please replace python3_path with your local python3 path. shell: which python3
if (platform.system() == "Darwin"):
# which python3
# 不如用PATH python
# 不确定
path = "/usr/local/bin/python3"
if platform.system() == "Windows":
path = "python3"
if platform.system() == "Linux":
path = "/usr/bin/python3"
return path
python3_path = get_python3_path()
class arduinoExtension(Extension):
def __init__(self):
name = type(self).__name__
super().__init__(name)
def boardaction(self):
self.board = PyMata3()
BOARD_LED = 13
self.board.set_pin_mode(BOARD_LED, Constants.OUTPUT)
print("LED On")
self.board.digital_write(BOARD_LED, 1)
self.board.sleep(1.0)
print("LED Off")
self.board.digital_write(BOARD_LED, 0)
self.board.sleep(1.0)
self.board.shutdown()
print("finished")
@threaded
def task(self):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(self.boardaction())
loop.run_forever()
def run(self):
self.task()
while self._running:
pass
export = arduinoExtension |
上海一家硬件公司开放的插件: https://github.com/Scratch3Lab/codelab_adapter_extensions/blob/master/extension_robofriends.py, |
这个我测试了一下,主要是firmata的串口操作导致的,第一次连接成功;第二次连接枚举失败,目前比较傻瓜的解决方案是每次启动插件的时候,重新烧录一遍固件 |
adapter arduino插件如何实现arduino编译和烧录的呢?调用arduino官方自带的gcc exe编译器? |
@bilikyar @zhouF96 @jatsmulator 可能比我更清楚 @zfm076 提出的这个问题, 是否能给出一些回答? |
这个问题的解决方案是avrdude,arduino的本身就是调用此模块来烧录程序的。 |
谢谢你们抽空回答我的问题。现在我在本地电脑已经完成了arduino的编译下载的exe程序开发。其实也是调用了arduino自带的gcc、avrdude的工具用python做一个exe文件而已。然后现在准备开发一套arduino的scratch blocks,按照网上的教程在我电脑搭建好了scratch-blocks、scratch-gui、scratch-vm。也编译通过了,网页也能打开scratch的编辑器了。 然后下一步就不懂怎么开发我想要的block了,也就是我要是想添加一个arduino的block 应该改哪些东西呢?有木有参考资料额?谢谢 |
你可以参考这个文章,然后你可以看看其他这个博客里文章,会对你比较有帮助。 |
谢谢,我按照文章里面操作。 |
npm install -g yarn |
λ yarn install |
这个问题是没添加环境变量,添加即可。 |
yarn你需要单独安装,这是像npm的包管理系统。 |
yarn已经安装完毕。webpack-dev-server --https这个也要单独安装? |
你可以通过yarn add webpack-dev-server 命令来安装; yarn add 命令在功能上等同于npm install |
我已经运行这个命令安装了的:npm install webpack-dev-server 。然后往终端输入λ nwebpack-dev-server 还是提示这个不是命令。 |
然后我参照 "scripts": {
i 「wds」: Generating SSL Certificate Replace Autoprefixer browsers option to Browserslist config. Using browsers option cause some error. Browserslist config If you really need to use option, rename it to overrideBrowserslist. Learn more at: |
咦?奇怪 居然能打开https://127.0.0.1:8601。。。 它上面不是说Project is running at https://0.0.0.0:8601/ 在这个网址上运行的么? |
你好,我想在网页端实现拖动block在右边显示出ardunio的代码。现在网页端block已经搭好了,不懂怎么将对应的block和实际的arduino代码对应起来。不懂需要设置scratch源码哪些地方。应该看哪方面的资料额? |
收到一封来自印度的邮件,之前始终没认真考虑接入Arduino,毕竟社区认为micro:bit/MicroPython/RPI更可能是未来,但由于低廉的价格,大量落后地区在使用Arduino,所以打算将pymata-aio内置到CodeLab Adapter,提供开箱可用的Arduino插件,不知是否有小伙伴愿意一起在这个分支上工作。
目前bilikyar已经完成了一部分工作:scratch3_arduino, 我们可以在这个基础上继续前进。
已经发布了内置pymata-aio的codelab-adapter版本: v0_8_3 。
The text was updated successfully, but these errors were encountered: