Jump to content

iGNUiCould

Members
  • Posts

    3
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Works for me... Here's some code that uses it to get the readings from a DHT11 sensor. /* * temphumid.c: * Read Temperature / Humidity from DHT11 sensor * -iGNUiCould */ #include <wiringPi.h> #include <stdio.h> #define MAX_TIMINGS 85 #define DHTPIN 7 // GPIO pin for DHT11 data int data[5] = {0, 0, 0, 0, 0}; // Function to read data from DHT11 void readDHT11() { uint8_t lastState = HIGH; uint8_t counter = 0; uint8_t j = 0, i; data[0] = data[1] = data[2] = data[3] = data[4] = 0; // Send start signal to DHT11 pinMode(DHTPIN, OUTPUT); digitalWrite(DHTPIN, LOW); delay(18); digitalWrite(DHTPIN, HIGH); delayMicroseconds(40); pinMode(DHTPIN, INPUT); // Read data from DHT11 for (i = 0; i < MAX_TIMINGS; i++) { counter = 0; while (digitalRead(DHTPIN) == lastState) { counter++; delayMicroseconds(1); if (counter == 255) { break; } } lastState = digitalRead(DHTPIN); if (counter == 255) { break; } // Ignore first 3 transitions if ((i >= 4) && (i % 2 == 0)) { data[j / 8] <<= 1; if (counter > 16) { data[j / 8] |= 1; } j++; } } // Verify checksum and print data if valid if ((j >= 40) && (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF))) { float humidity = data[0] + data[1] / 10.0; float tempC = data[2] + data[3] / 10.0; float tempF = tempC * 9.0 / 5.0 + 32; printf("Temperature = %.1f°F\n", tempF); printf("Humidity = %.1f%%\n", humidity); } else { printf("Data not valid\n"); } } int main() { if (wiringPiSetup() == -1) { printf("WiringPi setup failed\n"); return -1; } while (1) { readDHT11(); delay(2000); // Wait 2 seconds before reading again } return 0; }
  2. Are you saying the repo I posted is low quality because it doesn't contain a ton of extra code for boards I'm not using? I can remove it for you if you disapprove.
  3. If this is still an issue for anyone, I forked into a repo that is modified to work exclusively with the M4 Zero. Confirmed working on the M4 Zero 4G / 32G model. Should work on other M4 Zero variants as long as the pins are the same. https://github.com/ignuicould/WiringBPi-M4Zero I also have pascal bindings for fpc / Lazarus if anyone is interested.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines