[solved] Digital I/O Status on startup

Hi,

Not sure this is the right section of the Forum, but it seemed the best...

I've developed a project on the Arduino Uno, which uses the Digital Outputs to control some solenoid valves. It runs fine, but when I power it on, it triggers activity on some of the I/O lines, and fires the solenoids. It seems to be happening on pins 0 and 1. I can understand it doing this when I upload the code due to the serial transmission, but can you stop it happening when you just power on?

I did have the solenoids on Pin 13, but it was firing the internal LED on startup, and causing the same problem, which is why I moved the solenoids to pins 0 and 1. I'm not using any serial communication in sketch BTW.

Thanks in advance,

Peter (GB)

In order for the bootloader to function it has to activate the USART. Which is very likely why there is activity on pins 0 and 1. You can have a bootloader or you can have pins 0 and 1 untouched but you cannot have both.

You are programming it via the bootloader over serial right? That means the board is bootloaded, which means it will pull the serial lines high while it's in bootloader mode (inactive serial lines are high, not low).

Don't use pins 0, 1, or 13 for things that can't be pulsed high when the chip turns on, or don't use the bootloader, and program the chip via ISP (note - you can get pin 13 off that list if you built a custom version of optiboot with the LED flashes disabled).

Any other pin is okay - though the pins are tristated on reset, so if they're driving fets, you need external pulldowns.

Thanks for the explanation. I am indeed using the bootloader over serial.

I'm using all the digital pins, but I can move them around so pins 0, 1 and 13 are driving the LCD display, rather than the solenoids, so that should solve the problem.

I guess as the LCD isn't initialised until the sketch runs, it won't have any issues with the pins firing in bootloader mode. I'll try it today.

The other "solution" I considered (after reading your replies) was to use a good old-fashioned manually-operated switch to isolate the relays until the sketch was running! But the pin rewiring would be neater. :)

Thanks again for your help.

Peter

opentelemark: I'm using all the digital pins, but I can move them around so pins 0, 1 and 13 are driving the LCD display, rather than the solenoids, so that should solve the problem.

Suspicious.

When someone says "I'm using all the digital pins", I immediately suspect they do not understand what the "analog" pins are.

That's an interesting comment, Paul. It makes me think I'm missing something!

My understanding is that the UNO has 14 digital pins that can be configured as inputs or outputs, some of which can also be configured as PWM quasi-analog outputs.

Also, my understanding is that it also has six analog input pins that have an ADC to read input voltages. As I am so short of digital inputs for the project, I am already using these as quasi-digital inputs by using a pull-up resistor, and grounding the pin with the switch, so I can spot whether the the voltage is high or low.

I think that's right, but your comment chimed with something I read on the forum this morning, where somebody said that the analog pins could also be used as digital outputs (which I didn't understand), and leaves me wondering whether I have missed a feature!

Have I ? :)

Thanks, Peter

Sure sounds like it!

On a UNO, the "analog" pins are digital pins complete with the usual internal pull-ups. You use digitalRead and digitalWrite on them.

If you do not want USB interfacing, you should be using a Pro Mini which is smaller, and has a form more appropriate for a final application and has two extra analog-only inputs to be used. If you did need USB, then a Nano.

The only reason to use a UNO in a final application is if you need to use "shields" designed for that format.

If you are running short on input pins, you may be failing to employ the appropriate design techniques such as multiplexing.

A0 to A5 can be addressed as 14 to 19 for digital functions:

byte pinX = 2; // 0 to 19 possible with '328P

pinMode (pinX, INPUT_PULLUP ); // or OUTPUT for all 20 pins

Well I never. That's really interesting - I didn't know that. :) Thank you. I don't think it was mentioned in the Arduino manual I had.

And thanks, Paul, for your other comments. Just for context, I'm very new to this, having only bought the UNO about a month ago, and it seemed like a good place to start. I've done lots of real-time control coding in the past, when things were MUCH more expensive. I built a controller for a plant cell bioreactor. On the coding side, I initially learnt FORTRAN, and have also programmed in 6502 assembler, and Pascal. My first code was on punched cards, in fact.

I don't know much about multiplexing, so I'll look into that as, for future projects. In this case, I have enough digital pins ;) for the project, so I won't need to multiplex.

I've really enjoyed coming back to this, and am just building a water feature control system for my garden, so I'm not too concerned about using a UNO, rather than a nano. But I shall look into a nano for the next project.

Thanks again for all your comments.

Peter