I have a sensor hooked up to the Raspberry Pi 3 right now, and I am currently trying to read the humidity and temperature sensor data. This sensor was previously hooked up to an Arduino, and I have successfully read the sensor values using the following Arduino code:
vout = analogRead(LM35DZ); //Reading temperature sensor data, LM35DZ = A1
tempc = (vout*500)/1023; //Temperature in Celsius
readData = DHT.read22(dataPin); // Read humidity sensor data from Digital Port datapin = 8
t = DHT.temperature; // obtaining temperature for DHT sensor
h = DHT.humidity;
I am trying to achieve the same thing on the Raspberry Pi. I rehooked up all the wires and I am trying to get the same sensor data. My dataPin (previously pin 8 on Arduino) is connected to GPIO17 and LM35DZ(previous connected to A1 on Arduino) is connected to GPIO4.
I have two questions:
- How do you read analog data from a GPIO pin? I am looking for a similar functionality to Arduino's
analogRead()
function. I am reading temperature and sensor data from GPIO17 using the following code:
import dht11 import RPi.GPIO as GPIO readData = dht11.DHT11(pin = 17) humidityResult = readData.read() t = humidityResult.temperature h = humidityResult.humidity
But currently it's not reading any data (temperature and humidity give 0).
If anyone knows the solution to these two problems, please let me know!