Megapi+Raspberry Power


I got a Megapi and my plan was to use it to control two encoder motors, and attach it to a Raspberry Pi. However, after reading the FAQ it turns out I shouldn’t power the Raspberry by using the GPIO:

“When supplying power to Raspberry Pi through MegaPi and controlling motors at the same time, the voltage will be unstable and Raspberry Pi will reset. Just supply power to Raspberry Pi directly.”

How should this be done exactly? Isn’t one of the pins connecting the two boards the 5V for the Raspberry? Should it just be cut? Has anyone done something already with this setup? Thanks!


Hi Tomatito.

Yes, it is strongly suggest that you supply power to raspberry directly in this case sine the supply ability to raspberry is weak. You can give a test.


Thanks for your reply!
My question was actually how should the two boards be connected then. You provide a connector:

which connects the 5V from the MegaPi to the Raspberry. Should it not be used then? Which pins should be connected and which not?


Hi @tomatito,

Imho you just need to plug a power source to the 5V micro USB port of the raspberry pi. This could either be a power supply or one of these smartphone recharging batteries which you find in every electronics shops nowadays.

@tec_support, please correct me if I am wrong here, but there is no need to cut any pins.


Hi! but wouldn’t that mean having two power supply sources at the same time at the raspberry? one from the micro usb and one from the megapi…


@Srothe is correct.
@tomatito, you can just connect the 2*5 pins on MegaPi to Raspberry Pi, you don’t need to worry about the power, you can connect refer to the picture below:

Controlling Ultimate 2.0 Kit MegaPi from Raspberry

Thanks a lot for your answers! My worry was that I can either fry the raspberry or the megapi


@tomatito: you can safely connect both supplies at the same time, in parallel.



How do we communicate or send code from the Raspberry Pi to the MegaPi board? What are the detailed steps that would help do that??


Hi,Does it work? Megapi + Raspberry


Not exactly sure what your question is, but here is are the basics.

The Megapi is a microcontroller that does a good job with it’s limited resources to run the motors and sensors attached to it. It is NOT a general purpose computer. Most of the demos and example you see are of a general purpose computer (tablet, phone, pc, mac) sending commands via (bluetooth, wifi, usb, serial port) to a simple “firmware” running on the MegaPI.

The raspberry pi takes the general purpose computer role in this. So, for instance, if you install the standard firmware on the MegaPI, then connect it to the raspberry pi either through a USB cable or the GPIO serial connect (pictured in a post above), you can then send the commands that the standard firmware can understand through that serial connection.

Makeblock is supplying a python class (called MegaPI) that will run on your raspberry pi to send those commands and handle the callbacks (for sensor calls).

There are numerous examples in the makeblock git repository here:

But the basics are…(once you have the two devices connected), in python:

from megapi import *

bot = MegaPi()
 # if you are using the USB port
# otherwise ttyS0 or ttyAMA0 depending on your configuration

There is a good post on setting up the serial port on your RPi here: MegaPi Firmware / Python Interface



Not true… I connected both and smoke started to come out of an encoder motor


So you obviously had a problem with your wiring, which would be your own mistake, or you possibly had a defective component. What exactly makes you think the statements in this thread were wrong? Could you post a schema of your wiring, this would make it easier to identify the problem?


I connected a power source to the Raspberry Pi and the battery pack to the megapi. wiring was working fine until I added the power bank. The battery pack alone is sufficient to power both the raspberry and the megapi.


What voltage was the encoder motor designed for? Andwhich port did you connect it to?


9V… port 3… the battery pack was connected to the Megapi and my powerbank (5v) was connected to the raspberry pi.


Hi, is there something I am doing wrongly? I have performed all the necessary setup and I ran the following commends and got no results. Would you be able to shed some light please?

pi@raspberrypi:~ $ cd Documents
pi@raspberrypi:~/Documents $ python
init MegaPi
<megapi.mSerial instance at 0x766ead50>


megapi.mSerial instance at 0x766ead50


andrew, you simply cannot fry a 9V motor with using a 5V power supply. So either your battery pack was designed for higher voltage, or you missed out something else.
From the information we got from you, we can not give you better advice than to re-check your wiring and make sure you do not apply too much currency and power to the encoder.