Go Down

Topic: Writing to pins 0 or 1 (Read 569 times) previous topic - next topic

Krister Olsson

The millis() bug fix worked like a charm. Now I need help with one more thing for an exhibition in 3 weeks.

I'm using Arduino to control 13 servos. I have 12 hooked up to pins 2-13. Initially I was using digital servos, so I was able to hook the 13th servo up to pin 0 and control it using serialWrite commands (strangely enough).

I have had to since switch to analog servos for a number of reasons and can no longer use pin 0 with serialWrite as it sends my analog servo into a tailspin.

I know a forthcoming version of the software will allow the user to set which pins are used for serial I/O.

Is it possible to do that now through a quick patch? More specifically, is there a way to turn off serial I/O on pins 0/1 altogether?

Just need one extra pin! And it seems silly to throw another board at the problem.



You should be able to use pins 0 and 1 for either serial communication or digital i/o.  For the latter, just use pinMode(), digitalRead(), and digitalWrite() as with any other pin.  Just be sure not call any of the serial functions, as they'll interfere with the digital i/o.  

One catch is that you'll probably have to disconnect the servos on pins 0 and 1 when uploading your programs to the Arduino board.  Otherwise they can interfere with the serial data being sent from the computer.

Krister Olsson

Hmm. Doesn't seem to want to work for me. I did as suggested (used pinMode, didn't use serial, unplugged servo during upload), but my analog servos dont respond on pins one or two using digitalWrite. The remaining pins are fine.

Was this working in an earlier version? Perhaps this is a new bug?

Thanks for your help!


Whoops, I just remembered that older boards can only use pins 0 and 1 for the serial port.  Which version of the board do you have?  If it's too old, you'll need some advice from the Arduino hardware experts about connecting your last servo.

Alternatively, you might be able to use the analog input pins, but it will require some low-level end-runs around the Arduino API.  They're pins 0 to 5 on port C, which you can read and write using bit operation on the special variable PORTC, e.g.:

PORTC = 0x04; // turn on pin 2 (3rd bit) of port C

However, you might need some extra code to turn off the analog input functionality of those pins.  I'm not sure.  I'll try to take a look later this week after my thesis review.

Krister Olsson

Not sure which version. I swiped it from Casey a few weeks ago (it is USB).

Ah PORTC. I've done some PIC programming and a collaborator is an AVR guy so between us I'll see if I can  sort it out. (Though if you have some time later your help would of course be appreciated!)

Good luck on the thesis.


Thanks for the tip! It was super easy. Just set DDRC in setup for the PORTC pins you want to use, and voila, extra 6 outputs.


Please, could you give more details?

Maybe some  code?

Where can I found the arduino board version?



May 09, 2006, 10:56 am Last Edit: May 09, 2006, 10:57 am by armadillo Reason: 1
yeap, plis could you share some of your code with us newbies. I will like to connect 4 servos and im sure your code will help me a lot to understand and see how its done.



yep that could be a very helpfull tip krister
post it on the wiki please...
there is already a section for the "hidden powers" of arduino ;)
under the code library section
please add it there



Sort of veering off-topic here, but I've managed to hack up my own module which drives your basic HD44780 using only the analog pins. Very useful, since I tend not to use those for my projects (sensors and whatnot aren't my bag)

Go Up