Part 3: How to build a USB thermometer and barometer with P |
A USB pressure and temperature monitoring system with a PIC
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)
If you want to build an altimeter (yes, you have to bring the computer in the mountain :), you can use the formula: Firmware for a monitoring systemWe 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]
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 - RRDtoolI 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 USBMaking sense of the USB standard (Beyond logic)Understanding USB (usbdeveloper) USB 2.0 Specifications(usb.org) USB 1.1 specifications (pdf file) Getting helpAsk your question to the electronicfr community http://www.electronicfr.com/forum/phpBB2/viewforum.php?f=1.DisclaimerANY 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.
|
mXcomment 1.0.5 © 2007-2008 - visualclinic.fr
License Creative Commons - Some rights reserved
| < Prev |
|---|






