atael
Posts: 6
Joined: Wed Dec 19, 2012 9:03 pm
Contact: Website

Reading temp using MCP3800

Sun Jan 27, 2013 5:19 am

Hello,
I am trying to write a Java (SE 7 Embedded u10) program that reads temperature from a Analog Temp Sensor TMP36 (http://www.adafruit.com/products/165) using a MCP3800 ADC (https://www.adafruit.com/products/856).

In order to read analog data I need to use the following pins I think (outside of GND 3.3V):
  • DOUT (Data Out from MCP3008)
    CLK (Clock pin)
    DIN (Data In from Raspberry Pi),
    CS (Chip Select).
I've connected the MCP3800 like this:
  • VDD -> 3.3V
    VREF -> 3.3V
    AGND -> GND
    CLK -> #18
    DOUT -> #23
    DIN -> #24
    CS -> #25
    DGND -> GND
My thought is to have the
  • Pin #18 (CLK) as a GPIO Out Pin
    Pin #23 (DOUT) as a GPIO In Pin
    Pin #24 (DIN) as a GPIO Out Pin
    Pin #25 (CS) as a GPIO Out Pin
and the TM36 like this:
  • pin1 -> 3.3V
    pin2: analog out --> channel0 on mcp3008 (pin1)
    pin3: GND
And I am struggling (not sure what I am doing) but I would guess that I need to access the GPIO ports using java.io,RandomAccessFile (or java.nio.FIle) but I am short of knowledge on how to accomplish this. I am pretty sure part of my failure is that I am not sure I understand the Pi and the GPIO ports in full yet.

I have googled and binged around but can't fins any examples, so maybe someone on this forum has an idea on how to get me started?

Thanks
Andy

User avatar
savageautomate
Posts: 225
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
Contact: Website

Re: Reading temp using MCP3800

Wed Jan 30, 2013 2:46 am

Hi Andy,

I don't have an example on hand, but I would suggest using a library such as Pi4J that provides access to the SPI communication bus.

https://github.com/Pi4J/pi4j/blob/maste ... i/Spi.java

(This class is a JNI wrapper around the SPI implementation in the WiringPi native library)

-Robert.
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com

User avatar
OlivierLD
Posts: 4
Joined: Tue Jan 28, 2014 10:07 pm
Location: San Francisco, CA

Re: Reading temp using MCP3800

Tue Jan 28, 2014 10:13 pm

Hi Andy,
Not sure it is not too late, but just in case, I did something similar. It's not with a thermometer, it's with a potentiometer.
The Java source is available at https://code.google.com/p/raspberry-pi4j-samples/, the doc at http://www.lediouris.net/RaspberryPI/ADC/readme.html.

Cheers,
- Olivier

Return to “Java”