# How to readout a digital or analog pin

#1

Hello thogeher
I’m a totally newbe and want to know how I can read the data on digital or analog pin on the GrobePI.

I checked already the page with the port description. But I not know how to write a script to read out a specified pin of the Grove board. I tried already to modify an existing script but it not works. I would be happy if someone can write an example script.

I have also a general question about, if I’m on right way with the GrovePI. I want monitor two solar panels and measure voltage, current, power, temperature. All this two times cos of two panels. I choose a GrovePI because there is enough analog and digital ports for this project. Of course before I can read the signals I have to build some circuit with A/D converter. I just want to know if I can just read the received signals on the ports of the GrovePI.

Thanks and sorry for my English

#2

@cmonti,
There are a lot of ways to red data from the GrovePi. If you are using an analog sensor connected to an analog port (port description here) and there is sample code for reading the analog values in python here.

We also have a big collection of sensor examples in python here and in other languages too that you can use for your projects.

#3

Hello, thank you for the fast answhere. Now im searching the datasheet of the GrovePI. Or can you tell me the range of the analog Signal input? It is from 0V to 3.3V or from 0V to 5V?

#4

Hi @cmonti,

The range of input signal to the Analog Ports is 0-5V as the Analog Ports are connected to ATMEGA 328 on GrovePi+, which operates on 5v logic.
The ATMEGA 328 uses a 10 bit ADC.This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023, where each step in the value corresponds to 4.9mV (5/1023).
The information about the port description and working of GrovePi+ can be found here.

Do let us know if this helps,
-Shoban

#5

Hello Shoban I build up my voltage divider and connect it to the GrovePI to measure 0 - 5V. To readout the analog signal works very fine. Thanks for the descripion. And i have an another question. How it will looks when i digitalize the signal with an axternal A/D Converter? Of course use an digital Port on the GrovePI but how can looking the script and how ist the outcome in the terminal?Can you give me an example? Sorry im a totally beginner. Thanks for your supportMonti

#6

Hi @cmonti,

If you would like to know, if you could connect an external ADC to GrovePi, then the answer is yes. You can connect an external ADC to Serial or I2C ports.
We have used this Grove I2C ADC which connects to the I2C port of GrovePi+ and we have an example for it here .

Please let us know if this helps,
-Shoban

#7

Hello Shoban
Instead of a second ADC i want to use a Multiplexer. (DG408 from Intersil).

I build up already the circuit but i have problems with the digital output to manage the multiplexer.

I wrote a program in python to configure the defined pins as output. It works fine. Measured with multimeter 1 = +5V and 0 = 0V (50mV)
I connect the defined output pins direct to the multiplexer. I notice that the multiplexer is sensitive of interfering signals and not works correct. I set some resistor and capazitor to minimize the interfering signals. It helps a lttle. Start with output 0, the multiplexer was working correct. Send output 1, works also how i wnat. But send again 0 to the multiplexer, it not react on it. The multiplexer hang on this 1. Just with a manualy short circuit the multiplecer set the 1 back to 0.

After this reaction i build a Pull-Down resistor in my circuit (10kOhm). But after this, the output 1 of the pin was +1.1V instead of +5V. 1,1V is too less for the multiplexer to react.

The sign that with the pull-down resistor the output is stabil on 1,1V shows me, that maybe a inside resistor is in the circuit of the GrovePI.

So then i connect the pull-down resistor diffrent as pull-up resistor. Using pull-up resistor changes the logical signals. output 1 = 0 and output 0 =1.
But this also not works because i have now a permanently +V signal on the multiplexer.

I hope you can follow what i try to explain. The main problem for me is, when i send output signal from 1 to 0. The safed Voltage inside not goes to GND. Maybe you have an idea how i can solve this problem.

#8

Hi @cmonti,

Not very sure of a solution. Can you share with us the circuit diagram that you are using, so that we can have a look at it, to help you better.

-Shoban

#9

Hello Shoban
I solved the problem with a very high pull down resistor. (510k) Now it works fine. But i stand now in front of the next problem and i should know how high the internal resistor of the grove board is.
i set pin 14 as input and read out a analog signal which comes from the multiplexer. But the signal is not linear. for this i need to know the internal resistor of the board.

Regards

#10

Hi @cmonti,
I just checked the datasheet for the chip used on the GrovePi which is the Atmega328 and found this post too which you might find helpful.

#11

From problem to problem. I create now a GUI with PYQT4 to display my generated data. Inside this python script is implemented a part to manage a multiplexer. This GUI works good and display what i want. But in the background i become all time this Error: “traceback (most recent call last): File… number = bus.read_i2c_Block_data(address, 1) IOError: [Errno5] Input/Outputerror”. The Errorpath shows me the part which manages the multiplexer. I not understand this Error because i connect nothing to to i2c on the grove board. The scrips to manage the multiplexer works fine standalone in the terminal.
Can someone help me? I cant find solution in the internet.
Merry Cristmas

#12

Hi @cmonti,

Can you follow this guide, generate a test log and post it with your reply. Also can you share with us the code that you are using as it will help us to debug better.

-Shoban