MCP9700A Sensor & Ethernet

This project consists of reading the temperature by MCP9700A Sensor and view it on a webpage.


Required Components:

Temperature Sensor MCP9700A: Datasheet
RJ45 SI-60002-F: Datasheet


RJ45 SI-60002-F:

This is a RJ45 connector without leds.
You will find wiring diagram in this PAGE or I summarized it in this schematic:

/media/uploads/edodm85/rj45.png


MCP9700A:

You'll find everything for use this Temperature Sensor on my notebook page HERE
I connected the output of this Sensor with the pin p15 of mbed.


Code (with JavaScript):

The first part is to implement an HTTP Server on your mbed. The complete explanation is here: HTTP Server

I used a Static Ip (192.168.1.100 for mbed and 192.168.1.5 for my pc) because I connected the mbed directely to my pc.


#include "mbed.h"
#include "EthernetNetIf.h"
#include "HTTPServer.h"

DigitalOut led1(LED1, "led1");
DigitalOut led2(LED2, "led2");
DigitalOut led3(LED3, "led3");
DigitalOut led4(LED4, "led4");


LocalFileSystem fs("local");
AnalogIn temp(p15);     

EthernetNetIf eth(                              // Fix Ip
  IpAddr(192,168,1,100),                        //IP Address
  IpAddr(255,255,255,0),                        //Network Mask
  IpAddr(192,168,0,1),                        //Gateway
  IpAddr(192,168,0,1)                           //DNS
);

HTTPServer svr;



int main() {
  Base::add_rpc_class<DigitalOut>();            
  Base::add_rpc_class<AnalogIn>();            

  printf("Setting up...\n\r");                  // setup ip check
  EthernetErr ethErr = eth.setup();             
  printf("\n\r");
  if(ethErr)
  {
    printf("Error %d in setup.\n\r", ethErr);
    return -1;
  }
  printf("Setup OK\n\r");                       // setup ip OK
  
  
  
   FSHandler::mount("/local", "/");              //Mount /local path on web root path
  
  svr.addHandler<SimpleHandler>("/hello");      
  svr.addHandler<RPCHandler>("/rpc");                     
  svr.addHandler<FSHandler>("/");              
  //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm
  
  svr.bind(80);
  
  printf("Listening...\n\r");
    
  Timer tm;
  tm.start();
  //Listen indefinitely
  while(true)
  {
    Net::poll();                                
    if(tm.read()>.5)
    {
      led1=!led1;                               //Show that we are alive
      tm.start();
    }
  }
  
  return 0;

}



The second part is to implement the html script which shows the temperature value every 10 seconds and plot it in to a graph.

The javascript code is here: Example 3



Output:


To try this out extract the contents of this zip Example Code (htm file and .bin) directly onto mbed, reset and then navigate to http://192.168.1.100/prova.htm.

NB: For load the javascript files is required the internet connection.


/media/uploads/edodm85/im_example3.jpg


Update: implement the Highcharts graph


6 comments on MCP9700A Sensor & Ethernet:

28 Feb 2012

hi Edoardo, how as i do to off and on the leds Each independent

29 Feb 2012

Raul E Melo S wrote:

hi Edoardo, how as i do to off and on the leds Each independent

Hi Raul, I didn't understand your question?

Have you problems to compile the main code?

04 Mar 2012

thank you very much for the code really helped me, the only thing to consider is that you must delete this

/

that when compiling the code produces a error.espero serve something that my contribution is very useful for this code.

04 Mar 2012

Hi Edoardo, I wonder if you can help take the temperature reading without having to upgrade or re-read the variable, I want you always mustre the value obtained by the temperature sensor

04 Mar 2012

Ricardo Nieto wrote:

thank you very much for the code really helped me, the only thing to consider is that you must delete this

/

that when compiling the code produces a error.espero serve something that my contribution is very useful for this code.

Hi Ricardo, I corrected the code, thanks.

Ricardo Nieto wrote:

Hi Edoardo, I wonder if you can help take the temperature reading without having to upgrade or re-read the variable, I want you always mustre the value obtained by the temperature sensor

You can add this code "<meta http-equiv='refresh' content='30'>" between "<head>" and "</head>" but It refreshes the full page (also the temp) every 30 seconds.

Update: Now with javascript code is possible show the temperature value without having to upgrade or re-read the variable

23 Oct 2012

thank you

Please log in to post comments.