Need more inputs! [Solved]

I’m using all 16 GPIO as outputs in my current project, but would like to have at least one, preferably two input buttons.
I’m not using the RX,TX pins, but from what I’ve read on the forum I can’t change the use of these pins, is that correct ?
It would also appear that I can’t “mess” with the mode button.

So is my only option to multiplex some of the outputs in order to free up a couple of GPIO for switches ?
My project is currently using the 16 outputs at hopefully reliable millisecond accurate timings, is this likely to be effected by multiplexing outputs ?

I would like to add a button to start playback of a saved sequence and i’m also looking into maybe adding a button that could be used to control when the core connects to the cloud (i.e “push this button to connect, push and hold for 5 secs to disconnect”)

If it really comes to it then I guess I have to sacrifice 2 outputs to get these two buttons, but if there’s any other way I’d be happy to give it a go :smile:

If you don’t mind adding an extra IC, this might be useful:

thanks @Moors7

I think I have something similar in the maker kit … if there is no alternative method, then I’d better get a run up for that learning curve!

@mala and @Moors7, a member recently asked for me to port a library for the MCP23017 I2C 16-port I/O expander. It can be found here:

Hopefully, that helps! :smile:


Thanks for posting the links peekay123.
I think I would like to try and use the 74HC595 shift register IC that I have in the maker kit rather than buying the MCP23017.
Although there don’t seem to be as many examples with this part, it may be a bit more difficult for me to learn.

@mala, great choice if you don’t need the fancy features! Look in Arduino land for lots of examples of using the 74HC595. There are some topics in this forum where the 74HC595 was used for driving parallel LCD displays as well. :smile:


Seems like a good choice, but then again all the examples for the Arduino appear to use a library and functions that are not immediately available on the SparkCore, so that’s gonna leave me scratching my head for a while!

@mala, the shiftOut and shiftIn functions are already in Core firmware:

void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)

uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)

Take a look at this arduino 595 page on how to use the shiftOut command. Of course, you will need to change the pins to Core pins. :smile:


A ha!

I couldn’t see them mentioned in the documentation so presumed they weren’t in the firmware.

No that’s not correct :slight_smile: , you can make TX and RX digital IO’s if you haven’t enabled the Serial1 peripheral. Just tested this:

#include "application.h"

bool s = false;

void setup() {
  // Enable On-board blue LED

  // Make TX and RX digital IO
  // Physically jumper TX to RX (with a 1k ohm resistor at first, 
  // in case you mess up the code. Once you know it works, 
  // you can switch to just a wire)

void loop() {
  // Toggle TX output, which feeds RX input
  s = !s;

  // Update onboard D7 LED with state of RX input
  digitalWrite(D7, digitalRead(RX) );

  // Delay so we can see it change

@BDub thanks thats good to know…
Bit scared to try it just now, as I’ve had to do the first ever factory reset on my core…after it refusing to have anything flashed to it from the Web IDE :frowning:

I wouldn’t worry too much about that… I’ve done factory resets a million times. So much so that to make it faster I put the Core in DFU mode and run a script that flashes the factory firmware just to speed it up a little. It’s a nice way to get back to a solid starting point for testing all kinds of stuff, like the OTA process or if you wrote some code that’s locking you out of OTA reprogramming.

Look at it as your safety net… don’t worry it’s there, go ahead and jump!

thanks to @peekay123 and @BDub :smile:

Have tried both your suggestions… using the TX/RX as GPIO seemed surprisingly simple.
The Shift register “hello world” example here
is very pretty !

I will experiment working them both into versions of my project
The shift register may eventually win (dependent on timing accuracy) as I’m thinking it could be handy to use the RX/TX to link multiple units together at some point.