int main(int argc, char **argv) { # if 0 wiringPiSetupSys(); s500_sys_gpio_type(1); while(1) { digitalWrite(3, 1); printf(".....pin 3.........HIGH\n"); delay (6000) ; // mS digitalWrite(3, 0); printf(".....pin 3.........LOW\n"); delay (6000) ; // mS } #else wiringPiSetupSys(); while(1) { //注意: 以下的pin需要改为bcm 对应的pin digitalWrite(3, 1); printf(".....pin 3.........HIGH\n"); delay (6000) ; // mS digitalWrite(3, 0); printf(".....pin 3.........LOW\n"); delay (6000) ; // mS } #endif }
int main(void) { int i; /* Set up wiring pi library Using ...Sys assumes GPIOs have been exported previously and allows program to run in userland. Replace with ...Gpio to avoid need for exporting. This requires root privs to run. */ if (wiringPiSetupSys() == -1) { return 1; } /* Set as output */ pinMode(OUTPUT0, OUTPUT); for(i=0;i<5;i++) { /* Set output high */ digitalWrite(OUTPUT0, HIGH); delay(PERIOD); /* Set output low */ digitalWrite(OUTPUT0, LOW); delay(PERIOD); } /* Clean up - set as input */ pinMode(OUTPUT0, INPUT); return 0; }
void setup (void) { int i ; wiringPiSetupSys () ; if (piFaceSetup (200) == -1) exit (1) ; // Enable internal pull-ups for (i = 0 ; i < 8 ; ++i) pullUpDnControl (PIFACE + i, PUD_UP) ; // Calculate the actual charging voltage - standard calculation of // vCharge = r2 / (r1 + r2) * vBatt // // // -----+--- vBatt // | // R1 // | // +---+---- vCharge // | | // R2 C // | | // -----+---+----- vCharge = rDischarge / (rCharge + rDischarge) * vBatt ; // Start with no charge vCap = vCapLast = 0.0 ; }
int main (void) { uint8_t spiData [10] ; // set interface speed if (wiringPiSPISetup (0,100000) < 0) { fprintf (stderr, "Unable to open SPI device 0: %s\n", strerror (errno)) ; exit (1) ; } wiringPiSetupSys() ; wiringPiSetup() ; /* setup output ports */ pinMode(8, OUTPUT); /* reset */ pinMode(9, OUTPUT); /* rs */ /* reset LCD display */ digitalWrite(8,0); delayMicroseconds (100) ; digitalWrite(8,1); void write_cmd(int c) { digitalWrite(9,0); // set rs bit for cmd spiData[0]=c; wiringPiSPIDataRW (0, spiData, 1) ; }
int main(int argc, char **argv) { ros::init(argc, argv, "laserStepperController"); ros::NodeHandle nodeHandle; wiringPiSetupSys(); system("gpio export 19 output"); //pinMode(laserStepperDirectionPin, OUTPUT); system("gpio export 21 output"); //pinMode(laserStepperStepPin, OUTPUT); // Set the laser stepper direction digitalWrite(laserStepperStepPin, HIGH); ros::Rate(1.0); while(nodeHandle.ok()) { // keep moving the laser stepper digitalWrite(laserStepperStepPin, HIGH); usleep(1); digitalWrite(laserStepperStepPin, LOW); usleep(1); ros::spinOnce(); } // end while } // end main
int f_sysinit(int itype,int use_exit) { int ret=1; int code=-1; printf ( "<enter>f_sysinit(%d,%d)\n",itype,use_exit) ; switch(itype){ case 1: code=wiringPiSetup () ; break; case 2: // We need wiringPi setup in some way to make sure that // delay() works, but we don't need to be root to // use the I2C, so ... code=wiringPiSetupSys (); break; case 3: code=0; break; default: break; } if(code<0){ ret=0; fprintf (stderr, "<f_sysinit>wiringPiSetupSys setup failed\n") ; printf ( "wiringPiSetup setup failed with code %d \n",code) ; if(use_exit==1) { exit(1); } } printf ( "<exit>f_sysinit\n") ; return ret; }
/** * \brief Setup resources for SPI transactions * * Called Once to setup buffers, locks, and GPIO * \returns * If Setup has been called recently, 1 is returned as a warning. \n * If GPIO can't be loaded, the entire system is stopped with EXIT_FAILURE. \n * Otherwise, 0 is returned. */ int spiSetup(void) { // Setup resources for SPI transactions FILE *FPTR; FPTR = popen("gpio load spi", "r"); fclose(FPTR); // FIXME: use SLAVE_INT_PIN here FPTR = popen("gpio export 2 in", "r"); fclose(FPTR); //syslog(LOG_DEBUG, "Using pin %i", SLAVE_INT_PIN); if (wiringPiSetupSys() == -1) { syslog(LOG_ERR, "Couldn't setup wiringPi system!"); exit(EXIT_FAILURE); } if (wiringPiISR(SLAVE_INT_PIN, INT_EDGE_FALLING, &sgSerialSlaveSending) < 0) { syslog(LOG_ERR, "Couldn't setup interrupt on pin!"); exit(EXIT_FAILURE); } pthread_mutex_init(&transfer_lock, NULL); if (tx_buffer == NULL) { tx_buffer = queueInit(100); } else { syslog(LOG_WARNING, "spiSetup has already been called!"); return 1; } return 0; }
int main(int argc, char *argv[]) { /* output PIN is hardcoded for testing purposes see https://projects.drogon.net/raspberry-pi/wiringpi/pins/ for pin mapping of the raspberry pi GPIO connector */ int PIN = 17; int outlet = atoi(argv[1]); int command = atoi(argv[2]); if (wiringPiSetupSys () == -1) return 1; RCSwitch mySwitch = RCSwitch(); mySwitch.enableTransmit(PIN); switch(command) { case 1: mySwitch.switchOn(outlet, 4); break; case 0: mySwitch.switchOff(outlet, 4); break; default: printf("command[%i] is unsupported\n", command); return -1; } return 0; }
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 foreign_t pl_wiringPiSetupSys(){ if(wiringPiSetupSys() != 0){ printf("\nwiringPiSetup failed\n"); PL_fail; } PL_succeed; }
/* * Setup */ void setup(void) { // initialise the hardware // initialize variables // Initialize the communications from the thermistor task wiringPiSetupSys(); // Setup wiringPi piThreadCreate(readTemperature); // Start Thermistor reading task }
//-------------------------------------------------------------- void ofApp::setup(){ ofSetLogLevel(OF_LOG_VERBOSE); ofSetVerticalSync(true); // BCM // int pinMax = 4; int pinMap[4] = {18,27,22,23}; #ifdef TARGET_OPENGLES consoleListener.setup(this); if(wiringPiSetupSys() == -1){ printf("Error on wiringPi setup\n"); return; } #endif //this will let us just grab a video without recompiling ofDirectory currentVideoDirectory("videos"); if (currentVideoDirectory.exists()) { currentVideoDirectory.listDir(); vector<ofFile> files = currentVideoDirectory.getFiles(); for (int i=0; i<files.size(); i++) { if(i>=pinMax) break; Channel newChannel; newChannel.pin = pinMap[i]; #ifdef TARGET_OPENGLES // Pins pinMode(newChannel.pin, INPUT); // Video Player ofxOMXPlayerSettings settings; settings.videoPath = files[i].path(); settings.useHDMIForAudio = true; //default true settings.enableTexture = true; //default true settings.enableLooping = false; //default true settings.enableAudio = false; //default true, save resources by disabling ofxOMXPlayer* player = new ofxOMXPlayer(); player->setup(settings); #else ofVideoPlayer *player = new ofVideoPlayer(); player->loadMovie(files[i].path()); #endif newChannel.video = player; newChannel.state = false; channels.push_back(newChannel); } } nActive = -1; }
int main(void){ int setup = 0; printf("Start!!\n"); setup = wiringPiSetupSys(); wiringPiISR( READ_PIN, INT_EDGE_RISING, signal); while(setup != -1){ sleep(10000); } return 0; }
/* wiringPiSetupSys * * Parameters: None * Return Type: int */ mrb_value mrb_Pi_wiringPiSetupSys(mrb_state* mrb, mrb_value self) { /* Invocation */ int result = wiringPiSetupSys(); /* Box the return value */ mrb_value return_value = mrb_fixnum_value(result); return return_value; }
int main (int argc, char *argv []) { int bpm, msPerBeat, state = 0 ; unsigned int end ; printf ("Raspberry Pi PiFace Metronome\n") ; printf ("=============================\n") ; piHiPri (50) ; wiringPiSetupSys () ; // Needed for timing functions piFaceSetup (PIFACE) ; if (argc != 2) { printf ("Usage: %s <beates per minute>\n", argv [0]) ; exit (1) ; } if (strcmp (argv [1], "a") == 0) middleA () ; bpm = atoi (argv [1]) ; if ((bpm < 40) || (bpm > 208)) { printf ("%s range is 40 through 208 beats per minute\n", argv [0]) ; exit (1) ; } msPerBeat = 60000 / bpm ; // Main loop: // Put some random LED pairs up for a few seconds, then blank ... for (;;) { end = millis () + msPerBeat ; digitalWrite (PIFACE + 0, state) ; digitalWrite (PIFACE + 1, state) ; while (millis () < end) delayMicroseconds (500) ; state ^= 1 ; } return 0 ; }
void jshInit() { #ifdef USE_WIRINGPI if (geteuid() == 0) { printf("RUNNING AS SUDO - awesome. You'll get proper IRQ support\n"); wiringPiSetup(); } else { printf("NOT RUNNING AS SUDO - sorry, you'll get rubbish realtime IO. You also need to export the pins you want to use first.\n"); wiringPiSetupSys() ; } #endif int i; for (i=0;i<=EV_DEVICE_MAX;i++) ioDevices[i] = 0; jshInitDevices(); #ifndef __MINGW32__ if (!terminal_set) { struct termios new_termios; /* take two copies - one for now, one for later */ tcgetattr(0, &orig_termios); memcpy(&new_termios, &orig_termios, sizeof(new_termios)); /* register cleanup handler, and set the new terminal mode */ atexit(reset_terminal_mode); cfmakeraw(&new_termios); tcsetattr(0, TCSANOW, &new_termios); terminal_set = 1; } #endif//!__MINGW32__ for (i=0;i<JSH_PIN_COUNT;i++) { gpioState[i] = JSHPINSTATE_UNDEFINED; gpioEventFlags[i] = 0; } #ifdef SYSFS_GPIO_DIR for (i=0;i<JSH_PIN_COUNT;i++) { gpioShouldWatch[i] = false; } #endif isInitialised = true; int err = pthread_create(&inputThread, NULL, &jshInputThread, NULL); if (err != 0) printf("Unable to create input thread, %s", strerror(err)); }
void setup (void) { // Use the gpio program to initialise the hardware // (This is the crude, but effective) system ("gpio edge 17 falling") ; // Setup wiringPi wiringPiSetupSys () ; // Fire off our interrupt handler piThreadCreate (waitForIt) ; }
int lcd_init(){ wiringPiSetupSys () ; mcp23017Setup (AF_BASE, 0x20) ; adafruitLCDSetup (105) ; //setze Farbe lcdPosition (lcdHandle, 0, 0) ; lcdPuts (lcdHandle, "Warmwasserproben") ; lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, " Daten Aufnahme "); sleep (2); lcdPosition (lcdHandle, 0, 0) ; lcdPuts (lcdHandle, "Start ---> ") ; lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, "Press Select... "); waitForEnter () ; lcdClear (lcdHandle) ; adafruitLCDSetup (103) ; //setze Farbe return(0); }
int main (void) { int i, j ; wiringPiSetupSys () ; sn3218Setup (LED_BASE) ; for (;;) { for (i = 0 ; i < 256 ; ++i) for (j = 0 ; j < 18 ; ++j) analogWrite (LED_BASE + j, i) ; for (i = 255 ; i >= 0 ; --i) for (j = 0 ; j < 18 ; ++j) analogWrite (LED_BASE + j, i) ; } }
int main (void) { int pin ; int dataPtr ; int l, s, d ; printf ("Raspberry Pi - 6-LED Sequence\n") ; printf ("=============================\n") ; printf ("\n") ; printf (" Use the 2 buttons to temporarily speed up the sequence\n") ; wiringPiSetupSys () ; // Not using the Pi's GPIO here drcSetupSerial (GERT_BASE, 20, "/dev/ttyAMA0", 115200) ; for (pin = 0 ; pin < 6 ; ++pin) pinMode (pinMap [pin], OUTPUT) ; pinMode (GERT_BASE + 16, INPUT) ; // Buttons pinMode (GERT_BASE + 17, INPUT) ; pullUpDnControl (GERT_BASE + 16, PUD_UP) ; pullUpDnControl (GERT_BASE + 17, PUD_UP) ; dataPtr = 0 ; for (;;) { l = data [dataPtr++] ; // LED s = data [dataPtr++] ; // State d = data [dataPtr++] ; // Duration (10ths) if (s == 9) // 9 -> End Marker { dataPtr = 0 ; continue ; } digitalWrite (pinMap [l], s) ; delay (d * digitalRead (GERT_BASE + 16) * 15 + digitalRead (GERT_BASE + 17) * 20) ; } return 0 ; }
int main () { int x1, x2 ; double v1, v2 ; printf ("\n") ; printf ("Gertboard demo: Simple Voltmeters\n") ; printf ("=================================\n") ; // Always initialise wiringPi. Use wiringPiSys() if you don't need // (or want) to run as root wiringPiSetupSys () ; // Initialise the Gertboard analog hardware at pin 100 gertboardAnalogSetup (100) ; printf ("\n") ; printf ("| Channel 0 | Channel 1 |\n") ; for (;;) { // Read the 2 channels: x1 = analogRead (100) ; x2 = analogRead (101) ; // Convert to a voltage: v1 = (double)x1 / 1023.0 * 3.3 ; v2 = (double)x2 / 1023.0 * 3.3 ; // Print printf ("| %6.3f | %6.3f |\r", v1, v2) ; fflush (stdout) ; } return 0 ; }
void setup (void) { // Use the gpio program to initialise the hardware // (This is the crude, but effective bit) system ("gpio edge 24 falling") ; system ("gpio edge 10 falling") ; system ("gpio export 17 out") ; system ("gpio export 18 out") ; // Setup wiringPi wiringPiSetupSys () ; // Fire off our interrupt handler piThreadCreate (waitForLeftEncoder) ; piThreadCreate (waitForRightEncoder) ; }
void setup (void) { // Use the gpio program to initialise the hardware // (This is the crude, but effective bit) system ("gpio edge 0 falling") ; system ("gpio export 17 out") ; system ("gpio export 18 out") ; // Setup wiringPi wiringPiSetupSys () ; // Fire off our interrupt handler piThreadCreate (waitForIt) ; digitalWrite (17, 0) ; }
int main (void) { int pin, button ; printf ("Banana Pro wiringPi + LNDigital test program\n") ; printf ("===========================================\n") ; printf ("\n") ; printf ( "This program reads the buttons and uses them to toggle the first 4\n" "outputs. Push a button once to turn an output on, and push it again to\n" "turn it off again.\n\n") ; // Always initialise wiringPi. Use wiringPiSys() if you don't need // (or want) to run as root wiringPiSetupSys () ; piFaceSetup (LN_DIGITAL_BASE) ; // Enable internal pull-ups & start with all off for (pin = 0 ; pin < 8 ; ++pin) { pullUpDnControl (LN_DIGITAL_BASE + pin, PUD_UP) ; digitalWrite (LN_DIGITAL_BASE + pin, 0) ; } // Loop, scanning the buttons for (;;) { for (button = 0 ; button < 4 ; ++button) scanButton (button) ; delay (5) ; } return 0 ; }
int main(int argc, char **argv) { ros::init(argc, argv, "leftStepperController"); ros::NodeHandle nodeHandle; ros::Subscriber cmd_velSubscriber = nodeHandle.subscribe("cmd_vel", 10, cmd_velCallback); wiringPiSetupSys(); system("gpio export 7 output"); //pinMode(rightStepperDirectionPin, OUTPUT); system("gpio export 11 output"); //pinMode(rightStepperStepPin, OUTPUT); ros::Rate r(1.0); while(nodeHandle.ok()) ros::spinOnce(); r.sleep(); } // end main
/* * Class: com_pi4j_wiringpi_Gpio * Method: wiringPiSetupSys * Signature: ()I */ JNIEXPORT jint JNICALL Java_com_pi4j_wiringpi_Gpio_wiringPiSetupSys (JNIEnv *env, jclass obj) { wiringpi_init_mode = WPI_MODE_GPIO_SYS; return wiringPiSetupSys(); }
bool CGpio::StartHardware() { #ifndef WIN32 // TODO make sure the WIRINGPI_CODES environment variable is set, otherwise WiringPi makes the program exit upon error // Note : We're using the wiringPiSetupSys variant as it does not require root privilege if (wiringPiSetupSys() != 0) { _log.Log(LOG_ERROR, "GPIO: Error initializing wiringPi !"); return false; } #endif m_stoprequested=false; //Start worker thread that will be responsible for interrupt handling m_thread = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&CGpio::Do_Work, this))); m_bIsStarted=true; #ifndef WIN32 //Hook up interrupt call-backs for each input GPIO for(std::vector<CGpioPin>::iterator it = pins.begin(); it != pins.end(); ++it) { if (it->GetIsExported() && it->GetIsInput()) { _log.Log(LOG_NORM, "GPIO: Hooking interrupt handler for GPIO %d.", it->GetId()); switch (it->GetId()) { case 0: wiringPiISR(0, INT_EDGE_SETUP, &interruptHandler0); break; case 1: wiringPiISR(1, INT_EDGE_SETUP, &interruptHandler1); break; case 2: wiringPiISR(2, INT_EDGE_SETUP, &interruptHandler2); break; case 3: wiringPiISR(3, INT_EDGE_SETUP, &interruptHandler3); break; case 4: wiringPiISR(4, INT_EDGE_SETUP, &interruptHandler4); break; case 7: wiringPiISR(7, INT_EDGE_SETUP, &interruptHandler7); break; case 8: wiringPiISR(8, INT_EDGE_SETUP, &interruptHandler8); break; case 9: wiringPiISR(9, INT_EDGE_SETUP, &interruptHandler9); break; case 10: wiringPiISR(10, INT_EDGE_SETUP, &interruptHandler10); break; case 11: wiringPiISR(11, INT_EDGE_SETUP, &interruptHandler11); break; case 14: wiringPiISR(14, INT_EDGE_SETUP, &interruptHandler14); break; case 15: wiringPiISR(15, INT_EDGE_SETUP, &interruptHandler15); break; case 17: wiringPiISR(17, INT_EDGE_SETUP, &interruptHandler17); break; case 18: wiringPiISR(18, INT_EDGE_SETUP, &interruptHandler18); break; case 20: wiringPiISR(20, INT_EDGE_SETUP, &interruptHandler20); break; case 21: wiringPiISR(21, INT_EDGE_SETUP, &interruptHandler21); break; case 22: wiringPiISR(22, INT_EDGE_SETUP, &interruptHandler22); break; case 23: wiringPiISR(23, INT_EDGE_SETUP, &interruptHandler23); break; case 24: wiringPiISR(24, INT_EDGE_SETUP, &interruptHandler24); break; case 25: wiringPiISR(25, INT_EDGE_SETUP, &interruptHandler25); break; case 27: wiringPiISR(27, INT_EDGE_SETUP, &interruptHandler27); break; case 28: wiringPiISR(28, INT_EDGE_SETUP, &interruptHandler28); break; case 29: wiringPiISR(29, INT_EDGE_SETUP, &interruptHandler29); break; case 30: wiringPiISR(30, INT_EDGE_SETUP, &interruptHandler30); break; case 31: wiringPiISR(31, INT_EDGE_SETUP, &interruptHandler31); break; default: _log.Log(LOG_ERROR, "GPIO: Error hooking interrupt handler for unknown GPIO %d.", it->GetId()); } } } _log.Log(LOG_NORM, "GPIO: WiringPi is now initialized"); #endif sOnConnected(this); return (m_thread!=NULL); }
void setup(void) { wiringPiSetupSys(); piThreadCreate(waitForPin1); }
int main (void) { int i ; int step, ring, leg ; // Always initialise wiringPi: // Use the Sys method if you don't need to run as root wiringPiSetupSys () ; // Initialise the piGlow devLib with our chosen pin base piGlowSetup (1) ; // LEDs, one at a time printf ("LEDs, one at a time\n") ; for (; !keypressed () ;) for (leg = 0 ; leg < 3 ; ++leg) { for (ring = 0 ; ring < 6 ; ++ring) { pulseLed (leg, ring) ; if (keypressed ()) break ; } if (keypressed ()) break ; } clearKeypressed () ; // Rings, one at a time printf ("Rings, one at a time\n") ; for (; !keypressed () ;) for (ring = 0 ; ring < 6 ; ++ring) { pulseRing (ring) ; if (keypressed ()) break ; } clearKeypressed () ; // Legs, one at a time printf ("Legs, one at a time\n") ; for (; !keypressed () ;) for (leg = 0 ; leg < 3 ; ++leg) { pulseLeg (leg) ; if (keypressed ()) break ; } clearKeypressed () ; delay (1000) ; // Sequence - alternating rings, legs and random printf ("Sequence now\n") ; for (; !keypressed () ;) { for (i = 0 ; i < 20 ; ++i) for (step = 0 ; step < LEG_STEPS ; ++step) { for (leg = 0 ; leg < 3 ; ++leg) piGlowLeg (leg, legSequence [step * 3 + leg]) ; delay (80) ; } for (i = 0 ; i < 10 ; ++i) for (step = 0 ; step < RING_STEPS ; ++step) { for (ring = 0 ; ring < 6 ; ++ring) piGlowRing (ring, ringSequence [step * 6 + ring]) ; delay (80) ; } for (i = 0 ; i < 1000 ; ++i) { leg = random () % 3 ; ring = random () % 6 ; piGlow1 (leg, ring, random () % 256) ; delay (5) ; piGlow1 (leg, ring, 0) ; } } return 0 ; }
int main (void) { printf ("Raspberry Pi wiringPi GPIO speed test program\n") ; printf ("=============================================\n") ; // Start the standard way printf ("\nNative wiringPi method: (%8d iterations)\n", FAST_COUNT) ; wiringPiSetup () ; pinMode (7, OUTPUT) ; speedTest (7, FAST_COUNT) ; // GPIO printf ("\nNative GPIO method: (%8d iterations)\n", FAST_COUNT) ; wiringPiSetupGpio () ; pinMode (7, OUTPUT) ; speedTest (7, FAST_COUNT) ; // Phys printf ("\nPhysical pin GPIO method: (%8d iterations)\n", FAST_COUNT) ; wiringPiSetupPhys () ; pinMode (7, OUTPUT) ; speedTest (7, FAST_COUNT) ; // Switch to SYS mode: system ("/usr/bin/gpio export 7 out") ; printf ("\n/sys/class/gpio method: (%8d iterations)\n", SLOW_COUNT) ; wiringPiSetupSys () ; speedTest (7, SLOW_COUNT) ; return 0 ; }