| Ecrit par Administrator, le 27-10-2007 11:51 |
| Pages vues |
13145  |
|
FRONTPAGE_NO_TRANSLATION_AVAILABLE
A USB pressure and temperature monitoring system with a PIC In this last part we are adding a pressure sensor to the circuit described in the first and second part of this tutorial and we will build a monitoring system with RRDTOOL
How to Add a pressure sensor ( MPX4115 ) to build USB barometer or altimeter It's very easy to add an analogic pressure sensor to build a barometer or why not an altimeter. For exemple the Freescale MPX4115 is very easy to use. Look at the datasheet. The sensor can be powered by the USB bus, just connect the output to an analogic entry. The output voltage is linear with the presure. You can use the formula: Vout = 5 (P*0.009-0.095) With P in KPa an V in volts If you want to build an altimeter (yes, you have to bring the computer in the mountain :), you can use the formula: Altitude (in feet) = (10^(log(P/P_0)/5.2558797)-1)/-6.8755856*10^-6. Where P is the pressure at an unknown altitude, and P_0 is the pressure at sea level (zero feet). Firmware for a monitoring system We would like to mesure the temperature and pressure of a room every minuts and to display graph on a computer [my life]I'm system ingeneer and I like to control the temperature in my systems room, it's nice to check from my home if there is no climatisation failure...[/my life]  I modifyed the firmware to send the temperature and pressure values anytime I send a '1' to the USB port. On the computer a simple UNIX shell script send '1' to /dev/ttyACM0 and I can read the values. Then I use rrdtool to display temperature and pressure graph. Here are the importants parts of the firmware: void Exercise_Example(void) { static byte start_up_state = 0; int temp; int pres; if(start_up_state == 0) { // If we send the char '1' if(getsUSBUSART(input_buffer,"1")) if(input_buffer[0] == '1') start_up_state++; } else if(start_up_state == 1) { mLED_4_Toggle(); start_up_state++; } else if(start_up_state == 2) { if(mUSBUSARTIsTxTrfReady()) { putrsUSBUSART("\n"); start_up_state++; } } else if(start_up_state == 3) { // We will read temperature TRISAbits.TRISA0 = 1; // configure A/D convertor memset(output_buffer, '\0', 64); output_buffer[(6*3)] = 'T'; output_buffer[(6*5)+1] = '\n'; OpenADC( ADC_FOSC_8 & ADC_RIGHT_JUST & ADC_0_TAD, ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, 0b1011); SetChanADC(ADC_CH0); Delay10TCYx( 50 ); // Delay for 50TCY ConvertADC(); // Start conversion while( BusyADC() ); // Wait for completion temp = ReadADC(); // Read result CloseADC(); // Disable A/D converter temp=temp; // we can convert in degree here itoa(temp, output_buffer); if(mUSBUSARTIsTxTrfReady()) { mUSBUSARTTxRam((byte*)output_buffer,(6*5)+2); start_up_state++; } } else if(start_up_state == 4) { // We will read pressure TRISAbits.TRISA1 = 1; // configure A/D convertor memset(output_buffer, '\0', 64); output_buffer[(6*3)] = 'P'; output_buffer[(6*5)+1] = '\n';
OpenADC( ADC_FOSC_8 & ADC_RIGHT_JUST & ADC_0_TAD, ADC_CH1 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, 0b1011); SetChanADC(ADC_CH1); Delay10TCYx( 50 ); // Delay for 50TCY ConvertADC(); // Start conversion while( BusyADC() ); // Wait for completion pres = ReadADC(); // Read result CloseADC(); // Disable A/D converter pres=pres; itoa(pres, output_buffer); //ftoa(tempf,output_buffer); if(mUSBUSARTIsTxTrfReady()) { mUSBUSARTTxRam((byte*)output_buffer,(6*5)+2); start_up_state=0; } } }//end Exercise_Example
Rq: - I send directly value from ADC because it's easyer for me to do some calculus with the computer. - In this example, the sensor MPX4115 is connected to pin 3 of the MCU - You can download my user.c file from this link On the computer - RRDtool I suggest you to read the rrdtool documentation. I call rrdtool under linux with a script derivated from rrd_hddtemp - a script to monitor hard drive. I don't use hddtemp but I read data from USB with my little bourne shell script to read data on a linux system I get something like that: Some links about USB Making sense of the USB standard (Beyond logic) Understanding USB (usbdeveloper) USB 2.0 Specifications(usb.org) USB 1.1 specifications (pdf file) Getting help Ask your question to the electronicfr community http://www.electronicfr.com/forum/phpBB2/viewforum.php?f=1. Disclaimer ANY CONTENT ON THIS WEBSITE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Commentaires utilisateurs (0)
Commentaires en langue: English (3), French (0) |
|
|