Hubo Library

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
MCP970x.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <unistd.h>
3 #include "../hubolib.h"
4
5 using namespace HuboLib;
6
7 /*
8 Compile and link:
9 g++ MCP970x.cpp -L../ -lhubo -lpthread -lrt -o MCP970x.out
10 Run:
11 sudo ./MCP970x.out
12 Purpose:
13 Simple usage of an MCP9700 and MCP9701 temperature sensor.
14 */
15
16 int main(void)
17 {
18 /*
19 double volt;
20 printf ("Some voltages and their corresponding temperatures.\n");
21 volt = 0.0;
22 printf ("Voltage=%lf Associated temperatures: MCP9701=%lf°C MCP9700=%lf°C\n", volt, Get_MCP7901_Temperature(volt), Get_MCP7900_Temperature(volt));
23 volt = 0.4;
24 printf ("Voltage=%lf Associated temperatures: MCP9701=%lf°C MCP9700=%lf°C\n", volt, Get_MCP7901_Temperature(volt), Get_MCP7900_Temperature(volt));
25 volt = 0.5;
26 printf ("Voltage=%lf Associated temperatures: MCP9701=%lf°C MCP9700=%lf°C\n", volt, Get_MCP7901_Temperature(volt), Get_MCP7900_Temperature(volt));
27 volt = 1.0;
28 printf ("Voltage=%lf Associated temperatures: MCP9701=%lf°C MCP9700=%lf°C\n", volt, Get_MCP7901_Temperature(volt), Get_MCP7900_Temperature(volt));
29 volt = 2.0;
30 printf ("Voltage=%lf Associated temperatures: MCP9701=%lf°C MCP9700=%lf°C\n", volt, Get_MCP7901_Temperature(volt), Get_MCP7900_Temperature(volt));
31 */
32 // Initialize the library once in your program.
33 if (!Initialize())
34 {
35 printf ("Error: Initialize\n");
36 return 1;
37 }
38
39 // Retrieving the reference voltage requires the library to be initialized.
40 double volt = Get_VRef();
41 // printf ("Voltage=%lf Associated temperatures: MCP9701=%lf°C MCP9700=%lf°C\n", volt, Get_MCP7901_Temperature(volt), Get_MCP7900_Temperature(volt));
42
43 // We'll use channel 0 for testing.
44 unsigned short overSampling[MAX_MCP3x08_CHANNELS] = { 1, 1, 0, 0, 0, 0, 0, 0 };
45 Set_MCP3x08_Oversampling (overSampling);
46
47 // Wait until the ADC buffers are filled.
48 usleep(10000);
49 double volt2;
50 unsigned long adcCount, adcCount2;
51
52 while (1)
53 {
54 Get_AI_Channel (0, adcCount, volt); // Connect to MCP9700.
55 Get_AI_Channel (1, adcCount2, volt2); // Connect to MCP9701.
56 printf ("Associated temperatures: MCP9700=%lf°C MCP9701=%lf°C\n", Get_MCP9700_Temperature(volt), Get_MCP9701_Temperature(volt2));
57 usleep(1000000);
58 }
59 // Free library resources.
60 Uninitialize();
61
62 return 0;
63 }
MAX_MCP3x08_CHANNELS
#define MAX_MCP3x08_CHANNELS
Definition: hubolib.h:39
HuboLib::Get_MCP9700_Temperature
double Get_MCP9700_Temperature(double volt)
Converts a voltage value of an MCP9700 temperature sensor into the equivalent temperature.
HuboLib::Initialize
bool Initialize()
Initializes the library.
HuboLib::Get_VRef
double Get_VRef()
Retrieves the reference voltage value used for ADC count convertion.
HuboLib::Get_AI_Channel
bool Get_AI_Channel(int channel, unsigned long &count, double &volt)
Get the buffered and oversampled data from the MCP3x08.
HuboLib::Set_MCP3x08_Oversampling
bool Set_MCP3x08_Oversampling(unsigned short overSampling[MAX_MCP3x08_CHANNELS])
Specifies the ADC channels to be sampled as well as the number they get oversampled.
HuboLib::Uninitialize
void Uninitialize()
Releases any resources bound to the library.
HuboLib::Get_MCP9701_Temperature
double Get_MCP9701_Temperature(double volt)
Converts a voltage value of an MCP9701 temperature sensor into the equivalent temperature.
main
int main(void)
Definition: MCP970x.cpp:16
HuboLib
Definition: hubocfg.h:10