Git Product home page Git Product logo

s2m's Introduction

logo

Bringing You, Scratch, and micro:bit together!

s2m is a Python program that acts as a bridge between the Scratch 2 off-line editor and the micro:bit computer. It allows you to easily create Scratch programs that interact with the micro:bit.

logo

MAJOR FEATURES

  • s2m is compatible with both Python 2 and Python 3.

  • It runs on Windows, Mac, Raspberry Pi and Linux.

  • It is easy to install.

  • It is easy to use.

  • It is a whole lot of fun!

  • English, Brazilian-Portuguese, Hebrew, Japanese, Korean, Spanish and Traditional (tw) Chinese blocks are available for use.

  • If you would like to translate the blocks to your native language, check out the translation instructions in the User's Guide

    • Submit your translation, and it will become part of the s2m distribution package, with your name added to the list of translation contributors in the User's Guide.

For installation and usage instructions, please read the users guide.

This project was developed with Pycharmpyc

s2m's People

Contributors

champierre avatar lyshie avatar mryslab avatar ngammarano 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

Watchers

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

s2m's Issues

"Scroll hello, world" shows only "hello"

Scroll hello, world shows only "hello". I discovered this bug when I read the source code of s2mb.py. One way to solve this is to scroll from the original string.
I changed the code on line 99-101 to:

        # scroll text command
        elif cmd_id == 's':
            display.scroll(cmd[2:], wait=False)

Radio Option

Hi, Alan,
According to your experience, do you think is feasible to use Scratch to send and receive radio command to/from another micro:bit in a properly way, as BLE is not available in micropython?)

In this way should be possible to:

  • Scratch + usb connected micro:bit to control a remote micro:bit

  • Remote micro:bit to send command - to an usb connected micro:bit + Scratch - like (button A pressed, button B pressed , tilt up, tilt down, right, etc...) so they can control sprites remotelly.

I have changed your program, to make an experiement, but I realized that when I send commands to remote micro:bit, looks that Scratch broadcasts it several times - not sure if exist and effective way for debounce it, I have used wait in Scratch, but not sure if there is a collateral effect.

What I did was:
Got file s2mb.py
Included:

import radio
import random
radio.on()

replaced display.scroll(str(cmd_list[1]), wait=False) to radio.send(cmd_list[1]) so I could use your scroll command to send any code via radio using and existent block).

The receiver micro:bit I flashed with the following code:

import radio
import random
from  microbit import display

radio.on()
while True:

    incoming = radio.receive()
    if incoming == 'a':
        display.scroll("a")
    if incoming == 'b':
        display.scroll("b")
    if incoming == 'c':
        display.scroll("c")

At the Scratch side I have used:
image

I think Scratch sending to remote micro:bit should be possible (at least worked), but I have no idea on the other way around (which makes the thing much better) and also if is possible to define a radio signal in order to avoid send the same commmand to all micro:bit.

Thanks!

Current version of S2mb.py not working for input

Hi Alan,
I realized that after last update the analog and digital pins are not sending data to microbit - at least for me.
If I switch the file s2mb.py from 07 December 2017 (the first version I got), the microbit receives data in a properly way.
Please find enclosed the version that is working for me and the current one that doesn't - same I got in Github

I am testing with an LDR: (but connected to a microbit - of course ;o)
image

P.S Looks that the pip installer cames with s2mb2.py which is not avalaible from Github

s2mb_not_working.zip
s2mb_working.zip

Update on pt-br

Hi, @MrYsLab I just send an update from pt-br transalation.
I realized that I forgot to translate one block - Value instead of Valor.

I´d appreciate if you can update it in future realeases.

Thanks

pt-br.zip

Can't detect device in Windows 7

I followed the user guide, but can't detect device either by autodetecting or specifying serial port.
After modifying serial port detecting part in s2m.py, I can detect device either by autodetecting or specifying serial port now.

Original code:

# if no com port was specified, try doing auto discover.
if com_port is None:
    print('Autodetecting serial port. Please wait...')
    if sys.platform.startswith('darwin'):
        locations = glob.glob('/dev/tty.[usb*]*')
        locations = glob.glob('/dev/tty.[wchusb*]*') + locations
        locations.append('end')
        # for everyone else, here is a list of possible ports
    else:
        locations = ['dev/ttyACM0', '/dev/ttyACM0', '/dev/ttyACM1',
                        '/dev/ttyACM2', '/dev/ttyACM3', '/dev/ttyACM4',
                        '/dev/ttyACM5', '/dev/ttyUSB0', '/dev/ttyUSB1',
                        '/dev/ttyUSB2', '/dev/ttyUSB3', '/dev/ttyUSB4',
                        '/dev/ttyUSB5', '/dev/ttyUSB6', '/dev/ttyUSB7',
                        '/dev/ttyUSB8', '/dev/ttyUSB9',
                        '/dev/ttyUSB10',
                        '/dev/ttyS0', '/dev/ttyS1', '/dev/ttyS2',
                        '/dev/tty.usbserial', '/dev/tty.usbmodem', 'com2',
                        'com3', 'com4', 'com5', 'com6', 'com7', 'com8',
                        'com9', 'com10', 'com11', 'com12', 'com13',
                        'com14', 'com15', 'com16', 'com17', 'com18',
                        'com19', 'com20', 'com21', 'com22', 'com23', 'com24',
                        'com25', 'com26', 'com27', 'com28', 'com29', 'com30',
                        'com31', 'com32', 'com33', 'com34', 'com35', 'com36',
                        'com1', 'end'
                        ]

    detected = None
    for device in locations:
        try:
            self.micro_bit_serial = serial.Serial(port=device, baudrate=115200,
                                                    timeout=.1)
            detected = device
            break
        except serial.SerialException:
            if device == 'end':
                print('Unable to find Serial Port, Please plug in '
                        'cable or check cable connections.')
                detected = None
                exit()
        except OSError:
            pass
    self.com_port = detected

Modified:

# if no com port was specified, try doing auto discover.
if com_port is None:
    print('Autodetecting serial port. Please wait...')

    # listing all serial ports and checking if there is a micro:bit board
    import re
    from serial.tools.list_ports import comports
    for port, desc, opts in comports():
        if 'VID:PID=' in opts:
            vid, pid = re.search('VID:PID=(\w+):(\w+)', opts).groups()
            vid, pid = int(vid, 16), int(pid, 16)
            if vid == 0x0D28 and pid == 0x0204:
                self.com_port = port
                break

if self.com_port is None:
    print('Unable to detect Serial Port, Please plug in '
                'cable or check cable connections.')
    sys.exit(0)

F.Y.I.
ref: ntoll/microrepl

Localization Support

s2m has English UI only.
It would be great if it supports other languages. Localization support would be mandatory if students in elementary school wants to use s2m.

You can switch the block UI based on browser language.

Here is the code of an ScratchX extension that I created.
I think you can use similar logic.

https://github.com/champierre/scratch2mip/blob/master/scratch2mip.js#L32

Let me know if you need help for Japanese translation.

ValueError: invalid literal for int() with base 10: 'g'

I am getting below exception when executing s2m.

s2m version 2.11 Copyright(C) 2018 Alan Yorinks All rights reserved.

Python Version 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:23:52) [MSC v.1900 32 bit (Intel)]
Autodetecting serial port. Please wait...
Using COM Port:com3

s2mb Version: v

Auto launching Scratch
Starting HTTP Server!
Use to exit the extension.
Please make sure you save your Scratch project BEFORE pressing Ctrl-C.

Exception happened during processing of request from ('127.0.0.1', 44366)
Traceback (most recent call last):
File "i:\anaconda3-32\lib\socketserver.py", line 317, in _handle_request_noblock
self.process_request(request, client_address)
File "i:\anaconda3-32\lib\socketserver.py", line 348, in process_request
self.finish_request(request, client_address)
File "i:\anaconda3-32\lib\socketserver.py", line 361, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "i:\anaconda3-32\lib\socketserver.py", line 696, in init
self.handle()
File "i:\anaconda3-32\lib\http\server.py", line 418, in handle
self.handle_one_request()
File "i:\anaconda3-32\lib\http\server.py", line 406, in handle_one_request
method()
File "i:\anaconda3-32\lib\site-packages\s2m\s2m_http_server.py", line 76, in do_GET
self.send_resp(self.s2m.handle_poll())
File "i:\anaconda3-32\lib\site-packages\s2m\s2m.py", line 368, in handle_poll
resp = self.build_poll_response(reply)
File "i:\anaconda3-32\lib\site-packages\s2m\s2m.py", line 458, in build_poll_response
x = int(data_list[0])
ValueError: invalid literal for int() with base 10: 'g'

Display NO doesn't work

Display NO doesn't work. In the console I get:

Exception happened during processing of request from ('127.0.0.1', 51842)
Traceback (most recent call last):
  File "c:\python27\lib\SocketServer.py", line 295, in _handle_request_noblock
    self.process_request(request, client_address)
  File "c:\python27\lib\SocketServer.py", line 321, in process_request
    self.finish_request(request, client_address)
  File "c:\python27\lib\SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "c:\python27\lib\SocketServer.py", line 655, in __init__
    self.handle()
  File "c:\python27\lib\BaseHTTPServer.py", line 340, in handle
    self.handle_one_request()
  File "c:\python27\lib\BaseHTTPServer.py", line 328, in handle_one_request
    method()
  File "c:\python27\lib\site-packages\s2m\s2m_http_server.py", line 80, in do_GET
    self.process_command(cmd_list)
  File "c:\python27\lib\site-packages\s2m\s2m_http_server.py", line 127, in process_command
    resp = self.s2m.handle_display_image(cmd_list[1])
  File "c:\python27\lib\site-packages\s2m\s2m.py", line 327, in handle_display_image
    if data[2] == '_':
IndexError: string index out of range
----------------------------------------

I use this system:

s2m version 1.10  Copyright(C) 2017 Alan Yorinks  All rights reserved.

Python Version 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)]
Autodetecting serial port. Please wait...
Using COM Port:com3

s2mb Version: s2mb.py Version 1.05 05 December 2017

issues with PWM

@lyshie has reported some issues with analog write. There are documented in comments on an unrelated matter for a pull request:
#14

I am opening this issue to help expose it in case anyone else is seeing similar problems and want to add to the conversation.

Can s2m support the existed scratch project?

Thanks for ur help first
I have a old project ,and I want to improve it by micro:bit
Have some methods to connect extension?(I can only connect by a new project)
Hope that you know what I said thanks!

"Cannot locate s2m files on path." error

I think I properly followed the installation guide https://mryslab.github.io/s2m/install/.
When I started "s2m", I got "Cannot locate s2m files on path." as below.
What could it be wrong?

I use MacOS Sierra 10.12.6(16G29).

➜  ~ s2m

s2m version 1.03  Copyright(C) 2017 Alan Yorinks  All rights reserved.

Python Version 2.7.14 (default, Sep 25 2017, 09:53:22)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]
Autodetecting serial port. Please wait...
Using COM Port:/dev/tty.usbmodem14612

Cannot locate s2m files on path.
None

Change a server port from 50209 to 50210

Hi Alan, not sure if I have to use this channel to give a suggestion....sorry in case not.

I would like to suggest you to change the server port of file s2m_http_server.py from 50209 to 50210.
That will be nice in case a user want to combine extensions (Arduino and micro:bit).
So an Arduino can communicate to micro:bit via Scratch and vice versa.
I have changed my local file and worked fine for this purpose.
Thanks!

Duplicate image "ANGRY"

There are 2 "ANGRY" in images of s2m.s2e file.

"images": [
            "HAPPY",
            "SAD",
            "ANGRY",
            "SMILE",
            "HEART",
            "CONFUSED",
            "ANGRY",
            "ASLEEP",
            "SURPRISED",
            "SILLY",
            "FABULOUS",
            "MEH",
            "YES",
            "NO",
            "TRIANGLE",
            "DIAMOND",
            "DIAMOND_SMALL",
            "SQUARE",
            "SQUARE_SMALL",
            "TARGET",
            "STICKFIGURE",
            "RABBIT",
            "COW",
            "ROLLERSKATE",
            "HOUSE",
            "SNAKE",
            "ARROW_N",
            "ARROW_NE",
            "ARROW_E",
            "ARROW_SE",
            "ARROW_S",
            "ARROW_SW",
            "ARROW_W",
            "ARROW_NW"

	    ],

Spanish version

Hi, following a spanish version for motion project.
motion_es.zip

I have made a slight change in the spanish extension, changing the name from s2m to s2m-es, hope it's not an issue to suggest it as I was not the translator.
s2m_es.zip

Thanks!

Communication Scratch-Microbit stops after a while with intensive communication

In the attached project the communication Scratch-Microbit stops after a few minutes with much sound, e.g. buttons A and B does not work, and the LEDs does not update. The Scratch-project continues to run and updates the screen. There is no error message in the Command Prompt. You should not uncompress the zip-file, just rename it so that .zip is removed, since sb2-files are actually zip-files, but GitHub does not recognize this w/o the zip extension.
s2m-loudness.sb2.zip

The communication hangs faster if video in Scratch is switched on.

I think communication last longer if I e.g. change "wait 0 secs" in the forever-loop to e.g. "wait 0.2 secs".

A suggestion is, if possible, to output a message in s2m console that the communication with the micro:bit is broken.

It works again if I stop with Ctrl+C and then restart s2m.

I use a trial version of Windows that came out after Windows FCU. It's the latest in Slow Ring.
Microsoft Windows [Version 10.0.17025.1000]

I use latest Scratch and latest Adobe Air:
Scratch 2 Offline Editor v458.0.1

I use the latest serial driver that works with Mu for Windows REPL: https://codewith.mu/
i.e. https://os.mbed.com/media/downloads/drivers/mbedWinSerial_16466.exe

This is all output from s2m in Command Prompt:

s2m version 1.09  Copyright(C) 2017 Alan Yorinks  All rights reserved.

Python Version 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)]
Autodetecting serial port. Please wait...
Using COM Port:com3

s2mb Version: s2mb.py Version 1.04 23 November 2017

Auto launching Scratch
Starting HTTP Server!
Use <Ctrl-C> to exit the extension.
Please make sure you save your Scratch project BEFORE pressing Ctrl-C.


Problems installing

I had no trouble installing this on a Windows 7 machine, but the s2m blocks never appeared in Scratch. I tried on a Windows 10 machine and everything seems fine until I tried running s2m. I get these errors:

s2m version 2.11 Copyright(C) 2018 Alan Yorinks All rights reserved.

Python Version 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)]
Autodetecting serial port. Please wait...
Using COM Port:com4

s2mb Version: s2mb.py Version 1.10 14 April 2018

Auto launching Scratch
Traceback (most recent call last):
File "c:\program files\python37-32\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "c:\program files\python37-32\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Program Files\Python37-32\Scripts\s2m.exe_main
.py", line 9, in
File "c:\program files\python37-32\lib\site-packages\s2m\s2m.py", line 617, in main
base_path=user_base_path, display_base_path=display, language=lang)
File "c:\program files\python37-32\lib\site-packages\s2m\s2m.py", line 235, in init
self.auto_load_scratch()
File "c:\program files\python37-32\lib\site-packages\s2m\s2m.py", line 342, in auto_load_scratch
scratch_proc = Popen(exec_string, creationflags=subprocess.CREATE_NEW_PROCESS_GROUP)
File "c:\program files\python37-32\lib\subprocess.py", line 756, in init
restore_signals, start_new_session)
File "c:\program files\python37-32\lib\subprocess.py", line 1155, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

ANY SUGGESTIONS??

digital write

I want to turn on an led, but when I click the "Digital Write pin (0) value(0)"command, the led just flash and then turn off. I want to know if the led can be always on? Thanks a lot!

Can't detect serial port

I am having trouble getting s2m to run on Windows 10. Followed install instructions with install of Python 3.7, the Mu editor but at command prompt 's2m', I get the error message 'Failed to detect serial port. Check cable or connection'. I have successfully installed and run s2m on a pi but want it on laptop for convenience but cannot get past this step. Microbit is attached to COM 1. Any help gratefully received.

Conection lost after include tilt function

Hi @MrYsLab, I have tested the following sketch:
image

I am using the last version of your program.
Eveerything works fine until I tilt the device.
In that moment the green circle became red.
looking to DOS it´s exactly the same as before.
image

How it works for you?

Thanks!

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.