Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request for setup #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
95 changes: 68 additions & 27 deletions sketches/prototype/prototype.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Servo.h>
#include <EEPROM.h>
#include "DHT.h"
#include <IRremote.h>

SoftwareSerial *sserial = NULL;
Servo servos[8];
Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
Expand Down