Getting 16 digital inputs connected to the cloud

Hi all, for a new project I need to light up 16 NeoPixel Rings, for which I got a solution. But at the same time, I want to connect 16 momentary buttons/switches to the Spark and as one is going HIGH/LOW I want to capture that info and send that info out to the web.

  1. the first problem is how get 16 inputs done - I intend to use this MUX board which means I consume 4 digital pins on the Spark to get a total of 16 channels. I would then loop through the channels and check if a button has gone LOW for example. Does anyone see an issue with using the 16channel breakout board - or is there a smarter and better way to connect 16 buttons? I still need a few other pins, so I don’t want to consume all the spark pins

  2. I need to get that info out to the web, that’s where it is - still - getting a bit tricky. Callbacks and server-sent events are not yet supported, if they were I would use them (Does anyone have a rough timeline? If a beta is out in 2 weeks I’d wait…). My current plan is to save the open buttosn in a variable, e.g. like “b1,b2” whcih means b1 is open and b2 is open. Then I could poll for that variable from outside. I hate polling, but it seems to be the only solution right now.

Can I expose String variables with Spark.variable()? How long may these Strings be?
And again, if anyone from Spark had a rough timeline when to expect the event/server sent event/callback feature, that would be super great!!!


You need a serial-in parallel-out IC, I would use one of the following solutions:

The board you linked is a MUX/DeMUX with both Analog and Digital capabilities: definitely much more than you need for your project.

I don’t see anything bad in polling, especially if you make wise use of HTTP headers for cache controls. Nonetheless I would suggest to use a JSON structure, if possible, rather than a concatenated string. What about

  "actives": [2, 4, 6]

For the I/O, why not use an I2C i/o expander like this one from sparkfun. Besides using only 2 I2C pins, it has a built-in keypad scanner which I suspect you could adapt to your 16 buttons.


Thx for your reply - how would you create that json structure - concactenating strings? My idea to “expose” the data which switch is turned on at the end was around using bits - e.g. I’d turn on bit 0-15 of an integer using the bitWrite() functions and then simply return that integer, which gets on teh server turned into the individual bits again. JSON is of course simpler to read.

So can one expose a String variable then with Spark.variable() I assume… in the examples I just see integer values.

This feature (now called Spark.publish()) will be released in the next two weeks!

very sweet. so that will allow me to decide in my own code, e…g in the loop() when I want to call it. I assume I can call an “endpoint/callback” plus add some data, right? Very cool.

I haven’t tried it myself, but I was thinking of exposing an array of uint8_t as variable: that should be transformed in the JSON structure I suggested, but as I said I haven’t tried it myself.

The bit method is surely more adequate to microcontrollers world, but it will not be as easy to read. In case the array thing doesn’t work as I would expect probably a string concatenation can be achieved within a function which iterates on the bitmask.