Permalink
Browse files

Moving most of teh code from old repo

1 parent cb347ed commit 5f108d382493a56c9a2597523c70995025cbdc44 @numato committed Sep 24, 2015
Showing 1,523 changed files with 362,643 additions and 0 deletions.
@@ -0,0 +1,51 @@
+/*
+ * Relays 0,1 are connected to the Arduino digital pins 2,3 respectively using a ULN2003 IC.
+ * Writing HIGH to these digital pins makes corresponding relay to ON.
+ * Writing LOW to these digital pins makes corresponding relay to OFF.
+ */
+byte RelayPins[2] = {2,3};
+char Input[1];
+
+void setup()
+{
+ for(int i = 0; i < 2; i++) pinMode(RelayPins[i],OUTPUT); // Set all Relay pins to output
+ Serial.begin(9600);
+ delay(100);
+ Serial.println("2ChannelRelayShield demo sketch");
+ Serial.println("Enter the RelayNumber and Mode");
+ /*
+ * RelayNumber - 0 to 1
+ * Mode - 1 for ON and 0 for OFF
+ * ex: To make Relay1 ON send 11 and to OFF send 10
+ */
+ for(int j = 0; j < 2; j++) digitalWrite(RelayPins[j],LOW); // Default all Relays to off state
+}
+
+void loop()
+{
+ String Status;
+ if (Serial.available())
+ {
+ Serial.readBytesUntil(13, Input, 2); // Read bytes until pressed ENTER
+ int State = Input[1] - 48;
+ int RelayNum = Input[0]-48;
+ if((State == 0) || (State == 1))
+ {
+ digitalWrite(RelayPins[RelayNum], State); // Make Relay ON or OFF
+ }
+ else
+ {
+ Serial.println("Incorrect parameter");
+ }
+
+ Status = String("Relay ") + String(RelayNum) + String(" State is set to ") + String(State);
+
+ Serial.println(Status);
+
+ }
+}
+
+
+
+
+
@@ -0,0 +1,51 @@
+/*
+ * Relays 0,1,2,3 are connected to the Arduino digital pins 8,7,2,4 respectively using a ULN2003 IC.
+ * Writing HIGH to these digital pins makes corresponding relay to ON.
+ * Writing LOW to these digital pins makes corresponding relay to OFF.
+ */
+byte RelayPins[4] = {8,7,2,4};
+char Input[1];
+
+void setup()
+{
+ for(int i = 0; i < 4; i++) pinMode(RelayPins[i],OUTPUT); // Set all Relay pins to output
+ Serial.begin(9600);
+ delay(100);
+ Serial.println("4ChannelRelayShield demo sketch");
+ Serial.println("Enter the RelayNumber and Mode");
+ /*
+ * RelayNumber - 0 to 3
+ * Mode - 1 for ON and 0 for OFF
+ * ex: To make Relay2 ON send 21 and to OFF send 20
+ */
+ for(int j = 0; j < 4; j++) digitalWrite(RelayPins[j],LOW); // Default all Relays to off state
+}
+
+void loop()
+{
+ String Status;
+ if (Serial.available())
+ {
+ Serial.readBytesUntil(13, Input, 2); // Read bytes until pressed ENTER
+ int State = Input[1] - 48;
+ int RelayNum = Input[0]-48;
+ if((State == 0) || (State == 1))
+ {
+ digitalWrite(RelayPins[RelayNum], State); // Make Relay ON or OFF
+ }
+ else
+ {
+ Serial.println("Incorrect parameter");
+ }
+
+ Status = String("Relay ") + String(RelayNum) + String(" State is set to ") + String(State);
+
+ Serial.println(Status);
+
+ }
+}
+
+
+
+
+
@@ -0,0 +1,42 @@
+/*
+ * The selection pins(S0, S1, S2, S3) of 74HC4067 IC are connected to PORTA pins(PA0, PA1, PA2, PA3) of MCP23017(U4) IC.
+ * Common I/O of 74HC4067 IC is connected to Arduino analog pin A0
+ * Select jumper positions of AD4=0; AD5=0; AD6=1; to set the Address of U4 as 0x21
+ * Enable pin should be connected to ground to activate the I/O pins. Populate jumper GS7 to connect the Enable pin to GND.
+ * Select the Analog Pin(0-15) by defining the particular number in line number 18 of this code.
+ */
+
+#include"Wire.h"
+
+#define CommonInput A0
+#define AnalogPin 0 // Selects pin number 0 of Analog header
+
+void setup()
+{
+ Serial.begin(9600); // Begin Serial Communication
+ Wire.begin(); // Begin I2C Communication
+ /*
+ * The following code sets up I2C communication with MCP23017(U4), selects Bank 0 and set all PORTA pins as outputs.
+ * This is because the select pins of 74HC4067 are driven through MCP23017(U4). Please refer MCP23017 datasheet for
+ * register addresses.
+ */
+ Wire.beginTransmission(0x21); // Start I2C communication with MCP23017(U4)
+ Wire.write(0x00); // Set memory mapping address to IODIRA register of U4
+ Wire.write(0x00); // Set all PORTA pin of U4 to outputs
+ Wire.endTransmission(); // Ends I2C communication with U4
+
+ pinMode(CommonInput, INPUT); // Set Analog Common I/O(Arduino Analog A0) to INPUT
+}
+
+void loop()
+{
+ Wire.beginTransmission(0x21); // Start I2C communication with MCP23017(U4) IC
+ Wire.write(0x12); // Set memory mapping address to PORTA register of U4
+ Wire.write(AnalogPin); // Selects the Analog Pin to read (this will write the selection address to PORTA of U4)
+ Wire.endTransmission(); // Ends I2C communication with U4
+
+ int AdcValue = analogRead(CommonInput); // Read the ADC value from Common I/O(Arduino Analog A0)
+
+ Serial.println(AdcValue); // Print the ADC reading to serial monitor
+ delay(500);
+}
@@ -0,0 +1,82 @@
+/*
+ * There are two on board MCP23017(U2 and U4) IO Expander ICs on this Shield
+ * Select jumper positions of AD1=AD2=AD3=0, to set the Address of U2 as 0x20
+ * Select jumper positions of AD4=0; AD5=0; AD6=1, to set the Address of U4 as 0x21
+ * Digital Pins 0 - 7 belongs to PORTA and 8 - 15 belongs to PORTB of U2
+ * Digital Pins 24 - 27 belongs to PORTA and 16 - 23 belongs to PORTB of U4
+ */
+
+#include "Wire.h"
+
+byte U2PortA, U2PortB, U4PortA, U4PortB =0; // Define variables to hold I/O port readings.
+
+void setup()
+{
+ Serial.begin(9600); // Begin Serial Communication
+ Wire.begin(); // Begin I2C Communication
+ /*
+ * The following code starts I2C communication with MCP23017(U2).Please refer MCP23017 datasheet
+ * for register addresses. Sets all GPIOs of this IC to INPUT
+ */
+ Wire.beginTransmission(0x20); // Starts communication with MCP23017(U2) IC
+ Wire.write(0x00); // Set MCP23017 memory pointer to IODIRA address
+ Wire.write(0xFF); // Set all pins of PORTA to outputs
+ Wire.endTransmission(); // Ends I2C communication with MCP23017(U2) IC
+
+ Wire.beginTransmission(0x20); // Starts communication with MCP23017(U2) IC
+ Wire.write(0x01); // Set MCP23017 memory pointer to IODIRB address
+ Wire.write(0xFF); // Set all pins of PORTB to outputs
+ Wire.endTransmission(); // Ends I2C communication with MCP23017(U2) IC
+ /*
+ * The following code starts I2C communication with MCP23017(U4).Please refer MCP23017 datasheet
+ * for register addresses. Sets all GPIOs of this IC to INPUT
+ */
+ Wire.beginTransmission(0x21); // Starts communication with MCP23017(U4) IC
+ Wire.write(0x00); // Set MCP23017 memory pointer to IODIRA address
+ Wire.write(0xFF); // Set all PORTA pins to OUTPUT
+ Wire.endTransmission(); // Ends I2C communication with MCP23017(U4) IC
+
+ Wire.beginTransmission(0x21); // Starts communication with MCP23017(U4) IC
+ Wire.write(0x01); // Set MCP23017 memory pointer to IODIRB address
+ Wire.write(0xFF); // Set all PORTB pins to OUTPUT
+ Wire.endTransmission(); // Ends I2C communication with MCP23017(U4) IC
+}
+
+void loop()
+{
+ Wire.beginTransmission(0x20); // Starts I2C Communication with MCP23017(U2) IC
+ Wire.write(0x12); // Set MCP23017 memory pointer to PORTA address
+ Wire.endTransmission(); // Ends I2C communication with U2
+ Wire.requestFrom(0x20, 1); // Request one byte of data from MCP20317(U2)
+ U2PortA=Wire.read(); // Store the incoming byte of PORTA into "U2PortA"
+
+ Wire.beginTransmission(0x20); // Start I2C communication with U2
+ Wire.write(0x13); // Set MCP23017 memory pointer to PORTB address
+ Wire.endTransmission(); // Ends I2C communication with U2
+ Wire.requestFrom(0x20, 1); // Request one byte of data from MCP20317(U2)
+ U2PortB=Wire.read(); // Store the incoming byte of PORTB into "U2PortB"
+
+ Wire.beginTransmission(0x21); // Start I2C communication with MCP23017(U4)
+ Wire.write(0x12); // Set MCP23017 memory pointer to PORTA address
+ Wire.endTransmission(); // Ends I2C communication with U4
+ Wire.requestFrom(0x21, 1); // Request one byte of data from MCP20317(U4)
+ U4PortA=Wire.read(); // Store the incoming byte of PORTA into "U4PortA"
+
+ Wire.beginTransmission(0x21); // Start I2C communication with U4
+ Wire.write(0x13); // Set MCP23017 memory pointer to PORTB address
+ Wire.endTransmission(); // Ends I2C communication with U4
+ Wire.requestFrom(0x21, 1); // Request one byte of data from MCP20317
+ U4PortB=Wire.read(); // Store the incoming byte of PORTB into "U4PortB"
+
+ Serial.print("U2 PORTA: " );
+ Serial.println(U2PortA, BIN); // Print the contents of the PORTA register in binary
+ Serial.print("U2 PORTB: " );
+ Serial.println(U2PortB, BIN); // Print the contents of the PORTB register in binary
+ delay(500);
+
+ Serial.print("U4 PORTA: " );
+ Serial.println(U4PortA, BIN); // Print the contents of the PORTA register in binary
+ Serial.print("U4 PORTB: " );
+ Serial.println(U4PortB, BIN); // Print the contents of the PORTB register in binary
+ delay(500);
+}
@@ -0,0 +1,73 @@
+/*
+ * There are two on board MCP23017(U2 and U4) IO Expander ICs on this Shield
+ * Select jumper positions of AD1=AD2=AD3=0, to set the Address of U2 as 0x20
+ * Select jumper positions of AD4=0; AD5=0; AD6=1, to set the Address of U4 as 0x21
+ * Digital Pins 0 - 7 belongs to PORTA and 8 - 15 belongs to PORTB of U2
+ * Digital Pins 24 - 27 belongs to PORTA and 16 - 23 belongs to PORTB of U4
+ */
+
+#include "Wire.h"
+
+void setup()
+{
+ Wire.begin(); // Begin I2C bus
+ /*
+ * The following code starts I2C communication with MCP23017(U2).Please refer MCP23017 datasheet
+ * for register addresses. Sets all GPIOs of this IC to OUTPUT
+ */
+ Wire.beginTransmission(0x20); // Starts communication with MCP23017(U2) IC
+ Wire.write(0x00); // Set MCP23017 memory pointer to IODIRA address
+ Wire.write(0x00); // Set all pins of PORTA to outputs
+ Wire.endTransmission(); // Ends I2C communication with MCP23017(U2) IC
+
+ Wire.beginTransmission(0x20); // Starts communication with MCP23017(U2) IC
+ Wire.write(0x01); // Set MCP23017 memory pointer to IODIRB address
+ Wire.write(0x00); // Set all pins of PORTB to outputs
+ Wire.endTransmission(); // Ends I2C communication with MCP23017(U2) IC
+ /*
+ * The following code starts I2C communication with MCP23017(U4).Please refer MCP23017 datasheet
+ * for register addresses. Sets all GPIOs of this IC to OUTPUT
+ */
+ Wire.beginTransmission(0x21); // Starts communication with MCP23017(U4) IC
+ Wire.write(0x00); // Set MCP23017 memory pointer to IODIRA address
+ Wire.write(0x00); // Set all PORTA pins to OUTPUT
+ Wire.endTransmission(); // Ends I2C communication with MCP23017(U4) IC
+
+ Wire.beginTransmission(0x21); // Starts communication with MCP23017(U4) IC
+ Wire.write(0x01); // Set MCP23017 memory pointer to IODIRB address
+ Wire.write(0x00); // Set all PORTB pins to OUTPUT
+ Wire.endTransmission(); // Ends I2C communication with MCP23017(U4) IC
+}
+
+void DigitalIO(int i)
+{
+ Wire.beginTransmission(0x20);
+ Wire.write(0x12);
+ Wire.write(i); // Set or clear PORTA pins of U2
+ Wire.endTransmission();
+
+ Wire.beginTransmission(0x20);
+ Wire.write(0x13);
+ Wire.write(i); // Set or clear PORTB pins of U2
+ Wire.endTransmission();
+
+ Wire.beginTransmission(0x21);
+ Wire.write(0x12);
+ Wire.write(i); // Set or clear PORTA pins of U4
+ Wire.endTransmission();
+
+ Wire.beginTransmission(0x21);
+ Wire.write(0x13);
+ Wire.write(i); // Set or clear PORTB pins of U4
+ Wire.endTransmission();
+}
+
+void loop()
+{
+ DigitalIO(255); // All digital pins High
+ delay(100);
+ DigitalIO(0); // All digital pins Low
+ delay(100);
+}
+
+
Oops, something went wrong.

0 comments on commit 5f108d3

Please sign in to comment.