Skip to main content
added 427 characters in body
Source Link
Zeph
  • 445
  • 3
  • 11

And given all this, using a Mega2560 would probably be the easiest for a beginnerRecommendations, if a simple shift register for some simple digital inputs and outputs isn't sufficient for your set of sensors and actuators. It has more digital pins and more analog inputs and more PWM outputs. Most (tho not all) libraries will adapt just by changing pin numbers.

  1. If you can handle any fancy sensors or actuators with direct pins, and cover any simple ones with shift registers or I2C extender chips, that's a viable option. For example, if your code wants to check occasionally whether a flame has been sensed (digital version), or wants to turn on a motor, it's not that hard to go through a shift register instead of doing a direct pin access.

  2. If you go beyond that, and run out of pins for things that are much easier to handle when directly connected, then I suggest going to a Mega or Mega2560. It has more digital pins and more analog inputs and more PWM outputs. Most (tho not all) libraries will adapt just by changing pin numbers. It's much easier than rewriting libraries to use external digital and analog pins.

And given all this, using a Mega2560 would probably be the easiest for a beginner, if a simple shift register for some simple digital inputs and outputs isn't sufficient for your set of sensors and actuators. It has more digital pins and more analog inputs and more PWM outputs. Most (tho not all) libraries will adapt just by changing pin numbers.

Recommendations

  1. If you can handle any fancy sensors or actuators with direct pins, and cover any simple ones with shift registers or I2C extender chips, that's a viable option. For example, if your code wants to check occasionally whether a flame has been sensed (digital version), or wants to turn on a motor, it's not that hard to go through a shift register instead of doing a direct pin access.

  2. If you go beyond that, and run out of pins for things that are much easier to handle when directly connected, then I suggest going to a Mega or Mega2560. It has more digital pins and more analog inputs and more PWM outputs. Most (tho not all) libraries will adapt just by changing pin numbers. It's much easier than rewriting libraries to use external digital and analog pins.

Source Link
Zeph
  • 445
  • 3
  • 11

There are a number of ways to get more inputs and outputs, with different implications. And it depends on the types of sensors, and on the libraries or code snippets you want to use.

The first thing you need to do is list the sensors you want, along with the type of interface each uses; I use a spreadsheet.

For example, a flame sensor could just use a single digital output (going to a digital input on the Arduino), with the threshold set with a pot on the module. Or it could output an analog signal which goes to an analog input on the Arduino, allowing the code to detect intensity or set varying thresholds without needing to move the pot. Each approach has different implications.

There are still other sensor and actuator interfaces besides these two (simple digital and analog). Some give a variable value (like analog) but based on timing a pulse on a digital signal; this is how most inexpensive ultrasonic rangefinders work. And of course there are sensors which use standard (I2C or SPI) or proprietary (one-wire protocol, or the DHT-xx temp & humidity sensors).

Likewise some outputs will need PWM or other signally, beyond simple on/off.

Extra simple digital inputs, or outputs, can be had fairly easy with I2C extenders, or with shift registers. For example, checking a digital output flame sensor, or turning on a light.

Extra analog inputs can be done with analog multiplexing (like an electronic switch), or via external ADC modules using I2C or SPI.

If timing is required, there are larger potential problems. Often you would use a library to handle such things.

Libraries. Most sensor and actuator libraries will be written to use direct input and output pins on the Arduino. You may be able to pass a pin number when initializing, but if you are using a shift register or extender there's no way to tell the library how to use your custom extension. In this case you will have to roll our own code without using the library, or make a modified version of the library which does I/O through your hardware extension hardware.

Special Pin Functions. A second problem is special pin functions; if the library or code snippet you want to use expects to use a special feature of a pin (like a pin interrupt, or a timer input capture), that may not be available from your extension hardware, or may be extra work to handle. For example, some extenders may be able to signal an interrupt pin on the Arduino when one of their inputs changes - but you'll have to write your own interrupt handler to catch that, and replace the functionality of the direct pin interrupt.

Timing. And a third problem is that sometimes tight timing is hard to manage through extension hardware.

Most of these can be resolved with appropriate effort, sometimes easy and sometimes not. Look through your list of sensors and actuators; sort out which ones can most easily be attached to extension hardware (like a shift register), and which ones should be directly attached to the Arduino for simplicity or performance. You could be lucky.

And given all this, using a Mega2560 would probably be the easiest for a beginner, if a simple shift register for some simple digital inputs and outputs isn't sufficient for your set of sensors and actuators. It has more digital pins and more analog inputs and more PWM outputs. Most (tho not all) libraries will adapt just by changing pin numbers.