Pages: [1]   Go Down
Author Topic: Difference between pins 2 and 11 ?  (Read 815 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

All,

I've got a project that includes a WiFi shield, an LCD and a button.

When I wire my switch to pin 2, it works as expected - while the switch is pressed, the state is LOW and actions can happen in the loop. When I wire my switch to pin 11 or 12 (and change buttonPin to 11 or 12 in the sketch), when I press it, the state then stays LOW forever, even when I release it.

I am currently using pin 2 for Data 7 on the LCD and I can't work out why they behave differently.

Also, with the wifi shield, can I still use pins 11, 12 and 13 as input / output pins ? Or does the shield need them like it does 10 and 7 ?

Thanks,
Logged

UK
Offline Offline
God Member
*****
Karma: 17
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll assume we're talking about an Uno here?

Pins 10,11,12,13 are the SPI port. SPI is also broken out on the ICSP header.

The wifi shield uses SPI, via the ICSP header, so you can't use pins 10-13 for normal I/O or you will interfere with the SPI bus

Both the wifi chip and the SD card use SPI, with the wifi CS on hardware CS Pin 10 and the SD Card on Pin 4.

So, with the wifi shield connected, you should not use pins 4,10,11,12 or 13.

EDIT: From your post you also just mention wiring a switch to make an input go Low, so presumably you're connecting this switch to Gnd. You don't mention any pull-up resistors (internal or external) so your High state could actually be a floating input. If you understand pullup/pulldown resistors then fine, else you may want to read up on the importance of putting a pin into a known state before you apply any other input.
« Last Edit: January 18, 2013, 07:43:44 pm by tack » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

An, yes - I should have mentioned it's an Uno.

So using a wifi shield really reduces the number of remaining inputs then - I didn't realise that. I'll have to remove the LCD from the project if I still want to use switches.

Thanks for the response.
Logged

UK
Offline Offline
God Member
*****
Karma: 17
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What LCD are you using?

If it's something like a 16x2 or 2x40 character based display then there are ways of reducing the number of pins required by using IO expansion, in the form of Shift Registers or I2C expanders.

A common way is an I2C 'backpack' which will allow you to run a 1602/2004 with just 2 data pins plus supply.

Using the New LiquidCrystal library you also have the option of Shift Registers in 3 wire, 2 wire or even 1 wire configurations.

There are also ways to get more inputs for switches/buttons. You could use a voltage divide on an Analog pin to do something like 5-6 buttons on a single pin. You could use Shift Registers to get multiple inputs from 3 pins; 8 from a single 8 bit SR or cascade for up to 16, 24, 32 etc from the same 3 Arduino pins (using ShiftIn for inputs, or ShiftOut for outputs). You can even matrix your buttons and make use of the Keypad library to lower pin count, i.e 16 buttons with 8 pins. You can even combine and use Keypad I2C library with an I2C expanders to get 16 buttons on 2 pins.

There are lots of options.
« Last Edit: January 19, 2013, 04:56:51 am by tack » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What LCD are you using?

If it's something like a 16x2 or 2x40 character based display then there are ways of reducing the number of pins required by using IO expansion, in the form of Shift Registers or I2C expanders.

It's a 16x2 - http://www.oomlout.co.uk/lcd-display-16-x-2-p-212.html. I've got a 74HC595 shift register that came with my starter kit - I didn't know that there was an option to reduce the pin use.

I'm using the LiquidCrystal library at the moment, so this sounds quite feasible.

Do you know of any tutorials on this or links that give a brief explanation of the electronics side ?

Thanks!
Logged

Siena Italia
Offline Offline
Full Member
***
Karma: 2
Posts: 149
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do remember that analog pins can be used as digital if you don't need them for analog.  So you may not be quite out of pins.
Ciao,
Lenny
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Do remember that analog pins can be used as digital if you don't need them for analog

I wasn't aware of that - thanks for the pointer. I'll google on how to use those as digital. I only need 3 analog pins for this project for sensor input, so that should give me a few more options.

I just thought that analog pins were analog and that was that smiley
Logged

UK
Offline Offline
God Member
*****
Karma: 17
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, you can digitalWrite and digitalRead the analog pins just fine. They respond to the A0, A1 etc labels but also simply as pins 14--19 too.

If you are going to look at reducing your 1602 pins down with a 595 SR then you want the New LiquidCrystal Library. This replaces the original Arduino one and provides support for 4 & 8 bit parallel, I2C, 3 wire SR, 2 wire SR and 1 wire SR. All the details on connection are provided with the library.

https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home

The new library is considerably faster than the original. 2 wire SR is said to be the fastest, but I haven't tried this myself yet.

Make sure you remove any orIginal LiquidCrystal or LiquidCrystal_I2C libraries before installing the new one (which replaces both). If you just rename the old folders then you will have conflicts.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks - I'll give that a try tomorrow for sure !
Logged

Pages: [1]   Go Up
Jump to: