Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed MbedJSONValue HTTPClient TFT_fonts SPI_TFT_ILI9341 mbed-rtos picojsontest NTPClient SDFileSystem EthernetInterface DHT Stepper_Motor_X27168
Revision 4:1eea5edaffc4, committed 2019-05-01
- Comitter:
- aalbul3
- Date:
- Wed May 01 04:11:18 2019 +0000
- Parent:
- 3:564e4aca4ff8
- Commit message:
- This is a test
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Dht11.cpp Wed May 01 04:11:18 2019 +0000
@@ -0,0 +1,89 @@
+#include "Dht11.h"
+
+Dht11::Dht11(PinName const &p) : _pin(p) {
+ // Set creation time so we can make
+ // sure we pause at least 1 second for
+ // startup.
+ _timer.start();
+
+ _temperature = 0;
+ _humidity = 0;
+}
+
+int Dht11::read()
+{
+ // BUFFER TO RECEIVE
+ uint8_t bits[5];
+ uint8_t cnt = 7;
+ uint8_t idx = 0;
+
+ // EMPTY BUFFER
+ for (int i=0; i< 5; i++) bits[i] = 0;
+
+ // Verify sensor settled after boot
+ while(_timer.read_ms() < 1500) {}
+ _timer.stop();
+
+ // Notify it we are ready to read
+ _pin.output();
+ _pin = 0;
+ wait_ms(18);
+ _pin = 1;
+ wait_us(40);
+ _pin.input();
+
+ // ACKNOWLEDGE or TIMEOUT
+ unsigned int loopCnt = 10000;
+ while(_pin == 0)
+ if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
+
+ loopCnt = 10000;
+ while(_pin == 1)
+ if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
+
+ // READ OUTPUT - 40 BITS => 5 BYTES or TIMEOUT
+ for (int i=0; i<40; i++)
+ {
+ loopCnt = 10000;
+ while(_pin == 0)
+ if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
+
+ //unsigned long t = micros();
+ Timer t;
+ t. start();
+
+ loopCnt = 10000;
+ while(_pin == 1)
+ if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
+
+ if (t.read_us() > 40) bits[idx] |= (1 << cnt);
+ if (cnt == 0) // next byte?
+ {
+ cnt = 7; // restart at MSB
+ idx++; // next byte!
+ }
+ else cnt--;
+ }
+
+ // WRITE TO RIGHT VARS
+ // as bits[1] and bits[3] are allways zero they are omitted in formulas.
+ _humidity = bits[0];
+ _temperature = bits[2];
+
+ uint8_t sum = bits[0] + bits[2];
+
+ if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM;
+ return DHTLIB_OK;
+}
+
+float Dht11::getFahrenheit() {
+ return((_temperature * 1.8) + 32);
+}
+
+int Dht11::getCelsius() {
+ return(_temperature);
+}
+
+int Dht11::getHumidity() {
+ return(_humidity);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Dht11.h Wed May 01 04:11:18 2019 +0000
@@ -0,0 +1,74 @@
+#ifndef DHT11_H
+#define DHT11_H
+
+#include "mbed.h"
+
+#define DHTLIB_OK 0
+#define DHTLIB_ERROR_CHECKSUM -1
+#define DHTLIB_ERROR_TIMEOUT -2
+
+/** Class for the DHT11 sensor.
+ *
+ * Example:
+ * @code
+ * #include "mbed.h"
+ * #include "Dht11.h"
+ *
+ * Serial pc(USBTX, USBRX);
+ * Dht11 sensor(PTD7);
+ *
+ * int main() {
+ * sensor.read()
+ * pc.printf("T: %f, H: %d\r\n", sensor.getFahrenheit(), sensor.getHumidity());
+ * }
+ * @endcode
+ */
+class Dht11
+{
+public:
+ /** Construct the sensor object.
+ *
+ * @param pin PinName for the sensor pin.
+ */
+ Dht11(PinName const &p);
+
+ /** Update the humidity and temp from the sensor.
+ *
+ * @returns
+ * 0 on success, otherwise error.
+ */
+ int read();
+
+ /** Get the temp(f) from the saved object.
+ *
+ * @returns
+ * Fahrenheit float
+ */
+ float getFahrenheit();
+
+ /** Get the temp(c) from the saved object.
+ *
+ * @returns
+ * Celsius int
+ */
+ int getCelsius();
+
+ /** Get the humidity from the saved object.
+ *
+ * @returns
+ * Humidity percent int
+ */
+ int getHumidity();
+
+private:
+ /// percentage of humidity
+ int _humidity;
+ /// celsius
+ int _temperature;
+ /// pin to read the sensor info on
+ DigitalInOut _pin;
+ /// times startup (must settle for at least a second)
+ Timer _timer;
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Stepper_Motor_X27168.lib Wed May 01 04:11:18 2019 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ECE-4180/code/Stepper_Motor_X27168/#c346170974bc
--- a/main.cpp Mon Apr 29 01:03:45 2019 +0000
+++ b/main.cpp Wed May 01 04:11:18 2019 +0000
@@ -9,11 +9,18 @@
#include "SDFileSystem.h"
#include <MbedJSONValue.h>
#include <string>
+#include "StepperMotor_X27168.h"
//IMPORTANT YOU NEED TO SET THE API KEY for thingspeak look for "your key here"
//TAKE CARE URL doesn't excced buffer size
//sd card
// SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCLK, SSEL
//Ethernet Interface
+
+DigitalOut communicate(p30); ///Pull low until ready to go
+DigitalOut motor3(p23);
+StepperMotor_X27168 smotor3(p24,p25,p22,p21);
+
+
EthernetInterface eth;
//NTP service for date and Time used to set boards RTC
NTPClient ntp;
@@ -32,8 +39,28 @@
MbedJSONValue v;
+volatile char c = '\0'; // Initialized to the NULL character
+volatile int check = 0;
+Serial device(p28,p27); //9-10 11u; 28-27 1768
+void onCharReceived()
+{
+ c = device.getc();
+ check = 1;
+}
+
int main()
{
+ communicate = 0;
+ pc.printf("\r\nWeather Reporter\n");
+
+// while (1) {
+// wait(.1);
+// }
+// check = 0;
+
+// device.attach(&onCharReceived);
+
+
int ret=0;
@@ -56,9 +83,12 @@
mac = eth.getMACAddress();
pc.printf("MAC: %s\r\n", mac);
TCPSocketConnection sock;
+
sock.connect("api.openweathermap.org", 80);
+ wait(5);
char http_cmd[] = "GET /data/2.5/weather?q=Atlanta,US&APPID=a1c3afc7f18b7ef578cef48d5163cda6 HTTP/1.0\r\n\r\n";
if (!sock.is_connected()){
+ pc.printf("This not working");
return -1;
}
sock.send_all(http_cmd, sizeof(http_cmd)-1);
@@ -75,13 +105,14 @@
sock.close();
eth.disconnect();
+
float forecastHumidity=0;
// float temperature=-100;
float forcastTemp=0;
float forcastDescription = 0;
// float forcastPressure;
- wait(10);
+ wait(2);
pc.printf("\r\nDHT Test program");
pc.printf("\r\n******************\r\n");
wait(1); // wait 1 second for device stable status
@@ -147,14 +178,29 @@
std::time_t result = time(NULL);
// std::cout << std::asctime(std::localtime(&result))
- printf("\n\nCurrent Time: %s \r\n",ctime(&result));
- printf("Current Temperature: %s Kelvin \r\n",weather.temp);
- printf("Humidity is %s \r\n",weather.hum);
- printf("Weather Condition: %s \r\n", weather.desc);
+
+
+ // pc.printf("\n\nCurrent Time: %s \r\n",ctime(&result));
+ // pc.printf("Current Temperature: %s Kelvin \r\n",weather.temp);
+ // pc.printf("Humidity is %s \r\n",weather.hum);
+ // pc.printf("Weather Condition: %s \r\n", weather.desc);
+ //
+ double weather_temp = atof(weather.temp.c_str());
+ //double weather_temp = 301.483;
+ weather_temp = weather_temp - 273.15;
+ weather_temp = (weather_temp * 9/5) + 32;
+ // range is 60 - 85
+ weather_temp = weather_temp - 60;
+ weather_temp = weather_temp * 360/25;
+ wait(5);
+ motor3 = 1;
+ smotor3.step_position(weather_temp);
+ wait(1.5);
+ communicate = 1;
wait(60);
}
-}
-}
+
+}}