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.

  • \$\begingroup\$ As CL has commented, please update your question by adding the extra information you have written in comments. This helps the community answer one consistent question, and saves us effort reading all of the comments. Please read the help center to help you better understand how to ask questions that get good answers. \$\endgroup\$
    – gbulmer
    Oct 31, 2015 at 11:38
  • \$\begingroup\$ @gbulmer I've edited the question. \$\endgroup\$
    – Pavel_K
    Oct 31, 2015 at 12:03

2 Answers 2


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
 uint16_t adc_read(uint8_t ch)
    ch &= 0b00000111;  
    ADMUX = (ADMUX & 0xF8)|ch;    
    ADCSRA |= (1<<ADSC);
    while(ADCSRA & (1<<ADSC));
    return (ADC);

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

int main()
  uint16_t adc_result0;
    adc_result0 = adc_read(0); //reading values and storing it in variable for further processing.

Note: Above functions are just for the demo purpose and may not give the actual output.

  • \$\begingroup\$ Thank you for your answer. I use olinuxino A13. I've checked its datasheet there is now a word about ADC, but there are about 70 GPIO. How to understand it? \$\endgroup\$
    – Pavel_K
    Oct 31, 2015 at 9:09
  • \$\begingroup\$ Datasheet is the only friend you have while working on the board. For GPIOs you will have to read the pin description of your MCU. \$\endgroup\$
    – Aircraft
    Oct 31, 2015 at 9:39
  • \$\begingroup\$ What do you mean under MCU? \$\endgroup\$
    – Pavel_K
    Oct 31, 2015 at 9:42
  • 1
    \$\begingroup\$ @JimJim2000 All relevant information (such as which temp sensor you're using) belongs into the question. \$\endgroup\$
    – CL.
    Oct 31, 2015 at 9:51
  • 2
    \$\begingroup\$ That depends on which sensor you'll be buying. \$\endgroup\$
    – CL.
    Oct 31, 2015 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.