static rn2903_context _rn2903_preinit() { // make sure MRAA is initialized int mraa_rv; if ((mraa_rv = mraa_init()) != MRAA_SUCCESS) { printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv); return NULL; } rn2903_context dev = (rn2903_context)malloc(sizeof(struct _rn2903_context)); if (!dev) return NULL; // zero out context memset((void *)dev, 0, sizeof(struct _rn2903_context)); // first response wait time dev->cmd_resp_wait_ms = RN2903_DEFAULT_RESP_DELAY; // optional second response wait time dev->cmd_resp2_wait_ms = RN2903_DEFAULT_RESP2_DELAY; // init stored baudrate to RN2903_DEFAULT_BAUDRATE dev->baudrate = RN2903_DEFAULT_BAUDRATE; // uncomment for "early" debugging // dev->debug = true; return dev; }
mqx_context mqx_init(int16_t pin) { // make sure MRAA is initialized int mraa_rv; if ((mraa_rv = mraa_init()) != MRAA_SUCCESS) { printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv); return NULL; } mqx_context dev = (mqx_context) malloc(sizeof(struct _mqx_context)); if (dev == NULL) return NULL; /* Init aio pin */ dev->aio = mraa_aio_init(pin); if (dev->aio == NULL) { free(dev); return NULL; } /* Set the ADC ref, scale, and offset defaults */ dev->m_aRef = 5.0; dev->m_scale = 1.0; dev->m_offset = 0.0; return dev; }
void imuinit() { mraa_init(); i2c = mraa_i2c_init(1); sendi2c( GYRO_I2C_ADDR, FIFO_CTRL_REG_G, 0 ); sendi2c( GYRO_I2C_ADDR, CTRL_REG1_G, 0x0F ); //Normal mode, enable all axes //0xFF ); //??unknown config?? sendi2c( GYRO_I2C_ADDR, CTRL_REG2_G, 0x00); // Normal mode, high cutoff frequency sendi2c( GYRO_I2C_ADDR, CTRL_REG4_G, 0x10 ); // Set scale to 500 dps sendi2c( GYRO_I2C_ADDR, CTRL_REG5_G, 0x00 ); // FIFO Disabled, HPF Disabled sendi2c( XM_I2C_ADDR, FIFO_CTRL_REG, 0 ); sendi2c( XM_I2C_ADDR, CTRL_REG1_XM, 0xFF ); sendi2c( XM_I2C_ADDR, CTRL_REG2_XM, 0x00); //Set scale +/-2g sendi2c( XM_I2C_ADDR, CTRL_REG4_XM, 0x30 ); sendi2c( XM_I2C_ADDR, CTRL_REG5_XM, 0x94); sendi2c( XM_I2C_ADDR, CTRL_REG6_XM, 0x00); sendi2c( XM_I2C_ADDR, CTRL_REG7_XM, 0x00); /* return; while(1) { readGyro(); readAccel(); readMag(); printf("gx:%6.2f gy:%6.2f gz:%6.2f ax:%6.2f ay:%6.2f az:%6.2f mx:%6.2f my:%6.2f mz:%6.2f temp:%0.0f\n",gx,gy,gz,ax,ay,az,mx,my,mz,temp); usleep(20000); } */ }
led_context led_init(int pin){ // make sure MRAA is initialized int mraa_rv; if ((mraa_rv = mraa_init()) != MRAA_SUCCESS) { printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv); return NULL; } led_context dev = (led_context)malloc(sizeof(struct _led_context)); if (!dev) return NULL; dev->name = NULL; dev->gpioled = NULL; dev->led_pin = pin; dev->gpio = mraa_gpio_init(dev->led_pin); if (mraa_gpio_dir(dev->gpio, MRAA_GPIO_OUT) != MRAA_SUCCESS) { printf("%s: Unable to set pin %d as output.\n", __FUNCTION__, pin); free(dev); return NULL; } return dev; }
led_context led_init_str(const char* name){ // make sure MRAA is initialized int mraa_rv; if ((mraa_rv = mraa_init()) != MRAA_SUCCESS) { printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv); return NULL; } led_context dev = (led_context)malloc(sizeof(struct _led_context)); if (!dev) return NULL; dev->led_pin = -1; dev->gpio = NULL; dev->name = name; dev->gpioled = mraa_led_init(name); if (!dev->gpioled) { printf("%s: Unable to initialize gpioled device (%s).\n", __FUNCTION__, dev->name); free(dev); return NULL; } dev->max_brightness = mraa_led_read_max_brightness(dev->gpioled); return dev; }
es9257_context es9257_init(int32_t pin, int32_t min_pulse_width, int32_t max_pulse_width) { // make sure MRAA is initialized int mraa_rv; if ((mraa_rv = mraa_init()) != MRAA_SUCCESS) { printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv); return NULL; } es9257_context dev = (es9257_context) malloc(sizeof(struct _es9257_context)); if(dev == NULL){ printf("Unable to assign memory to the Servo motor structure"); return NULL; } dev->servo_pin = pin; // second is the min pulse width dev->min_pulse_width = min_pulse_width; // third is the max pulse width dev->max_pulse_width = max_pulse_width; dev->pwm = mraa_pwm_init(dev->servo_pin); if(dev->pwm == NULL){ printf("Unable to initialize the PWM pin"); } es9257_set_angle(dev, 0); return dev; }
ppd42ns_context ppd42ns_init(int pin) { ppd42ns_context dev = (ppd42ns_context)malloc(sizeof(struct _ppd42ns_context)); if (!dev) return NULL; dev->gpio = NULL; // make sure MRAA is initialized int mraa_rv; if ((mraa_rv = mraa_init()) != MRAA_SUCCESS) { printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv); ppd42ns_close(dev); return NULL; } // MRAA contexts... if ( !(dev->gpio = mraa_gpio_init(pin)) ) { printf("%s: mraa_gpio_init() failed\n", __FUNCTION__); ppd42ns_close(dev); return NULL; } mraa_gpio_dir(dev->gpio, MRAA_GPIO_IN); return dev; }
FskExport(FskErr) FskPinDigitalMRAA_fskLoad(FskLibrary library) { mraa_result_t result; result = mraa_init(); if ((result == MRAA_SUCCESS) || (result == MRAA_ERROR_PLATFORM_ALREADY_INITIALISED)) return FskExtensionInstall(kFskExtensionPinDigital, &gMRAAPinDigital); else return kFskErrOperationFailed; }
int main() { if (mraa_init() != MRAA_SUCCESS) { perror("Failed to initialize mraa\n"); return -1; } signal(SIGINT, sig_handler); //! [Interesting] // Instantiate a slide sensor on analog pin A0 slide_context sensor = slide_init(0); if (!sensor) { printf("slide_init() failed.\n"); return -1; } // Set the aref, scale, and offset slide_set_aref(sensor, 5.0); slide_set_scale(sensor, 1.0); slide_set_offset(sensor, -.1); printf("aRef: %0.03f scale: %0.03f offset: %0.03f\n\n", slide_get_aref(sensor), slide_get_scale(sensor), slide_get_offset(sensor)); // Every half a second, sample the sensor output while (shouldRun) { float normalized = 0.0; float raw_volts = 0.0; float volts = 0.0; slide_get_normalized(sensor, &normalized); slide_get_raw_volts(sensor, &raw_volts); slide_get_volts(sensor, &volts); printf("Normalized output: %0.03f, raw slide sensor output: %0.03f v " "adjusted output: %0.03f v\n", normalized, raw_volts, volts); upm_delay_ms(500); } //! [Interesting] printf("Exiting\n"); slide_close(sensor); return 0; }
void config(void) { mraa_init(); // Inicia a biblioteca MRAA ledPin = mraa_gpio_init(LED_PIN); btnPin = mraa_gpio_init(BTN_PIN); // Define que o terminal do LED é de saída mraa_gpio_dir(ledPin, MRAA_GPIO_OUT); // Ajusta o estado do LED para iniciar apagado mraa_gpio_write(ledPin, 0); }
// Initialization function void init() { // buzzer connected to A1 (aka digital out 15) mraa_init(); buzzer = new mraa::Gpio(15); buzzer->dir(mraa::DIR_OUT); stop_alarm(); // moisture sensor on analog (A2) moisture = new upm::GroveMoisture(2); }
void startMRAA( void ) { // printf( "\n I/O is enabled\n" ); mraa_init(); printf( " MRAA library Version: %s\n", mraa_get_version() ); mraa_platform_t platformType = mraa_get_platform_type(); printf( " Platform type: %d\n", platformType ); char *platformName = mraa_get_platform_name(); printf( " Platform name: %s\n", platformName ); }
int main() { uint8_t m[2]; m[0]=8; m[1]=255; mraa_init(); // can we put it in the beginning. Avoid repeating definition. mraa_i2c_context pwm12; pwm12 = mraa_i2c_init(2); mraa_i2c_address(pwm12,12); while(1) mraa_i2c_write(pwm12,m,2); return 0; }
void GPIO_Init(void) { mraa_init(); //J18-2 --> GPIO-165 SCS = mraa_gpio_init(15); printf("Ports initialized\n"); mraa_gpio_mode(SCS, MRAA_GPIO_PULLUP); printf("Ports modes set\n"); mraa_gpio_dir(SCS, MRAA_GPIO_OUT); printf("Port directions set\n"); }
// Initialization function void init() { mraa_init(); // temperature sensor connected to A1 (analog in) temps = new mraa::Aio(1); // buzzer connected to A2 (aka digital out 16) buzzer = new mraa::Gpio(16); buzzer->dir(mraa::DIR_OUT); stopAlarm(); // flame sensor on A3 flame = new mraa::Aio(3); }
int main() { printf("Arbotox Commander XBee Test!\n"); // Install signal handler to allow us to do some cleanup... struct sigaction sigIntHandler; sigIntHandler.sa_handler = SignalHandler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); mraa_uart_context uart; mraa_init(); uart = mraa_uart_init(0); if (uart == NULL) { printf("MRAA UART failed to setup\n"); } // Lets try to open the XBee device... command.begin(szDevice, B38400); printf("After Begin!\n"); // loop simply echo what we receive from xbee to terminal // Now lets try to get data from the commander. while (fRunning) { if (command.ReadMsgs()) { // We have data. see if anything has changed before if ((command.rightV != rightV) || (command.rightH != rightH) || (command.leftV != leftV) || (command.leftH != leftH) || (command.buttons != buttons) || (command.ext != ext)) { // Something changed so print it out rightV = command.rightV; rightH = command.rightH; leftV = command.leftV; leftH = command.leftH; buttons = command.buttons; ext = command.ext; printf("%x %x - %d %d %d %d\n", buttons, ext, rightV, rightH, leftV, leftH); } } usleep(100); } return 0; }
int main() { if (mraa_init() != MRAA_SUCCESS) { perror("Failed to initialize mraa\n"); return -1; } signal(SIGINT, sig_handler); //! [Interesting] // Instantiate a NMEA_GPS UBLOX based i2c sensor on i2c bus 0 at // address 0x42 nmea_gps_context sensor = nmea_gps_init_ublox_i2c(0, 0x42); if (!sensor) { printf("nmea_gps_init_ublox_i2c() failed.\n"); return 1; } char buffer[bufferLength]; int rv = 0; // loop, dumping NMEA data out as fast as it comes in while (shouldRun) { if (!nmea_gps_data_available(sensor, 0)) upm_delay_ms(500); else { if ((rv = nmea_gps_read(sensor, buffer, bufferLength)) >= 0) { int i; for (i=0; i<rv; i++) printf("%c", buffer[i]); } } } //! [Interesting] printf("Exiting\n"); nmea_gps_close(sensor); return 0; }
int main() { if (mraa_init() != MRAA_SUCCESS) { perror("Failed to initialize mraa\n"); return -1; } signal(SIGINT, sig_handler); //! [Interesting] // Instantiate a NMEA_GPS sensor on uart 0 at 9600 baud with enable // pin on D3. If you do not need an enable pin, you can specify -1. nmea_gps_context sensor = nmea_gps_init(0, 9600, 3); if (!sensor) { printf("nmea_gps_init() failed.\n"); return 1; } char buffer[bufferLength]; int rv = 0; // loop, dumping NMEA data out as fast as it comes in while (shouldRun && nmea_gps_data_available(sensor, 5000)) { if ((rv = nmea_gps_read(sensor, buffer, bufferLength)) >= 0) { int i; for (i=0; i<rv; i++) printf("%c", buffer[i]); } } if (shouldRun) printf("Timed out\n"); //! [Interesting] printf("Exiting\n"); nmea_gps_close(sensor); return 0; }
// uart init ecezo_context ecezo_uart_init(unsigned int uart, unsigned int baudrate) { // make sure MRAA is initialized int mraa_rv; if ((mraa_rv = mraa_init()) != MRAA_SUCCESS) { printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv); return NULL; } ecezo_context dev = (ecezo_context)malloc(sizeof(struct _ecezo_context)); if (!dev) return NULL; // zero out context memset((void *)dev, 0, sizeof(struct _ecezo_context)); // initialize the MRAA contexts // uart, default should be 8N1 if (!(dev->uart = mraa_uart_init(uart))) { printf("%s: mraa_uart_init() failed.\n", __FUNCTION__); ecezo_close(dev); return NULL; } if (mraa_uart_set_baudrate(dev->uart, baudrate)) { printf("%s: mraa_uart_set_baudrate() failed.\n", __FUNCTION__); ecezo_close(dev); return NULL; } mraa_uart_set_flowcontrol(dev->uart, false, false); if (generic_init(dev)) { printf("%s: generic_init() failed.\n", __FUNCTION__); ecezo_close(dev); return NULL; } return dev; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////// Modem related functions ////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int init_modem(){ mraa_init(); if( (uart = mraa_uart_init(0)) == NULL ){ writeToFile(src, "error INITIATING UART\n"); exit(UART_ERROR); } /*set uart boud rate [bps]*/ if ( mraa_uart_set_baudrate(uart, UART_BOUD_RATE)!=MRAA_SUCCESS) { writeToFile(src, "error seting baudrate\n"); exit(UART_ERROR); } if ( mraa_uart_set_mode(uart, 8,MRAA_UART_PARITY_NONE , 1)!=MRAA_SUCCESS) { writeToFile(src, "error seting mode\n"); } mraa_uart_set_flowcontrol(uart, 0, 0); writeToFile(src, "init modem\n"); }
mraa_boolean_t mraa_pin_mode_test(int pin, mraa_pinmodes_t mode) { if (plat == NULL) { mraa_init(); if (plat == NULL) return 0; } if (pin > plat->phy_pin_count || pin < 0) return 0; switch(mode) { case MRAA_PIN_VALID: if (plat->pins[pin].capabilites.valid == 1) return 1; break; case MRAA_PIN_GPIO: if (plat->pins[pin].capabilites.gpio ==1) return 1; break; case MRAA_PIN_PWM: if (plat->pins[pin].capabilites.pwm ==1) return 1; break; case MRAA_PIN_FAST_GPIO: if (plat->pins[pin].capabilites.fast_gpio ==1) return 1; break; case MRAA_PIN_SPI: if (plat->pins[pin].capabilites.spi ==1) return 1; break; case MRAA_PIN_I2C: if (plat->pins[pin].capabilites.i2c ==1) return 1; break; case MRAA_PIN_AIO: if (pin < plat->aio_count) pin = pin + plat->gpio_count; if (plat->pins[pin].capabilites.aio ==1) return 1; break; default: break; } return 0; }
int main(int argc, char **argv) { mraa_init(); float direction = 0; int16_t x = 0, y = 0, z = 0; char rx_tx_buf[MAX_BUFFER_LENGTH]; //! [Interesting] mraa_i2c_context i2c; i2c = mraa_i2c_init(0); mraa_i2c_address(i2c, HMC5883L_I2C_ADDR); rx_tx_buf[0] = HMC5883L_CONF_REG_B; rx_tx_buf[1] = GA_1_3_REG; mraa_i2c_write(i2c, rx_tx_buf, 2); //! [Interesting] mraa_i2c_address(i2c, HMC5883L_I2C_ADDR); rx_tx_buf[0] = HMC5883L_MODE_REG; rx_tx_buf[1] = HMC5883L_CONT_MODE; mraa_i2c_write(i2c, rx_tx_buf, 2); for(;;) { mraa_i2c_address(i2c, HMC5883L_I2C_ADDR); mraa_i2c_write_byte(i2c, HMC5883L_DATA_REG); mraa_i2c_address(i2c, HMC5883L_I2C_ADDR); mraa_i2c_read(i2c, rx_tx_buf, DATA_REG_SIZE); x = (rx_tx_buf[HMC5883L_X_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_X_LSB_REG] ; z = (rx_tx_buf[HMC5883L_Z_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_Z_LSB_REG] ; y = (rx_tx_buf[HMC5883L_Y_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_Y_LSB_REG] ; //scale and calculate direction direction = atan2(y * SCALE_0_92_MG, x * SCALE_0_92_MG); //check if the signs are reversed if (direction < 0) direction += 2 * M_PI; printf("Compass scaled data x : %f, y : %f, z : %f\n", x * SCALE_0_92_MG, y * SCALE_0_92_MG, z * SCALE_0_92_MG) ; printf("Heading : %f\n", direction * 180/M_PI) ; } }
void main(void) { mraa_init(); struct nano_timer timer; void *timer_data[1]; nano_timer_init(&timer, timer_data); mvs0608_context dev = mvs0608_init(2); bool abc = 0; while(1){ if(mvs0608_is_colliding(dev, &abc) != UPM_SUCCESS){ printf("an error has occured\n"); } nano_timer_start(&timer, SLEEPTICKS); nano_timer_test(&timer, TICKS_UNLIMITED); printf("value retrieved: %d\n", abc); } mvs0608_close(dev); }
// i2c ublox init ecezo_context ecezo_i2c_init(unsigned int bus, uint8_t addr) { // make sure MRAA is initialized int mraa_rv; if ((mraa_rv = mraa_init()) != MRAA_SUCCESS) { printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv); return NULL; } ecezo_context dev = (ecezo_context)malloc(sizeof(struct _ecezo_context)); if (!dev) return NULL; // zero out context memset((void *)dev, 0, sizeof(struct _ecezo_context)); // initialize the MRAA contexts if (!(dev->i2c = mraa_i2c_init(bus))) { printf("%s: mraa_i2c_init() failed.\n", __FUNCTION__); ecezo_close(dev); return NULL; } if (mraa_i2c_address(dev->i2c, addr)) { printf("%s: mraa_i2c_address() failed.\n", __FUNCTION__); ecezo_close(dev); return NULL; } if (generic_init(dev)) { printf("%s: generic_init() failed.\n", __FUNCTION__); ecezo_close(dev); return NULL; } return dev; }
int main() { if (mraa_init() != MRAA_SUCCESS) { perror("Failed to initialize mraa\n"); return -1; } signal(SIGINT, sig_handler); //! [Interesting] // Instantiate a URM37 sensor on UART 0, with the reset pin on D2 urm37_context sensor = urm37_init(0, 2, 0, 0, 0, false); if (!sensor) { printf("urm37_init() failed.\n"); return(1); } // Every half a second, sample the URM37 and output the measured // distance in cm. while (shouldRun) { float distance, temperature; urm37_get_distance(sensor, &distance, 0); printf("Detected distance (cm): %f\n", distance); urm37_get_temperature(sensor, &temperature); printf("Temperature (C): %f\n\n", temperature); upm_delay_ms(500); } //! [Interesting] printf("Exiting\n"); urm37_close(sensor); return 0; }
void GPIO_Init(void) { mraa_init(); //J18-2 --> GPIO-165 SCS = mraa_gpio_init(15); //printf("Ports initialized\n"); mraa_gpio_use_mmaped(SCS, 1); mraa_gpio_mode(SCS, MRAA_GPIO_PULLUP); //printf("Ports modes set\n"); mraa_gpio_dir(SCS, MRAA_GPIO_OUT); //printf("Port directions set\n"); VDD = mraa_gpio_init(31); // GP44 mraa_gpio_mode(VDD, MRAA_GPIO_PULLUP); mraa_gpio_dir(VDD, MRAA_GPIO_OUT); }
static speaker_context _common_init() { // make sure MRAA is initialized int mraa_rv; if ((mraa_rv = mraa_init()) != MRAA_SUCCESS) { printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv); return NULL; } speaker_context dev = (speaker_context)malloc(sizeof(struct _speaker_context)); if (!dev) return NULL; // zero out context memset((void *)dev, 0, sizeof(struct _speaker_context)); return dev; }
int main(int argc, char *argv[]) { mraa_init(); fprintf(stdout, "Hello mraa.\nVersion: %s\n", mraa_get_version()); // LED out = mraa_gpio_init(20); if(out == NULL){ printf("Error: init out.\r\n"); return 1; } mraa_gpio_dir(out, MRAA_GPIO_OUT); // Switch mraa_gpio_context in = mraa_gpio_init(14); if(in == NULL){ printf("Error: init in.\r\n"); return 1; } mraa_gpio_dir(in, MRAA_GPIO_IN); mraa_gpio_mode(in, MRAA_GPIO_PULLUP); // 割込関数の登録 mraa_gpio_isr(in, MRAA_GPIO_EDGE_BOTH, interrupt_in, (void *)in); while(1) {} mraa_gpio_isr_exit(in); mraa_gpio_close(in); mraa_gpio_close(out); mraa_deinit(); return 0; }
int main(int ac, char **av) { int iopin; mraa_result_t result; mraa_gpio_context gpio; int value; mraa_init(); if (ac != 3) { fprintf(stderr, "Usage: %s pin_number\n" \ "\nExample: %s 7 -> Read pin 7\n" , av[0], av[0]); return -1; } iopin = atoi(av[1]); /* Initialisation of pin */ gpio = mraa_gpio_init(iopin); if (gpio == NULL) { fprintf(stderr, "[-] Initialisation of pin %d failed. Is this pin exist on your platform?\n", iopin); return -1; } /* Set GPIO direction */ result = mraa_gpio_dir(gpio, MRAA_GPIO_IN); if (result != MRAA_SUCCESS) { mraa_result_print(result); return -1; } value = mraa_gpio_read(gpio); if (result != MRAA_SUCCESS) mraa_result_print(result); printf("%d", value); return 0; }
int main() { float Rsensor; //Resistance of sensor in K // Setup() mraa_init(); mraa_aio_context sensor = mraa_aio_init(analog_Pin_0); uint16_t adc_value = 0; float adc_value_float = 0.0; for (;;) { adc_value = mraa_aio_read(sensor); adc_value_float = mraa_aio_read_float(sensor); Rsensor=(float)(1023-adc_value)*10/adc_value; fprintf(stdout, "ADC A0 read %X - %d\n", adc_value, adc_value); fprintf(stdout, "ADC A0 read float - %.5f\n", adc_value_float); printf("Cant Luz: %.5f\n", Rsensor); usleep(10000); } mraa_aio_close(sensor); return MRAA_SUCCESS; }