int adc_read(){ int adc; wiringPiI2CWrite(fd,LDR_ch); adc = wiringPiI2CRead(fd); adc = wiringPiI2CRead(fd); return adc; }
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin) { int x ; wiringPiI2CWrite (node->fd, 0x40 | ((pin - node->pinBase) & 3)) ; x = wiringPiI2CRead (node->fd) ; // Throw away the first read x = wiringPiI2CRead (node->fd) ; return x ; }
json_t *rpi_i2c_byte_get(duda_request_t *dr, int parameter) { int fd = get_fd(dr); if (fd == -1) { return json->create_null(); } return json->create_number((double)wiringPiI2CRead(fd)); }
static int myDigitalRead (struct wiringPiNodeStruct *node, int pin) { int mask, value ; mask = 1 << ((pin - node->pinBase) & 7) ; value = wiringPiI2CRead (node->fd) ; if ((value & mask) == 0) return LOW ; else return HIGH ; }
int I2C_ReadByte(int fd) { int data = wiringPiI2CRead(fd); if(data == -1) { if(DEBUG) fprintf(stderr,"I2C ReadByte Error. Errno is: ",strerror(errno)); return 0; } if(DEBUG) printf("I2C read byte %d.\n",data); return data; }
int I2CADCExists(void) { int fd, result; result = 0; if (fd = open_i2c(MCP3426_ADDRESS)) { if (wiringPiI2CRead(fd) != -1) { result = 1; } close(fd); } return result; }
int pcf8574Setup (const int pinBase, const int i2cAddress) { int fd ; struct wiringPiNodeStruct *node ; if ((fd = wiringPiI2CSetup (i2cAddress)) < 0) return fd ; node = wiringPiNewNode (pinBase, 8) ; node->fd = fd ; node->pinMode = myPinMode ; node->digitalRead = myDigitalRead ; node->digitalWrite = myDigitalWrite ; node->data2 = wiringPiI2CRead (fd) ; return 0 ; }
/** * read a single port - function required for wiringPi interface * @param pin - port relative to pinBase * @return true - port is active, false - port is inactive */ bool Max7312::readPort(int pin){ bool portIsInput = isPortInput(pin); if(isLowerPort(pin)){ if (portIsInput){ wiringPiI2CWrite(fd, INPUT_PORT_1); } else { wiringPiI2CWrite(fd, OUTPUT_PORT_1); } } else { if (portIsInput){ wiringPiI2CWrite(fd, INPUT_PORT_2); } else { wiringPiI2CWrite(fd, OUTPUT_PORT_2); } } int port_data=wiringPiI2CRead(fd); if(isLowerPort(pin)){ _port1_data = port_data; } else { _port2_data = port_data; } return isPortActive(pin); }
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 myAnalogRead (struct wiringPiNodeStruct *node, int chan) { unsigned char config, b0, b1, b2, b3 ; int value = 0 ; // One-shot mode, trigger plus the other configs. config = 0x80 | ((chan - node->pinBase) << 5) | (node->data0 << 2) | (node->data1) ; wiringPiI2CWrite (node->fd, config) ; switch (node->data0) // Sample rate { case MCP3422_SR_3_75: // 18 bits delay (270) ; b0 = wiringPiI2CRead (node->fd) ; b1 = wiringPiI2CRead (node->fd) ; b2 = wiringPiI2CRead (node->fd) ; b3 = wiringPiI2CRead (node->fd) ; value = ((b0 & 3) << 16) | (b1 << 8) | b2 ; break ; case MCP3422_SR_15: // 16 bits delay ( 70) ; b0 = wiringPiI2CRead (node->fd) ; b1 = wiringPiI2CRead (node->fd) ; b2 = wiringPiI2CRead (node->fd) ; value = (b0 << 8) | b1 ; break ; case MCP3422_SR_60: // 14 bits delay ( 17) ; b0 = wiringPiI2CRead (node->fd) ; b1 = wiringPiI2CRead (node->fd) ; b2 = wiringPiI2CRead (node->fd) ; value = ((b0 & 0x3F) << 8) | b1 ; break ; case MCP3422_SR_240: // 12 bits delay ( 5) ; b0 = wiringPiI2CRead (node->fd) ; b1 = wiringPiI2CRead (node->fd) ; b2 = wiringPiI2CRead (node->fd) ; value = ((b0 & 0x0F) << 8) | b1 ; break ; } return value ; }
/** * read the value of higher byte * @return value of port */ unsigned char Max7312::readPort2(){ wiringPiI2CWrite(fd, INPUT_PORT_2); _port2_data=wiringPiI2CRead(fd); return _port2_data; }
uint8_t I2Cdev::readByte(int devAddr) { return (uint8_t)wiringPiI2CRead(devAddr); }
double digipotRead(char *digipot_label) { double x = -1 ; struct digipot *digipot = digipots ; for (; digipot < digipots + numberofdigipots ; digipot++) { int loop = 0 ; int found = 0 ; for (; loop < digipot->digipot_channels ; loop++) { int loop = 0 ; if (digipot_label == digipot->digipot_label[loop]) { if (digipot->digipot_group_qty == 0) // standard alone digipot { // printf("*** digipot_label: %s - digipot->digipot_label: %d - loop: %d \n", digipot_label, digipot->digipot_label, loop) ; int slaveAddressByte = digipot->digipot_address << 1 | 0b0 ; // prepare the first byte including the internal sub digipot address, only for displaying and tests, because it's sent automaticaly by wiringpi itself, don't care ! int instructionByte = loop << 5 ; // this is the "int reg", the second I2C byte sent by wiringpi wiringPiI2CWriteReg8(digipot->digipot_setUpIO, instructionByte, digipot->digipot_value[loop]) ; // send the complete I2C frame to the chip, rewrite the current wipper value, because the READ instruction get the last writed digipot int x = -1 ; x = wiringPiI2CRead(digipot->digipot_setUpIO) ; if (x > -1) { // convert tap position to attenuation in dB double tap = -(x - digipot->wiper_positions) ; double ratio ; if (digipot->digipot_0_position[loop] == "RIGHT") { ratio = ((digipot->wiper_positions - tap) / (digipot->wiper_positions -1)) ; } else if (digipot->digipot_0_position[loop] == "CENTER") { ratio = ((digipot->wiper_positions - tap) / ((digipot->wiper_positions/2) -1)) ; } else { printf("\n!!! ZERO position value not recognized !!!\n") ; printf("ELSE-digipot->digipot_0_position[loop]:%s",digipot->digipot_0_position[loop]) ; } double dB = (20 * log10(ratio)) ; digipot->digipot_att[loop] = dB ; // store the digipot attenuation in dB // printf("\n>>> Digipot Read response : x:%d - tap:%-0.0f - att:%0.2f(dB) \n", x, tap, dB) ; /* printf(">>> Digipot Read addr: Ox%x = %d - setUpIO: 0x%x = %d - slaveAddressByte: 0x%x = %d - instructionByte: 0x%x = %d - dataByte/att: 0x%x = %3.2f(dB) \n", digipot->digipot_address, digipot->digipot_address, digipot->digipot_setUpIO, digipot->digipot_setUpIO, slaveAddressByte, slaveAddressByte, instructionByte, instructionByte, x, dB) ; */ } else // stacked digipots drived simultaneously (grouped t oform a single serial or parallel SUPERDIGIPOT) { printf("\n!!! - Digipot Read error - !!!\n") ; } found = 1 ; // printf("found digipot") ; break ; } else { // superdigipot = group (stack) of real digipots } } // printf("boucle 1 \n") ; if (found == 1) { break ; } } // printf("boucle 2 \n") ; if (found == 1) { break ; } } // printf("sortie de boucle 2 \n") ; return x ; }
bool statusi2c(){ if(wiringPiI2CRead(expander) != -1)return true; else return false; }