Go Down

Topic: Running out of pins. (Read 778 times) previous topic - next topic

mcreefer

I'm working on a prototype and need to hook up a good amount of hardware to my arduino. I was going to use the nano but if any of you know of one that could handle the load listed below please let me know.

7 PWM pins for LEDS/Fans.
simple 2 line LCD.
keypad, was looking at this one. https://www.sparkfun.com/products/10411
temp sensor.
Real time clock.


Any advice? The LCD and Keypad are killing me on free pins.

Also one other question. If the keypad and LCD are used to adjust the timer values on the sketch are they retained on power loss or does it load up the original sketch?

MikMo

You could use a serial LCD, that would save quite a few pins.

There's also IO expanders like this

http://arduino-related.livejournal.com/1591.html

Krodal

The nano has 6 PWM outputs : http://arduino.cc/en/Main/ArduinoBoardNano
But for a led, you could use the SoftPWM : http://code.google.com/p/rogue-code/wiki/SoftPWMLibraryDocumentation
But the SoftPWM uses TIMER2, so that might be a problem if all of the 6 normal PWM outputs are in use.

The analog inputs can be used as digital pins. So you have 13 + 8 - 2 - 2 = 17 pins available (13 digital, 8 analog, rx and tx already in use, i2c in use).

A common RTC is the DS1307. It uses i2c. If you have a temperature sensor with i2c it doesn't need extra pins.
Four (?) pins for the keyboard.
Six pins for PWM, and one pin for simulated PWM for a led.
That makes 17 - 4 - 6 - 1 = 8 pins left for the display.
If you select the 4-bit databus for the display, you need 7 pins.
In the end, you even have 1 pin as a spare.

My advice : use a shift register 74HC595 for the display and perhaps also for leds. That way you have a few pins spare, because during a project I always need more pins than what I had in mind.

Far-seeker


Also one other question. If the keypad and LCD are used to adjust the timer values on the sketch are they retained on power loss or does it load up the original sketch?


If there is a reset or power loss you the sketch will load and run just like the first time after it was downloaded.  That means that the memory locations SRAM used for the variables will either be potentially random or any value assigned to them when they are defined in the code.  It is possible to store the data, either using the EEPROM space built into the ATMega ICs or an external data storage device (e.g. a dedicated EEPROM IC, SD Card, etc...).

mcreefer



Also one other question. If the keypad and LCD are used to adjust the timer values on the sketch are they retained on power loss or does it load up the original sketch?


If there is a reset or power loss you the sketch will load and run just like the first time after it was downloaded.  That means that the memory locations SRAM used for the variables will either be potentially random or any value assigned to them when they are defined in the code.  It is possible to store the data, either using the EEPROM space built into the ATMega ICs or an external data storage device (e.g. a dedicated EEPROM IC, SD Card, etc...).


So if I use my onboard EEPROM I would just need an option on the LCD menu that writes the changed values to the EEPROM... So I would load the first sketch on the arduino and write an "if" line that checks if anything is on the EEPROM. If nothing is on there copy the values that will change to the EEPROM. If something is on there copy the values into the running sketch... Is that a correct dumbed down way of how this works?

Far-seeker


So if I use my onboard EEPROM I would just need an option on the LCD menu that writes the changed values to the EEPROM... So I would load the first sketch on the arduino and write an "if" line that checks if anything is on the EEPROM. If nothing is on there copy the values that will change to the EEPROM. If something is on there copy the values into the running sketch... Is that a correct dumbed down way of how this works?


Well, sort of... 

Fundamentally the EEPROM is just an array of logic gates that are either 0 (i.e. LOW) or 1 (i.e. HIGH), so there will always be some number at an address even if it's a random sequence of 1s and 0s.  What you would need to do is set aside a specific memory address that you wirte a pre-determined value if you have actually saved settings you want to retrieve later, much like a flag variable.  Then in your setup() function you'd use and IF statement to check against the predetermined value, and if it's there then you retrieve the settings from other address locations in the EEPROM.

terryking228

I2C is nice.. 2 pins can run a 2 or 4 line display like this: http://goo.gl/qOVVr and other I2C devices like RTC can share the same pins.

Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

mcreefer



So if I use my onboard EEPROM I would just need an option on the LCD menu that writes the changed values to the EEPROM... So I would load the first sketch on the arduino and write an "if" line that checks if anything is on the EEPROM. If nothing is on there copy the values that will change to the EEPROM. If something is on there copy the values into the running sketch... Is that a correct dumbed down way of how this works?


Well, sort of... 

Fundamentally the EEPROM is just an array of logic gates that are either 0 (i.e. LOW) or 1 (i.e. HIGH), so there will always be some number at an address even if it's a random sequence of 1s and 0s.  What you would need to do is set aside a specific memory address that you wirte a pre-determined value if you have actually saved settings you want to retrieve later, much like a flag variable.  Then in your setup() function you'd use and IF statement to check against the predetermined value, and if it's there then you retrieve the settings from other address locations in the EEPROM.


Very well put. I think this will come in handy. I also think a serial lcd is the way to go for right now. And I will try and trim it down to 6 PWM pins for the sake of keeping it simple. The 7th one was going to controle the fanspeed via mosfet. Any have any other ideas on how to controle it without a PWM pin?

Go Up