Giving special instructions to specific cores with multiple cores flashed with the same Spark App

Hey there! We (myself and @julianozen ) are working on a hackathon project that has two spark cores working together to perform a set of functions. Specifically, each of the cores has different outputs that need to be coordinated. So ideally an abstract action sequence would look something like:

["SparkCoreA: set AnalogOut2 HIGH", "SparkCoreB: set AnalogOut6 HIGH",  "SparkCoreA: set AnalogOut4 LOW", ...etc]

Is this doable in a single Spark App? Is there a way to specify which core you are giving an instruction to?

I looked into the publish and subscribe API functions, and I think we could set up some sort of interaction between the cores to coordinate who can handle which instruction. But it seems like that could end up being more complicated than we would need.
Alternatively I guess we could set up two separate Spark Apps for each core, with one being a master and one being a slave. They could then coordinate via HTTPRequests. However, the potential problem I could see with that is high latency (as well as being more complicated than the possibility of just controlling a specific core from an app in charge of both).

Thanks much! Also, thanks @avidan for the help thus far!

I’m pretty sure there is a way to do a cloud handshake that then allows spark to spark local communication.

Time to ping an elite or two…
Since this is a university project, let’s recruit a fellow University rockstar from across the ocean.

2 Likes

Hey @kennethlimcp
Do you remember what I’m talking about here?

1 Like

If you want a generic app for both spark core but doing different functions, I will check the core ID and if it matches, do this function.

Spark to spark communication via the cloud will have some latency but we can always do some tricks like call both cores and set a flag then wait to execute at the same time!

You can have a master and all slaves which subscribe to an event by the master.

What you want to do is kinda fun. Let me know if you need more help and I’ll help write some code. :slight_smile:

1 Like

Ah hah! Of course, you can just check against the Spark core’s device ID, I totally forgot about that. I’ll let you know if we’ve got any more questions. Thanks for the help!

It might be a dumb question, but just to make sure of the meaning of the term “Spark app” in this context.

Do you mean to write up one single Core firmware that you’ll flash to all your Cores and they should communicate via the cloud, or do you mean a control application on a SmartDevice, PC, … that will control all your Cores by sending out individual “commands” to each of them?

Since the answer to your question will be completely different for each of the two meanings of “Spark app”.

Not a dumb question at all! I meant that it would be a single Core firmware that we flash to all of our cores, but with specific instructions for certain cores.

But to make things confusing, we will also be making a separate app that interacts with our Spark cores :smile:

I see :eyes:

then, of course, is Kenneth’s answer the way to go :wink:

mind sharing with us a bit more about WHAT you are doing? we might have some insight on a good way of HOW to do it. there is a lot of power in that little chip…

2 Likes

We’re hacking a microwave to be able to control it remotely! You’ll scan a food item with our iPhone app, which then confer’s with our Google AppEngine app and its database, fetching the instructions for cooking it. All you have to do is put the item in the microwave and press “Go” on the app, and it will start cooking for the appropriate amount of time at the appropriate power setting. If you need to stir, the app will notify you to do so.

We have two Spark Cores to map to all of the buttons needed (spark cores w/ 8 analog digital outputs, there are ~14 buttons we need to map to). This way the Cores will need to coordinate in order to figure out which can press which button in the sequence of actions necessary to cook the food item.

We’re sure this sorta stuff has been done before, but it’s a really fun exercise in working with all levels of the stack :slight_smile:

1 Like

Also thank you (to the max) to @avidan for the extra couple of cores, you saved our butts.

1 Like

Another dumb question - that I do bestest :wink:

When you talk about 14 buttons, how comes that you need analog pins? Are you doing it via servos that need to be positioned?
Otherwise you could have all 16+2 pins as digital outputs to just trigger digital actuators (push/release) or even replace the buttons with relays/transistors.

Another option would be to multiplex the pins.

When you talk about 14 buttons, how comes that you need analog pins? Are you doing it via servos that need to be positioned?
Otherwise you could have all 16+2 pins as digital outputs to just trigger digital actuators (push/release) or even replace the buttons with relays/transistors.

Another dumb answer on my part, I meant to say digital outputs!

But you can digitalWrite to A0-A7 too!

And if you need (and can do without Serial1 port) you can even use RX/TX as digital outs too.

1 Like