Is Firefly the end all be all solution to Grasshopper on a microcontroller?

Right now I’m working on an iOT project and, and I am beginning to realize a lot of the code i intend to write to serve my purposes already exists in grasshopper (and it’s many extended libraries).

I hope to run grasshopper on a microcontroller, likely the arduino nano, adafruit gemma, or raspberry pi.

The project will involve receiving and transmitting radio / wifi / bluetooth signals, and rgb LED control. The program will need to loop, therefore I believe it must be actually written in ghPython - I also need to look into this further.

I am beginning to explore options for running grasshopper code (and ghPython) on a microcontroller. I discovered Firefly, what seems to be a plugin that can execute grasshopper definitions on a microcontroller. I would like to use the most essential tool / toolset available to me and not something more robust than what I actually need.

My question is this; should i stop my search here with Firefly and move forward with making it work for my purposes, or are there other utilities available to do this sort of thing that may suit my needs more?

If you need more information about my purposes to best answer my question please feel free to ask and I will do my best to answer.

Thanks!

1 Like

Hi @alexeihaws,

Depending on what you actually want to do with the loop, it could probably also be done with Anemone or Hoopsnake (which are Grasshopper plugins).

I’m not sure if that is what is happening when you use Firefly with Arduino. Arduino is programmed in a C-like language and Firefly translates “node code” from Grasshopper to C code that is then compiled for Arduino.
I guess one problem with Firefly that could potentially arise, is that it’s terribly outdated. It hasn’t been updated by the developer for more than 10 years now and its latest version is for Rhino 5.

One thing that I’m certain of is that a Grasshopper definition can’t run on Arduino or Raspberry Pi unless you somehow convert it to “machine code” or to C, which than gets compiled to machine code, for Arduino. The Raspberry Pi is another animal really. It’s basically a standalone mini desktop computer/server running Linux, which doesn’t get much love from Rhino, meaning the Rhino app is not supported on Linux yet. :wink:

That’s pretty hard to give advice on. If you want to go the Firefly route, which probably would be the easiest, I’d run an easy example (i.e. blinking LED) first, simply to see whether Firefly still works with the latest Rhino/Grasshopper and Arduino, which both have come a long way in the last ten years.

Another option, agnostic to Firefly, would be Rhino Compute and/or rhino3dm, which are both available even on Linux I believe, and in CPython (vs. GHPython which is IronPython). However, this would mean that you’d have to entirely script everything and leave Grasshopper behind, at least for this project.

It’d be easier to give more advice, if you could outline your project a little. Maybe there’s something else that would even be better? What are programming skills like?

1 Like

Thanks for the incredibly detailed answer, your response made me rethink my concept a lot, and that alone was very helpful.

I will look into the resources that you mentioned and linked! They seem very relevant to my purposes, I think the research route I’m traversing is even clearer now.

I’ll describe my goal without blurting out the details of my passion project; I’m trying to create a system of individual devices that talk to each other, but also to a central hub device. The devices will sense and send geometric data back to the central hub. The hub will then use data from the devices and use it to compute instructions to be sent back to the devices. The data will be pertaining to the geometric and spatial relationships of the devices, so this is where I thought rhino would be very useful.

Rather than build a 3D engine from the ground up for my purpose why not use something existing that is quite capable of representing space.

I am very new to programming but am currently about 100 pages into Automate The Boring Stuff With Python and I’d say i’m learning fairly quickly. Forgive me if my initial question seemed confusing because I’m still wrapping my head around code, and also what the outer limits of grasshopper are, not to mention the concept itself is evolving rapidly as I gain more information.

I really appreciate your help!

I don’t expect a followup to this response necessarily, I just wanted to at least make your efforts go recognized…

1 Like

Check out gHowl. It supports sending and receiving OSC messages in grasshopper. Essentially you can communicate to other programs or devices like an arduino. So for example if you have an arduino collecting spatial data it can send that data to grasshopper vis OSC where it can be manipulated and sent back the same way.

Maybe you could have a couple of Arduinos, Teensies, etc. that only do the environmental probing via the desired senors and send the data back to the central hub, which could be a Raspberry Pi or any other computer really. The Raspberry has the benefit that it’s fairly inexpensive and can run for long periods of time, as opposed to your computer that you might want/need to shutdown/restart in regular intervals and can be easily programmed in Python. The microcontrollers would have to be programmed in C.
Depending on the distance and the volume of sensor data, you can use Bluetooth (ca. 5m), Wifi, LoRa (>10m), etc. to communicate between devices. On the Raspberry Pi, you could fetch the senor data at regular intervals and parse it into whatever data structure or human-readable format - could be a simple text file -, and store it.
Now, I’m not sure if you even need Firefly or gHowl, since you could simply read the parsed data into Grasshopper and convert it into geometry. There are many ways that you can get the data from the RPi. If it’s for example connected to your home network, you can simply mount it as a network share or SSH into it and get the data with for instance rsync.

1 Like

From quick googling I found a PythonLibrary called pySerial which also works for IronPython and so within Grasshopper. It enables you to read or write to a serial com port. This way you can really simple read or write data to your ardunio from within any app. Haven’t tried it, but it looks very straight forward.

https://pyserial.readthedocs.io/en/latest/index.html

Furthermore, if you have an ethernet shield or wifi build in, you could use tcp or udp, to access your arduino from anywhere.

I would always do anything on my own, not using outdated plugins. The learning is much greater and you have simply more control. Since you also need to code your Arduino, you are exposed to writing code anyway.

Hello,

That book is highly recommended. Are you aware of the differences between IronPython (in Rhino), Cpython (the standard python implementation), Micropython and Circuitpython (for microcontrollers)? It will be useful to bear in mind the fact that these have different capabilities.

There are two Humble Bundles available for the next few days - one for ‘makers’ and another for the Raspberry Pi which may be useful to you. They are excellent value if one or two of the included books look helpful. I can’t comment - I know python very well but haven’t experimented with microcontrollers. I recommend searching online for reviews of the included content before purchasing because the quality varies wildly.

Good luck with your project - it sounds fascinating and the idea of using Rhino / GH on a central computer for the 3D, communicating with microcontrollers running Python sounds like an excellent one.

-Graham

1 Like

Sorry for the late response.

From your explanation it sounds like almost exactly what I’m trying to do can be done using this. Thanks very much for the great resource!

The Raspberry has the benefit that it’s fairly inexpensive and can run for long periods of time, as opposed to your computer that you might want/need to shutdown/restart in regular intervals

Great idea here! this is something I was concerned about. I don’t know how difficult it would be to build a dedicated device for this application, perhaps something like a simple but powerful server would suffice…

Depending on the distance and the volume of sensor data, you can use Bluetooth (ca. 5m), Wifi, LoRa (>10m), etc. to communicate between devices.

I want a lot of scalability here so I have been looking into alternatives to WiFi or Bluetooth as range is an issue, as well as the fact that the devices must be in continual communication for data to be transmitted as far as I’m aware. I’m envisioning a system in which the devices might not be heard from for periods of time when say their signal is somehow blocked. When the signal is picked up again business as usual continues.

Now, I’m not sure if you even need Firefly or gHowl, since you could simply read the parsed data into Grasshopper and convert it into geometry. There are many ways that you can get the data from the RPi. If it’s for example connected to your home network, you can simply mount it as a network share or SSH into it and get the data with for instance rsync.

Well that is pleasant news! You’re using a lot of terms I’m unfamiliar with but I’ll look into all of these! Thanks for the help.

Well the Raspberry Pi could be the server. I don’t know how powerful you’d need it to be for your project though. This all depends on what you finally want to process on the RPi. If you’re only reading senor data at certain intervals and communicating with say you personal computer, I recon even an older, but tenacious device will do. :wink:

Could be LoRa, but it’s probably not as straightforward to implement than Bluetooth or WiFi (?). The benefits are very large transmission distances - I guess the record is something like 700 km - and super high energy efficiency. The downside is that only small amounts of data, maybe in a kilobyte range, can be transmitted at a time, which should be okay for most sensor data (?).

Yes, this could probably be pretty easily done in code on the Raspberry Pi.
If a sensor device is pinged and not available on your local network, skip it an recheck it at the next interval. Otherwise, request the sensor data.

2 Likes