I have just learned GPIO and I've read a lot of in internet. As I understood GPIO port can be at one of two states: out and in. In any states it can work with 0 and 1. For example, if we need to turn on a LED we change state to out and send 1. But I can't understand what happens when we connect to GPIO temperature sensor. It is clear that we change state to in. But what do we read from GPIO? 0s and 1? How can we get the temperature? Please, explain.

P.S. I use Olinuxino A13 board and currently I don't have any sensors. I just want to understand how it generally works and buy after that.

• @gbulmer I've edited the question. – Pavel Oct 31 '15 at 12:03

The Allwinner A13 does not have any Analogue-to-Digital-Converter (ADC) inputs.

According the the User Manual:

2.8 I2C and SPI under Debian
I2C and SPI are both supported in the latest Debian releases. There is respective kernel support for both. There is a python module called pyA13 might be found here: https://pypi.python.org/pypi/pyA13 It does have I2C (aka TWI) and SPI.

The I2C pins are described in section 6.3 UEXT module of the User Manual

So a straightforward way to interface the Olinuxino A13 to a temperature sensor is to get a temperature sensor with a built-in I2C interface, run Debian, and get at the temperature sensor form Python. I would expect to also be able to get at I2C from C, but I didn't see that mentioned)

There are quite a lot of I2C temperature sensors. They vary by operating voltage, resolution, and device package. I recommend trying to get things working quickly and cheaply first.

For example Microchip Temperature Sensors include devices with an I2C/SMBus. Some of these come in a Dual-In-Line package, which you can plug into a breadboard, and hence make it relatively easy to test things. Microchip parts are carried by a lot of distributers, so it shouldn't be too hard to get some (You should be able to pick one up for about 1GBP (\$1.50))

There are I2C temperature sensors from other manufacturers which may have benefits. I've used Microchip I2C sensors, they are cheap and they worked.

If you really want to, you could buy an external ADC, and interface to that. Their are ADC devices which provide parallel data transfer, so you could experiment with GPIO. Some support SPI. This would require more electronics than an I2C temperature sensor. Hence I'd recommend getting a couple of I2C temperature sensors anyway. They should make it easy to set things up, and might still be useful, to to give you a way to do temperature comparison, (which may help debug the system) if you decide to go analogue.

As you are dealing with temperature sensor here, so you need to use Analog to digital converter (ADC). You will have to put values into the ADC registers and then read the incoming values from ADC channel.

You have not mentioned which Micro controller you are focusing, so I am assuming Atmega32. You will have to read its datasheet to understand the ADC registers and you will have to make a function to read the values coming from the ADC channel and those values will be your temperature values.

For example:

 //function to read adc value
{
ch &= 0b00000111;
}


so in your main, all you need to do is read values using above function and store it in a variable.

int main()
{
while(1)
{