Switching power with the Arduino over a I2C connected PCF8574: Unterschied zwischen den Versionen
Aus DL8RDS Wiki
Dl8rds (Diskussion | Beiträge) |
Dl8rds (Diskussion | Beiträge) |
||
(Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt) | |||
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 == | ||
+ | |||
+ | You can watch the movie which explains this subproject on my Youtube channel. |
Aktuelle Version vom 16. Juli 2010, 22:46 Uhr
Inhaltsverzeichnis
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
- http://www.arduino.cc/en/Reference/Wire The WIRING "Wire" library
- http://www.neufeld.newton.ks.us/electronics/?p=241 A project in which the workings of the I2C protocol are well described
- www.nxp.com/documents/data_sheet/PCF8574.pdf The Datasheet for the PCF8574
3 The Scheme
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.