Switching power with the Arduino over a I2C connected PCF8574: Unterschied zwischen den Versionen

Aus DL8RDS Wiki
Wechseln zu: Navigation, Suche
 
Zeile 14: Zeile 14:
  
 
[[Image:pcf8574_i2c.jpg|400px]]
 
[[Image:pcf8574_i2c.jpg|400px]]
 +
 +
== The Code ==
 +
 +
#define CARD_ADR (0x4 << 3 | 0x0) // address 0100000
 +
 +
#include <Wire.h>
 +
 +
void setup()
 +
{
 +
  Wire.begin(); // join i2c bus (address optional for master)
 +
}
 +
 +
void loop()
 +
{
 +
  /* switch on P0 */
 +
  Wire.beginTransmission(CARD_ADR);
 +
  Wire.send(B00000001);
 +
  Wire.endTransmission();
 +
  delay(1000);
 +
 
 +
  /* switch off all pins */
 +
  Wire.beginTransmission(CARD_ADR);
 +
  Wire.send(B00000000);
 +
  Wire.endTransmission();
 +
  delay(1000); 
 +
 +
  /* switch on P1 */
 +
  Wire.beginTransmission(CARD_ADR);
 +
  Wire.send(B00000010);
 +
  Wire.endTransmission();
 +
  delay(1000);
 +
 
 +
  /* switch off all pins */
 +
  Wire.beginTransmission(CARD_ADR);
 +
  Wire.send(B00000000);
 +
  Wire.endTransmission();
 +
  delay(1000); 
 +
 
 +
}
 +
  
 
== The Movie ==
 
== The Movie ==
  
 
You can watch the movie which explains this subproject on my Youtube channel.
 
You can watch the movie which explains this subproject on my Youtube channel.

Aktuelle Version vom 16. Juli 2010, 22:46 Uhr

1 Goal

This little project wants do demonstrate how it is possible to switch a great number of lines with one single Arduino controller. It uses the PCF8574P chip. It is actually a reimplementation of this project:

2 References

3 The Scheme

Pcf8574 i2c.jpg

4 The Code

#define CARD_ADR (0x4 << 3 | 0x0) // address 0100000

#include <Wire.h>

void setup()
{
  Wire.begin(); // join i2c bus (address optional for master)
}

void loop()
{
  /* switch on P0 */
  Wire.beginTransmission(CARD_ADR);
  Wire.send(B00000001);
  Wire.endTransmission();
  delay(1000);
 
  /* switch off all pins */
  Wire.beginTransmission(CARD_ADR);
  Wire.send(B00000000);
  Wire.endTransmission();
  delay(1000);   

  /* switch on P1 */
  Wire.beginTransmission(CARD_ADR);
  Wire.send(B00000010);
  Wire.endTransmission();
  delay(1000);
 
  /* switch off all pins */
  Wire.beginTransmission(CARD_ADR);
  Wire.send(B00000000);
  Wire.endTransmission();
  delay(1000);   
 
}


5 The Movie

You can watch the movie which explains this subproject on my Youtube channel.