Coder Social home page Coder Social logo

spike-tools's Introduction

spike-tools

Utilities for experimenting with Lego Spike Hub

To install dependencies

pip3 install -r requirements.txt

The default device address to communicate with the hub is /dev/ttyACM0 and otherwise can be specified with --tty option. The port path can be discovered with sudo python -m serial.tools.list_ports.

Access to serial ports usually needs a special privilige. To avoid running every command with sudo you can do the follwing in Linux (needs logout to become effective).

sudo adduser <user name> dialout

If the center led of the hub flashes red shortly after connecting and/or you see random characters appearing when manually connecting to the hub via a terminal (something like ATE1 E0 ~x~), this likely indicates a modem controller is trying to talk to the hub (which won't succeed). Under Linux this can be disbled with:

sudo systemctl disable ModemManager

spikejsonrpc.py

A module to communicate with the Spike Hub using JSON RPC. Can be used to manage program slots of the on brick selector.

usage: spikejsonrpc.py [-h] [-t TTY] [--debug]
                       {list,ls,fwinfo,mv,upload,cp,rm,start,stop,display} ...

Tools for Spike Hub RPC protocol

positional arguments:
  {list,ls,fwinfo,mv,upload,cp,rm,start,stop,display}
    list (ls)           List stored programs
    fwinfo              Show firmware version
    mv                  Changes program slot
    upload (cp)         Uploads a program
    rm                  Removes the program at a given slot
    start               Starts a program
    stop                Stop program execution
    display             Displays image on the LED matrix

optional arguments:
  -h, --help            show this help message and exit
  -t TTY, --tty TTY     Spike Hub device path
  --debug               Enable debug

The programs launched with the default launcher need to be expressed in coroutines so they can be exited properly. hub/program_template.py is an example skeleton program handling initialization. It can be uploaded with:

sudo ./spikejsonrpc.py upload hub/program_template.py 19

cp.py

Copy a file to the hub filesystem.

usage: cp.py [-h] [-t TTY] file [dir]

convert_sound.py

Converts a sound file to a format accepted by hub.sound.play() method. Accepts any input format supported by librosa.

usage: convert_sound.py [-h] [-s START] [-d DURATION] file

spike-tools's People

Contributors

nutki 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spike-tools's Issues

[Question] How did you discover the rpc commands?

Hi @nutki,

I was wondering how you discovered this bit of code:

def display_set_pixel(self, x, y, brightness = 9):
    return self.send_message('scratch.display_set_pixel', { 'x':x, 'y': y, 'brightness': brightness})

Specifically the part where you send scratch.display_set_pixel, How did you discover that you can send this and are there more commands to send? Maybe commands for controlling motors or sound?

I'm looking forwards to your reply!

penguix0

Robot flashing red after uploading and launching

HI!
While uploading, everything works, but when I try to launch it, then it throws a error at me. Disabling the Modem Manager didn't help. When enabling debug mode I get:
DEBUG:root:Cannot parse JSON: bytearray(b'10, 300, 323, 319]], [61, [4, 0, 21, 23, 25]], [49, [0, 3, -133, 0]], [49, [0, -4, -137, 0]], [458, -597, 637], [1, 2, 0], [-23, -36, -36], "", 0]}')
This even happens when I try to upload a program with only 1 comment inside and with the program template. I have downloaded all the modules.
I'm using Linux/pop os, python3.9.1(brew) and also tried python3.9.0(apt), llvm9.0.1(with brew), llvmlite0.34.0. Everything should be compatible.

[Question] spike hub to wedo 2.0

hi, i have successfully connected over BLE a Lego Spike Hub and Lego WeDo 2.0.
Next step was to exchange some data between them, so i tried to change the WeDo 2.0 LED color.
Following the source code from this repo: https://github.com/nathankellenicki/node-poweredup , i could see that for setting the LED, 2 BLE Characteristics need to be used.
The question is, how to do this using the micropython on Spike hub? Since i saw that the send function of the connection object does not support the second parameter, the BLE Characteristic.

[request] enhance the list output to show the base64 decoded file names

Using spike-tools for a few hours now.

  • Looking at the list output first.
    The slot file name on my hub is base64 encoded.
    As an example:
    Name: ZGlyZWN0b3J5X2xpc3Q=
    Name decoded: directory_list

  • Looking at the list output with --debug I see a fields that are not printed

    • project-id - not base64 encoded but I do not understand it
    • id - some number that I also do not understand
    • type - in my case always python, but I have only one hub....

suggestions:

  1. Add a line to the list output (at most 20 lines, so only few) with the decoded file name
  2. remove id from the print and add type
    unless you have an explanation what it means.
  3. Add the project if we know what type of encoding there is on it

Something like this maybe:

# Name / Name decoded Size type Last Modified
0 ZGlyZWN0b3J5X2xpc3Q= 1725b python 2020-07-27 13:05:09
. directory_list
1 dHJ5X21vZHVsZXM= 357b python 2020-07-26 22:15:06
. try_modules
9 UHJpbWVDdWJlci12MXAx 1662b python 2020-07-26 18:02:38
. PrimeCuber-v1p1
10 YXZhaWxhYmxlbW9kdWxlcw== 494b python 2020-07-26 22:51:58
. availablemodules
. . . . 30940/31744kb Free

If you want a pull request for this I will make one, of course.

Bert

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.