Show Posts
Pages: [1]
1  Using Arduino / Sensors / Re: 74HC165 and 75HC565 on: August 15, 2011, 03:17:39 pm
sorry, what I meant by hardware was using the SPI library to use the built in SPI function of the Atmega verses using 4 other pins and using software like
Code:
BYTES_VAL_T read_shift_regs()
{
    byte bitVal;
    BYTES_VAL_T bytesVal = 0;

    /* Trigger a parallel Load to latch the state of the data lines,
    */
    digitalWrite(clockEnablePin, HIGH);
    digitalWrite(ploadPin, LOW);
    delayMicroseconds(PULSE_WIDTH_USEC);
    digitalWrite(ploadPin, HIGH);
    digitalWrite(clockEnablePin, LOW);

    /* Loop to read each bit value from the serial out line
     * of the SN74HC165N.
    */
    for(int i = 0; i < DATA_WIDTH; i++)
    {
        bitVal = digitalRead(dataPin);

        /* Set the corresponding bit in bytesVal.
        */
        bytesVal |= (bitVal << ((DATA_WIDTH-1) - i));

        /* Pulse the Clock (rising edge shifts the next bit).
        */
        digitalWrite(clockPin, HIGH);
        delayMicroseconds(PULSE_WIDTH_USEC);
        digitalWrite(clockPin, LOW);
    }
2  Using Arduino / Sensors / Re: 74HC165 and 75HC565 on: August 15, 2011, 01:43:47 pm
Cool...

My final project will consist of

14 optical water sensors
2 sets of lights (SSR for one and a transistor for the other)
5 pumps (SSR's for these)
4 fans (transistor)
1 temperature/humidity sensor
2 solenoids (SSR's for these)
these give me 14 inputs and 14 outputs so that leaves a small room for improvement/add ons

1 Flow sensor
1 LDR Circuit


along with Data Logging over the internet.

Hoping to put it all on the Arduino Ethernet board with only the transistors, shift registers, sensors and SSR's as added hardware.


Final thought,
Thank you all for helping. I will most likely be back a little further into the project.
3  Using Arduino / Sensors / Re: 74HC165 and 75HC565 on: August 15, 2011, 01:06:32 pm
OK...it works a bunch of == instead of = was a big coulperate and the final test code is
Code:
// inslude the SPI library:
#include <SPI.h>
/* digital pin 04 (SD Card SS pin)
 * digital pin 08 (Input SS pin) 74HC165
 * digital pin 09 (Output SS pin) 74HC595
 * digital pin 10 (Ethernet SS pin)
 * digital pin 11 (MOSI pin) 74HC595 Pin14
 * digital pin 12 (MISO pin) 74HC165 Pin9 (Q7)
 * digital pin 13 (SCK pin)
 */
//                                       __
const int InPutCE = 7; // 74HC165 Pin15 (CE)
//                                          __
const int InPutSelect = 8; // 74HC165 Pin1 (PL)
const int OutPutSelect = 9;// 74HC595 Pin12
unsigned int DataInput;
unsigned int OldDataInput;
int a = 0;
int i = 0;

void setup()
{
pinMode (OutPutSelect, OUTPUT);
pinMode (InPutSelect, OUTPUT);
pinMode (InPutCE, OUTPUT);
digitalWrite(InPutCE,HIGH);

SPI.begin();
}

void loop()
{
  int delayTime = 50;

    i=i+1;

    do
    {
     digitalWrite(InPutSelect,LOW);//Load inputs into the register
     digitalWrite(InPutSelect,HIGH);//Causes data to transfer serially at the DS with each clock pulse
     digitalWrite(InPutCE,LOW);//enables the clock
    // Transfer MSByte than LSByte
     DataInput = SPI.transfer(0x00);//transfers the MSB
     DataInput = (DataInput<<8)+SPI.transfer(0x00) ;//moves MSB to left byte than transfers the LSB to the right byte
     digitalWrite(InPutCE,HIGH);//Disables the clock
     delay(delayTime);
  //displays the swith status if new and old data are different
     if (DataInput != OldDataInput)
       {
        digitalWrite(OutPutSelect,LOW);
        // Transfer MSByte than LSByte
        SPI.transfer((DataInput>>8)&B11111111);
        SPI.transfer(DataInput&B11111111);
        // take the SS pin high to de-select the chip:
        digitalWrite(OutPutSelect,HIGH);
        delay(3000);
        a = a + 1;
        OldDataInput = DataInput;//makes the Data the new new "old data"
        }
     else
       {
         a = 0;
       }
    } while (a != 0); //basicaly continues untill the new data equals the old data.
   
    //Continues the original if statment for displaying the value of i in binary with leds...This part works with out a problem.
   digitalWrite(OutPutSelect,LOW);
   SPI.transfer((i >> 8) & B11111111);
   SPI.transfer(i & B11111111);
   digitalWrite(OutPutSelect,HIGH);
   delay(delayTime);
  }



On a side note...
Quote
I am trying to use as much hardware as possible
Funny most people try to minimize it smiley

If hardware is faster and takes up less memory space? than, why would most people minimize it?
4  Using Arduino / Sensors / Re: 74HC165 and 75HC565 on: August 15, 2011, 09:29:13 am
CrossRoads... I understand now. duh "i" will equal not does it equal.
5  Using Arduino / Sensors / Re: 74HC165 and 75HC565 on: August 15, 2011, 09:23:32 am
Nice work - good looking schematic!

OldDataInput == DataInput;//makes the Data the new new "old data"

Maybe try just 1 = here, for an assignment vs a comparison?

I'm fairly new to C and I believe that my line would work for my porpose, and I'm not quite sure what you mean by 1=here.

The issue I believe is here
Code:
    digitalWrite(InPutSelect,LOW);//Load inputs into the register
     delay(10);
     digitalWrite(InPutSelect,HIGH);//Causes data to transfer serially at the DS with each clock pulse
     delay(10);
     digitalWrite(InPutCE,LOW);//enables the clock
     delay(10);
    // Transfer MSByte than LSByte
     DataInput = SPI.transfer(0x00);//transfers the MSB
     DataInput = (DataInput<<8)&SPI.transfer(0x00);//moves MSB to left byte than transfers the LSB to the right byte
     digitalWrite(InPutCE,HIGH);//Disables the clock
      Serial.print("Datainput = ");
      Serial.println(DataInput,BIN);
      Serial.print("OldDataInput = ");
      Serial.println(OldDataInput,BIN);
     delay(delayTime);
DataInput is not being populated even when the switches are being toggled to lets say 0011100100000111. DataInput still reads 0x0000.
6  Using Arduino / Sensors / 74HC165 and 75HC565 on: August 15, 2011, 07:58:29 am
I hope I put this under the right topic.

I am automating a frog tank and am wanting to use 2 74HC165's for the sensor input and 2 74HC565 for the motor and light control. So what I have is this...
Code:
// inslude the SPI library:
#include <SPI.h>
/* digital pin 04 (SD Card SS pin)
 * digital pin 08 (Input SS pin) 74HC165
 * digital pin 09 (Output SS pin) 74HC595
 * digital pin 10 (Ethernet SS pin)
 * digital pin 11 (MOSI pin) 74HC595 Pin14
 * digital pin 12 (MISO pin) 74HC165 Pin9 (Q7)
 * digital pin 13 (SCK pin)
 */
//                                       __
const int InPutCE = 7; // 74HC165 Pin15 (CE)
//                                          __
const int InPutSelect = 8; // 74HC165 Pin1 (PL)
const int OutPutSelect = 9;// 74HC595 Pin12
unsigned int DataInput;
unsigned int OldDataInput;
int a = 0;
int i = 0;

void setup()
{
pinMode (OutPutSelect, OUTPUT);
pinMode (InPutSelect, OUTPUT);
pinMode (InPutCE, OUTPUT);
digitalWrite(InPutCE,HIGH);
Serial.begin(9600);
SPI.begin();
}

void loop()
{
  int delayTime = 50;

  //The i in the if statement is used to show a steady output to the 595 and reset when it reaches 0xFFFF
  if (i==65536){ //65536 = 2 bytes
    i==0;
  }
  else{
    i=i+1;
  }
 
 
// This Do section is a "Test Script" for getting the 165 to talk to the 595 VIA hardware SPI.
    do
    {
     digitalWrite(InPutSelect,LOW);//Load inputs into the register
     delay(10);
     digitalWrite(InPutSelect,HIGH);//Causes data to transfer serially at the DS with each clock pulse
     delay(10);
     digitalWrite(InPutCE,LOW);//enables the clock
     delay(10);
    // Transfer MSByte than LSByte
     DataInput = SPI.transfer(0x00);//transfers the MSB
     DataInput = (DataInput<<8)&SPI.transfer(0x00);//moves MSB to left byte than transfers the LSB to the right byte
     digitalWrite(InPutCE,HIGH);//Disables the clock
      Serial.print("Datainput = ");
      Serial.println(DataInput,BIN);
      Serial.print("OldDataInput = ");
      Serial.println(OldDataInput,BIN);
     delay(delayTime);
  //displays the swith status if new and old data are different
     if (DataInput != OldDataInput)
       {
        digitalWrite(OutPutSelect,LOW);
        // Transfer MSByte than LSByte
        SPI.transfer((DataInput>>8)&B11111111);
        SPI.transfer(DataInput&B11111111); //When testing Change "i" for "DataInput"
        // take the SS pin high to de-select the chip:
        digitalWrite(OutPutSelect,HIGH);
        delay(10000);
        a = a + 1;
        OldDataInput == DataInput;//makes the Data the new new "old data"
       }
     else
       {
         a = 0;
       }
    } while (a != 0); //basicaly continues untill the new data equals the old data.
   
    //Continues the original if statment for displaying the value of i in binary with leds...This part works with out a problem.
   digitalWrite(OutPutSelect,LOW);
   SPI.transfer((i >> 8) & B11111111);
   SPI.transfer(i & B11111111);
   digitalWrite(OutPutSelect,HIGH);
   delay(delayTime);
  }

I do not have an "O"scope so I put an LED and 330ohm between Q7 and ground and it is flashing indicating the transfer of data, but the data is not being saved to the variable.
I am trying to use as much hardware as possible and all I have found here has been software solutions to this.

The Attached PDF is the hardware schematic.

Pages: [1]