int main(void) { int cnt = 0; unsigned level = LOW; wiringPiSetupSys(); pcf8574Setup(BASE_8574, ADDR_I2C_8574); for (cnt = 0; cnt < NUM_IO_8574; cnt++) { pinMode(BASE_8574 + cnt, OUTPUT); } for(;;) { level = LOW; for (cnt = 0; cnt < NUM_IO_8574; cnt++) { digitalWrite(BASE_8574 + cnt, level); if ((cnt + 1) % NUM_IO_8574 / 2 == 0) { level = (level == LOW) ? HIGH : LOW; } } delay(500); } return EXIT_SUCCESS; }
static int doExtensionPcf8574 (char *progName, int pinBase, char *params) { int i2c ; if ((params = extractInt (progName, params, &i2c)) == NULL) return FALSE ; if ((i2c < 0x03) || (i2c > 0x77)) { verbError ("%s: i2c address (0x%X) out of range", progName, i2c) ; return FALSE ; } pcf8574Setup (pinBase, i2c) ; return TRUE ; }
void Driver::setup_pcf() { pcf8574Setup(100,0x20); pcf8574Setup(200,0x21); pcf8574Setup(300,0x22); pcf8574Setup(400,0x23); pcf8574Setup(500,0x24); pcf8574Setup(600,0x25); pcf8574Setup(700,0x26); pcf8574Setup(800,0x27); for(int i=1; i<9;i++) { for (int j=0; j<8;j++) { pinMode(i*100+j,INPUT); } } }
void ScanI2CBus() { int i; char buff[200]; // najpierw szukamy expanderów i2c na pcf8574 for (i = 0; i < 4; i++) { // zakładamy 4 ekspandery max hardware.i2c_PCF8574[i].fd = wiringPiI2CSetup (PCF8574_BASE_ADDR+i); // nie ma innego (?) sposobu na potwierdzenie czy urządzenie istnieje niż próba zapisu hardware.i2c_PCF8574[i].state = wiringPiI2CWrite (hardware.i2c_PCF8574[i].fd, wiringPiI2CRead(hardware.i2c_PCF8574[i].fd)); if (hardware.i2c_PCF8574[i].state != -1) { sprintf(buff,"Wykryty osprzęt: Expander pcf8574 o adresie %#x",PCF8574_BASE_ADDR+i); Log(buff,E_DEV); // dodatkowe porty trzeba zarejestrować pcf8574Setup (PCF8574_BASE_PIN+i*8,PCF8574_BASE_ADDR+i) ; } } //sprawdzamy czy jest obecne MinipH hardware.i2c_MinipH.fd = wiringPiI2CSetup(MINIPH_ADDR); hardware.i2c_MinipH.state = wiringPiI2CReadReg16(hardware.i2c_MinipH.fd, 0 ); if (hardware.i2c_MinipH.state != -1) { Log("Wykryty osprzęt: Mostek pomiarowy MinipH",E_DEV); } }
int main(int argc, char *argv[]) { struct tm *t; time_t tim; char buf[32]; const char* programName = argv[0]; const char* displayMessage = argv[1]; if(argc < 2) { fprintf(stderr, "Usage: %s display_message\n", programName); return -1; } /* initialize WiringPi */ wiringPiSetupSys(); /* initalize LCD */ lcdHandle = lcdInit(ROWS, COLUMNS, 4, AF_RS, AF_E, AF_D1, AF_D2, AF_D3, AF_D4, 0, 0, 0, 0); if(lcdHandle < 0) { fprintf(stderr, "lcdInit failed\n"); return -1; } /* initalize PCF8574 module, NOTE that the device address must be right & can be acquired by "i2cdetect -y 1" command */ pcf8574Setup(AF_BASE, 0x3f); /* turn on LCD backlight */ pinMode(AF_BL, OUTPUT); digitalWrite(AF_BL, 1); /* set LCD into write mode */ pinMode(AF_RW, OUTPUT); digitalWrite(AF_RW, 0); /* then we start to display various messages on the LCD screen */ lcdClear(lcdHandle); // clear the screen lcdPosition(lcdHandle, 3, 0); // set the cursor on the the 4th column & 1st row lcdPuts(lcdHandle, "RPi"); // print the text on the LCD at current cursor postion lcdPosition(lcdHandle, 4, 1); // set the cursor on the the 5th column & 2nd row lcdPuts(lcdHandle, "codelast"); waitForEnter(); lcdClear(lcdHandle); // clear the screen lcdPosition(lcdHandle, 0, 0); // set the cursor on the 1st column & 1st row lcdCursor(lcdHandle, true); // turn the cursor on lcdCursorBlink(lcdHandle, true); // turn the cursor blink on waitForEnter(); lcdCursor(lcdHandle, false); // turn the cursor off lcdCursorBlink(lcdHandle, false); // turn the cursor blink off lcdClear(lcdHandle); // clear the screen lcdPuts(lcdHandle, "Will scroll..."); waitForEnter(); while(true) { scrollMessage(0, COLUMNS, displayMessage); // scroll the specified message on the 1st row /* display current time on LCD */ tim = time(NULL); t = localtime(&tim); sprintf(buf, "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec); lcdPosition(lcdHandle, (COLUMNS - 8) / 2, 1); lcdPuts(lcdHandle, buf); } return 0; }