コード例 #1
0
ファイル: gpio.c プロジェクト: Dzenik/WiringCB-python
static int doModuleMcp23017 (char *progName, int pinBase, char *params)
{
  int i2c ;

// Extract the I2C address:

  if (*params != ':')
  {
    fprintf (stderr, "%s: colon expected after pin-base number\n", progName) ;
    return FALSE ;
  }

  ++params ;
  if (!isdigit (*params))
  {
    fprintf (stderr, "%s: digit expected after pin-base number\n", progName) ;
    return FALSE ;
  }

  i2c = strtol (params, NULL, 0) ;
  if ((i2c < 0x03) || (i2c > 0x77))
  {
    fprintf (stderr, "%s: i2c address (0x%X) out of range\n", progName, i2c) ;
    return FALSE ;
  }

  mcp23017Setup (pinBase, i2c) ;

  return TRUE ;
}
コード例 #2
0
ファイル: main.c プロジェクト: dimasalomatine/robohealth
int main(int argc, char **argv)
{
	printf("hello\n");
	
	cfg_dt cfg=load_config(argc,argv);
	printf("config loaded==>loglevel=%d\t\nlogfile=%s\n",cfg.log_level,cfg.logfile);
	
	f(argc, argv);
	
	
	if(1!=f_sysinit(cfg.itype,cfg.use_exit_critical_function))
	{ 
		release_config(&cfg);
		return 1;
     }
     else if(cfg.itype!=3)
     {
	
	  mcp23017Setup (BASE_I2C, 0x20) ;
	  
	
	// For the push button to stop it...

  pinMode         (BASE_I2C + 15, INPUT) ;
  pullUpDnControl (BASE_I2C + 15, PUD_UP) ;
  
  while (digitalRead (BASE_I2C + 15) == 0)
        delay (1) ;
  }
  
    piThreadCreate (matrixUpdater) ;
     while(getchar()!=32);
	release_config(&cfg);
	return 0;
}
コード例 #3
0
ファイル: q2w.c プロジェクト: kkadatoka/rpi-dev
int main (void)
{
  int i, bit ;

  wiringPiSetup () ;
  mcp23017Setup (100, 0x24) ;

  printf ("Raspberry Pi - MCP23017 Test\n") ;

  for (i = 6 ; i < 8 ; i++)
    pinMode (100 + i, OUTPUT) ;

  pinMode         (100 + 0, INPUT) ;
  pullUpDnControl (100 + 0, PUD_UP) ;

  for (;;)
  {
    for (i = 0 ; i < 1024 ; ++i)
    {
      for (bit = 6 ; bit < 8 ; bit++)
        digitalWrite (100 + bit, i & (1 << bit)) ;
      delay (5) ;
      if (digitalRead (100 + 0) == 0)
      {
	      printf("Got Key\n");
	      delay (1) ;
	      digitalWrite(100 + 6, 0);
	      digitalWrite(100+7,0) ;
	      printf("Exiting now...\n");
	      return 0;
      }
    }
  }
  return 0 ;
}
コード例 #4
0
ファイル: mqtt_sensors.c プロジェクト: jezpi/pigoda
int 
sensors_init(sensors_t *sn) 
{
	sensor_t 	*sp;
	char 		*endptr;
	long 		i2caddress;
	int 		scnf = 0;

	wiringPiSetup();
	mcp23017Setup (300, 0x24) ;
	sp = sn->sn_head;
	do {
		if (sp->s_st != SENS_INIT || (sp->s_type == SENS_I2C && sn->sn_adc_configured > 0)) {
			if (sn->sn_adc_configured > 0) {
				sp->s_st = SENS_OK;
			}
			sp = sp->s_next;
			continue;
		}
		switch(sp->s_type) {
			case SENS_I2C:
				switch(sp->s_i2ctype) {
					case I2C_PCF8591P:
						i2caddress = strtol(sp->s_address, &endptr, 16);
						pcf8591Setup(PIN_BASE, i2caddress);
						sp->s_st = SENS_OK;
						sn->sn_adc_configured = 1;
						break;
					case I2C_BMP85:
						bmp85_init();
						sp->s_st = SENS_OK;
						/* MQTT_log */
						break;
					default:
						return (-1);
				}
				scnf++;
			break;
			case SENS_W1:
				sp->s_st = SENS_OK;
				/* NOP */
				scnf++;
			break;
			default:
				return (-1);
			
		}
		sp = sp->s_next;
	} while (sp != NULL && sp != sn->sn_head);
	

	return (scnf);
}
コード例 #5
0
ファイル: wpiExtensions.c プロジェクト: WiringPi/WiringPi
static int doExtensionMcp23017 (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 ;
  }

  mcp23017Setup (pinBase, i2c) ;

  return TRUE ;
}
コード例 #6
0
ファイル: lcd_senso.c プロジェクト: udo-hase/senso
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);
}
コード例 #7
0
ファイル: homeremote.cpp プロジェクト: rob0tuss1n/HomeRemote
int main() {
    system("gpio load i2c");
    sqlite3 *database;
    sqlite3_open("database.sqlite", &database);
    wiringPiSetupGpio();
    mcp23017Setup(100, 0x20);
    getTableData(database);
    pinMode(22, OUTPUT);
    pinMode(101, OUTPUT);
    while (1) {
        digitalWrite(101, 1);
        digitalWrite(22, 1);
        delay(1000);
        digitalWrite(101, 0);
        digitalWrite(22, 0);
        delay(1000);
    }
}
コード例 #8
0
ファイル: servo-mcp23017.c プロジェクト: imaicom/Pi-MCP23017
void main() {

	char *df = "/dev/input/js0";
	struct ps3ctls ps3dat;

	wiringPiSetup();
	mcp23017Setup (BASE, 0x20) ;
	softPwmCreate(100,0,100); // GP100 start-0 10ms
	softPwmCreate(101,0,100); // GP101 start-0 10ms

	if(!(ps3c_init(&ps3dat, df))) {

		do {
			if (ps3c_test(&ps3dat) < 0) break;
		} while (!(ps3c_input(&ps3dat)));
		
		ps3c_exit(&ps3dat);		
	}
}
コード例 #9
0
ファイル: button.c プロジェクト: MattyClay/PiPiano
int main (void)
{
    int i;
    wiringPiSetup();
    mcp23017Setup(100, 0x20);
    printf ("PiPiano-buttons!\n") ;
    for (i = 0 ; i < 13 ; ++i) {
        pinMode (100+i, INPUT);
        pullUpDnControl (100+i, PUD_UP);
    }
    for (;;) {
        printf("\nButtons pressed: ");
        for (i = 0 ; i < 13 ; ++i) {
            if (!digitalRead(100+i)) {
                printf("%d ",i);
            }
        }
    }
    return 0;
}
コード例 #10
0
ファイル: fastio.cpp プロジェクト: ClumsyApe/Marlin
	static void
	setup_mcp23017() {

		// TODO: Check this is correct
		const int i2c_address = 0x20;

		mcp23017Setup(pin_base, i2c_address);

		pinMode(X_MIN_PIN, INPUT);
		pinMode(Y_MIN_PIN, INPUT);
		pinMode(Z_MIN_PIN, INPUT);

		pinMode(PS_ON_PIN, OUTPUT);

		pinMode(BUZZER_PIN, OUTPUT);

		pinMode(RED_LED_PIN, OUTPUT);
		pinMode(GREEN_LED_PIN, OUTPUT);

		pinMode(HEATER_BED_PIN, OUTPUT);
		pinMode(HEATER_0_PIN, OUTPUT);
	}
コード例 #11
0
ファイル: zyncoder.c プロジェクト: zynthian/zyncoder
int init_zyncoder() {
	int i,j;
	for (i=0;i<MAX_NUM_ZYNSWITCHES;i++) {
		zynswitches[i].enabled=0;
		zynswitches[i].midi_cc=0;
	}
	for (i=0;i<MAX_NUM_ZYNCODERS;i++) {
		zyncoders[i].enabled=0;
		for (j=0;j<ZYNCODER_TICKS_PER_RETENT;j++) zyncoders[i].dtus[j]=0;
	}
	wiringPiSetup();

#ifdef MCP23017_ENCODERS
	uint8_t reg;

	mcp23017Setup(MCP23017_BASE_PIN, 0x20);

	// get the node cooresponding to our mcp23017 so we can do direct writes
	mcp23017_node = wiringPiFindNode(MCP23017_BASE_PIN);

	// setup all the pins on the banks as inputs and disable pullups on
	// the zyncoder input
	reg = 0xff;
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IODIRA, reg);
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IODIRB, reg);

	// enable pullups on the unused pins (high two bits on each bank)
	reg = 0xff;
	//reg = 0xc0;
	//reg = 0x60;
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_GPPUA, reg);
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_GPPUB, reg);

	// disable polarity inversion
	reg = 0;
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IPOLA, reg);
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IPOLB, reg);

	// disable the comparison to DEFVAL register
	reg = 0;
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_INTCONA, reg);
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_INTCONB, reg);

	// configure the interrupt behavior for bank A
	uint8_t ioconf_value = wiringPiI2CReadReg8(mcp23017_node->fd, MCP23x17_IOCON);
	bitWrite(ioconf_value, 6, 0);	// banks are not mirrored
	bitWrite(ioconf_value, 2, 0);	// interrupt pin is not floating
	bitWrite(ioconf_value, 1, 1);	// interrupt is signaled by high
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IOCON, ioconf_value);

	// configure the interrupt behavior for bank B
	ioconf_value = wiringPiI2CReadReg8(mcp23017_node->fd, MCP23x17_IOCONB);
	bitWrite(ioconf_value, 6, 0);	// banks are not mirrored
	bitWrite(ioconf_value, 2, 0);	// interrupt pin is not floating
	bitWrite(ioconf_value, 1, 1);	// interrupt is signaled by high
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IOCONB, ioconf_value);

	// finally, enable the interrupt pins for banks a and b
	// enable interrupts on all pins
	reg = 0xff;
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_GPINTENA, reg);
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_GPINTENB, reg);

	// pi ISRs for the 23017
	// bank A
	wiringPiISR(MCP23017_INTA_PIN, INT_EDGE_RISING, mcp23017_bank_ISRs[0]);
	// bank B
	wiringPiISR(MCP23017_INTB_PIN, INT_EDGE_RISING, mcp23017_bank_ISRs[1]);

#ifdef DEBUG
	printf("MCP23017 initialized: INTA %d, INTB %d\n",MCP23017_INTA_PIN,MCP23017_INTB_PIN);
#endif
#else
	mcp23008Setup (100, 0x20);
	init_poll_zynswitches();
#endif
	return 1;
}