Closed kongaraju closed 10 years ago
Hi,
I use Raspberry pi model B,
http://cpcireland.farnell.com/jsp/search/productdetail.jsp?sku=SC12590
with Arduino Uno
http://arduino.cc/en/Main/arduinoBoardUno
and Relay Shield on the top of Arduino:
http://www.seeedstudio.com/wiki/Relay_Shield_V2.0
If you want to get temperature or humidity sensors, i recommend some digital sensors, I use DHT22, but you need to modify the arduino's software.
Best wishes, Barni
Thanks Barni,
please provide some more sensors information.
Hi,
you can find some sensor examples on the Arduino page of the project:
http://ni-c.github.io/heimcontrol.js/plugins/arduino.html
Regards, ni-c
Kongaraju:
if you want to use DHT22 or DHT11 sensors i will post here the arduino code i use, no problem.
Barni
I would really like to see the DHT22 code you use, Im having a few issues. Thanks.
Huh,
Everything went fine, until the arduino and duino library from raspberry(i think) crashed (?).
Here are the circumstances: i will post here one image showing my problem regarding the DHT22 readings.
I will paste below the arduino code, made from duino and example from the dht22.
DHT dht(DHTPIN, DHTTYPE); DHT dht2(DHT2PIN, DHTTYPE);
bool debug = true;
int index = 0;
char messageBuffer[12]; char cmd[3]; char pin[3]; char val[4]; char aux[4];
Servo servo;
void setup() { Serial.begin(115200); dht.begin(); dht2.begin(); }
void loop() { while(Serial.available() > 0) { char x = Serial.read(); if (x == '!') index = 0; // start else if (x == '.') process(); // end else messageBuffer[index++] = x; } }
/*
Deal with a full message and determine function to call */ void process() { index = 0;
strncpy(cmd, messageBuffer, 2); cmd[2] = '\0'; strncpy(pin, messageBuffer + 2, 2); pin[2] = '\0';
if (atoi(cmd) > 90) { strncpy(val, messageBuffer + 4, 2); val[2] = '\0'; strncpy(aux, messageBuffer + 6, 3); aux[3] = '\0'; } else { strncpy(val, messageBuffer + 4, 3); val[3] = '\0'; strncpy(aux, messageBuffer + 7, 3); aux[3] = '\0'; }
if (debug) { Serial.println(messageBuffer); } int cmdid = atoi(cmd);
// Serial.println(cmd); // Serial.println(pin); // Serial.println(val); // Serial.println(aux);
switch(cmdid) { case 0: sm(pin,val); break; case 1: dw(pin,val); break; case 2: dr(pin,val); break; case 3: aw(pin,val); break; case 4: ar(pin,val); break; case 97: handlePing(pin,val,aux); break; case 98: handleServo(pin,val,aux); break; case 99: toggleDebug(val); break; default: break; } }
/*
/*
/*
/*
/*
Analog read _/ void ar(char pin, char val) { if(debug) Serial.println("ar"); int p = getPin(pin); if(p == -1) { if(debug) Serial.println("badpin"); return; } pinMode(p, INPUT); // don't want to sw if (p == 14) { delay(250); float hval = dht2.readHumidity()_10; float tval = dht2.readTemperature()*10; delay(250); int hval1 = hval; int tval1 = tval; char n[8]; char m[8]; sprintf(m, "%s::%03d", pin, hval1);
sprintf(n, "A1::%03d", tval1);
Serial.println(m);
delay(250);
Serial.println(n);
// Serial.println(hval); //Serial.println(tval); delay(250);
}
if (p == 16) {
float hval = dht2.readHumidity()*10;
float tval = dht2.readTemperature()*10;
int hval1 = hval;
int tval1 = tval;
char n[8];
char m[8];
sprintf(m, "%s::%03d", pin, hval1); sprintf(n, "A3::%03d", tval1); //Serial.println(m); Serial.println(hval); Serial.println(tval);
//Serial.println(n);
}
}
void aw(char pin, char val) { if(debug) Serial.println("aw"); int p = getPin(pin); pinMode(p, OUTPUT); if(p == -1) { if(debug) Serial.println("badpin"); return; } analogWrite(p,atoi(val)); }
int getPin(char *pin) { //Converts to A0-A5, and returns -1 on error int ret = -1; if(pin[0] == 'A' || pin[0] == 'a') { switch(pin[1]) { case '0': ret = A0; break; case '1': ret = A1; break; case '2': ret = A2; break; case '3': ret = A3; break; case '4': ret = A4; break; case '5': ret = A5; break; default: break; } } else { ret = atoi(pin); if(ret == 0 && (pin[0] != '0' || pin[1] != '0')) { ret = -1; } } return ret; }
/*
fire, read / void handlePing(char pin, char val, char aux) { if (debug) Serial.println("ss"); int p = getPin(pin);
if(p == -1) { if(debug) Serial.println("badpin"); return; } Serial.println("got signal");
// 01(1) Fire and Read if (atoi(val) == 1) { char m[16];
pinMode(p, OUTPUT); digitalWrite(p, LOW); delayMicroseconds(2); digitalWrite(p, HIGH); delayMicroseconds(5); digitalWrite(p, LOW);
Serial.println("ping fired");
pinMode(p, INPUT); sprintf(m, "%s::read::%08d", pin, pulseIn(p, HIGH)); Serial.println(m);
delay(50); } }
/*
attach, detach, write, read, writeMicroseconds, attached / void handleServo(char pin, char val, char aux) { if (debug) Serial.println("ss"); int p = getPin(pin); if(p == -1) { if(debug) Serial.println("badpin"); return; } Serial.println("signal: servo");
// 00(0) Detach if (atoi(val) == 0) { servo.detach(); char m[12]; sprintf(m, "%s::detached", pin); Serial.println(m);
// 01(1) Attach } else if (atoi(val) == 1) { // servo.attach(p, 750, 2250); servo.attach(p); char m[12]; sprintf(m, "%s::attached", pin); Serial.println(m);
// 02(2) Write } else if (atoi(val) == 2) { Serial.println("writing to servo"); Serial.println(atoi(aux)); // Write to servo servo.write(atoi(aux)); delay(15);
// TODO: Experiment with microsecond pulses // digitalWrite(pin, HIGH); // start the pulse // delayMicroseconds(pulseWidth); // pulse width // digitalWrite(pin, LOW); // stop the pulse
// 03(3) Read } else if (atoi(val) == 3) { Serial.println("reading servo"); int sval = servo.read(); char m[13]; sprintf(m, "%s::read::%03d", pin, sval); Serial.println(m); } }
The main idea is to set on the web interface arduino sensor A0 A1 A2 A3 , and on the arduino i have 2 dht22 sensors.
For one month everything goes well, but now i have many errors on reading, like you see on the picture. Maybe some sync problem, but i'm not shure yet.
I have tryed to solve this:
but something is wrong. :(
Barni
Thanks for the help, its much appreciated
I am new to hardware, I want to use this project. so I want to buy hardware , please provide me technical specification of Raspberry pi and arduino board.
links will be more helpful
Thanks in advance.