Skip to content

Instantly share code, notes, and snippets.

@bricklife
Last active June 15, 2023 11:55
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bricklife/13c7fe07c3145dd94f4f23d20ccf5a79 to your computer and use it in GitHub Desktop.
Save bricklife/13c7fe07c3145dd94f4f23d20ccf5a79 to your computer and use it in GitHub Desktop.
LEGO SPIKE Prime JSON command examples

System

{"i":"EMWW","m":"get_firmware_info","p":{}}
{"m":"trigger_current_state","p":{}}
{"m":"program_modechange","p":{"mode":"play"}} // "mode": "play" or "download"
{"i":"ESGe","m":"set_hub_name","p":{"name":"U1BJS0U="}} // "name": Base64 string

Motor

{"i":"HTv-","m":"scratch.motor_run_for_degrees","p":{"port":"B","speed":75,"degrees":360,"stall":true,"stop":1}} // "stop": 0, 1, or 2 (float, brake, or hold position)
{"i":"rSHB","m":"scratch.motor_run_timed","p":{"port":"B","speed":-75,"time":1000,"stall":true,"stop":0}}
{"i":"VMMY","m":"scratch.motor_go_direction_to_position","p":{"port":"B","position":0,"speed":75,"direction":"shortest","stall":true,"stop":0}} // "direction": "shortest", "clockwise", or "counterclockwise"
{"i":"pmig","m":"scratch.motor_start","p":{"port":"B","speed":75,"stall":true}}
{"i":"DS_n","m":"scratch.motor_stop","p":{"port":"B","stop":1}}.

Movement

{"i":"x2k0","m":"scratch.move_tank_degrees","p":{"lmotor":"A","rmotor":"B","lspeed":50,"rspeed":50,"stop":1,"degrees":205}}
{"i":"m_9e","m":"scratch.move_tank_time","p":{"lmotor":"A","rmotor":"B","lspeed":50,"rspeed":20,"stop":1,"time":10000}}
{"i":"vX80","m":"scratch.move_start_speeds","p":{"lmotor":"A","rmotor":"B","lspeed":100,"rspeed":100}}
{"i":"G8o1","m":"scratch.move_stop","p":{"stop":1,"lmotor":"A","rmotor":"B"}}

Light

{"i":"rZZN","m":"scratch.display_image_for","p":"duration":2000,"image":"99099:99099:00000:90009:09990"}}
{"i":"qiIx","m":"scratch.display_image","p":{"image":"99099:99099:00000:90009:09990"}}
{"i":"MMh5","m":"scratch.display_text","p":{"text":"Hello"}}
{"i":"Ia6B","m":"scratch.display_clear","p":{}}
{"i":"0ajO","m":"scratch.display_set_pixel","p":{"brightness":9,"x":0,"y":0}}
{"i":"-PhJ","m":"scratch.center_button_lights","p":{"color":9}}
{"i":"gNnF","m":"scratch.ultrasonic_light_up","p":{"port":"A","lights":[100,100,100,100]}}

Sound

{"i":"2vPy","m":"scratch.sound_beep_for_time","p":{"duration":200,"note":60,"volume":10}}
{"i":"SUaE","m":"scratch.sound_beep","p":{"note":60,"volume":10}}
{"i":"f688","m":"scratch.sound_off","p":{}}

Sensor

{"i":"g1af","m":"scratch.reset_yaw","p":{}}
{"i":"Gxsi","m":"reset_program_time","p":{}}

More Motor

{"i":"umJ3","m":"scratch.motor_set_position","p":{"port":"A","offset":0}}
{"i":"SX5a","m":"scratch.motor_pwm","p":{"port":"B","power":100,"stall":false}}

More Movement

{"i":"udSX","m":"scratch.move_start_powers","p":{"lmotor":"A","rmotor":"B","lpower":50,"rpower":50}}

Dashboard

{"m":"sync_display","p":{"sync":true}}
{"i":"OAm_","m":"move_project","p":{"old_slotid":0,"new_slotid":1}}
{"i":"OmDx","m":"remove_project","p":{"slotid":1}}.

Download Mode

{"i":"fye7","m":"start_write_program","p":{"meta":{"created":1580451544403,"modified":1580614688346,"name":"Project 93"},"size":136,"slotid":0}}
{"i":"FRbV","m":"write_package","p":{"data":"ZnJ...<omitted>...Cg==","transferid":"2054"}} // "data": Base64 string
{"i":"3QDy","m":"program_execute","p":{"slotid":0}}
{"i":"UMN8","m":"program_terminate","p":{}}
@wheel7
Copy link

wheel7 commented Jun 29, 2020

Sweet! Thanks a lot.

I would like to understand how to determine these commands? Are they documented somewhere?

@bricklife
Copy link
Author

I found these JSON commands during sniffing the Bluetooth communication between SPIKE Hub and the app. I'm not sure whether there is any document in the internet.

@wheel7
Copy link

wheel7 commented Jun 29, 2020

Ahhh the fun stuff :D

Nice work. I have yet to do some real programming with Spike. I have two units and I would love to be able to communicate between them. But that is currently not possible, right?

@bricklife
Copy link
Author

As far as I know, not possible now.

@wheel7
Copy link

wheel7 commented Jun 29, 2020

I am thinking about communicating via the sensors. That would be a nice solution. Send some morse like code with the light/distance sensor or use colors or something.

@PhoBricks
Copy link

I am thinking about communicating via the sensors. That would be a nice solution. Send some morse like code with the light/distance sensor or use colors or something.

Unfortunately we do not have ambient right now if you're using the blockbased programming (Scratch), but it is already supported in Python :-)

@wheel7
Copy link

wheel7 commented Jul 23, 2020

I have managed to "connect" two light sensors and sens a signal from the first to the second. Now, I need to think about how to do the START signal end END signal. Kind of ready to send and end of transmission.

@ytt-bit
Copy link

ytt-bit commented May 22, 2022

How do I issue a command in JSON format to a Spike hub? The usual serial port / tty with bluetooth method results in a MicroPython REPL which doesn't take a JSON string if I understand correctly.

@fdeitelhoff
Copy link

How do I issue a command in JSON format to a Spike hub? The usual serial port / tty with bluetooth method results in a MicroPython REPL which doesn't take a JSON string if I understand correctly.

I have the same question! Is there a special mode in which the Spike accepts JSON commands?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment