From f2355eb47e86735235f1ac74541393e7114a072c Mon Sep 17 00:00:00 2001 From: Vyachez Date: Sat, 23 Jan 2016 17:37:58 +0200 Subject: [PATCH 1/2] updating_with_mod --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 07095ab..7de8bc6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ -# Python Arduino Command API +# DHT_IR_ULTRA Mod +Updated prototype.ino to control DHT sensor, Ultrasonic sensor, IR sensor + +# Ultrasonic sensor mapping example: +https://github.com/Vyachez/Mapping_with_sensor_Arduino_python +# Basics +# Python Arduino Command API The Python Arduino Command API is a light-weight Python library for communicating with [Arduino microcontroller boards](http://www.arduino.cc/) from a connected computer using standard serial IO, either over a physical wire From 1f7a1b4b616929d881e422848bc783ef0cd07bc4 Mon Sep 17 00:00:00 2001 From: Vyachez Date: Sat, 23 Jan 2016 17:48:24 +0200 Subject: [PATCH 2/2] updated prototype.ino --- sketches/prototype/prototype.ino | 95 +++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 27 deletions(-) diff --git a/sketches/prototype/prototype.ino b/sketches/prototype/prototype.ino index cee57ab..8f52e9d 100644 --- a/sketches/prototype/prototype.ino +++ b/sketches/prototype/prototype.ino @@ -1,7 +1,8 @@ #include #include #include -#include +#include "DHT.h" +#include SoftwareSerial *sserial = NULL; Servo servos[8]; @@ -93,7 +94,7 @@ uint8_t readCapacitivePin(String data) { //return cycles; Serial.println(cycles); } - +/* void Tone(String data){ int idx = data.indexOf('%'); int len = Str2int(data.substring(0,idx)); @@ -118,6 +119,19 @@ void ToneNo(String data){ int pin = Str2int(data); noTone(pin); } +*/ + +//Ir setup code +int RECV_PIN = 28; //defining pin for IR sensor + +IRrecv irrecv(RECV_PIN); + +decode_results results; + +//Ultra set up code +//defining pins +#define trigPin 26 +#define echoPin 5 void DigitalHandler(int mode, String data){ int pin = Str2int(data); @@ -302,20 +316,40 @@ void SV_write_ms(String data) { servos[pos].writeMicroseconds(uS); } -void sizeEEPROM() { - Serial.println(E2END + 1); +void DHT_read(String data) { + String sdata[2]; + split(sdata,2,data,'%'); + int pin = Str2int(sdata[0]); + // type can be 11 21 22 + int type = Str2int(sdata[1]); + DHT dht(pin, type); + dht.begin(); + float h = dht.readHumidity(); + float t = dht.readTemperature(); + Serial.print(h); + Serial.print(" "); + Serial.println(t); } -void EEPROMHandler(int mode, String data) { - String sdata[2]; - split(sdata, 2, data, '%'); - if (mode == 0) { - EEPROM.write(Str2int(sdata[0]), Str2int(sdata[1])); - } else { - Serial.println(EEPROM.read(Str2int(sdata[0]))); - } +void IR_read() { //this is the function for Ir receiver + if (irrecv.decode(&results)) { + Serial.println(results.value, HEX); + irrecv.resume(); // Receive the next value + } } +void Ul_read() { //this is the function for ultra sensor + long duration, distance; + digitalWrite(trigPin, LOW); + delayMicroseconds(2); + digitalWrite(trigPin, HIGH); + delayMicroseconds(10); + digitalWrite(trigPin, LOW); + duration = pulseIn(echoPin, HIGH); + distance = (duration/2) / 29.1; + Serial.println(distance); + } + void SerialParser(void) { char readChar[64]; Serial.readBytesUntil(33,readChar,64); @@ -376,12 +410,12 @@ void SerialParser(void) { else if (cmd == "version") { Version(); } - else if (cmd == "to") { +/* else if (cmd == "to") { Tone(data); } else if (cmd == "nto") { ToneNo(data); - } + } */ else if (cmd == "cap") { readCapacitivePin(data); } @@ -391,23 +425,30 @@ void SerialParser(void) { else if (cmd == "si") { shiftInHandler(data); } - else if (cmd == "eewr") { - EEPROMHandler(0, data); - } - else if (cmd == "eer") { - EEPROMHandler(1, data); - } - else if (cmd == "sz") { - sizeEEPROM(); - } + + else if (cmd == "dht") { + // read humidity and temperature + DHT_read(data); + } + + else if (cmd == "irrecv") { + // read ir data + IR_read(); + } + + else if (cmd == "ultra") { + // read ultrasonic distance sensor + Ul_read(); + } + } void setup() { - Serial.begin(9600); - while (!Serial) { - ; // wait for serial port to connect. Needed for Leonardo only + Serial.begin(921600); + irrecv.enableIRIn(); + pinMode(trigPin, OUTPUT); + pinMode(echoPin, INPUT); } -} void loop() { SerialParser();