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

**URL:** https://community.particle.io/t/giving-special-instructions-to-specific-cores-with-multiple-cores-flashed-with-the-same-spark-app/6931
**Category:** Cloud
**Created:** [September 13, 2014, 4:16am UTC](https://community.particle.io/t/giving-special-instructions-to-specific-cores-with-multiple-cores-flashed-with-the-same-spark-app/6931 "2014-09-13T04:16:18Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![noahrowlett](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/noahrowlett/32/3042_2.png) [@noahrowlett](https://community.particle.io/u/noahrowlett)
#### Post date: [September 13, 2014, 4:16am UTC](https://community.particle.io/t/giving-special-instructions-to-specific-cores-with-multiple-cores-flashed-with-the-same-spark-app/6931/1 "2014-09-13T04:16:19Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![avidan](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/avidan/32/84_2.png) [@avidan](https://community.particle.io/u/avidan)
#### Post date: [September 13, 2014, 5:49am UTC](https://community.particle.io/t/giving-special-instructions-to-specific-cores-with-multiple-cores-flashed-with-the-same-spark-app/6931/2 "2014-09-13T05:49:32Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![avidan](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/avidan/32/84_2.png) [@avidan](https://community.particle.io/u/avidan)
#### Post date: [September 13, 2014, 5:50am UTC](https://community.particle.io/t/giving-special-instructions-to-specific-cores-with-multiple-cores-flashed-with-the-same-spark-app/6931/3 "2014-09-13T05:50:00Z")

</div>

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

---

<div class="post-metadata">

### Author: ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)
#### Post date: [September 13, 2014, 6:05am UTC](https://community.particle.io/t/giving-special-instructions-to-specific-cores-with-multiple-cores-flashed-with-the-same-spark-app/6931/4 "2014-09-13T06:05:17Z")

</div>

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. 🙂

---

<div class="post-metadata">

### Author: ![noahrowlett](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/noahrowlett/32/3042_2.png) [@noahrowlett](https://community.particle.io/u/noahrowlett)
#### Post date: [September 13, 2014, 6:30am UTC](https://community.particle.io/t/giving-special-instructions-to-specific-cores-with-multiple-cores-flashed-with-the-same-spark-app/6931/5 "2014-09-13T06:30:47Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)
#### Post date: [September 13, 2014, 7:10am UTC](https://community.particle.io/t/giving-special-instructions-to-specific-cores-with-multiple-cores-flashed-with-the-same-spark-app/6931/6 "2014-09-13T07:10:18Z")

</div>

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”.

---

<div class="post-metadata">

### Author: ![noahrowlett](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/noahrowlett/32/3042_2.png) [@noahrowlett](https://community.particle.io/u/noahrowlett)
#### Post date: [September 13, 2014, 7:24am UTC](https://community.particle.io/t/giving-special-instructions-to-specific-cores-with-multiple-cores-flashed-with-the-same-spark-app/6931/7 "2014-09-13T07:24:42Z")

</div>

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 😄

---

<div class="post-metadata">

### Author: ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)
#### Post date: [September 13, 2014, 8:10am UTC](https://community.particle.io/t/giving-special-instructions-to-specific-cores-with-multiple-cores-flashed-with-the-same-spark-app/6931/8 "2014-09-13T08:10:05Z")

</div>

I see 👀

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

---

<div class="post-metadata">

### Author: ![avidan](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/avidan/32/84_2.png) [@avidan](https://community.particle.io/u/avidan)
#### Post date: [September 13, 2014, 10:18am UTC](https://community.particle.io/t/giving-special-instructions-to-specific-cores-with-multiple-cores-flashed-with-the-same-spark-app/6931/9 "2014-09-13T10:18:08Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![noahrowlett](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/noahrowlett/32/3042_2.png) [@noahrowlett](https://community.particle.io/u/noahrowlett)
#### Post date: [September 13, 2014, 5:40pm UTC](https://community.particle.io/t/giving-special-instructions-to-specific-cores-with-multiple-cores-flashed-with-the-same-spark-app/6931/10 "2014-09-13T17:40:05Z")

</div>

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 🙂

---

<div class="post-metadata">

### Author: ![noahrowlett](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/noahrowlett/32/3042_2.png) [@noahrowlett](https://community.particle.io/u/noahrowlett)
#### Post date: [September 13, 2014, 6:09pm UTC](https://community.particle.io/t/giving-special-instructions-to-specific-cores-with-multiple-cores-flashed-with-the-same-spark-app/6931/11 "2014-09-13T18:09:34Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)
#### Post date: [September 13, 2014, 9:04pm UTC](https://community.particle.io/t/giving-special-instructions-to-specific-cores-with-multiple-cores-flashed-with-the-same-spark-app/6931/12 "2014-09-13T21:04:43Z")

</div>

Another dumb question - that I do bestest 😉

> [@noahrowlett](#):
>
> spark cores w/ 8 analog outputs, there are ~14 buttons we need to map to

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.

---

<div class="post-metadata">

### Author: ![noahrowlett](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/noahrowlett/32/3042_2.png) [@noahrowlett](https://community.particle.io/u/noahrowlett)
#### Post date: [September 13, 2014, 9:11pm UTC](https://community.particle.io/t/giving-special-instructions-to-specific-cores-with-multiple-cores-flashed-with-the-same-spark-app/6931/13 "2014-09-13T21:11:48Z")

</div>

> 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!

---

<div class="post-metadata">

### Author: ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)
#### Post date: [September 13, 2014, 9:23pm UTC](https://community.particle.io/t/giving-special-instructions-to-specific-cores-with-multiple-cores-flashed-with-the-same-spark-app/6931/14 "2014-09-13T21:23:19Z")

</div>

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.
