I have made a pinlayout plan for my new greenhouse project and I am running short on pins. As I understand analog pins can be used as digital pins and thats good because I need a lot of IO pins.
The SD logger uses the three SPI pins and a SS pin. Thats 4 pins.
The LCD shield uses pin 4,5,6,7,8,9 and maybe A0. Thats 7 pins.
And I need 14 pins more than what the SD and LCD shield uses.
Ive found this library that modifies the Liquidcrystal library to use SPI. By doing so the LCD only needs 3 pins, MOSI, SCK, and SS.
If this works I only need 21 pins (still one pin short). But now the LCD is using SPI and the SD logger is using SPI, then they can share their SPI bus pins right?
Now the questions and thoughts:
Can this be done? LCD running on 2 SPI pins and a SS pin?
Will the buttons on the LCD shield work?
Can the LCD and SD shield use the MOSI and SCK as common pins?
The easy way around this would be to buy and arduino MEGA, but I would really like to keep the costs on this project down.
I think you should elaborate on what the real problem most likely is - the sensors.
Further, and since you are logging to SD, you are likely to require a clock. This usually requires two pins, using the I2C bus, pins A4,A5 on a Uno. You can get LCD displays that can share that bus - two pins. Indeed, I believe they are the most common form of 16x2 and 20x4 displays, and I guess this is because it is the most economical with pins..
Soil humidity sensor (homemade) requires 3 digital pins.
About the SD datalogger. There is a RTC build into that, which I would use. Does that need more pins than just the SD datalogger pins? Sorry is this sounds like a stupid question, but I thought that the RTC and the SD card used the same pins, but maybe I am mistaken.
I am now looking into shift registers, but find i hard to see how those work with LCDs. Maybe someone can clearify?
JacobJ:
Can you please explain how the sensors are my problem?
Sensors use pins, If you are actually going to have a problem, it is more likely to be because of them. As it happens I fail to where any problem could be. The sensors you mention are all one-wire and, while you say you want two DS18B20s, they can share a pin.
That's a total of three plus three for the humidity device. Six
Here is a list of the sensors needed in this project
Lightsensor module board: [
DS18B20 temp sensors module board (2 is used,
DHT22 temp and humidity module board
Soil humidity sensor (homemade) requires 3 digital pins.
About the SD datalogger. There is a RTC build into that, which I would use. Does that need more pins than just the SD datalogger pins? Sorry is this sounds like a stupid question, but I thought that the RTC and the SD card used the same pins, but maybe I am mistaken.
[/quote]
It's not a stupid question. I would have thought it most unlikely that they share pins. I have never seen an SDF/RTC combination but every clock module I have seen uses I2C bus and I have never seen an SD module that does.
I am now looking into shift registers, but find i hard to see how those work with LCDs. Maybe someone can clearify?
I can't see how, or why, you would use a shift register on an LCD, but I can't see a problem either.
I do see eight vacant pins, though, so I guess that means you have several options
Okay now I have read more about that I2C bus and how it works and it is great!
Maybe this is a stupid question, but why is everything not made as I2C bus connectors? As I can see you can get RTC and LCDs fairly cheap and they can both run on the same two pins.. cool..
JacobJ:
but why is everything not made as I2C bus connectors
It does require a certain amount of intelligence in the device and is not the sort of thing that is sensibly added to a relay. I have wondered why nobody has produced an I2C shield. This would use just A4,5, and provide control over a great swag of dumb things. I believe this would provide software advantages to anybody who uses an RTC.
There is performance cost associated with using fewer pins.
With i2c the default clock rate is 100khz so clocking the bits to/from the i2c device
can be considerably slower than running parallel connections.
That said, often the additional performance and reduced overhead is not needed.
bperrybap:
That said, often the additional performance and reduced overhead is not needed.
Generally not when accessing LCD displays, for one thing.
Best to wait until you are not doing anything else (time-)critical.
Nick_Pyner:
I can't see how, or why, you would use a shift register on an LCD, but I can't see a problem either.
Actually, using a shift register to interface the LCD is a very popular approach, including using a R-C timeout to reduce it to a 2-wire interface. As bperrybap would know, having written the code.
Ah, well that's something new. I supposed I should have said why when it has already been done for you. But cobbling up your own sounds a bit like reinventing the wheel when I2C displays are so commonplace.
How many pins do I need to drive those motors? Is it the ENA(B) pins you refer to as not needed?
In the project I have two electric screwdrivers that will be controlled by the L298N motor driver module. One motor is for the opening and closing of the windows in my greenhouse, the other motor is connected to two curtains that can be turned up and down. I am not sure I need any PWM on those motors yet, but I would like to keep that option open if possible. But can the ENA(B) pin just be tied to 5V and then only use the two INput pins on each motor to control them?
The "enable" pins should switch off both "high" and "low" side drivers with two consequences. One is saving power, at least whatever current is actually required to bias the driver devices. The other is the matter of dynamic braking; having both sides of the motor grounded (or indeed, held to Vcc) will bring it to a stop much faster than leaving them open.
There are thus four possible functional states to which you can drive the motor; forward, reverse, open and stop. With the three inputs, you can implement them all with the eight combinations; all four combinations with enable false are "open", whilst the other two combinations with both inputs at the same level are "stop". If you do not want the "stop" combination, you can simply make one input the complement of the other and control with only two lines, or if you do not want the "open", you simply leave the enable permanently set.
If however, you fancy using all four possible states, you feed the enable (if active high) input with a NAND gate from the two other inputs so that if one is high and the other low, it runs the motor in the specified direction, if both are low it makes it stop and if both are high, the drivers are disabled and it runs "open".
So what you are saying is, that I can tie the ENA and ENB to 5V and make both drivers open. Then I can set the IN1 and IN2 to HIGH or LOW, both combinations leaving the motor not running. If either IN1 or IN2 is different from one and another, the motor will turn. Switching the state of both IN pins will make the motor go the other way around?
I don't think I said that. If you tie the enables permanently active, the motor will run in one direction if only one input is high, or the other direction if only the other input is high, and if either both are high or both are low, the motor will be dynamically braked to a stop.
If you want the option of either dynamically braking the motor, or leaving it free-running, you would need to use a NAND gate for each enable.