Both MINDSTORMS EV3 and SPIKE Prime have an onboard BlueTooth chip. It turns out that it isn’t too hard to make them talk to each other. In this article, you’ll learn how you can do it with a little MicroPython script. After following this tutorial you will be able to design your own remote control devices with a SPIKE Hub. You can make any design that fits the EV3 robot you want to control.
UPDATE 2024! LEGO has removed a lot of functionality from SPIKE since the release of SPIKE3. This tutorial does not work with SPIKE 3.0. If you wish to try it, you need to install Pybricks on your hub, and then, in Pybricks, choose ‘restore original firmware’. This will bring the firmware version of your hub back to 2.0. Subsequently, you should flash it with MINDSTORMS Robot Inventor software if you want to program it. I was unable to make this work anymore. Ev3dev Debian seems to have made blocking changes too. I get this error.
Unexpected error: GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: Rejected send message, 1 matched rules; type="method_call", sender=":1.64" (uid=0 pid=2100 comm="brickrun -r -- pybricks-micropython main.py ") interface="org.ev3dev.ConsoleRunner" member="Start" error name="(unset)" requested_reply="0" destination="org.ev3dev.ConsoleRunner" (uid=1000 pid=360 comm="/usr/bin/conrun-server ")
If you know how to solve it, please let me know.
The fun thing about the setup I’m describing here is that you only need a script on the EV3 brick. A script on the SPIKE Prime hub is entirely optional. You can use the matrix or run a script that auto-centers motors and it will not interfere with the BlueTooth stream!
For those of you who don’t like to read, I have explained it all in a YouTube video. The SPIKE Prime hub connection is near the end of the video. While you watch, you can like and subscribe to be notified of cool new ideas!
How to connect a SPIKE Prime hub to EV3 for remote control
Time Needed : 5 minutes
How to connect a SPIKE Prime hub to a MINDSTORMS EV3 brick over Bluetooth
Boot your EV3 brick into a recent ev3dev
You can use either the official Python release from LEGO or use the latest ev3dev image. Burn either of those to a MicroSD card, insert it in the MINDSTORMS brick and boot it. Wait until the boot completes and you see a menu.
Start scanning for Bluetooth devices
Go to Wireless and Networks > Bluetooth. In that screen enable Bluetooth and set Visible to enabled. Select the ‘Start Scan’ option.
Enable BlueTooth on the SPIKE Prime hub
Turn on your SPIKE Prime hub and press the little BlueTooth button until the led ring around it starts blinking blue.
Select the SPIKE Prime hub in the Devices list on your EV3 brick
Scroll down until the SPIKE Prime hub appears. It could take a few seconds. I named my hub “Antons Second Hub” because I have two SPIKE Prime hubs.
Write down the MAC address you see
The address is made up of 6 hexadecimal numbers. In my case, it was 40:BD:32:42:EB:54. I press the Pair button here just to be sure. But I’m not 100% sure this is necessary. I haven’t tested the script without pairing. Maybe let me know in the comments?
Open the MicroPython script for your EV3 brick in VS Code
To do so, do file>new window. Or press cmd-shift-n.
Click the ‘run a command’ button
Type ‘clone’ and select ‘Git: Clone’
Paste this URL: https://github.com/antonvh/rc_robot_inventor_to_ev3_omnibot
Choose I nice location on your drive in the next dialog
Click ‘open’ when VS Code has finished downloading the clone.
Finally, click ‘trust’ when VS Code asks you to trust this repo. If you don’t you will not be able to use the LEGO MINDSTORMS VS Code extension.
I have a separate VS Code tutorial where I explain more in-depth how you can run scripts on the EV3 brick.Update the MAC address
Replace the Bluetooth MAC address on line 9 in main.py with the address you noted in step 5.
Connect and run
Connect an EV3 brick to your computer. I find it easiest to use USB. On ev3dev.org you can find guides to connect using wifi and Bluetooth.
Once the brick is connected go to the explorer in VS Code (cmd-shift-E) and then look for the bottom-most accordion tab: ‘ev3 device browser’. Here you can connect to your brick. Now you can run any script on your EV3 and start remote controlling. The SPIKE Prime hub is spewing telemetry data over BlueTooth all the time, so no need to run any scripts there!
Tools
- A PC or Mac with MS Visual Studio Code
Materials
- MicroSD Card
- SPIKE Prime hub
- MINDSTORMS EV3 brick
Here’s a video of the result. Remember to like and subscribe if you haven’t done so yet.
The MicroPython script for a SPIKE Prime remote control
On GitHub, you will find the script I used. It is based on a Pybricks project. Credits to them for reverse-engineering the telemetry stream and writing a class around that. The easiest way to use it is with the LEGO MINDSTORMS VS Code extension.
The Omnibot as shown in the video demo
You can download full code and building instructions from the digital downloads section.
Rubber band cannon omnibot Building Instructions – PDF
Strafe, aim and drive in every direction with this gun platform for a double-barrel rubber band cannon. Rain down terror on your housemates in Video conferences. To build this, you need three LEGO MINDSTORMS EV3 medium motors and a Large Motor. You need a bunch of Technic parts too, but they are pretty common. Here the full part lists:
<
ul>
With some tweaks the could also control a regular drift car.
VR Drift Car Building Instructions
With these building instructions, you can build a LEGO MINDSTORMS Drift Car. It has an optional camera mount so you can race in VR with your FPV goggles. This car is great for use with a PS3 controller, a <a href="https://www.antonsmindstorms.com/2020/02/14/how-to-connect-a-ps4-…
When i start program sometimes i get message like this:
Unhandled exception in thread started by <bound_method b5e67ab0 .>
Traceback (most recent call last):
File “/home/robot/sterowanie_zdalne/connection.py”, line 61, in reader
File “/home/robot/sterowanie_zdalne/connection.py”, line 57, in reader
File “”, line 1, in
NameError: name ‘null’ isn’t defined
Traceback (most recent call last):
File “/home/robot/sterowanie_zdalne/main.py”, line 14, in
File “/home/robot/sterowanie_zdalne/connection.py”, line 45, in __init__
NameError: name ‘IOError’ isn’t defined
But when i wait for 30 minutes and turn on Spike again everything works fine. Any ideas what could go wrong? I made no changes to connection.py
Interesting. Just turning the SPIKE on and off should do the trick. And maybe turn Bluetooth on and off on the ev3.
Hi is it possible to do the opposite and control lego spike with lego mindstorms ev3dev?
Yes, with remote procedure call from ev3. You will have to reverse engineer the rpc bluetooth calls.
How would I do that because I am new to python scripting.
In that case, you’d better try some simpler challenges first. It is pretty advanced.
Ya maybe because i know a little bit of ev3dev python from when i made a lego tank and controlled it with a ps3 controller.
So recently i made a swirlbot with lego spike and i made a joystick remote controll with lego mindstorms the only thing is i don’t know how to connect them with bluetooth. when i go to connect it i select the spike hub from the ev3dev bluetooth devices but it says operation currently unavailable. what should i do?
Hi, I was wondering if it is also possible to control Technic Hubs, like the ones found in 42100 Technic Liebherr Excavator R 9800 with an EV3? I would like to control the motors of the Techinc Hub with the help of python scripts run on the EV3. Thank you!
Not at the moment. New stuff is being programmed to allow this. If you like my Facebook page (https://www.facebook.com/antonsmindstorms/) and subscribe to YouTube (https://youtube.com/c/AntonsMindstormsHacks) you will be the first to know. The problem is the reverse engineering of the Bluetooth protocol and the development of a Python wrapper. That is a lot of work.
Nice video ! is it possible to make a Raspberry Pi and a Spike communicate via bluetooth?
Yes. There are some github repos out there with Python libraries for the Spike Prime RPC calls.
Thank you for your response !
my ev3 hub keeps disconnecting my spike hub what’s up with that
That’s ok.
when i start the program i get this error:
OSError: No data received
any help?
It is what the error says. Check your port definitions and settings, MAC addresses, pairing,…
i tried connecting my laptop to the robot inventor hub before running the program on the ev3, and it sometimes worked. no idea how
when i run the program it shows this error:
OSError: No data recieved
Exited with error code 1.