Neuron - Addressing GPIO from C++

  • administrators


    the Neuron does not use the GPIOs of RPi for the I/Os. Instead there are 1-3 ARM processors (depending on the S/M/L Neuron version) for each group which communicate with the RPi using SPI, where a kind of Modbus protocol is used.

    We are working on the Evok to be finalized and debloated images. Right now there is a pretty simple possibility of using the TCP modbus server (available at localhost:502) which is included in the Mervis img, map of the register is available at

    So the easiest way for you might be to get a C++ library for TCP Modbus and get the advantage of the Modbus interface.

    Do not forget to stop and disable unneeded seriveces which are included in the Mervis OS:

    systemctl stop sharkrt
    systemctl stop configtool
    systemctl disable sharkrt
    systemctl disable configtool

  • @tomas_hora Thanks a lot for your response!

    I will have to change the communiation layer in my application then, no problem but I just need to figure out how this works.

    I also have no idea if Mervis will be able to substitute my on software (it is a kind of 'if this then that' thing)

  • administrators

    @Boy-Lenssen I am sorry for that but we had to move on from the RPi GPIOs forward to allow better scalability and variability of our products.

    Mervis is basically if this than that platform that runs in loop... Not a realtime solution but suitable for most automation applications.

  • @tomas_hora I see that EVOK uses PIGPIO, which uses GPIO, is it still then usable with the neuron? I actually have no idea at the moment what Mervis does, need to check the tutorials on Youtube...

    Also, no knowledge on Modbus yet. I will start trying it out as soon as I have the Neuron (at a colleague's place now)

  • administrators

    @Boy-Lenssen Since the GPIOs are not used in Neuron, than PIGPIO does not have any sence there. You could use it to write your own implementation of the low level protocol on SPI, but why?

  • @tomas_hora I will first check Mervis and otherwise try or something. I think I'll manage, thanks!

  • @tomas_hora I had this project in the fridge for now, but picking it up now. I actually want to try to talk to the I/O ports via modbus, but need a bit of a start.

    I understand that I need to connect via IP and port number, but how do I talk to the ports next? How do I set them to pullup/down and input / output? How do I get triggered when an input changes?

    I want to try this out with Android Things IoT OS. Can I setup a modbus server myself to be able to talk to the ports?

    I'm so sorry, I just can't find a way to get started...Should I install Mervis and use a second Pi with Android Things to connect to the modbus?

  • administrators

    @Boy-Lenssen All the I/Os (except 1Wire) are acessible using the TCP Modbus protocol, the map of each register/coil can be found here

    Since it does not uses GPIOs of RPi, you do not need to set any pullups. Just use the registers/coils to set and read the states of IOs. You will need to poll the registers/coils periodically to catch the state of the I/O.

    I suggest you to take a look at some C++ ModBus TCP library that supports client mode.

    You can also use the Websockets, or HTTP REST api that evok provides (it is using the underlaying TCP Modbus):

  • @tomas_hora of course! How stupid of me, no pullups etc and input/outputs are dedicated on the device.

    One last question before I can start investigating: to get it working, I need to flash the Mervis image on SD card and use that on the Pi located in the Neuron, right? And then I need an additional Pi (if i want to run Android Things) to work as a client to address it?

  • administrators

    @Boy-Lenssen You can use the Mervis which already includes teh TCP Modbus. Or the standard Raspbian and install it on your own from github

    And yes, than you would need to run Android Things on a different RPi.

  • @tomas_hora Thanks for the patience! It is all becoming clear to me!

  • administrators

    @Boy-Lenssen You are welcome :) I am glad I helped a bit...

  • @tomas_hora Well, it looks like more questions arise, so I think I keep bothering you for just a bit more :) But if this thing works out, we will be buying a lot more of these devices!

    I am working on a project where it is quite critical we know when an input has changed. I would like to know which method is the fastest of the ones listed here:

    Another thing: if I need to shut down the system (it is shut down every day), should I create something that will gracefully shut down the Pi in the Neuron (when I'm using the Mervis image) or is that SD Card read-only and is there no chance of corruption?

  • administrators

    @Boy-Lenssen The fastest is definitely only the TCP Modbus since more SW between your calls and the HW causes more delays. The TCP Modbus server can handle easily thousand of requests per seconds. Evok does not scan that fast (by default twice per second but can be re-configured).

    If you disable the mervis system (sharkrt + configtool) on the MervisOS, than there is nothing else I am aware of that will try to write to the card. So everything except Mervis shoudl be read-only, but I cannot guarantee there is no chance of corruption.

    There is no ready solution for easy shutdown (except standard linux features like cronjob).

  • @tomas_hora I fired up the system with the december 6th version of Mervis software image (

    2 issues:

    1. what is the login for it? I have the Neuron connected to my screen and only get to the login.

    2. (where I checked it's IP address via my router) does not return anything. It gives a 404 in the browser and wget -qO- does nothing. shows a page with a login button, so the server is running.

  • administrators


    1. root:unipi
    2. The mervis services are still running, thus also its web interface on port 80 where you see the page with login. See the port of evok in /etc/evok.conf

    Btw. I suggest you to disable the sharkrt and configtool services first or even get started with a clean raspbian (lite) so you do not get confused by some of tuneups that are implemented in the MervisOS.

  • @tomas_hora so it is normal not to have access to the REST api? I thought this was available on the Mervis image.

    I just wanted to get some basics to try out, that is why I took the Mervis img

  • administrators

    @Boy-Lenssen The mervis image does not contain the newest version of evok that supports Neurons (since it is not needed). That is only available on github as above

  • @tomas_hora ok, going to try it on Jessie Lite...

    I am completely confused about the software that is available atm. Can you do a summary on what is what?

    I see Mervis had TCP modbus, but no REST API, which seems to be part of EVOK?
    I wanted to try out someting using the REST API, but on Mervis, there is only modbus?

    Do I see it correctly, and Mervis contains Modbus as it uses it to communicate itself? And is EVOK a collection of UniPi API possibilities?

    Edit: in meanwhile, I have installed EVOK without any issues on a Jessie Lite img and could address the REST API. The Pi I had it installed on was not the one in the UniPi. I have to use some pliers to get the SD-card out of the UniPi to replace it ;) will do that tomorrow, enough for today ;)

    Edit the next morning :) : I think I understand now. EVOK is something that is in development with API's and (in future?) control the UniPi via some UI, like Mervis
    Mervis is an off-the-shelve solution that already existed and works with the UniPi...

  • administrators

    @Boy-Lenssen :) You got it all right. Evok and the TCP Modbus server are opensourse solutions for people who want to do their own implementation.

    Mervis makes UniPi all in one PLC system including scada, HMI designer and database.